@sphereon/ssi-sdk.agent-config 0.33.1-feature.vcdm2.tsup.31 → 0.33.1-next.2
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/agentContextUtils.d.ts +21 -0
- package/dist/agentContextUtils.d.ts.map +1 -0
- package/dist/agentContextUtils.js +51 -0
- package/dist/agentContextUtils.js.map +1 -0
- package/dist/agentCreator.d.ts +54 -0
- package/dist/agentCreator.d.ts.map +1 -0
- package/dist/agentCreator.js +136 -0
- package/dist/agentCreator.js.map +1 -0
- package/dist/dataSources.d.ts +45 -0
- package/dist/dataSources.d.ts.map +1 -0
- package/dist/dataSources.js +152 -0
- package/dist/dataSources.js.map +1 -0
- package/dist/generic.d.ts +7 -0
- package/dist/generic.d.ts.map +1 -0
- package/dist/generic.js +3 -0
- package/dist/generic.js.map +1 -0
- package/dist/index.d.ts +7 -183
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -400
- package/dist/index.js.map +1 -1
- package/dist/objectCreator.d.ts +48 -0
- package/dist/objectCreator.d.ts.map +1 -0
- package/dist/objectCreator.js +201 -0
- package/dist/objectCreator.js.map +1 -0
- package/dist/typeormTypes.d.ts +11 -0
- package/dist/typeormTypes.d.ts.map +1 -0
- package/dist/typeormTypes.js +31 -0
- package/dist/typeormTypes.js.map +1 -0
- package/package.json +11 -23
- package/src/dataSources.ts +4 -3
- package/src/objectCreator.ts +22 -57
- package/dist/index.cjs +0 -433
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -186
package/dist/index.d.ts
CHANGED
|
@@ -1,186 +1,10 @@
|
|
|
1
|
-
import { IPluginMethodMap, IAgentContext, IKeyManager, IResolver, IDIDManager, ICredentialIssuer, ICredentialVerifier, ICredentialStatusVerifier, IDataStore, IDataStoreORM, TAgent, IAgentOptions } from '@veramo/core';
|
|
2
|
-
import { DataSource } from 'typeorm/data-source/DataSource.js';
|
|
3
|
-
import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions.js';
|
|
4
|
-
import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
|
-
* Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)
|
|
8
|
-
* @param context Tje agent context to check against
|
|
9
|
-
* @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
|
|
10
|
-
*/
|
|
11
|
-
declare function contextHasPlugin<Plugins extends IPluginMethodMap>(context: IAgentContext<any>, requiredMethod: string | string[]): context is IAgentContext<Plugins>;
|
|
12
|
-
/**
|
|
13
|
-
* The below methods are convenience methods to directly get the appropriate context after calling the respective method
|
|
14
|
-
*
|
|
15
|
-
* @param context
|
|
16
|
-
*/
|
|
17
|
-
declare function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager>;
|
|
18
|
-
declare function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager>;
|
|
19
|
-
declare function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver>;
|
|
20
|
-
declare function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer>;
|
|
21
|
-
declare function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier>;
|
|
22
|
-
declare function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier>;
|
|
23
|
-
declare function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore>;
|
|
24
|
-
declare function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM>;
|
|
25
|
-
|
|
26
|
-
declare class DataSources {
|
|
27
|
-
get defaultDbType(): SupportedDatabaseType;
|
|
28
|
-
set defaultDbType(value: SupportedDatabaseType);
|
|
29
|
-
private dataSources;
|
|
30
|
-
private configs;
|
|
31
|
-
private _defaultDbType;
|
|
32
|
-
private static singleton;
|
|
33
|
-
static singleInstance(): DataSources;
|
|
34
|
-
static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
|
|
35
|
-
private constructor();
|
|
36
|
-
addConfig(dbName: string, config: DataSourceOptions): this;
|
|
37
|
-
deleteConfig(dbName: string): this;
|
|
38
|
-
has(dbName: string): boolean;
|
|
39
|
-
delete(dbName: string): this;
|
|
40
|
-
getConfig(dbName: string): BaseDataSourceOptions;
|
|
41
|
-
getDbNames(): string[];
|
|
42
|
-
getDbConnection(dbName: string): Promise<DataSource>;
|
|
43
|
-
}
|
|
44
|
-
type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
|
|
45
|
-
type DateTimeType = 'timestamp' | 'datetime';
|
|
46
|
-
type DateType = 'date';
|
|
47
|
-
/**
|
|
48
|
-
* Gets the database connection.
|
|
49
|
-
*
|
|
50
|
-
* Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time
|
|
51
|
-
*
|
|
52
|
-
* @param connectionName The database name
|
|
53
|
-
* @param opts
|
|
54
|
-
*/
|
|
55
|
-
declare const getDbConnection: (connectionName: string, opts?: {
|
|
56
|
-
config: BaseDataSourceOptions | any;
|
|
57
|
-
}) => Promise<DataSource>;
|
|
58
|
-
declare const dropDatabase: (dbName: string, opts?: {
|
|
59
|
-
removeDataSource?: boolean;
|
|
60
|
-
}) => Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* Runs a migration down (drops DB schema)
|
|
63
|
-
* @param dataSource
|
|
64
|
-
*/
|
|
65
|
-
declare const revertMigration: (dataSource: DataSource) => Promise<void>;
|
|
66
|
-
declare const resetDatabase: (dbName: string) => Promise<void>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Creates a Veramo agent from a config object containing an `/agent` pointer.
|
|
70
|
-
* @param config - The configuration object
|
|
71
|
-
*
|
|
72
|
-
* @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
|
|
73
|
-
* the configuration options.
|
|
74
|
-
*
|
|
75
|
-
* @beta - This API may change without a major version bump
|
|
76
|
-
*/
|
|
77
|
-
declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
|
|
78
|
-
/**
|
|
79
|
-
* Helper function to create a new instance of the {@link Agent} class with correct type
|
|
80
|
-
*
|
|
81
|
-
* @remarks
|
|
82
|
-
* Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
|
|
87
|
-
* import { AgentRestClient } from '@veramo/remote-client'
|
|
88
|
-
* import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
|
|
89
|
-
* const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
|
|
90
|
-
* plugins: [
|
|
91
|
-
* new CredentialIssuer(),
|
|
92
|
-
* new AgentRestClient({
|
|
93
|
-
* url: 'http://localhost:3002/agent',
|
|
94
|
-
* enabledMethods: [
|
|
95
|
-
* 'resolveDid',
|
|
96
|
-
* 'handleMessage',
|
|
97
|
-
* ],
|
|
98
|
-
* }),
|
|
99
|
-
* ],
|
|
100
|
-
* })
|
|
101
|
-
* ```
|
|
102
|
-
* @param options - Agent configuration options
|
|
103
|
-
* @returns configured agent
|
|
104
2
|
* @public
|
|
105
3
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
* @param filePath
|
|
114
|
-
*/
|
|
115
|
-
declare const getConfig: (filePath: string | Buffer | URL) => Promise<{
|
|
116
|
-
version?: number;
|
|
117
|
-
[x: string]: any;
|
|
118
|
-
}>;
|
|
119
|
-
declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Creates objects from a configuration object and a set of pointers.
|
|
123
|
-
*
|
|
124
|
-
* Example:
|
|
125
|
-
* ```ts
|
|
126
|
-
* const { url } = createObjects({ "rpcUrl": "http://localhost:8545", }, { url: '/rpcUrl' })
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* The config can contain references (`$ref`) to other objects within using JSON pointers.
|
|
130
|
-
* Example:
|
|
131
|
-
* ```json
|
|
132
|
-
* {
|
|
133
|
-
* "rpcUrl": "http://localhost:8545",
|
|
134
|
-
* "endpoint": {
|
|
135
|
-
* "url": {
|
|
136
|
-
* "$ref": "/rpcUrl"
|
|
137
|
-
* }
|
|
138
|
-
* }
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* The config object can also contain references to NPM modules using the `$require` property.
|
|
143
|
-
* Example:
|
|
144
|
-
* ```json
|
|
145
|
-
* {
|
|
146
|
-
* "agent": {
|
|
147
|
-
* "$require": "@veramo/core#Agent",
|
|
148
|
-
* "$args": {
|
|
149
|
-
* "plugins": [
|
|
150
|
-
* { "$require": "@veramo/did-comm#DIDComm" },
|
|
151
|
-
* ]
|
|
152
|
-
* }
|
|
153
|
-
* }
|
|
154
|
-
* }
|
|
155
|
-
* ```
|
|
156
|
-
*
|
|
157
|
-
* Environment variables can also be specified using the `$env` property.
|
|
158
|
-
*
|
|
159
|
-
* @see Please see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for
|
|
160
|
-
* more information.
|
|
161
|
-
*
|
|
162
|
-
* @param config - The configuration object
|
|
163
|
-
* @param pointers - A map of JSON pointers to objects within that config that you wish to create
|
|
164
|
-
*
|
|
165
|
-
* @beta - This API may change without a major version bump
|
|
166
|
-
*/
|
|
167
|
-
declare function createObjects(config: object, pointers: Record<string, string>): Promise<Record<string, any>>;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Accept a Type or a Promise of that Type.
|
|
171
|
-
*
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
type OrPromise<T> = T | Promise<T>;
|
|
175
|
-
|
|
176
|
-
declare const getDbType: (opts?: {
|
|
177
|
-
defaultType: SupportedDatabaseType;
|
|
178
|
-
}) => SupportedDatabaseType;
|
|
179
|
-
declare const typeOrmDateTime: (opts?: {
|
|
180
|
-
defaultType: SupportedDatabaseType;
|
|
181
|
-
}) => DateTimeType;
|
|
182
|
-
declare const typeormDate: (opts?: {
|
|
183
|
-
defaultType: SupportedDatabaseType;
|
|
184
|
-
}) => DateType;
|
|
185
|
-
|
|
186
|
-
export { DataSources, type DateTimeType, type DateType, type OrPromise, type SupportedDatabaseType, contextHasCredentialIssuer, contextHasCredentialStatusVerifier, contextHasCredentialVerifier, contextHasDataStore, contextHasDataStoreORM, contextHasDidManager, contextHasDidResolver, contextHasKeyManager, contextHasPlugin, createAgent, createAgentFromConfig, createObjects, dropDatabase, getAgent, getConfig, getDbConnection, getDbType, resetDatabase, revertMigration, typeOrmDateTime, typeormDate };
|
|
4
|
+
export * from './agentContextUtils';
|
|
5
|
+
export * from './dataSources';
|
|
6
|
+
export * from './agentCreator';
|
|
7
|
+
export * from './objectCreator';
|
|
8
|
+
export * from './generic';
|
|
9
|
+
export * from './typeormTypes';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,402 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
__name(contextHasKeyManager, "contextHasKeyManager");
|
|
17
|
-
function contextHasDidManager(context) {
|
|
18
|
-
return contextHasPlugin(context, "didManagerGet");
|
|
19
|
-
}
|
|
20
|
-
__name(contextHasDidManager, "contextHasDidManager");
|
|
21
|
-
function contextHasDidResolver(context) {
|
|
22
|
-
return contextHasPlugin(context, "resolveDid");
|
|
23
|
-
}
|
|
24
|
-
__name(contextHasDidResolver, "contextHasDidResolver");
|
|
25
|
-
function contextHasCredentialIssuer(context) {
|
|
26
|
-
return contextHasPlugin(context, [
|
|
27
|
-
"createVerifiableCredential",
|
|
28
|
-
"createVerifiablePresentation"
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
__name(contextHasCredentialIssuer, "contextHasCredentialIssuer");
|
|
32
|
-
function contextHasCredentialVerifier(context) {
|
|
33
|
-
return contextHasPlugin(context, [
|
|
34
|
-
"verifyCredential",
|
|
35
|
-
"verifyPresentation"
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
__name(contextHasCredentialVerifier, "contextHasCredentialVerifier");
|
|
39
|
-
function contextHasCredentialStatusVerifier(context) {
|
|
40
|
-
return contextHasPlugin(context, [
|
|
41
|
-
"checkCredentialStatus"
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
__name(contextHasCredentialStatusVerifier, "contextHasCredentialStatusVerifier");
|
|
45
|
-
function contextHasDataStore(context) {
|
|
46
|
-
return contextHasPlugin(context, [
|
|
47
|
-
"dataStoreGetVerifiableCredential",
|
|
48
|
-
"dataStoreGetVerifiablePresentation"
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
__name(contextHasDataStore, "contextHasDataStore");
|
|
52
|
-
function contextHasDataStoreORM(context) {
|
|
53
|
-
return contextHasPlugin(context, [
|
|
54
|
-
"dataStoreORMGetVerifiableCredentials",
|
|
55
|
-
"dataStoreORMGetVerifiablePresentations"
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
__name(contextHasDataStoreORM, "contextHasDataStoreORM");
|
|
59
|
-
|
|
60
|
-
// src/dataSources.ts
|
|
61
|
-
import Debug from "debug";
|
|
62
|
-
import { DataSource } from "typeorm/data-source/DataSource.js";
|
|
63
|
-
var debug = Debug(`sphereon:ssi-sdk:database`);
|
|
64
|
-
var DataSources = class _DataSources {
|
|
65
|
-
static {
|
|
66
|
-
__name(this, "DataSources");
|
|
67
|
-
}
|
|
68
|
-
get defaultDbType() {
|
|
69
|
-
return this._defaultDbType;
|
|
70
|
-
}
|
|
71
|
-
set defaultDbType(value) {
|
|
72
|
-
this._defaultDbType = value;
|
|
73
|
-
}
|
|
74
|
-
dataSources = /* @__PURE__ */ new Map();
|
|
75
|
-
configs = /* @__PURE__ */ new Map();
|
|
76
|
-
_defaultDbType = "sqlite";
|
|
77
|
-
static singleton;
|
|
78
|
-
static singleInstance() {
|
|
79
|
-
if (!_DataSources.singleton) {
|
|
80
|
-
_DataSources.singleton = new _DataSources();
|
|
81
|
-
}
|
|
82
|
-
return _DataSources.singleton;
|
|
83
|
-
}
|
|
84
|
-
static newInstance(configs) {
|
|
85
|
-
return new _DataSources(configs);
|
|
86
|
-
}
|
|
87
|
-
constructor(configs) {
|
|
88
|
-
;
|
|
89
|
-
(configs ?? /* @__PURE__ */ new Map()).forEach((config, name) => this.addConfig(name, config));
|
|
90
|
-
}
|
|
91
|
-
addConfig(dbName, config) {
|
|
92
|
-
this.configs.set(dbName, config);
|
|
93
|
-
this._defaultDbType = config.type;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
deleteConfig(dbName) {
|
|
97
|
-
this.configs.delete(dbName);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
has(dbName) {
|
|
101
|
-
return this.configs.has(dbName) && this.dataSources.has(dbName);
|
|
102
|
-
}
|
|
103
|
-
delete(dbName) {
|
|
104
|
-
this.deleteConfig(dbName);
|
|
105
|
-
this.dataSources.delete(dbName);
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
getConfig(dbName) {
|
|
109
|
-
const config = this.configs.get(dbName);
|
|
110
|
-
if (!config) {
|
|
111
|
-
throw Error(`No DB config found for ${dbName}`);
|
|
112
|
-
}
|
|
113
|
-
return config;
|
|
114
|
-
}
|
|
115
|
-
getDbNames() {
|
|
116
|
-
return [
|
|
117
|
-
...this.configs.keys()
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
async getDbConnection(dbName) {
|
|
121
|
-
const config = this.getConfig(dbName);
|
|
122
|
-
if (!this._defaultDbType) {
|
|
123
|
-
this._defaultDbType = config.type;
|
|
124
|
-
}
|
|
125
|
-
let dataSource = this.dataSources.get(dbName);
|
|
126
|
-
if (dataSource) {
|
|
127
|
-
return dataSource;
|
|
128
|
-
}
|
|
129
|
-
dataSource = await new DataSource({
|
|
130
|
-
...config,
|
|
131
|
-
name: dbName
|
|
132
|
-
}).initialize();
|
|
133
|
-
this.dataSources.set(dbName, dataSource);
|
|
134
|
-
if (config.synchronize) {
|
|
135
|
-
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
136
|
-
} else if (config.migrationsRun) {
|
|
137
|
-
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
138
|
-
} else {
|
|
139
|
-
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
140
|
-
await dataSource.runMigrations();
|
|
141
|
-
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
|
142
|
-
}
|
|
143
|
-
return dataSource;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
var getDbConnection = /* @__PURE__ */ __name(async (connectionName, opts) => {
|
|
147
|
-
if (!DataSources.singleInstance().has(connectionName) && opts?.config) {
|
|
148
|
-
DataSources.singleInstance().addConfig(connectionName, opts?.config);
|
|
149
|
-
}
|
|
150
|
-
return DataSources.singleInstance().getDbConnection(connectionName);
|
|
151
|
-
}, "getDbConnection");
|
|
152
|
-
var dropDatabase = /* @__PURE__ */ __name(async (dbName, opts) => {
|
|
153
|
-
const { removeDataSource = false } = {
|
|
154
|
-
...opts
|
|
155
|
-
};
|
|
156
|
-
if (!DataSources.singleInstance().has(dbName)) {
|
|
157
|
-
return Promise.reject(Error(`No database present with name: ${dbName}`));
|
|
158
|
-
}
|
|
159
|
-
const connection = await getDbConnection(dbName);
|
|
160
|
-
await connection.dropDatabase();
|
|
161
|
-
if (removeDataSource) {
|
|
162
|
-
DataSources.singleInstance().delete(dbName);
|
|
163
|
-
} else if (!connection.isInitialized) {
|
|
164
|
-
await connection.initialize();
|
|
165
|
-
}
|
|
166
|
-
}, "dropDatabase");
|
|
167
|
-
var revertMigration = /* @__PURE__ */ __name(async (dataSource) => {
|
|
168
|
-
if (dataSource.isInitialized) {
|
|
169
|
-
await dataSource.undoLastMigration();
|
|
170
|
-
} else {
|
|
171
|
-
console.error("DataSource is not initialized");
|
|
172
|
-
}
|
|
173
|
-
}, "revertMigration");
|
|
174
|
-
var resetDatabase = /* @__PURE__ */ __name(async (dbName) => {
|
|
175
|
-
await dropDatabase(dbName);
|
|
176
|
-
const connection = await getDbConnection(dbName);
|
|
177
|
-
await connection.runMigrations();
|
|
178
|
-
}, "resetDatabase");
|
|
179
|
-
|
|
180
|
-
// src/objectCreator.ts
|
|
181
|
-
import { set, get } from "jsonpointer";
|
|
182
|
-
import parse from "url-parse";
|
|
183
|
-
async function createObjects(config, pointers) {
|
|
184
|
-
const objects = {};
|
|
185
|
-
async function resolveRefs(input) {
|
|
186
|
-
if (Array.isArray(input)) {
|
|
187
|
-
const resolved = [];
|
|
188
|
-
for (const item of input) {
|
|
189
|
-
resolved.push(await resolveRefs(item));
|
|
190
|
-
}
|
|
191
|
-
return resolved;
|
|
192
|
-
}
|
|
193
|
-
if (typeof input === "object") {
|
|
194
|
-
const resolved = {};
|
|
195
|
-
for (const property in input) {
|
|
196
|
-
if (input.hasOwnProperty(property)) {
|
|
197
|
-
if (property === "$ref") {
|
|
198
|
-
const pointer = input[property];
|
|
199
|
-
return await objectFromPointer(pointer);
|
|
200
|
-
} else if (property === "$require") {
|
|
201
|
-
return await objectFromConfig(input);
|
|
202
|
-
} else if (property === "$env") {
|
|
203
|
-
return process.env[input[property]];
|
|
204
|
-
} else {
|
|
205
|
-
resolved[property] = await resolveRefs(input[property]);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return resolved;
|
|
210
|
-
}
|
|
211
|
-
return input;
|
|
212
|
-
}
|
|
213
|
-
__name(resolveRefs, "resolveRefs");
|
|
214
|
-
async function objectFromConfig(objectConfig) {
|
|
215
|
-
console.log("Requiring", objectConfig["$require"]);
|
|
216
|
-
const parsed = parse(objectConfig["$require"], {}, true);
|
|
217
|
-
let npmModule = parsed.pathname;
|
|
218
|
-
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : void 0;
|
|
219
|
-
console.log(`member: ${member}`);
|
|
220
|
-
const type = parsed.query["t"] || "class";
|
|
221
|
-
const pointer = parsed.query["p"];
|
|
222
|
-
const args = objectConfig["$args"];
|
|
223
|
-
console.log({
|
|
224
|
-
module,
|
|
225
|
-
member,
|
|
226
|
-
type,
|
|
227
|
-
query: parsed.query,
|
|
228
|
-
pointer,
|
|
229
|
-
args
|
|
230
|
-
});
|
|
231
|
-
if (npmModule.slice(0, 2) === "./" || npmModule.slice(0, 3) === "../") {
|
|
232
|
-
console.log("objectFromConfig: Resolving relative path", npmModule);
|
|
233
|
-
const { resolve } = await import("path");
|
|
234
|
-
npmModule = resolve(npmModule);
|
|
235
|
-
}
|
|
236
|
-
const resolvedArgs = args !== void 0 ? await resolveRefs(args) : [];
|
|
237
|
-
console.error(`npmModule: ${npmModule}`);
|
|
238
|
-
return await Promise.resolve(await import(
|
|
239
|
-
/*@metro-ignore*/
|
|
240
|
-
npmModule
|
|
241
|
-
).then((mod) => {
|
|
242
|
-
if (member) {
|
|
243
|
-
return mod[member];
|
|
244
|
-
}
|
|
245
|
-
return mod;
|
|
246
|
-
}).then((required) => {
|
|
247
|
-
let object;
|
|
248
|
-
if (type === "class") {
|
|
249
|
-
object = new required(...resolvedArgs);
|
|
250
|
-
} else if (type === "function") {
|
|
251
|
-
object = required(...resolvedArgs);
|
|
252
|
-
} else if (type === "object") {
|
|
253
|
-
object = required;
|
|
254
|
-
} else {
|
|
255
|
-
console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`);
|
|
256
|
-
}
|
|
257
|
-
if (!pointer) {
|
|
258
|
-
return object;
|
|
259
|
-
}
|
|
260
|
-
if (!object) {
|
|
261
|
-
return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`));
|
|
262
|
-
}
|
|
263
|
-
return get(object, pointer);
|
|
264
|
-
}).catch((e) => {
|
|
265
|
-
console.error(e);
|
|
266
|
-
return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`));
|
|
267
|
-
}));
|
|
268
|
-
}
|
|
269
|
-
__name(objectFromConfig, "objectFromConfig");
|
|
270
|
-
async function objectFromPointer(pointer) {
|
|
271
|
-
const existingObject = get(objects, pointer);
|
|
272
|
-
if (existingObject) {
|
|
273
|
-
return existingObject;
|
|
274
|
-
} else {
|
|
275
|
-
const objectConfig = get(config, pointer);
|
|
276
|
-
if (!objectConfig) throw Error("Pointer not found: " + pointer);
|
|
277
|
-
try {
|
|
278
|
-
let object;
|
|
279
|
-
if (objectConfig["$require"]) {
|
|
280
|
-
object = await objectFromConfig(objectConfig);
|
|
281
|
-
} else if (objectConfig["$env"]) {
|
|
282
|
-
object = process.env[objectConfig["$env"]];
|
|
283
|
-
} else {
|
|
284
|
-
object = await resolveRefs(objectConfig);
|
|
285
|
-
}
|
|
286
|
-
set(objects, pointer, object);
|
|
287
|
-
return object;
|
|
288
|
-
} catch (e) {
|
|
289
|
-
console.log(e);
|
|
290
|
-
throw Error(e.message + ". While creating object from pointer: " + pointer);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
__name(objectFromPointer, "objectFromPointer");
|
|
295
|
-
const result = {};
|
|
296
|
-
for (const key of Object.keys(pointers)) {
|
|
297
|
-
if (pointers.hasOwnProperty(key)) {
|
|
298
|
-
result[key] = await objectFromPointer(pointers[key]);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
|
-
__name(createObjects, "createObjects");
|
|
304
|
-
|
|
305
|
-
// src/agentCreator.ts
|
|
306
|
-
import yaml from "yaml";
|
|
307
|
-
async function createAgentFromConfig(config) {
|
|
308
|
-
const { agent } = await createObjects(config, {
|
|
309
|
-
agent: "/agent"
|
|
310
|
-
});
|
|
311
|
-
return agent;
|
|
312
|
-
}
|
|
313
|
-
__name(createAgentFromConfig, "createAgentFromConfig");
|
|
314
|
-
async function createAgent(options) {
|
|
315
|
-
return new Agent(options);
|
|
316
|
-
}
|
|
317
|
-
__name(createAgent, "createAgent");
|
|
318
|
-
var getConfig = /* @__PURE__ */ __name(async (filePath) => {
|
|
319
|
-
let fileContent;
|
|
320
|
-
try {
|
|
321
|
-
const fs = await import(
|
|
322
|
-
/* webpackIgnore: true */
|
|
323
|
-
"fs"
|
|
324
|
-
);
|
|
325
|
-
fileContent = await fs.promises.readFile(filePath, "utf8");
|
|
326
|
-
} catch (e) {
|
|
327
|
-
console.log("Config file not found: " + filePath);
|
|
328
|
-
console.log('Use "veramo config create" to create one');
|
|
329
|
-
process.exit(1);
|
|
330
|
-
}
|
|
331
|
-
let config;
|
|
332
|
-
try {
|
|
333
|
-
config = yaml.parse(fileContent, {
|
|
334
|
-
prettyErrors: true
|
|
335
|
-
});
|
|
336
|
-
} catch (e) {
|
|
337
|
-
console.error(`Unable to parse config file: ${e.message} ${e.linePos}`);
|
|
338
|
-
process.exit(1);
|
|
339
|
-
}
|
|
340
|
-
if (config?.version != 3) {
|
|
341
|
-
console.error("Unsupported configuration file version:", config.version);
|
|
342
|
-
process.exit(1);
|
|
343
|
-
}
|
|
344
|
-
return config;
|
|
345
|
-
}, "getConfig");
|
|
346
|
-
async function getAgent(fileName) {
|
|
347
|
-
try {
|
|
348
|
-
return await createAgentFromConfig(await getConfig(fileName));
|
|
349
|
-
} catch (e) {
|
|
350
|
-
console.log("Unable to create agent from " + fileName + ".", e.message);
|
|
351
|
-
process.exit(1);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
__name(getAgent, "getAgent");
|
|
355
|
-
|
|
356
|
-
// src/typeormTypes.ts
|
|
357
|
-
var getDbType = /* @__PURE__ */ __name((opts) => {
|
|
358
|
-
const type = (typeof process === "object" ? process?.env?.DB_TYPE : void 0) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType;
|
|
359
|
-
if (!type) {
|
|
360
|
-
throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`);
|
|
361
|
-
}
|
|
362
|
-
return type;
|
|
363
|
-
}, "getDbType");
|
|
364
|
-
var typeOrmDateTime = /* @__PURE__ */ __name((opts) => {
|
|
365
|
-
switch (getDbType(opts)) {
|
|
366
|
-
case "postgres":
|
|
367
|
-
return "timestamp";
|
|
368
|
-
case "sqlite":
|
|
369
|
-
case "react-native":
|
|
370
|
-
return "datetime";
|
|
371
|
-
default:
|
|
372
|
-
throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`);
|
|
373
|
-
}
|
|
374
|
-
}, "typeOrmDateTime");
|
|
375
|
-
var typeormDate = /* @__PURE__ */ __name((opts) => {
|
|
376
|
-
return "date";
|
|
377
|
-
}, "typeormDate");
|
|
378
|
-
export {
|
|
379
|
-
DataSources,
|
|
380
|
-
contextHasCredentialIssuer,
|
|
381
|
-
contextHasCredentialStatusVerifier,
|
|
382
|
-
contextHasCredentialVerifier,
|
|
383
|
-
contextHasDataStore,
|
|
384
|
-
contextHasDataStoreORM,
|
|
385
|
-
contextHasDidManager,
|
|
386
|
-
contextHasDidResolver,
|
|
387
|
-
contextHasKeyManager,
|
|
388
|
-
contextHasPlugin,
|
|
389
|
-
createAgent,
|
|
390
|
-
createAgentFromConfig,
|
|
391
|
-
createObjects,
|
|
392
|
-
dropDatabase,
|
|
393
|
-
getAgent,
|
|
394
|
-
getConfig,
|
|
395
|
-
getDbConnection,
|
|
396
|
-
getDbType,
|
|
397
|
-
resetDatabase,
|
|
398
|
-
revertMigration,
|
|
399
|
-
typeOrmDateTime,
|
|
400
|
-
typeormDate
|
|
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);
|
|
401
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
__exportStar(require("./agentContextUtils"), exports);
|
|
21
|
+
__exportStar(require("./dataSources"), exports);
|
|
22
|
+
__exportStar(require("./agentCreator"), exports);
|
|
23
|
+
__exportStar(require("./objectCreator"), exports);
|
|
24
|
+
__exportStar(require("./generic"), exports);
|
|
25
|
+
__exportStar(require("./typeormTypes"), exports);
|
|
402
26
|
//# sourceMappingURL=index.js.map
|