@sphereon/ssi-sdk.agent-config 0.18.2-next.3 → 0.18.2-unstable.10

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.
@@ -1,55 +1,55 @@
1
- import { TAgent, IPluginMethodMap, IAgentOptions } from '@veramo/core';
2
- import fs from 'fs';
3
- /**
4
- * Creates a Veramo agent from a config object containing an `/agent` pointer.
5
- * @param config - The configuration object
6
- *
7
- * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
8
- * the configuration options.
9
- *
10
- * @beta - This API may change without a major version bump
11
- */
12
- export declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
13
- /**
14
- * Helper function to create a new instance of the {@link Agent} class with correct type
15
- *
16
- * @remarks
17
- * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
18
- *
19
- * @example
20
- * ```typescript
21
- * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
22
- * import { AgentRestClient } from '@veramo/remote-client'
23
- * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
24
- * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
25
- * plugins: [
26
- * new CredentialIssuer(),
27
- * new AgentRestClient({
28
- * url: 'http://localhost:3002/agent',
29
- * enabledMethods: [
30
- * 'resolveDid',
31
- * 'handleMessage',
32
- * ],
33
- * }),
34
- * ],
35
- * })
36
- * ```
37
- * @param options - Agent configuration options
38
- * @returns configured agent
39
- * @public
40
- */
41
- export declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(options: IAgentOptions & {
42
- context?: C;
43
- }): Promise<TAgent<T> & {
44
- context?: C;
45
- }>;
46
- /**
47
- * Parses a yaml config file and returns a config object
48
- * @param filePath
49
- */
50
- export declare const getConfig: (filePath: fs.PathLike) => Promise<{
51
- [x: string]: any;
52
- version?: number | undefined;
53
- }>;
54
- export declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
1
+ import { TAgent, IPluginMethodMap, IAgentOptions } from '@veramo/core';
2
+ import fs from 'fs';
3
+ /**
4
+ * Creates a Veramo agent from a config object containing an `/agent` pointer.
5
+ * @param config - The configuration object
6
+ *
7
+ * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
8
+ * the configuration options.
9
+ *
10
+ * @beta - This API may change without a major version bump
11
+ */
12
+ export declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
13
+ /**
14
+ * Helper function to create a new instance of the {@link Agent} class with correct type
15
+ *
16
+ * @remarks
17
+ * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
22
+ * import { AgentRestClient } from '@veramo/remote-client'
23
+ * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
24
+ * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
25
+ * plugins: [
26
+ * new CredentialIssuer(),
27
+ * new AgentRestClient({
28
+ * url: 'http://localhost:3002/agent',
29
+ * enabledMethods: [
30
+ * 'resolveDid',
31
+ * 'handleMessage',
32
+ * ],
33
+ * }),
34
+ * ],
35
+ * })
36
+ * ```
37
+ * @param options - Agent configuration options
38
+ * @returns configured agent
39
+ * @public
40
+ */
41
+ export declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(options: IAgentOptions & {
42
+ context?: C;
43
+ }): Promise<TAgent<T> & {
44
+ context?: C;
45
+ }>;
46
+ /**
47
+ * Parses a yaml config file and returns a config object
48
+ * @param filePath
49
+ */
50
+ export declare const getConfig: (filePath: fs.PathLike) => Promise<{
51
+ [x: string]: any;
52
+ version?: number | undefined;
53
+ }>;
54
+ export declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
55
55
  //# sourceMappingURL=agentCreator.d.ts.map
