@sphereon/ssi-sdk.agent-config 0.33.1-feature.vcdm2.tsup.29 → 0.33.1-feature.vcdm2.tsup.31

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 CHANGED
@@ -267,7 +267,6 @@ async function createObjects(config, pointers) {
267
267
  }
268
268
  __name(resolveRefs, "resolveRefs");
269
269
  async function objectFromConfig(objectConfig) {
270
- let object;
271
270
  console.log("Requiring", objectConfig["$require"]);
272
271
  const parsed = (0, import_url_parse.default)(objectConfig["$require"], {}, true);
273
272
  let npmModule = parsed.pathname;
@@ -280,7 +279,9 @@ async function createObjects(config, pointers) {
280
279
  module,
281
280
  member,
282
281
  type,
283
- query: parsed.query
282
+ query: parsed.query,
283
+ pointer,
284
+ args
284
285
  });
285
286
  if (npmModule.slice(0, 2) === "./" || npmModule.slice(0, 3) === "../") {
286
287
  console.log("objectFromConfig: Resolving relative path", npmModule);
@@ -288,23 +289,37 @@ async function createObjects(config, pointers) {
288
289
  npmModule = resolve(npmModule);
289
290
  }
290
291
  const resolvedArgs = args !== void 0 ? await resolveRefs(args) : [];
291
- try {
292
- let required = member ? (await import(npmModule))[member] : await import(npmModule);
292
+ console.error(`npmModule: ${npmModule}`);
293
+ return await Promise.resolve(await import(
294
+ /*@metro-ignore*/
295
+ npmModule
296
+ ).then((mod) => {
297
+ if (member) {
298
+ return mod[member];
299
+ }
300
+ return mod;
301
+ }).then((required) => {
302
+ let object;
293
303
  if (type === "class") {
294
304
  object = new required(...resolvedArgs);
295
305
  } else if (type === "function") {
296
306
  object = required(...resolvedArgs);
297
307
  } else if (type === "object") {
298
308
  object = required;
309
+ } else {
310
+ console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`);
311
+ }
312
+ if (!pointer) {
313
+ return object;
314
+ }
315
+ if (!object) {
316
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`));
299
317
  }
300
- } catch (e) {
301
- console.log(e);
302
- throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`);
303
- }
304
- if (pointer) {
305
318
  return (0, import_jsonpointer.get)(object, pointer);
306
- }
307
- return object;
319
+ }).catch((e) => {
320
+ console.error(e);
321
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`));
322
+ }));
308
323
  }
309
324
  __name(objectFromConfig, "objectFromConfig");
310
325
  async function objectFromPointer(pointer) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/agentContextUtils.ts","../src/dataSources.ts","../src/objectCreator.ts","../src/agentCreator.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 {\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 { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport { 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 { 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 let object\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})\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 try {\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 if (pointer) {\n return get(object, pointer)\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 { TAgent, IPluginMethodMap, IAgentOptions } 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 //@ts-ignore\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 { DataSources, DateTimeType, DateType, 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;AAFgB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+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","object","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","required","e","Error","message","get","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/objectCreator.ts","../src/agentCreator.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 {\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 { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport { 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 { 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(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 /*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 { TAgent, IPluginMethodMap, IAgentOptions } 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 //@ts-ignore\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 { DataSources, DateTimeType, DateType, 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 }): D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yB;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"]}
package/dist/index.js CHANGED
@@ -212,7 +212,6 @@ async function createObjects(config, pointers) {
212
212
  }
213
213
  __name(resolveRefs, "resolveRefs");
214
214
  async function objectFromConfig(objectConfig) {
215
- let object;
216
215
  console.log("Requiring", objectConfig["$require"]);
217
216
  const parsed = parse(objectConfig["$require"], {}, true);
218
217
  let npmModule = parsed.pathname;
@@ -225,7 +224,9 @@ async function createObjects(config, pointers) {
225
224
  module,
226
225
  member,
227
226
  type,
228
- query: parsed.query
227
+ query: parsed.query,
228
+ pointer,
229
+ args
229
230
  });
230
231
  if (npmModule.slice(0, 2) === "./" || npmModule.slice(0, 3) === "../") {
231
232
  console.log("objectFromConfig: Resolving relative path", npmModule);
@@ -233,23 +234,37 @@ async function createObjects(config, pointers) {
233
234
  npmModule = resolve(npmModule);
234
235
  }
235
236
  const resolvedArgs = args !== void 0 ? await resolveRefs(args) : [];
236
- try {
237
- let required = member ? (await import(npmModule))[member] : await import(npmModule);
237
+ console.error(`npmModule: ${npmModule}`);
238
+ return await Promise.resolve(await import(
239
+ /*@metro-ignore*/
240
+ npmModule
241
+ ).then((mod) => {
242
+ if (member) {
243
+ return mod[member];
244
+ }
245
+ return mod;
246
+ }).then((required) => {
247
+ let object;
238
248
  if (type === "class") {
239
249
  object = new required(...resolvedArgs);
240
250
  } else if (type === "function") {
241
251
  object = required(...resolvedArgs);
242
252
  } else if (type === "object") {
243
253
  object = required;
254
+ } else {
255
+ console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`);
256
+ }
257
+ if (!pointer) {
258
+ return object;
259
+ }
260
+ if (!object) {
261
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`));
244
262
  }
245
- } catch (e) {
246
- console.log(e);
247
- throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`);
248
- }
249
- if (pointer) {
250
263
  return get(object, pointer);
251
- }
252
- return object;
264
+ }).catch((e) => {
265
+ console.error(e);
266
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`));
267
+ }));
253
268
  }
254
269
  __name(objectFromConfig, "objectFromConfig");
255
270
  async function objectFromPointer(pointer) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/agentContextUtils.ts","../src/dataSources.ts","../src/objectCreator.ts","../src/agentCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["import {\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 { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport { 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 { 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 let object\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})\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 try {\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 if (pointer) {\n return get(object, pointer)\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 { TAgent, IPluginMethodMap, IAgentOptions } 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 //@ts-ignore\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 { DataSources, DateTimeType, DateType, 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,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QuB,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;;;ACrFf,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","set","get","parse","createObjects","config","pointers","objects","resolveRefs","input","Array","isArray","resolved","item","push","property","hasOwnProperty","pointer","objectFromPointer","objectFromConfig","process","env","objectConfig","object","console","log","parsed","parse","npmModule","pathname","member","hash","length","slice","undefined","type","query","args","module","resolve","resolvedArgs","required","e","Error","message","get","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/objectCreator.ts","../src/agentCreator.ts","../src/typeormTypes.ts"],"sourcesContent":["import {\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 { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js'\nimport { 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 { 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(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 /*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 { TAgent, IPluginMethodMap, IAgentOptions } 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 //@ts-ignore\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 { DataSources, DateTimeType, DateType, 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,SAAOD,iBAAiBC,SAAS,eAAA;AACnC;AAFgBY;AAIT,SAASC,sBAAsBb,SAAwC;AAC5E,SAAOD,iBAAiBC,SAAS,YAAA;AACnC;AAFgBa;AAIT,SAASC,2BAA2Bd,SAAwC;AACjF,SAAOD,i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,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;;;ACrFf,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","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.33.1-feature.vcdm2.tsup.29+24599d52",
3
+ "version": "0.33.1-feature.vcdm2.tsup.31+71b615ad",
4
4
  "source": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -8,6 +8,7 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  "import": {
11
+ "react-native": "./dist/index.js",
11
12
  "types": "./dist/index.d.ts",
12
13
  "import": "./dist/index.js"
13
14
  },
@@ -50,5 +51,5 @@
50
51
  "SSI",
51
52
  "Agent"
52
53
  ],
53
- "gitHead": "24599d527dfccefbee5d4f1137740a0b6083e2e3"
54
+ "gitHead": "71b615adbfef8ecd843edb2f3d0c58cb6453cff9"
54
55
  }
