@grandlinex/kernel 0.9.8 → 0.10.1

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/Kernel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IBaseKernelModule, ICClient, IKernel, KernelTrigger, PGConfig } from './lib';
1
+ import { IBaseKernelModule, ICClient, IKernel, KernelTrigger } from './lib';
2
2
  import BaseKernelModule from './classes/BaseKernelModule';
3
3
  import { CoreConfig } from './utils';
4
4
  import KernelDB from './database/KernelDB';
@@ -19,7 +19,6 @@ export default class Kernel extends Logger implements IKernel {
19
19
  private moduleList;
20
20
  private kernelModule;
21
21
  private offline;
22
- private pgConf;
23
22
  private updateSkip;
24
23
  private globalConfig;
25
24
  private preRun?;
@@ -42,7 +41,6 @@ export default class Kernel extends Logger implements IKernel {
42
41
  getModule(): IBaseKernelModule<any, any, any, any>;
43
42
  getAppName(): string;
44
43
  getAppCode(): string;
45
- getPGConf(): PGConfig | null;
46
44
  start(): Promise<boolean>;
47
45
  trigerFunction(triger: KernelTrigger): Promise<void>;
48
46
  setTrigerFunction(trigger: KernelTrigger, triggerFunc: (ik: IKernel) => Promise<void>): void;
package/dist/Kernel.js CHANGED
@@ -95,7 +95,6 @@ var Kernel = /** @class */ (function (_super) {
95
95
  _this.offline = false;
96
96
  _this.updateSkip = false;
97
97
  _this.appVersion = 'noVersion';
98
- _this.pgConf = null;
99
98
  _this.master = true;
100
99
  _this.trigerFunction = _this.trigerFunction.bind(_this);
101
100
  if (pathOverride) {
@@ -137,9 +136,6 @@ var Kernel = /** @class */ (function (_super) {
137
136
  Kernel.prototype.getAppCode = function () {
138
137
  return this.appCode;
139
138
  };
140
- Kernel.prototype.getPGConf = function () {
141
- return this.pgConf;
142
- };
143
139
  Kernel.prototype.start = function () {
144
140
  return __awaiter(this, void 0, void 0, function () {
145
141
  return __generator(this, function (_a) {
@@ -325,12 +321,27 @@ var Kernel = /** @class */ (function (_super) {
325
321
  (env === null || env === void 0 ? void 0 : env.DBPORT) &&
326
322
  (env === null || env === void 0 ? void 0 : env.POSTGRES_PASSWORD) &&
327
323
  (env === null || env === void 0 ? void 0 : env.POSTGRES_USER)) {
328
- this.pgConf = {
329
- host: env.DBPATH,
330
- port: Number(env.DBPORT),
331
- password: env.POSTGRES_PASSWORD,
332
- user: env.POSTGRES_USER,
324
+ this.globalConfig.db = {
325
+ postgres: {
326
+ host: env.DBPATH,
327
+ port: Number(env.DBPORT),
328
+ password: env.POSTGRES_PASSWORD,
329
+ user: env.POSTGRES_USER,
330
+ },
331
+ };
332
+ }
333
+ if ((env === null || env === void 0 ? void 0 : env.REDIS_URL) && (env === null || env === void 0 ? void 0 : env.REDIS_PORT)) {
334
+ var conf = {
335
+ url: env.REDIS_URL,
336
+ port: parseInt(env.REDIS_PORT, 10),
337
+ password: env === null || env === void 0 ? void 0 : env.REDIS_PASSWORD,
333
338
  };
339
+ if (this.globalConfig.db) {
340
+ this.globalConfig.db.redis = conf;
341
+ }
342
+ else {
343
+ this.globalConfig.db = { redis: conf };
344
+ }
334
345
  }
335
346
  if (env === null || env === void 0 ? void 0 : env.SERVER_PASSWOR) {
336
347
  this.debug('enable crypto client');
@@ -1,2 +1,12 @@
1
- export default abstract class BaseCache {
1
+ import { IBaseCache, IBaseKernelModule } from '../lib';
2
+ import BaseElement from './BaseElement';
3
+ export default abstract class BaseCache extends BaseElement implements IBaseCache {
4
+ constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>);
5
+ abstract start(): Promise<void>;
6
+ abstract stop(): Promise<void>;
7
+ abstract set(key: string, val: string): Promise<void>;
8
+ abstract get(key: string): Promise<string | undefined>;
9
+ abstract delete(key: string): Promise<void>;
10
+ abstract clearAll(key: string): Promise<void>;
11
+ abstract exist(key: string): Promise<boolean>;
2
12
  }
@@ -1,8 +1,29 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
2
20
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var BaseCache = /** @class */ (function () {
4
- function BaseCache() {
21
+ var BaseElement_1 = __importDefault(require("./BaseElement"));
22
+ var BaseCache = /** @class */ (function (_super) {
23
+ __extends(BaseCache, _super);
24
+ function BaseCache(chanel, module) {
25
+ return _super.call(this, "client-" + chanel, module) || this;
5
26
  }
6
27
  return BaseCache;
7
- }());
28
+ }(BaseElement_1.default));
8
29
  exports.default = BaseCache;
@@ -1,8 +1,5 @@
1
- import { IBaseElement, IBaseKernelModule, IKernel } from '../lib';
2
- import Logger from '../modules/logger/Logger';
3
- export default abstract class BaseClient extends Logger implements IBaseElement {
4
- module: IBaseKernelModule<any, any, any, any>;
1
+ import { IBaseElement, IBaseKernelModule } from '../lib';
2
+ import BaseElement from './BaseElement';
3
+ export default abstract class BaseClient extends BaseElement implements IBaseElement {
5
4
  constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>);
6
- getKernel(): IKernel;
7
- getModule(): IBaseKernelModule<any, any, any, any>;
8
5
  }
@@ -18,20 +18,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var Logger_1 = __importDefault(require("../modules/logger/Logger"));
21
+ var BaseElement_1 = __importDefault(require("./BaseElement"));
22
22
  var BaseClient = /** @class */ (function (_super) {
23
23
  __extends(BaseClient, _super);
24
24
  function BaseClient(chanel, module) {
25
- var _this = _super.call(this, "client-" + chanel, module.getKernel().getGlobalConfig().dir.temp) || this;
26
- _this.module = module;
27
- return _this;
25
+ return _super.call(this, "client-" + chanel, module) || this;
28
26
  }
29
- BaseClient.prototype.getKernel = function () {
30
- return this.module.getKernel();
31
- };
32
- BaseClient.prototype.getModule = function () {
33
- return this.module;
34
- };
35
27
  return BaseClient;
36
- }(Logger_1.default));
28
+ }(BaseElement_1.default));
37
29
  exports.default = BaseClient;
@@ -49,8 +49,9 @@ var BaseEndpoint = /** @class */ (function (_super) {
49
49
  BaseEndpoint.prototype.stop = function () {
50
50
  var _this = this;
51
51
  return new Promise(function (resolve) {
52
- var _a;
53
- (_a = _this.httpServer) === null || _a === void 0 ? void 0 : _a.close(function (err) { return (err ? resolve(false) : resolve(true)); });
52
+ if (_this.httpServer) {
53
+ _this.httpServer.close(function (err) { return (err ? resolve(false) : resolve(true)); });
54
+ }
54
55
  });
55
56
  };
56
57
  BaseEndpoint.prototype.getKernel = function () {
@@ -143,25 +143,28 @@ var BaseKernelModule = /** @class */ (function (_super) {
143
143
  this.tarBridges.forEach(function (b) { return b.setState(state); });
144
144
  };
145
145
  BaseKernelModule.prototype.register = function () {
146
- var _a;
146
+ var _a, _b;
147
147
  return __awaiter(this, void 0, void 0, function () {
148
- return __generator(this, function (_b) {
149
- switch (_b.label) {
148
+ return __generator(this, function (_c) {
149
+ switch (_c.label) {
150
150
  case 0: return [4 /*yield*/, this.waitForBridgeState(lib_1.BridgeState.ready)];
151
151
  case 1:
152
- _b.sent();
152
+ _c.sent();
153
153
  return [4 /*yield*/, this.initModule()];
154
154
  case 2:
155
- _b.sent();
155
+ _c.sent();
156
156
  return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.start())];
157
157
  case 3:
158
- _b.sent();
158
+ _c.sent();
159
+ return [4 /*yield*/, ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.start())];
160
+ case 4:
161
+ _c.sent();
159
162
  this.actionlist.forEach(function (el) {
160
163
  el.register();
161
164
  });
162
165
  return [4 /*yield*/, this.beforeServiceStart()];
163
- case 4:
164
- _b.sent();
166
+ case 5:
167
+ _c.sent();
165
168
  this.servicelist.forEach(function (service) {
166
169
  service.log('Starting');
167
170
  service.start();
@@ -173,14 +176,14 @@ var BaseKernelModule = /** @class */ (function (_super) {
173
176
  });
174
177
  };
175
178
  BaseKernelModule.prototype.shutdown = function () {
176
- var _a;
179
+ var _a, _b;
177
180
  return __awaiter(this, void 0, void 0, function () {
178
181
  var workload;
179
- return __generator(this, function (_b) {
180
- switch (_b.label) {
182
+ return __generator(this, function (_c) {
183
+ switch (_c.label) {
181
184
  case 0: return [4 /*yield*/, this.waitForBridgeState(lib_1.BridgeState.end)];
182
185
  case 1:
183
- _b.sent();
186
+ _c.sent();
184
187
  if (this.endpoint) {
185
188
  this.endpoint.stop();
186
189
  }
@@ -188,10 +191,13 @@ var BaseKernelModule = /** @class */ (function (_super) {
188
191
  this.servicelist.forEach(function (el) { return workload.push(el.stop()); });
189
192
  return [4 /*yield*/, Promise.all(workload)];
190
193
  case 2:
191
- _b.sent();
194
+ _c.sent();
192
195
  return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.disconnect())];
193
196
  case 3:
194
- _b.sent();
197
+ _c.sent();
198
+ return [4 /*yield*/, ((_b = this.cache) === null || _b === void 0 ? void 0 : _b.stop())];
199
+ case 4:
200
+ _c.sent();
195
201
  this.notifyBridges(lib_1.BridgeState.end);
196
202
  return [2 /*return*/];
197
203
  }
@@ -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
- export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, };
10
+ import BaseClient from './BaseClient';
11
+ import BaseBridge from './BaseBridge';
12
+ export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, };
@@ -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;
package/dist/index.d.ts CHANGED
@@ -12,5 +12,5 @@ export * from './lib';
12
12
  export * from './modules';
13
13
  export * from './services';
14
14
  export * from './utils';
15
- export { KernelModule };
15
+ export { KernelModule, Kernel };
16
16
  export default Kernel;
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);
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import express, { Request, Response } from 'express';
3
3
  import { CoreConfig } from '../utils/config';
4
- import BaseCache from '../classes/BaseCache';
5
4
  import { ILogger } from '../modules/logger/Logger';
6
5
  import { IAuthProvider, JwtToken } from '../classes/BaseAuthProvider';
7
6
  import { IDataBase } from '../modules/DBConnector/lib';
@@ -13,6 +12,15 @@ export declare enum BridgeState {
13
12
  }
14
13
  export declare type ActionTypes = 'POST' | 'GET' | 'USE';
15
14
  export declare type ServiceStates = 'INIT' | 'RUNNING' | 'SLEEPING';
15
+ export interface IBaseCache {
16
+ start(): Promise<void>;
17
+ set(key: string, val: string): Promise<void>;
18
+ get(key: string): Promise<string | undefined>;
19
+ delete(key: string): Promise<void>;
20
+ clearAll(key: string): Promise<void>;
21
+ exist(key: string): Promise<boolean>;
22
+ stop(): Promise<void>;
23
+ }
16
24
  export interface ICClient {
17
25
  setAuthProvider(provider: IAuthProvider): boolean;
18
26
  encrypt(message: string): {
@@ -59,9 +67,8 @@ export interface IKernel extends ILogger {
59
67
  setDevMode(mode: boolean): void;
60
68
  getGlobalConfig(): CoreConfig;
61
69
  getAppServerPort(): number;
62
- getPGConf(): PGConfig | null;
63
70
  }
64
- export interface IBaseKernelModule<T extends IDataBase<any> | null, P extends IBaseElement | null, C extends BaseCache | null, E extends IBaseEndpoint | null> extends ILogger {
71
+ export interface IBaseKernelModule<T extends IDataBase<any> | null, P extends IBaseElement | null, C extends IBaseCache | null, E extends IBaseEndpoint | null> extends ILogger {
65
72
  addSrcBridge(bridge: IBaseBrige): void;
66
73
  addTarBridge(bridge: IBaseBrige): void;
67
74
  getBridges(): IBaseBrige[];
@@ -110,12 +117,6 @@ export interface KeyType {
110
117
  secret: string;
111
118
  auth: Buffer;
112
119
  }
113
- export interface PGConfig {
114
- host: string;
115
- port: number;
116
- user: string;
117
- password: string;
118
- }
119
120
  export interface IBaseBrige {
120
121
  connect(): void;
121
122
  setState(state: BridgeState): void;
@@ -87,27 +87,28 @@ var PGConnector = /** @class */ (function (_super) {
87
87
  });
88
88
  };
89
89
  PGConnector.prototype.connect = function (run) {
90
+ var _a;
90
91
  return __awaiter(this, void 0, void 0, function () {
91
92
  var conf, client, e_2, query;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
93
+ return __generator(this, function (_b) {
94
+ switch (_b.label) {
94
95
  case 0:
95
- conf = this.module.getKernel().getPGConf();
96
- if (conf === null) {
96
+ conf = (_a = this.module.getKernel().getGlobalConfig().db) === null || _a === void 0 ? void 0 : _a.postgres;
97
+ if (conf === undefined) {
97
98
  this.error('NO PG CONFIG FOUND');
98
99
  return [2 /*return*/, false];
99
100
  }
100
- _a.label = 1;
101
+ _b.label = 1;
101
102
  case 1:
102
- _a.trys.push([1, 3, , 4]);
103
+ _b.trys.push([1, 3, , 4]);
103
104
  client = new pg_1.Client(conf);
104
105
  return [4 /*yield*/, client.connect()];
105
106
  case 2:
106
- _a.sent();
107
+ _b.sent();
107
108
  this.db = client;
108
109
  return [3 /*break*/, 4];
109
110
  case 3:
110
- e_2 = _a.sent();
111
+ e_2 = _b.sent();
111
112
  this.error(e_2);
112
113
  process.exit(3);
113
114
  return [2 /*return*/, false];
@@ -115,7 +116,7 @@ var PGConnector = /** @class */ (function (_super) {
115
116
  this.log('DB Connected');
116
117
  return [4 /*yield*/, client.query("SELECT count(schema_name)\n FROM information_schema.schemata\n where schema_name = '" + this.schemaName + "';")];
117
118
  case 5:
118
- query = _a.sent();
119
+ query = _b.sent();
119
120
  if (query.rows.length !== 1) {
120
121
  process.exit(3);
121
122
  }
@@ -133,10 +134,10 @@ var PGConnector = /** @class */ (function (_super) {
133
134
  },
134
135
  ])];
135
136
  case 6:
136
- _a.sent();
137
+ _b.sent();
137
138
  return [4 /*yield*/, this.initNewDB()];
138
139
  case 7:
139
- _a.sent();
140
+ _b.sent();
140
141
  return [2 /*return*/, true];
141
142
  case 8: return [2 /*return*/, query.rows[0].count === '1'];
142
143
  }
@@ -237,8 +238,15 @@ var PGConnector = /** @class */ (function (_super) {
237
238
  var _a;
238
239
  return __awaiter(this, void 0, void 0, function () {
239
240
  return __generator(this, function (_b) {
240
- (_a = this.db) === null || _a === void 0 ? void 0 : _a.end();
241
- return [2 /*return*/, true];
241
+ switch (_b.label) {
242
+ case 0:
243
+ if (!this.db) return [3 /*break*/, 2];
244
+ return [4 /*yield*/, ((_a = this.db) === null || _a === void 0 ? void 0 : _a.end())];
245
+ case 1:
246
+ _b.sent();
247
+ _b.label = 2;
248
+ case 2: return [2 /*return*/, true];
249
+ }
242
250
  });
243
251
  });
244
252
  };
@@ -96,7 +96,9 @@ var SQLightConnector = /** @class */ (function (_super) {
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();
99
- query === null || query === void 0 ? void 0 : query.run([key]);
99
+ if (query) {
100
+ query.run([key]);
101
+ }
100
102
  return [3 /*break*/, 3];
101
103
  case 2:
102
104
  e_1 = _b.sent();
@@ -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);
@@ -0,0 +1,27 @@
1
+ import { RedisClientType } from 'redis/dist/lib/client';
2
+ import BaseCache from '../../classes/BaseCache';
3
+ import { IBaseKernelModule } from '../../lib';
4
+ declare type RedisClient = RedisClientType<any, any> | null;
5
+ /**
6
+ * @class BaseRedisCache
7
+ * Multichannel Redis Client
8
+ */
9
+ export default abstract class BaseRedisCache extends BaseCache {
10
+ client: RedisClient;
11
+ constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>);
12
+ /**
13
+ * Start Redis client
14
+ * @throws Error No Redis config found
15
+ */
16
+ start(): Promise<void>;
17
+ set(key: string, val: string): Promise<void>;
18
+ get(key: string): Promise<string | undefined>;
19
+ delete(key: string): Promise<void>;
20
+ expire(key: string, seconds: number): Promise<void>;
21
+ exist(key: string): Promise<boolean>;
22
+ clearAll(): Promise<void>;
23
+ getRaw(): RedisClient;
24
+ stop(): Promise<void>;
25
+ private parseKey;
26
+ }
27
+ export {};
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ var redis_1 = require("redis");
58
+ var BaseCache_1 = __importDefault(require("../../classes/BaseCache"));
59
+ /**
60
+ * @class BaseRedisCache
61
+ * Multichannel Redis Client
62
+ */
63
+ var BaseRedisCache = /** @class */ (function (_super) {
64
+ __extends(BaseRedisCache, _super);
65
+ function BaseRedisCache(chanel, module) {
66
+ var _this = _super.call(this, chanel, module) || this;
67
+ _this.client = null;
68
+ return _this;
69
+ }
70
+ /**
71
+ * Start Redis client
72
+ * @throws Error No Redis config found
73
+ */
74
+ BaseRedisCache.prototype.start = function () {
75
+ var _a;
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var config;
78
+ var _this = this;
79
+ return __generator(this, function (_b) {
80
+ switch (_b.label) {
81
+ case 0:
82
+ config = (_a = this.getModule().getKernel().getGlobalConfig().db) === null || _a === void 0 ? void 0 : _a.redis;
83
+ if (!config) {
84
+ throw new Error('NO REDIS CONFIG FOUND');
85
+ }
86
+ this.client = (0, redis_1.createClient)({
87
+ socket: {
88
+ host: config.url,
89
+ port: config.port,
90
+ password: config.password,
91
+ },
92
+ });
93
+ this.client.on('error', function (err) {
94
+ _this.error(err);
95
+ });
96
+ return [4 /*yield*/, this.client.connect()];
97
+ case 1:
98
+ _b.sent();
99
+ this.log('Started');
100
+ return [2 /*return*/];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ BaseRedisCache.prototype.set = function (key, val) {
106
+ var _a;
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ return __generator(this, function (_b) {
109
+ switch (_b.label) {
110
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.set(this.parseKey(key), val))];
111
+ case 1:
112
+ _b.sent();
113
+ return [2 /*return*/];
114
+ }
115
+ });
116
+ });
117
+ };
118
+ BaseRedisCache.prototype.get = function (key) {
119
+ var _a;
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ return __generator(this, function (_b) {
122
+ return [2 /*return*/, (_a = this.client) === null || _a === void 0 ? void 0 : _a.get(this.parseKey(key))];
123
+ });
124
+ });
125
+ };
126
+ BaseRedisCache.prototype.delete = function (key) {
127
+ var _a;
128
+ return __awaiter(this, void 0, void 0, function () {
129
+ return __generator(this, function (_b) {
130
+ switch (_b.label) {
131
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.del(this.parseKey(key)))];
132
+ case 1:
133
+ _b.sent();
134
+ return [2 /*return*/];
135
+ }
136
+ });
137
+ });
138
+ };
139
+ BaseRedisCache.prototype.expire = function (key, seconds) {
140
+ var _a;
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ return __generator(this, function (_b) {
143
+ switch (_b.label) {
144
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.expire(this.parseKey(key), seconds))];
145
+ case 1:
146
+ _b.sent();
147
+ return [2 /*return*/];
148
+ }
149
+ });
150
+ });
151
+ };
152
+ BaseRedisCache.prototype.exist = function (key) {
153
+ var _a;
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var ex;
156
+ return __generator(this, function (_b) {
157
+ switch (_b.label) {
158
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.exists(this.parseKey(key)))];
159
+ case 1:
160
+ ex = _b.sent();
161
+ return [2 /*return*/, !!ex];
162
+ }
163
+ });
164
+ });
165
+ };
166
+ BaseRedisCache.prototype.clearAll = function () {
167
+ var _a;
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ return __generator(this, function (_b) {
170
+ switch (_b.label) {
171
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.flushAll())];
172
+ case 1:
173
+ _b.sent();
174
+ return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ BaseRedisCache.prototype.getRaw = function () {
180
+ return this.client;
181
+ };
182
+ BaseRedisCache.prototype.stop = function () {
183
+ var _a;
184
+ return __awaiter(this, void 0, void 0, function () {
185
+ return __generator(this, function (_b) {
186
+ switch (_b.label) {
187
+ case 0: return [4 /*yield*/, ((_a = this.client) === null || _a === void 0 ? void 0 : _a.disconnect())];
188
+ case 1:
189
+ _b.sent();
190
+ return [2 /*return*/];
191
+ }
192
+ });
193
+ });
194
+ };
195
+ BaseRedisCache.prototype.parseKey = function (key) {
196
+ return this.chanel + ":" + key;
197
+ };
198
+ return BaseRedisCache;
199
+ }(BaseCache_1.default));
200
+ exports.default = BaseRedisCache;
@@ -0,0 +1,2 @@
1
+ import BaseRedisCache from './BaseRedisCache';
2
+ export { BaseRedisCache };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseRedisCache = void 0;
7
+ var BaseRedisCache_1 = __importDefault(require("./BaseRedisCache"));
8
+ exports.BaseRedisCache = BaseRedisCache_1.default;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cors = void 0;
4
4
  var cors = function (req, res, next) {
5
+ res.setHeader('Access-Control-Allow-Headers', '*');
5
6
  res.setHeader('Access-Control-Allow-Origin', '*');
7
+ res.setHeader('Access-Control-Allow-Methods', '*');
6
8
  next();
7
9
  };
8
10
  exports.cors = cors;
@@ -1,3 +1,4 @@
1
1
  export * from './crypto';
2
2
  export * from './DBConnector';
3
3
  export * from './logger';
4
+ export * from './cache';
@@ -13,3 +13,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./crypto"), exports);
14
14
  __exportStar(require("./DBConnector"), exports);
15
15
  __exportStar(require("./logger"), exports);
16
+ __exportStar(require("./cache"), exports);
@@ -1,3 +1,9 @@
1
+ export interface PGConfig {
2
+ host: string;
3
+ port: number;
4
+ user: string;
5
+ password: string;
6
+ }
1
7
  export declare enum OsRelease {
2
8
  'FREEBSD' = 0,
3
9
  'OPENBSD' = 1,
@@ -24,5 +30,13 @@ export interface CoreConfig extends BaseCoreConfig {
24
30
  port: number;
25
31
  domain: string;
26
32
  };
33
+ db?: {
34
+ redis?: {
35
+ url: string;
36
+ port: number;
37
+ password?: string;
38
+ };
39
+ postgres?: PGConfig;
40
+ };
27
41
  }
28
42
  export declare function getConfig(appName: string, pathOverride?: string): BaseCoreConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/kernel",
3
- "version": "0.9.8",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,21 +34,22 @@
34
34
  "express": "^4.17.1",
35
35
  "jsonwebtoken": "^8.5.1",
36
36
  "node-forge": "^0.10.0",
37
- "pg": "^8.7.1"
37
+ "pg": "^8.7.1",
38
+ "redis": "^4.0.0-rc.1"
38
39
  },
39
40
  "devDependencies": {
41
+ "@grandlinex/docs-to-openapi": "^0.6.0",
40
42
  "@types/better-sqlite3": "^7.4.0",
41
- "@types/cors": "^2.8.12",
42
43
  "@types/express": "^4.17.13",
43
- "@types/jest": "^27.0.1",
44
+ "@types/jest": "^27.0.2",
44
45
  "@types/jsonwebtoken": "^8.5.5",
45
- "@types/node": "^16.9.2",
46
- "@types/node-forge": "^0.10.4",
46
+ "@types/node": "^16.9.6",
47
+ "@types/node-forge": "^0.10.5",
47
48
  "@types/pg": "^8.6.1",
48
- "@types/react": "^17.0.21",
49
- "@typescript-eslint/eslint-plugin": "^4.31.1",
50
- "@typescript-eslint/parser": "^4.31.1",
51
- "@grandlinex/docs-to-openapi": "^0.6.0",
49
+ "@types/react": "^17.0.24",
50
+ "@types/redis": "^2.8.32",
51
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
52
+ "@typescript-eslint/parser": "^4.31.2",
52
53
  "cross-env": "^7.0.3",
53
54
  "eslint": "^7.32.0",
54
55
  "eslint-config-airbnb": "^18.2.1",
@@ -58,16 +59,16 @@
58
59
  "eslint-plugin-jest": "^24.4.2",
59
60
  "eslint-plugin-jsx-a11y": "^6.4.1",
60
61
  "eslint-plugin-prettier": "^4.0.0",
61
- "eslint-plugin-react": "^7.25.2",
62
+ "eslint-plugin-react": "^7.26.0",
62
63
  "eslint-plugin-react-hooks": "^4.2.0",
63
64
  "html-webpack-plugin": "^5.3.2",
64
- "jest": "^27.2.0",
65
+ "jest": "^27.2.1",
65
66
  "jest-junit": "^12.2.0",
66
67
  "prettier": "^2.4.1",
67
68
  "ts-jest": "^27.0.5",
68
- "ts-loader": "^9.2.5",
69
+ "ts-loader": "^9.2.6",
69
70
  "ts-node": "^10.2.1",
70
- "typedoc": "^0.22.3",
71
+ "typedoc": "^0.22.4",
71
72
  "typescript": "^4.4.3"
72
73
  },
73
74
  "repository": {