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/websql';
3
- import { _, Utils, UtilsMigrations, Helpers, UtilsOs, crossPlatformPath, CoreModels } from 'tnp-core/websql';
3
+ import { _, Utils, UtilsMigrations, Helpers, UtilsOs, crossPlatformPath, CoreModels, UtilsTerminal } from 'tnp-core/websql';
4
4
  import { __decorate, __metadata, __param } from 'tslib';
5
5
  import * as tsorm from 'taon-typeorm/websql';
6
6
  import { OrignalClassKey, Entity, Table, TableIndex, EventSubscriber, DataSource } from 'taon-typeorm/websql';
@@ -10,7 +10,7 @@ import * as i0 from '@angular/core';
10
10
  import { InjectionToken, inject as inject$1, Injectable } from '@angular/core';
11
11
  import axios from 'axios';
12
12
  import { JSON10 } from 'json10/websql';
13
- import { Models as Models$1, Resource, RestHeaders, Mapping } from 'ng2-rest/websql';
13
+ import { RestResponseWrapper, Models as Models$1, Resource, RestHeaders, Mapping, HttpResponseError } from 'ng2-rest/websql';
14
14
  import { Observable, Subject, from } from 'rxjs';
15
15
  import { config } from 'tnp-config/websql';
16
16
  import * as JSON5 from 'json5';
@@ -596,9 +596,26 @@ class BaseClass {
596
596
  async _() { }
597
597
  //#endregion
598
598
  //#region clone
599
- clone(override) {
599
+ /**
600
+ *
601
+ * @param overrideObjOrFn if object is provided it will override values in cloned object,
602
+ * if function is provided it will be called with old cloned values and should return
603
+ * object with values to override
604
+ * @returns cloned instance of the class
605
+ */
606
+ clone(overrideObjOrFn) {
607
+ if (_.isString(overrideObjOrFn)) {
608
+ console.log(overrideObjOrFn);
609
+ throw new Error('String is not supported as .clone() method argument');
610
+ }
600
611
  const classFn = ClassHelpers.getClassFnFromObject(this);
601
- return cloneObj(override, classFn);
612
+ if (_.isFunction(overrideObjOrFn)) {
613
+ // console.log('clone with fn');
614
+ const oldValues = (_.cloneDeep(this) || {});
615
+ return cloneObj(overrideObjOrFn(oldValues), classFn);
616
+ }
617
+ // console.log('clone normal');
618
+ return cloneObj(overrideObjOrFn, classFn);
602
619
  }
603
620
  }
604
621
 
@@ -823,13 +840,16 @@ class BaseAngularsService {
823
840
  return currentContext ? currentContext.getClass(ctor) : void 0;
824
841
  });
825
842
  }
826
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
827
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService }); }
843
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
844
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService }); }
828
845
  }
829
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BaseAngularsService, decorators: [{
846
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: BaseAngularsService, decorators: [{
830
847
  type: Injectable
831
848
  }], ctorParameters: () => [] });
832
849
 
850
+ // ! TODO make it as a nice way to wrap normal request
851
+ class TaonRestResponseWrapper extends RestResponseWrapper {
852
+ }
833
853
  var Models;
834
854
  (function (Models) {
835
855
  //#region models / class types
@@ -887,25 +907,6 @@ var Models;
887
907
  let Http;
888
908
  (function (Http) {
889
909
  Http.Rest = Models$1;
890
- class Errors {
891
- constructor(message, code = 400) {
892
- this.message = message;
893
- this.code = code;
894
- this.toString = () => {
895
- return this.message;
896
- };
897
- }
898
- static create(message, code = 400) {
899
- return new Errors(message, code);
900
- }
901
- static entityNotFound(entity) {
902
- return Errors.create(`Entity ${ClassHelpers.getName(entity)} not found`);
903
- }
904
- static custom(message, code = 400) {
905
- return Errors.create(message, code);
906
- }
907
- }
908
- Http.Errors = Errors;
909
910
  //#endregion
910
911
  })(Http = Models.Http || (Models.Http = {}));
911
912
  //#endregion
@@ -1294,9 +1295,6 @@ const getResponseValue = (response, options) => {
1294
1295
  resolve(result);
1295
1296
  }
1296
1297
  catch (e) {
1297
- console.error(e);
1298
- console.error('[taon] Error during function call inside controller');
1299
- Helpers.renderError(e);
1300
1298
  reject(e);
1301
1299
  }
1302
1300
  }
@@ -1325,6 +1323,12 @@ var TaonHelpers;
1325
1323
  return p && typeof p === 'string' && p.trim() !== '';
1326
1324
  };