@@ -1,113 +1,113 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getAgent = exports.getConfig = exports.createAgent = exports.createAgentFromConfig = void 0;
16
- const objectCreator_js_1 = require("./objectCreator.js");
17
- const fs_1 = __importDefault(require("fs"));
18
- const yaml_1 = __importDefault(require("yaml"));
19
- /**
20
- * Creates a Veramo agent from a config object containing an `/agent` pointer.
21
- * @param config - The configuration object
22
- *
23
- * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
24
- * the configuration options.
25
- *
26
- * @beta - This API may change without a major version bump
27
- */
28
- function createAgentFromConfig(config) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- // @ts-ignore
31
- const { agent } = yield (0, objectCreator_js_1.createObjects)(config, { agent: '/agent' });
32
- return agent;
33
- });
34
- }
35
- exports.createAgentFromConfig = createAgentFromConfig;
36
- /**
37
- * Helper function to create a new instance of the {@link Agent} class with correct type
38
- *
39
- * @remarks
40
- * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
41
- *
42
- * @example
43
- * ```typescript
44
- * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
45
- * import { AgentRestClient } from '@veramo/remote-client'
46
- * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
47
- * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
48
- * plugins: [
49
- * new CredentialIssuer(),
50
- * new AgentRestClient({
51
- * url: 'http://localhost:3002/agent',
52
- * enabledMethods: [
53
- * 'resolveDid',
54
- * 'handleMessage',
55
- * ],
56
- * }),
57
- * ],
58
- * })
59
- * ```
60
- * @param options - Agent configuration options
61
- * @returns configured agent
62
- * @public
63
- */
64
- function createAgent(options) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- //@ts-ignore
67
- return new Agent(options);
68
- });
69
- }
70
- exports.createAgent = createAgent;
71
- /**
72
- * Parses a yaml config file and returns a config object
73
- * @param filePath
74
- */
75
- const getConfig = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
76
- let fileContent;
77
- // read file async
78
- try {
79
- fileContent = yield fs_1.default.promises.readFile(filePath, 'utf8');
80
- }
81
- catch (e) {
82
- console.log('Config file not found: ' + filePath);
83
- console.log('Use "veramo config create" to create one');
84
- process.exit(1);
85
- }
86
- let config;
87
- try {
88
- config = yaml_1.default.parse(fileContent, { prettyErrors: true });
89
- }
90
- catch (e) {
91
- console.error(`Unable to parse config file: ${e.message} ${e.linePos}`);
92
- process.exit(1);
93
- }
94
- if ((config === null || config === void 0 ? void 0 : config.version) != 3) {
95
- console.error('Unsupported configuration file version:', config.version);
96
- process.exit(1);
97
- }
98
- return config;
99
- });
100
- exports.getConfig = getConfig;
101
- function getAgent(fileName) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- try {
104
- return yield createAgentFromConfig(yield (0, exports.getConfig)(fileName));
105
- }
106
- catch (e) {
107
- console.log('Unable to create agent from ' + fileName + '.', e.message);
108
- process.exit(1);
109
- }
110
- });
111
- }
112
- exports.getAgent = getAgent;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAgent = exports.getConfig = exports.createAgent = exports.createAgentFromConfig = void 0;
16
+ const objectCreator_js_1 = require("./objectCreator.js");
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const yaml_1 = __importDefault(require("yaml"));
19
+ /**
20
+ * Creates a Veramo agent from a config object containing an `/agent` pointer.
21
+ * @param config - The configuration object
22
+ *
23
+ * @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
24
+ * the configuration options.
25
+ *
26
+ * @beta - This API may change without a major version bump
27
+ */
28
+ function createAgentFromConfig(config) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ // @ts-ignore
31
+ const { agent } = yield (0, objectCreator_js_1.createObjects)(config, { agent: '/agent' });
32
+ return agent;
33
+ });
34
+ }
35
+ exports.createAgentFromConfig = createAgentFromConfig;
36
+ /**
37
+ * Helper function to create a new instance of the {@link Agent} class with correct type
38
+ *
39
+ * @remarks
40
+ * Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
45
+ * import { AgentRestClient } from '@veramo/remote-client'
46
+ * import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
47
+ * const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
48
+ * plugins: [
49
+ * new CredentialIssuer(),
50
+ * new AgentRestClient({
51
+ * url: 'http://localhost:3002/agent',
52
+ * enabledMethods: [
53
+ * 'resolveDid',
54
+ * 'handleMessage',
55
+ * ],
56
+ * }),
57
+ * ],
58
+ * })
59
+ * ```
60
+ * @param options - Agent configuration options
61
+ * @returns configured agent
62
+ * @public
63
+ */
64
+ function createAgent(options) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ //@ts-ignore
67
+ return new Agent(options);
68
+ });
69
+ }
70
+ exports.createAgent = createAgent;
71
+ /**
72
+ * Parses a yaml config file and returns a config object
73
+ * @param filePath
74
+ */
75
+ const getConfig = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
76
+ let fileContent;
77
+ // read file async
78
+ try {
79
+ fileContent = yield fs_1.default.promises.readFile(filePath, 'utf8');
80
+ }
81
+ catch (e) {
82
+ console.log('Config file not found: ' + filePath);
83
+ console.log('Use "veramo config create" to create one');
84
+ process.exit(1);
85
+ }
86
+ let config;
87
+ try {
88
+ config = yaml_1.default.parse(fileContent, { prettyErrors: true });
89
+ }
90
+ catch (e) {
91
+ console.error(`Unable to parse config file: ${e.message} ${e.linePos}`);
92
+ process.exit(1);
93
+ }
94
+ if ((config === null || config === void 0 ? void 0 : config.version) != 3) {
95
+ console.error('Unsupported configuration file version:', config.version);
96
+ process.exit(1);
97
+ }
98
+ return config;
99
+ });
100
+ exports.getConfig = getConfig;
101
+ function getAgent(fileName) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ try {
104
+ return yield createAgentFromConfig(yield (0, exports.getConfig)(fileName));
105
+ }
106
+ catch (e) {
107
+ console.log('Unable to create agent from ' + fileName + '.', e.message);
108
+ process.exit(1);
109
+ }
110
+ });
111
+ }
112
+ exports.getAgent = getAgent;
113
113
  //# sourceMappingURL=agentCreator.js.map
