taon 19.0.66 → 19.0.68

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.
Files changed (120) hide show
  1. package/README.md +160 -160
  2. package/bin/start.js +281 -281
  3. package/bin/taon +6 -6
  4. package/bin/taon-debug +5 -5
  5. package/bin/taon-debug-brk +5 -5
  6. package/browser/README.md +24 -24
  7. package/browser/fesm2022/taon.mjs +305 -89
  8. package/browser/fesm2022/taon.mjs.map +1 -1
  9. package/browser/lib/base-classes/base-class.d.ts +8 -1
  10. package/browser/lib/base-classes/base-controller.d.ts +56 -4
  11. package/browser/lib/base-classes/base-crud-controller.d.ts +5 -4
  12. package/browser/lib/base-classes/base-middleware.d.ts +2 -2
  13. package/browser/lib/base-classes/base-repository.d.ts +3 -0
  14. package/browser/lib/config/method-config.d.ts +1 -0
  15. package/browser/lib/decorators/http/http-decorators.d.ts +2 -1
  16. package/browser/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  17. package/browser/lib/endpoint-context.d.ts +10 -4
  18. package/browser/lib/get-response-value.d.ts +1 -1
  19. package/browser/lib/helpers/taon-helpers.d.ts +1 -0
  20. package/browser/lib/index.d.ts +4 -0
  21. package/browser/lib/models.d.ts +4 -10
  22. package/browser/lib/realtime/realtime-client.d.ts +18 -14
  23. package/browser/lib/realtime/realtime-server.d.ts +28 -3
  24. package/browser/lib/realtime/realtime.models.d.ts +15 -2
  25. package/browser/package.json +1 -1
  26. package/icon-menu-taon.svg +15 -15
  27. package/lib/base-classes/base-class.d.ts +8 -1
  28. package/lib/base-classes/base-class.js +20 -2
  29. package/lib/base-classes/base-class.js.map +1 -1
  30. package/lib/base-classes/base-controller.d.ts +57 -5
  31. package/lib/base-classes/base-controller.js +83 -12
  32. package/lib/base-classes/base-controller.js.map +1 -1
  33. package/lib/base-classes/base-crud-controller.d.ts +5 -4
  34. package/lib/base-classes/base-crud-controller.js +16 -4
  35. package/lib/base-classes/base-crud-controller.js.map +1 -1
  36. package/lib/base-classes/base-middleware.d.ts +2 -2
  37. package/lib/base-classes/base-middleware.js +1 -0
  38. package/lib/base-classes/base-middleware.js.map +1 -1
  39. package/lib/base-classes/base-repository.d.ts +3 -0
  40. package/lib/base-classes/base-repository.js +3 -0
  41. package/lib/base-classes/base-repository.js.map +1 -1
  42. package/lib/build-info._auto-generated_.d.ts +1 -1
  43. package/lib/build-info._auto-generated_.js +1 -1
  44. package/lib/config/method-config.d.ts +1 -0
  45. package/lib/config/method-config.js.map +1 -1
  46. package/lib/decorators/classes/controller-config.d.ts +20 -0
  47. package/lib/decorators/classes/controller-config.js +21 -0
  48. package/lib/decorators/classes/controller-config.js.map +1 -0
  49. package/lib/decorators/classes/controller-options.d.ts +16 -0
  50. package/lib/decorators/classes/controller-options.js +20 -0
  51. package/lib/decorators/classes/controller-options.js.map +1 -0
  52. package/lib/decorators/http/http-decorators.d.ts +2 -1
  53. package/lib/decorators/http/http-decorators.js +2 -1
  54. package/lib/decorators/http/http-decorators.js.map +1 -1
  55. package/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  56. package/lib/decorators/http/http-methods-decorators.js +34 -1
  57. package/lib/decorators/http/http-methods-decorators.js.map +1 -1
  58. package/lib/endpoint-context.d.ts +10 -4
  59. package/lib/endpoint-context.js +178 -141
  60. package/lib/endpoint-context.js.map +1 -1
  61. package/lib/env/env.angular-node-app.d.ts +1 -2
  62. package/lib/env/env.angular-node-app.js +3 -4
  63. package/lib/env/env.angular-node-app.js.map +1 -1
  64. package/lib/env/env.docs-webapp.d.ts +1 -2
  65. package/lib/env/env.docs-webapp.js +3 -4
  66. package/lib/env/env.docs-webapp.js.map +1 -1
  67. package/lib/env/env.electron-app.d.ts +1 -2
  68. package/lib/env/env.electron-app.js +3 -4
  69. package/lib/env/env.electron-app.js.map +1 -1
  70. package/lib/env/env.mobile-app.d.ts +1 -2
  71. package/lib/env/env.mobile-app.js +3 -4
  72. package/lib/env/env.mobile-app.js.map +1 -1
  73. package/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -2
  74. package/lib/env/env.npm-lib-and-cli-tool.js +3 -4
  75. package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
  76. package/lib/env/env.vscode-plugin.d.ts +1 -2
  77. package/lib/env/env.vscode-plugin.js +3 -4
  78. package/lib/env/env.vscode-plugin.js.map +1 -1
  79. package/lib/get-response-value.d.ts +1 -1
  80. package/lib/get-response-value.js +0 -4
  81. package/lib/get-response-value.js.map +1 -1
  82. package/lib/helpers/taon-helpers.d.ts +1 -0
  83. package/lib/helpers/taon-helpers.js +6 -0
  84. package/lib/helpers/taon-helpers.js.map +1 -1
  85. package/lib/index.d.ts +4 -0
  86. package/lib/index.js +13 -2
  87. package/lib/index.js.map +1 -1
  88. package/lib/models.d.ts +4 -10
  89. package/lib/models.js +5 -23
  90. package/lib/models.js.map +1 -1
  91. package/lib/realtime/realtime-client.d.ts +18 -14
  92. package/lib/realtime/realtime-client.js +33 -25
  93. package/lib/realtime/realtime-client.js.map +1 -1
  94. package/lib/realtime/realtime-server.d.ts +28 -3
  95. package/lib/realtime/realtime-server.js +28 -2
  96. package/lib/realtime/realtime-server.js.map +1 -1
  97. package/lib/realtime/realtime.models.d.ts +15 -2
  98. package/lib/ui/index.js +2 -2
  99. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  100. package/package.json +1 -1
  101. package/websql/README.md +24 -24
  102. package/websql/fesm2022/taon.mjs +306 -91
  103. package/websql/fesm2022/taon.mjs.map +1 -1
  104. package/websql/lib/base-classes/base-class.d.ts +8 -1
  105. package/websql/lib/base-classes/base-controller.d.ts +56 -4
  106. package/websql/lib/base-classes/base-crud-controller.d.ts +5 -4
  107. package/websql/lib/base-classes/base-middleware.d.ts +2 -2
  108. package/websql/lib/base-classes/base-repository.d.ts +3 -0
  109. package/websql/lib/config/method-config.d.ts +1 -0
  110. package/websql/lib/decorators/http/http-decorators.d.ts +2 -1
  111. package/websql/lib/decorators/http/http-methods-decorators.d.ts +35 -4
  112. package/websql/lib/endpoint-context.d.ts +10 -4
  113. package/websql/lib/get-response-value.d.ts +1 -1
  114. package/websql/lib/helpers/taon-helpers.d.ts +1 -0
  115. package/websql/lib/index.d.ts +4 -0
  116. package/websql/lib/models.d.ts +4 -10
  117. package/websql/lib/realtime/realtime-client.d.ts +18 -14
  118. package/websql/lib/realtime/realtime-server.d.ts +28 -3
  119. package/websql/lib/realtime/realtime.models.d.ts +15 -2
  120. package/websql/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import * as coreHelpers from 'tnp-core/browser';
