@sphereon/ssi-sdk.agent-config 0.34.1-next.6 → 0.34.1-next.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/dataSources.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -172,7 +172,7 @@ var DataSources = class _DataSources {
|
|
|
172
172
|
...this.configs.keys()
|
|
173
173
|
];
|
|
174
174
|
}
|
|
175
|
-
async getDbConnection(dbName) {
|
|
175
|
+
async getDbConnection(dbName, allowAutomaticMigrations = true) {
|
|
176
176
|
const config = this.getConfig(dbName);
|
|
177
177
|
if (!this._defaultDbType) {
|
|
178
178
|
this._defaultDbType = config.type;
|
|
@@ -190,7 +190,7 @@ var DataSources = class _DataSources {
|
|
|
190
190
|
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
191
191
|
} else if (config.migrationsRun) {
|
|
192
192
|
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
193
|
-
} else {
|
|
193
|
+
} else if (allowAutomaticMigrations) {
|
|
194
194
|
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
195
195
|
await dataSource.runMigrations();
|
|
196
196
|
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/agentContextUtils.ts","../src/dataSources.ts","../src/agentCreator.ts","../src/objectCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './agentContextUtils'\nexport * from './dataSources'\nexport * from './agentCreator'\nexport * from './objectCreator'\nexport * from './generic'\nexport * from './typeormTypes'\n","import type {\n IAgentContext,\n ICredentialVerifier,\n IDataStore,\n IDataStoreORM,\n IDIDManager,\n IKeyManager,\n IPluginMethodMap,\n IResolver,\n ICredentialIssuer,\n ICredentialStatusVerifier,\n} from '@veramo/core'\n\n/**\n * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)\n * @param context Tje agent context to check against\n * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence\n */\nexport function contextHasPlugin<Plugins extends IPluginMethodMap>(\n context: IAgentContext<any>,\n requiredMethod: string | string[],\n): context is IAgentContext<Plugins> {\n const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod]\n const allMethods = context.agent.availableMethods()\n return methods.every((method) => allMethods.includes(method))\n}\n\n/**\n * The below methods are convenience methods to directly get the appropriate context after calling the respective method\n *\n * @param context\n */\n\nexport function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager> {\n return contextHasPlugin(context, 'keyManagerGet')\n}\n\nexport function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager> {\n return contextHasPlugin(context, 'didManagerGet') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver> {\n return contextHasPlugin(context, 'resolveDid') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer> {\n return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']) // W3C Credential issuer\n}\n\nexport function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier> {\n return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']) // W3c Credential Verifier\n}\n\nexport function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier> {\n return contextHasPlugin(context, ['checkCredentialStatus']) // W3c Credential status Verifier\n}\n\nexport function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore> {\n return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation'])\n}\n\nexport function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM> {\n return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations'])\n}\n","import Debug from 'debug'\nimport { DataSource } from 'typeorm/data-source/DataSource.js'\nimport type { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport type { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js'\n\nconst debug = Debug(`sphereon:ssi-sdk:database`)\n\nexport class DataSources {\n get defaultDbType(): SupportedDatabaseType {\n return this._defaultDbType\n }\n\n set defaultDbType(value: SupportedDatabaseType) {\n this._defaultDbType = value\n }\n private dataSources = new Map<string, DataSource>()\n private configs = new Map<string, DataSourceOptions>()\n private _defaultDbType: SupportedDatabaseType = 'sqlite'\n\n private static singleton: DataSources\n\n public static singleInstance() {\n if (!DataSources.singleton) {\n DataSources.singleton = new DataSources()\n }\n return DataSources.singleton\n }\n\n public static newInstance(configs?: Map<string, DataSourceOptions>) {\n return new DataSources(configs)\n }\n\n private constructor(configs?: Map<string, DataSourceOptions>) {\n ;(configs ?? new Map<string, DataSourceOptions>()).forEach((config, name) => this.addConfig(name, config))\n }\n\n addConfig(dbName: string, config: DataSourceOptions): this {\n this.configs.set(dbName, config)\n // yes we are aware last one wins\n this._defaultDbType = config.type as SupportedDatabaseType\n return this\n }\n\n deleteConfig(dbName: string): this {\n this.configs.delete(dbName)\n return this\n }\n has(dbName: string) {\n return this.configs.has(dbName) && this.dataSources.has(dbName)\n }\n\n delete(dbName: string): this {\n this.deleteConfig(dbName)\n this.dataSources.delete(dbName)\n return this\n }\n\n getConfig(dbName: string): BaseDataSourceOptions {\n const config = this.configs.get(dbName)\n if (!config) {\n throw Error(`No DB config found for ${dbName}`)\n }\n return config\n }\n\n public getDbNames(): string[] {\n return [...this.configs.keys()]\n }\n\n async getDbConnection(dbName: string): Promise<DataSource> {\n const config = this.getConfig(dbName)\n if (!this._defaultDbType) {\n this._defaultDbType = config.type as SupportedDatabaseType\n }\n /*if (config.synchronize) {\n return Promise.reject(\n `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`\n )\n }*/\n\n let dataSource = this.dataSources.get(dbName)\n if (dataSource) {\n return dataSource\n }\n\n dataSource = await new DataSource({ ...(config as DataSourceOptions), name: dbName }).initialize()\n this.dataSources.set(dbName, dataSource)\n if (config.synchronize) {\n debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`)\n } else if (config.migrationsRun) {\n debug(\n `Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`,\n )\n } else {\n debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)\n await dataSource.runMigrations()\n debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)\n }\n return dataSource\n }\n}\n\nexport type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native'\nexport type DateTimeType = 'timestamp' | 'datetime'\n\nexport type DateType = 'date'\n\n/**\n * Gets the database connection.\n *\n * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time\n *\n * @param connectionName The database name\n * @param opts\n */\nexport const getDbConnection = async (\n connectionName: string,\n opts?: {\n config: BaseDataSourceOptions | any\n },\n): Promise<DataSource> => {\n if (!DataSources.singleInstance().has(connectionName) && opts?.config) {\n DataSources.singleInstance().addConfig(connectionName, opts?.config)\n }\n return DataSources.singleInstance().getDbConnection(connectionName)\n}\n\nexport const dropDatabase = async (dbName: string, opts?: { removeDataSource?: boolean }): Promise<void> => {\n const { removeDataSource = false } = { ...opts }\n if (!DataSources.singleInstance().has(dbName)) {\n return Promise.reject(Error(`No database present with name: ${dbName}`))\n }\n\n const connection: DataSource = await getDbConnection(dbName)\n await connection.dropDatabase()\n if (removeDataSource) {\n DataSources.singleInstance().delete(dbName)\n } else if (!connection.isInitialized) {\n await connection.initialize()\n }\n}\n\n/**\n * Runs a migration down (drops DB schema)\n * @param dataSource\n */\nexport const revertMigration = async (dataSource: DataSource): Promise<void> => {\n if (dataSource.isInitialized) {\n await dataSource.undoLastMigration()\n } else {\n console.error('DataSource is not initialized')\n }\n}\nexport const resetDatabase = async (dbName: string): Promise<void> => {\n await dropDatabase(dbName)\n const connection = await getDbConnection(dbName)\n await connection.runMigrations()\n}\n","import { type TAgent, type IPluginMethodMap, type IAgentOptions, Agent } from '@veramo/core'\nimport { createObjects } from './objectCreator'\nimport yaml from 'yaml'\n\n/**\n * Creates a Veramo agent from a config object containing an `/agent` pointer.\n * @param config - The configuration object\n *\n * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on\n * the configuration options.\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {\n // @ts-ignore\n const { agent } = await createObjects(config, { agent: '/agent' })\n return agent\n}\n\n/**\n * Helper function to create a new instance of the {@link Agent} class with correct type\n *\n * @remarks\n * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE\n *\n * @example\n * ```typescript\n * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'\n * import { AgentRestClient } from '@veramo/remote-client'\n * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'\n * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({\n * plugins: [\n * new CredentialIssuer(),\n * new AgentRestClient({\n * url: 'http://localhost:3002/agent',\n * enabledMethods: [\n * 'resolveDid',\n * 'handleMessage',\n * ],\n * }),\n * ],\n * })\n * ```\n * @param options - Agent configuration options\n * @returns configured agent\n * @public\n */\nexport async function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(\n options: IAgentOptions & { context?: C },\n): Promise<TAgent<T> & { context?: C }> {\n return new Agent(options) as TAgent<T>\n}\n\n/**\n * Parses a yaml config file and returns a config object\n * @param filePath\n */\nexport const getConfig = async (filePath: string | Buffer | URL): Promise<{ version?: number; [x: string]: any }> => {\n let fileContent: string\n\n // read file async\n try {\n const fs = await import(/* webpackIgnore: true */ 'fs')\n fileContent = await fs.promises.readFile(filePath, 'utf8')\n } catch (e) {\n console.log('Config file not found: ' + filePath)\n console.log('Use \"veramo config create\" to create one')\n process.exit(1)\n }\n\n let config\n\n try {\n config = yaml.parse(fileContent, { prettyErrors: true })\n } catch (e: any) {\n console.error(`Unable to parse config file: ${e.message} ${e.linePos}`)\n process.exit(1)\n }\n\n if (config?.version != 3) {\n console.error('Unsupported configuration file version:', config.version)\n process.exit(1)\n }\n return config\n}\n\nexport async function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>> {\n try {\n return await createAgentFromConfig<T>(await getConfig(fileName))\n } catch (e: any) {\n console.log('Unable to create agent from ' + fileName + '.', e.message)\n process.exit(1)\n }\n}\n","import { set, get } from 'jsonpointer'\nimport parse from 'url-parse'\n\n/**\n * Creates objects from a configuration object and a set of pointers.\n *\n * Example:\n * ```ts\n * const { url } = createObjects({ \"rpcUrl\": \"http://localhost:8545\", }, { url: '/rpcUrl' })\n * ```\n *\n * The config can contain references (`$ref`) to other objects within using JSON pointers.\n * Example:\n * ```json\n * {\n * \"rpcUrl\": \"http://localhost:8545\",\n * \"endpoint\": {\n * \"url\": {\n * \"$ref\": \"/rpcUrl\"\n * }\n * }\n * }\n * ```\n *\n * The config object can also contain references to NPM modules using the `$require` property.\n * Example:\n * ```json\n * {\n * \"agent\": {\n * \"$require\": \"@veramo/core#Agent\",\n * \"$args\": {\n * \"plugins\": [\n * { \"$require\": \"@veramo/did-comm#DIDComm\" },\n * ]\n * }\n * }\n * }\n * ```\n *\n * Environment variables can also be specified using the `$env` property.\n *\n * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for\n * more information.\n *\n * @param config - The configuration object\n * @param pointers - A map of JSON pointers to objects within that config that you wish to create\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>> {\n const objects = {}\n\n async function resolveRefs(input: any): Promise<any> {\n if (Array.isArray(input)) {\n const resolved = []\n for (const item of input) {\n resolved.push(await resolveRefs(item))\n }\n return resolved\n }\n\n if (typeof input === 'object') {\n const resolved: any = {}\n for (const property in input) {\n if (input.hasOwnProperty(property)) {\n if (property === '$ref') {\n const pointer = input[property]\n return await objectFromPointer(pointer)\n } else if (property === '$require') {\n return await objectFromConfig(input)\n } else if (property === '$env') {\n return process.env[input[property]]\n } else {\n resolved[property] = await resolveRefs(input[property])\n }\n }\n }\n return resolved\n }\n\n return input\n }\n\n async function objectFromConfig(objectConfig: any): Promise<any> {\n console.log('Requiring', objectConfig['$require'])\n const parsed = parse(objectConfig['$require'], {}, true)\n let npmModule = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\n console.log(`member: ${member}`)\n const type = parsed.query['t'] || 'class'\n const pointer = parsed.query['p']\n const args = objectConfig['$args']\n console.log({ module, member, type, query: parsed.query, pointer, args })\n\n if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {\n console.log('objectFromConfig: Resolving relative path', npmModule)\n const { resolve } = await import('path')\n npmModule = resolve(npmModule)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n console.error(`npmModule: ${npmModule}`)\n // try {\n return await Promise.resolve(\n await import(/*@metro-ignore*/ npmModule)\n\n .then((mod) => {\n if (member) {\n return mod[member]\n }\n return mod\n })\n .then((required) => {\n let object: any\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n } else {\n console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)\n }\n if (!pointer) {\n return object\n }\n\n if (!object) {\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))\n }\n return get(object, pointer)\n })\n .catch((e) => {\n console.error(e)\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))\n }),\n )\n\n /*let required = member ? (await import(npmModule))[member] : await import(npmModule)\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n }*/\n // } catch (e: any) {\n // console.log(e)\n // throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)\n // }\n\n // return object\n }\n\n async function objectFromPointer(pointer: string) {\n const existingObject = get(objects, pointer)\n if (existingObject) {\n // console.log('Existing', pointer)\n return existingObject\n } else {\n // console.log('New', pointer)\n const objectConfig = get(config, pointer)\n if (!objectConfig) throw Error('Pointer not found: ' + pointer)\n try {\n let object\n if (objectConfig['$require']) {\n object = await objectFromConfig(objectConfig)\n } else if (objectConfig['$env']) {\n object = process.env[objectConfig['$env']]\n } else {\n object = await resolveRefs(objectConfig)\n }\n set(objects, pointer, object)\n return object\n } catch (e: any) {\n console.log(e)\n throw Error(e.message + '. While creating object from pointer: ' + pointer)\n }\n }\n }\n\n const result: any = {}\n for (const key of Object.keys(pointers)) {\n if (pointers.hasOwnProperty(key)) {\n result[key] = await objectFromPointer(pointers[key])\n }\n }\n return result\n}\n","import { DataSources, type DateTimeType, type DateType, type SupportedDatabaseType } from './dataSources'\n\nexport const getDbType = (opts?: { defaultType: SupportedDatabaseType }): SupportedDatabaseType => {\n const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType\n if (!type) {\n throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`)\n }\n return type as SupportedDatabaseType\n}\n\nexport const typeOrmDateTime = (opts?: { defaultType: SupportedDatabaseType }): DateTimeType => {\n switch (getDbType(opts)) {\n case 'postgres':\n return 'timestamp'\n case 'sqlite':\n case 'react-native':\n return 'datetime'\n default:\n throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`)\n }\n}\n\nexport const typeormDate = (opts?: { defaultType: SupportedDatabaseType }): DateType => {\n // The same for both DBs\n return 'date'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACkBO,SAASA,iBACdC,SACAC,gBAAiC;AAEjC,QAAMC,UAAUC,MAAMC,QAAQH,cAAAA,IAAkBA,iBAAiB;IAACA;;AAClE,QAAMI,aAAaL,QAAQM,MAAMC,iBAAgB;AACjD,SAAOL,QAAQM,MAAM,CAACC,WAAWJ,WAAWK,SAASD,MAAAA,CAAAA;AACvD;AAPgBV;AAeT,SAASY,qBAAqBX,SAAwC;AAC3E,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBW;AAIT,SAASC,qBAAqBZ,SAAwC;AAC3E,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBY;AAIT,SAASC,sBAAsBb,SAAwC;AAC5E,SAAOD,iBAAiBC,SAAS,YAAA;AACnC;AAFgBa;AAIT,SAASC,2BAA2Bd,SAAwC;AACjF,SAAOD,iBAAiBC,SAAS;IAAC;IAA8B;GAA+B;AACjG;AAFgBc;AAIT,SAASC,6BAA6Bf,SAAwC;AACnF,SAAOD,iBAAiBC,SAAS;IAAC;IAAoB;GAAqB;AAC7E;AAFgBe;AAIT,SAASC,mCAAmChB,SAAwC;AACzF,SAAOD,iBAAiBC,SAAS;IAAC;GAAwB;AAC5D;AAFgBgB;AAIT,SAASC,oBAAoBjB,SAAwC;AAC1E,SAAOD,iBAAiBC,SAAS;IAAC;IAAoC;GAAqC;AAC7G;AAFgBiB;AAIT,SAASC,uBAAuBlB,SAAwC;AAC7E,SAAOD,iBAAiBC,SAAS;IAAC;IAAwC;GAAyC;AACrH;AAFgBkB;;;AC7DhB,mBAAkB;AAClB,wBAA2B;AAI3B,I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AY,WAAWA,SAASC,KAAKC,UAAUC,WAAcC,YAAYC,eAAc,EAAGC,iBAAiBR,MAAMS;AACtI,MAAI,CAACR,MAAM;AACT,UAAMS,MAAM,iHAAiH;EAC/H;AACA,SAAOT;AACT,GANyB;AAQlB,IAAMU,kBAAkB,wBAACX,SAAAA;AAC9B,UAAQD,UAAUC,IAAAA,GAAAA;IAChB,KAAK;AACH,aAAO;IACT,KAAK;IACL,KAAK;AACH,aAAO;IACT;AACE,YAAMU,MAAM,WAAWX,UAAUC,IAAAA,CAAAA,kFAAuF;EAC5H;AACF,GAV+B;AAYxB,IAAMY,cAAc,wBAACZ,SAAAA;AAE1B,SAAO;AACT,GAH2B;","names":["contextHasPlugin","context","requiredMethod","methods","Array","isArray","allMethods","agent","availableMethods","every","method","includes","contextHasKeyManager","contextHasDidManager","contextHasDidResolver","contextHasCredentialIssuer","contextHasCredentialVerifier","contextHasCredentialStatusVerifier","contextHasDataStore","contextHasDataStoreORM","debug","Debug","DataSources","defaultDbType","_defaultDbType","value","dataSources","Map","configs","singleton","singleInstance","newInstance","forEach","config","name","addConfig","dbName","set","type","deleteConfig","delete","has","getConfig","get","Error","getDbNames","keys","getDbConnection","dataSource","DataSource","initialize","synchronize","migrationsRun","migrations","length","runMigrations","connectionName","opts","dropDatabase","removeDataSource","Promise","reject","connection","isInitialized","revertMigration","undoLastMigration","console","error","resetDatabase","createObjects","config","pointers","objects","resolveRefs","input","Array","isArray","resolved","item","push","property","hasOwnProperty","pointer","objectFromPointer","objectFromConfig","process","env","objectConfig","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","error","Promise","then","mod","required","object","reject","Error","get","catch","e","message","existingObject","set","result","key","Object","keys","createAgentFromConfig","config","agent","createObjects","createAgent","options","Agent","getConfig","filePath","fileContent","fs","promises","readFile","e","console","log","process","exit","yaml","parse","prettyErrors","error","message","linePos","version","getAgent","fileName","getDbType","opts","type","process","env","DB_TYPE","undefined","DataSources","singleInstance","defaultDbType","defaultType","Error","typeOrmDateTime","typeormDate"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/agentContextUtils.ts","../src/dataSources.ts","../src/agentCreator.ts","../src/objectCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './agentContextUtils'\nexport * from './dataSources'\nexport * from './agentCreator'\nexport * from './objectCreator'\nexport * from './generic'\nexport * from './typeormTypes'\n","import type {\n IAgentContext,\n ICredentialVerifier,\n IDataStore,\n IDataStoreORM,\n IDIDManager,\n IKeyManager,\n IPluginMethodMap,\n IResolver,\n ICredentialIssuer,\n ICredentialStatusVerifier,\n} from '@veramo/core'\n\n/**\n * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)\n * @param context Tje agent context to check against\n * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence\n */\nexport function contextHasPlugin<Plugins extends IPluginMethodMap>(\n context: IAgentContext<any>,\n requiredMethod: string | string[],\n): context is IAgentContext<Plugins> {\n const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod]\n const allMethods = context.agent.availableMethods()\n return methods.every((method) => allMethods.includes(method))\n}\n\n/**\n * The below methods are convenience methods to directly get the appropriate context after calling the respective method\n *\n * @param context\n */\n\nexport function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager> {\n return contextHasPlugin(context, 'keyManagerGet')\n}\n\nexport function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager> {\n return contextHasPlugin(context, 'didManagerGet') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver> {\n return contextHasPlugin(context, 'resolveDid') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer> {\n return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']) // W3C Credential issuer\n}\n\nexport function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier> {\n return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']) // W3c Credential Verifier\n}\n\nexport function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier> {\n return contextHasPlugin(context, ['checkCredentialStatus']) // W3c Credential status Verifier\n}\n\nexport function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore> {\n return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation'])\n}\n\nexport function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM> {\n return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations'])\n}\n","import Debug from 'debug'\nimport { DataSource } from 'typeorm/data-source/DataSource.js'\nimport type { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport type { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js'\n\nconst debug = Debug(`sphereon:ssi-sdk:database`)\n\nexport class DataSources {\n get defaultDbType(): SupportedDatabaseType {\n return this._defaultDbType\n }\n\n set defaultDbType(value: SupportedDatabaseType) {\n this._defaultDbType = value\n }\n private dataSources = new Map<string, DataSource>()\n private configs = new Map<string, DataSourceOptions>()\n private _defaultDbType: SupportedDatabaseType = 'sqlite'\n\n private static singleton: DataSources\n\n public static singleInstance() {\n if (!DataSources.singleton) {\n DataSources.singleton = new DataSources()\n }\n return DataSources.singleton\n }\n\n public static newInstance(configs?: Map<string, DataSourceOptions>) {\n return new DataSources(configs)\n }\n\n private constructor(configs?: Map<string, DataSourceOptions>) {\n ;(configs ?? new Map<string, DataSourceOptions>()).forEach((config, name) => this.addConfig(name, config))\n }\n\n addConfig(dbName: string, config: DataSourceOptions): this {\n this.configs.set(dbName, config)\n // yes we are aware last one wins\n this._defaultDbType = config.type as SupportedDatabaseType\n return this\n }\n\n deleteConfig(dbName: string): this {\n this.configs.delete(dbName)\n return this\n }\n has(dbName: string) {\n return this.configs.has(dbName) && this.dataSources.has(dbName)\n }\n\n delete(dbName: string): this {\n this.deleteConfig(dbName)\n this.dataSources.delete(dbName)\n return this\n }\n\n getConfig(dbName: string): BaseDataSourceOptions {\n const config = this.configs.get(dbName)\n if (!config) {\n throw Error(`No DB config found for ${dbName}`)\n }\n return config\n }\n\n public getDbNames(): string[] {\n return [...this.configs.keys()]\n }\n\n async getDbConnection(dbName: string, allowAutomaticMigrations: boolean = true): Promise<DataSource> {\n const config = this.getConfig(dbName)\n if (!this._defaultDbType) {\n this._defaultDbType = config.type as SupportedDatabaseType\n }\n /*if (config.synchronize) {\n return Promise.reject(\n `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`\n )\n }*/\n\n let dataSource = this.dataSources.get(dbName)\n if (dataSource) {\n return dataSource\n }\n\n dataSource = await new DataSource({ ...(config as DataSourceOptions), name: dbName }).initialize()\n this.dataSources.set(dbName, dataSource)\n if (config.synchronize) {\n debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`)\n } else if (config.migrationsRun) {\n debug(\n `Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`,\n )\n } else if (allowAutomaticMigrations) {\n debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)\n await dataSource.runMigrations()\n debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)\n }\n return dataSource\n }\n}\n\nexport type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native'\nexport type DateTimeType = 'timestamp' | 'datetime'\n\nexport type DateType = 'date'\n\n/**\n * Gets the database connection.\n *\n * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time\n *\n * @param connectionName The database name\n * @param opts\n */\nexport const getDbConnection = async (\n connectionName: string,\n opts?: {\n config: BaseDataSourceOptions | any\n },\n): Promise<DataSource> => {\n if (!DataSources.singleInstance().has(connectionName) && opts?.config) {\n DataSources.singleInstance().addConfig(connectionName, opts?.config)\n }\n return DataSources.singleInstance().getDbConnection(connectionName)\n}\n\nexport const dropDatabase = async (dbName: string, opts?: { removeDataSource?: boolean }): Promise<void> => {\n const { removeDataSource = false } = { ...opts }\n if (!DataSources.singleInstance().has(dbName)) {\n return Promise.reject(Error(`No database present with name: ${dbName}`))\n }\n\n const connection: DataSource = await getDbConnection(dbName)\n await connection.dropDatabase()\n if (removeDataSource) {\n DataSources.singleInstance().delete(dbName)\n } else if (!connection.isInitialized) {\n await connection.initialize()\n }\n}\n\n/**\n * Runs a migration down (drops DB schema)\n * @param dataSource\n */\nexport const revertMigration = async (dataSource: DataSource): Promise<void> => {\n if (dataSource.isInitialized) {\n await dataSource.undoLastMigration()\n } else {\n console.error('DataSource is not initialized')\n }\n}\nexport const resetDatabase = async (dbName: string): Promise<void> => {\n await dropDatabase(dbName)\n const connection = await getDbConnection(dbName)\n await connection.runMigrations()\n}\n","import { type TAgent, type IPluginMethodMap, type IAgentOptions, Agent } from '@veramo/core'\nimport { createObjects } from './objectCreator'\nimport yaml from 'yaml'\n\n/**\n * Creates a Veramo agent from a config object containing an `/agent` pointer.\n * @param config - The configuration object\n *\n * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on\n * the configuration options.\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {\n // @ts-ignore\n const { agent } = await createObjects(config, { agent: '/agent' })\n return agent\n}\n\n/**\n * Helper function to create a new instance of the {@link Agent} class with correct type\n *\n * @remarks\n * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE\n *\n * @example\n * ```typescript\n * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'\n * import { AgentRestClient } from '@veramo/remote-client'\n * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'\n * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({\n * plugins: [\n * new CredentialIssuer(),\n * new AgentRestClient({\n * url: 'http://localhost:3002/agent',\n * enabledMethods: [\n * 'resolveDid',\n * 'handleMessage',\n * ],\n * }),\n * ],\n * })\n * ```\n * @param options - Agent configuration options\n * @returns configured agent\n * @public\n */\nexport async function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(\n options: IAgentOptions & { context?: C },\n): Promise<TAgent<T> & { context?: C }> {\n return new Agent(options) as TAgent<T>\n}\n\n/**\n * Parses a yaml config file and returns a config object\n * @param filePath\n */\nexport const getConfig = async (filePath: string | Buffer | URL): Promise<{ version?: number; [x: string]: any }> => {\n let fileContent: string\n\n // read file async\n try {\n const fs = await import(/* webpackIgnore: true */ 'fs')\n fileContent = await fs.promises.readFile(filePath, 'utf8')\n } catch (e) {\n console.log('Config file not found: ' + filePath)\n console.log('Use \"veramo config create\" to create one')\n process.exit(1)\n }\n\n let config\n\n try {\n config = yaml.parse(fileContent, { prettyErrors: true })\n } catch (e: any) {\n console.error(`Unable to parse config file: ${e.message} ${e.linePos}`)\n process.exit(1)\n }\n\n if (config?.version != 3) {\n console.error('Unsupported configuration file version:', config.version)\n process.exit(1)\n }\n return config\n}\n\nexport async function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>> {\n try {\n return await createAgentFromConfig<T>(await getConfig(fileName))\n } catch (e: any) {\n console.log('Unable to create agent from ' + fileName + '.', e.message)\n process.exit(1)\n }\n}\n","import { set, get } from 'jsonpointer'\nimport parse from 'url-parse'\n\n/**\n * Creates objects from a configuration object and a set of pointers.\n *\n * Example:\n * ```ts\n * const { url } = createObjects({ \"rpcUrl\": \"http://localhost:8545\", }, { url: '/rpcUrl' })\n * ```\n *\n * The config can contain references (`$ref`) to other objects within using JSON pointers.\n * Example:\n * ```json\n * {\n * \"rpcUrl\": \"http://localhost:8545\",\n * \"endpoint\": {\n * \"url\": {\n * \"$ref\": \"/rpcUrl\"\n * }\n * }\n * }\n * ```\n *\n * The config object can also contain references to NPM modules using the `$require` property.\n * Example:\n * ```json\n * {\n * \"agent\": {\n * \"$require\": \"@veramo/core#Agent\",\n * \"$args\": {\n * \"plugins\": [\n * { \"$require\": \"@veramo/did-comm#DIDComm\" },\n * ]\n * }\n * }\n * }\n * ```\n *\n * Environment variables can also be specified using the `$env` property.\n *\n * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for\n * more information.\n *\n * @param config - The configuration object\n * @param pointers - A map of JSON pointers to objects within that config that you wish to create\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>> {\n const objects = {}\n\n async function resolveRefs(input: any): Promise<any> {\n if (Array.isArray(input)) {\n const resolved = []\n for (const item of input) {\n resolved.push(await resolveRefs(item))\n }\n return resolved\n }\n\n if (typeof input === 'object') {\n const resolved: any = {}\n for (const property in input) {\n if (input.hasOwnProperty(property)) {\n if (property === '$ref') {\n const pointer = input[property]\n return await objectFromPointer(pointer)\n } else if (property === '$require') {\n return await objectFromConfig(input)\n } else if (property === '$env') {\n return process.env[input[property]]\n } else {\n resolved[property] = await resolveRefs(input[property])\n }\n }\n }\n return resolved\n }\n\n return input\n }\n\n async function objectFromConfig(objectConfig: any): Promise<any> {\n console.log('Requiring', objectConfig['$require'])\n const parsed = parse(objectConfig['$require'], {}, true)\n let npmModule = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\n console.log(`member: ${member}`)\n const type = parsed.query['t'] || 'class'\n const pointer = parsed.query['p']\n const args = objectConfig['$args']\n console.log({ module, member, type, query: parsed.query, pointer, args })\n\n if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {\n console.log('objectFromConfig: Resolving relative path', npmModule)\n const { resolve } = await import('path')\n npmModule = resolve(npmModule)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n console.error(`npmModule: ${npmModule}`)\n // try {\n return await Promise.resolve(\n await import(/*@metro-ignore*/ npmModule)\n\n .then((mod) => {\n if (member) {\n return mod[member]\n }\n return mod\n })\n .then((required) => {\n let object: any\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n } else {\n console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)\n }\n if (!pointer) {\n return object\n }\n\n if (!object) {\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))\n }\n return get(object, pointer)\n })\n .catch((e) => {\n console.error(e)\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))\n }),\n )\n\n /*let required = member ? (await import(npmModule))[member] : await import(npmModule)\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n }*/\n // } catch (e: any) {\n // console.log(e)\n // throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)\n // }\n\n // return object\n }\n\n async function objectFromPointer(pointer: string) {\n const existingObject = get(objects, pointer)\n if (existingObject) {\n // console.log('Existing', pointer)\n return existingObject\n } else {\n // console.log('New', pointer)\n const objectConfig = get(config, pointer)\n if (!objectConfig) throw Error('Pointer not found: ' + pointer)\n try {\n let object\n if (objectConfig['$require']) {\n object = await objectFromConfig(objectConfig)\n } else if (objectConfig['$env']) {\n object = process.env[objectConfig['$env']]\n } else {\n object = await resolveRefs(objectConfig)\n }\n set(objects, pointer, object)\n return object\n } catch (e: any) {\n console.log(e)\n throw Error(e.message + '. While creating object from pointer: ' + pointer)\n }\n }\n }\n\n const result: any = {}\n for (const key of Object.keys(pointers)) {\n if (pointers.hasOwnProperty(key)) {\n result[key] = await objectFromPointer(pointers[key])\n }\n }\n return result\n}\n","import { DataSources, type DateTimeType, type DateType, type SupportedDatabaseType } from './dataSources'\n\nexport const getDbType = (opts?: { defaultType: SupportedDatabaseType }): SupportedDatabaseType => {\n const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType\n if (!type) {\n throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`)\n }\n return type as SupportedDatabaseType\n}\n\nexport const typeOrmDateTime = (opts?: { defaultType: SupportedDatabaseType }): DateTimeType => {\n switch (getDbType(opts)) {\n case 'postgres':\n return 'timestamp'\n case 'sqlite':\n case 'react-native':\n return 'datetime'\n default:\n throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`)\n }\n}\n\nexport const typeormDate = (opts?: { defaultType: SupportedDatabaseType }): DateType => {\n // The same for both DBs\n return 'date'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACkBO,SAASA,iBACdC,SACAC,gBAAiC;AAEjC,QAAMC,UAAUC,MAAMC,QAAQH,cAAAA,IAAkBA,iBAAiB;IAACA;;AAClE,QAAMI,aAAaL,QAAQM,MAAMC,iBAAgB;AACjD,SAAOL,QAAQM,MAAM,CAACC,WAAWJ,WAAWK,SAASD,MAAAA,CAAAA;AACvD;AAPgBV;AAeT,SAASY,qBAAqBX,SAAwC;AAC3E,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBW;AAIT,SAASC,qBAAqBZ,SAAwC;AAC3E,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBY;AAIT,SAASC,sBAAsBb,SAAwC;AAC5E,SAAOD,iBAAiBC,SAAS,YAAA;AACnC;AAFgBa;AAIT,SAASC,2BAA2Bd,SAAwC;AACjF,SAAOD,iBAAiBC,SAAS;IAAC;IAA8B;GAA+B;AACjG;AAFgBc;AAIT,SAASC,6BAA6Bf,SAAwC;AACnF,SAAOD,iBAAiBC,SAAS;IAAC;IAAoB;GAAqB;AAC7E;AAFgBe;AAIT,SAASC,mCAAmChB,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AQC,KAAK,CAAA;EACf;AACA,SAAOhB;AACT,GA3ByB;AA6BzB,eAAsBwB,SAAqCC,UAAgB;AACzE,MAAI;AACF,WAAO,MAAM1B,sBAAyB,MAAMO,UAAUmB,QAAAA,CAAAA;EACxD,SAASb,GAAQ;AACfC,YAAQC,IAAI,iCAAiCW,WAAW,KAAKb,EAAES,OAAO;AACtEN,YAAQC,KAAK,CAAA;EACf;AACF;AAPsBQ;;;AEpFf,IAAME,YAAY,wBAACC,SAAAA;AACxB,QAAMC,QAAQ,OAAOC,YAAY,WAAWA,SAASC,KAAKC,UAAUC,WAAcC,YAAYC,eAAc,EAAGC,iBAAiBR,MAAMS;AACtI,MAAI,CAACR,MAAM;AACT,UAAMS,MAAM,iHAAiH;EAC/H;AACA,SAAOT;AACT,GANyB;AAQlB,IAAMU,kBAAkB,wBAACX,SAAAA;AAC9B,UAAQD,UAAUC,IAAAA,GAAAA;IAChB,KAAK;AACH,aAAO;IACT,KAAK;IACL,KAAK;AACH,aAAO;IACT;AACE,YAAMU,MAAM,WAAWX,UAAUC,IAAAA,CAAAA,kFAAuF;EAC5H;AACF,GAV+B;AAYxB,IAAMY,cAAc,wBAACZ,SAAAA;AAE1B,SAAO;AACT,GAH2B;","names":["contextHasPlugin","context","requiredMethod","methods","Array","isArray","allMethods","agent","availableMethods","every","method","includes","contextHasKeyManager","contextHasDidManager","contextHasDidResolver","contextHasCredentialIssuer","contextHasCredentialVerifier","contextHasCredentialStatusVerifier","contextHasDataStore","contextHasDataStoreORM","debug","Debug","DataSources","defaultDbType","_defaultDbType","value","dataSources","Map","configs","singleton","singleInstance","newInstance","forEach","config","name","addConfig","dbName","set","type","deleteConfig","delete","has","getConfig","get","Error","getDbNames","keys","getDbConnection","allowAutomaticMigrations","dataSource","DataSource","initialize","synchronize","migrationsRun","migrations","length","runMigrations","connectionName","opts","dropDatabase","removeDataSource","Promise","reject","connection","isInitialized","revertMigration","undoLastMigration","console","error","resetDatabase","createObjects","config","pointers","objects","resolveRefs","input","Array","isArray","resolved","item","push","property","hasOwnProperty","pointer","objectFromPointer","objectFromConfig","process","env","objectConfig","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","error","Promise","then","mod","required","object","reject","Error","get","catch","e","message","existingObject","set","result","key","Object","keys","createAgentFromConfig","config","agent","createObjects","createAgent","options","Agent","getConfig","filePath","fileContent","fs","promises","readFile","e","console","log","process","exit","yaml","parse","prettyErrors","error","message","linePos","version","getAgent","fileName","getDbType","opts","type","process","env","DB_TYPE","undefined","DataSources","singleInstance","defaultDbType","defaultType","Error","typeOrmDateTime","typeormDate"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -39,7 +39,7 @@ declare class DataSources {
|
|
|
39
39
|
delete(dbName: string): this;
|
|
40
40
|
getConfig(dbName: string): BaseDataSourceOptions;
|
|
41
41
|
getDbNames(): string[];
|
|
42
|
-
getDbConnection(dbName: string): Promise<DataSource>;
|
|
42
|
+
getDbConnection(dbName: string, allowAutomaticMigrations?: boolean): Promise<DataSource>;
|
|
43
43
|
}
|
|
44
44
|
type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
|
|
45
45
|
type DateTimeType = 'timestamp' | 'datetime';
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ declare class DataSources {
|
|
|
39
39
|
delete(dbName: string): this;
|
|
40
40
|
getConfig(dbName: string): BaseDataSourceOptions;
|
|
41
41
|
getDbNames(): string[];
|
|
42
|
-
getDbConnection(dbName: string): Promise<DataSource>;
|
|
42
|
+
getDbConnection(dbName: string, allowAutomaticMigrations?: boolean): Promise<DataSource>;
|
|
43
43
|
}
|
|
44
44
|
type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
|
|
45
45
|
type DateTimeType = 'timestamp' | 'datetime';
|
package/dist/index.js
CHANGED
|
@@ -117,7 +117,7 @@ var DataSources = class _DataSources {
|
|
|
117
117
|
...this.configs.keys()
|
|
118
118
|
];
|
|
119
119
|
}
|
|
120
|
-
async getDbConnection(dbName) {
|
|
120
|
+
async getDbConnection(dbName, allowAutomaticMigrations = true) {
|
|
121
121
|
const config = this.getConfig(dbName);
|
|
122
122
|
if (!this._defaultDbType) {
|
|
123
123
|
this._defaultDbType = config.type;
|
|
@@ -135,7 +135,7 @@ var DataSources = class _DataSources {
|
|
|
135
135
|
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
136
136
|
} else if (config.migrationsRun) {
|
|
137
137
|
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
138
|
-
} else {
|
|
138
|
+
} else if (allowAutomaticMigrations) {
|
|
139
139
|
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
140
140
|
await dataSource.runMigrations();
|
|
141
141
|
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agentContextUtils.ts","../src/dataSources.ts","../src/agentCreator.ts","../src/objectCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["import type {\n IAgentContext,\n ICredentialVerifier,\n IDataStore,\n IDataStoreORM,\n IDIDManager,\n IKeyManager,\n IPluginMethodMap,\n IResolver,\n ICredentialIssuer,\n ICredentialStatusVerifier,\n} from '@veramo/core'\n\n/**\n * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)\n * @param context Tje agent context to check against\n * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence\n */\nexport function contextHasPlugin<Plugins extends IPluginMethodMap>(\n context: IAgentContext<any>,\n requiredMethod: string | string[],\n): context is IAgentContext<Plugins> {\n const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod]\n const allMethods = context.agent.availableMethods()\n return methods.every((method) => allMethods.includes(method))\n}\n\n/**\n * The below methods are convenience methods to directly get the appropriate context after calling the respective method\n *\n * @param context\n */\n\nexport function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager> {\n return contextHasPlugin(context, 'keyManagerGet')\n}\n\nexport function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager> {\n return contextHasPlugin(context, 'didManagerGet') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver> {\n return contextHasPlugin(context, 'resolveDid') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer> {\n return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']) // W3C Credential issuer\n}\n\nexport function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier> {\n return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']) // W3c Credential Verifier\n}\n\nexport function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier> {\n return contextHasPlugin(context, ['checkCredentialStatus']) // W3c Credential status Verifier\n}\n\nexport function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore> {\n return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation'])\n}\n\nexport function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM> {\n return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations'])\n}\n","import Debug from 'debug'\nimport { DataSource } from 'typeorm/data-source/DataSource.js'\nimport type { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport type { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js'\n\nconst debug = Debug(`sphereon:ssi-sdk:database`)\n\nexport class DataSources {\n get defaultDbType(): SupportedDatabaseType {\n return this._defaultDbType\n }\n\n set defaultDbType(value: SupportedDatabaseType) {\n this._defaultDbType = value\n }\n private dataSources = new Map<string, DataSource>()\n private configs = new Map<string, DataSourceOptions>()\n private _defaultDbType: SupportedDatabaseType = 'sqlite'\n\n private static singleton: DataSources\n\n public static singleInstance() {\n if (!DataSources.singleton) {\n DataSources.singleton = new DataSources()\n }\n return DataSources.singleton\n }\n\n public static newInstance(configs?: Map<string, DataSourceOptions>) {\n return new DataSources(configs)\n }\n\n private constructor(configs?: Map<string, DataSourceOptions>) {\n ;(configs ?? new Map<string, DataSourceOptions>()).forEach((config, name) => this.addConfig(name, config))\n }\n\n addConfig(dbName: string, config: DataSourceOptions): this {\n this.configs.set(dbName, config)\n // yes we are aware last one wins\n this._defaultDbType = config.type as SupportedDatabaseType\n return this\n }\n\n deleteConfig(dbName: string): this {\n this.configs.delete(dbName)\n return this\n }\n has(dbName: string) {\n return this.configs.has(dbName) && this.dataSources.has(dbName)\n }\n\n delete(dbName: string): this {\n this.deleteConfig(dbName)\n this.dataSources.delete(dbName)\n return this\n }\n\n getConfig(dbName: string): BaseDataSourceOptions {\n const config = this.configs.get(dbName)\n if (!config) {\n throw Error(`No DB config found for ${dbName}`)\n }\n return config\n }\n\n public getDbNames(): string[] {\n return [...this.configs.keys()]\n }\n\n async getDbConnection(dbName: string): Promise<DataSource> {\n const config = this.getConfig(dbName)\n if (!this._defaultDbType) {\n this._defaultDbType = config.type as SupportedDatabaseType\n }\n /*if (config.synchronize) {\n return Promise.reject(\n `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`\n )\n }*/\n\n let dataSource = this.dataSources.get(dbName)\n if (dataSource) {\n return dataSource\n }\n\n dataSource = await new DataSource({ ...(config as DataSourceOptions), name: dbName }).initialize()\n this.dataSources.set(dbName, dataSource)\n if (config.synchronize) {\n debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`)\n } else if (config.migrationsRun) {\n debug(\n `Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`,\n )\n } else {\n debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)\n await dataSource.runMigrations()\n debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)\n }\n return dataSource\n }\n}\n\nexport type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native'\nexport type DateTimeType = 'timestamp' | 'datetime'\n\nexport type DateType = 'date'\n\n/**\n * Gets the database connection.\n *\n * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time\n *\n * @param connectionName The database name\n * @param opts\n */\nexport const getDbConnection = async (\n connectionName: string,\n opts?: {\n config: BaseDataSourceOptions | any\n },\n): Promise<DataSource> => {\n if (!DataSources.singleInstance().has(connectionName) && opts?.config) {\n DataSources.singleInstance().addConfig(connectionName, opts?.config)\n }\n return DataSources.singleInstance().getDbConnection(connectionName)\n}\n\nexport const dropDatabase = async (dbName: string, opts?: { removeDataSource?: boolean }): Promise<void> => {\n const { removeDataSource = false } = { ...opts }\n if (!DataSources.singleInstance().has(dbName)) {\n return Promise.reject(Error(`No database present with name: ${dbName}`))\n }\n\n const connection: DataSource = await getDbConnection(dbName)\n await connection.dropDatabase()\n if (removeDataSource) {\n DataSources.singleInstance().delete(dbName)\n } else if (!connection.isInitialized) {\n await connection.initialize()\n }\n}\n\n/**\n * Runs a migration down (drops DB schema)\n * @param dataSource\n */\nexport const revertMigration = async (dataSource: DataSource): Promise<void> => {\n if (dataSource.isInitialized) {\n await dataSource.undoLastMigration()\n } else {\n console.error('DataSource is not initialized')\n }\n}\nexport const resetDatabase = async (dbName: string): Promise<void> => {\n await dropDatabase(dbName)\n const connection = await getDbConnection(dbName)\n await connection.runMigrations()\n}\n","import { type TAgent, type IPluginMethodMap, type IAgentOptions, Agent } from '@veramo/core'\nimport { createObjects } from './objectCreator'\nimport yaml from 'yaml'\n\n/**\n * Creates a Veramo agent from a config object containing an `/agent` pointer.\n * @param config - The configuration object\n *\n * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on\n * the configuration options.\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {\n // @ts-ignore\n const { agent } = await createObjects(config, { agent: '/agent' })\n return agent\n}\n\n/**\n * Helper function to create a new instance of the {@link Agent} class with correct type\n *\n * @remarks\n * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE\n *\n * @example\n * ```typescript\n * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'\n * import { AgentRestClient } from '@veramo/remote-client'\n * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'\n * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({\n * plugins: [\n * new CredentialIssuer(),\n * new AgentRestClient({\n * url: 'http://localhost:3002/agent',\n * enabledMethods: [\n * 'resolveDid',\n * 'handleMessage',\n * ],\n * }),\n * ],\n * })\n * ```\n * @param options - Agent configuration options\n * @returns configured agent\n * @public\n */\nexport async function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(\n options: IAgentOptions & { context?: C },\n): Promise<TAgent<T> & { context?: C }> {\n return new Agent(options) as TAgent<T>\n}\n\n/**\n * Parses a yaml config file and returns a config object\n * @param filePath\n */\nexport const getConfig = async (filePath: string | Buffer | URL): Promise<{ version?: number; [x: string]: any }> => {\n let fileContent: string\n\n // read file async\n try {\n const fs = await import(/* webpackIgnore: true */ 'fs')\n fileContent = await fs.promises.readFile(filePath, 'utf8')\n } catch (e) {\n console.log('Config file not found: ' + filePath)\n console.log('Use \"veramo config create\" to create one')\n process.exit(1)\n }\n\n let config\n\n try {\n config = yaml.parse(fileContent, { prettyErrors: true })\n } catch (e: any) {\n console.error(`Unable to parse config file: ${e.message} ${e.linePos}`)\n process.exit(1)\n }\n\n if (config?.version != 3) {\n console.error('Unsupported configuration file version:', config.version)\n process.exit(1)\n }\n return config\n}\n\nexport async function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>> {\n try {\n return await createAgentFromConfig<T>(await getConfig(fileName))\n } catch (e: any) {\n console.log('Unable to create agent from ' + fileName + '.', e.message)\n process.exit(1)\n }\n}\n","import { set, get } from 'jsonpointer'\nimport parse from 'url-parse'\n\n/**\n * Creates objects from a configuration object and a set of pointers.\n *\n * Example:\n * ```ts\n * const { url } = createObjects({ \"rpcUrl\": \"http://localhost:8545\", }, { url: '/rpcUrl' })\n * ```\n *\n * The config can contain references (`$ref`) to other objects within using JSON pointers.\n * Example:\n * ```json\n * {\n * \"rpcUrl\": \"http://localhost:8545\",\n * \"endpoint\": {\n * \"url\": {\n * \"$ref\": \"/rpcUrl\"\n * }\n * }\n * }\n * ```\n *\n * The config object can also contain references to NPM modules using the `$require` property.\n * Example:\n * ```json\n * {\n * \"agent\": {\n * \"$require\": \"@veramo/core#Agent\",\n * \"$args\": {\n * \"plugins\": [\n * { \"$require\": \"@veramo/did-comm#DIDComm\" },\n * ]\n * }\n * }\n * }\n * ```\n *\n * Environment variables can also be specified using the `$env` property.\n *\n * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for\n * more information.\n *\n * @param config - The configuration object\n * @param pointers - A map of JSON pointers to objects within that config that you wish to create\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>> {\n const objects = {}\n\n async function resolveRefs(input: any): Promise<any> {\n if (Array.isArray(input)) {\n const resolved = []\n for (const item of input) {\n resolved.push(await resolveRefs(item))\n }\n return resolved\n }\n\n if (typeof input === 'object') {\n const resolved: any = {}\n for (const property in input) {\n if (input.hasOwnProperty(property)) {\n if (property === '$ref') {\n const pointer = input[property]\n return await objectFromPointer(pointer)\n } else if (property === '$require') {\n return await objectFromConfig(input)\n } else if (property === '$env') {\n return process.env[input[property]]\n } else {\n resolved[property] = await resolveRefs(input[property])\n }\n }\n }\n return resolved\n }\n\n return input\n }\n\n async function objectFromConfig(objectConfig: any): Promise<any> {\n console.log('Requiring', objectConfig['$require'])\n const parsed = parse(objectConfig['$require'], {}, true)\n let npmModule = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\n console.log(`member: ${member}`)\n const type = parsed.query['t'] || 'class'\n const pointer = parsed.query['p']\n const args = objectConfig['$args']\n console.log({ module, member, type, query: parsed.query, pointer, args })\n\n if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {\n console.log('objectFromConfig: Resolving relative path', npmModule)\n const { resolve } = await import('path')\n npmModule = resolve(npmModule)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n console.error(`npmModule: ${npmModule}`)\n // try {\n return await Promise.resolve(\n await import(/*@metro-ignore*/ npmModule)\n\n .then((mod) => {\n if (member) {\n return mod[member]\n }\n return mod\n })\n .then((required) => {\n let object: any\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n } else {\n console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)\n }\n if (!pointer) {\n return object\n }\n\n if (!object) {\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))\n }\n return get(object, pointer)\n })\n .catch((e) => {\n console.error(e)\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))\n }),\n )\n\n /*let required = member ? (await import(npmModule))[member] : await import(npmModule)\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n }*/\n // } catch (e: any) {\n // console.log(e)\n // throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)\n // }\n\n // return object\n }\n\n async function objectFromPointer(pointer: string) {\n const existingObject = get(objects, pointer)\n if (existingObject) {\n // console.log('Existing', pointer)\n return existingObject\n } else {\n // console.log('New', pointer)\n const objectConfig = get(config, pointer)\n if (!objectConfig) throw Error('Pointer not found: ' + pointer)\n try {\n let object\n if (objectConfig['$require']) {\n object = await objectFromConfig(objectConfig)\n } else if (objectConfig['$env']) {\n object = process.env[objectConfig['$env']]\n } else {\n object = await resolveRefs(objectConfig)\n }\n set(objects, pointer, object)\n return object\n } catch (e: any) {\n console.log(e)\n throw Error(e.message + '. While creating object from pointer: ' + pointer)\n }\n }\n }\n\n const result: any = {}\n for (const key of Object.keys(pointers)) {\n if (pointers.hasOwnProperty(key)) {\n result[key] = await objectFromPointer(pointers[key])\n }\n }\n return result\n}\n","import { DataSources, type DateTimeType, type DateType, type SupportedDatabaseType } from './dataSources'\n\nexport const getDbType = (opts?: { defaultType: SupportedDatabaseType }): SupportedDatabaseType => {\n const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType\n if (!type) {\n throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`)\n }\n return type as SupportedDatabaseType\n}\n\nexport const typeOrmDateTime = (opts?: { defaultType: SupportedDatabaseType }): DateTimeType => {\n switch (getDbType(opts)) {\n case 'postgres':\n return 'timestamp'\n case 'sqlite':\n case 'react-native':\n return 'datetime'\n default:\n throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`)\n }\n}\n\nexport const typeormDate = (opts?: { defaultType: SupportedDatabaseType }): DateType => {\n // The same for both DBs\n return 'date'\n}\n"],"mappings":";;;;AAkBO,SAASA,iBACdC,SACAC,gBAAiC;AAEjC,QAAMC,UAAUC,MAAMC,QAAQH,cAAAA,IAAkBA,iBAAiB;IAACA;;AAClE,QAAMI,aAAaL,QAAQM,MAAMC,iBAAgB;AACjD,SAAOL,QAAQM,MAAM,CAACC,WAAWJ,WAAWK,SAASD,MAAAA,CAAAA;AACvD;AAPgBV;AAeT,SAASY,qBAAqBX,SAAwC;AAC3E,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBW;AAIT,SAASC,qBAAqBZ,SAAwC;AAC3E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CAAA;EACf;AAEA,MAAIhB;AAEJ,MAAI;AACFA,aAASiB,KAAKC,MAAMV,aAAa;MAAEW,cAAc;IAAK,CAAA;EACxD,SAASP,GAAQ;AACfC,YAAQO,MAAM,gCAAgCR,EAAES,OAAO,IAAIT,EAAEU,OAAO,EAAE;AACtEP,YAAQC,KAAK,CAAA;EACf;AAEA,MAAIhB,QAAQuB,WAAW,GAAG;AACxBV,YAAQO,MAAM,2CAA2CpB,OAAOuB,OAAO;AACvER,YAAQC,KAAK,CAAA;EACf;AACA,SAAOhB;AACT,GA3ByB;AA6BzB,eAAsBwB,SAAqCC,UAAgB;AACzE,MAAI;AACF,WAAO,MAAM1B,sBAAyB,MAAMO,UAAUmB,QAAAA,CAAAA;EACxD,SAASb,GAAQ;AACfC,YAAQC,IAAI,iCAAiCW,WAAW,KAAKb,EAAES,OAAO;AACtEN,YAAQC,KAAK,CAAA;EACf;AACF;AAPsBQ;;;AEpFf,IAAME,YAAY,wBAACC,SAAAA;AACxB,QAAMC,QAAQ,OAAOC,YAAY,WAAWA,SAASC,KAAKC,UAAUC,WAAcC,YAAYC,eAAc,EAAGC,iBAAiBR,MAAMS;AACtI,MAAI,CAACR,MAAM;AACT,UAAMS,MAAM,iHAAiH;EAC/H;AACA,SAAOT;AACT,GANyB;AAQlB,IAAMU,kBAAkB,wBAACX,SAAAA;AAC9B,UAAQD,UAAUC,IAAAA,GAAAA;IAChB,KAAK;AACH,aAAO;IACT,KAAK;IACL,KAAK;AACH,aAAO;IACT;AACE,YAAMU,MAAM,WAAWX,UAAUC,IAAAA,CAAAA,kFAAuF;EAC5H;AACF,GAV+B;AAYxB,IAAMY,cAAc,wBAACZ,SAAAA;AAE1B,SAAO;AACT,GAH2B;","names":["contextHasPlugin","context","requiredMethod","methods","Array","isArray","allMethods","agent","availableMethods","every","method","includes","contextHasKeyManager","contextHasDidManager","contextHasDidResolver","contextHasCredentialIssuer","contextHasCredentialVerifier","contextHasCredentialStatusVerifier","contextHasDataStore","contextHasDataStoreORM","Debug","DataSource","debug","Debug","DataSources","defaultDbType","_defaultDbType","value","dataSources","Map","configs","singleton","singleInstance","newInstance","forEach","config","name","addConfig","dbName","set","type","deleteConfig","delete","has","getConfig","get","Error","getDbNames","keys","getDbConnection","dataSource","DataSource","initialize","synchronize","migrationsRun","migrations","length","runMigrations","connectionName","opts","dropDatabase","removeDataSource","Promise","reject","connection","isInitialized","revertMigration","undoLastMigration","console","error","resetDatabase","Agent","set","get","parse","createObjects","config","pointers","objects","resolveRefs","input","Array","isArray","resolved","item","push","property","hasOwnProperty","pointer","objectFromPointer","objectFromConfig","process","env","objectConfig","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","error","Promise","then","mod","required","object","reject","Error","get","catch","e","message","existingObject","set","result","key","Object","keys","yaml","createAgentFromConfig","config","agent","createObjects","createAgent","options","Agent","getConfig","filePath","fileContent","fs","promises","readFile","e","console","log","process","exit","yaml","parse","prettyErrors","error","message","linePos","version","getAgent","fileName","getDbType","opts","type","process","env","DB_TYPE","undefined","DataSources","singleInstance","defaultDbType","defaultType","Error","typeOrmDateTime","typeormDate"]}
|
|
1
|
+
{"version":3,"sources":["../src/agentContextUtils.ts","../src/dataSources.ts","../src/agentCreator.ts","../src/objectCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["import type {\n IAgentContext,\n ICredentialVerifier,\n IDataStore,\n IDataStoreORM,\n IDIDManager,\n IKeyManager,\n IPluginMethodMap,\n IResolver,\n ICredentialIssuer,\n ICredentialStatusVerifier,\n} from '@veramo/core'\n\n/**\n * Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)\n * @param context Tje agent context to check against\n * @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence\n */\nexport function contextHasPlugin<Plugins extends IPluginMethodMap>(\n context: IAgentContext<any>,\n requiredMethod: string | string[],\n): context is IAgentContext<Plugins> {\n const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod]\n const allMethods = context.agent.availableMethods()\n return methods.every((method) => allMethods.includes(method))\n}\n\n/**\n * The below methods are convenience methods to directly get the appropriate context after calling the respective method\n *\n * @param context\n */\n\nexport function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager> {\n return contextHasPlugin(context, 'keyManagerGet')\n}\n\nexport function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager> {\n return contextHasPlugin(context, 'didManagerGet') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver> {\n return contextHasPlugin(context, 'resolveDid') // IResolver is always required for IDIDManager\n}\n\nexport function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer> {\n return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']) // W3C Credential issuer\n}\n\nexport function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier> {\n return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']) // W3c Credential Verifier\n}\n\nexport function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier> {\n return contextHasPlugin(context, ['checkCredentialStatus']) // W3c Credential status Verifier\n}\n\nexport function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore> {\n return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation'])\n}\n\nexport function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM> {\n return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations'])\n}\n","import Debug from 'debug'\nimport { DataSource } from 'typeorm/data-source/DataSource.js'\nimport type { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport type { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js'\n\nconst debug = Debug(`sphereon:ssi-sdk:database`)\n\nexport class DataSources {\n get defaultDbType(): SupportedDatabaseType {\n return this._defaultDbType\n }\n\n set defaultDbType(value: SupportedDatabaseType) {\n this._defaultDbType = value\n }\n private dataSources = new Map<string, DataSource>()\n private configs = new Map<string, DataSourceOptions>()\n private _defaultDbType: SupportedDatabaseType = 'sqlite'\n\n private static singleton: DataSources\n\n public static singleInstance() {\n if (!DataSources.singleton) {\n DataSources.singleton = new DataSources()\n }\n return DataSources.singleton\n }\n\n public static newInstance(configs?: Map<string, DataSourceOptions>) {\n return new DataSources(configs)\n }\n\n private constructor(configs?: Map<string, DataSourceOptions>) {\n ;(configs ?? new Map<string, DataSourceOptions>()).forEach((config, name) => this.addConfig(name, config))\n }\n\n addConfig(dbName: string, config: DataSourceOptions): this {\n this.configs.set(dbName, config)\n // yes we are aware last one wins\n this._defaultDbType = config.type as SupportedDatabaseType\n return this\n }\n\n deleteConfig(dbName: string): this {\n this.configs.delete(dbName)\n return this\n }\n has(dbName: string) {\n return this.configs.has(dbName) && this.dataSources.has(dbName)\n }\n\n delete(dbName: string): this {\n this.deleteConfig(dbName)\n this.dataSources.delete(dbName)\n return this\n }\n\n getConfig(dbName: string): BaseDataSourceOptions {\n const config = this.configs.get(dbName)\n if (!config) {\n throw Error(`No DB config found for ${dbName}`)\n }\n return config\n }\n\n public getDbNames(): string[] {\n return [...this.configs.keys()]\n }\n\n async getDbConnection(dbName: string, allowAutomaticMigrations: boolean = true): Promise<DataSource> {\n const config = this.getConfig(dbName)\n if (!this._defaultDbType) {\n this._defaultDbType = config.type as SupportedDatabaseType\n }\n /*if (config.synchronize) {\n return Promise.reject(\n `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`\n )\n }*/\n\n let dataSource = this.dataSources.get(dbName)\n if (dataSource) {\n return dataSource\n }\n\n dataSource = await new DataSource({ ...(config as DataSourceOptions), name: dbName }).initialize()\n this.dataSources.set(dbName, dataSource)\n if (config.synchronize) {\n debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`)\n } else if (config.migrationsRun) {\n debug(\n `Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`,\n )\n } else if (allowAutomaticMigrations) {\n debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)\n await dataSource.runMigrations()\n debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)\n }\n return dataSource\n }\n}\n\nexport type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native'\nexport type DateTimeType = 'timestamp' | 'datetime'\n\nexport type DateType = 'date'\n\n/**\n * Gets the database connection.\n *\n * Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time\n *\n * @param connectionName The database name\n * @param opts\n */\nexport const getDbConnection = async (\n connectionName: string,\n opts?: {\n config: BaseDataSourceOptions | any\n },\n): Promise<DataSource> => {\n if (!DataSources.singleInstance().has(connectionName) && opts?.config) {\n DataSources.singleInstance().addConfig(connectionName, opts?.config)\n }\n return DataSources.singleInstance().getDbConnection(connectionName)\n}\n\nexport const dropDatabase = async (dbName: string, opts?: { removeDataSource?: boolean }): Promise<void> => {\n const { removeDataSource = false } = { ...opts }\n if (!DataSources.singleInstance().has(dbName)) {\n return Promise.reject(Error(`No database present with name: ${dbName}`))\n }\n\n const connection: DataSource = await getDbConnection(dbName)\n await connection.dropDatabase()\n if (removeDataSource) {\n DataSources.singleInstance().delete(dbName)\n } else if (!connection.isInitialized) {\n await connection.initialize()\n }\n}\n\n/**\n * Runs a migration down (drops DB schema)\n * @param dataSource\n */\nexport const revertMigration = async (dataSource: DataSource): Promise<void> => {\n if (dataSource.isInitialized) {\n await dataSource.undoLastMigration()\n } else {\n console.error('DataSource is not initialized')\n }\n}\nexport const resetDatabase = async (dbName: string): Promise<void> => {\n await dropDatabase(dbName)\n const connection = await getDbConnection(dbName)\n await connection.runMigrations()\n}\n","import { type TAgent, type IPluginMethodMap, type IAgentOptions, Agent } from '@veramo/core'\nimport { createObjects } from './objectCreator'\nimport yaml from 'yaml'\n\n/**\n * Creates a Veramo agent from a config object containing an `/agent` pointer.\n * @param config - The configuration object\n *\n * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on\n * the configuration options.\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {\n // @ts-ignore\n const { agent } = await createObjects(config, { agent: '/agent' })\n return agent\n}\n\n/**\n * Helper function to create a new instance of the {@link Agent} class with correct type\n *\n * @remarks\n * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE\n *\n * @example\n * ```typescript\n * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'\n * import { AgentRestClient } from '@veramo/remote-client'\n * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'\n * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({\n * plugins: [\n * new CredentialIssuer(),\n * new AgentRestClient({\n * url: 'http://localhost:3002/agent',\n * enabledMethods: [\n * 'resolveDid',\n * 'handleMessage',\n * ],\n * }),\n * ],\n * })\n * ```\n * @param options - Agent configuration options\n * @returns configured agent\n * @public\n */\nexport async function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(\n options: IAgentOptions & { context?: C },\n): Promise<TAgent<T> & { context?: C }> {\n return new Agent(options) as TAgent<T>\n}\n\n/**\n * Parses a yaml config file and returns a config object\n * @param filePath\n */\nexport const getConfig = async (filePath: string | Buffer | URL): Promise<{ version?: number; [x: string]: any }> => {\n let fileContent: string\n\n // read file async\n try {\n const fs = await import(/* webpackIgnore: true */ 'fs')\n fileContent = await fs.promises.readFile(filePath, 'utf8')\n } catch (e) {\n console.log('Config file not found: ' + filePath)\n console.log('Use \"veramo config create\" to create one')\n process.exit(1)\n }\n\n let config\n\n try {\n config = yaml.parse(fileContent, { prettyErrors: true })\n } catch (e: any) {\n console.error(`Unable to parse config file: ${e.message} ${e.linePos}`)\n process.exit(1)\n }\n\n if (config?.version != 3) {\n console.error('Unsupported configuration file version:', config.version)\n process.exit(1)\n }\n return config\n}\n\nexport async function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>> {\n try {\n return await createAgentFromConfig<T>(await getConfig(fileName))\n } catch (e: any) {\n console.log('Unable to create agent from ' + fileName + '.', e.message)\n process.exit(1)\n }\n}\n","import { set, get } from 'jsonpointer'\nimport parse from 'url-parse'\n\n/**\n * Creates objects from a configuration object and a set of pointers.\n *\n * Example:\n * ```ts\n * const { url } = createObjects({ \"rpcUrl\": \"http://localhost:8545\", }, { url: '/rpcUrl' })\n * ```\n *\n * The config can contain references (`$ref`) to other objects within using JSON pointers.\n * Example:\n * ```json\n * {\n * \"rpcUrl\": \"http://localhost:8545\",\n * \"endpoint\": {\n * \"url\": {\n * \"$ref\": \"/rpcUrl\"\n * }\n * }\n * }\n * ```\n *\n * The config object can also contain references to NPM modules using the `$require` property.\n * Example:\n * ```json\n * {\n * \"agent\": {\n * \"$require\": \"@veramo/core#Agent\",\n * \"$args\": {\n * \"plugins\": [\n * { \"$require\": \"@veramo/did-comm#DIDComm\" },\n * ]\n * }\n * }\n * }\n * ```\n *\n * Environment variables can also be specified using the `$env` property.\n *\n * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for\n * more information.\n *\n * @param config - The configuration object\n * @param pointers - A map of JSON pointers to objects within that config that you wish to create\n *\n * @beta - This API may change without a major version bump\n */\nexport async function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>> {\n const objects = {}\n\n async function resolveRefs(input: any): Promise<any> {\n if (Array.isArray(input)) {\n const resolved = []\n for (const item of input) {\n resolved.push(await resolveRefs(item))\n }\n return resolved\n }\n\n if (typeof input === 'object') {\n const resolved: any = {}\n for (const property in input) {\n if (input.hasOwnProperty(property)) {\n if (property === '$ref') {\n const pointer = input[property]\n return await objectFromPointer(pointer)\n } else if (property === '$require') {\n return await objectFromConfig(input)\n } else if (property === '$env') {\n return process.env[input[property]]\n } else {\n resolved[property] = await resolveRefs(input[property])\n }\n }\n }\n return resolved\n }\n\n return input\n }\n\n async function objectFromConfig(objectConfig: any): Promise<any> {\n console.log('Requiring', objectConfig['$require'])\n const parsed = parse(objectConfig['$require'], {}, true)\n let npmModule = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\n console.log(`member: ${member}`)\n const type = parsed.query['t'] || 'class'\n const pointer = parsed.query['p']\n const args = objectConfig['$args']\n console.log({ module, member, type, query: parsed.query, pointer, args })\n\n if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {\n console.log('objectFromConfig: Resolving relative path', npmModule)\n const { resolve } = await import('path')\n npmModule = resolve(npmModule)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n console.error(`npmModule: ${npmModule}`)\n // try {\n return await Promise.resolve(\n await import(/*@metro-ignore*/ npmModule)\n\n .then((mod) => {\n if (member) {\n return mod[member]\n }\n return mod\n })\n .then((required) => {\n let object: any\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n } else {\n console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)\n }\n if (!pointer) {\n return object\n }\n\n if (!object) {\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))\n }\n return get(object, pointer)\n })\n .catch((e) => {\n console.error(e)\n return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))\n }),\n )\n\n /*let required = member ? (await import(npmModule))[member] : await import(npmModule)\n if (type === 'class') {\n object = new required(...resolvedArgs)\n } else if (type === 'function') {\n object = required(...resolvedArgs)\n } else if (type === 'object') {\n object = required\n }*/\n // } catch (e: any) {\n // console.log(e)\n // throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)\n // }\n\n // return object\n }\n\n async function objectFromPointer(pointer: string) {\n const existingObject = get(objects, pointer)\n if (existingObject) {\n // console.log('Existing', pointer)\n return existingObject\n } else {\n // console.log('New', pointer)\n const objectConfig = get(config, pointer)\n if (!objectConfig) throw Error('Pointer not found: ' + pointer)\n try {\n let object\n if (objectConfig['$require']) {\n object = await objectFromConfig(objectConfig)\n } else if (objectConfig['$env']) {\n object = process.env[objectConfig['$env']]\n } else {\n object = await resolveRefs(objectConfig)\n }\n set(objects, pointer, object)\n return object\n } catch (e: any) {\n console.log(e)\n throw Error(e.message + '. While creating object from pointer: ' + pointer)\n }\n }\n }\n\n const result: any = {}\n for (const key of Object.keys(pointers)) {\n if (pointers.hasOwnProperty(key)) {\n result[key] = await objectFromPointer(pointers[key])\n }\n }\n return result\n}\n","import { DataSources, type DateTimeType, type DateType, type SupportedDatabaseType } from './dataSources'\n\nexport const getDbType = (opts?: { defaultType: SupportedDatabaseType }): SupportedDatabaseType => {\n const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType\n if (!type) {\n throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`)\n }\n return type as SupportedDatabaseType\n}\n\nexport const typeOrmDateTime = (opts?: { defaultType: SupportedDatabaseType }): DateTimeType => {\n switch (getDbType(opts)) {\n case 'postgres':\n return 'timestamp'\n case 'sqlite':\n case 'react-native':\n return 'datetime'\n default:\n throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`)\n }\n}\n\nexport const typeormDate = (opts?: { defaultType: SupportedDatabaseType }): DateType => {\n // The same for both DBs\n return 'date'\n}\n"],"mappings":";;;;AAkBO,SAASA,iBACdC,SACAC,gBAAiC;AAEjC,QAAMC,UAAUC,MAAMC,QAAQH,cAAAA,IAAkBA,iBAAiB;IAACA;;AAClE,QAAMI,aAAaL,QAAQM,MAAMC,iBAAgB;AACjD,SAAOL,QAAQM,MAAM,CAACC,WAAWJ,WAAWK,SAAS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AAO;AACT,GAH2B;","names":["contextHasPlugin","context","requiredMethod","methods","Array","isArray","allMethods","agent","availableMethods","every","method","includes","contextHasKeyManager","contextHasDidManager","contextHasDidResolver","contextHasCredentialIssuer","contextHasCredentialVerifier","contextHasCredentialStatusVerifier","contextHasDataStore","contextHasDataStoreORM","Debug","DataSource","debug","Debug","DataSources","defaultDbType","_defaultDbType","value","dataSources","Map","configs","singleton","singleInstance","newInstance","forEach","config","name","addConfig","dbName","set","type","deleteConfig","delete","has","getConfig","get","Error","getDbNames","keys","getDbConnection","allowAutomaticMigrations","dataSource","DataSource","initialize","synchronize","migrationsRun","migrations","length","runMigrations","connectionName","opts","dropDatabase","removeDataSource","Promise","reject","connection","isInitialized","revertMigration","undoLastMigration","console","error","resetDatabase","Agent","set","get","parse","createObjects","config","pointers","objects","resolveRefs","input","Array","isArray","resolved","item","push","property","hasOwnProperty","pointer","objectFromPointer","objectFromConfig","process","env","objectConfig","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","error","Promise","then","mod","required","object","reject","Error","get","catch","e","message","existingObject","set","result","key","Object","keys","yaml","createAgentFromConfig","config","agent","createObjects","createAgent","options","Agent","getConfig","filePath","fileContent","fs","promises","readFile","e","console","log","process","exit","yaml","parse","prettyErrors","error","message","linePos","version","getAgent","fileName","getDbType","opts","type","process","env","DB_TYPE","undefined","DataSources","singleInstance","defaultDbType","defaultType","Error","typeOrmDateTime","typeormDate"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.agent-config",
|
|
3
|
-
"version": "0.34.1-next.
|
|
3
|
+
"version": "0.34.1-next.85+019802c5",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"SSI",
|
|
52
52
|
"Agent"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "019802c57e9c1f9e3df4ecbb1d6a17f49e8fdbeb"
|
|
55
55
|
}
|
package/src/dataSources.ts
CHANGED
|
@@ -67,7 +67,7 @@ export class DataSources {
|
|
|
67
67
|
return [...this.configs.keys()]
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async getDbConnection(dbName: string): Promise<DataSource> {
|
|
70
|
+
async getDbConnection(dbName: string, allowAutomaticMigrations: boolean = true): Promise<DataSource> {
|
|
71
71
|
const config = this.getConfig(dbName)
|
|
72
72
|
if (!this._defaultDbType) {
|
|
73
73
|
this._defaultDbType = config.type as SupportedDatabaseType
|
|
@@ -91,7 +91,7 @@ export class DataSources {
|
|
|
91
91
|
debug(
|
|
92
92
|
`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`,
|
|
93
93
|
)
|
|
94
|
-
} else {
|
|
94
|
+
} else if (allowAutomaticMigrations) {
|
|
95
95
|
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)
|
|
96
96
|
await dataSource.runMigrations()
|
|
97
97
|
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)
|