@@ -82,7 +82,6 @@ export async function createObjects(config: object, pointers: Record<string, str
82
82
  }
83
83
 
84
84
  async function objectFromConfig(objectConfig: any): Promise<any> {
85
- let object
86
85
  console.log('Requiring', objectConfig['$require'])
87
86
  const parsed = parse(objectConfig['$require'], {}, true)
88
87
  let npmModule = parsed.pathname
@@ -91,7 +90,7 @@ export async function createObjects(config: object, pointers: Record<string, str
91
90
  const type = parsed.query['t'] || 'class'
92
91
  const pointer = parsed.query['p']
93
92
  const args = objectConfig['$args']
94
- console.log({module, member, type, query: parsed.query})
93
+ console.log({ module, member, type, query: parsed.query, pointer, args })
95
94
 
96
95
  if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {
97
96
  console.log('objectFromConfig: Resolving relative path', npmModule)
@@ -100,23 +99,55 @@ export async function createObjects(config: object, pointers: Record<string, str
100
99
  }
101
100
 
102
101
  const resolvedArgs = args !== undefined ? await resolveRefs(args) : []
103
- try {
104
- let required = member ? (await import(npmModule))[member] : await import(npmModule)
105
- if (type === 'class') {
106
- object = new required(...resolvedArgs)
107
- } else if (type === 'function') {
108
- object = required(...resolvedArgs)
109
- } else if (type === 'object') {
110
- object = required
111
- }
112
- } catch (e: any) {
113
- console.log(e)
114
- throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)
115
- }
116
- if (pointer) {
117
- return get(object, pointer)
118
- }
119
- return object
102
+ console.error(`npmModule: ${npmModule}`)
103
+ // try {
104
+ return await Promise.resolve(await import(/*@metro-ignore*/npmModule)
105
+
106
+ .then((mod) => {
107
+ if (member) {
108
+ return mod[member]
109
+ }
110
+ return mod
111
+ })
112
+ .then((required) => {
113
+ let object: any
114
+ if (type === 'class') {
115
+ object = new required(...resolvedArgs)
116
+ } else if (type === 'function') {
117
+ object = required(...resolvedArgs)
118
+ } else if (type === 'object') {
119
+ object = required
120
+ } else {
121
+ console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)
122
+ }
123
+ if (!pointer) {
124
+ return object
125
+ }
126
+
127
+ if (!object) {
128
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))
129
+ }
130
+ return get(object, pointer)
131
+ })
132
+ .catch((e) => {
133
+ console.error(e)
134
+ return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))
135
+ }))
136
+
137
+ /*let required = member ? (await import(npmModule))[member] : await import(npmModule)
138
+ if (type === 'class') {
139
+ object = new required(...resolvedArgs)
140
+ } else if (type === 'function') {
141
+ object = required(...resolvedArgs)
142
+ } else if (type === 'object') {
143
+ object = required
144
+ }*/
145
+ // } catch (e: any) {
146
+ // console.log(e)
147
+ // throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)
148
+ // }
149
+
150
+ // return object
120
151
  }
121
152
 
122
153
  async function objectFromPointer(pointer: string) {