@@ -1,17 +1,17 @@
1
- import { DataSource } from 'typeorm';
2
- import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions';
3
- import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions';
4
- export declare class DataSources {
5
- private dataSources;
6
- private configs;
7
- private static singleton;
8
- static singleInstance(): DataSources;
9
- static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
10
- private constructor();
11
- addConfig(dbName: string, config: DataSourceOptions): this;
12
- deleteConfig(dbName: string): this;
13
- getConfig(dbName: string): BaseDataSourceOptions;
14
- getDbNames(): string[];
15
- getDbConnection(dbName: string): Promise<DataSource>;
16
- }
1
+ import { DataSource } from 'typeorm';
2
+ import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions';
3
+ import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions';
4
+ export declare class DataSources {
5
+ private dataSources;
6
+ private configs;
7
+ private static singleton;
8
+ static singleInstance(): DataSources;
9
+ static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
10
+ private constructor();
11
+ addConfig(dbName: string, config: DataSourceOptions): this;
12
+ deleteConfig(dbName: string): this;
13
+ getConfig(dbName: string): BaseDataSourceOptions;
14
+ getDbNames(): string[];
15
+ getDbConnection(dbName: string): Promise<DataSource>;
16
+ }
17
17
  //# sourceMappingURL=dataSources.d.ts.map
