UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

102 lines (101 loc) • 4.78 kB
import { Constructor } from "../utils/mixins.mjs"; import { CacheModule } from "../modules/cache/CacheModule.mjs"; import "../modules/cache/index.mjs"; import { DcqlModule } from "../modules/dcql/DcqlModule.mjs"; import "../types.mjs"; import { DifPresentationExchangeModule } from "../modules/dif-presentation-exchange/DifPresentationExchangeModule.mjs"; import { SdJwtVcModule } from "../modules/sd-jwt-vc/SdJwtVcModule.mjs"; import "../modules/sd-jwt-vc/index.mjs"; import { MdocModule } from "../modules/mdoc/MdocModule.mjs"; import "../modules/dif-presentation-exchange/index.mjs"; import { W3cCredentialsModule } from "../modules/vc/W3cCredentialsModule.mjs"; import "../modules/vc/index.mjs"; import { X509Module } from "../modules/x509/X509Module.mjs"; import "../modules/x509/index.mjs"; import { KeyManagementModule } from "../modules/kms/KeyManagementModule.mjs"; import "../modules/kms/index.mjs"; import { DidsModule } from "../modules/dids/DidsModule.mjs"; import "../modules/dids/index.mjs"; import { GenericRecordsModule } from "../modules/generic-records/GenericRecordsModule.mjs"; import "../modules/generic-records/index.mjs"; import { Module } from "../plugins/Module.mjs"; import "../plugins/index.mjs"; //#region src/agent/AgentModules.d.ts /** * Simple utility type that represent a map of modules. This is used to map from moduleKey (api key) to the api in the framework. */ type ModulesMap = { [key: string]: Module; }; type EmptyModuleMap = {}; /** * Default modules can be optionally defined to provide custom configuration. This type makes it so that it is not * possible to use a different key for the default modules */ type AgentModulesInput = ModulesMap; /** * Type that represents the default agent modules. This is the {@link ModulesMap} variant for the default modules in the framework. * It uses the return type of the {@link getDefaultAgentModules} method to automatically infer which modules are always available on * the agent and in the agent. namespace. */ type DefaultAgentModules = { [moduleKey in keyof ReturnType<typeof getDefaultAgentModules>]: ReturnType<ReturnType<typeof getDefaultAgentModules>[moduleKey]> }; type WithoutDefaultModules<Modules extends ModulesMap> = { [moduleKey in Exclude<keyof Modules, keyof DefaultAgentModules>]: Modules[moduleKey] }; type ModuleApiInstance<M extends Module> = M['api'] extends Constructor<unknown> ? InstanceType<M['api']> : undefined; /** * Type that represents the api object of the agent (`agent.xxx`). It will extract all keys of the modules and map this to the * registered {@link Module.api} class instance. If the module does not have an api class registered, the property will be removed * and won't be available on the api object. * * @example * If the following AgentModules type was passed: * ```ts * { * connections: DidCommConnectionsModule * indy: IndyModule * } * ``` * * And we use the `AgentApi` type like this: * ```ts * type MyAgentApi = AgentApi<{ * connections: DidCommConnectionsModule * indy: IndyModule * }> * ``` * * the resulting agent api will look like: * * ```ts * { * connections: ConnectionsApi * } * ``` * * The `indy` module has been ignored because it doesn't define an api class. */ type AgentApi<Modules extends ModulesMap> = { [moduleKey in keyof Modules as Modules[moduleKey]['api'] extends Constructor<unknown> ? moduleKey : never]: ModuleApiInstance<Modules[moduleKey]> }; /** * Method to get the default agent modules to be registered on any agent instance. It doens't configure the modules in any way, * and if that's needed the user needs to provide the module in the agent constructor */ declare function getDefaultAgentModules(): { readonly dcql: () => DcqlModule; readonly genericRecords: () => GenericRecordsModule; readonly dids: () => DidsModule; readonly w3cCredentials: () => W3cCredentialsModule; readonly cache: () => CacheModule; readonly pex: () => DifPresentationExchangeModule; readonly sdJwtVc: () => SdJwtVcModule; readonly x509: () => X509Module; readonly mdoc: () => MdocModule; readonly kms: () => KeyManagementModule; }; /** * Extend the provided modules object with the default agent modules. If the modules property already contains a module with the same * name as a default module, the module won't be added to the extended module object. This allows users of the framework to override * the modules with custom configuration. The agent constructor type ensures you can't provide a different module for a key that registered * on the default agent. */ //#endregion export { AgentApi, AgentModulesInput, DefaultAgentModules, EmptyModuleMap, ModuleApiInstance, ModulesMap, WithoutDefaultModules }; //# sourceMappingURL=AgentModules.d.mts.map