@feathersjs/feathers
- Version 5.0.30
- Published
- 160 kB
- 3 dependencies
- MIT license
Install
npm i @feathersjs/feathers
yarn add @feathersjs/feathers
pnpm add @feathersjs/feathers
Overview
A framework for real-time applications and REST API with JavaScript and TypeScript
Index
Variables
Functions
Classes
Interfaces
Type Aliases
- ApplicationHookFunction
- ApplicationHookMap
- ApplicationHookOptions
- AroundHookFunction
- AroundHookMap
- CustomMethod
- CustomMethods
- FeathersService
- Hook
- HookFunction
- HookMap
- HookOptions
- HookType
- Id
- NullableId
- PaginationParams
- Service
- ServiceGenericData
- ServiceGenericParams
- ServiceGenericType
- ServiceInterface
- ServiceMixin
- TransportConnection
Variables
variable defaultEventMap
const defaultEventMap: { create: string; update: string; patch: string; remove: string;};
variable defaultServiceArguments
const defaultServiceArguments: { find: string[]; get: string[]; create: string[]; update: string[]; patch: string[]; remove: string[];};
variable defaultServiceEvents
const defaultServiceEvents: string[];
variable defaultServiceMethods
const defaultServiceMethods: string[];
variable feathers
const feathers: typeof feathers;
variable protectedMethods
const protectedMethods: string[];
variable SERVICE
const SERVICE: any;
variable version
const version: any;
Functions
function collectHooks
collectHooks: ( target: HookEnabled, method: string) => AroundHookFunction< Application<any, any>, Service<any, Partial<any>, Params<Query>, Partial<Partial<any>>>>[];
function convertHookData
convertHookData: (input: any) => { [method: string]: | HookFunction< Application<any, any>, Service<any, Partial<any>, Params<Query>, Partial<Partial<any>>> >[] | AroundHookFunction< Application<any, any>, Service<any, Partial<any>, Params<Query>, Partial<Partial<any>>> >[];};
function createContext
createContext: ( service: Service, method: string, data?: HookContextData) => HookContext<Application<any, any>, any>;
function enableHooks
enableHooks: ( object: any) => (this: HookEnabled, input: HookMap<any, any>) => HookEnabled;
function feathers
feathers: typeof feathers;
function getHookMethods
getHookMethods: (service: any, options: ServiceOptions) => string[];
function getServiceOptions
getServiceOptions: (service: any) => ServiceOptions;
function hookMixin
hookMixin: <A>( this: A, service: FeathersService<A>, path: string, options: ServiceOptions) => FeathersService< A, Service<any, Partial<any>, Params<Query>, Partial<Partial<any>>>>;
function normalizeServiceOptions
normalizeServiceOptions: ( service: any, options?: ServiceOptions) => ServiceOptions;
function wrapService
wrapService: (location: string, service: any, options: ServiceOptions) => any;
Classes
class Feathers
class Feathers<Services, Settings> extends EventEmitter implements FeathersApplication<Services, Settings> {}
constructor
constructor();
property mixins
mixins: ServiceMixin<Application<Services, Settings>>[];
property registerHooks
protected registerHooks: (this: any, allHooks: any) => any;
property services
services: {};
property settings
settings: {};
property setup
setup: () => Promise<this>;
property teardown
teardown: () => Promise<this>;
property version
version: string;
method configure
configure: (callback: (this: this, app: this) => void) => this;
method defaultService
defaultService: (location: string) => ServiceInterface;
method get
get: <L extends keyof Settings & string>(name: L) => Settings[L];
method hooks
hooks: (hookMap: ApplicationHookOptions<this>) => this;
method service
service: <L extends keyof Services & string>( location: L) => FeathersService< this, keyof any extends keyof Services ? Service : Services[L]>;
method set
set: <L extends keyof Settings & string>(name: L, value: Settings[L]) => this;
method unuse
unuse: <L extends keyof Services & string>( location: L) => Promise< FeathersService< this, keyof any extends keyof Services ? Service : Services[L] >>;
method use
use: <L extends keyof Services & string>( path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions< keyof any extends keyof Services ? string : keyof Services[L] >) => this;
class FeathersHookManager
class FeathersHookManager<A> extends HookManager {}
constructor
constructor(app: {}, method: string);
property app
app: {};
property method
method: string;
method collectMiddleware
collectMiddleware: (self: any, args: any[]) => Middleware[];
method initializeContext
initializeContext: (self: any, args: any[], context: HookContext) => any;
method middleware
middleware: (mw: Middleware[]) => this;
Interfaces
interface Application
interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {}
interface ApplicationHookContext
interface ApplicationHookContext<A = Application> extends BaseHookContext {}
interface ClientService
interface ClientService< Result = any, Data = Partial<Result>, PatchData = Data, FindResult = Paginated<Result>, P = Params> {}
method create
create: { (data: Data[], params?: P): Promise<Result[]>; (data: Data, params?: P): Promise<Result>;};
method find
find: (params?: P) => Promise<FindResult>;
method get
get: (id: Id, params?: P) => Promise<Result>;
method patch
patch: { (id: NullableId, data: PatchData, params?: P): Promise<Result | Result[]>; (id: Id, data: PatchData, params?: P): Promise<Result>; (id: null, data: PatchData, params?: P): Promise<Result[]>;};
method remove
remove: { (id: NullableId, params?: P): Promise<Result | Result[]>; (id: Id, params?: P): Promise<Result>; (id: null, params?: P): Promise<Result[]>;};
method update
update: { (id: Id, data: Data, params?: P): Promise<Result>; (id: NullableId, data: Data, params?: P): Promise<Result | Result[]>; (id: null, data: Data, params?: P): Promise<Result[]>;};
interface FeathersApplication
interface FeathersApplication<Services = any, Settings = any> {}
property mixins
mixins: ServiceMixin<Application<Services, Settings>>[];
A list of callbacks that run when a new service is registered
property services
services: Services;
The index of all services keyed by their path.
__Important:__ Services should always be retrieved via
app.service('name')
not viaapp.services
.
property settings
settings: Settings;
The application settings that can be used via
app.get
andapp.set
property version
version: string;
The Feathers application version
method configure
configure: (callback: (this: this, app: this) => void) => this;
Runs a callback configure function with the current application instance.
Parameter callback
The callback
(app: Application) => {}
to run
method defaultService
defaultService: (location: string) => ServiceInterface;
Returns a fallback service instance that will be registered when no service was found. Usually throws a
NotFound
error but also used to instantiate client side services.Parameter location
The path of the service
method get
get: <L extends keyof Settings & string>(name: L) => Settings[L];
Retrieve an application setting by name
Parameter name
The setting name
method hooks
hooks: (map: ApplicationHookOptions<this>) => this;
Register application level hooks.
Parameter map
The application hook settings.
method service
service: <L extends keyof Services & string>( path: L) => FeathersService< this, keyof any extends keyof Services ? Service : Services[L]>;
Get the Feathers service instance for a path. This will be the service originally registered with Feathers functionality like hooks and events added.
Parameter path
The name of the service.
method set
set: <L extends keyof Settings & string>(name: L, value: Settings[L]) => this;
Set an application setting
Parameter name
The setting name
Parameter value
The setting value
method setup
setup: (server?: any) => Promise<this>;
Set up the application and call all services
.setup
method if available.Parameter server
A server instance (optional)
method teardown
teardown: (server?: any) => Promise<this>;
Tear down the application and call all services
.teardown
method if available.Parameter server
A server instance (optional)
method unuse
unuse: <L extends keyof Services & string>( path: L) => Promise< FeathersService< this, keyof any extends keyof Services ? Service : Services[L] >>;
Unregister an existing service.
Parameter path
The name of the service to unregister
method use
use: <L extends keyof Services & string>( path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions< keyof any extends keyof Services ? string : keyof Services[L] >) => this;
Register a new service or a sub-app. When passed another Feathers application, all its services will be re-registered with the
path
prefix.Parameter path
The path for the service to register
Parameter service
The service object to register or another Feathers application to use a sub-app under the
path
prefix.Parameter options
The options for this service
interface HookContext
interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {}
property app
readonly app: A;
A read only property that contains the Feathers application object. This can be used to retrieve other services (via context.app.service('name')) or configuration values.
property arguments
readonly arguments: any[];
The list of method arguments. Should not be modified, modify the
params
,data
andid
properties instead.
property data
data?: ServiceGenericData<S>;
A writeable property containing the data of a create, update and patch service method call.
property dispatch
dispatch?: ServiceGenericType<S>;
A writeable, optional property and contains a 'safe' version of the data that should be sent to any client. If context.dispatch has not been set context.result will be sent to the client instead.
property error
error?: any;
A writeable property with the error object that was thrown in a failed method call. It is only available in error hooks.
property event
event: string | null;
The event emitted by this method. Can be set to
null
to skip event emitting.
property http
http?: Http;
A writeable, optional property with options specific to HTTP transports.
property id
id?: Id;
A writeable property and the id for a get, remove, update and patch service method call. For remove, update and patch context.id can also be null when modifying multiple entries. In all other cases it will be undefined.
property method
readonly method: string;
A read only property with the name of the service method (one of find, get, create, update, patch, remove).
property params
params: ServiceGenericParams<S>;
A writeable property that contains the service method parameters (including params.query).
property path
path: 0 extends 1 & S ? keyof Serv<A> & string : GetKeyByValue<Serv<A>, S> & string;
A read only property and contains the service name (or path) without leading or trailing slashes.
property result
result?: ServiceGenericType<S>;
A writeable property containing the result of the successful service method call. It is only available in after hooks.
context.result
can also be set in- A before hook to skip the actual service method (database) call - An error hook to swallow the error and return a result instead
property service
readonly service: S;
A read only property and contains the service this hook currently runs on.
property statusCode
statusCode?: number;
A writeable, optional property that allows to override the standard HTTP status code that should be returned.
Deprecated
Use
http.status
instead.
property type
readonly type: HookType;
A read only property with the hook type (one of 'around', 'before', 'after' or 'error').
interface Http
interface Http {}
interface Paginated
interface Paginated<T> {}
The object returned from
.find
call by standard database adapters
interface PaginationOptions
interface PaginationOptions {}
interface Params
interface Params<Q = Query> {}
interface Query
interface Query {}
index signature
[key: string]: any;
interface RealTimeConnection
interface RealTimeConnection {}
A real-time connection object
index signature
[key: string]: any;
interface ServiceAddons
interface ServiceAddons<A = Application, S = Service> extends EventEmitter {}
interface ServiceHookOverloads
interface ServiceHookOverloads<S, P = Params> {}
method create
create: ( data: ServiceGenericData<S> | ServiceGenericData<S>[], params: P, context: HookContext) => Promise<HookContext>;
method find
find: ( params: P & { paginate?: PaginationParams }, context: HookContext) => Promise<HookContext>;
method get
get: (id: Id, params: P, context: HookContext) => Promise<HookContext>;
method patch
patch: ( id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext) => Promise<HookContext>;
method remove
remove: ( id: NullableId, params: P, context: HookContext) => Promise<HookContext>;
method update
update: ( id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext) => Promise<HookContext>;
interface ServiceMethods
interface ServiceMethods< Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {}
method create
create: (data: Data, params?: ServiceParams) => Promise<Result>;
method find
find: ( params?: ServiceParams & { paginate?: PaginationParams }) => Promise<Result | Result[]>;
method get
get: (id: Id, params?: ServiceParams) => Promise<Result>;
method patch
patch: ( id: NullableId, data: PatchData, params?: ServiceParams) => Promise<Result | Result[]>;
method remove
remove: (id: NullableId, params?: ServiceParams) => Promise<Result | Result[]>;
method setup
setup: (app: Application, path: string) => Promise<void>;
method teardown
teardown: (app: Application, path: string) => Promise<void>;
method update
update: ( id: NullableId, data: Data, params?: ServiceParams) => Promise<Result | Result[]>;
interface ServiceOptions
interface ServiceOptions<MethodTypes = string> {}
Options that can be passed when registering a service via
app.use(name, service, options)
property events
events?: string[] | readonly string[];
A list of custom events that this service emits to clients
property methods
methods?: MethodTypes[] | readonly MethodTypes[];
A list of service methods that should be available __externally__ to clients
property routeParams
routeParams?: { [key: string]: any };
Initial data to always add as route params to this service.
property serviceEvents
serviceEvents?: string[] | readonly string[];
Provide a full list of events that this service should emit to clients. Unlike the
events
option, this will not be merged with the default events.
interface ServiceOverloads
interface ServiceOverloads< Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {}
method create
create: (data: Data[], params?: ServiceParams) => Promise<Result[]>;
method patch
patch: { (id: Id, data: PatchData, params?: ServiceParams): Promise<Result>; (id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;};
method remove
remove: { (id: Id, params?: ServiceParams): Promise<Result>; (id: null, params?: ServiceParams): Promise<Result[]>;};
method update
update: { (id: Id, data: Data, params?: ServiceParams): Promise<Result>; (id: null, data: Data, params?: ServiceParams): Promise<Result[]>;};
Type Aliases
type ApplicationHookFunction
type ApplicationHookFunction<A> = ( context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
type ApplicationHookMap
type ApplicationHookMap<A> = { setup?: ApplicationHookFunction<A>[]; teardown?: ApplicationHookFunction<A>[];};
type ApplicationHookOptions
type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>;
type AroundHookFunction
type AroundHookFunction<A = Application, S = Service> = ( context: HookContext<A, S>, next: NextFunction) => Promise<void>;
type AroundHookMap
type AroundHookMap<A, S> = { [L in keyof S]?: AroundHookFunction<A, S>[];} & { all?: AroundHookFunction<A, S>[] };
type CustomMethod
type CustomMethod<T = any, R = T, P extends Params = Params> = ( data: T, params?: P) => Promise<R>;
The interface for a custom service method. Can e.g. be used to type client side services.
type CustomMethods
type CustomMethods<T extends { [key: string]: [any, any] }> = { [K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;};
type FeathersService
type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
type Hook
type Hook<A = Application, S = Service> = HookFunction<A, S>;
type HookFunction
type HookFunction<A = Application, S = Service> = ( this: S, context: HookContext<A, S>) => | Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;
type HookMap
type HookMap<A, S> = { around?: AroundHookMap<A, S>; before?: HookTypeMap<A, S>; after?: HookTypeMap<A, S>; error?: HookTypeMap<A, S>;};
type HookOptions
type HookOptions<A, S> = | AroundHookMap<A, S> | AroundHookFunction<A, S>[] | HookMap<A, S>;
type HookType
type HookType = 'before' | 'after' | 'error' | 'around';
type Id
type Id = number | string;
type NullableId
type NullableId = Id | null;
type PaginationParams
type PaginationParams = false | PaginationOptions;
type Service
type Service< Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = ServiceMethods<Result, Data, ServiceParams> & ServiceOverloads<Result, Data, ServiceParams, PatchData>;
A complete service interface. The
ServiceInterface
type should be preferred for customs service implementations
type ServiceGenericData
type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
type ServiceGenericParams
type ServiceGenericParams<S> = S extends ServiceInterface< infer _T, infer _D, infer P> ? P : any;
type ServiceGenericType
type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
type ServiceInterface
type ServiceInterface< Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = Partial<ServiceMethods<Result, Data, ServiceParams, PatchData>>;
The
Service
service interface but with none of the methods required.
type ServiceMixin
type ServiceMixin<A> = ( service: FeathersService<A>, path: string, options: ServiceOptions) => void;
type TransportConnection
type TransportConnection<Services = any> = { (app: Application<Services>): void; Service: any; service: <L extends keyof Services & string>( name: L ) => keyof any extends keyof Services ? ServiceInterface : Services[L];};
An interface usually use by transport clients that represents a e.g. HTTP or websocket connection that can be configured on the application.
Package Files (6)
Dependencies (3)
Dev Dependencies (6)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@feathersjs/feathers
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@feathersjs/feathers)
- HTML<a href="https://www.jsdocs.io/package/@feathersjs/feathers"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5724 ms. - Missing or incorrect documentation? Open an issue for this package.