@grandlinex/kernel 0.9.4 → 0.9.9
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/README.md +12 -1
- package/dist/Kernel.js +1 -1
- package/dist/KernelModule.js +11 -5
- package/dist/classes/BaseBridge.d.ts +1 -1
- package/dist/classes/BaseBridge.js +1 -5
- package/dist/classes/BaseKernelModule.d.ts +4 -5
- package/dist/classes/BaseKernelModule.js +13 -34
- package/dist/classes/index.d.ts +3 -1
- package/dist/classes/index.js +5 -1
- package/dist/database/KernelDB.d.ts +3 -1
- package/dist/database/KernelDB.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/modules/DBConnector/classes/DBConnection.d.ts +15 -5
- package/dist/modules/DBConnector/classes/DBConnection.js +110 -1
- package/dist/modules/DBConnector/connectors/PGConnector.d.ts +2 -3
- package/dist/modules/DBConnector/connectors/PGConnector.js +2 -3
- package/dist/modules/DBConnector/connectors/SQLightConnector.d.ts +2 -2
- package/dist/modules/DBConnector/connectors/SQLightConnector.js +23 -55
- package/dist/modules/DBConnector/index.d.ts +1 -0
- package/dist/modules/DBConnector/index.js +11 -0
- package/dist/modules/DBConnector/lib/index.d.ts +2 -1
- package/dist/modules/DBConnector/updater/BaseDBUpdate.d.ts +6 -6
- package/dist/modules/DBConnector/updater/BaseDBUpdate.js +8 -6
- package/dist/modules/crypto/CryptoClient.js +2 -3
- package/dist/modules/crypto/utils/cors.d.ts +3 -0
- package/dist/modules/crypto/utils/cors.js +10 -0
- package/dist/modules/crypto/utils/cryptoUtils.js +2 -2
- package/dist/modules/crypto/utils/index.d.ts +1 -0
- package/dist/modules/crypto/utils/index.js +1 -0
- package/package.json +17 -20
- package/tsconfig.json +0 -92
package/README.md
CHANGED
|
@@ -8,7 +8,18 @@ GrandLineX is an out-of-the-box server framework on top of ExpressJs.
|
|
|
8
8
|
[](https://github.com/GrandlineX/kernel)
|
|
9
9
|
[](https://www.npmjs.com/package/@grandlinex/kernel)
|
|
10
10
|

|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
### Status
|
|
13
|
+

|
|
14
|
+

|
|
15
|
+

|
|
16
|
+

|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
### Issues
|
|
20
|
+

|
|
21
|
+

|
|
22
|
+

|
|
12
23
|
|
|
13
24
|
|
|
14
25
|
## Documentation
|
package/dist/Kernel.js
CHANGED
|
@@ -286,7 +286,7 @@ var Kernel = /** @class */ (function (_super) {
|
|
|
286
286
|
return [4 /*yield*/, this.trigerFunction('stop')];
|
|
287
287
|
case 1:
|
|
288
288
|
_a.sent();
|
|
289
|
-
this.
|
|
289
|
+
this.moduleList.forEach(function (el) { return workload.push(el.shutdown()); });
|
|
290
290
|
return [4 /*yield*/, Promise.all(workload)];
|
|
291
291
|
case 2:
|
|
292
292
|
_a.sent();
|
package/dist/KernelModule.js
CHANGED
|
@@ -65,10 +65,16 @@ var KernelModule = /** @class */ (function (_super) {
|
|
|
65
65
|
__extends(KernelModule, _super);
|
|
66
66
|
function KernelModule(kernel) {
|
|
67
67
|
var _this = _super.call(this, 'kernel', kernel) || this;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
[
|
|
69
|
+
new ApiVersionAction_1.default(_this),
|
|
70
|
+
new ApiAuthTestAction_1.default(_this),
|
|
71
|
+
new GetTokenAction_1.default(_this),
|
|
72
|
+
].forEach(function (action) {
|
|
73
|
+
_this.addAction(action);
|
|
74
|
+
});
|
|
75
|
+
[new OfflineService_1.default(_this)].forEach(function (service) {
|
|
76
|
+
_this.addService(service);
|
|
77
|
+
});
|
|
72
78
|
return _this;
|
|
73
79
|
}
|
|
74
80
|
KernelModule.prototype.initModule = function () {
|
|
@@ -77,7 +83,7 @@ var KernelModule = /** @class */ (function (_super) {
|
|
|
77
83
|
return __generator(this, function (_a) {
|
|
78
84
|
switch (_a.label) {
|
|
79
85
|
case 0:
|
|
80
|
-
db = new KernelDB_1.default(this
|
|
86
|
+
db = new KernelDB_1.default(this);
|
|
81
87
|
this.setDb(db);
|
|
82
88
|
endpoint = new KernelEndpoint_1.default('api', this, this.getKernel().getAppServerPort());
|
|
83
89
|
this.setEndpoint(endpoint);
|
|
@@ -8,5 +8,5 @@ export default class BaseBridge extends Logger implements IBaseBrige {
|
|
|
8
8
|
connect(): void;
|
|
9
9
|
setState(state: BridgeState): void;
|
|
10
10
|
waitForState(state: BridgeState): Promise<boolean>;
|
|
11
|
-
getTarget():
|
|
11
|
+
getTarget(): IBaseKernelModule<any, any, any, any>;
|
|
12
12
|
}
|
|
@@ -87,11 +87,7 @@ var BaseBridge = /** @class */ (function (_super) {
|
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
89
|
BaseBridge.prototype.getTarget = function () {
|
|
90
|
-
return
|
|
91
|
-
return __generator(this, function (_a) {
|
|
92
|
-
return [2 /*return*/, this.target];
|
|
93
|
-
});
|
|
94
|
-
});
|
|
90
|
+
return this.target;
|
|
95
91
|
};
|
|
96
92
|
return BaseBridge;
|
|
97
93
|
}(modules_1.Logger));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBaseBrige, IBaseEndpoint, IBaseKernelModule, IKernel } from '../lib';
|
|
1
|
+
import { BridgeState, IBaseBrige, IBaseEndpoint, IBaseKernelModule, IKernel } from '../lib';
|
|
2
2
|
import BaseAction from './BaseAction';
|
|
3
3
|
import Logger from '../modules/logger/Logger';
|
|
4
4
|
import BaseService from './BaseService';
|
|
@@ -30,10 +30,8 @@ export default abstract class BaseKernelModule<T extends IDataBase<any> | null,
|
|
|
30
30
|
setClient(client: P): void;
|
|
31
31
|
getCache(): C | null;
|
|
32
32
|
setCache(cache: C): void;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
notifyBridgesRead(): void;
|
|
36
|
-
notifyBridgesEnd(): void;
|
|
33
|
+
waitForBridgeState(state: BridgeState): Promise<void>;
|
|
34
|
+
notifyBridges(state: BridgeState): void;
|
|
37
35
|
abstract initModule(): Promise<void>;
|
|
38
36
|
abstract beforeServiceStart(): Promise<void>;
|
|
39
37
|
register(): Promise<void>;
|
|
@@ -44,5 +42,6 @@ export default abstract class BaseKernelModule<T extends IDataBase<any> | null,
|
|
|
44
42
|
getName(): string;
|
|
45
43
|
getDependencyList(): string[];
|
|
46
44
|
getBridges(): IBaseBrige[];
|
|
45
|
+
getBridgeModule(name: string): IBaseKernelModule<any, any, any, any> | undefined;
|
|
47
46
|
abstract final(): Promise<void>;
|
|
48
47
|
}
|
|
@@ -123,34 +123,14 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
123
123
|
BaseKernelModule.prototype.setCache = function (cache) {
|
|
124
124
|
this.cache = cache;
|
|
125
125
|
};
|
|
126
|
-
BaseKernelModule.prototype.
|
|
126
|
+
BaseKernelModule.prototype.waitForBridgeState = function (state) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
128
|
var waitList;
|
|
129
129
|
return __generator(this, function (_a) {
|
|
130
130
|
switch (_a.label) {
|
|
131
131
|
case 0:
|
|
132
132
|
waitList = [];
|
|
133
|
-
this.srcBridges.forEach(function (b) {
|
|
134
|
-
return waitList.push(b.waitForState(lib_1.BridgeState.ready));
|
|
135
|
-
});
|
|
136
|
-
return [4 /*yield*/, Promise.all(waitList)];
|
|
137
|
-
case 1:
|
|
138
|
-
_a.sent();
|
|
139
|
-
return [2 /*return*/];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
BaseKernelModule.prototype.waitForBridgesEnd = function () {
|
|
145
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
var waitList;
|
|
147
|
-
return __generator(this, function (_a) {
|
|
148
|
-
switch (_a.label) {
|
|
149
|
-
case 0:
|
|
150
|
-
waitList = [];
|
|
151
|
-
this.tarBridges.forEach(function (b) {
|
|
152
|
-
return waitList.push(b.waitForState(lib_1.BridgeState.end));
|
|
153
|
-
});
|
|
133
|
+
this.srcBridges.forEach(function (b) { return waitList.push(b.waitForState(state)); });
|
|
154
134
|
return [4 /*yield*/, Promise.all(waitList)];
|
|
155
135
|
case 1:
|
|
156
136
|
_a.sent();
|
|
@@ -159,24 +139,21 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
159
139
|
});
|
|
160
140
|
});
|
|
161
141
|
};
|
|
162
|
-
BaseKernelModule.prototype.
|
|
163
|
-
this.tarBridges.forEach(function (b) { return b.setState(
|
|
164
|
-
};
|
|
165
|
-
BaseKernelModule.prototype.notifyBridgesEnd = function () {
|
|
166
|
-
this.srcBridges.forEach(function (b) { return b.setState(lib_1.BridgeState.end); });
|
|
142
|
+
BaseKernelModule.prototype.notifyBridges = function (state) {
|
|
143
|
+
this.tarBridges.forEach(function (b) { return b.setState(state); });
|
|
167
144
|
};
|
|
168
145
|
BaseKernelModule.prototype.register = function () {
|
|
169
146
|
var _a;
|
|
170
147
|
return __awaiter(this, void 0, void 0, function () {
|
|
171
148
|
return __generator(this, function (_b) {
|
|
172
149
|
switch (_b.label) {
|
|
173
|
-
case 0: return [4 /*yield*/, this.
|
|
150
|
+
case 0: return [4 /*yield*/, this.waitForBridgeState(lib_1.BridgeState.ready)];
|
|
174
151
|
case 1:
|
|
175
152
|
_b.sent();
|
|
176
153
|
return [4 /*yield*/, this.initModule()];
|
|
177
154
|
case 2:
|
|
178
155
|
_b.sent();
|
|
179
|
-
return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.
|
|
156
|
+
return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.start())];
|
|
180
157
|
case 3:
|
|
181
158
|
_b.sent();
|
|
182
159
|
this.actionlist.forEach(function (el) {
|
|
@@ -189,7 +166,7 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
189
166
|
service.log('Starting');
|
|
190
167
|
service.start();
|
|
191
168
|
});
|
|
192
|
-
this.
|
|
169
|
+
this.notifyBridges(lib_1.BridgeState.ready);
|
|
193
170
|
return [2 /*return*/];
|
|
194
171
|
}
|
|
195
172
|
});
|
|
@@ -201,7 +178,7 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
201
178
|
var workload;
|
|
202
179
|
return __generator(this, function (_b) {
|
|
203
180
|
switch (_b.label) {
|
|
204
|
-
case 0: return [4 /*yield*/, this.
|
|
181
|
+
case 0: return [4 /*yield*/, this.waitForBridgeState(lib_1.BridgeState.end)];
|
|
205
182
|
case 1:
|
|
206
183
|
_b.sent();
|
|
207
184
|
if (this.endpoint) {
|
|
@@ -215,9 +192,7 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
215
192
|
return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.disconnect())];
|
|
216
193
|
case 3:
|
|
217
194
|
_b.sent();
|
|
218
|
-
|
|
219
|
-
case 4:
|
|
220
|
-
_b.sent();
|
|
195
|
+
this.notifyBridges(lib_1.BridgeState.end);
|
|
221
196
|
return [2 /*return*/];
|
|
222
197
|
}
|
|
223
198
|
});
|
|
@@ -241,6 +216,10 @@ var BaseKernelModule = /** @class */ (function (_super) {
|
|
|
241
216
|
BaseKernelModule.prototype.getBridges = function () {
|
|
242
217
|
return this.srcBridges;
|
|
243
218
|
};
|
|
219
|
+
BaseKernelModule.prototype.getBridgeModule = function (name) {
|
|
220
|
+
var br = this.srcBridges.find(function (bridge) { return bridge.getTarget().getName() === name; });
|
|
221
|
+
return br === null || br === void 0 ? void 0 : br.getTarget();
|
|
222
|
+
};
|
|
244
223
|
return BaseKernelModule;
|
|
245
224
|
}(Logger_1.default));
|
|
246
225
|
exports.default = BaseKernelModule;
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ import BaseLoopService from './BaseLoopService';
|
|
|
7
7
|
import BaseApiAction from './BaseApiAction';
|
|
8
8
|
import BaseService from './BaseService';
|
|
9
9
|
import BaseAuthProvider from './BaseAuthProvider';
|
|
10
|
-
|
|
10
|
+
import BaseClient from './BaseClient';
|
|
11
|
+
import BaseBridge from './BaseBridge';
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, };
|
package/dist/classes/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BaseAction = exports.BaseCache = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
|
|
6
|
+
exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
|
|
7
7
|
var BaseAction_1 = __importDefault(require("./BaseAction"));
|
|
8
8
|
exports.BaseAction = BaseAction_1.default;
|
|
9
9
|
var BaseCache_1 = __importDefault(require("./BaseCache"));
|
|
@@ -22,3 +22,7 @@ var BaseService_1 = __importDefault(require("./BaseService"));
|
|
|
22
22
|
exports.BaseService = BaseService_1.default;
|
|
23
23
|
var BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
|
|
24
24
|
exports.BaseAuthProvider = BaseAuthProvider_1.default;
|
|
25
|
+
var BaseClient_1 = __importDefault(require("./BaseClient"));
|
|
26
|
+
exports.BaseClient = BaseClient_1.default;
|
|
27
|
+
var BaseBridge_1 = __importDefault(require("./BaseBridge"));
|
|
28
|
+
exports.BaseBridge = BaseBridge_1.default;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { KeyType } from '../lib';
|
|
2
|
+
import { IBaseKernelModule, KeyType } from '../lib';
|
|
3
3
|
import PGConnector from '../modules/DBConnector/connectors/PGConnector';
|
|
4
|
+
export declare const KERNEL_DB_VERSION = "1";
|
|
4
5
|
export default class KernelDB extends PGConnector {
|
|
6
|
+
constructor(module: IBaseKernelModule<any, any, any, any>);
|
|
5
7
|
initNewDB(): Promise<void>;
|
|
6
8
|
setKey(secret: string, iv: Buffer, auth: Buffer): Promise<number>;
|
|
7
9
|
getKey(id: number): Promise<KeyType>;
|
|
@@ -54,14 +54,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
55
|
};
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.KERNEL_DB_VERSION = void 0;
|
|
57
58
|
var crypto_1 = require("crypto");
|
|
58
59
|
var newInit_1 = __importDefault(require("./newInit"));
|
|
59
60
|
var PGConnector_1 = __importDefault(require("../modules/DBConnector/connectors/PGConnector"));
|
|
60
61
|
var utils_1 = require("../modules/crypto/utils");
|
|
62
|
+
exports.KERNEL_DB_VERSION = '1';
|
|
61
63
|
var KernelDB = /** @class */ (function (_super) {
|
|
62
64
|
__extends(KernelDB, _super);
|
|
63
|
-
function KernelDB() {
|
|
64
|
-
return _super
|
|
65
|
+
function KernelDB(module) {
|
|
66
|
+
return _super.call(this, module, exports.KERNEL_DB_VERSION) || this;
|
|
65
67
|
}
|
|
66
68
|
KernelDB.prototype.initNewDB = function () {
|
|
67
69
|
return __awaiter(this, void 0, void 0, function () {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -13,12 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.KernelModule = void 0;
|
|
16
|
+
exports.Kernel = exports.KernelModule = void 0;
|
|
17
17
|
/**
|
|
18
18
|
* @name Kernel Main Module
|
|
19
19
|
* @author David Nagy
|
|
20
20
|
*/
|
|
21
21
|
var Kernel_1 = __importDefault(require("./Kernel"));
|
|
22
|
+
exports.Kernel = Kernel_1.default;
|
|
22
23
|
var KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
23
24
|
exports.KernelModule = KernelModule_1.default;
|
|
24
25
|
__exportStar(require("./actions"), exports);
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export interface IBaseKernelModule<T extends IDataBase<any> | null, P extends IB
|
|
|
84
84
|
getCache(): C | null;
|
|
85
85
|
setCache(cache: C): void;
|
|
86
86
|
getName(): string;
|
|
87
|
+
getBridgeModule(name: string): IBaseKernelModule<any, any, any, any> | undefined;
|
|
87
88
|
}
|
|
88
89
|
export interface IBaseEndpoint extends IBaseElement {
|
|
89
90
|
start(): Promise<boolean>;
|
|
@@ -119,6 +120,6 @@ export interface IBaseBrige {
|
|
|
119
120
|
connect(): void;
|
|
120
121
|
setState(state: BridgeState): void;
|
|
121
122
|
waitForState(state: BridgeState): Promise<boolean>;
|
|
122
|
-
getTarget():
|
|
123
|
+
getTarget(): IBaseKernelModule<any, any, any, any>;
|
|
123
124
|
}
|
|
124
125
|
export declare type WorkLoad = Promise<any>[];
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { ILogger } from '../../logger/Logger';
|
|
2
|
-
import { IBaseDBUpdate, IDataBaseConnection } from '../lib';
|
|
3
|
-
export default abstract class DBConnection implements ILogger, IDataBaseConnection {
|
|
2
|
+
import { ConfigType, IBaseDBUpdate, IDataBaseConnection, SQLQuery } from '../lib';
|
|
3
|
+
export default abstract class DBConnection<T> implements ILogger, IDataBaseConnection {
|
|
4
4
|
logger: ILogger;
|
|
5
5
|
dbversion: string;
|
|
6
6
|
updater: IBaseDBUpdate | null;
|
|
7
|
+
schemaName: string;
|
|
7
8
|
private conected;
|
|
8
|
-
constructor(dbversion: string, logger: ILogger);
|
|
9
|
-
abstract disconnect(): Promise<boolean>;
|
|
9
|
+
constructor(dbversion: string, schemaName: string, logger: ILogger);
|
|
10
10
|
setUpdateChain(chain: IBaseDBUpdate): void;
|
|
11
|
+
canUpdate(): Promise<boolean>;
|
|
12
|
+
getCurrenDBVersion(): Promise<string>;
|
|
13
|
+
update(): Promise<boolean>;
|
|
11
14
|
isConected(): boolean;
|
|
12
15
|
setConnected(): void;
|
|
13
|
-
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
abstract disconnect(): Promise<boolean>;
|
|
18
|
+
abstract connect(): Promise<boolean>;
|
|
19
|
+
abstract execScripts(list: SQLQuery[]): Promise<T[]>;
|
|
20
|
+
abstract getConfig(key: string): Promise<ConfigType>;
|
|
21
|
+
abstract setConfig(key: string, value: string): Promise<boolean>;
|
|
22
|
+
abstract configExist(key: string): Promise<boolean>;
|
|
23
|
+
abstract removeConfig(key: string): Promise<void>;
|
|
14
24
|
debug(...ags: unknown[]): void;
|
|
15
25
|
error(...ags: unknown[]): void;
|
|
16
26
|
info(...ags: unknown[]): void;
|
|
@@ -1,22 +1,131 @@
|
|
|
1
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
var DBConnection = /** @class */ (function () {
|
|
4
|
-
function DBConnection(dbversion, logger) {
|
|
40
|
+
function DBConnection(dbversion, schemaName, logger) {
|
|
5
41
|
this.logger = logger;
|
|
6
42
|
this.conected = false;
|
|
7
43
|
this.dbversion = dbversion;
|
|
8
44
|
this.updater = null;
|
|
45
|
+
this.schemaName = schemaName;
|
|
9
46
|
this.debug = this.debug.bind(this);
|
|
10
47
|
}
|
|
11
48
|
DBConnection.prototype.setUpdateChain = function (chain) {
|
|
12
49
|
this.updater = chain;
|
|
13
50
|
};
|
|
51
|
+
DBConnection.prototype.canUpdate = function () {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var version;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0: return [4 /*yield*/, this.getConfig('dbversion')];
|
|
57
|
+
case 1:
|
|
58
|
+
version = _a.sent();
|
|
59
|
+
return [2 /*return*/, version.c_value !== this.dbversion];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
DBConnection.prototype.getCurrenDBVersion = function () {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var version;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, this.getConfig('dbversion')];
|
|
70
|
+
case 1:
|
|
71
|
+
version = _a.sent();
|
|
72
|
+
return [2 /*return*/, version.c_value];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
DBConnection.prototype.update = function () {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var _a, update, _b, _c;
|
|
80
|
+
return __generator(this, function (_d) {
|
|
81
|
+
switch (_d.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
_a = this.updater;
|
|
84
|
+
if (!_a) return [3 /*break*/, 2];
|
|
85
|
+
return [4 /*yield*/, this.canUpdate()];
|
|
86
|
+
case 1:
|
|
87
|
+
_a = (_d.sent());
|
|
88
|
+
_d.label = 2;
|
|
89
|
+
case 2:
|
|
90
|
+
if (!_a) return [3 /*break*/, 4];
|
|
91
|
+
_c = (_b = this.updater).find;
|
|
92
|
+
return [4 /*yield*/, this.getCurrenDBVersion()];
|
|
93
|
+
case 3:
|
|
94
|
+
update = _c.apply(_b, [_d.sent()]);
|
|
95
|
+
if (update) {
|
|
96
|
+
return [2 /*return*/, update.update()];
|
|
97
|
+
}
|
|
98
|
+
_d.label = 4;
|
|
99
|
+
case 4: return [2 /*return*/, true];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
14
104
|
DBConnection.prototype.isConected = function () {
|
|
15
105
|
return this.conected;
|
|
16
106
|
};
|
|
17
107
|
DBConnection.prototype.setConnected = function () {
|
|
18
108
|
this.conected = true;
|
|
19
109
|
};
|
|
110
|
+
DBConnection.prototype.start = function () {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, this.connect()];
|
|
115
|
+
case 1:
|
|
116
|
+
_a.sent();
|
|
117
|
+
return [4 /*yield*/, this.canUpdate()];
|
|
118
|
+
case 2:
|
|
119
|
+
if (!_a.sent()) return [3 /*break*/, 4];
|
|
120
|
+
return [4 /*yield*/, this.update()];
|
|
121
|
+
case 3:
|
|
122
|
+
_a.sent();
|
|
123
|
+
_a.label = 4;
|
|
124
|
+
case 4: return [2 /*return*/];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
20
129
|
DBConnection.prototype.debug = function () {
|
|
21
130
|
var ags = [];
|
|
22
131
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -3,10 +3,9 @@ import { ConfigType, IDataBase, SQLQuery } from '../lib';
|
|
|
3
3
|
import { IBaseKernelModule } from '../../../lib';
|
|
4
4
|
import DBConnection from '../classes/DBConnection';
|
|
5
5
|
declare type PGDBType = Client;
|
|
6
|
-
export default abstract class PGConnector extends DBConnection implements IDataBase<PGDBType> {
|
|
6
|
+
export default abstract class PGConnector extends DBConnection<QueryResult> implements IDataBase<PGDBType> {
|
|
7
7
|
db: PGDBType | null;
|
|
8
8
|
module: IBaseKernelModule<any, any, any, any>;
|
|
9
|
-
schemaName: string;
|
|
10
9
|
constructor(module: IBaseKernelModule<any, any, any, any>, dbversion: string);
|
|
11
10
|
removeConfig(key: string): Promise<void>;
|
|
12
11
|
abstract initNewDB(): Promise<void>;
|
|
@@ -15,7 +14,7 @@ export default abstract class PGConnector extends DBConnection implements IDataB
|
|
|
15
14
|
configExist(key: string): Promise<boolean>;
|
|
16
15
|
setConfig(key: string, value: string): Promise<boolean>;
|
|
17
16
|
getConfig(key: string): Promise<ConfigType>;
|
|
18
|
-
execScripts(list: SQLQuery[]): Promise<QueryResult[]
|
|
17
|
+
execScripts(list: SQLQuery[]): Promise<QueryResult[]>;
|
|
19
18
|
disconnect(): Promise<boolean>;
|
|
20
19
|
}
|
|
21
20
|
export {};
|
|
@@ -59,10 +59,9 @@ var DBConnection_1 = __importDefault(require("../classes/DBConnection"));
|
|
|
59
59
|
var PGConnector = /** @class */ (function (_super) {
|
|
60
60
|
__extends(PGConnector, _super);
|
|
61
61
|
function PGConnector(module, dbversion) {
|
|
62
|
-
var _this = _super.call(this, dbversion, module) || this;
|
|
62
|
+
var _this = _super.call(this, dbversion, module.getName(), module) || this;
|
|
63
63
|
_this.module = module;
|
|
64
64
|
_this.db = null;
|
|
65
|
-
_this.schemaName = module.getName();
|
|
66
65
|
return _this;
|
|
67
66
|
}
|
|
68
67
|
PGConnector.prototype.removeConfig = function (key) {
|
|
@@ -228,7 +227,7 @@ var PGConnector = /** @class */ (function (_super) {
|
|
|
228
227
|
case 6:
|
|
229
228
|
e_4 = _b.sent();
|
|
230
229
|
this.error(e_4);
|
|
231
|
-
return [2 /*return*/,
|
|
230
|
+
return [2 /*return*/, []];
|
|
232
231
|
case 7: return [2 /*return*/];
|
|
233
232
|
}
|
|
234
233
|
});
|
|
@@ -4,13 +4,13 @@ import { ConfigType, IDataBase, SQLQuery } from '../lib';
|
|
|
4
4
|
import { IBaseKernelModule } from '../../../lib';
|
|
5
5
|
import DBConnection from '../classes/DBConnection';
|
|
6
6
|
declare type DbType = Database.Database;
|
|
7
|
-
export default abstract class SQLightConnector extends DBConnection implements IDataBase<DbType> {
|
|
7
|
+
export default abstract class SQLightConnector extends DBConnection<RunResult> implements IDataBase<DbType> {
|
|
8
8
|
db: DbType | null;
|
|
9
9
|
private path;
|
|
10
10
|
constructor(module: IBaseKernelModule<any, any, any, any>, dbversion: string);
|
|
11
11
|
removeConfig(key: string): Promise<void>;
|
|
12
12
|
abstract initNewDB(): Promise<void>;
|
|
13
|
-
connect(
|
|
13
|
+
connect(): Promise<boolean>;
|
|
14
14
|
getRawDBObject(): DbType | null;
|
|
15
15
|
configExist(key: string): Promise<boolean>;
|
|
16
16
|
setConfig(key: string, value: string): Promise<boolean>;
|
|
@@ -79,7 +79,7 @@ var DBConnection_1 = __importDefault(require("../classes/DBConnection"));
|
|
|
79
79
|
var SQLightConnector = /** @class */ (function (_super) {
|
|
80
80
|
__extends(SQLightConnector, _super);
|
|
81
81
|
function SQLightConnector(module, dbversion) {
|
|
82
|
-
var _this = _super.call(this, dbversion, module) || this;
|
|
82
|
+
var _this = _super.call(this, dbversion, 'main', module) || this;
|
|
83
83
|
_this.path = Path.join(module.getKernel().getGlobalConfig().dir.db, module.getName() + ".db");
|
|
84
84
|
_this.db = null;
|
|
85
85
|
return _this;
|
|
@@ -92,7 +92,7 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
92
92
|
switch (_b.label) {
|
|
93
93
|
case 0:
|
|
94
94
|
_b.trys.push([0, 2, , 3]);
|
|
95
|
-
q = "DELETE\n FROM
|
|
95
|
+
q = "DELETE \n FROM " + this.schemaName + ".config\n WHERE c_key = $1;";
|
|
96
96
|
return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare(q))];
|
|
97
97
|
case 1:
|
|
98
98
|
query = _b.sent();
|
|
@@ -107,9 +107,9 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
};
|
|
110
|
-
SQLightConnector.prototype.connect = function (
|
|
110
|
+
SQLightConnector.prototype.connect = function () {
|
|
111
111
|
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var query, result, version,
|
|
112
|
+
var query, result, version, e_2;
|
|
113
113
|
return __generator(this, function (_a) {
|
|
114
114
|
switch (_a.label) {
|
|
115
115
|
case 0:
|
|
@@ -124,66 +124,34 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
124
124
|
}
|
|
125
125
|
_a.label = 1;
|
|
126
126
|
case 1:
|
|
127
|
-
_a.trys.push([1,
|
|
128
|
-
query = this.db.prepare(
|
|
127
|
+
_a.trys.push([1, 2, , 5]);
|
|
128
|
+
query = this.db.prepare("SELECT * FROM " + this.schemaName + ".config;");
|
|
129
129
|
result = query.all();
|
|
130
130
|
version = result.find(function (el) {
|
|
131
131
|
return el.c_key === 'dbversion';
|
|
132
132
|
});
|
|
133
|
-
|
|
134
|
-
if (version === undefined) {
|
|
135
|
-
v = '0';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
v = version.c_value;
|
|
139
|
-
}
|
|
140
|
-
if (!(v !== this.dbversion && this.updater !== null)) return [3 /*break*/, 6];
|
|
141
|
-
if (!run) return [3 /*break*/, 3];
|
|
142
|
-
return [4 /*yield*/, run('Datenbank Update')];
|
|
133
|
+
return [2 /*return*/, !!version];
|
|
143
134
|
case 2:
|
|
144
|
-
_a.sent();
|
|
145
|
-
_a.label = 3;
|
|
146
|
-
case 3:
|
|
147
|
-
this.log("DB UPDATE INFO from " + v + " to " + this.dbversion);
|
|
148
|
-
newUpdate = this.updater.find(v);
|
|
149
|
-
if (!(newUpdate !== null)) return [3 /*break*/, 5];
|
|
150
|
-
return [4 /*yield*/, newUpdate.update()];
|
|
151
|
-
case 4:
|
|
152
|
-
res = _a.sent();
|
|
153
|
-
if (!res) {
|
|
154
|
-
this.error('Error While DB UPDATE');
|
|
155
|
-
}
|
|
156
|
-
return [2 /*return*/, res];
|
|
157
|
-
case 5:
|
|
158
|
-
this.error('Cant Found UPDATE ');
|
|
159
|
-
return [2 /*return*/, false];
|
|
160
|
-
case 6: return [2 /*return*/, true];
|
|
161
|
-
case 7:
|
|
162
135
|
e_2 = _a.sent();
|
|
163
136
|
this.warn(e_2);
|
|
164
137
|
this.log('Create new Database');
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
exec: "INSERT INTO main.config (c_key, c_value)\n VALUES ('dbversion', '" + this.dbversion + "');",
|
|
177
|
-
param: [],
|
|
178
|
-
},
|
|
179
|
-
])];
|
|
180
|
-
case 10:
|
|
138
|
+
return [4 /*yield*/, this.execScripts([
|
|
139
|
+
{
|
|
140
|
+
exec: "CREATE TABLE " + this.schemaName + ".config(c_key text not null ,c_value text , PRIMARY KEY (c_key));",
|
|
141
|
+
param: [],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
exec: "INSERT INTO " + this.schemaName + ".config (c_key, c_value)\n VALUES ('dbversion', '" + this.dbversion + "');",
|
|
145
|
+
param: [],
|
|
146
|
+
},
|
|
147
|
+
])];
|
|
148
|
+
case 3:
|
|
181
149
|
_a.sent();
|
|
182
150
|
return [4 /*yield*/, this.initNewDB()];
|
|
183
|
-
case
|
|
151
|
+
case 4:
|
|
184
152
|
_a.sent();
|
|
185
153
|
return [2 /*return*/, true];
|
|
186
|
-
case
|
|
154
|
+
case 5: return [2 /*return*/];
|
|
187
155
|
}
|
|
188
156
|
});
|
|
189
157
|
});
|
|
@@ -196,7 +164,7 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
196
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
197
165
|
var query, exist;
|
|
198
166
|
return __generator(this, function (_b) {
|
|
199
|
-
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("SELECT *\n FROM
|
|
167
|
+
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("SELECT *\n FROM " + this.schemaName + ".config\n WHERE c_key = '" + key + "'");
|
|
200
168
|
exist = query === null || query === void 0 ? void 0 : query.get();
|
|
201
169
|
return [2 /*return*/, !!exist && exist.c_key !== undefined && exist.c_value !== undefined];
|
|
202
170
|
});
|
|
@@ -207,7 +175,7 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
207
175
|
return __awaiter(this, void 0, void 0, function () {
|
|
208
176
|
var query;
|
|
209
177
|
return __generator(this, function (_b) {
|
|
210
|
-
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("REPLACE INTO
|
|
178
|
+
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("REPLACE INTO " + this.schemaName + ".config (c_key, c_value)\n VALUES ('" + key + "', '" + value + "');");
|
|
211
179
|
if (query === undefined) {
|
|
212
180
|
return [2 /*return*/, false];
|
|
213
181
|
}
|
|
@@ -221,7 +189,7 @@ var SQLightConnector = /** @class */ (function (_super) {
|
|
|
221
189
|
return __awaiter(this, void 0, void 0, function () {
|
|
222
190
|
var query;
|
|
223
191
|
return __generator(this, function (_b) {
|
|
224
|
-
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("SELECT *\n FROM
|
|
192
|
+
query = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare("SELECT *\n FROM " + this.schemaName + ".config\n WHERE c_key = '" + key + "'");
|
|
225
193
|
return [2 /*return*/, query === null || query === void 0 ? void 0 : query.get()];
|
|
226
194
|
});
|
|
227
195
|
});
|
|
@@ -2,4 +2,5 @@ import DBConnection from './classes/DBConnection';
|
|
|
2
2
|
import PGConnector from './connectors/PGConnector';
|
|
3
3
|
import SQLightConnector from './connectors/SQLightConnector';
|
|
4
4
|
import BaseDBUpdate from './updater/BaseDBUpdate';
|
|
5
|
+
export * from './lib';
|
|
5
6
|
export { DBConnection, PGConnector, BaseDBUpdate, SQLightConnector };
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
14
|
};
|
|
@@ -12,3 +22,4 @@ var SQLightConnector_1 = __importDefault(require("./connectors/SQLightConnector"
|
|
|
12
22
|
exports.SQLightConnector = SQLightConnector_1.default;
|
|
13
23
|
var BaseDBUpdate_1 = __importDefault(require("./updater/BaseDBUpdate"));
|
|
14
24
|
exports.BaseDBUpdate = BaseDBUpdate_1.default;
|
|
25
|
+
__exportStar(require("./lib"), exports);
|
|
@@ -27,8 +27,9 @@ export interface IDataBase<T> extends IDataBaseConnection {
|
|
|
27
27
|
}
|
|
28
28
|
export interface IDataBaseConnection extends ILogger {
|
|
29
29
|
setUpdateChain(chain: IBaseDBUpdate): void;
|
|
30
|
+
start(): Promise<void>;
|
|
30
31
|
isConected(): boolean;
|
|
31
32
|
disconnect(): Promise<boolean>;
|
|
32
33
|
setConnected(): void;
|
|
33
|
-
connect(
|
|
34
|
+
connect(): Promise<boolean>;
|
|
34
35
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import DBConnection from '../classes/DBConnection';
|
|
2
2
|
import { IBaseDBUpdate } from '../lib';
|
|
3
|
-
export default abstract class BaseDBUpdate implements IBaseDBUpdate {
|
|
3
|
+
export default abstract class BaseDBUpdate<T> implements IBaseDBUpdate {
|
|
4
4
|
srcVersion: string;
|
|
5
5
|
tarVersion: string;
|
|
6
|
-
private db;
|
|
6
|
+
private readonly db;
|
|
7
7
|
private nextUpdate;
|
|
8
|
-
constructor(srcVersion: string, tarVersion: string, db: DBConnection);
|
|
8
|
+
protected constructor(srcVersion: string, tarVersion: string, db: DBConnection<T>);
|
|
9
9
|
update(): Promise<boolean>;
|
|
10
10
|
abstract performe(): Promise<boolean>;
|
|
11
11
|
updateNext(): Promise<boolean>;
|
|
12
|
-
setNext(db: BaseDBUpdate): void;
|
|
13
|
-
find(version: string): BaseDBUpdate | null;
|
|
14
|
-
getDb(): DBConnection
|
|
12
|
+
setNext(db: BaseDBUpdate<T>): void;
|
|
13
|
+
find(version: string): BaseDBUpdate<T> | null;
|
|
14
|
+
getDb(): DBConnection<T>;
|
|
15
15
|
getSource(): string;
|
|
16
16
|
}
|
|
@@ -45,20 +45,22 @@ var BaseDBUpdate = /** @class */ (function () {
|
|
|
45
45
|
}
|
|
46
46
|
BaseDBUpdate.prototype.update = function () {
|
|
47
47
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var perf, next
|
|
48
|
+
var perf, next;
|
|
49
49
|
return __generator(this, function (_a) {
|
|
50
50
|
switch (_a.label) {
|
|
51
51
|
case 0: return [4 /*yield*/, this.performe()];
|
|
52
52
|
case 1:
|
|
53
53
|
perf = _a.sent();
|
|
54
|
+
if (perf) {
|
|
55
|
+
this.db.log("Update DB from " + this.srcVersion + " to " + this.tarVersion + " successful");
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error("Updating DB from " + this.srcVersion + " to " + this.tarVersion + " failed");
|
|
59
|
+
}
|
|
54
60
|
return [4 /*yield*/, this.updateNext()];
|
|
55
61
|
case 2:
|
|
56
62
|
next = _a.sent();
|
|
57
|
-
|
|
58
|
-
if (result) {
|
|
59
|
-
this.db.log("Update DB from " + this.srcVersion + " to " + this.tarVersion + " successful");
|
|
60
|
-
}
|
|
61
|
-
return [2 /*return*/, result];
|
|
63
|
+
return [2 /*return*/, perf && next];
|
|
62
64
|
}
|
|
63
65
|
});
|
|
64
66
|
});
|
|
@@ -60,7 +60,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
60
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
61
|
var crypto = __importStar(require("crypto"));
|
|
62
62
|
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
63
|
-
var crypto_1 = require("crypto");
|
|
64
63
|
var encryptionType = 'aes-256-gcm';
|
|
65
64
|
var encryptionEncoding = 'base64';
|
|
66
65
|
var bufferEncryption = 'utf8';
|
|
@@ -83,7 +82,7 @@ var CryptoClient = /** @class */ (function () {
|
|
|
83
82
|
};
|
|
84
83
|
CryptoClient.prototype.generateSecureToken = function (length) {
|
|
85
84
|
return new Promise(function (resolve) {
|
|
86
|
-
|
|
85
|
+
crypto.randomBytes(length, function (err, buf) {
|
|
87
86
|
if (err) {
|
|
88
87
|
resolve('');
|
|
89
88
|
}
|
|
@@ -134,7 +133,7 @@ var CryptoClient = /** @class */ (function () {
|
|
|
134
133
|
});
|
|
135
134
|
};
|
|
136
135
|
CryptoClient.prototype.jwtGenerateAccessToken = function (data) {
|
|
137
|
-
return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn: '
|
|
136
|
+
return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn: '1 days' });
|
|
138
137
|
};
|
|
139
138
|
CryptoClient.prototype.apiTokenValidation = function (username, token, requestType) {
|
|
140
139
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cors = void 0;
|
|
4
|
+
var cors = function (req, res, next) {
|
|
5
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
6
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
7
|
+
res.setHeader('Access-Control-Allow-Methods', '*');
|
|
8
|
+
next();
|
|
9
|
+
};
|
|
10
|
+
exports.cors = cors;
|
|
@@ -10,4 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./cors"), exports);
|
|
13
14
|
__exportStar(require("./cryptoUtils"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"run": "ts-node tests/run.ts",
|
|
12
12
|
"test-converage": "jest --runInBand --ci --collectCoverage --coverageDirectory=\"./coverage\" --reporters=default --reporters=jest-junit",
|
|
13
13
|
"makeDocs": "typedoc",
|
|
14
|
-
"openDocs": "npm run makeDocs
|
|
15
|
-
"makeSpec": "
|
|
14
|
+
"openDocs": "npm run makeDocs",
|
|
15
|
+
"makeSpec": "makeOpenApi"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"typescript",
|
|
@@ -26,10 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "BSD-3-Clause",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"axios": "^0.21.
|
|
29
|
+
"axios": "^0.21.4",
|
|
30
30
|
"better-sqlite3": "^7.4.3",
|
|
31
31
|
"body-parser": "^1.19.0",
|
|
32
|
-
"cors": "^2.8.5",
|
|
33
32
|
"dotenv": "^10.0.0",
|
|
34
33
|
"electron-log": "^4.4.1",
|
|
35
34
|
"express": "^4.17.1",
|
|
@@ -39,38 +38,36 @@
|
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
40
|
"@types/better-sqlite3": "^7.4.0",
|
|
42
|
-
"@types/cors": "^2.8.12",
|
|
43
41
|
"@types/express": "^4.17.13",
|
|
44
42
|
"@types/jest": "^27.0.1",
|
|
45
43
|
"@types/jsonwebtoken": "^8.5.5",
|
|
46
|
-
"@types/node": "^16.
|
|
47
|
-
"@types/node-
|
|
48
|
-
"@types/node-forge": "^0.10.3",
|
|
44
|
+
"@types/node": "^16.9.2",
|
|
45
|
+
"@types/node-forge": "^0.10.4",
|
|
49
46
|
"@types/pg": "^8.6.1",
|
|
50
|
-
"@types/react": "^17.0.
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
52
|
-
"@typescript-eslint/parser": "^4.
|
|
47
|
+
"@types/react": "^17.0.21",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
|
49
|
+
"@typescript-eslint/parser": "^4.31.1",
|
|
50
|
+
"@grandlinex/docs-to-openapi": "^0.6.0",
|
|
53
51
|
"cross-env": "^7.0.3",
|
|
54
52
|
"eslint": "^7.32.0",
|
|
55
53
|
"eslint-config-airbnb": "^18.2.1",
|
|
56
|
-
"eslint-config-airbnb-typescript": "^
|
|
54
|
+
"eslint-config-airbnb-typescript": "^14.0.0",
|
|
57
55
|
"eslint-config-prettier": "^8.3.0",
|
|
58
56
|
"eslint-plugin-import": "^2.24.2",
|
|
59
|
-
"eslint-plugin-jest": "^24.4.
|
|
57
|
+
"eslint-plugin-jest": "^24.4.2",
|
|
60
58
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
61
59
|
"eslint-plugin-prettier": "^4.0.0",
|
|
62
|
-
"eslint-plugin-react": "^7.25.
|
|
60
|
+
"eslint-plugin-react": "^7.25.2",
|
|
63
61
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
64
62
|
"html-webpack-plugin": "^5.3.2",
|
|
65
|
-
"
|
|
66
|
-
"jest": "^27.1.0",
|
|
63
|
+
"jest": "^27.2.0",
|
|
67
64
|
"jest-junit": "^12.2.0",
|
|
68
|
-
"prettier": "^2.
|
|
65
|
+
"prettier": "^2.4.1",
|
|
69
66
|
"ts-jest": "^27.0.5",
|
|
70
67
|
"ts-loader": "^9.2.5",
|
|
71
68
|
"ts-node": "^10.2.1",
|
|
72
|
-
"typedoc": "^0.
|
|
73
|
-
"typescript": "^4.4.
|
|
69
|
+
"typedoc": "^0.22.3",
|
|
70
|
+
"typescript": "^4.4.3"
|
|
74
71
|
},
|
|
75
72
|
"repository": {
|
|
76
73
|
"type": "git",
|
package/tsconfig.json
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react",
|
|
4
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
5
|
-
"baseUrl": "./src",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
/* Basic Options */
|
|
8
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
9
|
-
"target": "es5",
|
|
10
|
-
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
13
|
-
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
14
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
15
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
16
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
17
|
-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
18
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
19
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
20
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
21
|
-
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
22
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
23
|
-
// "composite": true, /* Enable project compilation */
|
|
24
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
25
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
26
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
27
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
28
|
-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
29
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
30
|
-
|
|
31
|
-
/* Strict Type-Checking Options */
|
|
32
|
-
"strict": true,
|
|
33
|
-
/* Enable all strict type-checking options. */
|
|
34
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
35
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
36
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
37
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
38
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
39
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
40
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
41
|
-
|
|
42
|
-
/* Additional Checks */
|
|
43
|
-
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
44
|
-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
45
|
-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
46
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
47
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
48
|
-
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
49
|
-
|
|
50
|
-
/* Module Resolution Options */
|
|
51
|
-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
52
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
53
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
54
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
55
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
56
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
57
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
58
|
-
"esModuleInterop": true,
|
|
59
|
-
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
60
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
61
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
62
|
-
|
|
63
|
-
/* Source Map Options */
|
|
64
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
65
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
67
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
68
|
-
|
|
69
|
-
/* Experimental Options */
|
|
70
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
71
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
72
|
-
|
|
73
|
-
/* Advanced Options */
|
|
74
|
-
"skipLibCheck": true,
|
|
75
|
-
/* Skip type checking of declaration files. */
|
|
76
|
-
"forceConsistentCasingInFileNames": true
|
|
77
|
-
/* Disallow inconsistently-cased references to the same file. */
|
|
78
|
-
},
|
|
79
|
-
"exclude": [
|
|
80
|
-
"node_modules",
|
|
81
|
-
"dist",
|
|
82
|
-
"data",
|
|
83
|
-
"tests"
|
|
84
|
-
],
|
|
85
|
-
"typedocOptions": {
|
|
86
|
-
"entryPoints": [
|
|
87
|
-
"./src"
|
|
88
|
-
],
|
|
89
|
-
"out": "docs",
|
|
90
|
-
"exclude": "node_modules"
|
|
91
|
-
}
|
|
92
|
-
}
|