@sphereon/ssi-sdk.agent-config 0.32.1-next.54 → 0.33.1-feature.vcdm2.4
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.js +9 -20
- package/dist/agentContextUtils.js.map +1 -1
- package/dist/agentCreator.js +23 -71
- package/dist/agentCreator.js.map +1 -1
- package/dist/dataSources.js +54 -75
- package/dist/dataSources.js.map +1 -1
- package/dist/generic.js +1 -2
- package/dist/index.js +6 -22
- package/dist/index.js.map +1 -1
- package/dist/objectCreator.js +96 -142
- package/dist/objectCreator.js.map +1 -1
- package/dist/typeormTypes.js +7 -14
- package/dist/typeormTypes.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,20 +1,9 @@
|
|
|
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
1
|
/**
|
|
13
2
|
* 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
3
|
* @param context Tje agent context to check against
|
|
15
4
|
* @param requiredMethod One or more method the plugin provides, so we can check availability and thus plugin presence
|
|
16
5
|
*/
|
|
17
|
-
function contextHasPlugin(context, requiredMethod) {
|
|
6
|
+
export function contextHasPlugin(context, requiredMethod) {
|
|
18
7
|
const methods = Array.isArray(requiredMethod) ? requiredMethod : [requiredMethod];
|
|
19
8
|
const allMethods = context.agent.availableMethods();
|
|
20
9
|
return methods.every((method) => allMethods.includes(method));
|
|
@@ -24,28 +13,28 @@ function contextHasPlugin(context, requiredMethod) {
|
|
|
24
13
|
*
|
|
25
14
|
* @param context
|
|
26
15
|
*/
|
|
27
|
-
function contextHasKeyManager(context) {
|
|
16
|
+
export function contextHasKeyManager(context) {
|
|
28
17
|
return contextHasPlugin(context, 'keyManagerGet');
|
|
29
18
|
}
|
|
30
|
-
function contextHasDidManager(context) {
|
|
19
|
+
export function contextHasDidManager(context) {
|
|
31
20
|
return contextHasPlugin(context, 'didManagerGet'); // IResolver is always required for IDIDManager
|
|
32
21
|
}
|
|
33
|
-
function contextHasDidResolver(context) {
|
|
22
|
+
export function contextHasDidResolver(context) {
|
|
34
23
|
return contextHasPlugin(context, 'resolveDid'); // IResolver is always required for IDIDManager
|
|
35
24
|
}
|
|
36
|
-
function contextHasCredentialIssuer(context) {
|
|
25
|
+
export function contextHasCredentialIssuer(context) {
|
|
37
26
|
return contextHasPlugin(context, ['createVerifiableCredential', 'createVerifiablePresentation']); // W3C Credential issuer
|
|
38
27
|
}
|
|
39
|
-
function contextHasCredentialVerifier(context) {
|
|
28
|
+
export function contextHasCredentialVerifier(context) {
|
|
40
29
|
return contextHasPlugin(context, ['verifyCredential', 'verifyPresentation']); // W3c Credential Verifier
|
|
41
30
|
}
|
|
42
|
-
function contextHasCredentialStatusVerifier(context) {
|
|
31
|
+
export function contextHasCredentialStatusVerifier(context) {
|
|
43
32
|
return contextHasPlugin(context, ['checkCredentialStatus']); // W3c Credential status Verifier
|
|
44
33
|
}
|
|
45
|
-
function contextHasDataStore(context) {
|
|
34
|
+
export function contextHasDataStore(context) {
|
|
46
35
|
return contextHasPlugin(context, ['dataStoreGetVerifiableCredential', 'dataStoreGetVerifiablePresentation']);
|
|
47
36
|
}
|
|
48
|
-
function contextHasDataStoreORM(context) {
|
|
37
|
+
export function contextHasDataStoreORM(context) {
|
|
49
38
|
return contextHasPlugin(context, ['dataStoreORMGetVerifiableCredentials', 'dataStoreORMGetVerifiablePresentations']);
|
|
50
39
|
}
|
|
51
40
|
//# sourceMappingURL=agentContextUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentContextUtils.js","sourceRoot":"","sources":["../src/agentContextUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agentContextUtils.js","sourceRoot":"","sources":["../src/agentContextUtils.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA2B,EAC3B,cAAiC;IAEjC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAA;IACjF,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAA;IACnD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;AAC/D,CAAC;AAED;;;;GAIG;AAEH,MAAM,UAAU,oBAAoB,CAAC,OAAwC;IAC3E,OAAO,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;AACnD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAwC;IAC3E,OAAO,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA,CAAC,+CAA+C;AACnG,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAwC;IAC5E,OAAO,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA,CAAC,+CAA+C;AAChG,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAwC;IACjF,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,4BAA4B,EAAE,8BAA8B,CAAC,CAAC,CAAA,CAAC,wBAAwB;AAC3H,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,OAAwC;IACnF,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,CAAC,CAAA,CAAC,0BAA0B;AACzG,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,OAAwC;IACzF,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAA,CAAC,iCAAiC;AAC/F,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAwC;IAC1E,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,kCAAkC,EAAE,oCAAoC,CAAC,CAAC,CAAA;AAC9G,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAwC;IAC7E,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC,sCAAsC,EAAE,wCAAwC,CAAC,CAAC,CAAA;AACtH,CAAC"}
|
package/dist/agentCreator.js
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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"));
|
|
1
|
+
import { createObjects } from './objectCreator';
|
|
2
|
+
import yaml from 'yaml';
|
|
44
3
|
/**
|
|
45
4
|
* Creates a Veramo agent from a config object containing an `/agent` pointer.
|
|
46
5
|
* @param config - The configuration object
|
|
@@ -50,12 +9,10 @@ const yaml_1 = __importDefault(require("yaml"));
|
|
|
50
9
|
*
|
|
51
10
|
* @beta - This API may change without a major version bump
|
|
52
11
|
*/
|
|
53
|
-
function createAgentFromConfig(config) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return agent;
|
|
58
|
-
});
|
|
12
|
+
export async function createAgentFromConfig(config) {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const { agent } = await createObjects(config, { agent: '/agent' });
|
|
15
|
+
return agent;
|
|
59
16
|
}
|
|
60
17
|
/**
|
|
61
18
|
* Helper function to create a new instance of the {@link Agent} class with correct type
|
|
@@ -85,22 +42,20 @@ function createAgentFromConfig(config) {
|
|
|
85
42
|
* @returns configured agent
|
|
86
43
|
* @public
|
|
87
44
|
*/
|
|
88
|
-
function createAgent(options) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return new Agent(options);
|
|
92
|
-
});
|
|
45
|
+
export async function createAgent(options) {
|
|
46
|
+
//@ts-ignore
|
|
47
|
+
return new Agent(options);
|
|
93
48
|
}
|
|
94
49
|
/**
|
|
95
50
|
* Parses a yaml config file and returns a config object
|
|
96
51
|
* @param filePath
|
|
97
52
|
*/
|
|
98
|
-
const getConfig = (filePath) =>
|
|
53
|
+
export const getConfig = async (filePath) => {
|
|
99
54
|
let fileContent;
|
|
100
55
|
// read file async
|
|
101
56
|
try {
|
|
102
|
-
const fs =
|
|
103
|
-
fileContent =
|
|
57
|
+
const fs = await import(/* webpackIgnore: true */ 'fs');
|
|
58
|
+
fileContent = await fs.promises.readFile(filePath, 'utf8');
|
|
104
59
|
}
|
|
105
60
|
catch (e) {
|
|
106
61
|
console.log('Config file not found: ' + filePath);
|
|
@@ -109,28 +64,25 @@ const getConfig = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
109
64
|
}
|
|
110
65
|
let config;
|
|
111
66
|
try {
|
|
112
|
-
config =
|
|
67
|
+
config = yaml.parse(fileContent, { prettyErrors: true });
|
|
113
68
|
}
|
|
114
69
|
catch (e) {
|
|
115
70
|
console.error(`Unable to parse config file: ${e.message} ${e.linePos}`);
|
|
116
71
|
process.exit(1);
|
|
117
72
|
}
|
|
118
|
-
if (
|
|
73
|
+
if (config?.version != 3) {
|
|
119
74
|
console.error('Unsupported configuration file version:', config.version);
|
|
120
75
|
process.exit(1);
|
|
121
76
|
}
|
|
122
77
|
return config;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
process.exit(1);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
78
|
+
};
|
|
79
|
+
export async function getAgent(fileName) {
|
|
80
|
+
try {
|
|
81
|
+
return await createAgentFromConfig(await getConfig(fileName));
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.log('Unable to create agent from ' + fileName + '.', e.message);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
135
87
|
}
|
|
136
88
|
//# sourceMappingURL=agentCreator.js.map
|
package/dist/agentCreator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentCreator.js","sourceRoot":"","sources":["../src/agentCreator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agentCreator.js","sourceRoot":"","sources":["../src/agentCreator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAA6B,MAAc;IACpF,aAAa;IACb,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClE,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAwC;IAExC,YAAY;IACZ,OAAO,IAAI,KAAK,CAAC,OAAO,CAAc,CAAA;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EA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AC,GAAG,CAAC,8BAA8B,GAAG,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;QACvE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
package/dist/dataSources.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 {
|
|
1
|
+
import Debug from 'debug';
|
|
2
|
+
import { DataSource } from 'typeorm';
|
|
3
|
+
const debug = Debug(`sphereon:ssi-sdk:database`);
|
|
4
|
+
export class DataSources {
|
|
20
5
|
get defaultDbType() {
|
|
21
6
|
return this._defaultDbType;
|
|
22
7
|
}
|
|
23
8
|
set defaultDbType(value) {
|
|
24
9
|
this._defaultDbType = value;
|
|
25
10
|
}
|
|
11
|
+
dataSources = new Map();
|
|
12
|
+
configs = new Map();
|
|
13
|
+
_defaultDbType = 'sqlite';
|
|
14
|
+
static singleton;
|
|
26
15
|
static singleInstance() {
|
|
27
16
|
if (!DataSources.singleton) {
|
|
28
17
|
DataSources.singleton = new DataSources();
|
|
@@ -33,11 +22,8 @@ class DataSources {
|
|
|
33
22
|
return new DataSources(configs);
|
|
34
23
|
}
|
|
35
24
|
constructor(configs) {
|
|
36
|
-
this.dataSources = new Map();
|
|
37
|
-
this.configs = new Map();
|
|
38
|
-
this._defaultDbType = 'sqlite';
|
|
39
25
|
;
|
|
40
|
-
(configs
|
|
26
|
+
(configs ?? new Map()).forEach((config, name) => this.addConfig(name, config));
|
|
41
27
|
}
|
|
42
28
|
addConfig(dbName, config) {
|
|
43
29
|
this.configs.set(dbName, config);
|
|
@@ -67,39 +53,36 @@ class DataSources {
|
|
|
67
53
|
getDbNames() {
|
|
68
54
|
return [...this.configs.keys()];
|
|
69
55
|
}
|
|
70
|
-
getDbConnection(dbName) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
}
|
|
56
|
+
async getDbConnection(dbName) {
|
|
57
|
+
const config = this.getConfig(dbName);
|
|
58
|
+
if (!this._defaultDbType) {
|
|
59
|
+
this._defaultDbType = config.type;
|
|
60
|
+
}
|
|
61
|
+
/*if (config.synchronize) {
|
|
62
|
+
return Promise.reject(
|
|
63
|
+
`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
|
|
64
|
+
)
|
|
65
|
+
}*/
|
|
66
|
+
let dataSource = this.dataSources.get(dbName);
|
|
67
|
+
if (dataSource) {
|
|
98
68
|
return dataSource;
|
|
99
|
-
}
|
|
69
|
+
}
|
|
70
|
+
dataSource = await new DataSource({ ...config, name: dbName }).initialize();
|
|
71
|
+
this.dataSources.set(dbName, dataSource);
|
|
72
|
+
if (config.synchronize) {
|
|
73
|
+
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
74
|
+
}
|
|
75
|
+
else if (config.migrationsRun) {
|
|
76
|
+
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
80
|
+
await dataSource.runMigrations();
|
|
81
|
+
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
|
82
|
+
}
|
|
83
|
+
return dataSource;
|
|
100
84
|
}
|
|
101
85
|
}
|
|
102
|
-
exports.DataSources = DataSources;
|
|
103
86
|
/**
|
|
104
87
|
* Gets the database connection.
|
|
105
88
|
*
|
|
@@ -108,45 +91,41 @@ exports.DataSources = DataSources;
|
|
|
108
91
|
* @param connectionName The database name
|
|
109
92
|
* @param opts
|
|
110
93
|
*/
|
|
111
|
-
const getDbConnection = (connectionName, opts) =>
|
|
112
|
-
if (!DataSources.singleInstance().has(connectionName) &&
|
|
113
|
-
DataSources.singleInstance().addConfig(connectionName, opts
|
|
94
|
+
export const getDbConnection = async (connectionName, opts) => {
|
|
95
|
+
if (!DataSources.singleInstance().has(connectionName) && opts?.config) {
|
|
96
|
+
DataSources.singleInstance().addConfig(connectionName, opts?.config);
|
|
114
97
|
}
|
|
115
98
|
return DataSources.singleInstance().getDbConnection(connectionName);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
const { removeDataSource = false } = Object.assign({}, opts);
|
|
99
|
+
};
|
|
100
|
+
export const dropDatabase = async (dbName, opts) => {
|
|
101
|
+
const { removeDataSource = false } = { ...opts };
|
|
120
102
|
if (!DataSources.singleInstance().has(dbName)) {
|
|
121
103
|
return Promise.reject(Error(`No database present with name: ${dbName}`));
|
|
122
104
|
}
|
|
123
|
-
const connection =
|
|
124
|
-
|
|
105
|
+
const connection = await getDbConnection(dbName);
|
|
106
|
+
await connection.dropDatabase();
|
|
125
107
|
if (removeDataSource) {
|
|
126
108
|
DataSources.singleInstance().delete(dbName);
|
|
127
109
|
}
|
|
128
110
|
else if (!connection.isInitialized) {
|
|
129
|
-
|
|
111
|
+
await connection.initialize();
|
|
130
112
|
}
|
|
131
|
-
}
|
|
132
|
-
exports.dropDatabase = dropDatabase;
|
|
113
|
+
};
|
|
133
114
|
/**
|
|
134
115
|
* Runs a migration down (drops DB schema)
|
|
135
116
|
* @param dataSource
|
|
136
117
|
*/
|
|
137
|
-
const revertMigration = (dataSource) =>
|
|
118
|
+
export const revertMigration = async (dataSource) => {
|
|
138
119
|
if (dataSource.isInitialized) {
|
|
139
|
-
|
|
120
|
+
await dataSource.undoLastMigration();
|
|
140
121
|
}
|
|
141
122
|
else {
|
|
142
123
|
console.error('DataSource is not initialized');
|
|
143
124
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
exports.resetDatabase = resetDatabase;
|
|
125
|
+
};
|
|
126
|
+
export const resetDatabase = async (dbName) => {
|
|
127
|
+
await dropDatabase(dbName);
|
|
128
|
+
const connection = await getDbConnection(dbName);
|
|
129
|
+
await connection.runMigrations();
|
|
130
|
+
};
|
|
152
131
|
//# sourceMappingURL=dataSources.js.map
|
package/dist/dataSources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataSources.js","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dataSources.js","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKpC,MAAM,KAAK,GAAG,KAAK,CAAC,2BAA2B,CAAC,CAAA;AAEhD,MAAM,OAAO,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;IACO,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC3C,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAA;IAC9C,cAAc,GAA0B,QAAQ,CAAA;IAEhD,MAAM,CAAC,SAAS,CAAa;IAE9B,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;QAC1D,CAAC;QAAA,CAAC,OAAO,IAAI,IAAI,GAAG,EAA6B,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,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
|
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
1
|
/**
|
|
18
2
|
* @public
|
|
19
3
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
export * from './agentContextUtils';
|
|
5
|
+
export * from './dataSources';
|
|
6
|
+
export * from './agentCreator';
|
|
7
|
+
export * from './objectCreator';
|
|
8
|
+
export * from './generic';
|
|
9
|
+
export * from './typeormTypes';
|
|
26
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","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/objectCreator.js
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = createObjects;
|
|
39
|
-
const jsonpointer_1 = require("jsonpointer");
|
|
40
|
-
const url_parse_1 = __importDefault(require("url-parse"));
|
|
1
|
+
import { set, get } from 'jsonpointer';
|
|
2
|
+
import parse from 'url-parse';
|
|
41
3
|
/**
|
|
42
4
|
* Creates objects from a configuration object and a set of pointers.
|
|
43
5
|
*
|
|
@@ -84,118 +46,110 @@ const url_parse_1 = __importDefault(require("url-parse"));
|
|
|
84
46
|
*
|
|
85
47
|
* @beta - This API may change without a major version bump
|
|
86
48
|
*/
|
|
87
|
-
function createObjects(config, pointers) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return resolved;
|
|
98
|
-
}
|
|
99
|
-
if (typeof input === 'object') {
|
|
100
|
-
const resolved = {};
|
|
101
|
-
for (const property in input) {
|
|
102
|
-
if (input.hasOwnProperty(property)) {
|
|
103
|
-
if (property === '$ref') {
|
|
104
|
-
const pointer = input[property];
|
|
105
|
-
return yield objectFromPointer(pointer);
|
|
106
|
-
}
|
|
107
|
-
else if (property === '$require') {
|
|
108
|
-
return yield objectFromConfig(input);
|
|
109
|
-
}
|
|
110
|
-
else if (property === '$env') {
|
|
111
|
-
return process.env[input[property]];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
resolved[property] = yield resolveRefs(input[property]);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return resolved;
|
|
119
|
-
}
|
|
120
|
-
return input;
|
|
121
|
-
});
|
|
49
|
+
export async function createObjects(config, pointers) {
|
|
50
|
+
const objects = {};
|
|
51
|
+
async function resolveRefs(input) {
|
|
52
|
+
if (Array.isArray(input)) {
|
|
53
|
+
const resolved = [];
|
|
54
|
+
for (const item of input) {
|
|
55
|
+
resolved.push(await resolveRefs(item));
|
|
56
|
+
}
|
|
57
|
+
return resolved;
|
|
122
58
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const type = parsed.query['t'] || 'class';
|
|
131
|
-
const pointer = parsed.query['p'];
|
|
132
|
-
const args = objectConfig['$args'];
|
|
133
|
-
// console.log({module, member, type, query: parsed.query})
|
|
134
|
-
if (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {
|
|
135
|
-
const { resolve } = yield Promise.resolve().then(() => __importStar(require('path')));
|
|
136
|
-
module = resolve(module);
|
|
137
|
-
}
|
|
138
|
-
const resolvedArgs = args !== undefined ? yield resolveRefs(args) : [];
|
|
139
|
-
try {
|
|
140
|
-
let required = member ? (yield Promise.resolve(`${module}`).then(s => __importStar(require(s))))[member] : yield Promise.resolve(`${module}`).then(s => __importStar(require(s)));
|
|
141
|
-
if (type === 'class') {
|
|
142
|
-
object = new required(...resolvedArgs);
|
|
59
|
+
if (typeof input === 'object') {
|
|
60
|
+
const resolved = {};
|
|
61
|
+
for (const property in input) {
|
|
62
|
+
if (input.hasOwnProperty(property)) {
|
|
63
|
+
if (property === '$ref') {
|
|
64
|
+
const pointer = input[property];
|
|
65
|
+
return await objectFromPointer(pointer);
|
|
143
66
|
}
|
|
144
|
-
else if (
|
|
145
|
-
|
|
67
|
+
else if (property === '$require') {
|
|
68
|
+
return await objectFromConfig(input);
|
|
146
69
|
}
|
|
147
|
-
else if (
|
|
148
|
-
|
|
70
|
+
else if (property === '$env') {
|
|
71
|
+
return process.env[input[property]];
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
resolved[property] = await resolveRefs(input[property]);
|
|
149
75
|
}
|
|
150
76
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
if (pointer) {
|
|
155
|
-
return (0, jsonpointer_1.get)(object, pointer);
|
|
156
|
-
}
|
|
157
|
-
return object;
|
|
158
|
-
});
|
|
77
|
+
}
|
|
78
|
+
return resolved;
|
|
159
79
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
80
|
+
return input;
|
|
81
|
+
}
|
|
82
|
+
async function objectFromConfig(objectConfig) {
|
|
83
|
+
let object;
|
|
84
|
+
// console.log('Requiring', objectConfig['$require'])
|
|
85
|
+
const parsed = parse(objectConfig['$require'], {}, true);
|
|
86
|
+
let module = parsed.pathname;
|
|
87
|
+
const member = parsed.hash.length > 1 ? parsed.hash.slice(1) : undefined;
|
|
88
|
+
const type = parsed.query['t'] || 'class';
|
|
89
|
+
const pointer = parsed.query['p'];
|
|
90
|
+
const args = objectConfig['$args'];
|
|
91
|
+
// console.log({module, member, type, query: parsed.query})
|
|
92
|
+
if (module.slice(0, 2) === './' || module.slice(0, 3) === '../') {
|
|
93
|
+
const { resolve } = await import('path');
|
|
94
|
+
module = resolve(module);
|
|
95
|
+
}
|
|
96
|
+
const resolvedArgs = args !== undefined ? await resolveRefs(args) : [];
|
|
97
|
+
try {
|
|
98
|
+
let required = member ? (await import(module))[member] : await import(module);
|
|
99
|
+
if (type === 'class') {
|
|
100
|
+
object = new required(...resolvedArgs);
|
|
101
|
+
}
|
|
102
|
+
else if (type === 'function') {
|
|
103
|
+
object = required(...resolvedArgs);
|
|
104
|
+
}
|
|
105
|
+
else if (type === 'object') {
|
|
106
|
+
object = required;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
throw new Error(`Error creating ${module}['${member}']: ${e.message}`);
|
|
111
|
+
}
|
|
112
|
+
if (pointer) {
|
|
113
|
+
return get(object, pointer);
|
|
114
|
+
}
|
|
115
|
+
return object;
|
|
116
|
+
}
|
|
117
|
+
async function objectFromPointer(pointer) {
|
|
118
|
+
const existingObject = get(objects, pointer);
|
|
119
|
+
if (existingObject) {
|
|
120
|
+
// console.log('Existing', pointer)
|
|
121
|
+
return existingObject;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// console.log('New', pointer)
|
|
125
|
+
const objectConfig = get(config, pointer);
|
|
126
|
+
if (!objectConfig)
|
|
127
|
+
throw Error('Pointer not found: ' + pointer);
|
|
128
|
+
try {
|
|
129
|
+
let object;
|
|
130
|
+
if (objectConfig['$require']) {
|
|
131
|
+
object = await objectFromConfig(objectConfig);
|
|
132
|
+
}
|
|
133
|
+
else if (objectConfig['$env']) {
|
|
134
|
+
object = process.env[objectConfig['$env']];
|
|
166
135
|
}
|
|
167
136
|
else {
|
|
168
|
-
|
|
169
|
-
const objectConfig = (0, jsonpointer_1.get)(config, pointer);
|
|
170
|
-
if (!objectConfig)
|
|
171
|
-
throw Error('Pointer not found: ' + pointer);
|
|
172
|
-
try {
|
|
173
|
-
let object;
|
|
174
|
-
if (objectConfig['$require']) {
|
|
175
|
-
object = yield objectFromConfig(objectConfig);
|
|
176
|
-
}
|
|
177
|
-
else if (objectConfig['$env']) {
|
|
178
|
-
object = process.env[objectConfig['$env']];
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
object = yield resolveRefs(objectConfig);
|
|
182
|
-
}
|
|
183
|
-
(0, jsonpointer_1.set)(objects, pointer, object);
|
|
184
|
-
return object;
|
|
185
|
-
}
|
|
186
|
-
catch (e) {
|
|
187
|
-
throw Error(e.message + '. While creating object from pointer: ' + pointer);
|
|
188
|
-
}
|
|
137
|
+
object = await resolveRefs(objectConfig);
|
|
189
138
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
result[key] = yield objectFromPointer(pointers[key]);
|
|
139
|
+
set(objects, pointer, object);
|
|
140
|
+
return object;
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
throw Error(e.message + '. While creating object from pointer: ' + pointer);
|
|
196
144
|
}
|
|
197
145
|
}
|
|
198
|
-
|
|
199
|
-
}
|
|
146
|
+
}
|
|
147
|
+
const result = {};
|
|
148
|
+
for (const key of Object.keys(pointers)) {
|
|
149
|
+
if (pointers.hasOwnProperty(key)) {
|
|
150
|
+
result[key] = await objectFromPointer(pointers[key]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
200
154
|
}
|
|
201
155
|
//# sourceMappingURL=objectCreator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectCreator.js","sourceRoot":"","sources":["../src/objectCreator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"objectCreator.js","sourceRoot":"","sources":["../src/objectCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,MAAM,WAAW,CAAA;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,QAAgC;IAClF,MAAM,OAAO,GAAG,EAAE,CAAA;IAElB,KAAK,UAAU,WAAW,CAAC,KAAU;QACnC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,EAAE,CAAA;YACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,QAAQ,CAAC,IAAI,CAAC,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;YACxC,CAAC;YACD,OAAO,QAAQ,CAAA;QACjB,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAAQ,EAAE,CAAA;YACxB,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;gBAC7B,IAAI,KAAK,CAAC,cAAc,CAAC,QAAQ,C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D,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/typeormTypes.js
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const dataSources_1 = require("./dataSources");
|
|
5
|
-
const getDbType = (opts) => {
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
const type = (_c = (_b = (typeof process === 'object' ? (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.DB_TYPE : undefined)) !== null && _b !== void 0 ? _b : dataSources_1.DataSources.singleInstance().defaultDbType) !== null && _c !== void 0 ? _c : opts === null || opts === void 0 ? void 0 : opts.defaultType;
|
|
1
|
+
import { DataSources } from './dataSources';
|
|
2
|
+
export const getDbType = (opts) => {
|
|
3
|
+
const type = (typeof process === 'object' ? process?.env?.DB_TYPE : undefined) ?? DataSources.singleInstance().defaultDbType ?? opts?.defaultType;
|
|
8
4
|
if (!type) {
|
|
9
5
|
throw Error(`Could not determine DB type. Please set the DB_TYPE global variable or env var to one of 'postgres' or 'sqlite'`);
|
|
10
6
|
}
|
|
11
7
|
return type;
|
|
12
8
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
switch ((0, exports.getDbType)(opts)) {
|
|
9
|
+
export const typeOrmDateTime = (opts) => {
|
|
10
|
+
switch (getDbType(opts)) {
|
|
16
11
|
case 'postgres':
|
|
17
12
|
return 'timestamp';
|
|
18
13
|
case 'sqlite':
|
|
19
14
|
case 'react-native':
|
|
20
15
|
return 'datetime';
|
|
21
16
|
default:
|
|
22
|
-
throw Error(`DB type ${
|
|
17
|
+
throw Error(`DB type ${getDbType(opts)} not supported. Right now only sqlite, react-native and postgresql are supported`);
|
|
23
18
|
}
|
|
24
19
|
};
|
|
25
|
-
|
|
26
|
-
const typeormDate = (opts) => {
|
|
20
|
+
export const typeormDate = (opts) => {
|
|
27
21
|
// The same for both DBs
|
|
28
22
|
return 'date';
|
|
29
23
|
};
|
|
30
|
-
exports.typeormDate = typeormDate;
|
|
31
24
|
//# sourceMappingURL=typeormTypes.js.map
|
package/dist/typeormTypes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeormTypes.js","sourceRoot":"","sources":["../src/typeormTypes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeormTypes.js","sourceRoot":"","sources":["../src/typeormTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiD,MAAM,eAAe,CAAA;AAE1F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAA6C,EAAyB,EAAE;IAChG,MAAM,IAAI,GAAG,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,IAAI,IAAI,EAAE,WAAW,CAAA;IACjJ,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,iHAAiH,CAAC,CAAA;IAChI,CAAC;IACD,OAAO,IAA6B,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAA6C,EAAgB,EAAE;IAC7F,QAAQ,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,KAAK,UAAU;YACb,OAAO,WAAW,CAAA;QACpB,KAAK,QAAQ,CAAC;QACd,KAAK,cAAc;YACjB,OAAO,UAAU,CAAA;QACnB;YACE,MAAM,KAAK,CAAC,WAAW,SAAS,CAAC,IAAI,CAAC,kFAAkF,CAAC,CAAA;IAC7H,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAA6C,EAAY,EAAE;IACrF,wBAAwB;IACxB,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.agent-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@veramo/core": "4.2.0",
|
|
13
13
|
"debug": "^4.3.5",
|
|
14
14
|
"jsonpointer": "^5.0.1",
|
|
15
|
-
"typeorm": "^0.3.
|
|
15
|
+
"typeorm": "^0.3.21",
|
|
16
16
|
"url-parse": "^1.5.10",
|
|
17
17
|
"yaml": "^2.4.5"
|
|
18
18
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"Agent"
|
|
40
40
|
],
|
|
41
41
|
"nx": {},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9f634bdb714061141e277508c124b08d626f6036"
|
|
43
43
|
}
|