@@ -1,81 +1,81 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DataSources = void 0;
16
- const debug_1 = __importDefault(require("debug"));
17
- const typeorm_1 = require("typeorm");
18
- const debug = (0, debug_1.default)(`demo:databaseService`);
19
- class DataSources {
20
- static singleInstance() {
21
- if (!DataSources.singleton) {
22
- DataSources.singleton = new DataSources();
23
- }
24
- return DataSources.singleton;
25
- }
26
- static newInstance(configs) {
27
- return new DataSources(configs);
28
- }
29
- constructor(configs) {
30
- this.dataSources = new Map();
31
- this.configs = configs !== null && configs !== void 0 ? configs : new Map();
32
- }
33
- addConfig(dbName, config) {
34
- this.configs.set(dbName, config);
35
- return this;
36
- }
37
- deleteConfig(dbName) {
38
- this.configs.delete(dbName);
39
- return this;
40
- }
41
- getConfig(dbName) {
42
- const config = this.configs.get(dbName);
43
- if (!config) {
44
- throw Error(`No DB config found for ${dbName}`);
45
- }
46
- return config;
47
- }
48
- getDbNames() {
49
- return [...this.configs.keys()];
50
- }
51
- getDbConnection(dbName) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const config = this.getConfig(dbName);
54
- /*if (config.synchronize) {
55
- return Promise.reject(
56
- `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
57
- )
58
- }*/
59
- let dataSource = this.dataSources.get(dbName);
60
- if (dataSource) {
61
- return dataSource;
62
- }
63
- dataSource = yield new typeorm_1.DataSource(Object.assign(Object.assign({}, config), { name: dbName })).initialize();
64
- this.dataSources.set(dbName, dataSource);
65
- if (config.synchronize) {
66
- debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
67
- }
68
- else if (config.migrationsRun) {
69
- debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
70
- }
71
- else {
72
- debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
73
- yield dataSource.runMigrations();
74
- debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
75
- }
76
- return dataSource;
77
- });
78
- }
79
- }
80
- exports.DataSources = DataSources;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DataSources = void 0;
16
+ const debug_1 = __importDefault(require("debug"));
17
+ const typeorm_1 = require("typeorm");
18
+ const debug = (0, debug_1.default)(`demo:databaseService`);
19
+ class DataSources {
20
+ static singleInstance() {
21
+ if (!DataSources.singleton) {
22
+ DataSources.singleton = new DataSources();
23
+ }
24
+ return DataSources.singleton;
25
+ }
26
+ static newInstance(configs) {
27
+ return new DataSources(configs);
28
+ }
29
+ constructor(configs) {
30
+ this.dataSources = new Map();
31
+ this.configs = configs !== null && configs !== void 0 ? configs : new Map();
32
+ }
33
+ addConfig(dbName, config) {
34
+ this.configs.set(dbName, config);
35
+ return this;
36
+ }
37
+ deleteConfig(dbName) {
38
+ this.configs.delete(dbName);
39
+ return this;
40
+ }
41
+ getConfig(dbName) {
42
+ const config = this.configs.get(dbName);
43
+ if (!config) {
44
+ throw Error(`No DB config found for ${dbName}`);
45
+ }
46
+ return config;
47
+ }
48
+ getDbNames() {
49
+ return [...this.configs.keys()];
50
+ }
51
+ getDbConnection(dbName) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const config = this.getConfig(dbName);
54
+ /*if (config.synchronize) {
55
+ return Promise.reject(
56
+ `WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
57
+ )
58
+ }*/
59
+ let dataSource = this.dataSources.get(dbName);
60
+ if (dataSource) {
61
+ return dataSource;
62
+ }
63
+ dataSource = yield new typeorm_1.DataSource(Object.assign(Object.assign({}, config), { name: dbName })).initialize();
64
+ this.dataSources.set(dbName, dataSource);
65
+ if (config.synchronize) {
66
+ debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
67
+ }
68
+ else if (config.migrationsRun) {
69
+ debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
70
+ }
71
+ else {
72
+ debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
73
+ yield dataSource.runMigrations();
74
+ debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
75
+ }
76
+ return dataSource;
77
+ });
78
+ }
79
+ }
80
+ exports.DataSources = DataSources;
81
81
  //# sourceMappingURL=dataSources.js.map
package/dist/generic.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /**
2
- * Accept a Type or a Promise of that Type.
3
- *
4
- * @internal
5
- */
6
- export type OrPromise<T> = T | Promise<T>;
1
+ /**
2
+ * Accept a Type or a Promise of that Type.
3
+ *
4
+ * @internal
5
+ */
6
+ export type OrPromise<T> = T | Promise<T>;
7
7
  //# sourceMappingURL=generic.d.ts.map
