From 9dec8df9643274f62cf4369978edd5bdd229145a Mon Sep 17 00:00:00 2001 From: Jan Lohage Date: Thu, 25 Jan 2018 22:41:41 +0100 Subject: [PATCH] fix(@feathersjs/various): proper module augmentation, add reexports (#23195) * fix feathersjs__{authentication-client,express,socket-commons} * fix feathersjs__authentication-client --- ...feathersjs__authentication-client-tests.ts | 11 +++++-- .../feathersjs__feathers.d.ts | 14 -------- .../index.d.ts | 12 +++++-- .../feathersjs__express-tests.ts | 9 ++++-- types/feathersjs__express/index.d.ts | 16 ++++++++-- .../feathersjs__socket-commons/feathers.d.ts | 18 ----------- .../feathersjs__socket-commons-tests.ts | 10 +++++- types/feathersjs__socket-commons/index.d.ts | 32 +++++++++++++++++-- .../socket-commons.d.ts | 13 -------- 9 files changed, 78 insertions(+), 57 deletions(-) delete mode 100644 types/feathersjs__authentication-client/feathersjs__feathers.d.ts delete mode 100644 types/feathersjs__socket-commons/feathers.d.ts delete mode 100644 types/feathersjs__socket-commons/socket-commons.d.ts diff --git a/types/feathersjs__authentication-client/feathersjs__authentication-client-tests.ts b/types/feathersjs__authentication-client/feathersjs__authentication-client-tests.ts index 3d4eb36362..2a4ea96f91 100644 --- a/types/feathersjs__authentication-client/feathersjs__authentication-client-tests.ts +++ b/types/feathersjs__authentication-client/feathersjs__authentication-client-tests.ts @@ -1,4 +1,11 @@ +import feathers from '@feathersjs/feathers'; import feathersAuthClient from '@feathersjs/authentication-client'; -// we can't really do much, because the augmentation of @feathersjs/feathers breaks importing it here. -const configureFn = feathersAuthClient({}); +const app = feathers(); +app.configure(feathersAuthClient()); +app.authenticate({strategy : 'abcdef'}).then(() => {}); +app.logout().then(() => {}); + +// check if the non-augmented @feathersjs/feathers typings still work +app.on('asd', () => {}); +app.service('asd').get(0).then(() => {}); diff --git a/types/feathersjs__authentication-client/feathersjs__feathers.d.ts b/types/feathersjs__authentication-client/feathersjs__feathers.d.ts deleted file mode 100644 index 9c0fa2e05e..0000000000 --- a/types/feathersjs__authentication-client/feathersjs__feathers.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare module '@feathersjs/feathers' { - import { - FeathersAuthCredentials, - Passport - } from '@feathersjs/authentication-client'; - - interface Application { - authenticate(options?: FeathersAuthCredentials): Promise; - - logout(): Promise; - - passport: Passport; - } -} diff --git a/types/feathersjs__authentication-client/index.d.ts b/types/feathersjs__authentication-client/index.d.ts index a29039aab9..16f4f4a415 100644 --- a/types/feathersjs__authentication-client/index.d.ts +++ b/types/feathersjs__authentication-client/index.d.ts @@ -3,8 +3,6 @@ // Definitions by: Abraao Alves , Jan Lohage // Definitions: https://github.com/feathersjs-ecosystem/feathers-typescript -import './feathersjs__feathers'; - export default function feathersAuthClient(config?: FeathersAuthClientConfig): () => void; export interface FeathersAuthClientConfig { @@ -62,3 +60,13 @@ export interface Passport { getStorage(storage: any): any; } + +declare module '@feathersjs/feathers' { + interface Application { + authenticate(options?: FeathersAuthCredentials): Promise; + + logout(): Promise; + + passport: Passport; + } +} diff --git a/types/feathersjs__express/feathersjs__express-tests.ts b/types/feathersjs__express/feathersjs__express-tests.ts index d7f981eaa0..687191d0c6 100644 --- a/types/feathersjs__express/feathersjs__express-tests.ts +++ b/types/feathersjs__express/feathersjs__express-tests.ts @@ -1,5 +1,8 @@ import feathers, { Application } from '@feathersjs/feathers'; -import feathersExpress from '@feathersjs/express'; -import { Application as ExpressApplication } from 'express'; +import feathersExpress, { original, rest, notFound, errorHandler } from '@feathersjs/express'; -const app: ExpressApplication & Application<{}> = feathersExpress(feathers()); +const app = feathersExpress(feathers()); + +app.configure(rest()); +app.use(notFound()); +app.use(errorHandler()); diff --git a/types/feathersjs__express/index.d.ts b/types/feathersjs__express/index.d.ts index 2bce8b54dd..26e58ae565 100644 --- a/types/feathersjs__express/index.d.ts +++ b/types/feathersjs__express/index.d.ts @@ -5,6 +5,18 @@ // TypeScript Version: 2.2 import { Application as FeathersApplication } from '@feathersjs/feathers'; -import { Application as ExpressApplication } from 'express'; +import * as express from 'express'; -export default function feathersExpress(app: FeathersApplication): ExpressApplication & FeathersApplication; +export default function feathersExpress(app: FeathersApplication): express.Application & FeathersApplication; + +export function errorHandler(options?: any): express.ErrorRequestHandler; +export function notFound(): express.RequestHandler; +export const rest: { + (): () => void; + formatter: express.RequestHandler; +}; + +/* + * Re-export of the express package. Can't be typed properly without just copying everything. + **/ +export const original: any; diff --git a/types/feathersjs__socket-commons/feathers.d.ts b/types/feathersjs__socket-commons/feathers.d.ts deleted file mode 100644 index 08438e4899..0000000000 --- a/types/feathersjs__socket-commons/feathers.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -declare module '@feathersjs/feathers' { - import { Channel } from '@feathersjs/socket-commons'; - import { HookContext } from '@feathersjs/feathers'; - - export interface ServiceAddons { - publish(callback: (data: T, hook: HookContext) => Channel): this - - publish(event: string, callback: (data: T, hook: HookContext) => Channel): this - } - - export interface Application { - channel(...names: string[]): Channel; - - publish(callback: (data: T, hook: HookContext) => Channel | Channel[]): Application; - - publish(event: string, callback: (data: T, hook: HookContext) => Channel | Channel[]): Application; - } -} diff --git a/types/feathersjs__socket-commons/feathersjs__socket-commons-tests.ts b/types/feathersjs__socket-commons/feathersjs__socket-commons-tests.ts index 2b7e49481e..e52fa00d78 100644 --- a/types/feathersjs__socket-commons/feathersjs__socket-commons-tests.ts +++ b/types/feathersjs__socket-commons/feathersjs__socket-commons-tests.ts @@ -1 +1,9 @@ -const dummy: any = null; +import feathers from '@feathersjs/feathers'; + +const app = feathers(); + +app.channel('abc').send({}); + +// check if the non-augmented @feathersjs/feathers typings still work +app.on('asd', () => {}); +app.service('asd').get(0).then(() => {}); diff --git a/types/feathersjs__socket-commons/index.d.ts b/types/feathersjs__socket-commons/index.d.ts index 38d46a0ec5..fca658bf76 100644 --- a/types/feathersjs__socket-commons/index.d.ts +++ b/types/feathersjs__socket-commons/index.d.ts @@ -2,6 +2,34 @@ // Project: http://feathersjs.com/ // Definitions by: Jan Lohage // Definitions: https://github.com/feathersjs-ecosystem/feathers-typescript +// TypeScript Version: 2.3 -import './socket-commons'; -import './feathers'; +import { HookContext } from '@feathersjs/feathers'; + +export type Connection = any; // todo: spec connection + +export interface Channel { + join(...connections: Connection[]): this; + + leave(...connections: Connection[]): this; + + filter(callback: (connection: Connection) => boolean): Channel; + + send(data: any): this; +} + +declare module '@feathersjs/feathers' { + interface ServiceAddons { + publish(callback: (data: T, hook: HookContext) => Channel): this; + + publish(event: string, callback: (data: T, hook: HookContext) => Channel): this; + } + + interface Application { + channel(...names: string[]): Channel; + + publish(callback: (data: T, hook: HookContext) => Channel | Channel[]): Application; + + publish(event: string, callback: (data: T, hook: HookContext) => Channel | Channel[]): Application; + } +} diff --git a/types/feathersjs__socket-commons/socket-commons.d.ts b/types/feathersjs__socket-commons/socket-commons.d.ts deleted file mode 100644 index 2f32f24bd4..0000000000 --- a/types/feathersjs__socket-commons/socket-commons.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -declare module '@feathersjs/socket-commons' { - export type Connection = any; // todo: spec connection - - export interface Channel { - join(...connections: Connection[]): this; - - leave(...connections: Connection[]): this; - - filter(callback: (connection: Connection) => boolean): Channel; - - send(data: any): this; - } -}