3
- import { _, Utils, Helpers, UtilsOs, CoreModels, crossPlatformPath } from 'tnp-core/browser';
3
+ import { _, Utils, Helpers, UtilsOs, CoreModels, crossPlatformPath, UtilsTerminal } from 'tnp-core/browser';
4
4
  import { __decorate, __metadata, __param } from 'tslib';
5
5
  import { SYMBOL, CLASS } from 'typescript-class-helpers/browser';
6
6
  import { OrignalClassKey, Table } from 'taon-typeorm/browser';
@@ -9,7 +9,7 @@ import * as i0 from '@angular/core';
9
9
  import { InjectionToken, inject as inject$1, Injectable } from '@angular/core';
10
10
  import axios from 'axios';
11
11
  import { JSON10 } from 'json10/browser';
12
- import { Models as Models$1, Resource, RestHeaders, Mapping } from 'ng2-rest/browser';
12
+ import { RestResponseWrapper, Models as Models$1, Resource, RestHeaders, Mapping, HttpResponseError } from 'ng2-rest/browser';
13
13
  import { Observable, from, Subject } from 'rxjs';
14
14
  import { config } from 'tnp-config/browser';
15
15
  import * as JSON5 from 'json5';
@@ -488,9 +488,26 @@ class BaseClass {
488
488
  async _() { }
489
489
  //#endregion
490
490
  //#region clone
491
- clone(override) {
491
+ /**
492
+ *
493
+ * @param overrideObjOrFn if object is provided it will override values in cloned object,
494
+ * if function is provided it will be called with old cloned values and should return
495
+ * object with values to override
496
+ * @returns cloned instance of the class
497
+ */
498
+ clone(overrideObjOrFn) {
499
+ if (_.isString(overrideObjOrFn)) {
500
+ console.log(overrideObjOrFn);
501
+ throw new Error('String is not supported as .clone() method argument');
502
+ }
492
503
  const classFn = ClassHelpers.getClassFnFromObject(this);
493
- return cloneObj(override, classFn);
504
+ if (_.isFunction(overrideObjOrFn)) {
505
+ // console.log('clone with fn');
506
+ const oldValues = (_.cloneDeep(this) || {});
507
+ return cloneObj(overrideObjOrFn(oldValues), classFn);
508
+ }
509
+ // console.log('clone normal');
510
+ return cloneObj(overrideObjOrFn, classFn);
494
511
  }
495
512
  }
496
513
 
@@ -703,10 +720,10 @@ class BaseAngularsService {
703
720
  return currentContext ? currentContext.getClass(ctor) : void 0;
704
721
  });