package/dist/generic.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=generic.js.map
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * @public
3
- */
4
- export * from './dataSources';
5
- export * from './agentCreator';
6
- export * from './objectCreator';
7
- export * from './generic';
1
+ /**
2
+ * @public
3
+ */
4
+ export * from './dataSources';
5
+ export * from './agentCreator';
6
+ export * from './objectCreator';
7
+ export * from './generic';
8
8
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * @public
19
- */
20
- __exportStar(require("./dataSources"), exports);
21
- __exportStar(require("./agentCreator"), exports);
22
- __exportStar(require("./objectCreator"), exports);
23
- __exportStar(require("./generic"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * @public
19
+ */
20
+ __exportStar(require("./dataSources"), exports);
21
+ __exportStar(require("./agentCreator"), exports);
22
+ __exportStar(require("./objectCreator"), exports);
23
+ __exportStar(require("./generic"), exports);
24
24
  //# sourceMappingURL=index.js.map
@@ -1,48 +1,48 @@
1
- /**
2
- * Creates objects from a configuration object and a set of pointers.
3
- *
4
- * Example:
5
- * ```ts
6
- * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
7
- * ```
8
- *
9
- * The config can contain references (`$ref`) to other objects within using JSON pointers.
10
- * Example:
11
- * ```json
12
- * {
13
- * "rpcUrl": "http://localhost:8545",
14
- * "endpoint": {
15
- * "url": {
16
- * "$ref": "/rpcUrl"
17
- * }
18
- * }
19
- * }
20
- * ```
21
- *
22
- * The config object can also contain references to NPM modules using the `$require` property.
23
- * Example:
24
- * ```json
25
- * {
26
- * "agent": {
27
- * "$require": "@veramo/core#Agent",
28
- * "$args": {
29
- * "plugins": [
30
- * { "$require": "@veramo/did-comm#DIDComm" },
31
- * ]
32
- * }
33
- * }
34
- * }
35
- * ```
36
- *
37
- * Environment variables can also be specified using the `$env` property.
38
- *
39
- * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
40
- * more information.
41
- *
42
- * @param config - The configuration object
43
- * @param pointers - A map of JSON pointers to objects within that config that you wish to create
44
- *
45
- * @beta - This API may change without a major version bump
46
- */
47
- export declare function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>>;
1
+ /**
2
+ * Creates objects from a configuration object and a set of pointers.
3
+ *
4
+ * Example:
5
+ * ```ts
6
+ * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
7
+ * ```
8
+ *
9
+ * The config can contain references (`$ref`) to other objects within using JSON pointers.
10
+ * Example:
11
+ * ```json
12
+ * {
13
+ * "rpcUrl": "http://localhost:8545",
14
+ * "endpoint": {
15
+ * "url": {
16
+ * "$ref": "/rpcUrl"
17
+ * }
18
+ * }
19
+ * }
20
+ * ```
21
+ *
22
+ * The config object can also contain references to NPM modules using the `$require` property.
23
+ * Example:
24
+ * ```json
25
+ * {
26
+ * "agent": {
27
+ * "$require": "@veramo/core#Agent",
28
+ * "$args": {
29
+ * "plugins": [
30
+ * { "$require": "@veramo/did-comm#DIDComm" },
31
+ * ]
32
+ * }
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * Environment variables can also be specified using the `$env` property.
38
+ *
39
+ * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
40
+ * more information.
41
+ *
42
+ * @param config - The configuration object
43
+ * @param pointers - A map of JSON pointers to objects within that config that you wish to create
44
+ *
45
+ * @beta - This API may change without a major version bump
46
+ */
47
+ export declare function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>>;
48
48
  //# sourceMappingURL=objectCreator.d.ts.map
@@ -1,203 +1,203 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.createObjects = void 0;
39
- const jsonpointer_1 = require("jsonpointer");
40
- const url_parse_1 = __importDefault(require("url-parse"));
41
- const path_1 = require("path");
42
- /**
43
- * Creates objects from a configuration object and a set of pointers.
44
- *
45
- * Example:
46
- * ```ts
47
- * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
48
- * ```
49
- *
50
- * The config can contain references (`$ref`) to other objects within using JSON pointers.
51
- * Example:
52
- * ```json
53
- * {
54
- * "rpcUrl": "http://localhost:8545",
55
- * "endpoint": {
56
- * "url": {
57
- * "$ref": "/rpcUrl"
58
- * }
59
- * }
60
- * }
61
- * ```
62
- *
63
- * The config object can also contain references to NPM modules using the `$require` property.
64
- * Example:
65
- * ```json
66
- * {
67
- * "agent": {
68
- * "$require": "@veramo/core#Agent",
69
- * "$args": {
70
- * "plugins": [
71
- * { "$require": "@veramo/did-comm#DIDComm" },
72
- * ]
73
- * }
74
- * }
75
- * }
76
- * ```
77
- *
78
- * Environment variables can also be specified using the `$env` property.
79
- *
80
- * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
81
- * more information.
82
- *
83
- * @param config - The configuration object
84
- * @param pointers - A map of JSON pointers to objects within that config that you wish to create
85
- *
86
- * @beta - This API may change without a major version bump
87
- */
88
- function createObjects(config, pointers) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const objects = {};
91
- function resolveRefs(input) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- if (Array.isArray(input)) {
94
- const resolved = [];
95
- for (const item of input) {
96
- resolved.push(yield resolveRefs(item));
97
- }
98
- return resolved;
99
- }
100
- if (typeof input === 'object') {
101
- const resolved = {};
102
- for (const property in input) {
103
- if (input.hasOwnProperty(property)) {
104
- if (property === '$ref') {
105
- const pointer = input[property];
106
- return yield objectFromPointer(pointer);
107
- }
108
- else if (property === '$require') {
109
- return yield objectFromConfig(input);
110
- }
111
- else if (property === '$env') {
112
- return process.env[input[property]];
113
- }
114
- else {
115
- resolved[property] = yield resolveRefs(input[property]);
116
- }
117
- }
118
- }
119
- return resolved;
120
- }
121
- return input;
122
- });
123
- }
124
- function objectFromConfig(objectConfig) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- var _a, _b;
127
- let object;
128
- // console.log('Requiring', objectConfig['$require'])
129
- const parsed = (0, url_parse_1.default)(objectConfig['$require'], {}, true);
130
- let module = parsed.pathname;
131
- const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined;
132
- const type = parsed.query['t'] || 'class';
133
- const pointer = parsed.query['p'];
134
- const args = objectConfig['$args'];
135
- // console.log({module, member, type, query: parsed.query})
136
- if (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {
137
- module = (0, path_1.resolve)(module);
138
- }
139
- const resolvedArgs = args !== undefined ? yield resolveRefs(args) : [];
140
- try {
141
- let required = member ? (yield (_a = module, Promise.resolve().then(() => __importStar(require(_a)))))[member] : yield (_b = module, Promise.resolve().then(() => __importStar(require(_b))));
142
- if (type === 'class') {
143
- object = new required(...resolvedArgs);
144
- }
145
- else if (type === 'function') {
146
- object = required(...resolvedArgs);
147
- }
148
- else if (type === 'object') {
149
- object = required;
150
- }
151
- }
152
- catch (e) {
153
- throw new Error(`Error creating ${module}['${member}']: ${e.message}`);
154
- }
155
- if (pointer) {
156
- return (0, jsonpointer_1.get)(object, pointer);
157
- }
158
- return object;
159
- });
160
- }
161
- function objectFromPointer(pointer) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const existingObject = (0, jsonpointer_1.get)(objects, pointer);
164
- if (existingObject) {
165
- // console.log('Existing', pointer)
166
- return existingObject;
167
- }
168
- else {
169
- // console.log('New', pointer)
170
- const objectConfig = (0, jsonpointer_1.get)(config, pointer);
171
- if (!objectConfig)
172
- throw Error('Pointer not found: ' + pointer);
173
- try {
174
- let object;
175
- if (objectConfig['$require']) {
176
- object = yield objectFromConfig(objectConfig);
177
- }
178
- else if (objectConfig['$env']) {
179
- object = process.env[objectConfig['$env']];
180
- }
181
- else {
182
- object = yield resolveRefs(objectConfig);
183
- }
184
- (0, jsonpointer_1.set)(objects, pointer, object);
185
- return object;
186
- }
187
- catch (e) {
188
- throw Error(e.message + '. While creating object from pointer: ' + pointer);
189
- }
190
- }
191
- });
192
- }
193
- const result = {};
194
- for (const key of Object.keys(pointers)) {
195
- if (pointers.hasOwnProperty(key)) {
196
- result[key] = yield objectFromPointer(pointers[key]);
197
- }
198
- }
199
- return result;
200
- });
201
- }
202
- exports.createObjects = createObjects;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.createObjects = void 0;
39
+ const jsonpointer_1 = require("jsonpointer");
40
+ const url_parse_1 = __importDefault(require("url-parse"));
41
+ const path_1 = require("path");
42
+ /**
43
+ * Creates objects from a configuration object and a set of pointers.
44
+ *
45
+ * Example:
46
+ * ```ts
47
+ * const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
48
+ * ```
49
+ *
50
+ * The config can contain references (`$ref`) to other objects within using JSON pointers.
51
+ * Example:
52
+ * ```json
53
+ * {
54
+ * "rpcUrl": "http://localhost:8545",
55
+ * "endpoint": {
56
+ * "url": {
57
+ * "$ref": "/rpcUrl"
58
+ * }
59
+ * }
60
+ * }
61
+ * ```
62
+ *
63
+ * The config object can also contain references to NPM modules using the `$require` property.
64
+ * Example:
65
+ * ```json
66
+ * {
67
+ * "agent": {
68
+ * "$require": "@veramo/core#Agent",
69
+ * "$args": {
70
+ * "plugins": [
71
+ * { "$require": "@veramo/did-comm#DIDComm" },
72
+ * ]
73
+ * }
74
+ * }
75
+ * }
76
+ * ```
77
+ *
78
+ * Environment variables can also be specified using the `$env` property.
79
+ *
80
+ * @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
81
+ * more information.
82
+ *
83
+ * @param config - The configuration object
84
+ * @param pointers - A map of JSON pointers to objects within that config that you wish to create
85
+ *
86
+ * @beta - This API may change without a major version bump
87
+ */
88
+ function createObjects(config, pointers) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const objects = {};
91
+ function resolveRefs(input) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ if (Array.isArray(input)) {
94
+ const resolved = [];
95
+ for (const item of input) {
96
+ resolved.push(yield resolveRefs(item));
97
+ }
98
+ return resolved;
99
+ }
100
+ if (typeof input === 'object') {
101
+ const resolved = {};
102
+ for (const property in input) {
103
+ if (input.hasOwnProperty(property)) {
104
+ if (property === '$ref') {
105
+ const pointer = input[property];
106
+ return yield objectFromPointer(pointer);
107
+ }
108
+ else if (property === '$require') {
109
+ return yield objectFromConfig(input);
110
+ }
111
+ else if (property === '$env') {
112
+ return process.env[input[property]];
113
+ }
114
+ else {
115
+ resolved[property] = yield resolveRefs(input[property]);
116
+ }
117
+ }
118
+ }
119
+ return resolved;
120
+ }
121
+ return input;
122
+ });
123
+ }
124
+ function objectFromConfig(objectConfig) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ var _a, _b;
127
+ let object;
128
+ // console.log('Requiring', objectConfig['$require'])
129
+ const parsed = (0, url_parse_1.default)(objectConfig['$require'], {}, true);
130
+ let module = parsed.pathname;
131
+ const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined;
132
+ const type = parsed.query['t'] || 'class';
133
+ const pointer = parsed.query['p'];
134
+ const args = objectConfig['$args'];
135
+ // console.log({module, member, type, query: parsed.query})
136
+ if (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {
137
+ module = (0, path_1.resolve)(module);
138
+ }
139
+ const resolvedArgs = args !== undefined ? yield resolveRefs(args) : [];
140
+ try {
141
+ let required = member ? (yield (_a = module, Promise.resolve().then(() => __importStar(require(_a)))))[member] : yield (_b = module, Promise.resolve().then(() => __importStar(require(_b))));
142
+ if (type === 'class') {
143
+ object = new required(...resolvedArgs);
144
+ }
145
+ else if (type === 'function') {
146
+ object = required(...resolvedArgs);
147
+ }
148
+ else if (type === 'object') {
149
+ object = required;
150
+ }
151
+ }
152
+ catch (e) {
153
+ throw new Error(`Error creating ${module}['${member}']: ${e.message}`);
154
+ }
155
+ if (pointer) {
156
+ return (0, jsonpointer_1.get)(object, pointer);
157
+ }
158
+ return object;
159
+ });
160
+ }
161
+ function objectFromPointer(pointer) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const existingObject = (0, jsonpointer_1.get)(objects, pointer);
164
+ if (existingObject) {
165
+ // console.log('Existing', pointer)
166
+ return existingObject;
167
+ }
168
+ else {
169
+ // console.log('New', pointer)
170
+ const objectConfig = (0, jsonpointer_1.get)(config, pointer);
171
+ if (!objectConfig)
172
+ throw Error('Pointer not found: ' + pointer);
173
+ try {
174
+ let object;
175
+ if (objectConfig['$require']) {
176
+ object = yield objectFromConfig(objectConfig);
177
+ }
178
+ else if (objectConfig['$env']) {
179
+ object = process.env[objectConfig['$env']];
180
+ }
181
+ else {
182
+ object = yield resolveRefs(objectConfig);
183
+ }
184
+ (0, jsonpointer_1.set)(objects, pointer, object);
185
+ return object;
186
+ }
187
+ catch (e) {
188
+ throw Error(e.message + '. While creating object from pointer: ' + pointer);
189
+ }
190
+ }
191
+ });
192
+ }
193
+ const result = {};
194
+ for (const key of Object.keys(pointers)) {
195
+ if (pointers.hasOwnProperty(key)) {
196
+ result[key] = yield objectFromPointer(pointers[key]);
197
+ }
198
+ }
199
+ return result;
200
+ });
201
+ }
202
+ exports.createObjects = createObjects;
203
203
  //# sourceMappingURL=objectCreator.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.agent-config",
3
- "version": "0.18.2-next.3+8d0ea61f",
3
+ "version": "0.18.2-unstable.10+f2428c90",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,5 +38,5 @@
38
38
  "SSI",
39
39
  "Agent"
40
40
  ],
41
- "gitHead": "8d0ea61f25e33ef614e9579e727ba319cce5bcc0"
41
+ "gitHead": "f2428c90a2d35170a6c8e6c732ce74add79a4ffe"
42
42
  }