taon 19.0.66 → 19.0.67
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/README.md +160 -160
- package/bin/start.js +281 -281
- package/bin/taon +6 -6
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +5 -5
- package/browser/README.md +24 -24
- package/browser/fesm2022/taon.mjs +272 -68
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/base-classes/base-class.d.ts +8 -1
- package/browser/lib/base-classes/base-controller.d.ts +56 -4
- package/browser/lib/base-classes/base-crud-controller.d.ts +5 -4
- package/browser/lib/base-classes/base-repository.d.ts +3 -0
- package/browser/lib/config/method-config.d.ts +1 -0
- package/browser/lib/decorators/http/http-decorators.d.ts +2 -1
- package/browser/lib/decorators/http/http-methods-decorators.d.ts +35 -4
- package/browser/lib/endpoint-context.d.ts +3 -0
- package/browser/lib/get-response-value.d.ts +1 -1
- package/browser/lib/helpers/taon-helpers.d.ts +1 -0
- package/browser/lib/index.d.ts +4 -0
- package/browser/lib/models.d.ts +4 -10
- package/browser/lib/realtime/realtime-client.d.ts +18 -14
- package/browser/lib/realtime/realtime-server.d.ts +28 -3
- package/browser/lib/realtime/realtime.models.d.ts +15 -2
- package/browser/package.json +1 -1
- package/icon-menu-taon.svg +15 -15
- package/lib/base-classes/base-class.d.ts +8 -1
- package/lib/base-classes/base-class.js +20 -2
- package/lib/base-classes/base-class.js.map +1 -1
- package/lib/base-classes/base-controller.d.ts +57 -5
- package/lib/base-classes/base-controller.js +83 -12
- package/lib/base-classes/base-controller.js.map +1 -1
- package/lib/base-classes/base-crud-controller.d.ts +5 -4
- package/lib/base-classes/base-crud-controller.js +16 -4
- package/lib/base-classes/base-crud-controller.js.map +1 -1
- package/lib/base-classes/base-repository.d.ts +3 -0
- package/lib/base-classes/base-repository.js +3 -0
- package/lib/base-classes/base-repository.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/config/method-config.d.ts +1 -0
- package/lib/config/method-config.js.map +1 -1
- package/lib/decorators/http/http-decorators.d.ts +2 -1
- package/lib/decorators/http/http-decorators.js +2 -1
- package/lib/decorators/http/http-decorators.js.map +1 -1
- package/lib/decorators/http/http-methods-decorators.d.ts +35 -4
- package/lib/decorators/http/http-methods-decorators.js +34 -1
- package/lib/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib/endpoint-context.d.ts +3 -0
- package/lib/endpoint-context.js +152 -122
- package/lib/endpoint-context.js.map +1 -1
- package/lib/get-response-value.d.ts +1 -1
- package/lib/get-response-value.js +0 -4
- package/lib/get-response-value.js.map +1 -1
- package/lib/helpers/taon-helpers.d.ts +1 -0
- package/lib/helpers/taon-helpers.js +6 -0
- package/lib/helpers/taon-helpers.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +4 -10
- package/lib/models.js +5 -23
- package/lib/models.js.map +1 -1
- package/lib/realtime/realtime-client.d.ts +18 -14
- package/lib/realtime/realtime-client.js +33 -25
- package/lib/realtime/realtime-client.js.map +1 -1
- package/lib/realtime/realtime-server.d.ts +28 -3
- package/lib/realtime/realtime-server.js +28 -2
- package/lib/realtime/realtime-server.js.map +1 -1
- package/lib/realtime/realtime.models.d.ts +15 -2
- 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/README.md +24 -24
- package/websql/fesm2022/taon.mjs +273 -70
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/base-classes/base-class.d.ts +8 -1
- package/websql/lib/base-classes/base-controller.d.ts +56 -4
- package/websql/lib/base-classes/base-crud-controller.d.ts +5 -4
- package/websql/lib/base-classes/base-repository.d.ts +3 -0
- package/websql/lib/config/method-config.d.ts +1 -0
- package/websql/lib/decorators/http/http-decorators.d.ts +2 -1
- package/websql/lib/decorators/http/http-methods-decorators.d.ts +35 -4
- package/websql/lib/endpoint-context.d.ts +3 -0
- package/websql/lib/get-response-value.d.ts +1 -1
- package/websql/lib/helpers/taon-helpers.d.ts +1 -0
- package/websql/lib/index.d.ts +4 -0
- package/websql/lib/models.d.ts +4 -10
- package/websql/lib/realtime/realtime-client.d.ts +18 -14
- package/websql/lib/realtime/realtime-server.d.ts +28 -3
- package/websql/lib/realtime/realtime.models.d.ts +15 -2
- package/websql/package.json +1 -1
package/websql/fesm2022/taon.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -830,6 +847,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
|
|
|
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(
|
|
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(
|
|
1658
|
+
const className = !customEvent && ClassHelpers.getName(entityClassFnOrObj);
|
|
1635
1659
|
if (_.isString(property)) {
|
|
1636
1660
|
if (property.trim() === '') {
|
|
1637
|
-
throw new Error(`[Taon][listenChangesEntity..
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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;
|
|
@@ -4157,9 +4201,7 @@ class EndpointContext {
|
|
|
4157
4201
|
//#endregion
|
|
4158
4202
|
//#region methods & getters / write active routes
|
|
4159
4203
|
writeActiveRoutes() {
|
|
4160
|
-
if (this.isRemoteHost ||
|
|
4161
|
-
this.isRunOrRevertOnlyMigrationAppStart ||
|
|
4162
|
-
this.skipWritingServerRoutes) {
|
|
4204
|
+
if (this.isRemoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
|
|
4163
4205
|
return;
|
|
4164
4206
|
}
|
|
4165
4207
|
// const contexts: EndpointContext[] = [this];
|
|
@@ -4185,7 +4227,7 @@ class EndpointContext {
|
|
|
4185
4227
|
`routes-${this.config.contextName}.rest`,
|
|
4186
4228
|
]);
|
|
4187
4229
|
this.logFramework && console.log(`[taon] routes file: ${fileName} `);
|
|
4188
|
-
|
|
4230
|
+
this.logRoutes && console.log(routes);
|
|
4189
4231
|
/* */
|
|
4190
4232
|
/* */
|
|
4191
4233
|
/* */
|
|
@@ -4670,6 +4712,39 @@ class EndpointContext {
|
|
|
4670
4712
|
};
|
|
4671
4713
|
}
|
|
4672
4714
|
//#endregion
|
|
4715
|
+
sendError(res, error, req, expressPath) {
|
|
4716
|
+
/* */
|
|
4717
|
+
/* */
|
|
4718
|
+
/* */
|
|
4719
|
+
/* */
|
|
4720
|
+
/* */
|
|
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
|
+
return (void 0);
|
|
4747
|
+
}
|
|
4673
4748
|
//#region methods & getters / init client
|
|
4674
4749
|
/**
|
|
4675
4750
|
* client can be browser or nodejs (when remote host)
|
|
@@ -4704,8 +4779,8 @@ class EndpointContext {
|
|
|
4704
4779
|
});
|
|
4705
4780
|
//#endregion
|
|
4706
4781
|
// : { received: any; /* Rest<any, any> */ }
|
|
4707
|
-
this.logHttp &&
|
|
4708
|
-
|
|
4782
|
+
// this.logHttp &&
|
|
4783
|
+
// console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
|
|
4709
4784
|
// console.log('INITING', methodConfig); // TODO inject in static
|
|
4710
4785
|
//#region resolve storage
|
|
4711
4786
|
// TODO not a good idea
|
|
@@ -5701,6 +5776,9 @@ let BaseRepository = class BaseRepository extends BaseCustomRepository {
|
|
|
5701
5776
|
return models;
|
|
5702
5777
|
//#endregion
|
|
5703
5778
|
}
|
|
5779
|
+
/**
|
|
5780
|
+
* @deprecated use bulkSave instead
|
|
5781
|
+
*/
|
|
5704
5782
|
async bulkCreate(items, options) {
|
|
5705
5783
|
return this.bulkSave(items, options);
|
|
5706
5784
|
}
|
|
@@ -6211,7 +6289,7 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
|
|
|
6211
6289
|
else {
|
|
6212
6290
|
options = { pathOrOptions, pathIsGlobal };
|
|
6213
6291
|
}
|
|
6214
|
-
const { overrideContentType, overrideResponseType, middlewares } = options;
|
|
6292
|
+
const { overrideContentType, overrideResponseType, overrideExpressSendAsHtml, middlewares, } = options;
|
|
6215
6293
|
methodConfig.methodName = propertyKey;
|
|
6216
6294
|
methodConfig.middlewares = middlewares;
|
|
6217
6295
|
methodConfig.type = method;
|
|
@@ -6236,12 +6314,44 @@ const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, p
|
|
|
6236
6314
|
methodConfig.global = pathIsGlobal;
|
|
6237
6315
|
methodConfig.contentType = overrideContentType;
|
|
6238
6316
|
methodConfig.responseType = overrideResponseType;
|
|
6317
|
+
methodConfig.overrideExpressSendAsHtml = overrideExpressSendAsHtml;
|
|
6239
6318
|
};
|
|
6240
6319
|
function GET(pathOrOptions, pathIsGlobal = false) {
|
|
6241
6320
|
return function (target, propertyKey, descriptor) {
|
|
6242
6321
|
metaReq('get', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6243
6322
|
};
|
|
6244
6323
|
}
|
|
6324
|
+
/**
|
|
6325
|
+
* Method for sending html website from text
|
|
6326
|
+
* Example
|
|
6327
|
+
*
|
|
6328
|
+
* ```ts
|
|
6329
|
+
* ...
|
|
6330
|
+
* // in your taon controller
|
|
6331
|
+
* ..Taon.Http.HTML()
|
|
6332
|
+
* sendHtmlDummyWebsite(): Taon.ResponseHtml {
|
|
6333
|
+
* return `
|
|
6334
|
+
<html>
|
|
6335
|
+
<head>
|
|
6336
|
+
<title>Dummy website</title>
|
|
6337
|
+
</head>
|
|
6338
|
+
<body>
|
|
6339
|
+
<h1>This is dummy website</h1>
|
|
6340
|
+
<p>Served as HTML string from Taon controller method</p>
|
|
6341
|
+
</body>
|
|
6342
|
+
</html>
|
|
6343
|
+
* `; *
|
|
6344
|
+
* }
|
|
6345
|
+
* ...
|
|
6346
|
+
* ```
|
|
6347
|
+
*/
|
|
6348
|
+
function HTML(pathOrOptions) {
|
|
6349
|
+
return function (target, propertyKey, descriptor) {
|
|
6350
|
+
const opt = pathOrOptions;
|
|
6351
|
+
opt.overrideExpressSendAsHtml = true;
|
|
6352
|
+
metaReq('get', opt, target, propertyKey, descriptor, pathOrOptions, opt.pathIsGlobal);
|
|
6353
|
+
};
|
|
6354
|
+
}
|
|
6245
6355
|
function HEAD(pathOrOptions, pathIsGlobal = false) {
|
|
6246
6356
|
return function (target, propertyKey, descriptor) {
|
|
6247
6357
|
metaReq('head', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
@@ -6317,7 +6427,7 @@ let BaseController = class BaseController extends BaseInjector {
|
|
|
6317
6427
|
*/
|
|
6318
6428
|
async afterAllCtxInited(options) { }
|
|
6319
6429
|
//#region upload form data to server
|
|
6320
|
-
uploadFormDataToServer(formData) {
|
|
6430
|
+
uploadFormDataToServer(formData, queryParams) {
|
|
6321
6431
|
/* */
|
|
6322
6432
|
/* */
|
|
6323
6433
|
/* */
|
|
@@ -6352,11 +6462,13 @@ let BaseController = class BaseController extends BaseInjector {
|
|
|
6352
6462
|
* Hook after file is uploaded
|
|
6353
6463
|
* through `uploadFormDataToServer` or `uploadLocalFileToServer`
|
|
6354
6464
|
*/
|
|
6355
|
-
afterFileUploadAction(file) {
|
|
6465
|
+
afterFileUploadAction(file, queryParams) {
|
|
6356
6466
|
// empty
|
|
6357
6467
|
}
|
|
6358
6468
|
//#region upload local file to server
|
|
6359
|
-
async uploadLocalFileToServer(absFilePath, options) {
|
|
6469
|
+
async uploadLocalFileToServer(absFilePath, options, queryParams) {
|
|
6470
|
+
/* */
|
|
6471
|
+
/* */
|
|
6360
6472
|
/* */
|
|
6361
6473
|
/* */
|
|
6362
6474
|
/* */
|
|
@@ -6371,6 +6483,75 @@ let BaseController = class BaseController extends BaseInjector {
|
|
|
6371
6483
|
/* */
|
|
6372
6484
|
return (void 0);
|
|
6373
6485
|
}
|
|
6486
|
+
//#endregion
|
|
6487
|
+
// async check() {
|
|
6488
|
+
// await this._waitForProperStatusChange({
|
|
6489
|
+
// request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
6490
|
+
// statusCheck: resp => resp.body.json[0].ok,
|
|
6491
|
+
// });
|
|
6492
|
+
// }
|
|
6493
|
+
/**
|
|
6494
|
+
* Easy way to wait for status change with http (1s default) pooling.
|
|
6495
|
+
*
|
|
6496
|
+
* example (in sub class):
|
|
6497
|
+
* ```ts
|
|
6498
|
+
async check() {
|
|
6499
|
+
await this.waitForProperStatusChange({
|
|
6500
|
+
request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
6501
|
+
statusCheck: resp => resp.body.json[0].ok,
|
|
6502
|
+
});
|
|
6503
|
+
}
|
|
6504
|
+
* ```
|
|
6505
|
+
*/
|
|
6506
|
+
async _waitForProperStatusChange(options) {
|
|
6507
|
+
const poolingInterval = options.poolingInterval || 1000;
|
|
6508
|
+
const taonRequest = options.request;
|
|
6509
|
+
let maxTries = options.maxTries || Number.POSITIVE_INFINITY;
|
|
6510
|
+
let i = 0;
|
|
6511
|
+
let httpErrorsCount = 0;
|
|
6512
|
+
while (true) {
|
|
6513
|
+
await UtilsTerminal.waitMilliseconds(poolingInterval);
|
|
6514
|
+
try {
|
|
6515
|
+
const resp = await taonRequest({
|
|
6516
|
+
reqIndexNum: i,
|
|
6517
|
+
httpErrorsCount,
|
|
6518
|
+
});
|
|
6519
|
+
if (options.statusCheck && options.statusCheck(resp)) {
|
|
6520
|
+
return;
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
catch (error) {
|
|
6524
|
+
httpErrorsCount++;
|
|
6525
|
+
if (options.loopRequestsOnBackendError) {
|
|
6526
|
+
const isProperTaonError = error instanceof HttpResponseError &&
|
|
6527
|
+
error.body.json[CoreModels.TaonHttpErrorCustomProp];
|
|
6528
|
+
const isHttpError = error instanceof HttpResponseError && !isProperTaonError;
|
|
6529
|
+
const isUnknownError = !(error instanceof HttpResponseError);
|
|
6530
|
+
const resBool = await options.loopRequestsOnBackendError({
|
|
6531
|
+
taonError: isProperTaonError ? error : void 0,
|
|
6532
|
+
unknownHttpError: isHttpError ? error : void 0,
|
|
6533
|
+
unknownError: isUnknownError ? error : void 0,
|
|
6534
|
+
reqIndexNum: i,
|
|
6535
|
+
httpErrorsCount,
|
|
6536
|
+
});
|
|
6537
|
+
if (resBool) {
|
|
6538
|
+
i++;
|
|
6539
|
+
continue;
|
|
6540
|
+
}
|
|
6541
|
+
else {
|
|
6542
|
+
return;
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
if (httpErrorsCount >
|
|
6546
|
+
(options.allowedHttpErrors || Number.POSITIVE_INFINITY)) {
|
|
6547
|
+
throw new Error(`Too many http errors (${httpErrorsCount}) for "${options.actionName}".`);
|
|
6548
|
+
}
|
|
6549
|
+
}
|
|
6550
|
+
if (i++ > maxTries) {
|
|
6551
|
+
throw new Error(`Timeout waiting for "${options.actionName}" to be finished. Waited for ${maxTries} seconds`);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
}
|
|
6374
6555
|
};
|
|
6375
6556
|
__decorate([
|
|
6376
6557
|
POST({
|
|
@@ -6381,8 +6562,9 @@ __decorate([
|
|
|
6381
6562
|
}),
|
|
6382
6563
|
}),
|
|
6383
6564
|
__param(0, Body()),
|
|
6565
|
+
__param(1, Query()),
|
|
6384
6566
|
__metadata("design:type", Function),
|
|
6385
|
-
__metadata("design:paramtypes", [FormData]),
|
|
6567
|
+
__metadata("design:paramtypes", [FormData, Object]),
|
|
6386
6568
|
__metadata("design:returntype", Object)
|
|
6387
6569
|
], BaseController.prototype, "uploadFormDataToServer", null);
|
|
6388
6570
|
BaseController = __decorate([
|
|
@@ -6414,7 +6596,7 @@ let BaseCrudController = class BaseCrudController extends BaseController {
|
|
|
6414
6596
|
else {
|
|
6415
6597
|
Helpers.error(`Entity class not provided for controller ${ClassHelpers.getName(this)}.
|
|
6416
6598
|
|
|
6417
|
-
Please provide entity as class
|
|
6599
|
+
Please provide entity as class property entityClassFn:
|
|
6418
6600
|
|
|
6419
6601
|
class ${ClassHelpers.getName(this)} extends BaseCrudController<Entity> {
|
|
6420
6602
|
// ...
|
|
@@ -6561,11 +6743,20 @@ let BaseCrudController = class BaseCrudController extends BaseController {
|
|
|
6561
6743
|
//#endregion
|
|
6562
6744
|
}
|
|
6563
6745
|
//#endregion
|
|
6746
|
+
//#region bulk delete
|
|
6747
|
+
clearTable() {
|
|
6748
|
+
//#region @websqlFunc
|
|
6749
|
+
return async () => {
|
|
6750
|
+
await this.db.clear();
|
|
6751
|
+
};
|
|
6752
|
+
//#endregion
|
|
6753
|
+
}
|
|
6754
|
+
//#endregion
|
|
6564
6755
|
//#region create
|
|
6565
|
-
|
|
6756
|
+
save(item) {
|
|
6566
6757
|
//#region @websqlFunc
|
|
6567
6758
|
return async () => {
|
|
6568
|
-
const model = await this.db.
|
|
6759
|
+
const model = await this.db.save(item);
|
|
6569
6760
|
return model;
|
|
6570
6761
|
};
|
|
6571
6762
|
//#endregion
|
|
@@ -6639,7 +6830,7 @@ __decorate([
|
|
|
6639
6830
|
DELETE(),
|
|
6640
6831
|
__param(0, Query(`id`)),
|
|
6641
6832
|
__metadata("design:type", Function),
|
|
6642
|
-
__metadata("design:paramtypes", [
|
|
6833
|
+
__metadata("design:paramtypes", [Object]),
|
|
6643
6834
|
__metadata("design:returntype", Object)
|
|
6644
6835
|
], BaseCrudController.prototype, "deleteById", null);
|
|
6645
6836
|
__decorate([
|
|
@@ -6649,13 +6840,19 @@ __decorate([
|
|
|
6649
6840
|
__metadata("design:paramtypes", [Array]),
|
|
6650
6841
|
__metadata("design:returntype", Object)
|
|
6651
6842
|
], BaseCrudController.prototype, "bulkDelete", null);
|
|
6843
|
+
__decorate([
|
|
6844
|
+
DELETE(),
|
|
6845
|
+
__metadata("design:type", Function),
|
|
6846
|
+
__metadata("design:paramtypes", []),
|
|
6847
|
+
__metadata("design:returntype", Object)
|
|
6848
|
+
], BaseCrudController.prototype, "clearTable", null);
|
|
6652
6849
|
__decorate([
|
|
6653
6850
|
POST(),
|
|
6654
6851
|
__param(0, Body()),
|
|
6655
6852
|
__metadata("design:type", Function),
|
|
6656
6853
|
__metadata("design:paramtypes", [Object]),
|
|
6657
6854
|
__metadata("design:returntype", Object)
|
|
6658
|
-
], BaseCrudController.prototype, "
|
|
6855
|
+
], BaseCrudController.prototype, "save", null);
|
|
6659
6856
|
__decorate([
|
|
6660
6857
|
POST(),
|
|
6661
6858
|
__param(0, Body()),
|
|
@@ -6922,6 +7119,7 @@ var Http;
|
|
|
6922
7119
|
Http.DELETE = DELETE;
|
|
6923
7120
|
Http.PATCH = PATCH;
|
|
6924
7121
|
Http.HEAD = HEAD;
|
|
7122
|
+
Http.HTML = HTML;
|
|
6925
7123
|
Http.Response = Models$1.HttpResponse;
|
|
6926
7124
|
let Param;
|
|
6927
7125
|
(function (Param) {
|
|
@@ -6936,6 +7134,11 @@ var Http;
|
|
|
6936
7134
|
// TODO export all things
|
|
6937
7135
|
var Taon;
|
|
6938
7136
|
(function (Taon) {
|
|
7137
|
+
Taon.error = (opt) => {
|
|
7138
|
+
throw () => {
|
|
7139
|
+
return opt;
|
|
7140
|
+
};
|
|
7141
|
+
};
|
|
6939
7142
|
Taon.Http = Http;
|
|
6940
7143
|
Taon.Base = Base;
|
|
6941
7144
|
Taon.Orm = Orm;
|
|
@@ -6989,5 +7192,5 @@ var Taon;
|
|
|
6989
7192
|
* Generated bundle index. Do not edit.
|
|
6990
7193
|
*/
|
|
6991
7194
|
|
|
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 };
|
|
7195
|
+
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
7196
|
//# sourceMappingURL=taon.mjs.map
|