taon 19.0.48 → 19.0.50
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/browser/fesm2022/taon.mjs +304 -198
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/constants.d.ts +2 -1
- package/browser/lib/endpoint-context.d.ts +28 -1
- package/browser/lib/helpers/class-helpers.d.ts +0 -1
- package/browser/lib/models.d.ts +19 -0
- package/browser/lib/realtime/realtime-core.d.ts +2 -2
- package/browser/lib/realtime/realtime-server.d.ts +2 -2
- package/browser/package.json +1 -1
- package/lib/base-classes/base-subscriber.d.ts +4 -0
- package/lib/base-classes/base-subscriber.js +25 -0
- package/lib/base-classes/base-subscriber.js.map +1 -0
- package/lib/build-info._auto-generated_.d.ts +17 -1
- package/lib/build-info._auto-generated_.js +18 -2
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/constants.js.map +1 -1
- package/lib/create-context.js +15 -0
- package/lib/create-context.js.map +1 -1
- package/lib/endpoint-context.d.ts +28 -1
- package/lib/endpoint-context.js +132 -56
- package/lib/endpoint-context.js.map +1 -1
- package/lib/env.js +5 -1
- package/lib/env.js.map +1 -1
- package/lib/helpers/class-helpers.d.ts +0 -1
- package/lib/helpers/class-helpers.js +13 -14
- package/lib/helpers/class-helpers.js.map +1 -1
- package/lib/models.d.ts +19 -0
- package/lib/models.js +3 -0
- package/lib/models.js.map +1 -1
- package/lib/realtime/realtime-client.js +9 -0
- package/lib/realtime/realtime-client.js.map +1 -1
- package/lib/realtime/realtime-core.d.ts +2 -2
- package/lib/realtime/realtime-core.js +6 -5
- package/lib/realtime/realtime-core.js.map +1 -1
- package/lib/realtime/realtime-server.d.ts +2 -2
- package/lib/realtime/realtime-server.js +20 -23
- package/lib/realtime/realtime-server.js.map +1 -1
- package/lib/realtime/realtime-strategy/realtime-abstract-mock.d.ts +10 -0
- package/lib/realtime/realtime-strategy/realtime-abstract-mock.js +214 -0
- package/lib/realtime/realtime-strategy/realtime-abstract-mock.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/index.d.ts +0 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/index.js +5 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/index.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-namespace.d.ts +22 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-namespace.js +139 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-namespace.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-wrapper.d.ts +16 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-wrapper.js +68 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-main-wrapper.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-namespace.d.ts +10 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-namespace.js +56 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-namespace.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-wrapper.d.ts +10 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-wrapper.js +50 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc-renderer-wrapper.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc.models.d.ts +13 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc.models.js +3 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc-models/realtime-strategy-ipc.models.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/index.d.ts +2 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/index.js +6 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/index.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-client.d.ts +16 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-client.js +54 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-client.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-namespaces.d.ts +17 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-namespaces.js +52 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-namespaces.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-server.d.ts +11 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-server.js +39 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-server.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-socket.d.ts +13 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-socket.js +46 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock-socket.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock.models.d.ts +11 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock.models.js +3 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock-models/realtime-strategy-mock.models.js.map +1 -0
- package/lib/realtime/realtime-strategy/realtime-strategy-mock.js +2 -2
- package/lib/realtime/realtime-strategy/realtime-strategy-mock.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.js +5 -1
- package/lib/storage.js.map +1 -1
- package/lib/ui/directives/firedev-inject-html.directive.d.ts +6 -0
- package/lib/ui/directives/firedev-long-press.directive.d.ts +22 -0
- package/lib/ui/directives/index.d.ts +3 -0
- package/lib/ui/directives/index.js +5 -0
- package/lib/ui/directives/index.js.map +1 -0
- package/lib/ui/directives/safe.pipe.d.ts +7 -0
- package/lib/ui/directives/taon-inject-html.directive.d.ts +6 -0
- package/lib/ui/directives/taon-long-press.directive.d.ts +22 -0
- package/lib/ui/directives/view-mode.d.ts +5 -0
- package/lib/ui/directives/view-mode.js +10 -0
- package/lib/ui/directives/view-mode.js.map +1 -0
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/taon-admin-edit-mode.component.d.ts +29 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/taon-admin-edit-mode.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.d.ts +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/taon-db-admin.component.d.ts +8 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/taon-file-general-opt.component.d.ts +13 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/taon-file-general-opt.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.d.ts +5 -0
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.js +3 -0
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin-control.service.d.ts +14 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +43 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +5 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +3 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +1 -0
- package/lib/ui/taon-full-material.module.d.ts +5 -0
- package/lib/ui/taon-github-fork-me-corner/index.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-corner/index.js +5 -0
- package/lib/ui/taon-github-fork-me-corner/index.js.map +1 -0
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +3 -0
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.js +5 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.js.map +1 -0
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +3 -0
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +2 -0
- package/lib/ui/taon-notifications/index.d.ts +4 -0
- package/lib/ui/taon-notifications/index.js +24 -0
- package/lib/ui/taon-notifications/index.js.map +1 -0
- package/lib/ui/taon-notifications/taon-notifications.component.d.ts +9 -0
- package/lib/ui/taon-notifications/taon-notifications.models.d.ts +6 -0
- package/lib/ui/taon-notifications/taon-notifications.models.js +5 -0
- package/lib/ui/taon-notifications/taon-notifications.models.js.map +1 -0
- package/lib/ui/taon-notifications/taon-notifications.module.d.ts +2 -0
- package/lib/ui/taon-notifications/taon-notifications.service.d.ts +11 -0
- package/lib/ui/taon-progress-bar/index.d.ts +2 -0
- package/lib/ui/taon-progress-bar/index.js +5 -0
- package/lib/ui/taon-progress-bar/index.js.map +1 -0
- package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +13 -0
- package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +2 -0
- package/lib/ui/taon-session-passcode/index.d.ts +1 -0
- package/lib/ui/taon-session-passcode/index.js +5 -0
- package/lib/ui/taon-session-passcode/index.js.map +1 -0
- package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +35 -0
- package/lib/ui/taon-table/index.d.ts +2 -0
- package/lib/ui/taon-table/index.js +5 -0
- package/lib/ui/taon-table/index.js.map +1 -0
- package/lib/ui/taon-table/taon-table.component.d.ts +34 -0
- package/lib/ui/taon-table/taon-table.module.d.ts +2 -0
- package/lib/ui/taon.models.d.ts +11 -0
- package/lib/ui/taon.models.js +3 -0
- package/lib/ui/taon.models.js.map +1 -0
- package/lib/ui/toan-full-material.module.d.ts +2 -0
- package/package.json +1 -1
- package/tmp-environment.json +43 -0
- package/websql/fesm2022/taon.mjs +335 -230
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/constants.d.ts +2 -1
- package/websql/lib/endpoint-context.d.ts +28 -1
- package/websql/lib/helpers/class-helpers.d.ts +0 -1
- package/websql/lib/models.d.ts +19 -0
- package/websql/lib/realtime/realtime-core.d.ts +2 -2
- package/websql/lib/realtime/realtime-server.d.ts +2 -2
- package/websql/package.json +1 -1
package/websql/fesm2022/taon.mjs
CHANGED
|
@@ -7,12 +7,12 @@ import { OrignalClassKey, Entity, Table, TableIndex, EventSubscriber, DataSource
|
|
|
7
7
|
import { walk } from 'lodash-walk-object/websql';
|
|
8
8
|
import { SYMBOL, CLASS } from 'typescript-class-helpers/websql';
|
|
9
9
|
import { Models as Models$1, RestHeaders, Resource, Mapping } from 'ng2-rest/websql';
|
|
10
|
-
import * as JSON5 from 'json5';
|
|
11
10
|
import * as i0 from '@angular/core';
|
|
12
11
|
import { InjectionToken, inject as inject$1, Injectable } from '@angular/core';
|
|
13
12
|
import axios from 'axios';
|
|
14
13
|
import { JSON10 } from 'json10/websql';
|
|
15
14
|
import { Observable, Subject, from } from 'rxjs';
|
|
15
|
+
import * as JSON5 from 'json5';
|
|
16
16
|
import { io } from 'socket.io-client';
|
|
17
17
|
import { MySqlQuerySource } from 'taon-type-sql/websql';
|
|
18
18
|
|
|
@@ -424,146 +424,6 @@ var Models;
|
|
|
424
424
|
//#endregion
|
|
425
425
|
})(Models || (Models = {}));
|
|
426
426
|
|
|
427
|
-
var TaonHelpers;
|
|
428
|
-
(function (TaonHelpers) {
|
|
429
|
-
//#region fillUpTo string
|
|
430
|
-
TaonHelpers.fillUpTo = (s, nCharacters) => {
|
|
431
|
-
return _.times(nCharacters, n => {
|
|
432
|
-
if (s.charAt(n)) {
|
|
433
|
-
return s.charAt(n);
|
|
434
|
-
}
|
|
435
|
-
return ' ';
|
|
436
|
-
}).join('');
|
|
437
|
-
};
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region is good path
|
|
440
|
-
TaonHelpers.isGoodPath = (p) => {
|
|
441
|
-
return p && typeof p === 'string' && p.trim() !== '';
|
|
442
|
-
};
|
|
443
|
-
//#endregion
|
|
444
|
-
//#region try transform params
|
|
445
|
-
TaonHelpers.tryTransformParam = param => {
|
|
446
|
-
if (typeof param === 'string') {
|
|
447
|
-
let n = Number(param);
|
|
448
|
-
if (!isNaN(n))
|
|
449
|
-
return n;
|
|
450
|
-
const bool = param.trim().toLowerCase();
|
|
451
|
-
if (bool === 'true') {
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
if (bool === 'false') {
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
try {
|
|
458
|
-
const t = JSON5.parse(param);
|
|
459
|
-
return t;
|
|
460
|
-
}
|
|
461
|
-
catch (e) {
|
|
462
|
-
return param;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return param;
|
|
466
|
-
};
|
|
467
|
-
//#endregion
|
|
468
|
-
//#region get expores path
|
|
469
|
-
TaonHelpers.getExpressPath = (c, pathOrClassConfig) => {
|
|
470
|
-
if (typeof pathOrClassConfig === 'string')
|
|
471
|
-
return `${c.calculatedPath}${pathOrClassConfig}`.replace(/\/$/, '');
|
|
472
|
-
return `${c.calculatedPath}${pathOrClassConfig.path}`.replace(/\/$/, '');
|
|
473
|
-
};
|
|
474
|
-
//#endregion
|
|
475
|
-
//#region get default value tyep
|
|
476
|
-
TaonHelpers.defaultType = value => {
|
|
477
|
-
if (typeof value === 'string')
|
|
478
|
-
return '';
|
|
479
|
-
if (typeof value === 'boolean')
|
|
480
|
-
return false;
|
|
481
|
-
if (Array.isArray(value))
|
|
482
|
-
return {};
|
|
483
|
-
if (typeof value === 'object')
|
|
484
|
-
return {};
|
|
485
|
-
};
|
|
486
|
-
//#endregion
|
|
487
|
-
//#region parse json with string jsons
|
|
488
|
-
TaonHelpers.parseJSONwithStringJSONs = (object, waring = false) => {
|
|
489
|
-
// console.log('checking object', object)
|
|
490
|
-
if (!_.isObject(object)) {
|
|
491
|
-
if (waring) {
|
|
492
|
-
console.error(`
|
|
493
|
-
parseJSONwithStringJSONs(...)
|
|
494
|
-
Parameter should be a object, but is ${typeof object}
|
|
495
|
-
`, object);
|
|
496
|
-
}
|
|
497
|
-
return object;
|
|
498
|
-
}
|
|
499
|
-
let res = _.cloneDeep(object);
|
|
500
|
-
Object.keys(res).forEach(key => {
|
|
501
|
-
let isJson = false;
|
|
502
|
-
try {
|
|
503
|
-
const possibleJSON = JSON.parse(res[key]);
|
|
504
|
-
res[key] = possibleJSON;
|
|
505
|
-
isJson = true;
|
|
506
|
-
}
|
|
507
|
-
catch (e) {
|
|
508
|
-
isJson = false;
|
|
509
|
-
}
|
|
510
|
-
// console.log(`key ${key} is json `, isJson)
|
|
511
|
-
if (isJson) {
|
|
512
|
-
res[key] = TaonHelpers.parseJSONwithStringJSONs(res[key], false);
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
return res;
|
|
516
|
-
};
|
|
517
|
-
//#endregion
|
|
518
|
-
//#region is plain file or folder
|
|
519
|
-
TaonHelpers.isPlainFileOrFolder = filePath => {
|
|
520
|
-
return /^([a-zA-Z]|\-|\_|\@|\#|\$|\!|\^|\&|\*|\(|\))+$/.test(filePath);
|
|
521
|
-
};
|
|
522
|
-
//#endregion
|
|
523
|
-
//#region ips key name repsonse
|
|
524
|
-
TaonHelpers.ipcKeyNameResponse = (target, methodConfig, expressPath) => {
|
|
525
|
-
return [
|
|
526
|
-
'response',
|
|
527
|
-
ClassHelpers.getName(target),
|
|
528
|
-
methodConfig.methodName,
|
|
529
|
-
methodConfig.type,
|
|
530
|
-
expressPath,
|
|
531
|
-
].join('--');
|
|
532
|
-
};
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region ipc key name request
|
|
535
|
-
TaonHelpers.ipcKeyNameRequest = (target, methodConfig, expressPath) => {
|
|
536
|
-
return [
|
|
537
|
-
'request',
|
|
538
|
-
ClassHelpers.getName(target),
|
|
539
|
-
methodConfig.methodName,
|
|
540
|
-
methodConfig.type,
|
|
541
|
-
expressPath,
|
|
542
|
-
].join('--');
|
|
543
|
-
};
|
|
544
|
-
//#endregion
|
|
545
|
-
//#region websql mocks
|
|
546
|
-
TaonHelpers.websqlMocks = headers => {
|
|
547
|
-
const response = {
|
|
548
|
-
status(status) {
|
|
549
|
-
// console.log({status})
|
|
550
|
-
return {
|
|
551
|
-
send(send) {
|
|
552
|
-
// console.log({status})
|
|
553
|
-
},
|
|
554
|
-
};
|
|
555
|
-
},
|
|
556
|
-
setHeader(key, value) {
|
|
557
|
-
// console.log('Dummy set header', arguments)
|
|
558
|
-
headers[key] = value;
|
|
559
|
-
},
|
|
560
|
-
};
|
|
561
|
-
const request = {};
|
|
562
|
-
return { request, response };
|
|
563
|
-
};
|
|
564
|
-
//#endregion
|
|
565
|
-
})(TaonHelpers || (TaonHelpers = {}));
|
|
566
|
-
|
|
567
427
|
/* */
|
|
568
428
|
/* */
|
|
569
429
|
var ClassHelpers;
|
|
@@ -754,19 +614,19 @@ var ClassHelpers;
|
|
|
754
614
|
};
|
|
755
615
|
//#endregion
|
|
756
616
|
//#region get path for
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
};
|
|
617
|
+
// export const getCalculatedPathFor = (target: Function) => {
|
|
618
|
+
// const configs = getControllerConfigs(target);
|
|
619
|
+
// const parentscalculatedPath = _.slice(configs, 1)
|
|
620
|
+
// .reverse()
|
|
621
|
+
// .map(bc => {
|
|
622
|
+
// if (TaonHelpers.isGoodPath(bc.path)) {
|
|
623
|
+
// return bc.path;
|
|
624
|
+
// }
|
|
625
|
+
// return bc.className;
|
|
626
|
+
// })
|
|
627
|
+
// .join('/');
|
|
628
|
+
// return `/${parentscalculatedPath}/${ClassHelpers.getName(target)}`;
|
|
629
|
+
// };
|
|
770
630
|
//#endregion
|
|
771
631
|
})(ClassHelpers || (ClassHelpers = {}));
|
|
772
632
|
|
|
@@ -874,6 +734,7 @@ TAON_CONTEXT = new InjectionToken('TAON_CONTEXT');
|
|
|
874
734
|
let CURRENT_HOST_BACKEND_PORT;
|
|
875
735
|
//#region @browser
|
|
876
736
|
CURRENT_HOST_BACKEND_PORT = new InjectionToken('CURRENT_HOST_BACKEND_PORT');
|
|
737
|
+
const apiPrefix = 'api';
|
|
877
738
|
|
|
878
739
|
const inject = (entity) => {
|
|
879
740
|
return new Proxy({}, {
|
|
@@ -1399,6 +1260,146 @@ const getResponseValue = (response, options) => {
|
|
|
1399
1260
|
//#endregion
|
|
1400
1261
|
};
|
|
1401
1262
|
|
|
1263
|
+
var TaonHelpers;
|
|
1264
|
+
(function (TaonHelpers) {
|
|
1265
|
+
//#region fillUpTo string
|
|
1266
|
+
TaonHelpers.fillUpTo = (s, nCharacters) => {
|
|
1267
|
+
return _.times(nCharacters, n => {
|
|
1268
|
+
if (s.charAt(n)) {
|
|
1269
|
+
return s.charAt(n);
|
|
1270
|
+
}
|
|
1271
|
+
return ' ';
|
|
1272
|
+
}).join('');
|
|
1273
|
+
};
|
|
1274
|
+
//#endregion
|
|
1275
|
+
//#region is good path
|
|
1276
|
+
TaonHelpers.isGoodPath = (p) => {
|
|
1277
|
+
return p && typeof p === 'string' && p.trim() !== '';
|
|
1278
|
+
};
|
|
1279
|
+
//#endregion
|
|
1280
|
+
//#region try transform params
|
|
1281
|
+
TaonHelpers.tryTransformParam = param => {
|
|
1282
|
+
if (typeof param === 'string') {
|
|
1283
|
+
let n = Number(param);
|
|
1284
|
+
if (!isNaN(n))
|
|
1285
|
+
return n;
|
|
1286
|
+
const bool = param.trim().toLowerCase();
|
|
1287
|
+
if (bool === 'true') {
|
|
1288
|
+
return true;
|
|
1289
|
+
}
|
|
1290
|
+
if (bool === 'false') {
|
|
1291
|
+
return false;
|
|
1292
|
+
}
|
|
1293
|
+
try {
|
|
1294
|
+
const t = JSON5.parse(param);
|
|
1295
|
+
return t;
|
|
1296
|
+
}
|
|
1297
|
+
catch (e) {
|
|
1298
|
+
return param;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return param;
|
|
1302
|
+
};
|
|
1303
|
+
//#endregion
|
|
1304
|
+
//#region get expores path
|
|
1305
|
+
TaonHelpers.getExpressPath = (c, pathOrClassConfig) => {
|
|
1306
|
+
if (typeof pathOrClassConfig === 'string')
|
|
1307
|
+
return `${c.calculatedPath}${pathOrClassConfig}`.replace(/\/$/, '');
|
|
1308
|
+
return `${c.calculatedPath}${pathOrClassConfig.path}`.replace(/\/$/, '');
|
|
1309
|
+
};
|
|
1310
|
+
//#endregion
|
|
1311
|
+
//#region get default value tyep
|
|
1312
|
+
TaonHelpers.defaultType = value => {
|
|
1313
|
+
if (typeof value === 'string')
|
|
1314
|
+
return '';
|
|
1315
|
+
if (typeof value === 'boolean')
|
|
1316
|
+
return false;
|
|
1317
|
+
if (Array.isArray(value))
|
|
1318
|
+
return {};
|
|
1319
|
+
if (typeof value === 'object')
|
|
1320
|
+
return {};
|
|
1321
|
+
};
|
|
1322
|
+
//#endregion
|
|
1323
|
+
//#region parse json with string jsons
|
|
1324
|
+
TaonHelpers.parseJSONwithStringJSONs = (object, waring = false) => {
|
|
1325
|
+
// console.log('checking object', object)
|
|
1326
|
+
if (!_.isObject(object)) {
|
|
1327
|
+
if (waring) {
|
|
1328
|
+
console.error(`
|
|
1329
|
+
parseJSONwithStringJSONs(...)
|
|
1330
|
+
Parameter should be a object, but is ${typeof object}
|
|
1331
|
+
`, object);
|
|
1332
|
+
}
|
|
1333
|
+
return object;
|
|
1334
|
+
}
|
|
1335
|
+
let res = _.cloneDeep(object);
|
|
1336
|
+
Object.keys(res).forEach(key => {
|
|
1337
|
+
let isJson = false;
|
|
1338
|
+
try {
|
|
1339
|
+
const possibleJSON = JSON.parse(res[key]);
|
|
1340
|
+
res[key] = possibleJSON;
|
|
1341
|
+
isJson = true;
|
|
1342
|
+
}
|
|
1343
|
+
catch (e) {
|
|
1344
|
+
isJson = false;
|
|
1345
|
+
}
|
|
1346
|
+
// console.log(`key ${key} is json `, isJson)
|
|
1347
|
+
if (isJson) {
|
|
1348
|
+
res[key] = TaonHelpers.parseJSONwithStringJSONs(res[key], false);
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
return res;
|
|
1352
|
+
};
|
|
1353
|
+
//#endregion
|
|
1354
|
+
//#region is plain file or folder
|
|
1355
|
+
TaonHelpers.isPlainFileOrFolder = filePath => {
|
|
1356
|
+
return /^([a-zA-Z]|\-|\_|\@|\#|\$|\!|\^|\&|\*|\(|\))+$/.test(filePath);
|
|
1357
|
+
};
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region ips key name repsonse
|
|
1360
|
+
TaonHelpers.ipcKeyNameResponse = (target, methodConfig, expressPath) => {
|
|
1361
|
+
return [
|
|
1362
|
+
'response',
|
|
1363
|
+
ClassHelpers.getName(target),
|
|
1364
|
+
methodConfig.methodName,
|
|
1365
|
+
methodConfig.type,
|
|
1366
|
+
expressPath,
|
|
1367
|
+
].join('--');
|
|
1368
|
+
};
|
|
1369
|
+
//#endregion
|
|
1370
|
+
//#region ipc key name request
|
|
1371
|
+
TaonHelpers.ipcKeyNameRequest = (target, methodConfig, expressPath) => {
|
|
1372
|
+
return [
|
|
1373
|
+
'request',
|
|
1374
|
+
ClassHelpers.getName(target),
|
|
1375
|
+
methodConfig.methodName,
|
|
1376
|
+
methodConfig.type,
|
|
1377
|
+
expressPath,
|
|
1378
|
+
].join('--');
|
|
1379
|
+
};
|
|
1380
|
+
//#endregion
|
|
1381
|
+
//#region websql mocks
|
|
1382
|
+
TaonHelpers.websqlMocks = headers => {
|
|
1383
|
+
const response = {
|
|
1384
|
+
status(status) {
|
|
1385
|
+
// console.log({status})
|
|
1386
|
+
return {
|
|
1387
|
+
send(send) {
|
|
1388
|
+
// console.log({status})
|
|
1389
|
+
},
|
|
1390
|
+
};
|
|
1391
|
+
},
|
|
1392
|
+
setHeader(key, value) {
|
|
1393
|
+
// console.log('Dummy set header', arguments)
|
|
1394
|
+
headers[key] = value;
|
|
1395
|
+
},
|
|
1396
|
+
};
|
|
1397
|
+
const request = {};
|
|
1398
|
+
return { request, response };
|
|
1399
|
+
};
|
|
1400
|
+
//#endregion
|
|
1401
|
+
})(TaonHelpers || (TaonHelpers = {}));
|
|
1402
|
+
|
|
1402
1403
|
//#region imports
|
|
1403
1404
|
/* */
|
|
1404
1405
|
/* */
|
|
@@ -1518,6 +1519,15 @@ class RealtimeClient {
|
|
|
1518
1519
|
realtime: this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
1519
1520
|
};
|
|
1520
1521
|
// console.log('[browser] nspPath', nspPath);
|
|
1522
|
+
if (this.core.ctx.config.frontendHost &&
|
|
1523
|
+
this.core.ctx.config.frontendHost !== '') {
|
|
1524
|
+
console.log(`[${this.core.ctx.contextName}] USING FRONTEND HOST ${this.core.ctx.config.frontendHost}`);
|
|
1525
|
+
nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
|
|
1526
|
+
nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
|
|
1527
|
+
}
|
|
1528
|
+
else {
|
|
1529
|
+
console.log(`[${this.core.ctx.contextName}] NOT USING FRONTEND HOST`);
|
|
1530
|
+
}
|
|
1521
1531
|
this.core.ctx.logRealtime &&
|
|
1522
1532
|
console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
|
|
1523
1533
|
this.core.ctx.logRealtime &&
|
|
@@ -1667,6 +1677,7 @@ to use socket realtime connection;
|
|
|
1667
1677
|
}
|
|
1668
1678
|
|
|
1669
1679
|
//#region imports
|
|
1680
|
+
/* */
|
|
1670
1681
|
//#endregion
|
|
1671
1682
|
class RealtimeServer {
|
|
1672
1683
|
// private jobs = {};
|
|
@@ -1693,45 +1704,43 @@ class RealtimeServer {
|
|
|
1693
1704
|
`);
|
|
1694
1705
|
}
|
|
1695
1706
|
//#region prepare namespaces pathes
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
realtime: this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
1699
|
-
};
|
|
1707
|
+
const nspPathGlobal = this.core.pathFor();
|
|
1708
|
+
const nspPathRealtime = this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName));
|
|
1700
1709
|
//#endregion
|
|
1701
1710
|
// console.log('[backend] nspPath', nspPath);
|
|
1711
|
+
const cors = {
|
|
1712
|
+
origin: this.core.ctx.frontendHostUri.origin, // only origin needs to be set - pathname not needed
|
|
1713
|
+
methods: this.core.allHttpMethods,
|
|
1714
|
+
};
|
|
1715
|
+
// console.log('frontendHost', this.core.ctx.config.frontendHost);
|
|
1716
|
+
// console.log('cors', cors);
|
|
1702
1717
|
//#region prepare global BE socket
|
|
1703
|
-
this.core.connectSocketBE = this.core.strategy.ioServer(Helpers.isWebSQL ? this.core.ctx.
|
|
1704
|
-
path:
|
|
1705
|
-
cors
|
|
1706
|
-
origin: this.core.ctx.config.frontendHost,
|
|
1707
|
-
methods: this.core.allHttpMethods,
|
|
1708
|
-
},
|
|
1718
|
+
this.core.connectSocketBE = this.core.strategy.ioServer(Helpers.isWebSQL ? this.core.ctx.uriOrigin : this.core.ctx.serverTcpUdp, {
|
|
1719
|
+
path: nspPathGlobal.pathname,
|
|
1720
|
+
cors,
|
|
1709
1721
|
}, // @ts-ignore
|
|
1710
1722
|
this.core.ctx);
|
|
1711
1723
|
this.core.ctx.logRealtime &&
|
|
1712
1724
|
console.info(`[backend] CREATE GLOBAL NAMESPACE: '${this.core.connectSocketBE.path()}'` +
|
|
1713
|
-
` , path: '${
|
|
1725
|
+
` , path: '${nspPathGlobal.pathname}'`);
|
|
1714
1726
|
this.core.connectSocketBE.on('connection', clientSocket => {
|
|
1715
|
-
console.info(`[backend] client connected to namespace "${
|
|
1727
|
+
console.info(`[backend] client connected to namespace "${nspPathGlobal.pathname}", ` +
|
|
1716
1728
|
` host: ${this.core.ctx.host}`);
|
|
1717
1729
|
});
|
|
1718
1730
|
//#endregion
|
|
1719
1731
|
//#region prepare realtime BE socket
|
|
1720
1732
|
this.core.socketBE = this.core.strategy.ioServer(Helpers.isWebSQL || Helpers.isElectron
|
|
1721
|
-
? this.core.ctx.
|
|
1733
|
+
? this.core.ctx.uriOrigin
|
|
1722
1734
|
: this.core.ctx.serverTcpUdp, {
|
|
1723
|
-
path:
|
|
1724
|
-
cors
|
|
1725
|
-
origin: this.core.ctx.config.frontendHost,
|
|
1726
|
-
methods: this.core.allHttpMethods,
|
|
1727
|
-
},
|
|
1735
|
+
path: nspPathRealtime.pathname,
|
|
1736
|
+
cors,
|
|
1728
1737
|
}, // @ts-ignore
|
|
1729
1738
|
this.core.ctx);
|
|
1730
1739
|
this.core.ctx.logRealtime &&
|
|
1731
1740
|
console.info(`[backend] CREATE REALTIME NAMESPACE: '${this.core.socketBE.path()}'` +
|
|
1732
|
-
` , path: '${
|
|
1741
|
+
` , path: '${nspPathRealtime.pathname}' `);
|
|
1733
1742
|
this.core.socketBE.on('connection', backendSocketForClient => {
|
|
1734
|
-
console.info(`[backend] client connected to namespace "${
|
|
1743
|
+
console.info(`[backend] client connected to namespace "${nspPathRealtime.pathname}", ` +
|
|
1735
1744
|
` host: ${this.core.ctx.host}`);
|
|
1736
1745
|
backendSocketForClient.on(Symbols.REALTIME.ROOM_SUBSCRIBE_CUSTOM(this.core.ctx.contextName), roomName => {
|
|
1737
1746
|
this.core.ctx.logRealtime &&
|
|
@@ -2440,12 +2449,12 @@ class RealtimeStrategyMock extends RealtimeStrategy {
|
|
|
2440
2449
|
//#endregion
|
|
2441
2450
|
//#region server & io
|
|
2442
2451
|
ioServer(url, opt) {
|
|
2443
|
-
const server = MockServer.from(url || this.ctx.
|
|
2452
|
+
const server = MockServer.from(url || this.ctx.uriOrigin);
|
|
2444
2453
|
return server.of(opt?.path || '/');
|
|
2445
2454
|
}
|
|
2446
2455
|
get ioClient() {
|
|
2447
2456
|
const clientIo = (uri, opts) => {
|
|
2448
|
-
return new MockSocket(uri || this.ctx.
|
|
2457
|
+
return new MockSocket(uri || this.ctx.uriOrigin, opts);
|
|
2449
2458
|
};
|
|
2450
2459
|
return clientIo;
|
|
2451
2460
|
}
|
|
@@ -2515,6 +2524,7 @@ class RealtimeCore {
|
|
|
2515
2524
|
//#endregion
|
|
2516
2525
|
//#region methods & getters / resovle staraegy
|
|
2517
2526
|
resolveStrategy() {
|
|
2527
|
+
// console.log(`[taon] resolveStrategy for this.ctx.mode ${this.ctx.mode}`);
|
|
2518
2528
|
if (this.ctx.mode === 'backend-frontend(websql)' ||
|
|
2519
2529
|
this.ctx.mode === 'backend-frontend(websql-electron)') {
|
|
2520
2530
|
// debugger
|
|
@@ -2534,15 +2544,14 @@ class RealtimeCore {
|
|
|
2534
2544
|
//#endregion
|
|
2535
2545
|
//#region path for
|
|
2536
2546
|
pathFor(namespace) {
|
|
2537
|
-
const uri = this.ctx.uri;
|
|
2538
2547
|
let nsp = namespace ? namespace : '';
|
|
2539
2548
|
nsp = nsp === '/' ? '' : nsp;
|
|
2540
|
-
|
|
2541
|
-
let prefix = `taonContext`;
|
|
2549
|
+
let prefix = `${apiPrefix}/${this.ctx.contextName}/udp`;
|
|
2542
2550
|
if (Helpers.isElectron) {
|
|
2543
2551
|
prefix = ``;
|
|
2544
2552
|
}
|
|
2545
|
-
const href = `${
|
|
2553
|
+
const href = `${this.ctx.uriOrigin}${this.ctx.uriPathnameOrNothingIfRoot}` +
|
|
2554
|
+
`/${prefix}${prefix && nsp ? '-' + nsp : nsp}`;
|
|
2546
2555
|
// console.log(`HREF: ${href}, nsp: ${nsp}`)
|
|
2547
2556
|
return new URL(href);
|
|
2548
2557
|
}
|
|
@@ -2644,9 +2653,6 @@ class EndpointContext {
|
|
|
2644
2653
|
}
|
|
2645
2654
|
return this.config?.logs === true;
|
|
2646
2655
|
}
|
|
2647
|
-
//#endregion
|
|
2648
|
-
//#endregion
|
|
2649
|
-
//#region constructor
|
|
2650
2656
|
constructor(originalConfig, configFn) {
|
|
2651
2657
|
this.originalConfig = originalConfig;
|
|
2652
2658
|
this.configFn = configFn;
|
|
@@ -2721,6 +2727,13 @@ class EndpointContext {
|
|
|
2721
2727
|
//#region fields / entities triggers
|
|
2722
2728
|
this.entitiesTriggers = {};
|
|
2723
2729
|
//#endregion
|
|
2730
|
+
//#endregion
|
|
2731
|
+
//#region constructor
|
|
2732
|
+
/**
|
|
2733
|
+
* Inside docker there is not need for https secure server
|
|
2734
|
+
*/
|
|
2735
|
+
this.isRunningInsideDocker = false;
|
|
2736
|
+
//#endregion
|
|
2724
2737
|
//#region methods & getters / clone class
|
|
2725
2738
|
this.cloneClassWithNewMetadata = ({ BaseClass, className, config, ctx, classType, }) => {
|
|
2726
2739
|
// Return a new class that extends the base class
|
|
@@ -2816,6 +2829,7 @@ class EndpointContext {
|
|
|
2816
2829
|
}
|
|
2817
2830
|
return classes;
|
|
2818
2831
|
};
|
|
2832
|
+
this.isRunningInsideDocker = UtilsOs.isRunningInDocker();
|
|
2819
2833
|
}
|
|
2820
2834
|
//#endregion
|
|
2821
2835
|
//#region methods & getters / init
|
|
@@ -2874,6 +2888,10 @@ class EndpointContext {
|
|
|
2874
2888
|
}
|
|
2875
2889
|
this.mode = 'remote-backend(tcp+udp)';
|
|
2876
2890
|
}
|
|
2891
|
+
// console.log(`
|
|
2892
|
+
// useIpcWhenElectron: ${this.config.useIpcWhenElectron}
|
|
2893
|
+
// Helpers.isElectron: ${Helpers.isElectron}
|
|
2894
|
+
// `)
|
|
2877
2895
|
if (this.config.useIpcWhenElectron && Helpers.isElectron) {
|
|
2878
2896
|
if (Helpers.isWebSQL) {
|
|
2879
2897
|
this.mode = 'backend-frontend(websql-electron)';
|
|
@@ -2882,6 +2900,11 @@ class EndpointContext {
|
|
|
2882
2900
|
this.mode = 'backend-frontend(ipc-electron)';
|
|
2883
2901
|
}
|
|
2884
2902
|
}
|
|
2903
|
+
// mode === undefined for BaseContext => ok behavior
|
|
2904
|
+
// console.log(`Mode for BE/FE communication: ${this.mode}`);
|
|
2905
|
+
// if(!this.mode) {
|
|
2906
|
+
// console.log(this.config)
|
|
2907
|
+
// }
|
|
2885
2908
|
if (!this.mode && !this.config.abstract) {
|
|
2886
2909
|
Helpers.error(`[taon] Context "${this.contextName}": You need to provide host or remoteHost or useIpcWhenElectron`, false, true);
|
|
2887
2910
|
/* */
|
|
@@ -3029,6 +3052,14 @@ class EndpointContext {
|
|
|
3029
3052
|
/* */
|
|
3030
3053
|
/* */
|
|
3031
3054
|
/* */
|
|
3055
|
+
/* */
|
|
3056
|
+
/* */
|
|
3057
|
+
/* */
|
|
3058
|
+
/* */
|
|
3059
|
+
/* */
|
|
3060
|
+
/* */
|
|
3061
|
+
/* */
|
|
3062
|
+
/* */
|
|
3032
3063
|
}
|
|
3033
3064
|
//#endregion
|
|
3034
3065
|
//#region prepare realtime
|
|
@@ -3072,12 +3103,12 @@ class EndpointContext {
|
|
|
3072
3103
|
console.log(`
|
|
3073
3104
|
|
|
3074
3105
|
|
|
3075
|
-
IS RUNNING IN DOCKER: ${
|
|
3106
|
+
IS RUNNING IN DOCKER: ${this.isRunningInsideDocker}
|
|
3076
3107
|
|
|
3077
3108
|
`);
|
|
3078
3109
|
//#region @websqlFunc
|
|
3079
3110
|
let databaseConfig = Models.DatabaseConfig.from({});
|
|
3080
|
-
if (
|
|
3111
|
+
if (this.isRunningInsideDocker) {
|
|
3081
3112
|
if (this.USE_MARIADB_MYSQL_IN_DOCKER) {
|
|
3082
3113
|
// Helpers.info('Running in docker, using in mysql database');
|
|
3083
3114
|
// // TODO auto resolve database config in docker
|
|
@@ -3235,6 +3266,10 @@ class EndpointContext {
|
|
|
3235
3266
|
/* */
|
|
3236
3267
|
/* */
|
|
3237
3268
|
/* */
|
|
3269
|
+
/* */
|
|
3270
|
+
/* */
|
|
3271
|
+
/* */
|
|
3272
|
+
/* */
|
|
3238
3273
|
return (void 0);
|
|
3239
3274
|
}
|
|
3240
3275
|
//#endregion
|
|
@@ -3542,6 +3577,13 @@ class EndpointContext {
|
|
|
3542
3577
|
}
|
|
3543
3578
|
//#endregion
|
|
3544
3579
|
//#region methods & getters / uri
|
|
3580
|
+
get frontendHostUri() {
|
|
3581
|
+
const url = this.config?.frontendHost?.startsWith('http')
|
|
3582
|
+
? this.config.frontendHost
|
|
3583
|
+
: `${globalThis?.location?.protocol || 'http:'}//${this.config?.frontendHost}`;
|
|
3584
|
+
const uri = new URL(url.replace(/\/$/, ''));
|
|
3585
|
+
return uri;
|
|
3586
|
+
}
|
|
3545
3587
|
get uri() {
|
|
3546
3588
|
const url = this.host
|
|
3547
3589
|
? new URL(this.host)
|
|
@@ -3551,16 +3593,56 @@ class EndpointContext {
|
|
|
3551
3593
|
return url;
|
|
3552
3594
|
}
|
|
3553
3595
|
//#endregion
|
|
3596
|
+
get uriPort() {
|
|
3597
|
+
if (!this.uri?.origin?.includes('localhost')) {
|
|
3598
|
+
return this.config?.hostPortNumber?.toString();
|
|
3599
|
+
}
|
|
3600
|
+
return this.uri?.port;
|
|
3601
|
+
}
|
|
3602
|
+
get uriProtocol() {
|
|
3603
|
+
return this.uri?.protocol;
|
|
3604
|
+
}
|
|
3605
|
+
/**
|
|
3606
|
+
* Examples
|
|
3607
|
+
* http://localhost:3000
|
|
3608
|
+
* https://localhost (from localhost:80) *
|
|
3609
|
+
*/
|
|
3610
|
+
get uriOrigin() {
|
|
3611
|
+
return this.uri?.origin;
|
|
3612
|
+
}
|
|
3613
|
+
/**
|
|
3614
|
+
* Exampels
|
|
3615
|
+
* http://localhost:3000/path/to/somewhere
|
|
3616
|
+
* https://localhost/path/to/somewhere (from localhost:80)
|
|
3617
|
+
*/
|
|
3618
|
+
// get uriOriginWithPathname(): string | undefined {
|
|
3619
|
+
// return this.uri?.origin
|
|
3620
|
+
// ? this.uri?.origin + this.uriPathnameOrNothingIfRoot.replace(/\/$/, '')
|
|
3621
|
+
// : undefined;
|
|
3622
|
+
// }
|
|
3623
|
+
get uriPathname() {
|
|
3624
|
+
return this.uri?.pathname;
|
|
3625
|
+
}
|
|
3626
|
+
/**
|
|
3627
|
+
* Examples
|
|
3628
|
+
* http://localhost:3000/path/to/somewhere -> '/path/to/somewhere'
|
|
3629
|
+
* http://localhost:3000 -> '' #
|
|
3630
|
+
* https://localhost/path/to/ -> '/path/to/somewhere' # remove last slash
|
|
3631
|
+
*/
|
|
3632
|
+
get uriPathnameOrNothingIfRoot() {
|
|
3633
|
+
const isNonRootProperPathName = this.uri?.pathname && this.uri.pathname !== '/';
|
|
3634
|
+
return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
|
|
3635
|
+
}
|
|
3554
3636
|
/**
|
|
3555
3637
|
* Port from uri as number
|
|
3556
3638
|
* @returns {Number | undefined}
|
|
3557
3639
|
*/
|
|
3558
3640
|
get port() {
|
|
3559
|
-
return this.uri?.port ? Number(this.
|
|
3641
|
+
return this.uri?.port ? Number(this.uriPort) : undefined;
|
|
3560
3642
|
}
|
|
3561
3643
|
//#region methods & getters / is https server
|
|
3562
3644
|
get isHttpServer() {
|
|
3563
|
-
return this.
|
|
3645
|
+
return this.uriProtocol === 'https:';
|
|
3564
3646
|
}
|
|
3565
3647
|
//#endregion
|
|
3566
3648
|
//#region methods & getters / public assets
|
|
@@ -3571,6 +3653,9 @@ class EndpointContext {
|
|
|
3571
3653
|
return this.config.contextName;
|
|
3572
3654
|
}
|
|
3573
3655
|
//#endregion
|
|
3656
|
+
get activeContext() {
|
|
3657
|
+
return this.config.activeContext || null;
|
|
3658
|
+
}
|
|
3574
3659
|
get appId() {
|
|
3575
3660
|
return this.config.appId;
|
|
3576
3661
|
}
|
|
@@ -3677,7 +3762,7 @@ class EndpointContext {
|
|
|
3677
3762
|
}
|
|
3678
3763
|
else {
|
|
3679
3764
|
if (this.USE_MARIADB_MYSQL_IN_DOCKER) {
|
|
3680
|
-
autoSave = !
|
|
3765
|
+
autoSave = !this.isRunningInsideDocker; // in docker I am using mysql or posgress
|
|
3681
3766
|
}
|
|
3682
3767
|
else {
|
|
3683
3768
|
autoSave = true; // on docker with sqljs I need to save db
|
|
@@ -3762,7 +3847,7 @@ class EndpointContext {
|
|
|
3762
3847
|
return;
|
|
3763
3848
|
}
|
|
3764
3849
|
const allControllers = this.getClassFunByArr(Models.ClassType.CONTROLLER);
|
|
3765
|
-
// console.log('allControllers', allControllers)
|
|
3850
|
+
// console.log('allControllers', allControllers);
|
|
3766
3851
|
for (const controllerClassFn of allControllers) {
|
|
3767
3852
|
controllerClassFn[Symbols.classMethodsNames] =
|
|
3768
3853
|
ClassHelpers.getMethodsNames(controllerClassFn);
|
|
@@ -3782,15 +3867,17 @@ class EndpointContext {
|
|
|
3782
3867
|
classConfig.calculatedPath = classConfig.path;
|
|
3783
3868
|
}
|
|
3784
3869
|
else {
|
|
3785
|
-
classConfig.calculatedPath =
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3870
|
+
classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
|
|
3871
|
+
`/${apiPrefix}/${this.contextName}/tcp${parentscalculatedPath}/` +
|
|
3872
|
+
`${ClassHelpers.getName(controllerClassFn)}`)
|
|
3873
|
+
.replace(/\/\//g, '/')
|
|
3874
|
+
.split('/')
|
|
3875
|
+
.reduce((acc, bc) => {
|
|
3876
|
+
return _.last(acc) === bc ? acc : [...acc, bc];
|
|
3877
|
+
}, [])
|
|
3878
|
+
.join('/');
|
|
3793
3879
|
}
|
|
3880
|
+
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
3794
3881
|
_.slice(configs, 1).forEach(bc => {
|
|
3795
3882
|
const alreadyIs = classConfig.methods;
|
|
3796
3883
|
const toMerge = _.cloneDeep(bc.methods);
|
|
@@ -3813,16 +3900,21 @@ class EndpointContext {
|
|
|
3813
3900
|
const methodConfig = classConfig.methods[methodName];
|
|
3814
3901
|
// debugger
|
|
3815
3902
|
const type = methodConfig.type;
|
|
3903
|
+
// this is quick fix - in docker global path should not be used
|
|
3904
|
+
const globalPathPart = this.isRunningInsideDocker ||
|
|
3905
|
+
!this.frontendHostUri?.origin?.includes('localhost') // fe with domain -> is in docker
|
|
3906
|
+
? `${this.uriPathnameOrNothingIfRoot.replace(/\/$/, '')}/${apiPrefix}/${this.contextName}`.replace(/\/\//, '/')
|
|
3907
|
+
: '';
|
|
3816
3908
|
const expressPath = methodConfig.global
|
|
3817
|
-
?
|
|
3909
|
+
? `${globalPathPart}/${methodConfig.path?.replace(/\/$/, '')}`.replace(/\/\//, '/')
|
|
3818
3910
|
: TaonHelpers.getExpressPath(classConfig, methodConfig);
|
|
3819
|
-
// console.log({ expressPath })
|
|
3911
|
+
// console.log({ expressPath });
|
|
3820
3912
|
if (Helpers.isNode || Helpers.isWebSQL) {
|
|
3821
3913
|
//#region @websql
|
|
3822
|
-
const
|
|
3914
|
+
const route = this.initServer(type, methodConfig, classConfig, expressPath, controllerClassFn);
|
|
3823
3915
|
this.activeRoutes.push({
|
|
3824
|
-
|
|
3825
|
-
method,
|
|
3916
|
+
expressPath: route.expressPath,
|
|
3917
|
+
method: route.method,
|
|
3826
3918
|
});
|
|
3827
3919
|
//#endregion
|
|
3828
3920
|
}
|
|
@@ -3854,21 +3946,21 @@ class EndpointContext {
|
|
|
3854
3946
|
this.skipWritingServerRoutes) {
|
|
3855
3947
|
return;
|
|
3856
3948
|
}
|
|
3857
|
-
const contexts = [this];
|
|
3949
|
+
// const contexts: EndpointContext[] = [this];
|
|
3858
3950
|
//#region @websql
|
|
3859
3951
|
const troutes = Utils.uniqArray(this.activeRoutes.map(f => {
|
|
3860
|
-
return `${f.method} ${f.
|
|
3952
|
+
return `${f.method} ${f.expressPath}`;
|
|
3861
3953
|
})).map(f => {
|
|
3862
|
-
const [method,
|
|
3863
|
-
return (`\n### ${_.startCase(_.last(
|
|
3954
|
+
const [method, expressPath] = f.split(' ');
|
|
3955
|
+
return (`\n### ${_.startCase(_.last(expressPath.split('/')))}\n` +
|
|
3864
3956
|
TaonHelpers.fillUpTo(method.toUpperCase() + ' ', 10) +
|
|
3865
|
-
this.
|
|
3866
|
-
|
|
3957
|
+
this.uriOrigin +
|
|
3958
|
+
expressPath);
|
|
3867
3959
|
// return `${TaonHelpers.string(method.toUpperCase() + ':')
|
|
3868
|
-
// .fillUpTo(10)}${context.
|
|
3960
|
+
// .fillUpTo(10)}${context.uriHref.replace(/\/$/, '')}${expressPath}`
|
|
3869
3961
|
});
|
|
3870
3962
|
const routes = [
|
|
3871
|
-
...['', `# ROUTES FOR HOST ${this.
|
|
3963
|
+
...['', `# ROUTES FOR HOST ${this.uriOrigin} `],
|
|
3872
3964
|
...troutes,
|
|
3873
3965
|
].join('\n');
|
|
3874
3966
|
const fileName = crossPlatformPath([
|
|
@@ -4011,7 +4103,7 @@ class EndpointContext {
|
|
|
4011
4103
|
next();
|
|
4012
4104
|
};
|
|
4013
4105
|
//#endregion
|
|
4014
|
-
const url = this.uri;
|
|
4106
|
+
// const url = this.uri;
|
|
4015
4107
|
//#region get result
|
|
4016
4108
|
const getResult = async (resolvedParams, req, res) => {
|
|
4017
4109
|
const response = methodConfig.descriptor.value.apply(
|
|
@@ -4027,12 +4119,7 @@ class EndpointContext {
|
|
|
4027
4119
|
return result;
|
|
4028
4120
|
};
|
|
4029
4121
|
//#endregion
|
|
4030
|
-
|
|
4031
|
-
expressPath = url.pathname.startsWith('/')
|
|
4032
|
-
? `${url.pathname}${expressPath}`
|
|
4033
|
-
: expressPath;
|
|
4034
|
-
expressPath = expressPath.replace(/\/\//g, '/');
|
|
4035
|
-
// console.log(`BACKEND: expressPath: ${ expressPath } `)
|
|
4122
|
+
// console.log(`BACKEND: expressPath: "${expressPath}" `);
|
|
4036
4123
|
//#endregion
|
|
4037
4124
|
if (Helpers.isElectron) {
|
|
4038
4125
|
/* */
|
|
@@ -4056,6 +4143,9 @@ class EndpointContext {
|
|
|
4056
4143
|
/* */
|
|
4057
4144
|
/* */
|
|
4058
4145
|
/* */
|
|
4146
|
+
/* */
|
|
4147
|
+
/* */
|
|
4148
|
+
/* */
|
|
4059
4149
|
}
|
|
4060
4150
|
if (!this.remoteHost) {
|
|
4061
4151
|
//#region apply dummy websql express routers
|
|
@@ -4283,7 +4373,7 @@ class EndpointContext {
|
|
|
4283
4373
|
/* */
|
|
4284
4374
|
}
|
|
4285
4375
|
return {
|
|
4286
|
-
|
|
4376
|
+
expressPath: expressPath,
|
|
4287
4377
|
method: methodConfig.type,
|
|
4288
4378
|
};
|
|
4289
4379
|
}
|
|
@@ -4321,7 +4411,7 @@ class EndpointContext {
|
|
|
4321
4411
|
body: void 0,
|
|
4322
4412
|
isArray: void 0,
|
|
4323
4413
|
method: methodConfig.type,
|
|
4324
|
-
url: `${ctx.
|
|
4414
|
+
url: `${ctx.uriOrigin}${'' // TODO express path
|
|
4325
4415
|
}${methodConfig.path} `,
|
|
4326
4416
|
}, Helpers.isBlob(body) || _.isString(body)
|
|
4327
4417
|
? body
|
|
@@ -4434,7 +4524,7 @@ class EndpointContext {
|
|
|
4434
4524
|
body: void 0,
|
|
4435
4525
|
isArray: void 0,
|
|
4436
4526
|
method: methodConfig.type,
|
|
4437
|
-
url: `${ctx.
|
|
4527
|
+
url: `${ctx.uriOrigin}${'' // TODO express path
|
|
4438
4528
|
}${methodConfig.path} `,
|
|
4439
4529
|
}, Helpers.isBlob(body) || _.isString(body)
|
|
4440
4530
|
? body
|
|
@@ -4474,37 +4564,37 @@ class EndpointContext {
|
|
|
4474
4564
|
//#region resolve frontend parameters
|
|
4475
4565
|
if (!storage[Symbols.old.ENDPOINT_META_CONFIG])
|
|
4476
4566
|
storage[Symbols.old.ENDPOINT_META_CONFIG] = {};
|
|
4477
|
-
if (!storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.
|
|
4478
|
-
storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.
|
|
4567
|
+
if (!storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.uriOrigin])
|
|
4568
|
+
storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.uriOrigin] = {};
|
|
4479
4569
|
const endpoints = storage[Symbols.old.ENDPOINT_META_CONFIG];
|
|
4480
4570
|
let rest;
|
|
4481
|
-
if (!endpoints[ctx.
|
|
4571
|
+
if (!endpoints[ctx.uriOrigin][expressPath]) {
|
|
4482
4572
|
let headers = {};
|
|
4483
4573
|
if (methodConfig.contentType && !methodConfig.responseType) {
|
|
4484
|
-
rest = Resource.create(ctx.
|
|
4574
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4485
4575
|
'Content-Type': methodConfig.contentType,
|
|
4486
4576
|
Accept: methodConfig.contentType,
|
|
4487
4577
|
}));
|
|
4488
4578
|
}
|
|
4489
4579
|
else if (methodConfig.contentType && methodConfig.responseType) {
|
|
4490
|
-
rest = Resource.create(ctx.
|
|
4580
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4491
4581
|
'Content-Type': methodConfig.contentType,
|
|
4492
4582
|
Accept: methodConfig.contentType,
|
|
4493
4583
|
responsetypeaxios: methodConfig.responseType,
|
|
4494
4584
|
}));
|
|
4495
4585
|
}
|
|
4496
4586
|
else if (!methodConfig.contentType && methodConfig.responseType) {
|
|
4497
|
-
rest = Resource.create(ctx.
|
|
4587
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4498
4588
|
responsetypeaxios: methodConfig.responseType,
|
|
4499
4589
|
}));
|
|
4500
4590
|
}
|
|
4501
4591
|
else {
|
|
4502
|
-
rest = Resource.create(ctx.
|
|
4592
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY);
|
|
4503
4593
|
}
|
|
4504
|
-
endpoints[ctx.
|
|
4594
|
+
endpoints[ctx.uriOrigin][expressPath] = rest;
|
|
4505
4595
|
}
|
|
4506
4596
|
else {
|
|
4507
|
-
rest = endpoints[ctx.
|
|
4597
|
+
rest = endpoints[ctx.uriOrigin][expressPath];
|
|
4508
4598
|
}
|
|
4509
4599
|
const method = type.toLowerCase();
|
|
4510
4600
|
const isWithBody = method === 'put' || method === 'post';
|
|
@@ -4633,6 +4723,11 @@ const createContextTemplate = (configFn) => {
|
|
|
4633
4723
|
*/
|
|
4634
4724
|
const createContext = (configFn) => {
|
|
4635
4725
|
let config = configFn({});
|
|
4726
|
+
// console.log(
|
|
4727
|
+
// `
|
|
4728
|
+
// [Taon] Creating context ${config.contextName}...`,
|
|
4729
|
+
// {config},
|
|
4730
|
+
// );
|
|
4636
4731
|
const endpointContextRef = new EndpointContext(config, configFn);
|
|
4637
4732
|
const res = {
|
|
4638
4733
|
//#region types
|
|
@@ -4733,6 +4828,16 @@ const createContext = (configFn) => {
|
|
|
4733
4828
|
return await new Promise(async (resolve, reject) => {
|
|
4734
4829
|
//#region init in set timeout
|
|
4735
4830
|
setTimeout(async () => {
|
|
4831
|
+
if (UtilsOs.isRunningInDocker()) {
|
|
4832
|
+
const activeContext = config?.activeContext || null;
|
|
4833
|
+
if (_.isString(activeContext) &&
|
|
4834
|
+
activeContext !== '' &&
|
|
4835
|
+
activeContext !== config?.contextName) {
|
|
4836
|
+
console.warn(`[taon] Context ${endpointContextRef.contextName} is not active context, skipping initialization.`);
|
|
4837
|
+
resolve(endpointContextRef);
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4736
4841
|
await endpointContextRef.init({
|
|
4737
4842
|
...overrideOptions,
|
|
4738
4843
|
});
|
|
@@ -6360,5 +6465,5 @@ var Taon;
|
|
|
6360
6465
|
* Generated bundle index. Do not edit.
|
|
6361
6466
|
*/
|
|
6362
6467
|
|
|
6363
|
-
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, createContext, inject };
|
|
6468
|
+
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
|
|
6364
6469
|
//# sourceMappingURL=taon.mjs.map
|