@sphereon/ssi-sdk.agent-config 0.33.1-next.2 → 0.33.1-next.68
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 +436 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +186 -0
- package/dist/index.d.ts +183 -7
- package/dist/index.js +403 -24
- package/dist/index.js.map +1 -1
- package/package.json +23 -11
- package/src/agentContextUtils.ts +1 -1
- package/src/agentCreator.ts +1 -2
- package/src/dataSources.ts +3 -4
- package/src/objectCreator.ts +59 -22
- package/src/typeormTypes.ts +1 -1
- package/dist/agentContextUtils.d.ts +0 -21
- package/dist/agentContextUtils.d.ts.map +0 -1
- package/dist/agentContextUtils.js +0 -51
- package/dist/agentContextUtils.js.map +0 -1
- package/dist/agentCreator.d.ts +0 -54
- package/dist/agentCreator.d.ts.map +0 -1
- package/dist/agentCreator.js +0 -136
- package/dist/agentCreator.js.map +0 -1
- package/dist/dataSources.d.ts +0 -45
- package/dist/dataSources.d.ts.map +0 -1
- package/dist/dataSources.js +0 -152
- package/dist/dataSources.js.map +0 -1
- package/dist/generic.d.ts +0 -7
- package/dist/generic.d.ts.map +0 -1
- package/dist/generic.js +0 -3
- package/dist/generic.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/objectCreator.d.ts +0 -48
- package/dist/objectCreator.d.ts.map +0 -1
- package/dist/objectCreator.js +0 -201
- package/dist/objectCreator.js.map +0 -1
- package/dist/typeormTypes.d.ts +0 -11
- package/dist/typeormTypes.d.ts.map +0 -1
- package/dist/typeormTypes.js +0 -31
- package/dist/typeormTypes.js.map +0 -1
package/src/objectCreator.ts
CHANGED
|
@@ -82,38 +82,74 @@ export async function createObjects(config: object, pointers: Record<string, str
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
async function objectFromConfig(objectConfig: any): Promise<any> {
|
|
85
|
-
|
|
86
|
-
// console.log('Requiring', objectConfig['$require'])
|
|
85
|
+
console.log('Requiring', objectConfig['$require'])
|
|
87
86
|
const parsed = parse(objectConfig['$require'], {}, true)
|
|
88
|
-
let
|
|
87
|
+
let npmModule = parsed.pathname
|
|
89
88
|
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined
|
|
89
|
+
console.log(`member: ${member}`)
|
|
90
90
|
const type = parsed.query['t'] || 'class'
|
|
91
91
|
const pointer = parsed.query['p']
|
|
92
92
|
const args = objectConfig['$args']
|
|
93
|
-
|
|
93
|
+
console.log({ module, member, type, query: parsed.query, pointer, args })
|
|
94
94
|
|
|
95
|
-
if (
|
|
95
|
+
if (npmModule.slice(0, 2) === './' || npmModule.slice(0, 3) === '../') {
|
|
96
|
+
console.log('objectFromConfig: Resolving relative path', npmModule)
|
|
96
97
|
const { resolve } = await import('path')
|
|
97
|
-
|
|
98
|
+
npmModule = resolve(npmModule)
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
const resolvedArgs = args !== undefined ? await resolveRefs(args) : []
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
console.error(`npmModule: ${npmModule}`)
|
|
103
|
+
// try {
|
|
104
|
+
return await Promise.resolve(
|
|
105
|
+
await import(/*@metro-ignore*/ npmModule)
|
|
106
|
+
|
|
107
|
+
.then((mod) => {
|
|
108
|
+
if (member) {
|
|
109
|
+
return mod[member]
|
|
110
|
+
}
|
|
111
|
+
return mod
|
|
112
|
+
})
|
|
113
|
+
.then((required) => {
|
|
114
|
+
let object: any
|
|
115
|
+
if (type === 'class') {
|
|
116
|
+
object = new required(...resolvedArgs)
|
|
117
|
+
} else if (type === 'function') {
|
|
118
|
+
object = required(...resolvedArgs)
|
|
119
|
+
} else if (type === 'object') {
|
|
120
|
+
object = required
|
|
121
|
+
} else {
|
|
122
|
+
console.error(`Likely we have a bug in agent object creation. type = ${type} is not of type class, function or object`)
|
|
123
|
+
}
|
|
124
|
+
if (!pointer) {
|
|
125
|
+
return object
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!object) {
|
|
129
|
+
return Promise.reject(Error(`Error creating ${npmModule}['${member}']: Object is undefined and pointer was present requiring an object.`))
|
|
130
|
+
}
|
|
131
|
+
return get(object, pointer)
|
|
132
|
+
})
|
|
133
|
+
.catch((e) => {
|
|
134
|
+
console.error(e)
|
|
135
|
+
return Promise.reject(Error(`Error creating ${npmModule}['${member}']: ${e.message}`))
|
|
136
|
+
}),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
/*let required = member ? (await import(npmModule))[member] : await import(npmModule)
|
|
140
|
+
if (type === 'class') {
|
|
141
|
+
object = new required(...resolvedArgs)
|
|
142
|
+
} else if (type === 'function') {
|
|
143
|
+
object = required(...resolvedArgs)
|
|
144
|
+
} else if (type === 'object') {
|
|
145
|
+
object = required
|
|
146
|
+
}*/
|
|
147
|
+
// } catch (e: any) {
|
|
148
|
+
// console.log(e)
|
|
149
|
+
// throw new Error(`Error creating ${npmModule}['${member}']: ${e.message}`)
|
|
150
|
+
// }
|
|
151
|
+
|
|
152
|
+
// return object
|
|
117
153
|
}
|
|
118
154
|
|
|
119
155
|
async function objectFromPointer(pointer: string) {
|
|
@@ -137,6 +173,7 @@ export async function createObjects(config: object, pointers: Record<string, str
|
|
|
137
173
|
set(objects, pointer, object)
|
|
138
174
|
return object
|
|
139
175
|
} catch (e: any) {
|
|
176
|
+
console.log(e)
|
|
140
177
|
throw Error(e.message + '. While creating object from pointer: ' + pointer)
|
|
141
178
|
}
|
|
142
179
|
}
|
package/src/typeormTypes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataSources, DateTimeType, DateType, SupportedDatabaseType } from './dataSources'
|
|
1
|
+
import { DataSources, type DateTimeType, type DateType, type SupportedDatabaseType } from './dataSources'
|
|
2
2
|
|
|
3
3
|
export const getDbType = (opts?: { defaultType: SupportedDatabaseType }): SupportedDatabaseType => {
|
|
4
4
|
const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IAgentContext, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IPluginMethodMap, IResolver, ICredentialIssuer, ICredentialStatusVerifier } from '@veramo/core';
|
|
2
|
-
/**
|
|
3
|
-
* Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)
|
|
4
|
-
* @param context Tje agent context to check against
|
|
5
|
-
* @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
|
|
6
|
-
*/
|
|
7
|
-
export declare function contextHasPlugin<Plugins extends IPluginMethodMap>(context: IAgentContext<any>, requiredMethod: string | string[]): context is IAgentContext<Plugins>;
|
|
8
|
-
/**
|
|
9
|
-
* The below methods are convenience methods to directly get the appropriate context after calling the respective method
|
|
10
|
-
*
|
|
11
|
-
* @param context
|
|
12
|
-
*/
|
|
13
|
-
export declare function contextHasKeyManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IKeyManager>;
|
|
14
|
-
export declare function contextHasDidManager(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver & IDIDManager>;
|
|
15
|
-
export declare function contextHasDidResolver(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IResolver>;
|
|
16
|
-
export declare function contextHasCredentialIssuer(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialIssuer>;
|
|
17
|
-
export declare function contextHasCredentialVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialVerifier>;
|
|
18
|
-
export declare function contextHasCredentialStatusVerifier(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<ICredentialStatusVerifier>;
|
|
19
|
-
export declare function contextHasDataStore(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStore>;
|
|
20
|
-
export declare function contextHasDataStoreORM(context: IAgentContext<IPluginMethodMap>): context is IAgentContext<IDataStoreORM>;
|
|
21
|
-
//# sourceMappingURL=agentContextUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentContextUtils.d.ts","sourceRoot":"","sources":["../src/agentContextUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,cAAc,CAAA;AAErB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,gBAAgB,EAC/D,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,EAC3B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,GAChC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAInC;AAED;;;;GAIG;AAEH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,CAEpH;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,SAAS,GAAG,WAAW,CAAC,CAEhI;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,CAEnH;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,iBAAiB,CAAC,CAEhI;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAEpI;AAED,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,yBAAyB,CAAC,CAEhJ;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAElH;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,OAAO,IAAI,aAAa,CAAC,aAAa,CAAC,CAExH"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contextHasPlugin = contextHasPlugin;
|
|
4
|
-
exports.contextHasKeyManager = contextHasKeyManager;
|
|
5
|
-
exports.contextHasDidManager = contextHasDidManager;
|
|
6
|
-
exports.contextHasDidResolver = contextHasDidResolver;
|
|
7
|
-
exports.contextHasCredentialIssuer = contextHasCredentialIssuer;
|
|
8
|
-
exports.contextHasCredentialVerifier = contextHasCredentialVerifier;
|
|
9
|
-
exports.contextHasCredentialStatusVerifier = contextHasCredentialStatusVerifier;
|
|
10
|
-
exports.contextHasDataStore = contextHasDataStore;
|
|
11
|
-
exports.contextHasDataStoreORM = contextHasDataStoreORM;
|
|
12
|
-
/**
|
|
13
|
-
* Allows to get a type agent context plugin methods based on provided or inferred types and at least one method for these plugin(s)
|
|
14
|
-
* @param context Tje agent context to check against
|
|
15
|
-
* @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
|
|
16
|
-
*/
|
|
17
|
-
function contextHasPlugin(context, requiredMethod) {
|
|
18
|
-
const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod];
|
|
19
|
-
const allMethods = context.agent.availableMethods();
|
|
20
|
-
return methods.every((method) => allMethods.includes(method));
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The below methods are convenience methods to directly get the appropriate context after calling the respective method
|
|
24
|
-
*
|
|
25
|
-
* @param context
|
|
26
|
-
*/
|
|
27
|
-
function contextHasKeyManager(context) {
|
|
28
|
-
return contextHasPlugin(context, 'keyManagerGet');
|
|
29
|
-
}
|
|
30
|
-
function contextHasDidManager(context) {
|
|
31
|
-
return contextHasPlugin(context, 'didManagerGet'); // IResolver is always required for IDIDManager
|
|
32
|
-
}
|
|
33
|
-
function contextHasDidResolver(context) {
|
|
34
|
-
return contextHasPlugin(context, 'resolveDid'); // IResolver is always required for IDIDManager
|
|
35
|
-
}
|
|
36
|
-
function contextHasCredentialIssuer(context) {
|
|
37
|
-
return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']); // W3C Credential issuer
|
|
38
|
-
}
|
|
39
|
-
function contextHasCredentialVerifier(context) {
|
|
40
|
-
return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']); // W3c Credential Verifier
|
|
41
|
-
}
|
|
42
|
-
function contextHasCredentialStatusVerifier(context) {
|
|
43
|
-
return contextHasPlugin(context, ['checkCredentialStatus']); // W3c Credential status Verifier
|
|
44
|
-
}
|
|
45
|
-
function contextHasDataStore(context) {
|
|
46
|
-
return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation']);
|
|
47
|
-
}
|
|
48
|
-
function contextHasDataStoreORM(context) {
|
|
49
|
-
return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations']);
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=agentContextUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentContextUtils.js","sourceRoot":"","sources":["../src/agentContextUtils.ts"],"names":[],"mappings":";;AAkBA,4CAOC;AAQD,oDAEC;AAED,oDAEC;AAED,sDAEC;AAED,gEAEC;AAED,oEAEC;AAED,gFAEC;AAED,kDAEC;AAED,wDAEC;AAlDD;;;;GAIG;AACH,SAAgB,gBAAgB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AoC,CAAC,CAAC,CAAA;AAC9G,CAAC;AAED,SAAgB,sBAAsB,CAAC,OAAwC;IAC7E,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,sCAAsC,EAAE,wCAAwC,CAAC,CAAC,CAAA;AACtH,CAAC"}
|
package/dist/agentCreator.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { TAgent, IPluginMethodMap, IAgentOptions } from '@veramo/core';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a Veramo agent from a config object containing an `/agent` pointer.
|
|
4
|
-
* @param config - The configuration object
|
|
5
|
-
*
|
|
6
|
-
* @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
|
|
7
|
-
* the configuration options.
|
|
8
|
-
*
|
|
9
|
-
* @beta - This API may change without a major version bump
|
|
10
|
-
*/
|
|
11
|
-
export declare function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>>;
|
|
12
|
-
/**
|
|
13
|
-
* Helper function to create a new instance of the {@link Agent} class with correct type
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
|
|
21
|
-
* import { AgentRestClient } from '@veramo/remote-client'
|
|
22
|
-
* import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
|
|
23
|
-
* const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
|
|
24
|
-
* plugins: [
|
|
25
|
-
* new CredentialIssuer(),
|
|
26
|
-
* new AgentRestClient({
|
|
27
|
-
* url: 'http://localhost:3002/agent',
|
|
28
|
-
* enabledMethods: [
|
|
29
|
-
* 'resolveDid',
|
|
30
|
-
* 'handleMessage',
|
|
31
|
-
* ],
|
|
32
|
-
* }),
|
|
33
|
-
* ],
|
|
34
|
-
* })
|
|
35
|
-
* ```
|
|
36
|
-
* @param options - Agent configuration options
|
|
37
|
-
* @returns configured agent
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
export declare function createAgent<T extends IPluginMethodMap, C = Record<string, any>>(options: IAgentOptions & {
|
|
41
|
-
context?: C;
|
|
42
|
-
}): Promise<TAgent<T> & {
|
|
43
|
-
context?: C;
|
|
44
|
-
}>;
|
|
45
|
-
/**
|
|
46
|
-
* Parses a yaml config file and returns a config object
|
|
47
|
-
* @param filePath
|
|
48
|
-
*/
|
|
49
|
-
export declare const getConfig: (filePath: string | Buffer | URL) => Promise<{
|
|
50
|
-
version?: number;
|
|
51
|
-
[x: string]: any;
|
|
52
|
-
}>;
|
|
53
|
-
export declare function getAgent<T extends IPluginMethodMap>(fileName: string): Promise<TAgent<T>>;
|
|
54
|
-
//# sourceMappingURL=agentCreator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentCreator.d.ts","sourceRoot":"","sources":["../src/agentCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAItE;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,SAAS,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAI1G;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,WAAW,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnF,OAAO,EAAE,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,GACvC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC,CAGtC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,aAAoB,MAAM,GAAG,MAAM,GAAG,GAAG,KAAG,OAAO,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CA2B/G,CAAA;AAED,wBAAsB,QAAQ,CAAC,CAAC,SAAS,gBAAgB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAO/F"}
|
package/dist/agentCreator.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
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.getConfig = void 0;
|
|
39
|
-
exports.createAgentFromConfig = createAgentFromConfig;
|
|
40
|
-
exports.createAgent = createAgent;
|
|
41
|
-
exports.getAgent = getAgent;
|
|
42
|
-
const objectCreator_1 = require("./objectCreator");
|
|
43
|
-
const yaml_1 = __importDefault(require("yaml"));
|
|
44
|
-
/**
|
|
45
|
-
* Creates a Veramo agent from a config object containing an `/agent` pointer.
|
|
46
|
-
* @param config - The configuration object
|
|
47
|
-
*
|
|
48
|
-
* @see {@link https://veramo.io/docs/veramo_agent/configuration_internals | Configuration Internals} for details on
|
|
49
|
-
* the configuration options.
|
|
50
|
-
*
|
|
51
|
-
* @beta - This API may change without a major version bump
|
|
52
|
-
*/
|
|
53
|
-
function createAgentFromConfig(config) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
const { agent } = yield (0, objectCreator_1.createObjects)(config, { agent: '/agent' });
|
|
57
|
-
return agent;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Helper function to create a new instance of the {@link Agent} class with correct type
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
* Use {@link TAgent} to configure agent type (list of available methods) for autocomplete in IDE
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import { createAgent, IResolver, IMessageHandler } from '@veramo/core'
|
|
69
|
-
* import { AgentRestClient } from '@veramo/remote-client'
|
|
70
|
-
* import { CredentialIssuer, ICredentialIssuer } from '@veramo/credential-w3c'
|
|
71
|
-
* const agent = createAgent<IResolver & IMessageHandler & ICredentialIssuer>({
|
|
72
|
-
* plugins: [
|
|
73
|
-
* new CredentialIssuer(),
|
|
74
|
-
* new AgentRestClient({
|
|
75
|
-
* url: 'http://localhost:3002/agent',
|
|
76
|
-
* enabledMethods: [
|
|
77
|
-
* 'resolveDid',
|
|
78
|
-
* 'handleMessage',
|
|
79
|
-
* ],
|
|
80
|
-
* }),
|
|
81
|
-
* ],
|
|
82
|
-
* })
|
|
83
|
-
* ```
|
|
84
|
-
* @param options - Agent configuration options
|
|
85
|
-
* @returns configured agent
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
function createAgent(options) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
//@ts-ignore
|
|
91
|
-
return new Agent(options);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Parses a yaml config file and returns a config object
|
|
96
|
-
* @param filePath
|
|
97
|
-
*/
|
|
98
|
-
const getConfig = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
let fileContent;
|
|
100
|
-
// read file async
|
|
101
|
-
try {
|
|
102
|
-
const fs = yield Promise.resolve().then(() => __importStar(require(/* webpackIgnore: true */ 'fs')));
|
|
103
|
-
fileContent = yield fs.promises.readFile(filePath, 'utf8');
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
console.log('Config file not found: ' + filePath);
|
|
107
|
-
console.log('Use "veramo config create" to create one');
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
let config;
|
|
111
|
-
try {
|
|
112
|
-
config = yaml_1.default.parse(fileContent, { prettyErrors: true });
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
console.error(`Unable to parse config file: ${e.message} ${e.linePos}`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
if ((config === null || config === void 0 ? void 0 : config.version) != 3) {
|
|
119
|
-
console.error('Unsupported configuration file version:', config.version);
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
return config;
|
|
123
|
-
});
|
|
124
|
-
exports.getConfig = getConfig;
|
|
125
|
-
function getAgent(fileName) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
try {
|
|
128
|
-
return yield createAgentFromConfig(yield (0, exports.getConfig)(fileName));
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
console.log('Unable to create agent from ' + fileName + '.', e.message);
|
|
132
|
-
process.exit(1);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=agentCreator.js.map
|
package/dist/agentCreator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentCreator.js","sourceRoot":"","sources":["../src/agentCreator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,sDAIC;AA8BD,kCAKC;AAmCD,4BAOC;AA7FD,mDAA+C;AAC/C,gDAAuB;AAEvB;;;;;;;;GAQG;AACH,SAAsB,qBAAqB,CAA6B,MAAc;;QACpF,aAAa;QACb,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,6BAAa,EAAC,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;QAClE,OAAO,KAAK,CAAA;IACd,CAAC;CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAsB,WAAW,CAC/B,OAAwC;;QAExC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;QACzE,IAAI,CAAC;YACH,OAAO,MAAM,qBAAqB,CAAI,MAAM,IAAA,iBAAS,EAAC,QAAQ,CAAC,CAAC,CAAA;QAClE,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;CAAA"}
|
package/dist/dataSources.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
get defaultDbType(): SupportedDatabaseType;
|
|
6
|
-
set defaultDbType(value: SupportedDatabaseType);
|
|
7
|
-
private dataSources;
|
|
8
|
-
private configs;
|
|
9
|
-
private _defaultDbType;
|
|
10
|
-
private static singleton;
|
|
11
|
-
static singleInstance(): DataSources;
|
|
12
|
-
static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
|
|
13
|
-
private constructor();
|
|
14
|
-
addConfig(dbName: string, config: DataSourceOptions): this;
|
|
15
|
-
deleteConfig(dbName: string): this;
|
|
16
|
-
has(dbName: string): boolean;
|
|
17
|
-
delete(dbName: string): this;
|
|
18
|
-
getConfig(dbName: string): BaseDataSourceOptions;
|
|
19
|
-
getDbNames(): string[];
|
|
20
|
-
getDbConnection(dbName: string): Promise<DataSource>;
|
|
21
|
-
}
|
|
22
|
-
export type SupportedDatabaseType = 'postgres' | 'sqlite' | 'react-native';
|
|
23
|
-
export type DateTimeType = 'timestamp' | 'datetime';
|
|
24
|
-
export type DateType = 'date';
|
|
25
|
-
/**
|
|
26
|
-
* Gets the database connection.
|
|
27
|
-
*
|
|
28
|
-
* Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time
|
|
29
|
-
*
|
|
30
|
-
* @param connectionName The database name
|
|
31
|
-
* @param opts
|
|
32
|
-
*/
|
|
33
|
-
export declare const getDbConnection: (connectionName: string, opts?: {
|
|
34
|
-
config: BaseDataSourceOptions | any;
|
|
35
|
-
}) => Promise<DataSource>;
|
|
36
|
-
export declare const dropDatabase: (dbName: string, opts?: {
|
|
37
|
-
removeDataSource?: boolean;
|
|
38
|
-
}) => Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Runs a migration down (drops DB schema)
|
|
41
|
-
* @param dataSource
|
|
42
|
-
*/
|
|
43
|
-
export declare const revertMigration: (dataSource: DataSource) => Promise<void>;
|
|
44
|
-
export declare const resetDatabase: (dbName: string) => Promise<void>;
|
|
45
|
-
//# sourceMappingURL=dataSources.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataSources.d.ts","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAA;AAEjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAA;AAIzE,qBAAa,WAAW;IACtB,IAAI,aAAa,IAAI,qBAAqB,CAEzC;IAED,IAAI,aAAa,CAAC,KAAK,EAAE,qBAAqB,EAE7C;IACD,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,cAAc,CAAkC;IAExD,OAAO,CAAC,MAAM,CAAC,SAAS,CAAa;WAEvB,cAAc;WAOd,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAIlE,OAAO;IAIP,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAO1D,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIlC,GAAG,CAAC,MAAM,EAAE,MAAM;IAIlB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAQzC,UAAU,IAAI,MAAM,EAAE;IAIvB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CA+B3D;AAED,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,QAAQ,GAAG,cAAc,CAAA;AAC1E,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,UAAU,CAAA;AAEnD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,mBACV,MAAM,SACf;IACL,MAAM,EAAE,qBAAqB,GAAG,GAAG,CAAA;CACpC,KACA,OAAO,CAAC,UAAU,CAKpB,CAAA;AAED,eAAO,MAAM,YAAY,WAAkB,MAAM,SAAS;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,KAAG,OAAO,CAAC,IAAI,CAatG,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,eAAsB,UAAU,KAAG,OAAO,CAAC,IAAI,CAM1E,CAAA;AACD,eAAO,MAAM,aAAa,WAAkB,MAAM,KAAG,OAAO,CAAC,IAAI,CAIhE,CAAA"}
|
package/dist/dataSources.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
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.resetDatabase = exports.revertMigration = exports.dropDatabase = exports.getDbConnection = exports.DataSources = void 0;
|
|
16
|
-
const debug_1 = __importDefault(require("debug"));
|
|
17
|
-
const typeorm_1 = require("typeorm");
|
|
18
|
-
const debug = (0, debug_1.default)(`sphereon:ssi-sdk:database`);
|
|
19
|
-
class DataSources {
|
|
20
|
-
get defaultDbType() {
|
|
21
|
-
return this._defaultDbType;
|
|
22
|
-
}
|
|
23
|
-
set defaultDbType(value) {
|
|
24
|
-
this._defaultDbType = value;
|
|
25
|
-
}
|
|
26
|
-
static singleInstance() {
|
|
27
|
-
if (!DataSources.singleton) {
|
|
28
|
-
DataSources.singleton = new DataSources();
|
|
29
|
-
}
|
|
30
|
-
return DataSources.singleton;
|
|
31
|
-
}
|
|
32
|
-
static newInstance(configs) {
|
|
33
|
-
return new DataSources(configs);
|
|
34
|
-
}
|
|
35
|
-
constructor(configs) {
|
|
36
|
-
this.dataSources = new Map();
|
|
37
|
-
this.configs = new Map();
|
|
38
|
-
this._defaultDbType = 'sqlite';
|
|
39
|
-
;
|
|
40
|
-
(configs !== null && configs !== void 0 ? configs : new Map()).forEach((config, name) => this.addConfig(name, config));
|
|
41
|
-
}
|
|
42
|
-
addConfig(dbName, config) {
|
|
43
|
-
this.configs.set(dbName, config);
|
|
44
|
-
// yes we are aware last one wins
|
|
45
|
-
this._defaultDbType = config.type;
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
deleteConfig(dbName) {
|
|
49
|
-
this.configs.delete(dbName);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
has(dbName) {
|
|
53
|
-
return this.configs.has(dbName) && this.dataSources.has(dbName);
|
|
54
|
-
}
|
|
55
|
-
delete(dbName) {
|
|
56
|
-
this.deleteConfig(dbName);
|
|
57
|
-
this.dataSources.delete(dbName);
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
getConfig(dbName) {
|
|
61
|
-
const config = this.configs.get(dbName);
|
|
62
|
-
if (!config) {
|
|
63
|
-
throw Error(`No DB config found for ${dbName}`);
|
|
64
|
-
}
|
|
65
|
-
return config;
|
|
66
|
-
}
|
|
67
|
-
getDbNames() {
|
|
68
|
-
return [...this.configs.keys()];
|
|
69
|
-
}
|
|
70
|
-
getDbConnection(dbName) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const config = this.getConfig(dbName);
|
|
73
|
-
if (!this._defaultDbType) {
|
|
74
|
-
this._defaultDbType = config.type;
|
|
75
|
-
}
|
|
76
|
-
/*if (config.synchronize) {
|
|
77
|
-
return Promise.reject(
|
|
78
|
-
`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
|
|
79
|
-
)
|
|
80
|
-
}*/
|
|
81
|
-
let dataSource = this.dataSources.get(dbName);
|
|
82
|
-
if (dataSource) {
|
|
83
|
-
return dataSource;
|
|
84
|
-
}
|
|
85
|
-
dataSource = yield new typeorm_1.DataSource(Object.assign(Object.assign({}, config), { name: dbName })).initialize();
|
|
86
|
-
this.dataSources.set(dbName, dataSource);
|
|
87
|
-
if (config.synchronize) {
|
|
88
|
-
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
89
|
-
}
|
|
90
|
-
else if (config.migrationsRun) {
|
|
91
|
-
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
95
|
-
yield dataSource.runMigrations();
|
|
96
|
-
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
|
97
|
-
}
|
|
98
|
-
return dataSource;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.DataSources = DataSources;
|
|
103
|
-
/**
|
|
104
|
-
* Gets the database connection.
|
|
105
|
-
*
|
|
106
|
-
* Also makes sure that migrations are run (versioning for DB schema's), so we can properly update over time
|
|
107
|
-
*
|
|
108
|
-
* @param connectionName The database name
|
|
109
|
-
* @param opts
|
|
110
|
-
*/
|
|
111
|
-
const getDbConnection = (connectionName, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
-
if (!DataSources.singleInstance().has(connectionName) && (opts === null || opts === void 0 ? void 0 : opts.config)) {
|
|
113
|
-
DataSources.singleInstance().addConfig(connectionName, opts === null || opts === void 0 ? void 0 : opts.config);
|
|
114
|
-
}
|
|
115
|
-
return DataSources.singleInstance().getDbConnection(connectionName);
|
|
116
|
-
});
|
|
117
|
-
exports.getDbConnection = getDbConnection;
|
|
118
|
-
const dropDatabase = (dbName, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
-
const { removeDataSource = false } = Object.assign({}, opts);
|
|
120
|
-
if (!DataSources.singleInstance().has(dbName)) {
|
|
121
|
-
return Promise.reject(Error(`No database present with name: ${dbName}`));
|
|
122
|
-
}
|
|
123
|
-
const connection = yield (0, exports.getDbConnection)(dbName);
|
|
124
|
-
yield connection.dropDatabase();
|
|
125
|
-
if (removeDataSource) {
|
|
126
|
-
DataSources.singleInstance().delete(dbName);
|
|
127
|
-
}
|
|
128
|
-
else if (!connection.isInitialized) {
|
|
129
|
-
yield connection.initialize();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
exports.dropDatabase = dropDatabase;
|
|
133
|
-
/**
|
|
134
|
-
* Runs a migration down (drops DB schema)
|
|
135
|
-
* @param dataSource
|
|
136
|
-
*/
|
|
137
|
-
const revertMigration = (dataSource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
if (dataSource.isInitialized) {
|
|
139
|
-
yield dataSource.undoLastMigration();
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
console.error('DataSource is not initialized');
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
exports.revertMigration = revertMigration;
|
|
146
|
-
const resetDatabase = (dbName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
-
yield (0, exports.dropDatabase)(dbName);
|
|
148
|
-
const connection = yield (0, exports.getDbConnection)(dbName);
|
|
149
|
-
yield connection.runMigrations();
|
|
150
|
-
});
|
|
151
|
-
exports.resetDatabase = resetDatabase;
|
|
152
|
-
//# sourceMappingURL=dataSources.js.map
|
package/dist/dataSources.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataSources.js","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,qCAAoC;AAKpC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,2BAA2B,CAAC,CAAA;AAEhD,MAAa,WAAW;IACtB,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAED,IAAI,aAAa,CAAC,KAA4B;QAC5C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;IAC7B,CAAC;IAOM,MAAM,CAAC,cAAc;QAC1B,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;YAC3B,WAAW,CAAC,SAAS,GAAG,IAAI,WAAW,EAAE,CAAA;QAC3C,CAAC;QACD,OAAO,WAAW,CAAC,SAAS,CAAA;IAC9B,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,OAAwC;QAChE,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,YAAoB,OAAwC;QAjBpD,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;QAC3C,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D,CAAC;AACH,CAAC,CAAA,CAAA;AANY,QAAA,eAAe,mBAM3B;AACM,MAAM,aAAa,GAAG,CAAO,MAAc,EAAiB,EAAE;IACnE,MAAM,IAAA,oBAAY,EAAC,MAAM,CAAC,CAAA;IAC1B,MAAM,UAAU,GAAG,MAAM,IAAA,uBAAe,EAAC,MAAM,CAAC,CAAA;IAChD,MAAM,UAAU,CAAC,aAAa,EAAE,CAAA;AAClC,CAAC,CAAA,CAAA;AAJY,QAAA,aAAa,iBAIzB"}
|
package/dist/generic.d.ts
DELETED
package/dist/generic.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../src/generic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/generic.js
DELETED
package/dist/generic.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../src/generic.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|