Skip to main content

@ada-anvil/sdk-core

Table of contents

Classes

Type Aliases

Variables

Functions

Type Aliases

AnyFunction

Ƭ AnyFunction<T>: (...args: any[]) => T

Type parameters

NameType
Tany

Type declaration

▸ (...args): T

Parameters
NameType
...argsany[]
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

NameType
Tany

Type declaration

• (...args)

Parameters
NameType
...argsany[]

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

NameType
Pextends readonly Plugin[]
Gextends SdkGetters<P>
EE

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
NameType
Nameextends string
RR
Parameters
NameType
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

NameType
Textends Record<string, Token> = Record<string, Token>

Plugin

Ƭ Plugin<Name, Flat, SD>: Object

Type parameters

NameType
Nameextends string = string
Flatextends boolean = boolean
SDextends ServiceDefinitions = Record<string, any>

Type declaration

NameTypeDescription
flatFlatIf 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
moduleDependencyModuleThe DependencyModule that contains the plugin's bindings.
nameNameThe name of the plugin.
tokensTokens<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

NameType
SDextends ServiceDefinitions = Record<string, any>
Accessextends 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

NameType
Pextends readonly Plugin[]
ReturnContainerextends boolean = boolean

SdkContainer

Ƭ SdkContainer<ReturnContainer>: ReturnContainer extends true ? { container: Container } : {}

Type parameters

NameType
ReturnContainerextends 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

NameType
Pextends readonly Plugin[]
Accextends Record<string, Record<string, Token> | Token> = Record<string, never>

ServiceAccess

Ƭ ServiceAccess: "public" | "private"


ServiceDefinition

Ƭ ServiceDefinition: Object

Type declaration

NameTypeDescription
accessServiceAccessThe 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.
scopeBindingScopeThe scope of the service's binding. See https://brandi.js.org/reference/binding-scopes
serviceConstructor | AnyFunctionThe 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

NameType
SDextends ServiceDefinitions

Type declaration

NameType
allRestrictedTokens<SD, "public" | "private">
privateRestrictedTokens<SD, "private">
publicRestrictedTokens<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

NameType
Nameextends string
SDextends ServiceDefinition

Parameters

NameType
definitionObject
definition.nameName
definition.serviceSD

Returns

Plugin<Name, true, { [N in Name]: SD }>

createPlugin<Name, SDs, Flat>(definition): Plugin<Name, Flat, SDs>

Type parameters

NameType
Nameextends string
SDsextends ServiceDefinitions
Flatextends boolean = boolean

Parameters

NameTypeDescription
definitionObject-
definition.flat?FlatIf 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.nameName-
definition.servicesSDs-

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

NameType
Pextends readonly Plugin<string, boolean, Record<string, any>>[]
ReturnContainerextends boolean = boolean

Parameters

NameTypeDescription
optsObject
opts.plugins?[...{ [K in string | number | symbol]: P[K] }[]] | []List of plugins to use Default ts []
opts.returnContainer?ReturnContainerIf 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

NameType
Textends UnknownCreator<unknown>

Parameters

NameTypeDescription
targetTconstructor or function whose dependencies will be injected.
...tokensToTokens<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

NameType
Nameextends string
SDsextends ServiceDefinitions

Parameters

NameType
pluginPlugin<Name, true, SDs>

Returns

Plugin<Name, false, SDs>