705
722
  }
706
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
707
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService }); }
723
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
724
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService }); }
708
725
  }
709
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService, decorators: [{
726
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, decorators: [{
710
727
  type: Injectable
711
728
  }], ctorParameters: () => [] });
712
729
 
@@ -1208,9 +1225,6 @@ const getResponseValue = (response, options) => {
1208
1225
  /* */
1209
1226
  /* */
1210
1227
  /* */
1211
- /* */
1212
- /* */
1213
- /* */
1214
1228
  return (void 0);
1215
1229
  };
1216
1230
 
@@ -1231,6 +1245,12 @@ var TaonHelpers;
1231
1245
  return p && typeof p === 'string' && p.trim() !== '';
1232
1246
  };
1233
1247
  //#endregion
1248
+ TaonHelpers.firstStringOrElemFromArray = (stringOrArrayOfString) => {
1249
+ if (Array.isArray(stringOrArrayOfString)) {
1250
+ return _.first(stringOrArrayOfString);
1251
+ }
1252
+ return stringOrArrayOfString;
1253
+ };
1234
1254
  //#region try transform params
1235
1255
  TaonHelpers.tryTransformParam = param => {
1236
1256
  if (typeof param === 'string') {
@@ -1354,6 +1374,9 @@ var TaonHelpers;
1354
1374
  //#endregion
1355
1375
  })(TaonHelpers || (TaonHelpers = {}));
1356
1376
 
1377
+ // ! TODO make it as a nice way to wrap normal request
1378
+ class TaonRestResponseWrapper extends RestResponseWrapper {
1379
+ }
1357
1380
  var Models;
