@sphereon/ssi-sdk.agent-config 0.15.1 → 0.15.2-next.103
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/dataSources.d.ts +17 -0
- package/dist/dataSources.d.ts.map +1 -0
- package/dist/dataSources.js +81 -0
- package/dist/dataSources.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/dataSources.ts +79 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions';
|
|
3
|
+
import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions';
|
|
4
|
+
export declare class DataSources {
|
|
5
|
+
private dataSources;
|
|
6
|
+
private configs;
|
|
7
|
+
private static singleton;
|
|
8
|
+
static singleInstance(): DataSources;
|
|
9
|
+
static newInstance(configs?: Map<string, DataSourceOptions>): DataSources;
|
|
10
|
+
private constructor();
|
|
11
|
+
addConfig(dbName: string, config: DataSourceOptions): this;
|
|
12
|
+
deleteConfig(dbName: string): this;
|
|
13
|
+
getConfig(dbName: string): BaseDataSourceOptions;
|
|
14
|
+
getDbNames(): string[];
|
|
15
|
+
getDbConnection(dbName: string): Promise<DataSource>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=dataSources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAA;AAIzE,qBAAa,WAAW;IACtB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,OAAO,CAAA;IAEf,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;IAK1D,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKlC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAQzC,UAAU,IAAI,MAAM,EAAE;IAIvB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CA4B3D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DataSources = void 0;
|
|
16
|
+
const debug_1 = __importDefault(require("debug"));
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const debug = (0, debug_1.default)(`demo:databaseService`);
|
|
19
|
+
class DataSources {
|
|
20
|
+
static singleInstance() {
|
|
21
|
+
if (!DataSources.singleton) {
|
|
22
|
+
DataSources.singleton = new DataSources();
|
|
23
|
+
}
|
|
24
|
+
return DataSources.singleton;
|
|
25
|
+
}
|
|
26
|
+
static newInstance(configs) {
|
|
27
|
+
return new DataSources(configs);
|
|
28
|
+
}
|
|
29
|
+
constructor(configs) {
|
|
30
|
+
this.dataSources = new Map();
|
|
31
|
+
this.configs = configs !== null && configs !== void 0 ? configs : new Map();
|
|
32
|
+
}
|
|
33
|
+
addConfig(dbName, config) {
|
|
34
|
+
this.configs.set(dbName, config);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
deleteConfig(dbName) {
|
|
38
|
+
this.configs.delete(dbName);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
getConfig(dbName) {
|
|
42
|
+
const config = this.configs.get(dbName);
|
|
43
|
+
if (!config) {
|
|
44
|
+
throw Error(`No DB config found for ${dbName}`);
|
|
45
|
+
}
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
getDbNames() {
|
|
49
|
+
return [...this.configs.keys()];
|
|
50
|
+
}
|
|
51
|
+
getDbConnection(dbName) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const config = this.getConfig(dbName);
|
|
54
|
+
/*if (config.synchronize) {
|
|
55
|
+
return Promise.reject(
|
|
56
|
+
`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
|
|
57
|
+
)
|
|
58
|
+
}*/
|
|
59
|
+
let dataSource = this.dataSources.get(dbName);
|
|
60
|
+
if (dataSource) {
|
|
61
|
+
return dataSource;
|
|
62
|
+
}
|
|
63
|
+
dataSource = yield new typeorm_1.DataSource(Object.assign(Object.assign({}, config), { name: dbName })).initialize();
|
|
64
|
+
this.dataSources.set(dbName, dataSource);
|
|
65
|
+
if (config.synchronize) {
|
|
66
|
+
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`);
|
|
67
|
+
}
|
|
68
|
+
else if (config.migrationsRun) {
|
|
69
|
+
debug(`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`);
|
|
73
|
+
yield dataSource.runMigrations();
|
|
74
|
+
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`);
|
|
75
|
+
}
|
|
76
|
+
return dataSource;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.DataSources = DataSources;
|
|
81
|
+
//# sourceMappingURL=dataSources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataSources.js","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,qCAAoC;AAIpC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,sBAAsB,CAAC,CAAA;AAE3C,MAAa,WAAW;IAMf,MAAM,CAAC,cAAc;QAC1B,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE;YAC1B,WAAW,CAAC,SAAS,GAAG,IAAI,WAAW,EAAE,CAAA;SAC1C;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;QAhBpD,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAA;QAiBjD,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,GAAG,EAAiC,CAAA;IACpE,CAAC;IAED,SAAS,CAAC,MAAc,EAAE,MAAyB;QACjD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,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oDAAoD,CAAC,CAAA;aAC3F;YACD,OAAO,UAAU,CAAA;QACnB,CAAC;KAAA;CACF;AAvED,kCAuEC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
+
__exportStar(require("./dataSources"), exports);
|
|
20
21
|
__exportStar(require("./agentCreator"), exports);
|
|
21
22
|
__exportStar(require("./objectCreator"), exports);
|
|
22
23
|
__exportStar(require("./generic"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,iDAA8B;AAC9B,kDAA+B;AAC/B,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,gDAA6B;AAC7B,iDAA8B;AAC9B,kDAA+B;AAC/B,4CAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.agent-config",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2-next.103+2e89d229",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@veramo/core": "4.2.0",
|
|
13
|
+
"debug": "^4.3.4",
|
|
13
14
|
"jsonpointer": "^5.0.1",
|
|
14
15
|
"typeorm": "^0.3.12",
|
|
15
16
|
"url-parse": "^1.5.10",
|
|
16
17
|
"yaml": "^2.2.2"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"@types/
|
|
20
|
+
"@types/debug": "^4.1.8",
|
|
21
|
+
"@types/url-parse": "^1.4.8",
|
|
22
|
+
"typescript": "4.9.5"
|
|
20
23
|
},
|
|
21
24
|
"files": [
|
|
22
25
|
"dist/**/*",
|
|
@@ -35,5 +38,5 @@
|
|
|
35
38
|
"SSI",
|
|
36
39
|
"Agent"
|
|
37
40
|
],
|
|
38
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "2e89d229090e7ce002492181816dbea5846e08fe"
|
|
39
42
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Debug from 'debug'
|
|
2
|
+
import { DataSource } from 'typeorm'
|
|
3
|
+
import { BaseDataSourceOptions } from 'typeorm/data-source/BaseDataSourceOptions'
|
|
4
|
+
import { DataSourceOptions } from 'typeorm/data-source/DataSourceOptions'
|
|
5
|
+
|
|
6
|
+
const debug = Debug(`demo:databaseService`)
|
|
7
|
+
|
|
8
|
+
export class DataSources {
|
|
9
|
+
private dataSources = new Map<string, DataSource>()
|
|
10
|
+
private configs
|
|
11
|
+
|
|
12
|
+
private static singleton: DataSources
|
|
13
|
+
|
|
14
|
+
public static singleInstance() {
|
|
15
|
+
if (!DataSources.singleton) {
|
|
16
|
+
DataSources.singleton = new DataSources()
|
|
17
|
+
}
|
|
18
|
+
return DataSources.singleton
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static newInstance(configs?: Map<string, DataSourceOptions>) {
|
|
22
|
+
return new DataSources(configs)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private constructor(configs?: Map<string, DataSourceOptions>) {
|
|
26
|
+
this.configs = configs ?? new Map<string, BaseDataSourceOptions>()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addConfig(dbName: string, config: DataSourceOptions): this {
|
|
30
|
+
this.configs.set(dbName, config)
|
|
31
|
+
return this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
deleteConfig(dbName: string): this {
|
|
35
|
+
this.configs.delete(dbName)
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getConfig(dbName: string): BaseDataSourceOptions {
|
|
40
|
+
const config = this.configs.get(dbName)
|
|
41
|
+
if (!config) {
|
|
42
|
+
throw Error(`No DB config found for ${dbName}`)
|
|
43
|
+
}
|
|
44
|
+
return config
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public getDbNames(): string[] {
|
|
48
|
+
return [...this.configs.keys()]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getDbConnection(dbName: string): Promise<DataSource> {
|
|
52
|
+
const config = this.getConfig(dbName)
|
|
53
|
+
/*if (config.synchronize) {
|
|
54
|
+
return Promise.reject(
|
|
55
|
+
`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`
|
|
56
|
+
)
|
|
57
|
+
}*/
|
|
58
|
+
|
|
59
|
+
let dataSource = this.dataSources.get(dbName)
|
|
60
|
+
if (dataSource) {
|
|
61
|
+
return dataSource
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
dataSource = await new DataSource({ ...(config as DataSourceOptions), name: dbName }).initialize()
|
|
65
|
+
this.dataSources.set(dbName, dataSource)
|
|
66
|
+
if (config.synchronize) {
|
|
67
|
+
debug(`WARNING: Automatic migrations need to be disabled in this app! Adjust the database configuration and set synchronize to false`)
|
|
68
|
+
} else if (config.migrationsRun) {
|
|
69
|
+
debug(
|
|
70
|
+
`Migrations are currently managed from config. Please set migrationsRun and synchronize to false to get consistent behaviour. We run migrations from code explicitly`
|
|
71
|
+
)
|
|
72
|
+
} else {
|
|
73
|
+
debug(`Running ${dataSource.migrations.length} migration(s) from code if needed...`)
|
|
74
|
+
await dataSource.runMigrations()
|
|
75
|
+
debug(`${dataSource.migrations.length} migration(s) from code were inspected and applied`)
|
|
76
|
+
}
|
|
77
|
+
return dataSource
|
|
78
|
+
}
|
|
79
|
+
}
|