@ada-anvil/sdk-core
Table of contents
Classes
Type Aliases
- AnyFunction
- BindingScope
- CompilableClassType
- Constructor
- DefaultCorePlugins
- EnhanceFn
- Enhancers
- Getters
- Plugin
- RestrictedTokens
- Sdk
- SdkContainer
- SdkGetters
- ServiceAccess
- ServiceDefinition
- ServiceDefinitions
- ServiceReturnType
- Tokens
- inferSdkInputs
- inferSdkOutputs
Variables
Functions
Type Aliases
AnyFunction
Ƭ AnyFunction<T>: (...args: any[]) => T
Type parameters
| Name | Type |
|---|---|
T | any |
Type declaration
▸ (...args): T
Parameters
| Name | Type |
|---|---|
...args | any[] |
Returns
T
BindingScope
Ƭ BindingScope: "singleton" | "container" | "transient" | "resolution"
CompilableClassType
Ƭ CompilableClassType<C>: Omit<C, never>
This fixes a TS limitation which prevents the use of private attributes in classes that need to be compiled.
See
https://stackoverflow.com/a/74491860
Type parameters
| Name |
|---|
C |
Constructor
Ƭ Constructor<T>: (...args: any[]) => T
Type parameters
| Name | Type |
|---|---|
T | any |
Type declaration
• (...args)
Parameters
| Name | Type |
|---|---|
...args | any[] |
DefaultCorePlugins
Ƭ DefaultCorePlugins: [...typeof defaultCorePlugins]
EnhanceFn
Ƭ EnhanceFn<P, G, E>: <Name, R>(enhancerFn: (getters: G) => { name: Name ; result: R }) => G & { enhance: EnhanceFn<P, G, Enhancers<E, { [K in Name]: R }>> ; enhancers: Enhancers<E, { [K in Name]: R }> }
Type parameters
| Name | Type |
|---|---|
P | extends readonly Plugin[] |
G | extends SdkGetters<P> |
E | E |
Type declaration
▸ <Name, R>(enhancerFn): G & { enhance: EnhanceFn<P, G, Enhancers<E, { [K in Name]: R }>> ; enhancers: Enhancers<E, { [K in Name]: R }> }
Type parameters
| Name | Type |
|---|---|
Name | extends string |
R | R |
Parameters
| Name | Type |
|---|---|
enhancerFn | (getters: G) => { name: Name ; result: R } |
Returns
G & { enhance: EnhanceFn<P, G, Enhancers<E, { [K in Name]: R }>> ; enhancers: Enhancers<E, { [K in Name]: R }> }
Enhancers
Ƭ Enhancers<Prev, New>: Prev extends undefined ? New : Omit<Prev, keyof New> & New
Type parameters
| Name |
|---|
Prev |
New |
Getters
Ƭ Getters<T>: { [K in keyof T]: TokenType<T[K]> }
Type parameters
| Name | Type |
|---|---|
T | extends Record<string, Token> = Record<string, Token> |
Plugin
Ƭ Plugin<Name, Flat, SD>: Object
Type parameters
| Name | Type |
|---|---|
Name | extends string = string |
Flat | extends boolean = boolean |
SD | extends ServiceDefinitions = Record<string, any> |
Type declaration
| Name | Type | Description |
|---|---|---|
flat | Flat | If true, the plugin's services will be available as direct properties of the SDK instance. Otherwise, they will be wrapped in a property named after the plugin. Default ts false Example ts // For example, if the plugin is named `core`: // If `flat` is `true`: sdk.api sdk.auth // If `flat` is `false`: sdk.core.api sdk.core.auth |
module | DependencyModule | The DependencyModule that contains the plugin's bindings. |
name | Name | The name of the plugin. |
tokens | Tokens<SD> | The pointer tokens for the plugin's services. |
RestrictedTokens
Ƭ RestrictedTokens<SD, Access>: { [Key in keyof SD as SD[Key]["access"] extends Access ? Key : never]: Token<ServiceReturnType<SD[Key]["service"]>> }
Type parameters
| Name | Type |
|---|---|
SD | extends ServiceDefinitions = Record<string, any> |
Access | extends ServiceAccess = "public" | "private" |
Sdk
Ƭ Sdk<P, ReturnContainer>: IsDuplicateFree<P> extends true ? SdkGetters<P> & { enhance: EnhanceFn<P, SdkGetters<P>, unknown> } & SdkContainer<ReturnContainer> : typeof DUPLICATE_PLUGINS_ERROR
Type parameters
| Name | Type |
|---|---|
P | extends readonly Plugin[] |
ReturnContainer | extends boolean = boolean |
SdkContainer
Ƭ SdkContainer<ReturnContainer>: ReturnContainer extends true ? { container: Container } : {}
Type parameters
| Name | Type |
|---|---|
ReturnContainer | extends boolean = boolean |
SdkGetters
Ƭ SdkGetters<P, Acc>: P extends [infer Head, ...(infer Rest)] ? Head extends Plugin ? Rest extends readonly Plugin[] ? SdkGetters<Rest, Acc extends Record<string, never> ? PluginGetters<Head> : Acc & PluginGetters<Head>> : Acc : Acc : Acc
Type parameters
| Name | Type |
|---|---|
P | extends readonly Plugin[] |
Acc | extends Record<string, Record<string, Token> | Token> = Record<string, never> |
ServiceAccess
Ƭ ServiceAccess: "public" | "private"
ServiceDefinition
Ƭ ServiceDefinition: Object
Type declaration
| Name | Type | Description |
|---|---|---|
access | ServiceAccess | The access type of the service's binding. If public, the service will be available to the user the SDK instance. If private, the service will only be available to other services in the SDK. |
scope | BindingScope | The scope of the service's binding. See https://brandi.js.org/reference/binding-scopes |
service | Constructor | AnyFunction | The service to bind. It can be a class or a function. |
ServiceDefinitions
Ƭ ServiceDefinitions: Object
Index signature
▪ [k: string]: ServiceDefinition
ServiceReturnType
Ƭ ServiceReturnType<T>: T extends Constructor<infer R> ? R : T extends AnyFunction<infer R> ? R : never
Type parameters
| Name |
|---|
T |
Tokens
Ƭ Tokens<SD>: Object
Type parameters
| Name | Type |
|---|---|
SD | extends ServiceDefinitions |
Type declaration
| Name | Type |
|---|---|
all | RestrictedTokens<SD, "public" | "private"> |
private | RestrictedTokens<SD, "private"> |
public | RestrictedTokens<SD, "public"> |
inferSdkInputs
Ƭ inferSdkInputs<S>: S extends Sdk<infer P> ? RecursivePluginInputsOrOutputs<"inputs", P> : never
Type parameters
| Name |
|---|
S |
inferSdkOutputs
Ƭ inferSdkOutputs<S>: S extends Sdk<infer P> ? RecursivePluginInputsOrOutputs<"outputs", P> : never
Type parameters
| Name |
|---|
S |
Variables
corePlugin
• Const corePlugin: Plugin<"core", true, { debug: { access: "public" = "public"; scope: "container" = "container"; service: typeof DebugService = DebugService } }>
defaultCorePlugins
• Const defaultCorePlugins: readonly [Plugin<"core", true, { debug: { access: "public" = "public"; scope: "container" = "container"; service: typeof DebugService = DebugService } }>]
Functions
createPlugin
▸ createPlugin<Name, SD>(definition): Plugin<Name, true, { [N in Name]: SD }>
Creates pointer tokens for the given service or services and binds them to a DependencyModule following the given scope and access type.
Example
// Create a plugin with a single service:
const apiPlugin = createPlugin({
name: "api",
service: { service: ApiService, scope: "container", access: "private" },
});
// Create a plugin with multiple services:
const apiPlugin = createPlugin({
name: "core",
services: {
api: { service: ApiService, scope: "container", access: "private" },
},
});
Type parameters
| Name | Type |
|---|---|
Name | extends string |
SD | extends ServiceDefinition |
Parameters
| Name | Type |
|---|---|
definition | Object |
definition.name | Name |
definition.service | SD |
Returns
Plugin<Name, true, { [N in Name]: SD }>
▸ createPlugin<Name, SDs, Flat>(definition): Plugin<Name, Flat, SDs>
Type parameters
| Name | Type |
|---|---|
Name | extends string |
SDs | extends ServiceDefinitions |
Flat | extends boolean = boolean |
Parameters
| Name | Type | Description |
|---|---|---|
definition | Object | - |
definition.flat? | Flat | If true, the plugin's services will be available as direct properties of the SDK instance. Otherwise, they will be wrapped in a property named after the plugin. Default ts false Example ts // For example, if the plugin is named `core`: // If `flat` is `true`: sdk.api sdk.auth // If `flat` is `false`: sdk.core.api sdk.core.auth |
definition.name | Name | - |
definition.services | SDs | - |
Returns
Plugin<Name, Flat, SDs>
createSdk
▸ createSdk<P, ReturnContainer>(opts?): Sdk<[...DefaultCorePlugins, ...P], ReturnContainer>
Creates a new SDK instance.
Example
const sdk = createSdk({
plugins: [plugin1, plugin2],
returnContainer: true,
});
Type parameters
| Name | Type |
|---|---|
P | extends readonly Plugin<string, boolean, Record<string, any>>[] |
ReturnContainer | extends boolean = boolean |
Parameters
| Name | Type | Description |
|---|---|---|
opts | Object | |
opts.plugins? | [...{ [K in string | number | symbol]: P[K] }[]] | [] | List of plugins to use Default ts [] |
opts.returnContainer? | ReturnContainer | If true, the container will be returned as part of the SDK instance It is recommended to leave this as false, unless you need to access the container directly (e.g. for testing) Default ts false |
Returns
Sdk<[...DefaultCorePlugins, ...P], ReturnContainer>
SDK instance
injected
▸ injected<T>(target, ...tokens): T
Description
Registers target injections.
Link
https://brandi.js.org/reference/pointers-and-registrators#injectedtarget-tokens
Type parameters
| Name | Type |
|---|---|
T | extends UnknownCreator<unknown> |
Parameters
| Name | Type | Description |
|---|---|---|
target | T | constructor or function whose dependencies will be injected. |
...tokens | ToTokens<UnknownCreatorParameters<T>> extends TokenValue<unknown>[] ? ToTokens<UnknownCreatorParameters<T>> : never | - |
Returns
T
the target first argument.
unflatten
▸ unflatten<Name, SDs>(plugin): Plugin<Name, false, SDs>
Type parameters
| Name | Type |
|---|---|
Name | extends string |
SDs | extends ServiceDefinitions |
Parameters
| Name | Type |
|---|---|
plugin | Plugin<Name, true, SDs> |
Returns
Plugin<Name, false, SDs>