chyz 2.0.0-rc.23 → 2.0.0-rc.25
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/BaseChyz.d.ts +1 -2
- package/BaseChyz.d.ts.map +1 -1
- package/BaseChyz.js +64 -50
- package/base/CEvents.d.ts +3 -0
- package/base/CEvents.d.ts.map +1 -1
- package/base/CEvents.js +3 -0
- package/package.json +1 -1
package/BaseChyz.d.ts
CHANGED
package/BaseChyz.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseChyz.d.ts","sourceRoot":"","sources":["../src/BaseChyz.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseChyz.d.ts","sourceRoot":"","sources":["../src/BaseChyz.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAC;AAsGjC,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC;IACvB,MAAM,CAAC,SAAS,EAAE,GAAG,CAAS;IAC9B,OAAO,CAAC,KAAK,CAAgB;IAC7B,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACnB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAc;IAC/B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAiB;IACzC,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,MAAM,CAAC,WAAW,CAA4B;IACtD,OAAc,UAAU,EAAE,GAAG,CAAK;IAClC,OAAc,WAAW,EAAE,GAAG,CAAK;IACnC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAU;IAGtC,MAAM,KAAK,YAAY,IAAI,GAAG,CAE7B;IAED,MAAM,KAAK,YAAY,CAAC,KAAK,EAAE,GAAG,EAEjC;IAED,IAAI,cAAc,IAAI,M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z.js
CHANGED
|
@@ -35,18 +35,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
/**
|
|
39
|
+
* https server
|
|
40
|
+
*/
|
|
41
|
+
const express_1 = __importDefault(require("express"));
|
|
42
|
+
const bodyParser = require("body-parser");
|
|
43
|
+
const https_1 = require("https");
|
|
44
|
+
const http_1 = require("http");
|
|
45
|
+
const fs = require("fs");
|
|
46
|
+
/**
|
|
47
|
+
* Freamwork
|
|
48
|
+
*/
|
|
38
49
|
const base_1 = require("./base");
|
|
39
50
|
const Utils_1 = __importStar(require("./requiments/Utils"));
|
|
40
51
|
const Logs_1 = require("./base/Logs");
|
|
41
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
42
|
-
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
43
52
|
const CEvents_1 = require("./base/CEvents");
|
|
44
|
-
const https = require('https');
|
|
45
|
-
const express = require("express");
|
|
46
53
|
const compression = require('compression');
|
|
47
|
-
const fs = require('fs');
|
|
54
|
+
// const fs = require('fs');
|
|
55
|
+
const ip = require('ip');
|
|
56
|
+
const methodOverride = require('method-override');
|
|
57
|
+
const Server = (0, express_1.default)();
|
|
58
|
+
const cors = require('cors');
|
|
59
|
+
const emitter = require('events').EventEmitter;
|
|
60
|
+
const em = new emitter();
|
|
61
|
+
/**
|
|
62
|
+
* set request id
|
|
63
|
+
*/
|
|
64
|
+
Object.defineProperty(Server.request, 'reqId', {
|
|
65
|
+
configurable: true,
|
|
66
|
+
enumerable: true,
|
|
67
|
+
writable: true
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(Server.request, 'user', {
|
|
70
|
+
configurable: true,
|
|
71
|
+
enumerable: true,
|
|
72
|
+
writable: true
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(Server.request, 'identity', {
|
|
75
|
+
configurable: true,
|
|
76
|
+
enumerable: true,
|
|
77
|
+
writable: true
|
|
78
|
+
});
|
|
48
79
|
const validate = require('validate.js');
|
|
49
|
-
|
|
80
|
+
const dayjs = require('dayjs');
|
|
81
|
+
const utc = require('dayjs/plugin/utc');
|
|
82
|
+
const relative = require('dayjs/plugin/relativeTime');
|
|
83
|
+
dayjs.extend(utc);
|
|
84
|
+
dayjs.extend(relative);
|
|
50
85
|
/**
|
|
51
86
|
* Use
|
|
52
87
|
* selectedBox: {
|
|
@@ -85,39 +120,14 @@ validate.extend(validate.validators.datetime, {
|
|
|
85
120
|
// The value is guaranteed not to be null or undefined but otherwise it
|
|
86
121
|
// could be anything.
|
|
87
122
|
parse: function (value, options) {
|
|
88
|
-
return +(
|
|
123
|
+
return +dayjs().utc(value);
|
|
89
124
|
},
|
|
90
125
|
// Input is a unix timestamp
|
|
91
126
|
format: function (value, options) {
|
|
92
127
|
var format = options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss";
|
|
93
|
-
return (
|
|
128
|
+
return dayjs().utc(value).format(format);
|
|
94
129
|
}
|
|
95
130
|
});
|
|
96
|
-
const ip = require('ip');
|
|
97
|
-
const bodyParser = require('body-parser');
|
|
98
|
-
const methodOverride = require('method-override');
|
|
99
|
-
const Server = express();
|
|
100
|
-
const cors = require('cors');
|
|
101
|
-
const emitter = require('events').EventEmitter;
|
|
102
|
-
const em = new emitter();
|
|
103
|
-
/**
|
|
104
|
-
* set request id
|
|
105
|
-
*/
|
|
106
|
-
Object.defineProperty(Server.request, 'reqId', {
|
|
107
|
-
configurable: true,
|
|
108
|
-
enumerable: true,
|
|
109
|
-
writable: true
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(Server.request, 'user', {
|
|
112
|
-
configurable: true,
|
|
113
|
-
enumerable: true,
|
|
114
|
-
writable: true
|
|
115
|
-
});
|
|
116
|
-
Object.defineProperty(Server.request, 'identity', {
|
|
117
|
-
configurable: true,
|
|
118
|
-
enumerable: true,
|
|
119
|
-
writable: true
|
|
120
|
-
});
|
|
121
131
|
class BaseChyz {
|
|
122
132
|
constructor() {
|
|
123
133
|
this._port = 3001;
|
|
@@ -186,6 +196,7 @@ class BaseChyz {
|
|
|
186
196
|
}
|
|
187
197
|
app(config = {}) {
|
|
188
198
|
var _a;
|
|
199
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_INIT_BEFORE, this, config);
|
|
189
200
|
/**
|
|
190
201
|
* Config set
|
|
191
202
|
*/
|
|
@@ -220,6 +231,7 @@ class BaseChyz {
|
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
233
|
this.init();
|
|
234
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_INIT_AFTER, this, config);
|
|
223
235
|
return this;
|
|
224
236
|
}
|
|
225
237
|
static trace(...args) {
|
|
@@ -333,7 +345,7 @@ class BaseChyz {
|
|
|
333
345
|
let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
|
|
334
346
|
route.id = actionId;
|
|
335
347
|
BaseChyz.debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`));
|
|
336
|
-
BaseChyz.
|
|
348
|
+
BaseChyz.propvider[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`), (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
337
349
|
try {
|
|
338
350
|
BaseChyz.debug(`Call Request id ${instance.id}`);
|
|
339
351
|
yield instance.beforeAction(route, req, res);
|
|
@@ -372,10 +384,10 @@ class BaseChyz {
|
|
|
372
384
|
});
|
|
373
385
|
}
|
|
374
386
|
middleware() {
|
|
375
|
-
BaseChyz.
|
|
376
|
-
BaseChyz.
|
|
377
|
-
BaseChyz.
|
|
378
|
-
BaseChyz.
|
|
387
|
+
BaseChyz.propvider.use(bodyParser.json({ limit: '1mb' }));
|
|
388
|
+
BaseChyz.propvider.use(bodyParser.urlencoded({ limit: '1mb', extended: true })); // support encoded bodies
|
|
389
|
+
BaseChyz.propvider.use(methodOverride());
|
|
390
|
+
BaseChyz.propvider.use(cors());
|
|
379
391
|
//
|
|
380
392
|
// // CORS
|
|
381
393
|
// BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
@@ -398,54 +410,56 @@ class BaseChyz {
|
|
|
398
410
|
// use compression filter function
|
|
399
411
|
return compression.filter(req, res);
|
|
400
412
|
};
|
|
401
|
-
BaseChyz.
|
|
413
|
+
BaseChyz.propvider.use(compression({ filter: shouldCompress }));
|
|
402
414
|
//
|
|
403
415
|
// //static file path
|
|
404
416
|
if (this.config.staticFilePath) {
|
|
405
417
|
BaseChyz.info('Static file path', this.config.staticFilePath);
|
|
406
|
-
BaseChyz.
|
|
418
|
+
BaseChyz.propvider.use(express_1.default.static(this.config.staticFilePath));
|
|
407
419
|
}
|
|
408
420
|
//Middlewares
|
|
409
421
|
for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
|
|
410
422
|
if (!Utils_1.Utils.isFunction(middleware1)) {
|
|
411
423
|
let keycloak = BaseChyz.middlewares[middleware1].keycloak;
|
|
412
|
-
BaseChyz.
|
|
424
|
+
BaseChyz.propvider.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
|
|
413
425
|
}
|
|
414
426
|
else {
|
|
415
|
-
BaseChyz.
|
|
427
|
+
BaseChyz.propvider.use(BaseChyz.middlewares[middleware1]);
|
|
416
428
|
}
|
|
417
429
|
}
|
|
418
|
-
BaseChyz.
|
|
419
|
-
BaseChyz.
|
|
430
|
+
BaseChyz.propvider.use(this.errorResponder);
|
|
431
|
+
BaseChyz.propvider.use(this.errorHandler);
|
|
432
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_MIDDLEWARE, this);
|
|
420
433
|
}
|
|
421
434
|
Start() {
|
|
422
435
|
var _a, _b;
|
|
423
436
|
BaseChyz.info("Express Server Starting");
|
|
424
|
-
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_BEFORE_START);
|
|
437
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_BEFORE_START, this);
|
|
425
438
|
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.ssl) {
|
|
426
|
-
BaseChyz.httpServer =
|
|
439
|
+
BaseChyz.httpServer = (0, https_1.createServer)((_b = this.config) === null || _b === void 0 ? void 0 : _b.ssl, BaseChyz.propvider);
|
|
427
440
|
BaseChyz.httpServer.listen(this._port, () => {
|
|
428
441
|
BaseChyz.info("Express Server Start ");
|
|
429
442
|
BaseChyz.info(`Liten Port ${this._port}`);
|
|
430
443
|
BaseChyz.info(`https://localhost:${this._port}`);
|
|
431
444
|
BaseChyz.info(`https://${ip.address()}:${this._port}`);
|
|
432
|
-
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_START);
|
|
445
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_START, this);
|
|
433
446
|
});
|
|
434
447
|
}
|
|
435
448
|
else {
|
|
436
|
-
BaseChyz.httpServer =
|
|
449
|
+
BaseChyz.httpServer = (0, http_1.createServer)(BaseChyz.propvider);
|
|
450
|
+
BaseChyz.propvider.listen(this._port, () => {
|
|
437
451
|
BaseChyz.info("Express Server Start ");
|
|
438
452
|
BaseChyz.info(`Liten Port ${this._port}`);
|
|
439
453
|
BaseChyz.info(`http://localhost:${this._port}`);
|
|
440
454
|
BaseChyz.info(`http://${ip.address()}:${this._port}`);
|
|
441
|
-
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_START);
|
|
455
|
+
BaseChyz.EventEmitter.emit(CEvents_1.CEvents.ON_START, this);
|
|
442
456
|
});
|
|
443
457
|
}
|
|
444
458
|
return this;
|
|
445
459
|
}
|
|
446
460
|
}
|
|
447
461
|
exports.default = BaseChyz;
|
|
448
|
-
BaseChyz.
|
|
462
|
+
BaseChyz.propvider = Server;
|
|
449
463
|
BaseChyz.logs = new Logs_1.Logs();
|
|
450
464
|
BaseChyz._validate = validate;
|
|
451
465
|
BaseChyz.controllers = [];
|
package/base/CEvents.d.ts
CHANGED
package/base/CEvents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CEvents.d.ts","sourceRoot":"","sources":["../../src/base/CEvents.ts"],"names":[],"mappings":"AAQA,oBAAY,OAAO;IACf,eAAe,kBAAkB;IACjC,cAAc,kBAAkB;IAChC,QAAQ,YAAY;IAEpB,gBAAgB,mBAAmB;IACnC,eAAe,kBAAkB;IAEjC,gBAAgB,mBAAiB;IACjC,gBAAgB,mBAAiB;CAGpC"}
|
|
1
|
+
{"version":3,"file":"CEvents.d.ts","sourceRoot":"","sources":["../../src/base/CEvents.ts"],"names":[],"mappings":"AAQA,oBAAY,OAAO;IACf,cAAc,iBAAe;IAC7B,aAAa,gBAAc;IAC3B,aAAa,iBAAe;IAC5B,eAAe,kBAAkB;IACjC,cAAc,kBAAkB;IAChC,QAAQ,YAAY;IAEpB,gBAAgB,mBAAmB;IACnC,eAAe,kBAAkB;IAEjC,gBAAgB,mBAAiB;IACjC,gBAAgB,mBAAiB;CAGpC"}
|
package/base/CEvents.js
CHANGED
|
@@ -11,6 +11,9 @@ exports.CEvents = void 0;
|
|
|
11
11
|
*/
|
|
12
12
|
var CEvents;
|
|
13
13
|
(function (CEvents) {
|
|
14
|
+
CEvents["ON_INIT_BEFORE"] = "oninitbefore";
|
|
15
|
+
CEvents["ON_INIT_AFTER"] = "oninitafter";
|
|
16
|
+
CEvents["ON_MIDDLEWARE"] = "onmiddleware";
|
|
14
17
|
CEvents["ON_BEFORE_START"] = "onbeforestart";
|
|
15
18
|
CEvents["ON_AFTER_START"] = "onafterestart";
|
|
16
19
|
CEvents["ON_START"] = "onstart";
|