@sphereon/ssi-sdk.agent-config 0.33.1-feature.vcdm2.tsup.27 → 0.33.1-feature.vcdm2.tsup.29
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 +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/objectCreator.ts +11 -7
package/dist/index.cjs
CHANGED
|
@@ -268,19 +268,28 @@ async function createObjects(config, pointers) {
|
|
|
268
268
|
__name(resolveRefs, "resolveRefs");
|
|
269
269
|
async function objectFromConfig(objectConfig) {
|
|
270
270
|
let object;
|
|
271
|
+
console.log("Requiring", objectConfig["$require"]);
|
|
271
272
|
const parsed = (0, import_url_parse.default)(objectConfig["$require"], {}, true);
|
|
272
|
-
let
|
|
273
|
+
let npmModule = parsed.pathname;
|
|
273
274
|
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : void 0;
|
|
275
|
+
console.log(`member: ${member}`);
|
|
274
276
|
const type = parsed.query["t"] || "class";
|
|
275
277
|
const pointer = parsed.query["p"];
|
|
276
278
|
const args = objectConfig["$args"];
|
|
277
|
-
|
|
279
|
+
console.log({
|
|
280
|
+
module,
|
|
281
|
+
member,
|
|
282
|
+
type,
|
|
283
|
+
query: parsed.query
|
|
284
|
+
});
|
|
285
|
+
if (npmModule.slice(0, 2) === "./" || npmModule.slice(0, 3) === "../") {
|
|
286
|
+
console.log("objectFromConfig: Resolving relative path", npmModule);
|
|
278
287
|
const { resolve } = await import("path");
|
|
279
|
-
|
|
288
|
+
npmModule = resolve(npmModule);
|
|
280
289
|
}
|
|
281
290
|
const resolvedArgs = args !== void 0 ? await resolveRefs(args) : [];
|
|
282
291
|
try {
|
|
283
|
-
let required = member ? (await import(
|
|
292
|
+
let required = member ? (await import(npmModule))[member] : await import(npmModule);
|
|
284
293
|
if (type === "class") {
|
|
285
294
|
object = new required(...resolvedArgs);
|
|
286
295
|
} else if (type === "function") {
|
|
@@ -289,7 +298,8 @@ async function createObjects(config, pointers) {
|
|
|
289
298
|
object = required;
|
|
290
299
|
}
|
|
291
300
|
} catch (e) {
|
|
292
|
-
|
|
301
|
+
console.log(e);
|
|
302
|
+
throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`);
|
|
293
303
|
}
|
|
294
304
|
if (pointer) {
|
|
295
305
|
return (0, import_jsonpointer.get)(object, pointer);
|
|
@@ -316,6 +326,7 @@ async function createObjects(config, pointers) {
|
|
|
316
326
|
(0, import_jsonpointer.set)(objects, pointer, object);
|
|
317
327
|
return object;
|
|
318
328
|
} catch (e) {
|
|
329
|
+
console.log(e);
|
|
319
330
|
throw Error(e.message + ". While creating object from pointer: " + pointer);
|
|
320
331
|
}
|
|
321
332
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 module = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\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 (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {\n const { resolve } = await import('path')\n module = resolve(module)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n try {\n let required = member ? (await import(module))[member] : await import(module)\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 throw new Error(`Error creating ${module}['${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 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,S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AAU,MAAA;EACrD,SAASK,GAAG;AACVC,YAAQC,IAAI,4BAA4BP,QAAAA;AACxCM,YAAQC,IAAI,0CAAA;AACZC,YAAQC,KAAK,CAAA;EACf;AAEA,MAAIhB;AAEJ,MAAI;AACFA,aAASiB,YAAAA,QAAKC,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;;;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","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","parsed","parse","module","pathname","member","hash","length","slice","undefined","type","query","args","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 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,YA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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","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"]}
|
package/dist/index.js
CHANGED
|
@@ -213,19 +213,28 @@ async function createObjects(config, pointers) {
|
|
|
213
213
|
__name(resolveRefs, "resolveRefs");
|
|
214
214
|
async function objectFromConfig(objectConfig) {
|
|
215
215
|
let object;
|
|
216
|
+
console.log("Requiring", objectConfig["$require"]);
|
|
216
217
|
const parsed = parse(objectConfig["$require"], {}, true);
|
|
217
|
-
let
|
|
218
|
+
let npmModule = parsed.pathname;
|
|
218
219
|
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : void 0;
|
|
220
|
+
console.log(`member: ${member}`);
|
|
219
221
|
const type = parsed.query["t"] || "class";
|
|
220
222
|
const pointer = parsed.query["p"];
|
|
221
223
|
const args = objectConfig["$args"];
|
|
222
|
-
|
|
224
|
+
console.log({
|
|
225
|
+
module,
|
|
226
|
+
member,
|
|
227
|
+
type,
|
|
228
|
+
query: parsed.query
|
|
229
|
+
});
|
|
230
|
+
if (npmModule.slice(0, 2) === "./" || npmModule.slice(0, 3) === "../") {
|
|
231
|
+
console.log("objectFromConfig: Resolving relative path", npmModule);
|
|
223
232
|
const { resolve } = await import("path");
|
|
224
|
-
|
|
233
|
+
npmModule = resolve(npmModule);
|
|
225
234
|
}
|
|
226
235
|
const resolvedArgs = args !== void 0 ? await resolveRefs(args) : [];
|
|
227
236
|
try {
|
|
228
|
-
let required = member ? (await import(
|
|
237
|
+
let required = member ? (await import(npmModule))[member] : await import(npmModule);
|
|
229
238
|
if (type === "class") {
|
|
230
239
|
object = new required(...resolvedArgs);
|
|
231
240
|
} else if (type === "function") {
|
|
@@ -234,7 +243,8 @@ async function createObjects(config, pointers) {
|
|
|
234
243
|
object = required;
|
|
235
244
|
}
|
|
236
245
|
} catch (e) {
|
|
237
|
-
|
|
246
|
+
console.log(e);
|
|
247
|
+
throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`);
|
|
238
248
|
}
|
|
239
249
|
if (pointer) {
|
|
240
250
|
return get(object, pointer);
|
|
@@ -261,6 +271,7 @@ async function createObjects(config, pointers) {
|
|
|
261
271
|
set(objects, pointer, object);
|
|
262
272
|
return object;
|
|
263
273
|
} catch (e) {
|
|
274
|
+
console.log(e);
|
|
264
275
|
throw Error(e.message + ". While creating object from pointer: " + pointer);
|
|
265
276
|
}
|
|
266
277
|
}
|
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 module = parsed.pathname\n const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined\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 (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {\n const { resolve } = await import('path')\n module = resolve(module)\n }\n\n const resolvedArgs = args !== undefined ? await resolveRefs(args) : []\n try {\n let required = member ? (await import(module))[member] : await import(module)\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 throw new Error(`Error creating ${module}['${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 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,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,OAAOC,WAAW;AAClB,SAASC,kBAAkB;AAI3B,IAAMC,QAAQC,MAAM,2BAA2B;AAExC,IAAMC,cAAN,MAAMA,aAAAA;EAPb,OAOaA;;;EACX,IAAIC,gBAAuC;AACzC,WAAO,KAAKC;EACd;EAEA,IAAID,cAAcE,OAA8B;AAC9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;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","parsed","parse","module","pathname","member","hash","length","slice","undefined","type","query","args","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 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,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,OAAOC,WAAW;AAClB,SAASC,kBAAkB;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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","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"]}
|
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.
|
|
3
|
+
"version": "0.33.1-feature.vcdm2.tsup.29+24599d52",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"SSI",
|
|
51
51
|
"Agent"
|
|
52
52
|
],
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "24599d527dfccefbee5d4f1137740a0b6083e2e3"
|
|
54
54
|
}
|
package/src/objectCreator.ts
CHANGED
|
@@ -83,23 +83,25 @@ export async function createObjects(config: object, pointers: Record<string, str
|
|
|
83
83
|
|
|
84
84
|
async function objectFromConfig(objectConfig: any): Promise<any> {
|
|
85
85
|
let object
|
|
86
|
-
|
|
86
|
+
console.log('Requiring', objectConfig['$require'])
|
|
87
87
|
const parsed = parse(objectConfig['$require'], {}, true)
|
|
88
|
-
let
|
|
88
|
+
let npmModule = parsed.pathname
|
|
89
89
|
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined
|
|
90
|
+
console.log(`member: ${member}`)
|
|
90
91
|
const type = parsed.query['t'] || 'class'
|
|
91
92
|
const pointer = parsed.query['p']
|
|
92
93
|
const args = objectConfig['$args']
|
|
93
|
-
|
|
94
|
+
console.log({module, member, type, query: parsed.query})
|
|
94
95
|
|
|
95
|
-
if (
|
|
96
|
+
if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {
|
|
97
|
+
console.log('objectFromConfig: Resolving relative path', npmModule)
|
|
96
98
|
const { resolve } = await import('path')
|
|
97
|
-
|
|
99
|
+
npmModule = resolve(npmModule)
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
const resolvedArgs = args !== undefined ? await resolveRefs(args) : []
|
|
101
103
|
try {
|
|
102
|
-
let required = member ? (await import(
|
|
104
|
+
let required = member ? (await import(npmModule))[member] : await import(npmModule)
|
|
103
105
|
if (type === 'class') {
|
|
104
106
|
object = new required(...resolvedArgs)
|
|
105
107
|
} else if (type === 'function') {
|
|
@@ -108,7 +110,8 @@ export async function createObjects(config: object, pointers: Record<string, str
|
|
|
108
110
|
object = required
|
|
109
111
|
}
|
|
110
112
|
} catch (e: any) {
|
|
111
|
-
|
|
113
|
+
console.log(e)
|
|
114
|
+
throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)
|
|
112
115
|
}
|
|
113
116
|
if (pointer) {
|
|
114
117
|
return get(object, pointer)
|
|
@@ -137,6 +140,7 @@ export async function createObjects(config: object, pointers: Record<string, str
|
|
|
137
140
|
set(objects, pointer, object)
|
|
138
141
|
return object
|
|
139
142
|
} catch (e: any) {
|
|
143
|
+
console.log(e)
|
|
140
144
|
throw Error(e.message + '. While creating object from pointer: ' + pointer)
|
|
141
145
|
}
|
|
142
146
|
}
|