1358
1381
  (function (Models) {
1359
1382
  //#region models / class types
@@ -1411,25 +1434,6 @@ var Models;
1411
1434
  let Http;
1412
1435
  (function (Http) {
1413
1436
  Http.Rest = Models$1;
1414
- class Errors {
1415
- constructor(message, code = 400) {
1416
- this.message = message;
1417
- this.code = code;
1418
- this.toString = () => {
1419
- return this.message;
1420
- };
1421
- }
1422
- static create(message, code = 400) {
1423
- return new Errors(message, code);
1424
- }
1425
- static entityNotFound(entity) {
1426
- return Errors.create(`Entity ${ClassHelpers.getName(entity)} not found`);
1427
- }
1428
- static custom(message, code = 400) {
1429
- return Errors.create(message, code);
1430
- }
1431
- }
1432
- Http.Errors = Errors;
1433
1437
  /* */
1434
1438
  /* */
1435
1439
  /* */
@@ -1539,6 +1543,14 @@ class RealtimeSubsManager {
1539
1543
 
1540
1544
  //#region imports
1541
1545
  //#endregion
1546
+ /**
1547
+ * Client for realtime communication
1548
+ * you can listen to:
1549
+ * - entity changes (any property in table changed)
1550
+ * - entity custom property changes (specific property changed)
1551
+ * - entity table changes (new instance added, instance removed)
1552
+ * - custom events
1553
+ */
1542
1554
  class RealtimeClient {
1543
1555
  constructor(core) {
1544
1556
  this.core = core;
@@ -1612,20 +1624,32 @@ class RealtimeClient {
1612
1624
  //#endregion
1613
1625
  //#region methods & getters / listen changes entity
1614
1626
  /**
1627
+ * Usage:
1628
+ * myContext.realtimeClient.listenChangesEntity(myEntityInstance);
1629
+ *
1630
+ *
1615
1631
  * Changes trigger on backend needs to be done manually.. example code:
1616
1632
  *
1617
- * ...
1618
- * Context.Realtime.Server.TrigggerEntityChanges(myEntityInstance);
1633
+ * myContext.realtimeServer.triggerEntityChanges(myEntityInstance);
1619
1634
  * ...
1620
1635
  */
1621
- listenChangesEntity(entityClassFn, idOrUniqValue, options) {
1636
+ listenChangesEntity(entityClassFnOrObj, options) {
1622
1637
  options = options || {};
1638
+ if (_.isObject(entityClassFnOrObj)) {
1639
+ const orgObj = entityClassFnOrObj;
1640
+ entityClassFnOrObj =
1641
+ ClassHelpers.getClassFnFromObject(entityClassFnOrObj);
1642
+ const uniqueKey = ClassHelpers.getUniqueKey(entityClassFnOrObj);
1643
+ if (uniqueKey) {
1644
+ options.idOrUniqValue = orgObj[uniqueKey];
1645
+ }
1646
+ }
1623
1647
  //#region parameters validation
1624
1648
  const { property, customEvent } = options;
1625
- const className = !customEvent && ClassHelpers.getName(entityClassFn);
1649
+ const className = !customEvent && ClassHelpers.getName(entityClassFnOrObj);
1626
1650
  if (_.isString(property)) {
1627
1651
  if (property.trim() === '') {
1628
- throw new Error(`[Taon][listenChangesEntity.. incorect property '' for ${className}`);
1652
+ throw new Error(`[Taon][listenChangesEntity.. incorrect property '' for ${className}`);
1629
1653
  }
1630
1654
  }
1631
1655
  //#endregion
@@ -1650,8 +1674,8 @@ to use socket realtime connection;
1650
1674
  }
1651
1675
  else {
1652
1676
  roomName = _.isString(property)
1653
- ? Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, idOrUniqValue)
1654
- : Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, idOrUniqValue);
1677
+ ? Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, options.idOrUniqValue)
1678
+ : Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, options.idOrUniqValue);
1655
1679
  }
1656
1680
  const roomSubOptions = {
1657
1681
  core: this.core,
@@ -1674,32 +1698,20 @@ to use socket realtime connection;
1674
1698
  }
1675
1699
  //#endregion
1676
1700
  //#region listen changes entity table
1701
+ /**
1702
+ * Listen changes entity table
1703
+ * Example: for pagination, lists update ...
1704
+ */
1677
1705
  listenChangesEntityTable(entityClassFn) {
1678
1706
  const className = ClassHelpers.getName(entityClassFn);
1679
- return this.listenChangesEntity(entityClassFn, void 0, {
1707
+ return this.listenChangesEntity(entityClassFn, {
1680
1708
  customEvent: Symbols.REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className),
1681
1709
  });
1682
1710
  }
1683
1711
  //#endregion
1684
- //#region listen change entity object
1685
- /**
1686
- * Changes trigger on backend needs to be done manually.. example code:
1687
- *
1688
- * ...
1689
- * Context.Realtime.Server.TrigggerEntityChanges(myEntityInstance);
1690
- * // or
1691
- * Context.Realtime.Server.TrigggerEntityPropertyChanges(myEntityInstance,{ property: 'geolocationX' });
1692
- * ...
1693
- */
1694
- listenChangesEntityObj(entity, options) {
1695
- const classFn = ClassHelpers.getClassFnFromObject(entity);
1696
- const uniqueKey = ClassHelpers.getUniqueKey(classFn);
1697
- return this.listenChangesEntity(classFn, entity[uniqueKey], options);
1698
- }
1699
- //#endregion
1700
1712
  //#region listen changes custom event
1701
1713
  listenChangesCustomEvent(customEvent) {
1702
- return this.listenChangesEntity(void 0, void 0, {
1714
+ return this.listenChangesEntity(void 0, {
1703
1715
  customEvent,
1704
1716
  });
1705
1717
  }
@@ -1725,6 +1737,17 @@ to use socket realtime connection;
1725
1737
  //#region imports
1726
1738
  /* */
1727
1739
  //#endregion
1740
+ /**
1741
+ * Server for realtime communication
1742
+ * you can trigger:
1743
+ * - entity changes (any property in table changed)
1744
+ * - entity custom property changes (specific property changed)
1745
+ * - entity table changes (new instance added, instance removed)
1746
+ * - custom events
1747
+ *
1748
+ * and also listen to:
1749
+ * - custom events from yourself
1750
+ */
1728
1751
  class RealtimeServer {
1729
1752
  // private jobs = {};
1730
1753
  constructor(core) {
@@ -1972,7 +1995,12 @@ class RealtimeServer {
1972
1995
  //#endregion
1973
1996
  //#region entity changes
1974
1997
  //#region methods & getters / trigger entity changes
1975
- triggerEntityChanges(entityObjOrClass, idToTrigger) {
1998
+ triggerEntityChanges(entityObjOrClass,
1999
+ /**
2000
+ * value of unique key property of entity instance
2001
+ * (this value is not needed if entityObjOrClass is instance of entity)
2002
+ */
2003
+ idToTrigger) {
1976
2004
  if (this.core.ctx.disabledRealtime) {
1977
2005
  const className = ClassHelpers.getName(entityObjOrClass);
1978
2006
  console.warn(`[Taon][TriggerEntityChanges] Entity "${className}' is not realtime`);
@@ -1982,7 +2010,17 @@ class RealtimeServer {
1982
2010
  }
1983
2011
  //#endregion
1984
2012
  //#region methods & getters / trigger entity property changes
1985
- triggerEntityPropertyChanges(entityObjOrClass, property, idToTrigger) {
2013
+ triggerEntityPropertyChanges(entityObjOrClass,
2014
+ /**
2015
+ * property name or array of property names that changed
2016
+ * for entity instance
2017
+ */
2018
+ property,
2019
+ /**
2020
+ * value of unique key property of entity instance
2021
+ * (this value is not needed if entityObjOrClass is instance of entity)
2022
+ */
2023
+ idToTrigger) {
1986
2024
  if (this.core.ctx.disabledRealtime) {
1987
2025
  const className = ClassHelpers.getName(entityObjOrClass);
1988
2026
  console.warn(`[Taon][TriggerEntityPropertyChanges][property=${property}] Entity "${className}' is not realtime`);
@@ -2760,6 +2798,12 @@ class EndpointContext {
2760
2798
  }
2761
2799
  return this.config?.logs === true;
2762
2800
  }
2801
+ get logRoutes() {
2802
+ if (_.isObject(this.config?.logs)) {
2803
+ return !!this.config.logs.routes;
2804
+ }
2805
+ return this.config?.logs === true;
2806
+ }
2763
2807
  get logDb() {
2764
2808
  if (_.isObject(this.config?.logs)) {
2765
2809
  return !!this.config.logs.db;
@@ -2783,21 +2827,15 @@ class EndpointContext {
2783
2827
  this.originalConfig = originalConfig;
2784
2828
  this.configFn = configFn;
2785
2829
  this.cloneOptions = cloneOptions;
2786
- //#region static
2830
+ //#endregion
2831
+ //#endregion
2832
+ //#region fields
2833
+ //#region fields / use mariadb mysql in docker
2787
2834
  /**
2788
2835
  * JUST FOR TESTING PURPOSES
2789
2836
  */
2790
2837
  this.USE_MARIADB_MYSQL_IN_DOCKER = false;
2791
2838
  //#endregion
2792
- // public static findForTraget(classFnOrObject: any): EndpointContext {
2793
- // const obj = ClassHelpers.getClassFnFromObject(classFnOrObject) || {};
2794
- // return (
2795
- // classFnOrObject[Symbols.ctxInClassOrClassObj] ||
2796
- // obj[Symbols.ctxInClassOrClassObj]
2797
- // );
2798
- // }
2799
- //#endregion
2800
- //#region fields
2801
2839
  //#region fields / flags
2802
2840
  this.disabledRealtime = false;
2803
2841
  /**
@@ -2806,8 +2844,12 @@ class EndpointContext {
2806
2844
  */
2807
2845
  this.inited = false;
2808
2846
  //#endregion
2847
+ //#region fields / db migrations
2809
2848
  this.dbMigrations = new ContextDbMigrations(this);
2849
+ //#endregion
2850
+ //#region fields / local instance obj symbol
2810
2851
  this.localInstaceObjSymbol = Symbol('localInstaceObjSymbol');
2852
+ //#endregion
2811
2853
  //#region fields / all instances of classes from context
2812
2854
  /**
2813
2855
  * all instances of classes from context
@@ -2824,7 +2866,9 @@ class EndpointContext {
2824
2866
  //#region fields / active routes
2825
2867
  this.activeRoutes = [];
2826
2868
  //#endregion
2869
+ //#region fields / skip writing server routes
2827
2870
  this.skipWritingServerRoutes = false;
2871
+ //#endregion
2828
2872
  //#region fields / types from contexts
2829
2873
  this.injectableTypesfromContexts = [
2830
2874
  Models.ClassType.CONTROLLER,
@@ -2835,11 +2879,12 @@ class EndpointContext {
2835
2879
  Models.ClassType.MIGRATION,
2836
2880
  ];
2837
2881
  //#endregion
2882
+ //#region fields / all types from contexts
2838
2883
  this.allTypesfromContexts = [
2839
2884
  ...this.injectableTypesfromContexts,
2840
2885
  Models.ClassType.ENTITY,
2841
2886
  ];
2842
- // public __contextForControllerInstanceAccess?: EndpointContext;
2887
+ //#endregion
2843
2888
  //#region fields / express app
2844
2889
  this.expressApp = {};
2845
2890
  //#endregion
@@ -3772,7 +3817,7 @@ class EndpointContext {
3772
3817
  return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
3773
3818
  }
3774
3819
  //#endregion
3775
- //#region port from uri
3820
+ //#region methods & getters / port from uri
3776
3821
  get uriPort() {
3777
3822
  if (!this.uri?.origin?.includes('localhost')) {
3778
3823
  return this.config?.hostPortNumber?.toString();
@@ -3793,12 +3838,15 @@ class EndpointContext {
3793
3838
  return this.uriProtocol === 'https:';
3794
3839
  }
3795
3840
  //#endregion
3796
- //#region methods & getters / public assets
3841
+ //#region methods & getters / is remote host
3842
+ /**
3843
+ * Check if context is for remote only
3844
+ */
3797
3845
  get isRemoteHost() {
3798
3846
  return !!this.cloneOptions?.useAsRemoteContext;
3799
3847
  }
3800
3848
  //#endregion
3801
- //#region methods & getters / public assets
3849
+ //#region methods & getters / context name
3802
3850
  /**
3803
3851
  * ipc/udp needs this
3804
3852
  */
@@ -3807,7 +3855,7 @@ class EndpointContext {
3807
3855
  return this.config?.contextName || this.originalConfig?.contextName;
3808
3856
  }
3809
3857
  //#endregion
3810
- //#region methods & getters / public assets
3858
+ //#region methods & getters / context name for communication
3811
3859
  /**
3812
3860
  * ipc/udp needs this
3813
3861
  */
@@ -3826,7 +3874,7 @@ class EndpointContext {
3826
3874
  return contextName;
3827
3875
  }
3828
3876
  //#endregion
3829
- //#region methods & getters / public assets
3877
+ //#region methods & getters / get context type
3830
3878
  /**
3831
3879
  * Check context type
3832
3880
  */
@@ -3870,8 +3918,8 @@ class EndpointContext {
3870
3918
  return this.config.host;
3871
3919
  }
3872
3920
  //#endregion
3873
- //#region methods & getters / host
3874
- get orgin() {
3921
+ //#region methods & getters / origin
3922
+ get origin() {
3875
3923
  return this.uri?.origin;
3876
3924
  }
3877
3925
  //#endregion
@@ -4255,9 +4303,7 @@ class EndpointContext {
4255
4303
  //#endregion
4256
4304
  //#region methods & getters / write active routes
4257
4305
  writeActiveRoutes() {
4258
- if (this.isRemoteHost ||
4259
- this.isRunOrRevertOnlyMigrationAppStart ||
4260
- this.skipWritingServerRoutes) {
4306
+ if (this.isRemoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
4261
4307
  return;
4262
4308
  }
4263
4309
  // const contexts: EndpointContext[] = [this];
@@ -4297,6 +4343,7 @@ class EndpointContext {
4297
4343
  /* */
4298
4344
  /* */
4299
4345
  /* */
4346
+ /* */
4300
4347
  }
4301
4348
  //#endregion
4302
4349
  //#region methods & getters / middlewares
@@ -4775,6 +4822,41 @@ class EndpointContext {
4775
4822
  };
4776
4823
  }
4777
4824
  //#endregion
4825
+ //#region methods & getters / send error
4826
+ sendError(res, error, req, expressPath) {
4827
+ /* */
4828
+ /* */
4829
+ /* */
4830
+ /* */
4831
+ /* */
4832
+ /* */
4833
+ /* */
4834
+ /* */
4835
+ /* */
4836
+ /* */
4837
+ /* */
4838
+ /* */
4839
+ /* */
4840
+ /* */
4841
+ /* */
4842
+ /* */
4843
+ /* */
4844
+ /* */
4845
+ /* */
4846
+ /* */
4847
+ /* */
4848
+ /* */
4849
+ /* */
4850
+ /* */
4851
+ /* */
4852
+ /* */
4853
+ /* */
4854
+ /* */
4855
+ /* */
4856
+ /* */
4857
+ return (void 0);
4858
+ }
4859
+ //#endregion
4778
4860
  //#region methods & getters / init client
4779
4861
  /**
4780
4862
  * client can be browser or nodejs (when remote host)
@@ -4809,8 +4891,8 @@ class EndpointContext {
4809
4891
  });
4810
4892
  //#endregion
4811
4893
  // : { received: any; /* Rest<any, any> */ }
4812
- this.logHttp &&
4813
- console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
4894
+ // this.logHttp &&
4895
+ // console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
4814
4896
  // console.log('INITING', methodConfig); // TODO inject in static
4815
4897
  //#region resolve storage
4816
4898
  // TODO not a good idea
@@ -5655,6 +5737,7 @@ class BaseInjector {
5655
5737
  }
5656
5738
  }
5657
5739
 
5740
+ //#endregion
5658
5741
  /**
5659
5742
  * TODO
5660
5743
  * - global provider available in all contexts
@@ -5887,6 +5970,9 @@ let BaseRepository = class BaseRepository extends BaseCustomRepository {
5887
5970
  /* */
5888
5971
  return (void 0);
5889
5972
  }
5973
+ /**
5974
+ * @deprecated use bulkSave instead
5975
+ */
5890
5976
  async bulkCreate(items, options) {
5891
5977
  return this.bulkSave(items, options);
5892
5978
  }
@@ -6414,7 +6500,7 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
6414
6500
  else {
6415
6501
  options = { pathOrOptions, pathIsGlobal };
6416
6502
  }
6417
- const { overrideContentType, overrideResponseType, middlewares } = options;
6503
+ const { overrideContentType, overrideResponseType, overrideExpressSendAsHtml, middlewares, } = options;
6418
6504
  methodConfig.methodName = propertyKey;
6419
6505
  methodConfig.middlewares = middlewares;
6420
6506
  methodConfig.type = method;
@@ -6439,12 +6525,44 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
6439
6525
  methodConfig.global = pathIsGlobal;
6440
6526
  methodConfig.contentType = overrideContentType;
6441
6527
  methodConfig.responseType = overrideResponseType;
6528
+ methodConfig.overrideExpressSendAsHtml = overrideExpressSendAsHtml;
6442
6529
  };
6443
6530
  function GET(pathOrOptions, pathIsGlobal = false) {
6444
6531
  return function (target, propertyKey, descriptor) {
6445
6532
  metaReq('get', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
6446
6533
  };
6447
6534
  }
6535
+ /**
6536
+ * Method for sending html website from text
6537
+ * Example
6538
+ *
6539
+ * ```ts
6540
+ * ...
6541
+ * // in your taon controller
6542
+ * ..Taon.Http.HTML()
6543
+ * sendHtmlDummyWebsite(): Taon.ResponseHtml {
6544
+ * return `
6545
+ <html>
6546
+ <head>
6547
+ <title>Dummy website</title>
6548
+ </head>
6549
+ <body>
6550
+ <h1>This is dummy website</h1>
6551
+ <p>Served as HTML string from Taon controller method</p>
6552
+ </body>
6553
+ </html>
6554
+ * `; *
6555
+ * }
6556
+ * ...
6557
+ * ```
6558
+ */
6559
+ function HTML(pathOrOptions) {
6560
+ return function (target, propertyKey, descriptor) {
6561
+ const opt = pathOrOptions;
6562
+ opt.overrideExpressSendAsHtml = true;
6563
+ metaReq('get', opt, target, propertyKey, descriptor, pathOrOptions, opt.pathIsGlobal);
6564
+ };
6565
+ }
6448
6566
  function HEAD(pathOrOptions, pathIsGlobal = false) {
6449
6567
  return function (target, propertyKey, descriptor) {
6450
6568
  metaReq('head', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
@@ -6520,7 +6638,7 @@ let BaseController = class BaseController extends BaseInjector {
6520
6638
  */
6521
6639
  async afterAllCtxInited(options) { }
6522
6640
  //#region upload form data to server
6523
- uploadFormDataToServer(formData) {
6641
+ uploadFormDataToServer(formData, queryParams) {
6524
6642
  /* */
6525
6643
  /* */
6526
6644
  /* */
@@ -6555,11 +6673,13 @@ let BaseController = class BaseController extends BaseInjector {
6555
6673
  * Hook after file is uploaded
6556
6674
  * through `uploadFormDataToServer` or `uploadLocalFileToServer`
6557
6675
  */
6558
- afterFileUploadAction(file) {
6676
+ afterFileUploadAction(file, queryParams) {
6559
6677
  // empty
6560
6678
  }
6561
6679
  //#region upload local file to server
6562
- async uploadLocalFileToServer(absFilePath, options) {
6680
+ async uploadLocalFileToServer(absFilePath, options, queryParams) {
6681
+ /* */
6682
+ /* */
6563
6683
  /* */
6564
6684
  /* */
6565
6685
  /* */
@@ -6574,6 +6694,75 @@ let BaseController = class BaseController extends BaseInjector {
6574
6694
  /* */
6575
6695
  return (void 0);
6576
6696
  }
6697
+ //#endregion
6698
+ // async check() {
6699
+ // await this._waitForProperStatusChange({
6700
+ // request: () => this.uploadFormDataToServer(void 0, void 0).request(),
6701
+ // statusCheck: resp => resp.body.json[0].ok,
6702
+ // });
6703
+ // }
6704
+ /**
6705
+ * Easy way to wait for status change with http (1s default) pooling.
6706
+ *
6707
+ * example (in sub class):
6708
+ * ```ts
6709
+ async check() {
6710
+ await this.waitForProperStatusChange({
6711
+ request: () => this.uploadFormDataToServer(void 0, void 0).request(),
6712
+ statusCheck: resp => resp.body.json[0].ok,
6713
+ });
6714
+ }
6715
+ * ```
6716
+ */
6717
+ async _waitForProperStatusChange(options) {
6718
+ const poolingInterval = options.poolingInterval || 1000;
6719
+ const taonRequest = options.request;
6720
+ let maxTries = options.maxTries || Number.POSITIVE_INFINITY;
6721
+ let i = 0;
6722
+ let httpErrorsCount = 0;
6723
+ while (true) {
6724
+ await UtilsTerminal.waitMilliseconds(poolingInterval);
6725
+ try {
6726
+ const resp = await taonRequest({
6727
+ reqIndexNum: i,
6728
+ httpErrorsCount,
6729
+ });
6730
+ if (options.statusCheck && options.statusCheck(resp)) {
6731
+ return;
6732
+ }
6733
+ }
6734
+ catch (error) {
6735
+ httpErrorsCount++;
6736
+ if (options.loopRequestsOnBackendError) {
6737
+ const isProperTaonError = error instanceof HttpResponseError &&
6738
+ error.body.json[CoreModels.TaonHttpErrorCustomProp];
6739
+ const isHttpError = error instanceof HttpResponseError && !isProperTaonError;
6740
+ const isUnknownError = !(error instanceof HttpResponseError);
6741
+ const resBool = await options.loopRequestsOnBackendError({
6742
+ taonError: isProperTaonError ? error : void 0,
6743
+ unknownHttpError: isHttpError ? error : void 0,
6744
+ unknownError: isUnknownError ? error : void 0,
6745
+ reqIndexNum: i,
6746
+ httpErrorsCount,
6747
+ });
6748
+ if (resBool) {
6749
+ i++;
6750
+ continue;
6751
+ }
6752
+ else {
6753
+ return;
6754
+ }
6755
+ }
6756
+ if (httpErrorsCount >
6757
+ (options.allowedHttpErrors || Number.POSITIVE_INFINITY)) {
6758
+ throw new Error(`Too many http errors (${httpErrorsCount}) for "${options.actionName}".`);
6759
+ }
6760
+ }
6761
+ if (i++ > maxTries) {
6762
+ throw new Error(`Timeout waiting for "${options.actionName}" to be finished. Waited for ${maxTries} seconds`);
6763
+ }
6764
+ }
6765
+ }
6577
6766
  };
6578
6767
  __decorate([
6579
6768
  POST({
@@ -6584,8 +6773,9 @@ __decorate([
6584
6773
  }),
6585
6774
  }),
6586
6775
  __param(0, Body()),
6776
+ __param(1, Query()),
6587
6777
  __metadata("design:type", Function),
6588
- __metadata("design:paramtypes", [FormData]),
6778
+ __metadata("design:paramtypes", [FormData, Object]),
6589
6779
  __metadata("design:returntype", Object)
6590
6780
  ], BaseController.prototype, "uploadFormDataToServer", null);
6591
6781
  BaseController = __decorate([
@@ -6617,7 +6807,7 @@ let BaseCrudController = class BaseCrudController extends BaseController {
6617
6807
  else {
6618
6808
  Helpers.error(`Entity class not provided for controller ${ClassHelpers.getName(this)}.
6619
6809
 
6620
- Please provide entity as class propery entityClassFn:
6810
+ Please provide entity as class property entityClassFn:
6621
6811
 
6622
6812
  class ${ClassHelpers.getName(this)} extends BaseCrudController<Entity> {
6623
6813
  // ...
@@ -6772,8 +6962,17 @@ let BaseCrudController = class BaseCrudController extends BaseController {
6772
6962
  return (void 0);
6773
6963
  }
6774
6964
  //#endregion
6965
+ //#region bulk delete
6966
+ clearTable() {
6967
+ /* */
6968
+ /* */
6969
+ /* */
6970
+ /* */
6971
+ return (void 0);
6972
+ }
6973
+ //#endregion
6775
6974
  //#region create
6776
- create(item) {
6975
+ save(item) {
6777
6976
  /* */
6778
6977
  /* */
6779
6978
  /* */
@@ -6850,7 +7049,7 @@ __decorate([
6850
7049
  DELETE(),
6851
7050
  __param(0, Query(`id`)),
6852
7051
  __metadata("design:type", Function),
6853
- __metadata("design:paramtypes", [Number]),
7052
+ __metadata("design:paramtypes", [Object]),
6854
7053
  __metadata("design:returntype", Object)
6855
7054
  ], BaseCrudController.prototype, "deleteById", null);
6856
7055
  __decorate([
@@ -6860,13 +7059,19 @@ __decorate([
6860
7059
  __metadata("design:paramtypes", [Array]),
6861
7060
  __metadata("design:returntype", Object)
6862
7061
  ], BaseCrudController.prototype, "bulkDelete", null);
7062
+ __decorate([
7063
+ DELETE(),
7064
+ __metadata("design:type", Function),
7065
+ __metadata("design:paramtypes", []),
7066
+ __metadata("design:returntype", Object)
7067
+ ], BaseCrudController.prototype, "clearTable", null);
6863
7068
  __decorate([
6864
7069
  POST(),
6865
7070
  __param(0, Body()),
6866
7071
  __metadata("design:type", Function),
6867
7072
  __metadata("design:paramtypes", [Object]),
6868
7073
  __metadata("design:returntype", Object)
6869
- ], BaseCrudController.prototype, "create", null);
7074
+ ], BaseCrudController.prototype, "save", null);
6870
7075
  __decorate([
6871
7076
  POST(),
6872
7077
  __param(0, Body()),
@@ -7132,6 +7337,7 @@ var Http;
7132
7337
  Http.DELETE = DELETE;
7133
7338
  Http.PATCH = PATCH;
7134
7339
  Http.HEAD = HEAD;
7340
+ Http.HTML = HTML;
7135
7341
  Http.Response = Models$1.HttpResponse;
7136
7342
  let Param;
7137
7343
  (function (Param) {
@@ -7146,6 +7352,16 @@ var Http;
7146
7352
  // TODO export all things
7147
7353
  var Taon;
7148
7354
  (function (Taon) {
7355
+ Taon.error = (opt) => {
7356
+ throw () => {
7357
+ if (typeof opt === 'string') {
7358
+ opt = {
7359
+ message: opt
7360
+ };
7361
+ }
7362
+ return opt;
7363
+ };
7364
+ };
7149
7365
  Taon.Http = Http;
7150
7366
  Taon.Base = Base;
7151
7367
  Taon.getResponseValue = getResponseValue;
@@ -7198,5 +7414,5 @@ var Taon;
7198
7414
  * Generated bundle index. Do not edit.
7199
7415
  */
7200
7416
 
7201
- export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseFileUploadMiddleware, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, ContextsEndpointStorage, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
7417
+ export { BaseClass, BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseFileUploadMiddleware, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, ContextsEndpointStorage, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
7202
7418
  //# sourceMappingURL=taon.mjs.map