1327
1325
  //#endregion
1326
+ TaonHelpers.firstStringOrElemFromArray = (stringOrArrayOfString) => {
1327
+ if (Array.isArray(stringOrArrayOfString)) {
1328
+ return _.first(stringOrArrayOfString);
1329
+ }
1330
+ return stringOrArrayOfString;
1331
+ };
1328
1332
  //#region try transform params
1329
1333
  TaonHelpers.tryTransformParam = param => {
1330
1334
  if (typeof param === 'string') {
@@ -1548,6 +1552,14 @@ class RealtimeSubsManager {
1548
1552
 
1549
1553
  //#region imports
1550
1554
  //#endregion
1555
+ /**
1556
+ * Client for realtime communication
1557
+ * you can listen to:
1558
+ * - entity changes (any property in table changed)
1559
+ * - entity custom property changes (specific property changed)
1560
+ * - entity table changes (new instance added, instance removed)
1561
+ * - custom events
1562
+ */
1551
1563
  class RealtimeClient {
1552
1564
  constructor(core) {
1553
1565
  this.core = core;
@@ -1621,20 +1633,32 @@ class RealtimeClient {
1621
1633
  //#endregion
1622
1634
  //#region methods & getters / listen changes entity
1623
1635
  /**
1636
+ * Usage:
1637
+ * myContext.realtimeClient.listenChangesEntity(myEntityInstance);
1638
+ *
1639
+ *
1624
1640
  * Changes trigger on backend needs to be done manually.. example code:
1625
1641
  *
1626
- * ...
1627
- * Context.Realtime.Server.TrigggerEntityChanges(myEntityInstance);
1642
+ * myContext.realtimeServer.triggerEntityChanges(myEntityInstance);
1628
1643
  * ...
1629
1644
  */
1630
- listenChangesEntity(entityClassFn, idOrUniqValue, options) {
1645
+ listenChangesEntity(entityClassFnOrObj, options) {
1631
1646
  options = options || {};
1647
+ if (_.isObject(entityClassFnOrObj)) {
1648
+ const orgObj = entityClassFnOrObj;
1649
+ entityClassFnOrObj =
1650
+ ClassHelpers.getClassFnFromObject(entityClassFnOrObj);
1651
+ const uniqueKey = ClassHelpers.getUniqueKey(entityClassFnOrObj);
1652
+ if (uniqueKey) {
1653
+ options.idOrUniqValue = orgObj[uniqueKey];
1654
+ }
1655
+ }
1632
1656
  //#region parameters validation
1633
1657
  const { property, customEvent } = options;
1634
- const className = !customEvent && ClassHelpers.getName(entityClassFn);
1658
+ const className = !customEvent && ClassHelpers.getName(entityClassFnOrObj);
1635
1659
  if (_.isString(property)) {
1636
1660
  if (property.trim() === '') {
1637
- throw new Error(`[Taon][listenChangesEntity.. incorect property '' for ${className}`);
1661
+ throw new Error(`[Taon][listenChangesEntity.. incorrect property '' for ${className}`);
1638
1662
  }
1639
1663
  }
1640
1664
  //#endregion
@@ -1659,8 +1683,8 @@ to use socket realtime connection;
1659
1683
  }
1660
1684
  else {
1661
1685
  roomName = _.isString(property)
1662
- ? Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, idOrUniqValue)
1663
- : Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, idOrUniqValue);
1686
+ ? Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, options.idOrUniqValue)
1687
+ : Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, options.idOrUniqValue);
1664
1688
  }
1665
1689
  const roomSubOptions = {
1666
1690
  core: this.core,
@@ -1683,32 +1707,20 @@ to use socket realtime connection;
1683
1707
  }
1684
1708
  //#endregion
1685
1709
  //#region listen changes entity table
1710
+ /**
1711
+ * Listen changes entity table
1712
+ * Example: for pagination, lists update ...
1713
+ */
1686
1714
  listenChangesEntityTable(entityClassFn) {
1687
1715
  const className = ClassHelpers.getName(entityClassFn);
1688
- return this.listenChangesEntity(entityClassFn, void 0, {
1716
+ return this.listenChangesEntity(entityClassFn, {
1689
1717
  customEvent: Symbols.REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className),
1690
1718
  });
1691
1719
  }
1692
1720
  //#endregion
1693
- //#region listen change entity object
1694
- /**
1695
- * Changes trigger on backend needs to be done manually.. example code:
1696
- *
1697
- * ...
1698
- * Context.Realtime.Server.TrigggerEntityChanges(myEntityInstance);
1699
- * // or
1700
- * Context.Realtime.Server.TrigggerEntityPropertyChanges(myEntityInstance,{ property: 'geolocationX' });
1701
- * ...
1702
- */
1703
- listenChangesEntityObj(entity, options) {
1704
- const classFn = ClassHelpers.getClassFnFromObject(entity);
1705
- const uniqueKey = ClassHelpers.getUniqueKey(classFn);
1706
- return this.listenChangesEntity(classFn, entity[uniqueKey], options);
1707
- }
1708
- //#endregion
1709
1721
  //#region listen changes custom event
1710
1722
  listenChangesCustomEvent(customEvent) {
1711
- return this.listenChangesEntity(void 0, void 0, {
1723
+ return this.listenChangesEntity(void 0, {
1712
1724
  customEvent,
1713
1725
  });
1714
1726
  }
@@ -1734,6 +1746,17 @@ to use socket realtime connection;
1734
1746
  //#region imports
1735
1747
  /* */
1736
1748
  //#endregion
1749
+ /**
1750
+ * Server for realtime communication
1751
+ * you can trigger:
1752
+ * - entity changes (any property in table changed)
1753
+ * - entity custom property changes (specific property changed)
1754
+ * - entity table changes (new instance added, instance removed)
1755
+ * - custom events
1756
+ *
1757
+ * and also listen to:
1758
+ * - custom events from yourself
1759
+ */
1737
1760
  class RealtimeServer {
1738
1761
  // private jobs = {};
1739
1762
  constructor(core) {
@@ -1881,7 +1904,12 @@ class RealtimeServer {
1881
1904
  //#endregion
1882
1905
  //#region entity changes
1883
1906
  //#region methods & getters / trigger entity changes
1884
- triggerEntityChanges(entityObjOrClass, idToTrigger) {
1907
+ triggerEntityChanges(entityObjOrClass,
1908
+ /**
1909
+ * value of unique key property of entity instance
1910
+ * (this value is not needed if entityObjOrClass is instance of entity)
1911
+ */
1912
+ idToTrigger) {
1885
1913
  if (this.core.ctx.disabledRealtime) {
1886
1914
  const className = ClassHelpers.getName(entityObjOrClass);
1887
1915
  console.warn(`[Taon][TriggerEntityChanges] Entity "${className}' is not realtime`);
@@ -1891,7 +1919,17 @@ class RealtimeServer {
1891
1919
  }
1892
1920
  //#endregion
1893
1921
  //#region methods & getters / trigger entity property changes
1894
- triggerEntityPropertyChanges(entityObjOrClass, property, idToTrigger) {
1922
+ triggerEntityPropertyChanges(entityObjOrClass,
1923
+ /**
1924
+ * property name or array of property names that changed
1925
+ * for entity instance
1926
+ */
1927
+ property,
1928
+ /**
1929
+ * value of unique key property of entity instance
1930
+ * (this value is not needed if entityObjOrClass is instance of entity)
1931
+ */
1932
+ idToTrigger) {
1895
1933
  if (this.core.ctx.disabledRealtime) {
1896
1934
  const className = ClassHelpers.getName(entityObjOrClass);
1897
1935
  console.warn(`[Taon][TriggerEntityPropertyChanges][property=${property}] Entity "${className}' is not realtime`);
@@ -2710,6 +2748,12 @@ class EndpointContext {
2710
2748
  }
2711
2749
  return this.config?.logs === true;
2712
2750
  }
2751
+ get logRoutes() {
2752
+ if (_.isObject(this.config?.logs)) {
2753
+ return !!this.config.logs.routes;
2754
+ }
2755
+ return this.config?.logs === true;
2756
+ }
2713
2757
  get logDb() {
2714
2758
  if (_.isObject(this.config?.logs)) {
2715
2759
  return !!this.config.logs.db;
@@ -2733,21 +2777,15 @@ class EndpointContext {
2733
2777
  this.originalConfig = originalConfig;
2734
2778
  this.configFn = configFn;
2735
2779
  this.cloneOptions = cloneOptions;
2736
- //#region static
2780
+ //#endregion
2781
+ //#endregion
2782
+ //#region fields
2783
+ //#region fields / use mariadb mysql in docker
2737
2784
  /**
2738
2785
  * JUST FOR TESTING PURPOSES
2739
2786
  */
2740
2787
  this.USE_MARIADB_MYSQL_IN_DOCKER = false;
2741
2788
  //#endregion
2742
- // public static findForTraget(classFnOrObject: any): EndpointContext {
2743
- // const obj = ClassHelpers.getClassFnFromObject(classFnOrObject) || {};
2744
- // return (
2745
- // classFnOrObject[Symbols.ctxInClassOrClassObj] ||
2746
- // obj[Symbols.ctxInClassOrClassObj]
2747
- // );
2748
- // }
2749
- //#endregion
2750
- //#region fields
2751
2789
  //#region fields / flags
2752
2790
  this.disabledRealtime = false;
2753
2791
  /**
@@ -2756,8 +2794,12 @@ class EndpointContext {
2756
2794
  */
2757
2795
  this.inited = false;
2758
2796
  //#endregion
2797
+ //#region fields / db migrations
2759
2798
  this.dbMigrations = new ContextDbMigrations(this);
2799
+ //#endregion
2800
+ //#region fields / local instance obj symbol
2760
2801
  this.localInstaceObjSymbol = Symbol('localInstaceObjSymbol');
2802
+ //#endregion
2761
2803
  //#region fields / all instances of classes from context
2762
2804
  /**
2763
2805
  * all instances of classes from context
@@ -2778,7 +2820,9 @@ class EndpointContext {
2778
2820
  //#region @websql
2779
2821
  this.repos = new Map();
2780
2822
  //#endregion
2823
+ //#region fields / skip writing server routes
2781
2824
  this.skipWritingServerRoutes = false;
2825
+ //#endregion
2782
2826
  //#region fields / types from contexts
2783
2827
  this.injectableTypesfromContexts = [
2784
2828
  Models.ClassType.CONTROLLER,
@@ -2789,11 +2833,12 @@ class EndpointContext {
2789
2833
  Models.ClassType.MIGRATION,
2790
2834
  ];
2791
2835
  //#endregion
2836
+ //#region fields / all types from contexts
2792
2837
  this.allTypesfromContexts = [
2793
2838
  ...this.injectableTypesfromContexts,
2794
2839
  Models.ClassType.ENTITY,
2795
2840
  ];
2796
- // public __contextForControllerInstanceAccess?: EndpointContext;
2841
+ //#endregion
2797
2842
  //#region fields / express app
2798
2843
  this.expressApp = {};
2799
2844
  //#endregion
@@ -3714,7 +3759,7 @@ class EndpointContext {
3714
3759
  return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
3715
3760
  }
3716
3761
  //#endregion
3717
- //#region port from uri
3762
+ //#region methods & getters / port from uri
3718
3763
  get uriPort() {
3719
3764
  if (!this.uri?.origin?.includes('localhost')) {
3720
3765
  return this.config?.hostPortNumber?.toString();
@@ -3735,12 +3780,15 @@ class EndpointContext {
3735
3780
  return this.uriProtocol === 'https:';
3736
3781
  }
3737
3782
  //#endregion
3738
- //#region methods & getters / public assets
3783
+ //#region methods & getters / is remote host
3784
+ /**
3785
+ * Check if context is for remote only
3786
+ */
3739
3787
  get isRemoteHost() {
3740
3788
  return !!this.cloneOptions?.useAsRemoteContext;
3741
3789
  }
3742
3790
  //#endregion
3743
- //#region methods & getters / public assets
3791
+ //#region methods & getters / context name
3744
3792
  /**
3745
3793
  * ipc/udp needs this
3746
3794
  */
@@ -3749,7 +3797,7 @@ class EndpointContext {
3749
3797
  return this.config?.contextName || this.originalConfig?.contextName;
3750
3798
  }
3751
3799
  //#endregion
3752
- //#region methods & getters / public assets
3800
+ //#region methods & getters / context name for communication
3753
3801
  /**
3754
3802
  * ipc/udp needs this
3755
3803
  */
@@ -3768,7 +3816,7 @@ class EndpointContext {
3768
3816
  return contextName;
3769
3817
  }
3770
3818
  //#endregion
3771
- //#region methods & getters / public assets
3819
+ //#region methods & getters / get context type
3772
3820
  /**
3773
3821
  * Check context type
3774
3822
  */
@@ -3812,8 +3860,8 @@ class EndpointContext {
3812
3860
  return this.config.host;
3813
3861
  }
3814
3862
  //#endregion
3815
- //#region methods & getters / host
3816
- get orgin() {
3863
+ //#region methods & getters / origin
3864
+ get origin() {
3817
3865
  return this.uri?.origin;
3818
3866
  }
3819
3867
  //#endregion
@@ -4157,9 +4205,7 @@ class EndpointContext {
4157
4205
  //#endregion
4158
4206
  //#region methods & getters / write active routes
4159
4207
  writeActiveRoutes() {
4160
- if (this.isRemoteHost ||
4161
- this.isRunOrRevertOnlyMigrationAppStart ||
4162
- this.skipWritingServerRoutes) {
4208
+ if (this.isRemoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
4163
4209
  return;
4164
4210
  }
4165
4211
  // const contexts: EndpointContext[] = [this];
@@ -4185,7 +4231,7 @@ class EndpointContext {
4185
4231
  `routes-${this.config.contextName}.rest`,
4186
4232
  ]);
4187
4233
  this.logFramework && console.log(`[taon] routes file: ${fileName} `);
4188
- // Helpers.log(JSON.stringify(routes, null, 4))
4234
+ this.logRoutes && console.log(routes);
4189
4235
  /* */
4190
4236
  /* */
4191
4237
  /* */
@@ -4670,6 +4716,41 @@ class EndpointContext {
4670
4716
  };
4671
4717
  }
4672
4718
  //#endregion
4719
+ //#region methods & getters / send error
4720
+ sendError(res, error, req, expressPath) {
4721
+ /* */
4722
+ /* */
4723
+ /* */
4724
+ /* */
4725
+ /* */
4726
+ /* */
4727
+ /* */
4728
+ /* */
4729
+ /* */
4730
+ /* */
4731
+ /* */
4732
+ /* */
4733
+ /* */
4734
+ /* */
4735
+ /* */
4736
+ /* */
4737
+ /* */
4738
+ /* */
4739
+ /* */
4740
+ /* */
4741
+ /* */
4742
+ /* */
4743
+ /* */
4744
+ /* */
4745
+ /* */
4746
+ /* */
4747
+ /* */
4748
+ /* */
4749
+ /* */
4750
+ /* */
4751
+ return (void 0);
4752
+ }
4753
+ //#endregion
4673
4754
  //#region methods & getters / init client
4674
4755
  /**
4675
4756
  * client can be browser or nodejs (when remote host)
@@ -4704,8 +4785,8 @@ class EndpointContext {
4704
4785
  });
4705
4786
  //#endregion
4706
4787
  // : { received: any; /* Rest<any, any> */ }
4707
- this.logHttp &&
4708
- console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
4788
+ // this.logHttp &&
4789
+ // console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
4709
4790
  // console.log('INITING', methodConfig); // TODO inject in static
4710
4791
  //#region resolve storage
4711
4792
  // TODO not a good idea
@@ -5481,6 +5562,7 @@ class BaseInjector {
5481
5562
  }
5482
5563
  }
5483
5564
 
5565
+ //#endregion
5484
5566
  /**
5485
5567
  * TODO
5486
5568
  * - global provider available in all contexts
@@ -5701,6 +5783,9 @@ let BaseRepository = class BaseRepository extends BaseCustomRepository {
5701
5783
  return models;
5702
5784
  //#endregion
5703
5785
  }
5786
+ /**
5787
+ * @deprecated use bulkSave instead
5788
+ */
5704
5789
  async bulkCreate(items, options) {
5705
5790
  return this.bulkSave(items, options);
5706
5791
  }
@@ -6211,7 +6296,7 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
6211
6296
  else {
6212
6297
  options = { pathOrOptions, pathIsGlobal };
6213
6298
  }
6214
- const { overrideContentType, overrideResponseType, middlewares } = options;
6299
+ const { overrideContentType, overrideResponseType, overrideExpressSendAsHtml, middlewares, } = options;
6215
6300
  methodConfig.methodName = propertyKey;
6216
6301
  methodConfig.middlewares = middlewares;
6217
6302
  methodConfig.type = method;
@@ -6236,12 +6321,44 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
6236
6321
  methodConfig.global = pathIsGlobal;
6237
6322
  methodConfig.contentType = overrideContentType;
6238
6323
  methodConfig.responseType = overrideResponseType;
6324
+ methodConfig.overrideExpressSendAsHtml = overrideExpressSendAsHtml;
6239
6325
  };
6240
6326
  function GET(pathOrOptions, pathIsGlobal = false) {
6241
6327
  return function (target, propertyKey, descriptor) {
6242
6328
  metaReq('get', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
6243
6329
  };
6244
6330
  }
6331
+ /**
6332
+ * Method for sending html website from text
6333
+ * Example
6334
+ *
6335
+ * ```ts
6336
+ * ...
6337
+ * // in your taon controller
6338
+ * ..Taon.Http.HTML()
6339
+ * sendHtmlDummyWebsite(): Taon.ResponseHtml {
6340
+ * return `
6341
+ <html>
6342
+ <head>
6343
+ <title>Dummy website</title>
6344
+ </head>
6345
+ <body>
6346
+ <h1>This is dummy website</h1>
6347
+ <p>Served as HTML string from Taon controller method</p>
6348
+ </body>
6349
+ </html>
6350
+ * `; *
6351
+ * }
6352
+ * ...
6353
+ * ```
6354
+ */
6355
+ function HTML(pathOrOptions) {
6356
+ return function (target, propertyKey, descriptor) {
6357
+ const opt = pathOrOptions;
6358
+ opt.overrideExpressSendAsHtml = true;
6359
+ metaReq('get', opt, target, propertyKey, descriptor, pathOrOptions, opt.pathIsGlobal);
6360
+ };
6361
+ }
6245
6362
  function HEAD(pathOrOptions, pathIsGlobal = false) {
6246
6363
  return function (target, propertyKey, descriptor) {
6247
6364
  metaReq('head', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
@@ -6317,7 +6434,7 @@ let BaseController = class BaseController extends BaseInjector {
6317
6434
  */
6318
6435
  async afterAllCtxInited(options) { }
6319
6436
  //#region upload form data to server
6320
- uploadFormDataToServer(formData) {
6437
+ uploadFormDataToServer(formData, queryParams) {
6321
6438
  /* */
6322
6439
  /* */
6323
6440
  /* */
@@ -6352,11 +6469,13 @@ let BaseController = class BaseController extends BaseInjector {
6352
6469
  * Hook after file is uploaded
6353
6470
  * through `uploadFormDataToServer` or `uploadLocalFileToServer`
6354
6471
  */
6355
- afterFileUploadAction(file) {
6472
+ afterFileUploadAction(file, queryParams) {
6356
6473
  // empty
6357
6474
  }
6358
6475
  //#region upload local file to server
6359
- async uploadLocalFileToServer(absFilePath, options) {
6476
+ async uploadLocalFileToServer(absFilePath, options, queryParams) {
6477
+ /* */
6478
+ /* */
6360
6479
  /* */
6361
6480
  /* */
6362
6481
  /* */
@@ -6371,6 +6490,75 @@ let BaseController = class BaseController extends BaseInjector {
6371
6490
  /* */
6372
6491
  return (void 0);
6373
6492
  }
6493
+ //#endregion
6494
+ // async check() {
6495
+ // await this._waitForProperStatusChange({
6496
+ // request: () => this.uploadFormDataToServer(void 0, void 0).request(),
6497
+ // statusCheck: resp => resp.body.json[0].ok,
6498
+ // });
6499
+ // }
6500
+ /**
6501
+ * Easy way to wait for status change with http (1s default) pooling.
6502
+ *
6503
+ * example (in sub class):
6504
+ * ```ts
6505
+ async check() {
6506
+ await this.waitForProperStatusChange({
6507
+ request: () => this.uploadFormDataToServer(void 0, void 0).request(),
6508
+ statusCheck: resp => resp.body.json[0].ok,
6509
+ });
6510
+ }
6511
+ * ```
6512
+ */
6513
+ async _waitForProperStatusChange(options) {
6514
+ const poolingInterval = options.poolingInterval || 1000;
6515
+ const taonRequest = options.request;
6516
+ let maxTries = options.maxTries || Number.POSITIVE_INFINITY;
6517
+ let i = 0;
6518
+ let httpErrorsCount = 0;
6519
+ while (true) {
6520
+ await UtilsTerminal.waitMilliseconds(poolingInterval);
6521
+ try {
6522
+ const resp = await taonRequest({
6523
+ reqIndexNum: i,
6524
+ httpErrorsCount,
6525
+ });
6526
+ if (options.statusCheck && options.statusCheck(resp)) {
6527
+ return;
6528
+ }
6529
+ }
6530
+ catch (error) {
6531
+ httpErrorsCount++;
6532
+ if (options.loopRequestsOnBackendError) {
6533
+ const isProperTaonError = error instanceof HttpResponseError &&
6534
+ error.body.json[CoreModels.TaonHttpErrorCustomProp];
6535
+ const isHttpError = error instanceof HttpResponseError && !isProperTaonError;
6536
+ const isUnknownError = !(error instanceof HttpResponseError);
6537
+ const resBool = await options.loopRequestsOnBackendError({
6538
+ taonError: isProperTaonError ? error : void 0,
6539
+ unknownHttpError: isHttpError ? error : void 0,
6540
+ unknownError: isUnknownError ? error : void 0,
6541
+ reqIndexNum: i,
6542
+ httpErrorsCount,
6543
+ });
6544
+ if (resBool) {
6545
+ i++;
6546
+ continue;
6547
+ }
6548
+ else {
6549
+ return;
6550
+ }
6551
+ }
6552
+ if (httpErrorsCount >
6553
+ (options.allowedHttpErrors || Number.POSITIVE_INFINITY)) {
6554
+ throw new Error(`Too many http errors (${httpErrorsCount}) for "${options.actionName}".`);
6555
+ }
6556
+ }
6557
+ if (i++ > maxTries) {
6558
+ throw new Error(`Timeout waiting for "${options.actionName}" to be finished. Waited for ${maxTries} seconds`);
6559
+ }
6560
+ }
6561
+ }
6374
6562
  };
6375
6563
  __decorate([
6376
6564
  POST({
@@ -6381,8 +6569,9 @@ __decorate([
6381
6569
  }),
6382
6570
  }),
6383
6571
  __param(0, Body()),
6572
+ __param(1, Query()),
6384
6573
  __metadata("design:type", Function),
6385
- __metadata("design:paramtypes", [FormData]),
6574
+ __metadata("design:paramtypes", [FormData, Object]),
6386
6575
  __metadata("design:returntype", Object)
6387
6576
  ], BaseController.prototype, "uploadFormDataToServer", null);
6388
6577
  BaseController = __decorate([
@@ -6414,7 +6603,7 @@ let BaseCrudController = class BaseCrudController extends BaseController {
6414
6603
  else {
6415
6604
  Helpers.error(`Entity class not provided for controller ${ClassHelpers.getName(this)}.
6416
6605
 
6417
- Please provide entity as class propery entityClassFn:
6606
+ Please provide entity as class property entityClassFn:
6418
6607
 
6419
6608
  class ${ClassHelpers.getName(this)} extends BaseCrudController<Entity> {
6420
6609
  // ...
@@ -6561,11 +6750,20 @@ let BaseCrudController = class BaseCrudController extends BaseController {
6561
6750
  //#endregion
6562
6751
  }
6563
6752
  //#endregion
6753
+ //#region bulk delete
6754
+ clearTable() {
6755
+ //#region @websqlFunc
6756
+ return async () => {
6757
+ await this.db.clear();
6758
+ };
6759
+ //#endregion
6760
+ }
6761
+ //#endregion
6564
6762
  //#region create
6565
- create(item) {
6763
+ save(item) {
6566
6764
  //#region @websqlFunc
6567
6765
  return async () => {
6568
- const model = await this.db.create(item);
6766
+ const model = await this.db.save(item);
6569
6767
  return model;
6570
6768
  };
6571
6769
  //#endregion
@@ -6639,7 +6837,7 @@ __decorate([
6639
6837
  DELETE(),
6640
6838
  __param(0, Query(`id`)),
6641
6839
  __metadata("design:type", Function),
6642
- __metadata("design:paramtypes", [Number]),
6840
+ __metadata("design:paramtypes", [Object]),
6643
6841
  __metadata("design:returntype", Object)
6644
6842
  ], BaseCrudController.prototype, "deleteById", null);
6645
6843
  __decorate([
@@ -6649,13 +6847,19 @@ __decorate([
6649
6847
  __metadata("design:paramtypes", [Array]),
6650
6848
  __metadata("design:returntype", Object)
6651
6849
  ], BaseCrudController.prototype, "bulkDelete", null);
6850
+ __decorate([
6851
+ DELETE(),
6852
+ __metadata("design:type", Function),
6853
+ __metadata("design:paramtypes", []),
6854
+ __metadata("design:returntype", Object)
6855
+ ], BaseCrudController.prototype, "clearTable", null);
6652
6856
  __decorate([
6653
6857
  POST(),
6654
6858
  __param(0, Body()),
6655
6859
  __metadata("design:type", Function),
6656
6860
  __metadata("design:paramtypes", [Object]),
6657
6861
  __metadata("design:returntype", Object)
6658
- ], BaseCrudController.prototype, "create", null);
6862
+ ], BaseCrudController.prototype, "save", null);
6659
6863
  __decorate([
6660
6864
  POST(),
6661
6865
  __param(0, Body()),
@@ -6922,6 +7126,7 @@ var Http;
6922
7126
  Http.DELETE = DELETE;
6923
7127
  Http.PATCH = PATCH;
6924
7128
  Http.HEAD = HEAD;
7129
+ Http.HTML = HTML;
6925
7130
  Http.Response = Models$1.HttpResponse;
6926
7131
  let Param;
6927
7132
  (function (Param) {
@@ -6936,6 +7141,16 @@ var Http;
6936
7141
  // TODO export all things
6937
7142
  var Taon;
6938
7143
  (function (Taon) {
7144
+ Taon.error = (opt) => {
7145
+ throw () => {
7146
+ if (typeof opt === 'string') {
7147
+ opt = {
7148
+ message: opt
7149
+ };
7150
+ }
7151
+ return opt;
7152
+ };
7153
+ };
6939
7154
  Taon.Http = Http;
6940
7155
  Taon.Base = Base;
6941
7156
  Taon.Orm = Orm;
@@ -6989,5 +7204,5 @@ var Taon;
6989
7204
  * Generated bundle index. Do not edit.
6990
7205
  */
6991
7206
 
6992
- 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 };
7207
+ 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 };
6993
7208
  //# sourceMappingURL=taon.mjs.map