CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-feathersjs--feathers

A framework for real-time applications and REST API with JavaScript and TypeScript

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Feathers

Feathers is a lightweight web framework for creating APIs and real-time applications using TypeScript or JavaScript. It provides a service-oriented architecture with built-in support for hooks, events, authentication, and database integrations, enabling developers to build modern backends that support both REST APIs and real-time functionality through WebSockets.

Package Information

  • Package Name: @feathersjs/feathers
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @feathersjs/feathers

Core Imports

import { feathers, Application } from "@feathersjs/feathers";

For CommonJS:

const { feathers } = require("@feathersjs/feathers");

Main Exports

Core Functions and Classes

  • feathers<T, S>() - Factory function that creates new Feathers application instance
  • Feathers - Main application class
  • version - Package version string
  • feathers.setDebug - Debug utility function

Service Utilities

  • SERVICE - Internal symbol for service metadata
  • defaultServiceMethods - Standard service methods array
  • defaultServiceArguments - Service method argument mappings
  • defaultEventMap - Service method to event name mappings
  • defaultServiceEvents - Default service events array
  • protectedMethods - Protected method names array
  • getHookMethods() - Get hookable service methods
  • getServiceOptions() - Retrieve service configuration
  • normalizeServiceOptions() - Normalize service options
  • wrapService() - Wrap service with Feathers functionality

Hook System Functions

  • convertHookData() - Convert hook registration formats
  • collectHooks() - Collect hooks for execution
  • enableHooks() - Add hook capability to objects
  • createContext() - Create hook execution context
  • FeathersHookManager - Hook management class
  • hookMixin() - Service hook integration mixin

Event System Functions

  • eventHook() - Core event emission hook
  • eventMixin() - Add event capability to services

Complete Type System

All TypeScript interfaces, types, and utilities for building typed Feathers applications (see Types section below).

Basic Usage

import { feathers, Service } from "@feathersjs/feathers";

// Create a Feathers application
const app = feathers();

// Define a simple service
class MessageService implements Service {
  messages = [
    { id: 1, text: "Hello world!" },
    { id: 2, text: "Welcome to Feathers!" }
  ];

  async find() {
    return this.messages;
  }

  async get(id: number) {
    return this.messages.find(msg => msg.id === id);
  }

  async create(data: { text: string }) {
    const message = { id: Date.now(), ...data };
    this.messages.push(message);
    return message;
  }
}

// Register the service
app.use("messages", new MessageService());

// Set up the application
await app.setup();

// Use the service
const messages = await app.service("messages").find();
console.log(messages);

Architecture

Feathers is built around several key components:

  • Application Core: Main Feathers class that manages services, settings, and lifecycle
  • Service Layer: Service-oriented architecture where each service handles CRUD operations for a specific resource
  • Hook System: Middleware system for cross-cutting concerns (validation, authentication, logging)
  • Event System: Real-time event emission for service operations (created, updated, patched, removed)
  • Lifecycle Management: Setup and teardown methods for proper initialization and cleanup

Capabilities

Application Management

Core application functionality for creating Feathers instances, managing settings, and controlling application lifecycle.

function feathers<T = any, S = any>(): Application<T, S>;

interface Application<Services = any, Settings = any> extends EventEmitter {
  version: string;
  services: Services;
  settings: Settings;
  get<L extends keyof Settings & string>(name: L): Settings[L];
  set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
  configure(callback: (this: this, app: this) => void): this;
  setup(server?: any): Promise<this>;
  teardown(server?: any): Promise<this>;
}

Application Management

Service Registration and Management

Service registration, retrieval, and lifecycle management within the Feathers application.

interface Application<Services = any, Settings = any> {
  use<L extends keyof Services & string>(
    path: L,
    service: ServiceInterface | Application,
    options?: ServiceOptions
  ): this;
  service<L extends keyof Services & string>(path: L): FeathersService;
  unuse<L extends keyof Services & string>(location: L): Promise<FeathersService>;
}

interface ServiceOptions<MethodTypes = string> {
  events?: string[] | readonly string[];
  methods?: MethodTypes[] | readonly MethodTypes[];
  serviceEvents?: string[] | readonly string[];
  routeParams?: { [key: string]: any };
}

Service Management

Hook System

Middleware system for intercepting and modifying service method calls with support for before, after, error, and around hooks.

interface Application<Services = any, Settings = any> {
  hooks(hookMap: ApplicationHookOptions<this>): this;
}

interface FeathersService<A = Application, S = Service> {
  hooks(options: HookOptions<A, S>): this;
}

type HookFunction<A = Application, S = Service> = (
  this: S,
  context: HookContext<A, S>
) => Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;

type AroundHookFunction<A = Application, S = Service> = (
  context: HookContext<A, S>,
  next: NextFunction
) => Promise<void>;

Hook System

Service Interfaces

Standard service method interfaces and type definitions for implementing Feathers services.

interface ServiceMethods<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {
  find(params?: ServiceParams & { paginate?: PaginationParams }): Promise<Result | Result[]>;
  get(id: Id, params?: ServiceParams): Promise<Result>;
  create(data: Data, params?: ServiceParams): Promise<Result>;
  update(id: NullableId, data: Data, params?: ServiceParams): Promise<Result | Result[]>;
  patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>;
  remove(id: NullableId, params?: ServiceParams): Promise<Result | Result[]>;
  setup?(app: Application, path: string): Promise<void>;
  teardown?(app: Application, path: string): Promise<void>;
}

type ServiceInterface<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = 
  Partial<ServiceMethods<Result, Data, ServiceParams, PatchData>>;

Service Interfaces

Types

Core Types

type Id = number | string;
type NullableId = Id | null;

// Re-exported from @feathersjs/hooks
type NextFunction = () => Promise<void>;

interface Query {
  [key: string]: any;
}

interface Params<Q = Query> {
  query?: Q;
  provider?: string;
  route?: { [key: string]: any };
  headers?: { [key: string]: any };
}

interface Paginated<T> {
  total: number;
  limit: number;
  skip: number;
  data: T[];
}

interface PaginationOptions {
  default?: number;
  max?: number;
}

type PaginationParams = false | PaginationOptions;

Hook Context

interface HookContext<A = Application, S = any> {
  readonly app: A;
  readonly method: string;
  readonly path: string;
  readonly service: S;
  readonly type: HookType;
  readonly arguments: any[];
  data?: any;
  error?: any;
  id?: Id;
  params: Params;
  result?: any;
  dispatch?: any;
  http?: Http;
  event: string | null;
}

type HookType = 'before' | 'after' | 'error' | 'around';

interface Http {
  status?: number;
  headers?: { [key: string]: string | string[] };
  location?: string;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@feathersjs/feathers@5.0.x
Publish Source
CLI
Badge
tessl/npm-feathersjs--feathers badge