@carpasse/dapi
Advanced tools
Comparing version 1.1.0-beta.1 to 1.1.0-beta.2
@@ -16,3 +16,3 @@ import { DapiDefinition } from './DapiMixin'; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_1 extends keyof API ? { [key_1 in T_1]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -25,3 +25,3 @@ readonly hooks: keyof API extends infer T_2 extends keyof API ? { [key_2 in T_2]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -46,3 +46,3 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; | ||
}; | ||
} & T> & { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; } & ThisType<InstanceType<{ | ||
} & T> & { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; } & ThisType<InstanceType<{ | ||
new (...args: any[]): { | ||
@@ -52,3 +52,3 @@ readonly __definition: DapiDefinition<DEPENDENCIES, API>; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_3 extends keyof API ? { [key_1 in T_3]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -61,3 +61,3 @@ readonly hooks: keyof API extends infer T_4 extends keyof API ? { [key_2 in T_4]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -86,3 +86,3 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_5 extends keyof API ? { [key_1 in T_5]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -95,3 +95,3 @@ readonly hooks: keyof API extends infer T_6 extends keyof API ? { [key_2 in T_6]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -98,0 +98,0 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; |
@@ -1,2 +0,2 @@ | ||
import { Constructor, ParamsExtract } from './types/utils'; | ||
import { Constructor, ExtractFirstParam } from './types/utils'; | ||
import { DapiFns, DecoratorFn, HookFn } from './types'; | ||
@@ -30,3 +30,3 @@ /** | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T extends keyof DAPI ? { [key_1 in T]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -39,3 +39,3 @@ readonly hooks: keyof DAPI extends infer T_1 extends keyof DAPI ? { [key_2 in T_1]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -141,3 +141,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
}; | ||
} & T> & { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; } & ThisType<InstanceType<{ | ||
} & T> & { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; } & ThisType<InstanceType<{ | ||
new (...args: any[]): { | ||
@@ -147,3 +147,3 @@ readonly __definition: DapiDefinition<DEPENDENCIES, DAPI>; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T extends keyof DAPI ? { [key_1 in T]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -156,3 +156,3 @@ readonly hooks: keyof DAPI extends infer T_1 extends keyof DAPI ? { [key_2 in T_1]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -263,3 +263,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T_2 extends keyof DAPI ? { [key_1 in T_2]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -272,3 +272,3 @@ readonly hooks: keyof DAPI extends infer T_3 extends keyof DAPI ? { [key_2 in T_3]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -379,3 +379,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T_4 extends keyof DAPI ? { [key_1 in T_4]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -388,3 +388,3 @@ readonly hooks: keyof DAPI extends infer T_5 extends keyof DAPI ? { [key_2 in T_5]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -391,0 +391,0 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; |
@@ -50,2 +50,6 @@ /** | ||
/** | ||
* Returns a new Type that extracts from the beginning of a Tuple of type TUPLE all the elements that match the specified type EXTRACTED in the beginning. | ||
*/ | ||
export type ExtractFirstParam<F extends AnyFunction> = Parameters<F> extends [] ? [] : ParamsExtract<F, [Parameters<F>[0]]>; | ||
/** | ||
* Returns a new Type union with all the keys of type T that have values of type V. | ||
@@ -52,0 +56,0 @@ */ |
@@ -16,3 +16,3 @@ import { DapiDefinition } from './DapiMixin'; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_1 extends keyof API ? { [key_1 in T_1]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -25,3 +25,3 @@ readonly hooks: keyof API extends infer T_2 extends keyof API ? { [key_2 in T_2]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -46,3 +46,3 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; | ||
}; | ||
} & T> & { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; } & ThisType<InstanceType<{ | ||
} & T> & { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; } & ThisType<InstanceType<{ | ||
new (...args: any[]): { | ||
@@ -52,3 +52,3 @@ readonly __definition: DapiDefinition<DEPENDENCIES, API>; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_3 extends keyof API ? { [key_1 in T_3]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -61,3 +61,3 @@ readonly hooks: keyof API extends infer T_4 extends keyof API ? { [key_2 in T_4]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -86,3 +86,3 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof API)[]; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
readonly __facade: { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
readonly decorators: keyof API extends infer T_5 extends keyof API ? { [key_1 in T_5]?: import("./types").DecoratorFn<API[key_1], any>[] | undefined; } : never; | ||
@@ -95,3 +95,3 @@ readonly hooks: keyof API extends infer T_6 extends keyof API ? { [key_2 in T_6]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").TupleExtract<Parameters<API[key]>, [DEPENDENCIES]>) => ReturnType<API[key]>; }; | ||
__makeFacade(): { [key in keyof API]: (...args: import("./types/utils").ExtractFirstParam<API[key]>) => ReturnType<API[key]>; }; | ||
__makeDecorable<KEY extends keyof API>(key: KEY): void; | ||
@@ -98,0 +98,0 @@ unmakeDecorable<KEY_1 extends keyof API>(key: KEY_1): void; |
@@ -1,2 +0,2 @@ | ||
import { Constructor, ParamsExtract } from './types/utils'; | ||
import { Constructor, ExtractFirstParam } from './types/utils'; | ||
import { DapiFns, DecoratorFn, HookFn } from './types'; | ||
@@ -30,3 +30,3 @@ /** | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T extends keyof DAPI ? { [key_1 in T]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -39,3 +39,3 @@ readonly hooks: keyof DAPI extends infer T_1 extends keyof DAPI ? { [key_2 in T_1]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -141,3 +141,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
}; | ||
} & T> & { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; } & ThisType<InstanceType<{ | ||
} & T> & { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; } & ThisType<InstanceType<{ | ||
new (...args: any[]): { | ||
@@ -147,3 +147,3 @@ readonly __definition: DapiDefinition<DEPENDENCIES, DAPI>; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T extends keyof DAPI ? { [key_1 in T]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -156,3 +156,3 @@ readonly hooks: keyof DAPI extends infer T_1 extends keyof DAPI ? { [key_2 in T_1]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -263,3 +263,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T_2 extends keyof DAPI ? { [key_1 in T_2]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -272,3 +272,3 @@ readonly hooks: keyof DAPI extends infer T_3 extends keyof DAPI ? { [key_2 in T_3]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -379,3 +379,3 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; | ||
readonly __decoratedFns: (keyof DAPI)[]; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
readonly __facade: { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
readonly decorators: keyof DAPI extends infer T_4 extends keyof DAPI ? { [key_1 in T_4]?: DecoratorFn<DAPI[key_1], any>[] | undefined; } : never; | ||
@@ -388,3 +388,3 @@ readonly hooks: keyof DAPI extends infer T_5 extends keyof DAPI ? { [key_2 in T_5]: { | ||
readonly name: string | undefined; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; }; | ||
__makeFacade(): { [key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; }; | ||
__makeDecorable<KEY extends keyof DAPI>(key: KEY): void; | ||
@@ -391,0 +391,0 @@ unmakeDecorable<KEY_1 extends keyof DAPI>(key: KEY_1): void; |
@@ -50,2 +50,6 @@ /** | ||
/** | ||
* Returns a new Type that extracts from the beginning of a Tuple of type TUPLE all the elements that match the specified type EXTRACTED in the beginning. | ||
*/ | ||
export type ExtractFirstParam<F extends AnyFunction> = Parameters<F> extends [] ? [] : ParamsExtract<F, [Parameters<F>[0]]>; | ||
/** | ||
* Returns a new Type union with all the keys of type T that have values of type V. | ||
@@ -52,0 +56,0 @@ */ |
{ | ||
"name": "@carpasse/dapi", | ||
"version": "1.1.0-beta.1", | ||
"version": "1.1.0-beta.2", | ||
"description": "Simple library to create complex systems out of pure functions", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -400,3 +400,3 @@ # dapi | ||
```Typescript | ||
toJSON(...args: ParamsExtract<JSON['stringify'], [Parameters<JSON['stringify']>[0]]>) | ||
toJSON(...args: ExtractFirstParam<JSON['stringify'], [Parameters<JSON['stringify']>[0]]>) | ||
``` | ||
@@ -403,0 +403,0 @@ |
@@ -13,7 +13,8 @@ /* eslint-disable id-length, max-classes-per-file */ | ||
ParamsExtract, | ||
RemoveNever | ||
RemoveNever, | ||
ExtractFirstParam | ||
} from '../types/utils'; | ||
import {assertType} from '../types/assertType'; | ||
describe('utils', () => { | ||
describe('type utils', () => { | ||
describe('ExtractKeys', () => { | ||
@@ -261,2 +262,28 @@ it('should extract the keys of an object that match the keys of another object', () => { | ||
}); | ||
describe('ExtractFirstParam', () => { | ||
it('should return a new Type that extracts from the beginning of the params tuple those that match EXTRACTED in the beginning', () => { | ||
const fn = (a: number, b: string, c: boolean) => {}; | ||
type fnType = typeof fn; | ||
assertType<ExtractFirstParam<fnType>>(['b', true]); | ||
}); | ||
it('should work with functions of only one param', () => { | ||
const fn = (a: number) => {}; | ||
type fnType = typeof fn; | ||
assertType<ExtractFirstParam<fnType>>([]); | ||
}); | ||
it('should work with functions of 0 params', () => { | ||
const fn = () => {}; | ||
type fnType = typeof fn; | ||
assertType<ExtractFirstParam<fnType>>([]); | ||
}); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import {Constructor, ParamsExtract} from './types/utils'; | ||
import {Constructor, ExtractFirstParam} from './types/utils'; | ||
import {DapiFns, DecoratorFn, HookFn} from './types'; | ||
@@ -55,3 +55,3 @@ | ||
type Facade = { | ||
[key in keyof DAPI]: (...args: ParamsExtract<DAPI[key], [DEPENDENCIES]>) => ReturnType<DAPI[key]>; | ||
[key in keyof DAPI]: (...args: ExtractFirstParam<DAPI[key]>) => ReturnType<DAPI[key]>; | ||
}; | ||
@@ -94,3 +94,3 @@ | ||
// @ts-expect-error - tried to define an index signature but it didn't work | ||
this[key] = (...params: ParamsExtract<DAPI[typeof key], [DEPENDENCIES]>) => { | ||
this[key] = (...params: ExtractFirstParam<DAPI[typeof key], [DEPENDENCIES]>) => { | ||
return this.__facade[key](...params); | ||
@@ -107,3 +107,3 @@ }; | ||
facade[key] = (...params: ParamsExtract<DAPI[typeof key], [DEPENDENCIES]>) => { | ||
facade[key] = (...params: ExtractFirstParam<DAPI[typeof key]>) => { | ||
return command.call(this, this.__deps, ...params); | ||
@@ -123,3 +123,3 @@ }; | ||
this.__facade[key] = (...params: ParamsExtract<DAPI[typeof key], [DEPENDENCIES]>) => { | ||
this.__facade[key] = (...params: ExtractFirstParam<DAPI[typeof key]>) => { | ||
const decoratorFns = this.decorators[key]; | ||
@@ -160,3 +160,3 @@ const decorators = [...(decoratorFns ?? [])]; | ||
this.__facade[key] = (...params: ParamsExtract<DAPI[typeof key], [DEPENDENCIES]>) => { | ||
this.__facade[key] = (...params: ExtractFirstParam<DAPI[typeof key]>) => { | ||
return command.call(this, this.__deps, ...params); | ||
@@ -219,3 +219,3 @@ }; | ||
*/ | ||
toJSON(...args: ParamsExtract<JSON['stringify'], [Parameters<JSON['stringify']>[0]]>) { | ||
toJSON(...args: ExtractFirstParam<JSON['stringify']>) { | ||
return JSON.stringify(this.__definition, ...args); | ||
@@ -222,0 +222,0 @@ } |
@@ -83,2 +83,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
>; | ||
/** | ||
* Returns a new Type that extracts from the beginning of a Tuple of type TUPLE all the elements that match the specified type EXTRACTED in the beginning. | ||
*/ | ||
export type ExtractFirstParam<F extends AnyFunction> = Parameters<F> extends [] | ||
? [] | ||
: ParamsExtract<F, [Parameters<F>[0]]>; | ||
@@ -85,0 +91,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207324
3455