taon 19.0.48 → 19.0.49
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 +247 -192
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/constants.d.ts +2 -1
- package/browser/lib/endpoint-context.d.ts +22 -1
- package/browser/lib/helpers/class-helpers.d.ts +0 -1
- 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/build-info._auto-generated_.d.ts +2 -1
- package/lib/build-info._auto-generated_.js +3 -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/endpoint-context.d.ts +22 -1
- package/lib/endpoint-context.js +96 -50
- package/lib/endpoint-context.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/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 +22 -22
- package/lib/realtime/realtime-server.js.map +1 -1
- 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/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/package.json +1 -1
- package/websql/fesm2022/taon.mjs +274 -223
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/constants.d.ts +2 -1
- package/websql/lib/endpoint-context.d.ts +22 -1
- package/websql/lib/helpers/class-helpers.d.ts +0 -1
- 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
|
/* */
|
|
@@ -1667,6 +1668,7 @@ to use socket realtime connection;
|
|
|
1667
1668
|
}
|
|
1668
1669
|
|
|
1669
1670
|
//#region imports
|
|
1671
|
+
/* */
|
|
1670
1672
|
//#endregion
|
|
1671
1673
|
class RealtimeServer {
|
|
1672
1674
|
// private jobs = {};
|
|
@@ -1693,45 +1695,44 @@ class RealtimeServer {
|
|
|
1693
1695
|
`);
|
|
1694
1696
|
}
|
|
1695
1697
|
//#region prepare namespaces pathes
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
realtime: this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
1699
|
-
};
|
|
1698
|
+
const nspPathGlobal = this.core.pathFor();
|
|
1699
|
+
const nspPathRealtime = this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName));
|
|
1700
1700
|
//#endregion
|
|
1701
1701
|
// console.log('[backend] nspPath', nspPath);
|
|
1702
|
+
const fronendURL = new URL(this.core.ctx.config.frontendHost.replace(/\/$/, ''));
|
|
1703
|
+
const cors = {
|
|
1704
|
+
origin: fronendURL.origin, // only origin needs to be set - pathname not needed
|
|
1705
|
+
methods: this.core.allHttpMethods,
|
|
1706
|
+
};
|
|
1707
|
+
// console.log('frontendHost', this.core.ctx.config.frontendHost);
|
|
1708
|
+
// console.log('cors', cors);
|
|
1702
1709
|
//#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
|
-
},
|
|
1710
|
+
this.core.connectSocketBE = this.core.strategy.ioServer(Helpers.isWebSQL ? this.core.ctx.uriOrigin : this.core.ctx.serverTcpUdp, {
|
|
1711
|
+
path: nspPathGlobal.pathname,
|
|
1712
|
+
cors,
|
|
1709
1713
|
}, // @ts-ignore
|
|
1710
1714
|
this.core.ctx);
|
|
1711
1715
|
this.core.ctx.logRealtime &&
|
|
1712
1716
|
console.info(`[backend] CREATE GLOBAL NAMESPACE: '${this.core.connectSocketBE.path()}'` +
|
|
1713
|
-
` , path: '${
|
|
1717
|
+
` , path: '${nspPathGlobal.pathname}'`);
|
|
1714
1718
|
this.core.connectSocketBE.on('connection', clientSocket => {
|
|
1715
|
-
console.info(`[backend] client connected to namespace "${
|
|
1719
|
+
console.info(`[backend] client connected to namespace "${nspPathGlobal.pathname}", ` +
|
|
1716
1720
|
` host: ${this.core.ctx.host}`);
|
|
1717
1721
|
});
|
|
1718
1722
|
//#endregion
|
|
1719
1723
|
//#region prepare realtime BE socket
|
|
1720
1724
|
this.core.socketBE = this.core.strategy.ioServer(Helpers.isWebSQL || Helpers.isElectron
|
|
1721
|
-
? this.core.ctx.
|
|
1725
|
+
? this.core.ctx.uriOrigin
|
|
1722
1726
|
: this.core.ctx.serverTcpUdp, {
|
|
1723
|
-
path:
|
|
1724
|
-
cors
|
|
1725
|
-
origin: this.core.ctx.config.frontendHost,
|
|
1726
|
-
methods: this.core.allHttpMethods,
|
|
1727
|
-
},
|
|
1727
|
+
path: nspPathRealtime.pathname,
|
|
1728
|
+
cors,
|
|
1728
1729
|
}, // @ts-ignore
|
|
1729
1730
|
this.core.ctx);
|
|
1730
1731
|
this.core.ctx.logRealtime &&
|
|
1731
1732
|
console.info(`[backend] CREATE REALTIME NAMESPACE: '${this.core.socketBE.path()}'` +
|
|
1732
|
-
` , path: '${
|
|
1733
|
+
` , path: '${nspPathRealtime.pathname}' `);
|
|
1733
1734
|
this.core.socketBE.on('connection', backendSocketForClient => {
|
|
1734
|
-
console.info(`[backend] client connected to namespace "${
|
|
1735
|
+
console.info(`[backend] client connected to namespace "${nspPathRealtime.pathname}", ` +
|
|
1735
1736
|
` host: ${this.core.ctx.host}`);
|
|
1736
1737
|
backendSocketForClient.on(Symbols.REALTIME.ROOM_SUBSCRIBE_CUSTOM(this.core.ctx.contextName), roomName => {
|
|
1737
1738
|
this.core.ctx.logRealtime &&
|
|
@@ -2440,12 +2441,12 @@ class RealtimeStrategyMock extends RealtimeStrategy {
|
|
|
2440
2441
|
//#endregion
|
|
2441
2442
|
//#region server & io
|
|
2442
2443
|
ioServer(url, opt) {
|
|
2443
|
-
const server = MockServer.from(url || this.ctx.
|
|
2444
|
+
const server = MockServer.from(url || this.ctx.uriOrigin);
|
|
2444
2445
|
return server.of(opt?.path || '/');
|
|
2445
2446
|
}
|
|
2446
2447
|
get ioClient() {
|
|
2447
2448
|
const clientIo = (uri, opts) => {
|
|
2448
|
-
return new MockSocket(uri || this.ctx.
|
|
2449
|
+
return new MockSocket(uri || this.ctx.uriOrigin, opts);
|
|
2449
2450
|
};
|
|
2450
2451
|
return clientIo;
|
|
2451
2452
|
}
|
|
@@ -2515,6 +2516,7 @@ class RealtimeCore {
|
|
|
2515
2516
|
//#endregion
|
|
2516
2517
|
//#region methods & getters / resovle staraegy
|
|
2517
2518
|
resolveStrategy() {
|
|
2519
|
+
// console.log(`[taon] resolveStrategy for this.ctx.mode ${this.ctx.mode}`);
|
|
2518
2520
|
if (this.ctx.mode === 'backend-frontend(websql)' ||
|
|
2519
2521
|
this.ctx.mode === 'backend-frontend(websql-electron)') {
|
|
2520
2522
|
// debugger
|
|
@@ -2534,15 +2536,14 @@ class RealtimeCore {
|
|
|
2534
2536
|
//#endregion
|
|
2535
2537
|
//#region path for
|
|
2536
2538
|
pathFor(namespace) {
|
|
2537
|
-
const uri = this.ctx.uri;
|
|
2538
2539
|
let nsp = namespace ? namespace : '';
|
|
2539
2540
|
nsp = nsp === '/' ? '' : nsp;
|
|
2540
|
-
|
|
2541
|
-
let prefix = `taonContext`;
|
|
2541
|
+
let prefix = `${apiPrefix}/${this.ctx.contextName}/udp`;
|
|
2542
2542
|
if (Helpers.isElectron) {
|
|
2543
2543
|
prefix = ``;
|
|
2544
2544
|
}
|
|
2545
|
-
const href = `${
|
|
2545
|
+
const href = `${this.ctx.uriOrigin}${this.ctx.uriPathnameOrNothingIfRoot}` +
|
|
2546
|
+
`/${prefix}${prefix && nsp ? '-' + nsp : nsp}`;
|
|
2546
2547
|
// console.log(`HREF: ${href}, nsp: ${nsp}`)
|
|
2547
2548
|
return new URL(href);
|
|
2548
2549
|
}
|
|
@@ -2874,6 +2875,10 @@ class EndpointContext {
|
|
|
2874
2875
|
}
|
|
2875
2876
|
this.mode = 'remote-backend(tcp+udp)';
|
|
2876
2877
|
}
|
|
2878
|
+
// console.log(`
|
|
2879
|
+
// useIpcWhenElectron: ${this.config.useIpcWhenElectron}
|
|
2880
|
+
// Helpers.isElectron: ${Helpers.isElectron}
|
|
2881
|
+
// `)
|
|
2877
2882
|
if (this.config.useIpcWhenElectron && Helpers.isElectron) {
|
|
2878
2883
|
if (Helpers.isWebSQL) {
|
|
2879
2884
|
this.mode = 'backend-frontend(websql-electron)';
|
|
@@ -2882,6 +2887,11 @@ class EndpointContext {
|
|
|
2882
2887
|
this.mode = 'backend-frontend(ipc-electron)';
|
|
2883
2888
|
}
|
|
2884
2889
|
}
|
|
2890
|
+
// mode === undefined for BaseContext => ok behavior
|
|
2891
|
+
// console.log(`Mode for BE/FE communication: ${this.mode}`);
|
|
2892
|
+
// if(!this.mode) {
|
|
2893
|
+
// console.log(this.config)
|
|
2894
|
+
// }
|
|
2885
2895
|
if (!this.mode && !this.config.abstract) {
|
|
2886
2896
|
Helpers.error(`[taon] Context "${this.contextName}": You need to provide host or remoteHost or useIpcWhenElectron`, false, true);
|
|
2887
2897
|
/* */
|
|
@@ -3235,6 +3245,10 @@ class EndpointContext {
|
|
|
3235
3245
|
/* */
|
|
3236
3246
|
/* */
|
|
3237
3247
|
/* */
|
|
3248
|
+
/* */
|
|
3249
|
+
/* */
|
|
3250
|
+
/* */
|
|
3251
|
+
/* */
|
|
3238
3252
|
return (void 0);
|
|
3239
3253
|
}
|
|
3240
3254
|
//#endregion
|
|
@@ -3551,16 +3565,53 @@ class EndpointContext {
|
|
|
3551
3565
|
return url;
|
|
3552
3566
|
}
|
|
3553
3567
|
//#endregion
|
|
3568
|
+
get uriPort() {
|
|
3569
|
+
return this.uri?.port;
|
|
3570
|
+
}
|
|
3571
|
+
get uriProtocol() {
|
|
3572
|
+
return this.uri?.protocol;
|
|
3573
|
+
}
|
|
3574
|
+
/**
|
|
3575
|
+
* Examples
|
|
3576
|
+
* http://localhost:3000
|
|
3577
|
+
* https://localhost (from localhost:80) *
|
|
3578
|
+
*/
|
|
3579
|
+
get uriOrigin() {
|
|
3580
|
+
return this.uri?.origin;
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Exampels
|
|
3584
|
+
* http://localhost:3000/path/to/somewhere
|
|
3585
|
+
* https://localhost/path/to/somewhere (from localhost:80)
|
|
3586
|
+
*/
|
|
3587
|
+
// get uriOriginWithPathname(): string | undefined {
|
|
3588
|
+
// return this.uri?.origin
|
|
3589
|
+
// ? this.uri?.origin + this.uriPathnameOrNothingIfRoot.replace(/\/$/, '')
|
|
3590
|
+
// : undefined;
|
|
3591
|
+
// }
|
|
3592
|
+
get uriPathname() {
|
|
3593
|
+
return this.uri?.pathname;
|
|
3594
|
+
}
|
|
3595
|
+
/**
|
|
3596
|
+
* Examples
|
|
3597
|
+
* http://localhost:3000/path/to/somewhere -> '/path/to/somewhere'
|
|
3598
|
+
* http://localhost:3000 -> '' #
|
|
3599
|
+
* https://localhost/path/to/ -> '/path/to/somewhere' # remove last slash
|
|
3600
|
+
*/
|
|
3601
|
+
get uriPathnameOrNothingIfRoot() {
|
|
3602
|
+
const isNonRootProperPathName = this.uri?.pathname && this.uri.pathname !== '/';
|
|
3603
|
+
return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
|
|
3604
|
+
}
|
|
3554
3605
|
/**
|
|
3555
3606
|
* Port from uri as number
|
|
3556
3607
|
* @returns {Number | undefined}
|
|
3557
3608
|
*/
|
|
3558
3609
|
get port() {
|
|
3559
|
-
return this.uri?.port ? Number(this.
|
|
3610
|
+
return this.uri?.port ? Number(this.uriPort) : undefined;
|
|
3560
3611
|
}
|
|
3561
3612
|
//#region methods & getters / is https server
|
|
3562
3613
|
get isHttpServer() {
|
|
3563
|
-
return this.
|
|
3614
|
+
return this.uriProtocol === 'https:';
|
|
3564
3615
|
}
|
|
3565
3616
|
//#endregion
|
|
3566
3617
|
//#region methods & getters / public assets
|
|
@@ -3762,7 +3813,7 @@ class EndpointContext {
|
|
|
3762
3813
|
return;
|
|
3763
3814
|
}
|
|
3764
3815
|
const allControllers = this.getClassFunByArr(Models.ClassType.CONTROLLER);
|
|
3765
|
-
// console.log('allControllers', allControllers)
|
|
3816
|
+
// console.log('allControllers', allControllers);
|
|
3766
3817
|
for (const controllerClassFn of allControllers) {
|
|
3767
3818
|
controllerClassFn[Symbols.classMethodsNames] =
|
|
3768
3819
|
ClassHelpers.getMethodsNames(controllerClassFn);
|
|
@@ -3782,15 +3833,17 @@ class EndpointContext {
|
|
|
3782
3833
|
classConfig.calculatedPath = classConfig.path;
|
|
3783
3834
|
}
|
|
3784
3835
|
else {
|
|
3785
|
-
classConfig.calculatedPath =
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3836
|
+
classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
|
|
3837
|
+
`/${apiPrefix}/${this.contextName}/tcp${parentscalculatedPath}/` +
|
|
3838
|
+
`${ClassHelpers.getName(controllerClassFn)}`)
|
|
3839
|
+
.replace(/\/\//g, '/')
|
|
3840
|
+
.split('/')
|
|
3841
|
+
.reduce((acc, bc) => {
|
|
3842
|
+
return _.last(acc) === bc ? acc : [...acc, bc];
|
|
3843
|
+
}, [])
|
|
3844
|
+
.join('/');
|
|
3793
3845
|
}
|
|
3846
|
+
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
3794
3847
|
_.slice(configs, 1).forEach(bc => {
|
|
3795
3848
|
const alreadyIs = classConfig.methods;
|
|
3796
3849
|
const toMerge = _.cloneDeep(bc.methods);
|
|
@@ -3816,13 +3869,13 @@ class EndpointContext {
|
|
|
3816
3869
|
const expressPath = methodConfig.global
|
|
3817
3870
|
? `/${methodConfig.path?.replace(/\//, '')}`
|
|
3818
3871
|
: TaonHelpers.getExpressPath(classConfig, methodConfig);
|
|
3819
|
-
// console.log({ expressPath })
|
|
3872
|
+
// console.log({ expressPath });
|
|
3820
3873
|
if (Helpers.isNode || Helpers.isWebSQL) {
|
|
3821
3874
|
//#region @websql
|
|
3822
|
-
const
|
|
3875
|
+
const route = this.initServer(type, methodConfig, classConfig, expressPath, controllerClassFn);
|
|
3823
3876
|
this.activeRoutes.push({
|
|
3824
|
-
|
|
3825
|
-
method,
|
|
3877
|
+
expressPath: route.expressPath,
|
|
3878
|
+
method: route.method,
|
|
3826
3879
|
});
|
|
3827
3880
|
//#endregion
|
|
3828
3881
|
}
|
|
@@ -3854,21 +3907,21 @@ class EndpointContext {
|
|
|
3854
3907
|
this.skipWritingServerRoutes) {
|
|
3855
3908
|
return;
|
|
3856
3909
|
}
|
|
3857
|
-
const contexts = [this];
|
|
3910
|
+
// const contexts: EndpointContext[] = [this];
|
|
3858
3911
|
//#region @websql
|
|
3859
3912
|
const troutes = Utils.uniqArray(this.activeRoutes.map(f => {
|
|
3860
|
-
return `${f.method} ${f.
|
|
3913
|
+
return `${f.method} ${f.expressPath}`;
|
|
3861
3914
|
})).map(f => {
|
|
3862
|
-
const [method,
|
|
3863
|
-
return (`\n### ${_.startCase(_.last(
|
|
3915
|
+
const [method, expressPath] = f.split(' ');
|
|
3916
|
+
return (`\n### ${_.startCase(_.last(expressPath.split('/')))}\n` +
|
|
3864
3917
|
TaonHelpers.fillUpTo(method.toUpperCase() + ' ', 10) +
|
|
3865
|
-
this.
|
|
3866
|
-
|
|
3918
|
+
this.uriOrigin +
|
|
3919
|
+
expressPath);
|
|
3867
3920
|
// return `${TaonHelpers.string(method.toUpperCase() + ':')
|
|
3868
|
-
// .fillUpTo(10)}${context.
|
|
3921
|
+
// .fillUpTo(10)}${context.uriHref.replace(/\/$/, '')}${expressPath}`
|
|
3869
3922
|
});
|
|
3870
3923
|
const routes = [
|
|
3871
|
-
...['', `# ROUTES FOR HOST ${this.
|
|
3924
|
+
...['', `# ROUTES FOR HOST ${this.uriOrigin} `],
|
|
3872
3925
|
...troutes,
|
|
3873
3926
|
].join('\n');
|
|
3874
3927
|
const fileName = crossPlatformPath([
|
|
@@ -4011,7 +4064,7 @@ class EndpointContext {
|
|
|
4011
4064
|
next();
|
|
4012
4065
|
};
|
|
4013
4066
|
//#endregion
|
|
4014
|
-
const url = this.uri;
|
|
4067
|
+
// const url = this.uri;
|
|
4015
4068
|
//#region get result
|
|
4016
4069
|
const getResult = async (resolvedParams, req, res) => {
|
|
4017
4070
|
const response = methodConfig.descriptor.value.apply(
|
|
@@ -4027,12 +4080,7 @@ class EndpointContext {
|
|
|
4027
4080
|
return result;
|
|
4028
4081
|
};
|
|
4029
4082
|
//#endregion
|
|
4030
|
-
|
|
4031
|
-
expressPath = url.pathname.startsWith('/')
|
|
4032
|
-
? `${url.pathname}${expressPath}`
|
|
4033
|
-
: expressPath;
|
|
4034
|
-
expressPath = expressPath.replace(/\/\//g, '/');
|
|
4035
|
-
// console.log(`BACKEND: expressPath: ${ expressPath } `)
|
|
4083
|
+
// console.log(`BACKEND: expressPath: "${expressPath}" `);
|
|
4036
4084
|
//#endregion
|
|
4037
4085
|
if (Helpers.isElectron) {
|
|
4038
4086
|
/* */
|
|
@@ -4056,6 +4104,9 @@ class EndpointContext {
|
|
|
4056
4104
|
/* */
|
|
4057
4105
|
/* */
|
|
4058
4106
|
/* */
|
|
4107
|
+
/* */
|
|
4108
|
+
/* */
|
|
4109
|
+
/* */
|
|
4059
4110
|
}
|
|
4060
4111
|
if (!this.remoteHost) {
|
|
4061
4112
|
//#region apply dummy websql express routers
|
|
@@ -4283,7 +4334,7 @@ class EndpointContext {
|
|
|
4283
4334
|
/* */
|
|
4284
4335
|
}
|
|
4285
4336
|
return {
|
|
4286
|
-
|
|
4337
|
+
expressPath: expressPath,
|
|
4287
4338
|
method: methodConfig.type,
|
|
4288
4339
|
};
|
|
4289
4340
|
}
|
|
@@ -4321,7 +4372,7 @@ class EndpointContext {
|
|
|
4321
4372
|
body: void 0,
|
|
4322
4373
|
isArray: void 0,
|
|
4323
4374
|
method: methodConfig.type,
|
|
4324
|
-
url: `${ctx.
|
|
4375
|
+
url: `${ctx.uriOrigin}${'' // TODO express path
|
|
4325
4376
|
}${methodConfig.path} `,
|
|
4326
4377
|
}, Helpers.isBlob(body) || _.isString(body)
|
|
4327
4378
|
? body
|
|
@@ -4434,7 +4485,7 @@ class EndpointContext {
|
|
|
4434
4485
|
body: void 0,
|
|
4435
4486
|
isArray: void 0,
|
|
4436
4487
|
method: methodConfig.type,
|
|
4437
|
-
url: `${ctx.
|
|
4488
|
+
url: `${ctx.uriOrigin}${'' // TODO express path
|
|
4438
4489
|
}${methodConfig.path} `,
|
|
4439
4490
|
}, Helpers.isBlob(body) || _.isString(body)
|
|
4440
4491
|
? body
|
|
@@ -4474,37 +4525,37 @@ class EndpointContext {
|
|
|
4474
4525
|
//#region resolve frontend parameters
|
|
4475
4526
|
if (!storage[Symbols.old.ENDPOINT_META_CONFIG])
|
|
4476
4527
|
storage[Symbols.old.ENDPOINT_META_CONFIG] = {};
|
|
4477
|
-
if (!storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.
|
|
4478
|
-
storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.
|
|
4528
|
+
if (!storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.uriOrigin])
|
|
4529
|
+
storage[Symbols.old.ENDPOINT_META_CONFIG][ctx.uriOrigin] = {};
|
|
4479
4530
|
const endpoints = storage[Symbols.old.ENDPOINT_META_CONFIG];
|
|
4480
4531
|
let rest;
|
|
4481
|
-
if (!endpoints[ctx.
|
|
4532
|
+
if (!endpoints[ctx.uriOrigin][expressPath]) {
|
|
4482
4533
|
let headers = {};
|
|
4483
4534
|
if (methodConfig.contentType && !methodConfig.responseType) {
|
|
4484
|
-
rest = Resource.create(ctx.
|
|
4535
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4485
4536
|
'Content-Type': methodConfig.contentType,
|
|
4486
4537
|
Accept: methodConfig.contentType,
|
|
4487
4538
|
}));
|
|
4488
4539
|
}
|
|
4489
4540
|
else if (methodConfig.contentType && methodConfig.responseType) {
|
|
4490
|
-
rest = Resource.create(ctx.
|
|
4541
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4491
4542
|
'Content-Type': methodConfig.contentType,
|
|
4492
4543
|
Accept: methodConfig.contentType,
|
|
4493
4544
|
responsetypeaxios: methodConfig.responseType,
|
|
4494
4545
|
}));
|
|
4495
4546
|
}
|
|
4496
4547
|
else if (!methodConfig.contentType && methodConfig.responseType) {
|
|
4497
|
-
rest = Resource.create(ctx.
|
|
4548
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY, RestHeaders.from({
|
|
4498
4549
|
responsetypeaxios: methodConfig.responseType,
|
|
4499
4550
|
}));
|
|
4500
4551
|
}
|
|
4501
4552
|
else {
|
|
4502
|
-
rest = Resource.create(ctx.
|
|
4553
|
+
rest = Resource.create(ctx.uriOrigin, expressPath, Symbols.old.MAPPING_CONFIG_HEADER, Symbols.old.CIRCURAL_OBJECTS_MAP_BODY);
|
|
4503
4554
|
}
|
|
4504
|
-
endpoints[ctx.
|
|
4555
|
+
endpoints[ctx.uriOrigin][expressPath] = rest;
|
|
4505
4556
|
}
|
|
4506
4557
|
else {
|
|
4507
|
-
rest = endpoints[ctx.
|
|
4558
|
+
rest = endpoints[ctx.uriOrigin][expressPath];
|
|
4508
4559
|
}
|
|
4509
4560
|
const method = type.toLowerCase();
|
|
4510
4561
|
const isWithBody = method === 'put' || method === 'post';
|
|
@@ -6360,5 +6411,5 @@ var Taon;
|
|
|
6360
6411
|
* Generated bundle index. Do not edit.
|
|
6361
6412
|
*/
|
|
6362
6413
|
|
|
6363
|
-
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, createContext, inject };
|
|
6414
|
+
export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
|
|
6364
6415
|
//# sourceMappingURL=taon.mjs.map
|