From f2ff2570e76c44e40a3aaca5e7a93dfa6c2db097 Mon Sep 17 00:00:00 2001 From: Jordan Tucker Date: Fri, 5 Apr 2019 14:25:24 -0500 Subject: [PATCH] fix(@feathersjs/feathers): Use `export =` --- types/feathersjs__feathers/index.d.ts | 372 +++++++++++++------------- 1 file changed, 189 insertions(+), 183 deletions(-) diff --git a/types/feathersjs__feathers/index.d.ts b/types/feathersjs__feathers/index.d.ts index 4746b29ff7..e5ffc8abf7 100644 --- a/types/feathersjs__feathers/index.d.ts +++ b/types/feathersjs__feathers/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Jan Lohage // Abraao Alves // Tim Mensch +// Jordan Tucker // Definitions: https://github.com/feathersjs-ecosystem/feathers-typescript // TypeScript Version: 2.3 @@ -10,190 +11,195 @@ /// import { EventEmitter } from 'events'; -import * as self from '@feathersjs/feathers'; -// tslint:disable-next-line no-unnecessary-generics -declare const feathers: (() => Application) & typeof self; -export default feathers; - -export const version: string; -export const SKIP: SkipSymbol; - -export type Id = number | string; -export type NullableId = Id | null; - -export interface Query { - [key: string]: any; -} - -export interface PaginationOptions { - default: number; - max: number; -} - -export type ClientSideParams = Pick; -export type ServerSideParams = Params; - -export interface Params { - query?: Query; - paginate?: false | Pick; - - [key: string]: any; // (JL) not sure if we want this -} - -export interface Paginated { - total: number; - limit: number; - skip: number; - data: T[]; -} - -// tslint:disable-next-line void-return -export type Hook = (hook: HookContext) => (Promise | HookContext | SkipSymbol | void); - -export type SkipSymbol = symbol | '__feathersSkipHooks'; - -export interface HookContext { - /** - * 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. - */ - readonly app: Application; - /** - * A writeable property containing the data of a create, update and patch service - * method call. - */ - data?: T; - /** - * A writeable property with the error object that was thrown in a failed method call. - * It is only available in error hooks. - */ - error?: any; - /** - * 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. - */ - id?: string | number; - /** - * A read only property with the name of the service method (one of find, get, - * create, update, patch, remove). - */ - readonly method: string; - /** - * A writeable property that contains the service method parameters (including - * params.query). - */ - params: Params; - /** - * A read only property and contains the service name (or path) without leading or - * trailing slashes. - */ - readonly path: string; - /** - * 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 - */ - result?: T; - /** - * A read only property and contains the service this hook currently runs on. - */ - readonly service: Service; - /** - * 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. - */ - dispatch?: T; - /** - * A writeable, optional property that allows to override the standard HTTP status - * code that should be returned. - */ - statusCode?: number; - /** - * A read only property with the hook type (one of before, after or error). - */ - readonly type: "before" | "after" | "error"; -} - -export interface HookMap { - all: Hook | Hook[]; - find: Hook | Hook[]; - get: Hook | Hook[]; - create: Hook | Hook[]; - update: Hook | Hook[]; - patch: Hook | Hook[]; - remove: Hook | Hook[]; -} - -export interface HooksObject { - before: Partial; - after: Partial; - error: Partial; -} - -// todo: figure out what to do: These methods don't actually need to be implemented, so they can be undefined at runtime. Yet making them optional gets cumbersome in strict mode. -export interface ServiceMethods { - find(params?: Params): Promise>; - - get(id: Id, params?: Params): Promise; - - create(data: Partial | Array>, params?: Params): Promise; - - update(id: NullableId, data: T, params?: Params): Promise; - - patch(id: NullableId, data: Partial, params?: Params): Promise; - - remove(id: NullableId, params?: Params): Promise; -} - -export interface SetupMethod { - setup(app: Application, path: string): void; -} - -export interface ServiceOverloads { - create(data: Array>, params?: Params): Promise; - - create(data: Partial, params?: Params): Promise; - - patch(id: NullableId, data: Pick, params?: Params): Promise; -} - -export interface ServiceAddons extends EventEmitter { - hooks(hooks: Partial): this; -} - -export type Service = ServiceOverloads & ServiceAddons & ServiceMethods; - -export interface Application extends EventEmitter { - get(name: string): any; - - set(name: string, value: any): this; - - disable(name: string): this; - - disabled(name: string): boolean; - - enable(name: string): this; - - enabled(name: string): boolean; - - configure(callback: (this: this, app: this) => void): this; - - hooks(hooks: Partial): this; - - setup(server?: any): this; - - service(location: L): Service; - - service(location: string): Service; - - use(path: string, service: Partial & SetupMethod> | Application, options?: any): this; +declare const feathers: Feathers; +export = feathers; +interface Feathers { + // tslint:disable-next-line no-unnecessary-generics + (): feathers.Application; version: string; + SKIP: feathers.SkipSymbol; + default: Feathers; +} + +declare namespace feathers { + type Id = number | string; + type NullableId = Id | null; + + interface Query { + [key: string]: any; + } + + interface PaginationOptions { + default: number; + max: number; + } + + type ClientSideParams = Pick; + type ServerSideParams = Params; + + interface Params { + query?: Query; + paginate?: false | Pick; + + [key: string]: any; // (JL) not sure if we want this + } + + interface Paginated { + total: number; + limit: number; + skip: number; + data: T[]; + } + + // tslint:disable-next-line void-return + type Hook = (hook: HookContext) => (Promise | HookContext | SkipSymbol | void); + + type SkipSymbol = symbol | '__feathersSkipHooks'; + + interface HookContext { + /** + * 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. + */ + readonly app: Application; + /** + * A writeable property containing the data of a create, update and patch service + * method call. + */ + data?: T; + /** + * A writeable property with the error object that was thrown in a failed method call. + * It is only available in error hooks. + */ + error?: any; + /** + * 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. + */ + id?: string | number; + /** + * A read only property with the name of the service method (one of find, get, + * create, update, patch, remove). + */ + readonly method: string; + /** + * A writeable property that contains the service method parameters (including + * params.query). + */ + params: Params; + /** + * A read only property and contains the service name (or path) without leading or + * trailing slashes. + */ + readonly path: string; + /** + * 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 + */ + result?: T; + /** + * A read only property and contains the service this hook currently runs on. + */ + readonly service: Service; + /** + * 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. + */ + dispatch?: T; + /** + * A writeable, optional property that allows to override the standard HTTP status + * code that should be returned. + */ + statusCode?: number; + /** + * A read only property with the hook type (one of before, after or error). + */ + readonly type: "before" | "after" | "error"; + } + + interface HookMap { + all: Hook | Hook[]; + find: Hook | Hook[]; + get: Hook | Hook[]; + create: Hook | Hook[]; + update: Hook | Hook[]; + patch: Hook | Hook[]; + remove: Hook | Hook[]; + } + + interface HooksObject { + before: Partial; + after: Partial; + error: Partial; + } + + // todo: figure out what to do: These methods don't actually need to be implemented, so they can be undefined at runtime. Yet making them optional gets cumbersome in strict mode. + interface ServiceMethods { + find(params?: Params): Promise>; + + get(id: Id, params?: Params): Promise; + + create(data: Partial | Array>, params?: Params): Promise; + + update(id: NullableId, data: T, params?: Params): Promise; + + patch(id: NullableId, data: Partial, params?: Params): Promise; + + remove(id: NullableId, params?: Params): Promise; + } + + interface SetupMethod { + setup(app: Application, path: string): void; + } + + interface ServiceOverloads { + create(data: Array>, params?: Params): Promise; + + create(data: Partial, params?: Params): Promise; + + patch(id: NullableId, data: Pick, params?: Params): Promise; + } + + interface ServiceAddons extends EventEmitter { + hooks(hooks: Partial): this; + } + + type Service = ServiceOverloads & ServiceAddons & ServiceMethods; + + interface Application extends EventEmitter { + get(name: string): any; + + set(name: string, value: any): this; + + disable(name: string): this; + + disabled(name: string): boolean; + + enable(name: string): this; + + enabled(name: string): boolean; + + configure(callback: (this: this, app: this) => void): this; + + hooks(hooks: Partial): this; + + setup(server?: any): this; + + service(location: L): Service; + + service(location: string): Service; + + use(path: string, service: Partial & SetupMethod> | Application, options?: any): this; + + version: string; + } }