@universal-packages/dynamic-api
Advanced tools
Comparing version 1.1.0 to 1.2.0
import { DynamicApiOptions, Dynamics } from './DynamicApi.types'; | ||
export default class DynamicApi { | ||
export default class DynamicApi<D extends Record<string, any>> { | ||
readonly options: DynamicApiOptions; | ||
@@ -7,7 +7,7 @@ readonly dynamics: Dynamics; | ||
loadDynamics(): Promise<void>; | ||
performDynamic(name: string, payload?: Record<string, any>): Promise<any>; | ||
performDynamic<N extends keyof D>(name: N, payload?: D[N]['payload']): Promise<D[N]['result']>; | ||
private perform; | ||
performDynamicSync(name: string, payload?: Record<string, any>): any; | ||
performDynamicSync<N extends keyof D>(name: N, payload?: D[N]['payload']): D[N]['result']; | ||
private performSync; | ||
private getDynamicRegistry; | ||
} |
@@ -19,3 +19,3 @@ import DynamicApi from './DynamicApi'; | ||
export interface DynamicLike { | ||
perform: (payload?: Record<string, any>, forHookResultOrDynamicApi?: any | DynamicApi, dynamicApi?: DynamicApi) => any | Promise<any>; | ||
perform: (payload?: Record<string, any>, forHookResultOrDynamicApi?: any | DynamicApi<any>, dynamicApi?: DynamicApi<any>) => any | Promise<any>; | ||
} | ||
@@ -22,0 +22,0 @@ export interface DynamicClassLike { |
{ | ||
"name": "@universal-packages/dynamic-api", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Dynamic decoupling-adapting system", | ||
@@ -5,0 +5,0 @@ "author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)", |
@@ -168,2 +168,20 @@ # Dynamic API | ||
### Typing dynamics | ||
Since all here is dynamic `performDynamic` takes generic payloads and return generic results, if you want to type your dynamics you can always create an interface typing the payload and the result of your dynamics. | ||
```ts | ||
interface DynamicNames { | ||
calculate: { | ||
payload: { fast: boolean } | ||
result: string | ||
} | ||
} | ||
const dynamicApi = new DynamicApi<DynamicNames>({ dynamicsLocation: './src' }) | ||
// Now result is string type and performDynamic will require a payload of the specific shape | ||
const result = dynamicApi.performDynamic('calculate', { fast: true }) | ||
``` | ||
## Contributing | ||
@@ -170,0 +188,0 @@ |
Sorry, the diff of this file is not supported yet
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
25613
196