taon 21.0.89 → 21.0.91
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/VERIFIED-BUILD-DATA.jsonc +5 -0
- package/bin/taon +5 -5
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +4 -4
- package/browser/fesm2022/taon-browser.mjs +1097 -1190
- package/browser/fesm2022/taon-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/taon-browser.d.ts +261 -256
- package/browser-prod/fesm2022/taon-browser-prod.mjs +1098 -1191
- package/browser-prod/fesm2022/taon-browser-prod.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod/types/taon-browser-prod.d.ts +259 -254
- package/icon-menu-taon.svg +15 -15
- package/lib/base-classes/base-context.js +1 -2
- package/lib/base-classes/base-context.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/create-context.js +6 -0
- package/lib/create-context.js.map +1 -1
- package/lib/endpoint-context.d.ts +7 -1
- package/lib/endpoint-context.js +18 -1
- package/lib/endpoint-context.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/realtime/realtime-client.js +20 -9
- package/lib/realtime/realtime-client.js.map +1 -1
- package/lib/realtime/realtime-core.js +9 -4
- package/lib/realtime/realtime-core.js.map +1 -1
- package/lib/realtime/realtime-server.js +8 -2
- package/lib/realtime/realtime-server.js.map +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-context.js +1 -2
- package/lib-prod/base-classes/base-context.js.map +1 -1
- package/lib-prod/base-classes/base-controller.js.map +1 -1
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/create-context.js +6 -0
- package/lib-prod/create-context.js.map +1 -1
- package/lib-prod/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib-prod/endpoint-context-storage.js.map +1 -1
- package/lib-prod/endpoint-context.d.ts +7 -1
- package/lib-prod/endpoint-context.js +18 -1
- package/lib-prod/endpoint-context.js.map +1 -1
- package/lib-prod/helpers/class-helpers.js.map +1 -1
- package/lib-prod/index.js.map +1 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +20 -9
- package/lib-prod/realtime/realtime-client.js.map +1 -1
- package/lib-prod/realtime/realtime-core.js +9 -4
- package/lib-prod/realtime/realtime-core.js.map +1 -1
- package/lib-prod/realtime/realtime-server.js +8 -2
- package/lib-prod/realtime/realtime-server.js.map +1 -1
- package/lib-prod/ui/index.d.ts +1 -1
- package/lib-prod/ui/index.js +1 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.d.ts +1 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -1
- package/package.json +1 -1
- package/websql/fesm2022/taon-websql.mjs +835 -1024
- package/websql/fesm2022/taon-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/taon-websql.d.ts +261 -256
- package/websql-prod/fesm2022/taon-websql-prod.mjs +837 -1025
- package/websql-prod/fesm2022/taon-websql-prod.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod/types/taon-websql-prod.d.ts +259 -254
|
@@ -3,9 +3,9 @@ import { _, CoreModels, Utils, UtilsMigrations, Helpers, UtilsOs, crossPlatformP
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import { JSON10 } from 'json10/websql';
|
|
5
5
|
import { walk } from 'lodash-walk-object/websql';
|
|
6
|
-
import { RestResponseWrapper, Resource, HttpResponse, RestHeaders, decodeMappingForHeaderJson, DefaultMapping, DefaultModel
|
|
6
|
+
import { RestResponseWrapper, Resource, HttpResponse, RestHeaders, decodeMappingForHeaderJson, HttpResponseError, DefaultMapping, DefaultModel } from 'ng2-rest/websql';
|
|
7
7
|
import { Observable, Subject, from } from 'rxjs';
|
|
8
|
-
import { Table, TableIndex, EventSubscriber, Entity, DataSource, Column, PrimaryGeneratedColumn, VersionColumn
|
|
8
|
+
import { Table, TableIndex, EventSubscriber, Entity, DataSource, Column, PrimaryGeneratedColumn, VersionColumn } from 'taon-typeorm/websql';
|
|
9
9
|
export { AfterInsert, AfterLoad, AfterRecover, AfterRemove, AfterSoftRemove, AfterUpdate, BeforeInsert, BeforeRecover, BeforeRemove, BeforeSoftRemove, BeforeUpdate, Column, Connection, CreateDateColumn, Column as CustomColumn, DeleteDateColumn, Generated, Generated as GeneratedColumn, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryColumn, PrimaryGeneratedColumn, Repository, TreeChildren, TreeParent, UpdateDateColumn, VersionColumn, VirtualColumn } from 'taon-typeorm/websql';
|
|
10
10
|
import * as i0 from '@angular/core';
|
|
11
11
|
import { InjectionToken, Injectable, signal, inject as inject$1, PLATFORM_ID, ViewContainerRef, ViewChild, Component } from '@angular/core';
|
|
@@ -1239,18 +1239,29 @@ class RealtimeClient {
|
|
|
1239
1239
|
realtime: this.core.pathFor(Symbols.REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
1240
1240
|
};
|
|
1241
1241
|
// console.log('[browser] nspPath', nspPath);
|
|
1242
|
-
if (this.core.ctx.
|
|
1243
|
-
|
|
1244
|
-
this.core.ctx.
|
|
1242
|
+
if (this.core.ctx.isRemoteHost) {
|
|
1243
|
+
// NEED for remote host
|
|
1244
|
+
const nodeClientHostOrigin = this.core.ctx.host;
|
|
1245
1245
|
this.core.ctx.logRealtime &&
|
|
1246
|
-
Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
|
|
1247
|
-
` ${
|
|
1248
|
-
nspPath.global = new URL(`${
|
|
1249
|
-
nspPath.realtime = new URL(`${
|
|
1246
|
+
Helpers.logInfo(`[${this.core.ctx.contextName}] USING REMOTE FRONTEND HOST` +
|
|
1247
|
+
` ${nodeClientHostOrigin} FOR REMOTE REALTIME`);
|
|
1248
|
+
nspPath.global = new URL(`${nodeClientHostOrigin}${nspPath.global.pathname}`);
|
|
1249
|
+
nspPath.realtime = new URL(`${nodeClientHostOrigin}${nspPath.realtime.pathname}`);
|
|
1250
1250
|
}
|
|
1251
1251
|
else {
|
|
1252
|
-
this.core.ctx.
|
|
1253
|
-
|
|
1252
|
+
if (this.core.ctx.config.frontendHost &&
|
|
1253
|
+
this.core.ctx.config.frontendHost !== '' &&
|
|
1254
|
+
this.core.ctx.isRunningInsideDocker) {
|
|
1255
|
+
this.core.ctx.logRealtime &&
|
|
1256
|
+
Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
|
|
1257
|
+
` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
|
|
1258
|
+
nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
|
|
1259
|
+
nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
|
|
1260
|
+
}
|
|
1261
|
+
else {
|
|
1262
|
+
this.core.ctx.logRealtime &&
|
|
1263
|
+
Helpers.logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
|
|
1264
|
+
}
|
|
1254
1265
|
}
|
|
1255
1266
|
this.core.ctx.logRealtime &&
|
|
1256
1267
|
console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
|
|
@@ -1420,7 +1431,7 @@ class RealtimeServer {
|
|
|
1420
1431
|
constructor(core) {
|
|
1421
1432
|
this.core = core;
|
|
1422
1433
|
this.core = core;
|
|
1423
|
-
if (core.ctx.disabledRealtime
|
|
1434
|
+
if (core.ctx.disabledRealtime) {
|
|
1424
1435
|
return;
|
|
1425
1436
|
}
|
|
1426
1437
|
//#region @websql
|
|
@@ -1531,7 +1542,7 @@ class RealtimeServer {
|
|
|
1531
1542
|
// console.info('__triger entity changes');
|
|
1532
1543
|
//#region @websql
|
|
1533
1544
|
let roomName;
|
|
1534
|
-
if (this.core.ctx.disabledRealtime
|
|
1545
|
+
if (this.core.ctx.disabledRealtime) {
|
|
1535
1546
|
return;
|
|
1536
1547
|
}
|
|
1537
1548
|
if (customEvent) {
|
|
@@ -1555,6 +1566,12 @@ class RealtimeServer {
|
|
|
1555
1566
|
? Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, ClassHelpers.getName(entityFn), property, valueOfUniqueProperty)
|
|
1556
1567
|
: Symbols.REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, ClassHelpers.getName(entityFn), valueOfUniqueProperty);
|
|
1557
1568
|
}
|
|
1569
|
+
if (this.core.ctx.isRemoteHost) {
|
|
1570
|
+
// USE REMOTE HOST
|
|
1571
|
+
// this allows me to trigger event from other remote server!
|
|
1572
|
+
this.core.socketFE.emit(customEvent ? customEvent : roomName, customEvent ? customEventData : '');
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1558
1575
|
this.core.socketBE.in(roomName).emit(roomName, // roomName == eventName in room na
|
|
1559
1576
|
customEvent ? customEventData : '');
|
|
1560
1577
|
//#endregion
|
|
@@ -2264,10 +2281,15 @@ class RealtimeCore {
|
|
|
2264
2281
|
];
|
|
2265
2282
|
this.ctx = ctx;
|
|
2266
2283
|
this.strategy = this.resolveStrategy();
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2284
|
+
this.ctx.logRealtime &&
|
|
2285
|
+
console.log(`
|
|
2286
|
+
|
|
2287
|
+
[ctx=${this.ctx.contextName}]
|
|
2288
|
+
mode = ${this.ctx.mode}
|
|
2289
|
+
realtime strategy = ${this.strategy}
|
|
2290
|
+
context type = ${this.ctx.contextType}
|
|
2291
|
+
|
|
2292
|
+
`);
|
|
2271
2293
|
if (UtilsOs.isWebSQL) {
|
|
2272
2294
|
this.server = new RealtimeServer(this);
|
|
2273
2295
|
// console.log('DONE INITING SERVER');
|
|
@@ -2495,9 +2517,23 @@ class EndpointContext {
|
|
|
2495
2517
|
get isRunOrRevertOnlyMigrationAppStart() {
|
|
2496
2518
|
return !!(this.onlyMigrationRun || this.onlyMigrationRevertToTimestamp);
|
|
2497
2519
|
}
|
|
2520
|
+
get realtime() {
|
|
2521
|
+
if (!this._realtime) {
|
|
2522
|
+
throw new Error(`Please initialize context before accessing
|
|
2523
|
+
.realtime.client or realtime.server properties.
|
|
2524
|
+
|
|
2525
|
+
`);
|
|
2526
|
+
}
|
|
2527
|
+
return this._realtime;
|
|
2528
|
+
}
|
|
2529
|
+
set realtime(v) {
|
|
2530
|
+
this._realtime = v;
|
|
2531
|
+
}
|
|
2532
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
2498
2533
|
get realtimeClient() {
|
|
2499
2534
|
return this.realtime.client;
|
|
2500
2535
|
}
|
|
2536
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
2501
2537
|
get realtimeServer() {
|
|
2502
2538
|
return this.realtime.server;
|
|
2503
2539
|
}
|
|
@@ -3639,6 +3675,9 @@ class EndpointContext {
|
|
|
3639
3675
|
}
|
|
3640
3676
|
//#endregion
|
|
3641
3677
|
//#region methods & getters / init subscribers
|
|
3678
|
+
/**
|
|
3679
|
+
* init typeorm subscribers
|
|
3680
|
+
*/
|
|
3642
3681
|
async initSubscribers() {
|
|
3643
3682
|
//#region @websqlFunc
|
|
3644
3683
|
if (this.isRemoteHost) {
|
|
@@ -5188,9 +5227,15 @@ const createContextFn = (configFn, cloneOptions) => {
|
|
|
5188
5227
|
get realtime() {
|
|
5189
5228
|
return {
|
|
5190
5229
|
get client() {
|
|
5230
|
+
if (!endpointContextRef) {
|
|
5231
|
+
throw new Error(`Please .initialize() context before using <context>.realtime.client.<anything> `);
|
|
5232
|
+
}
|
|
5191
5233
|
return endpointContextRef.realtimeClient;
|
|
5192
5234
|
},
|
|
5193
5235
|
get server() {
|
|
5236
|
+
if (!endpointContextRef) {
|
|
5237
|
+
throw new Error(`Please .initialize() context before using <context>.realtime.server.<anything> `);
|
|
5238
|
+
}
|
|
5194
5239
|
return endpointContextRef.realtimeServer;
|
|
5195
5240
|
},
|
|
5196
5241
|
};
|
|
@@ -5797,287 +5842,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
|
|
|
5797
5842
|
type: Injectable
|
|
5798
5843
|
}], ctorParameters: () => [] });
|
|
5799
5844
|
|
|
5800
|
-
/**
|
|
5801
|
-
* Entity decorator
|
|
5802
|
-
*/
|
|
5803
|
-
function TaonEntity(options) {
|
|
5804
|
-
return function (constructor) {
|
|
5805
|
-
options = options || {};
|
|
5806
|
-
options.uniqueKeyProp = options.uniqueKeyProp || 'id';
|
|
5807
|
-
if (!options.className) {
|
|
5808
|
-
const nameForClass = constructor?.name || 'AnyClass';
|
|
5809
|
-
throw `Please define 'classname' property inside decorator of class '${nameForClass}':
|
|
5810
|
-
|
|
5811
|
-
@TaonEntity({
|
|
5812
|
-
className: '${nameForClass}'
|
|
5813
|
-
})
|
|
5814
|
-
class ${constructor?.name} {
|
|
5815
|
-
//...
|
|
5816
|
-
|
|
5817
|
-
`;
|
|
5818
|
-
}
|
|
5819
|
-
ClassHelpers.setName(constructor, options?.className);
|
|
5820
|
-
DefaultMapping(options?.defaultModelMapping)(constructor);
|
|
5821
|
-
DefaultModel(options.defaultModelMapping)(constructor);
|
|
5822
|
-
Reflect.defineMetadata(Symbols.metadata.options.entity, options, constructor);
|
|
5823
|
-
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
5824
|
-
//#region @websql
|
|
5825
|
-
Entity(options?.className)(constructor);
|
|
5826
|
-
//#endregion
|
|
5827
|
-
CLASS.setName(constructor, options?.className); // TODO QUICK_FIX for ng2-rest
|
|
5828
|
-
};
|
|
5829
|
-
}
|
|
5830
|
-
class TaonEntityOptions extends DecoratorAbstractOpt {
|
|
5831
|
-
}
|
|
5832
|
-
|
|
5833
|
-
var TaonGlobalStateStatus;
|
|
5834
|
-
(function (TaonGlobalStateStatus) {
|
|
5835
|
-
TaonGlobalStateStatus["NORMAL"] = "normal";
|
|
5836
|
-
/**
|
|
5837
|
-
* no new transactions allowed
|
|
5838
|
-
* existing ones may finish
|
|
5839
|
-
*/
|
|
5840
|
-
TaonGlobalStateStatus["DRAINING"] = "draining";
|
|
5841
|
-
/**
|
|
5842
|
-
* DB is readonly
|
|
5843
|
-
* app is readonly (no writes, no side effects)
|
|
5844
|
-
*/
|
|
5845
|
-
TaonGlobalStateStatus["READONLY"] = "readonly";
|
|
5846
|
-
/**
|
|
5847
|
-
* Db and app still readonly - migration in progress
|
|
5848
|
-
*/
|
|
5849
|
-
TaonGlobalStateStatus["MIGRATING"] = "migrating";
|
|
5850
|
-
/**
|
|
5851
|
-
* emergency stop / maintenance mode
|
|
5852
|
-
*/
|
|
5853
|
-
TaonGlobalStateStatus["FROZEN"] = "frozen";
|
|
5854
|
-
})(TaonGlobalStateStatus || (TaonGlobalStateStatus = {}));
|
|
5855
|
-
const allowedTaonGlobalStatusOrders = {
|
|
5856
|
-
[TaonGlobalStateStatus.NORMAL]: [
|
|
5857
|
-
TaonGlobalStateStatus.DRAINING,
|
|
5858
|
-
TaonGlobalStateStatus.FROZEN,
|
|
5859
|
-
],
|
|
5860
|
-
[TaonGlobalStateStatus.DRAINING]: [
|
|
5861
|
-
TaonGlobalStateStatus.READONLY,
|
|
5862
|
-
TaonGlobalStateStatus.FROZEN,
|
|
5863
|
-
],
|
|
5864
|
-
[TaonGlobalStateStatus.READONLY]: [
|
|
5865
|
-
TaonGlobalStateStatus.MIGRATING,
|
|
5866
|
-
TaonGlobalStateStatus.NORMAL,
|
|
5867
|
-
TaonGlobalStateStatus.FROZEN,
|
|
5868
|
-
],
|
|
5869
|
-
[TaonGlobalStateStatus.MIGRATING]: [
|
|
5870
|
-
TaonGlobalStateStatus.READONLY
|
|
5871
|
-
],
|
|
5872
|
-
[TaonGlobalStateStatus.FROZEN]: [
|
|
5873
|
-
TaonGlobalStateStatus.READONLY,
|
|
5874
|
-
TaonGlobalStateStatus.NORMAL,
|
|
5875
|
-
],
|
|
5876
|
-
};
|
|
5877
|
-
|
|
5878
|
-
const TaonGlobalStateDefaultsValues = {
|
|
5879
|
-
description: '',
|
|
5880
|
-
version: 0,
|
|
5881
|
-
id: void 0,
|
|
5882
|
-
status: TaonGlobalStateStatus.NORMAL,
|
|
5883
|
-
};
|
|
5884
|
-
|
|
5885
|
-
//#region imports
|
|
5886
|
-
//#endregion
|
|
5887
|
-
let TAON_GLOBAL_STATE = class TAON_GLOBAL_STATE extends TaonBaseAbstractEntity {
|
|
5888
|
-
};
|
|
5889
|
-
__decorate([
|
|
5890
|
-
Column({
|
|
5891
|
-
type: 'varchar',
|
|
5892
|
-
length: 20,
|
|
5893
|
-
nullable: false,
|
|
5894
|
-
default: TaonGlobalStateDefaultsValues.status,
|
|
5895
|
-
})
|
|
5896
|
-
//#endregion
|
|
5897
|
-
,
|
|
5898
|
-
__metadata("design:type", String)
|
|
5899
|
-
], TAON_GLOBAL_STATE.prototype, "status", void 0);
|
|
5900
|
-
__decorate([
|
|
5901
|
-
CreateDateColumn()
|
|
5902
|
-
//#endregion
|
|
5903
|
-
,
|
|
5904
|
-
__metadata("design:type", Date)
|
|
5905
|
-
], TAON_GLOBAL_STATE.prototype, "createdAt", void 0);
|
|
5906
|
-
__decorate([
|
|
5907
|
-
Column({
|
|
5908
|
-
type: 'int',
|
|
5909
|
-
nullable: true,
|
|
5910
|
-
})
|
|
5911
|
-
//#endregion
|
|
5912
|
-
,
|
|
5913
|
-
__metadata("design:type", Date)
|
|
5914
|
-
], TAON_GLOBAL_STATE.prototype, "secondsBeforeReadonly", void 0);
|
|
5915
|
-
TAON_GLOBAL_STATE = __decorate([
|
|
5916
|
-
TaonEntity({
|
|
5917
|
-
className: 'TAON_GLOBAL_STATE',
|
|
5918
|
-
createTable: true,
|
|
5919
|
-
})
|
|
5920
|
-
], TAON_GLOBAL_STATE);
|
|
5921
|
-
|
|
5922
|
-
/**
|
|
5923
|
-
* Controller decorator
|
|
5924
|
-
*/
|
|
5925
|
-
function TaonController(options) {
|
|
5926
|
-
return function (constructor) {
|
|
5927
|
-
ClassHelpers.setName(constructor, options?.className);
|
|
5928
|
-
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
5929
|
-
const cfg = ClassHelpers.ensureClassConfig(constructor);
|
|
5930
|
-
options = options || {};
|
|
5931
|
-
cfg.className = options.className || constructor.name;
|
|
5932
|
-
cfg.path = options.path || '';
|
|
5933
|
-
cfg.realtime = options.realtime;
|
|
5934
|
-
cfg.middlewares = options.middlewares;
|
|
5935
|
-
};
|
|
5936
|
-
}
|
|
5937
|
-
|
|
5938
|
-
const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal) => {
|
|
5939
|
-
const methodConfig = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
5940
|
-
let options;
|
|
5941
|
-
if (typeof pathOrOptions === 'object') {
|
|
5942
|
-
options = pathOrOptions;
|
|
5943
|
-
pathOrOptions = options.path;
|
|
5944
|
-
pathIsGlobal = !!options.pathIsGlobal;
|
|
5945
|
-
path = options.path;
|
|
5946
|
-
}
|
|
5947
|
-
else {
|
|
5948
|
-
options = { pathOrOptions, pathIsGlobal };
|
|
5949
|
-
}
|
|
5950
|
-
const { overrideContentType, overrideResponseType, overrideExpressSendAsHtml, middlewares, } = options;
|
|
5951
|
-
methodConfig.methodName = propertyKey;
|
|
5952
|
-
methodConfig.middlewares = middlewares;
|
|
5953
|
-
methodConfig.type = method;
|
|
5954
|
-
if (!path) {
|
|
5955
|
-
let paramsPathConcatedPath = '';
|
|
5956
|
-
for (const key in methodConfig.parameters) {
|
|
5957
|
-
if (methodConfig.parameters.hasOwnProperty(key)) {
|
|
5958
|
-
const element = methodConfig.parameters[key];
|
|
5959
|
-
if (element.paramType === 'Path' &&
|
|
5960
|
-
_.isString(element.paramName) &&
|
|
5961
|
-
element.paramName.trim().length > 0) {
|
|
5962
|
-
paramsPathConcatedPath += `/${element.paramName}/:${element.paramName}`;
|
|
5963
|
-
}
|
|
5964
|
-
}
|
|
5965
|
-
}
|
|
5966
|
-
methodConfig.path = `/${propertyKey}${paramsPathConcatedPath}`;
|
|
5967
|
-
}
|
|
5968
|
-
else {
|
|
5969
|
-
methodConfig.path = path;
|
|
5970
|
-
}
|
|
5971
|
-
methodConfig.descriptor = descriptor;
|
|
5972
|
-
methodConfig.global = pathIsGlobal;
|
|
5973
|
-
methodConfig.contentType = overrideContentType;
|
|
5974
|
-
methodConfig.responseType = overrideResponseType;
|
|
5975
|
-
methodConfig.overrideExpressSendAsHtml = overrideExpressSendAsHtml;
|
|
5976
|
-
};
|
|
5977
|
-
function GET(pathOrOptions, pathIsGlobal = false) {
|
|
5978
|
-
return function (target, propertyKey, descriptor) {
|
|
5979
|
-
metaReq('get', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
5980
|
-
};
|
|
5981
|
-
}
|
|
5982
|
-
/**
|
|
5983
|
-
* Method for sending html website from text
|
|
5984
|
-
* Example
|
|
5985
|
-
*
|
|
5986
|
-
* ```ts
|
|
5987
|
-
* ...
|
|
5988
|
-
* // in your taon controller
|
|
5989
|
-
* ..Taon.Http.HTML()
|
|
5990
|
-
* sendHtmlDummyWebsite(): Taon.ResponseHtml {
|
|
5991
|
-
* return `
|
|
5992
|
-
<html>
|
|
5993
|
-
<head>
|
|
5994
|
-
<title>Dummy website</title>
|
|
5995
|
-
</head>
|
|
5996
|
-
<body>
|
|
5997
|
-
<h1>This is dummy website</h1>
|
|
5998
|
-
<p>Served as HTML string from Taon controller method</p>
|
|
5999
|
-
</body>
|
|
6000
|
-
</html>
|
|
6001
|
-
* `; *
|
|
6002
|
-
* }
|
|
6003
|
-
* ...
|
|
6004
|
-
* ```
|
|
6005
|
-
*/
|
|
6006
|
-
function HTML(pathOrOptions) {
|
|
6007
|
-
return function (target, propertyKey, descriptor) {
|
|
6008
|
-
const opt = pathOrOptions;
|
|
6009
|
-
opt.overrideExpressSendAsHtml = true;
|
|
6010
|
-
metaReq('get', opt, target, propertyKey, descriptor, pathOrOptions, opt.pathIsGlobal);
|
|
6011
|
-
};
|
|
6012
|
-
}
|
|
6013
|
-
function HEAD(pathOrOptions, pathIsGlobal = false) {
|
|
6014
|
-
return function (target, propertyKey, descriptor) {
|
|
6015
|
-
metaReq('head', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6016
|
-
};
|
|
6017
|
-
}
|
|
6018
|
-
function POST(pathOrOptions, pathIsGlobal = false) {
|
|
6019
|
-
return function (target, propertyKey, descriptor) {
|
|
6020
|
-
metaReq('post', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6021
|
-
};
|
|
6022
|
-
}
|
|
6023
|
-
function PUT(pathOrOptions, pathIsGlobal = false) {
|
|
6024
|
-
return function (target, propertyKey, descriptor) {
|
|
6025
|
-
metaReq('put', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6026
|
-
};
|
|
6027
|
-
}
|
|
6028
|
-
function PATCH(pathOrOptions, pathIsGlobal = false) {
|
|
6029
|
-
return function (target, propertyKey, descriptor) {
|
|
6030
|
-
metaReq('patch', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6031
|
-
};
|
|
6032
|
-
}
|
|
6033
|
-
function DELETE(pathOrOptions, pathIsGlobal = false) {
|
|
6034
|
-
return function (target, propertyKey, descriptor) {
|
|
6035
|
-
metaReq('delete', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6036
|
-
};
|
|
6037
|
-
}
|
|
6038
|
-
|
|
6039
|
-
function metaParam(param, name, expire, defaultValue = undefined, target, propertyKey, parameterIndex) {
|
|
6040
|
-
const methodCfg = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
6041
|
-
const nameKey = name ? name : param;
|
|
6042
|
-
// const key = name || `${param}_${parameterIndex}`;
|
|
6043
|
-
methodCfg.parameters[nameKey] = {
|
|
6044
|
-
index: parameterIndex,
|
|
6045
|
-
paramName: name,
|
|
6046
|
-
paramType: param,
|
|
6047
|
-
defaultType: defaultValue,
|
|
6048
|
-
expireInSeconds: expire,
|
|
6049
|
-
};
|
|
6050
|
-
// console.log('params updated', methodConfig);
|
|
6051
|
-
}
|
|
6052
|
-
/**
|
|
6053
|
-
* @deprecated use Taon.Http.Param.Path (is more safe and cleaner)
|
|
6054
|
-
*/
|
|
6055
|
-
function Path(name) {
|
|
6056
|
-
return function (target, propertyKey, parameterIndex) {
|
|
6057
|
-
metaParam('Path', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6058
|
-
};
|
|
6059
|
-
}
|
|
6060
|
-
function Query(name) {
|
|
6061
|
-
return function (target, propertyKey, parameterIndex) {
|
|
6062
|
-
metaParam('Query', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6063
|
-
};
|
|
6064
|
-
}
|
|
6065
|
-
function Cookie(name, expireInSecond = 3600) {
|
|
6066
|
-
return function (target, propertyKey, parameterIndex) {
|
|
6067
|
-
metaParam('Cookie', name, expireInSecond, {}, target, propertyKey, parameterIndex);
|
|
6068
|
-
};
|
|
6069
|
-
}
|
|
6070
|
-
function Header(name) {
|
|
6071
|
-
return function (target, propertyKey, parameterIndex) {
|
|
6072
|
-
metaParam('Header', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6073
|
-
};
|
|
6074
|
-
}
|
|
6075
|
-
function Body(name) {
|
|
6076
|
-
return function (target, propertyKey, parameterIndex) {
|
|
6077
|
-
metaParam('Body', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6078
|
-
};
|
|
6079
|
-
}
|
|
6080
|
-
|
|
6081
5845
|
/**
|
|
6082
5846
|
* Provider decorator
|
|
6083
5847
|
*/
|
|
@@ -6352,450 +6116,6 @@ TaonBaseFileUploadMiddleware = __decorate([
|
|
|
6352
6116
|
})
|
|
6353
6117
|
], TaonBaseFileUploadMiddleware);
|
|
6354
6118
|
|
|
6355
|
-
let TaonBaseController = class TaonBaseController extends TaonBaseInjector {
|
|
6356
|
-
/**
|
|
6357
|
-
* Hook that is called when taon app is inited
|
|
6358
|
-
* (all contexts are created and inited)
|
|
6359
|
-
*/
|
|
6360
|
-
async afterAllCtxInited(options) { }
|
|
6361
|
-
//#region upload form data to server
|
|
6362
|
-
uploadFormDataToServer(formData, queryParams) {
|
|
6363
|
-
/* */
|
|
6364
|
-
/* */
|
|
6365
|
-
/* */
|
|
6366
|
-
/* */
|
|
6367
|
-
/* */
|
|
6368
|
-
/* */
|
|
6369
|
-
/* */
|
|
6370
|
-
/* */
|
|
6371
|
-
/* */
|
|
6372
|
-
/* */
|
|
6373
|
-
/* */
|
|
6374
|
-
/* */
|
|
6375
|
-
/* */
|
|
6376
|
-
/* */
|
|
6377
|
-
/* */
|
|
6378
|
-
/* */
|
|
6379
|
-
/* */
|
|
6380
|
-
/* */
|
|
6381
|
-
/* */
|
|
6382
|
-
/* */
|
|
6383
|
-
/* */
|
|
6384
|
-
/* */
|
|
6385
|
-
/* */
|
|
6386
|
-
/* */
|
|
6387
|
-
/* */
|
|
6388
|
-
/* */
|
|
6389
|
-
return (void 0);
|
|
6390
|
-
}
|
|
6391
|
-
//#endregion
|
|
6392
|
-
//#region after file upload hook
|
|
6393
|
-
/**
|
|
6394
|
-
* Hook after file is uploaded
|
|
6395
|
-
* through `uploadFormDataToServer` or `uploadLocalFileToServer`
|
|
6396
|
-
*/
|
|
6397
|
-
afterFileUploadAction(file, queryParams) {
|
|
6398
|
-
// empty
|
|
6399
|
-
}
|
|
6400
|
-
//#region upload local file to server
|
|
6401
|
-
async uploadLocalFileToServer(absFilePath, options, queryParams) {
|
|
6402
|
-
/* */
|
|
6403
|
-
/* */
|
|
6404
|
-
/* */
|
|
6405
|
-
/* */
|
|
6406
|
-
/* */
|
|
6407
|
-
/* */
|
|
6408
|
-
/* */
|
|
6409
|
-
/* */
|
|
6410
|
-
/* */
|
|
6411
|
-
/* */
|
|
6412
|
-
/* */
|
|
6413
|
-
/* */
|
|
6414
|
-
/* */
|
|
6415
|
-
/* */
|
|
6416
|
-
return (void 0);
|
|
6417
|
-
}
|
|
6418
|
-
//#endregion
|
|
6419
|
-
// async check() {
|
|
6420
|
-
// await this._waitForProperStatusChange({
|
|
6421
|
-
// request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
6422
|
-
// statusCheck: resp => resp.body.json[0].ok,
|
|
6423
|
-
// });
|
|
6424
|
-
// }
|
|
6425
|
-
/**
|
|
6426
|
-
* Easy way to wait for status change with http (1s default) pooling.
|
|
6427
|
-
*
|
|
6428
|
-
* example (in sub class):
|
|
6429
|
-
* ```ts
|
|
6430
|
-
async check() {
|
|
6431
|
-
await this.waitForProperStatusChange({
|
|
6432
|
-
request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
6433
|
-
statusCheck: resp => resp.body.json[0].ok,
|
|
6434
|
-
});
|
|
6435
|
-
}
|
|
6436
|
-
* ```
|
|
6437
|
-
*/
|
|
6438
|
-
async _waitForProperStatusChange(options) {
|
|
6439
|
-
const poolingInterval = options.poolingInterval || 1000;
|
|
6440
|
-
const taonRequest = options.request;
|
|
6441
|
-
let maxTries = options.maxTries || Number.POSITIVE_INFINITY;
|
|
6442
|
-
let i = 0;
|
|
6443
|
-
let httpErrorsCount = 0;
|
|
6444
|
-
while (true) {
|
|
6445
|
-
await UtilsTerminal.waitMilliseconds(poolingInterval);
|
|
6446
|
-
try {
|
|
6447
|
-
const resp = await taonRequest({
|
|
6448
|
-
reqIndexNum: i,
|
|
6449
|
-
httpErrorsCount,
|
|
6450
|
-
});
|
|
6451
|
-
if (options.statusCheck && options.statusCheck(resp)) {
|
|
6452
|
-
return;
|
|
6453
|
-
}
|
|
6454
|
-
}
|
|
6455
|
-
catch (error) {
|
|
6456
|
-
httpErrorsCount++;
|
|
6457
|
-
if (options.loopRequestsOnBackendError) {
|
|
6458
|
-
const isProperTaonError = error instanceof HttpResponseError &&
|
|
6459
|
-
error.body.json[CoreModels.TaonHttpErrorCustomProp];
|
|
6460
|
-
const isHttpError = error instanceof HttpResponseError && !isProperTaonError;
|
|
6461
|
-
const isUnknownError = !(error instanceof HttpResponseError);
|
|
6462
|
-
const resBool = await options.loopRequestsOnBackendError({
|
|
6463
|
-
taonError: isProperTaonError ? error : void 0,
|
|
6464
|
-
unknownHttpError: isHttpError ? error : void 0,
|
|
6465
|
-
unknownError: isUnknownError ? error : void 0,
|
|
6466
|
-
reqIndexNum: i,
|
|
6467
|
-
httpErrorsCount,
|
|
6468
|
-
});
|
|
6469
|
-
if (resBool) {
|
|
6470
|
-
i++;
|
|
6471
|
-
continue;
|
|
6472
|
-
}
|
|
6473
|
-
else {
|
|
6474
|
-
return;
|
|
6475
|
-
}
|
|
6476
|
-
}
|
|
6477
|
-
if (httpErrorsCount >
|
|
6478
|
-
(options.allowedHttpErrors || Number.POSITIVE_INFINITY)) {
|
|
6479
|
-
throw new Error(`Too many http errors (${httpErrorsCount}) for "${options.actionName}".`);
|
|
6480
|
-
}
|
|
6481
|
-
}
|
|
6482
|
-
if (i++ > maxTries) {
|
|
6483
|
-
throw new Error(`Timeout waiting for "${options.actionName}" to be finished. Waited for ${maxTries} seconds`);
|
|
6484
|
-
}
|
|
6485
|
-
}
|
|
6486
|
-
}
|
|
6487
|
-
};
|
|
6488
|
-
__decorate([
|
|
6489
|
-
POST({
|
|
6490
|
-
overrideContentType: 'multipart/form-data',
|
|
6491
|
-
middlewares: ({ parentMiddlewares }) => ({
|
|
6492
|
-
...parentMiddlewares,
|
|
6493
|
-
TaonBaseFileUploadMiddleware,
|
|
6494
|
-
}),
|
|
6495
|
-
}),
|
|
6496
|
-
__param(0, Body()),
|
|
6497
|
-
__param(1, Query()),
|
|
6498
|
-
__metadata("design:type", Function),
|
|
6499
|
-
__metadata("design:paramtypes", [FormData, Object]),
|
|
6500
|
-
__metadata("design:returntype", Object)
|
|
6501
|
-
], TaonBaseController.prototype, "uploadFormDataToServer", null);
|
|
6502
|
-
TaonBaseController = __decorate([
|
|
6503
|
-
TaonController({
|
|
6504
|
-
className: 'TaonBaseController',
|
|
6505
|
-
})
|
|
6506
|
-
], TaonBaseController);
|
|
6507
|
-
|
|
6508
|
-
//#endregion
|
|
6509
|
-
/**
|
|
6510
|
-
* Please override property entityClassFn with entity class.
|
|
6511
|
-
*/
|
|
6512
|
-
let TaonBaseCrudController = class TaonBaseCrudController extends TaonBaseController {
|
|
6513
|
-
//#endregion
|
|
6514
|
-
//#region init
|
|
6515
|
-
async _() {
|
|
6516
|
-
if (!_.isFunction(this.entityClassResolveFn)) {
|
|
6517
|
-
Helpers.warn(`Skipping initing CRUD controller ${ClassHelpers.getName(this)} because entityClassResolveFn is not provided.`);
|
|
6518
|
-
return;
|
|
6519
|
-
}
|
|
6520
|
-
let entityClassFn = this.entityClassResolveFn();
|
|
6521
|
-
this.db = this.injectRepo(entityClassFn);
|
|
6522
|
-
if (entityClassFn) {
|
|
6523
|
-
const configEntity = Reflect.getMetadata(Symbols.metadata.options.entity, ClassHelpers.getClassFnFromObject(this));
|
|
6524
|
-
if (configEntity?.createTable === false) {
|
|
6525
|
-
Helpers.warn(`Table for entity ${ClassHelpers.getName(entityClassFn)} will not be created. Crud will not work properly.`);
|
|
6526
|
-
}
|
|
6527
|
-
}
|
|
6528
|
-
else {
|
|
6529
|
-
Helpers.error(`Entity class not provided for controller ${ClassHelpers.getName(this)}.
|
|
6530
|
-
|
|
6531
|
-
Please provide entity as class property entityClassFn:
|
|
6532
|
-
|
|
6533
|
-
class ${ClassHelpers.getName(this)} extends TaonBaseCrudController<Entity> {
|
|
6534
|
-
// ...
|
|
6535
|
-
entityClassResolveFn = ()=> MyEntityClass;
|
|
6536
|
-
// ...
|
|
6537
|
-
}
|
|
6538
|
-
|
|
6539
|
-
`);
|
|
6540
|
-
}
|
|
6541
|
-
await super._();
|
|
6542
|
-
}
|
|
6543
|
-
//#endregion
|
|
6544
|
-
//#region bufferd changes
|
|
6545
|
-
bufforedChanges(id, property, alreadyLength) {
|
|
6546
|
-
//#region @websqlFunc
|
|
6547
|
-
return async (request, response) => {
|
|
6548
|
-
const model = await this.db.getBy(id);
|
|
6549
|
-
if (model === void 0) {
|
|
6550
|
-
return;
|
|
6551
|
-
}
|
|
6552
|
-
Validators.preventUndefinedModel(model, id);
|
|
6553
|
-
let value = model[property];
|
|
6554
|
-
let result;
|
|
6555
|
-
if (_.isString(value) || _.isArray(value)) {
|
|
6556
|
-
result = value.slice(alreadyLength);
|
|
6557
|
-
}
|
|
6558
|
-
return result;
|
|
6559
|
-
};
|
|
6560
|
-
//#endregion
|
|
6561
|
-
}
|
|
6562
|
-
//#endregion
|
|
6563
|
-
//#region pagintation
|
|
6564
|
-
pagination(pageNumber = 1, pageSize = 10, search = '') {
|
|
6565
|
-
//#region @websqlFunc
|
|
6566
|
-
return async (request, response) => {
|
|
6567
|
-
if (this.db.repositoryExists) {
|
|
6568
|
-
const query = {
|
|
6569
|
-
page: pageNumber,
|
|
6570
|
-
take: pageSize,
|
|
6571
|
-
keyword: search,
|
|
6572
|
-
};
|
|
6573
|
-
// console.log({
|
|
6574
|
-
// query
|
|
6575
|
-
// })
|
|
6576
|
-
const take = query.take || 10;
|
|
6577
|
-
const page = query.page || 1;
|
|
6578
|
-
const skip = (page - 1) * take;
|
|
6579
|
-
const keyword = query.keyword || '';
|
|
6580
|
-
const [result, total] = await this.db.findAndCount({
|
|
6581
|
-
// where: { name: Like('%' + keyword + '%') },
|
|
6582
|
-
// order: { name: "DESC" },
|
|
6583
|
-
take: take,
|
|
6584
|
-
skip: skip,
|
|
6585
|
-
});
|
|
6586
|
-
response?.setHeader(Symbols.old.X_TOTAL_COUNT, total);
|
|
6587
|
-
// const lastPage = Math.ceil(total / take);
|
|
6588
|
-
// const nextPage = page + 1 > lastPage ? null : page + 1;
|
|
6589
|
-
// const prevPage = page - 1 < 1 ? null : page - 1;
|
|
6590
|
-
// console.log({
|
|
6591
|
-
// result,
|
|
6592
|
-
// total
|
|
6593
|
-
// })
|
|
6594
|
-
return result;
|
|
6595
|
-
}
|
|
6596
|
-
return [];
|
|
6597
|
-
};
|
|
6598
|
-
//#endregion
|
|
6599
|
-
}
|
|
6600
|
-
//#endregion
|
|
6601
|
-
//#region get all
|
|
6602
|
-
getAll() {
|
|
6603
|
-
//#region @websqlFunc
|
|
6604
|
-
return async (request, response) => {
|
|
6605
|
-
if (this.db.repositoryExists) {
|
|
6606
|
-
const { models, totalCount } = await this.db.getAll();
|
|
6607
|
-
response?.setHeader(Symbols.old.X_TOTAL_COUNT, totalCount);
|
|
6608
|
-
return models;
|
|
6609
|
-
}
|
|
6610
|
-
return [];
|
|
6611
|
-
};
|
|
6612
|
-
//#endregion
|
|
6613
|
-
}
|
|
6614
|
-
//#endregion
|
|
6615
|
-
//#region get by id
|
|
6616
|
-
getBy(id) {
|
|
6617
|
-
//#region @websqlFunc
|
|
6618
|
-
return async () => {
|
|
6619
|
-
const model = await this.db.getBy(id);
|
|
6620
|
-
return model;
|
|
6621
|
-
};
|
|
6622
|
-
//#endregion
|
|
6623
|
-
}
|
|
6624
|
-
//#endregion
|
|
6625
|
-
//#region update by id
|
|
6626
|
-
updateById(id, item) {
|
|
6627
|
-
//#region @websqlFunc
|
|
6628
|
-
return async () => {
|
|
6629
|
-
const model = await this.db.updateById(id, item);
|
|
6630
|
-
return model;
|
|
6631
|
-
};
|
|
6632
|
-
//#endregion
|
|
6633
|
-
}
|
|
6634
|
-
//#endregion
|
|
6635
|
-
//#region patch by id
|
|
6636
|
-
patchById(id, item) {
|
|
6637
|
-
//#region @websqlFunc
|
|
6638
|
-
return async () => {
|
|
6639
|
-
const model = await this.db.updateById(id, item);
|
|
6640
|
-
return model;
|
|
6641
|
-
};
|
|
6642
|
-
//#endregion
|
|
6643
|
-
}
|
|
6644
|
-
//#endregion
|
|
6645
|
-
//#region bulk update
|
|
6646
|
-
bulkUpdate(items) {
|
|
6647
|
-
//#region @websqlFunc
|
|
6648
|
-
return async () => {
|
|
6649
|
-
if (!Array.isArray(items) || items?.length === 0) {
|
|
6650
|
-
return [];
|
|
6651
|
-
}
|
|
6652
|
-
const { models } = await this.db.bulkUpdate(items);
|
|
6653
|
-
return models;
|
|
6654
|
-
};
|
|
6655
|
-
//#endregion
|
|
6656
|
-
}
|
|
6657
|
-
//#endregion
|
|
6658
|
-
//#region delete by id
|
|
6659
|
-
deleteById(id) {
|
|
6660
|
-
//#region @websqlFunc
|
|
6661
|
-
return async () => {
|
|
6662
|
-
const model = await this.db.deleteById(id);
|
|
6663
|
-
return model;
|
|
6664
|
-
};
|
|
6665
|
-
//#endregion
|
|
6666
|
-
}
|
|
6667
|
-
//#endregion
|
|
6668
|
-
//#region bulk delete
|
|
6669
|
-
bulkDelete(ids) {
|
|
6670
|
-
//#region @websqlFunc
|
|
6671
|
-
return async () => {
|
|
6672
|
-
const models = await this.db.bulkDelete(ids);
|
|
6673
|
-
return models;
|
|
6674
|
-
};
|
|
6675
|
-
//#endregion
|
|
6676
|
-
}
|
|
6677
|
-
//#endregion
|
|
6678
|
-
//#region bulk delete
|
|
6679
|
-
clearTable() {
|
|
6680
|
-
//#region @websqlFunc
|
|
6681
|
-
return async () => {
|
|
6682
|
-
await this.db.clear();
|
|
6683
|
-
};
|
|
6684
|
-
//#endregion
|
|
6685
|
-
}
|
|
6686
|
-
//#endregion
|
|
6687
|
-
//#region create
|
|
6688
|
-
save(item) {
|
|
6689
|
-
//#region @websqlFunc
|
|
6690
|
-
return async () => {
|
|
6691
|
-
const model = await this.db.save(item);
|
|
6692
|
-
return model;
|
|
6693
|
-
};
|
|
6694
|
-
//#endregion
|
|
6695
|
-
}
|
|
6696
|
-
//#endregion
|
|
6697
|
-
//#region bulk create
|
|
6698
|
-
bulkCreate(items) {
|
|
6699
|
-
//#region @websqlFunc
|
|
6700
|
-
return async () => {
|
|
6701
|
-
const models = await this.db.bulkCreate(items);
|
|
6702
|
-
return models;
|
|
6703
|
-
};
|
|
6704
|
-
//#endregion
|
|
6705
|
-
}
|
|
6706
|
-
};
|
|
6707
|
-
__decorate([
|
|
6708
|
-
GET(),
|
|
6709
|
-
__param(0, Query(`id`)),
|
|
6710
|
-
__param(1, Query(`property`)),
|
|
6711
|
-
__param(2, Query('alreadyLength')),
|
|
6712
|
-
__metadata("design:type", Function),
|
|
6713
|
-
__metadata("design:paramtypes", [Object, String, Number]),
|
|
6714
|
-
__metadata("design:returntype", Object)
|
|
6715
|
-
], TaonBaseCrudController.prototype, "bufforedChanges", null);
|
|
6716
|
-
__decorate([
|
|
6717
|
-
GET(),
|
|
6718
|
-
__param(0, Query('pageNumber')),
|
|
6719
|
-
__param(1, Query('pageSize')),
|
|
6720
|
-
__param(2, Query('search')),
|
|
6721
|
-
__metadata("design:type", Function),
|
|
6722
|
-
__metadata("design:paramtypes", [Number, Number, String]),
|
|
6723
|
-
__metadata("design:returntype", Object)
|
|
6724
|
-
], TaonBaseCrudController.prototype, "pagination", null);
|
|
6725
|
-
__decorate([
|
|
6726
|
-
GET(),
|
|
6727
|
-
__metadata("design:type", Function),
|
|
6728
|
-
__metadata("design:paramtypes", []),
|
|
6729
|
-
__metadata("design:returntype", Object)
|
|
6730
|
-
], TaonBaseCrudController.prototype, "getAll", null);
|
|
6731
|
-
__decorate([
|
|
6732
|
-
GET(),
|
|
6733
|
-
__param(0, Query(`id`)),
|
|
6734
|
-
__metadata("design:type", Function),
|
|
6735
|
-
__metadata("design:paramtypes", [Object]),
|
|
6736
|
-
__metadata("design:returntype", Object)
|
|
6737
|
-
], TaonBaseCrudController.prototype, "getBy", null);
|
|
6738
|
-
__decorate([
|
|
6739
|
-
PUT(),
|
|
6740
|
-
__param(0, Query(`id`)),
|
|
6741
|
-
__param(1, Body()),
|
|
6742
|
-
__metadata("design:type", Function),
|
|
6743
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
6744
|
-
__metadata("design:returntype", Object)
|
|
6745
|
-
], TaonBaseCrudController.prototype, "updateById", null);
|
|
6746
|
-
__decorate([
|
|
6747
|
-
PATCH(),
|
|
6748
|
-
__param(0, Query(`id`)),
|
|
6749
|
-
__param(1, Body()),
|
|
6750
|
-
__metadata("design:type", Function),
|
|
6751
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
6752
|
-
__metadata("design:returntype", Object)
|
|
6753
|
-
], TaonBaseCrudController.prototype, "patchById", null);
|
|
6754
|
-
__decorate([
|
|
6755
|
-
PUT(),
|
|
6756
|
-
__param(0, Body()),
|
|
6757
|
-
__metadata("design:type", Function),
|
|
6758
|
-
__metadata("design:paramtypes", [Array]),
|
|
6759
|
-
__metadata("design:returntype", Object)
|
|
6760
|
-
], TaonBaseCrudController.prototype, "bulkUpdate", null);
|
|
6761
|
-
__decorate([
|
|
6762
|
-
DELETE(),
|
|
6763
|
-
__param(0, Query(`id`)),
|
|
6764
|
-
__metadata("design:type", Function),
|
|
6765
|
-
__metadata("design:paramtypes", [Object]),
|
|
6766
|
-
__metadata("design:returntype", Object)
|
|
6767
|
-
], TaonBaseCrudController.prototype, "deleteById", null);
|
|
6768
|
-
__decorate([
|
|
6769
|
-
DELETE(),
|
|
6770
|
-
__param(0, Query(`ids`)),
|
|
6771
|
-
__metadata("design:type", Function),
|
|
6772
|
-
__metadata("design:paramtypes", [Array]),
|
|
6773
|
-
__metadata("design:returntype", Object)
|
|
6774
|
-
], TaonBaseCrudController.prototype, "bulkDelete", null);
|
|
6775
|
-
__decorate([
|
|
6776
|
-
DELETE(),
|
|
6777
|
-
__metadata("design:type", Function),
|
|
6778
|
-
__metadata("design:paramtypes", []),
|
|
6779
|
-
__metadata("design:returntype", Object)
|
|
6780
|
-
], TaonBaseCrudController.prototype, "clearTable", null);
|
|
6781
|
-
__decorate([
|
|
6782
|
-
POST(),
|
|
6783
|
-
__param(0, Body()),
|
|
6784
|
-
__metadata("design:type", Function),
|
|
6785
|
-
__metadata("design:paramtypes", [Object]),
|
|
6786
|
-
__metadata("design:returntype", Object)
|
|
6787
|
-
], TaonBaseCrudController.prototype, "save", null);
|
|
6788
|
-
__decorate([
|
|
6789
|
-
POST(),
|
|
6790
|
-
__param(0, Body()),
|
|
6791
|
-
__metadata("design:type", Function),
|
|
6792
|
-
__metadata("design:paramtypes", [Object]),
|
|
6793
|
-
__metadata("design:returntype", Object)
|
|
6794
|
-
], TaonBaseCrudController.prototype, "bulkCreate", null);
|
|
6795
|
-
TaonBaseCrudController = __decorate([
|
|
6796
|
-
TaonController({ className: 'TaonBaseCrudController' })
|
|
6797
|
-
], TaonBaseCrudController);
|
|
6798
|
-
|
|
6799
6119
|
/**
|
|
6800
6120
|
* Repository decorator
|
|
6801
6121
|
*/
|
|
@@ -7281,245 +6601,792 @@ let TaonBaseRepository = class TaonBaseRepository extends TaonBaseCustomReposito
|
|
|
7281
6601
|
findAndCountBy(where) {
|
|
7282
6602
|
return this.repo.findAndCountBy(where);
|
|
7283
6603
|
}
|
|
7284
|
-
//#endregion
|
|
7285
|
-
//#region crud operations / typeorm / find by ids
|
|
6604
|
+
//#endregion
|
|
6605
|
+
//#region crud operations / typeorm / find by ids
|
|
6606
|
+
/**
|
|
6607
|
+
* Finds entities with ids.
|
|
6608
|
+
* Optionally find options or conditions can be applied.
|
|
6609
|
+
*
|
|
6610
|
+
* @deprecated use `findBy` method instead in conjunction with `In` operator, for example:
|
|
6611
|
+
*
|
|
6612
|
+
* .findBy({
|
|
6613
|
+
* id: In([1, 2, 3])
|
|
6614
|
+
* })
|
|
6615
|
+
*/
|
|
6616
|
+
findByIds(ids) {
|
|
6617
|
+
return this.repo.findByIds(ids);
|
|
6618
|
+
}
|
|
6619
|
+
//#endregion
|
|
6620
|
+
//#region crud operations / typeorm / find one
|
|
6621
|
+
/**
|
|
6622
|
+
* Finds first entity by a given find options.
|
|
6623
|
+
* If entity was not found in the database - returns null.
|
|
6624
|
+
*/
|
|
6625
|
+
findOne(options) {
|
|
6626
|
+
return this.repo.findOne(options);
|
|
6627
|
+
}
|
|
6628
|
+
//#endregion
|
|
6629
|
+
//#region crud operations / typeorm / find one by
|
|
6630
|
+
/**
|
|
6631
|
+
* Finds first entity that matches given where condition.
|
|
6632
|
+
* If entity was not found in the database - returns null.
|
|
6633
|
+
*/
|
|
6634
|
+
findOneBy(where) {
|
|
6635
|
+
return this.repo.findOneBy(where);
|
|
6636
|
+
}
|
|
6637
|
+
//#endregion
|
|
6638
|
+
//#region crud operations / typeorm / find one or fail
|
|
6639
|
+
/**
|
|
6640
|
+
* Finds first entity that matches given id.
|
|
6641
|
+
* If entity was not found in the database - returns null.
|
|
6642
|
+
*
|
|
6643
|
+
* @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:
|
|
6644
|
+
*
|
|
6645
|
+
* .findOneBy({
|
|
6646
|
+
* id: 1 // where "id" is your primary column name
|
|
6647
|
+
* })
|
|
6648
|
+
*/
|
|
6649
|
+
findOneById(id) {
|
|
6650
|
+
return this.repo.findOneById(id);
|
|
6651
|
+
}
|
|
6652
|
+
//#endregion
|
|
6653
|
+
//#region crud operations / typeorm / find one or fail
|
|
6654
|
+
/**
|
|
6655
|
+
* Finds first entity by a given find options.
|
|
6656
|
+
* If entity was not found in the database - rejects with error.
|
|
6657
|
+
*/
|
|
6658
|
+
findOneOrFail(options) {
|
|
6659
|
+
return this.repo.findOneOrFail(options);
|
|
6660
|
+
}
|
|
6661
|
+
//#endregion
|
|
6662
|
+
//#region crud operations / typeorm / find one by or fail
|
|
6663
|
+
/**
|
|
6664
|
+
* Finds first entity that matches given where condition.
|
|
6665
|
+
* If entity was not found in the database - rejects with error.
|
|
6666
|
+
*/
|
|
6667
|
+
findOneByOrFail(where) {
|
|
6668
|
+
return this.repo.findOneByOrFail(where);
|
|
6669
|
+
}
|
|
6670
|
+
//#endregion
|
|
6671
|
+
//#region crud operations / typeorm / query
|
|
6672
|
+
/**
|
|
6673
|
+
* Executes a raw SQL query and returns a raw database results.
|
|
6674
|
+
* Raw query execution is supported only by relational databases (MongoDB is not supported).
|
|
6675
|
+
*/
|
|
6676
|
+
query(query, parameters) {
|
|
6677
|
+
return this.repo.query(query, parameters);
|
|
6678
|
+
}
|
|
6679
|
+
//#endregion
|
|
6680
|
+
//#region crud operations / typeorm / query
|
|
6681
|
+
/**
|
|
6682
|
+
* Executes a raw SQL query and returns a raw database results.
|
|
6683
|
+
* Raw query execution is supported only by relational databases (MongoDB is not supported).
|
|
6684
|
+
*/
|
|
6685
|
+
createQueryBuilder(alias, queryRunner) {
|
|
6686
|
+
return this.repo.createQueryBuilder(alias, queryRunner);
|
|
6687
|
+
}
|
|
6688
|
+
//#endregion
|
|
6689
|
+
//#region crud operations / typeorm / clear
|
|
6690
|
+
/**
|
|
6691
|
+
* Clears all the data from the given table/collection (truncates/drops it).
|
|
6692
|
+
*
|
|
6693
|
+
* Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
|
|
6694
|
+
* @see https://stackoverflow.com/a/5972738/925151
|
|
6695
|
+
*/
|
|
6696
|
+
clear() {
|
|
6697
|
+
return this.repo.clear();
|
|
6698
|
+
}
|
|
6699
|
+
//#endregion
|
|
6700
|
+
//#region crud operations / typeorm / increment
|
|
6701
|
+
/**
|
|
6702
|
+
* Increments some column by provided value of the entities matched given conditions.
|
|
6703
|
+
*/
|
|
6704
|
+
increment(conditions, propertyPath, value) {
|
|
6705
|
+
return this.repo.increment(conditions, propertyPath, value);
|
|
6706
|
+
}
|
|
6707
|
+
//#endregion
|
|
6708
|
+
//#region crud operations / typeorm / decrement
|
|
6709
|
+
/**
|
|
6710
|
+
* Decrements some column by provided value of the entities matched given conditions.
|
|
6711
|
+
*/
|
|
6712
|
+
decrement(conditions, propertyPath, value) {
|
|
6713
|
+
return this.repo.decrement(conditions, propertyPath, value);
|
|
6714
|
+
}
|
|
6715
|
+
//#endregion
|
|
6716
|
+
//#region crud operations / get all
|
|
6717
|
+
/**
|
|
6718
|
+
* @deprecated use findAndCount instead
|
|
6719
|
+
*/
|
|
6720
|
+
async getAll() {
|
|
6721
|
+
//#region @websqlFunc
|
|
6722
|
+
// console.log('repo', this.__repository);
|
|
6723
|
+
// console.log(
|
|
6724
|
+
// `repo taget name "${ClassHelpers.getName(this.__repository.target)}"`,
|
|
6725
|
+
// );
|
|
6726
|
+
// debugger;
|
|
6727
|
+
const totalCount = await this.repo.count();
|
|
6728
|
+
const models = await this.repo.find();
|
|
6729
|
+
// console.log('models', models);
|
|
6730
|
+
// console.log('totalCount', totalCount);
|
|
6731
|
+
return { models, totalCount };
|
|
6732
|
+
//#endregion
|
|
6733
|
+
}
|
|
6734
|
+
//#endregion
|
|
6735
|
+
//#region crud operations / get by id
|
|
6736
|
+
async getBy(id) {
|
|
6737
|
+
//#region @websqlFunc
|
|
6738
|
+
const model = await await this.repo.findOne({
|
|
6739
|
+
where: { id },
|
|
6740
|
+
});
|
|
6741
|
+
return model;
|
|
6742
|
+
//#endregion
|
|
6743
|
+
}
|
|
6744
|
+
};
|
|
6745
|
+
TaonBaseRepository = __decorate([
|
|
6746
|
+
TaonRepository({ className: 'TaonBaseRepository' }),
|
|
6747
|
+
__metadata("design:paramtypes", [Function])
|
|
6748
|
+
], TaonBaseRepository);
|
|
6749
|
+
|
|
6750
|
+
const TaonBaseContext = createContext(() => ({
|
|
6751
|
+
contextName: 'TaonBaseContext',
|
|
6752
|
+
abstract: true,
|
|
6753
|
+
contexts: {
|
|
6754
|
+
// TaonGlobalStateContext,
|
|
6755
|
+
},
|
|
6756
|
+
middlewares: {
|
|
6757
|
+
TaonBaseFileUploadMiddleware,
|
|
6758
|
+
},
|
|
6759
|
+
repositories: {
|
|
6760
|
+
// @ts-ignore
|
|
6761
|
+
TaonBaseRepository,
|
|
6762
|
+
},
|
|
6763
|
+
}));
|
|
6764
|
+
|
|
6765
|
+
var baseContext = /*#__PURE__*/Object.freeze({
|
|
6766
|
+
__proto__: null,
|
|
6767
|
+
TaonBaseContext: TaonBaseContext
|
|
6768
|
+
});
|
|
6769
|
+
|
|
6770
|
+
/**
|
|
6771
|
+
* Controller decorator
|
|
6772
|
+
*/
|
|
6773
|
+
function TaonController(options) {
|
|
6774
|
+
return function (constructor) {
|
|
6775
|
+
ClassHelpers.setName(constructor, options?.className);
|
|
6776
|
+
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
6777
|
+
const cfg = ClassHelpers.ensureClassConfig(constructor);
|
|
6778
|
+
options = options || {};
|
|
6779
|
+
cfg.className = options.className || constructor.name;
|
|
6780
|
+
cfg.path = options.path || '';
|
|
6781
|
+
cfg.realtime = options.realtime;
|
|
6782
|
+
cfg.middlewares = options.middlewares;
|
|
6783
|
+
};
|
|
6784
|
+
}
|
|
6785
|
+
|
|
6786
|
+
const metaReq = (method, path, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal) => {
|
|
6787
|
+
const methodConfig = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
6788
|
+
let options;
|
|
6789
|
+
if (typeof pathOrOptions === 'object') {
|
|
6790
|
+
options = pathOrOptions;
|
|
6791
|
+
pathOrOptions = options.path;
|
|
6792
|
+
pathIsGlobal = !!options.pathIsGlobal;
|
|
6793
|
+
path = options.path;
|
|
6794
|
+
}
|
|
6795
|
+
else {
|
|
6796
|
+
options = { pathOrOptions, pathIsGlobal };
|
|
6797
|
+
}
|
|
6798
|
+
const { overrideContentType, overrideResponseType, overrideExpressSendAsHtml, middlewares, } = options;
|
|
6799
|
+
methodConfig.methodName = propertyKey;
|
|
6800
|
+
methodConfig.middlewares = middlewares;
|
|
6801
|
+
methodConfig.type = method;
|
|
6802
|
+
if (!path) {
|
|
6803
|
+
let paramsPathConcatedPath = '';
|
|
6804
|
+
for (const key in methodConfig.parameters) {
|
|
6805
|
+
if (methodConfig.parameters.hasOwnProperty(key)) {
|
|
6806
|
+
const element = methodConfig.parameters[key];
|
|
6807
|
+
if (element.paramType === 'Path' &&
|
|
6808
|
+
_.isString(element.paramName) &&
|
|
6809
|
+
element.paramName.trim().length > 0) {
|
|
6810
|
+
paramsPathConcatedPath += `/${element.paramName}/:${element.paramName}`;
|
|
6811
|
+
}
|
|
6812
|
+
}
|
|
6813
|
+
}
|
|
6814
|
+
methodConfig.path = `/${propertyKey}${paramsPathConcatedPath}`;
|
|
6815
|
+
}
|
|
6816
|
+
else {
|
|
6817
|
+
methodConfig.path = path;
|
|
6818
|
+
}
|
|
6819
|
+
methodConfig.descriptor = descriptor;
|
|
6820
|
+
methodConfig.global = pathIsGlobal;
|
|
6821
|
+
methodConfig.contentType = overrideContentType;
|
|
6822
|
+
methodConfig.responseType = overrideResponseType;
|
|
6823
|
+
methodConfig.overrideExpressSendAsHtml = overrideExpressSendAsHtml;
|
|
6824
|
+
};
|
|
6825
|
+
function GET(pathOrOptions, pathIsGlobal = false) {
|
|
6826
|
+
return function (target, propertyKey, descriptor) {
|
|
6827
|
+
metaReq('get', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6828
|
+
};
|
|
6829
|
+
}
|
|
6830
|
+
/**
|
|
6831
|
+
* Method for sending html website from text
|
|
6832
|
+
* Example
|
|
6833
|
+
*
|
|
6834
|
+
* ```ts
|
|
6835
|
+
* ...
|
|
6836
|
+
* // in your taon controller
|
|
6837
|
+
* ..Taon.Http.HTML()
|
|
6838
|
+
* sendHtmlDummyWebsite(): Taon.ResponseHtml {
|
|
6839
|
+
* return `
|
|
6840
|
+
<html>
|
|
6841
|
+
<head>
|
|
6842
|
+
<title>Dummy website</title>
|
|
6843
|
+
</head>
|
|
6844
|
+
<body>
|
|
6845
|
+
<h1>This is dummy website</h1>
|
|
6846
|
+
<p>Served as HTML string from Taon controller method</p>
|
|
6847
|
+
</body>
|
|
6848
|
+
</html>
|
|
6849
|
+
* `; *
|
|
6850
|
+
* }
|
|
6851
|
+
* ...
|
|
6852
|
+
* ```
|
|
6853
|
+
*/
|
|
6854
|
+
function HTML(pathOrOptions) {
|
|
6855
|
+
return function (target, propertyKey, descriptor) {
|
|
6856
|
+
const opt = pathOrOptions;
|
|
6857
|
+
opt.overrideExpressSendAsHtml = true;
|
|
6858
|
+
metaReq('get', opt, target, propertyKey, descriptor, pathOrOptions, opt.pathIsGlobal);
|
|
6859
|
+
};
|
|
6860
|
+
}
|
|
6861
|
+
function HEAD(pathOrOptions, pathIsGlobal = false) {
|
|
6862
|
+
return function (target, propertyKey, descriptor) {
|
|
6863
|
+
metaReq('head', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6864
|
+
};
|
|
6865
|
+
}
|
|
6866
|
+
function POST(pathOrOptions, pathIsGlobal = false) {
|
|
6867
|
+
return function (target, propertyKey, descriptor) {
|
|
6868
|
+
metaReq('post', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6869
|
+
};
|
|
6870
|
+
}
|
|
6871
|
+
function PUT(pathOrOptions, pathIsGlobal = false) {
|
|
6872
|
+
return function (target, propertyKey, descriptor) {
|
|
6873
|
+
metaReq('put', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6874
|
+
};
|
|
6875
|
+
}
|
|
6876
|
+
function PATCH(pathOrOptions, pathIsGlobal = false) {
|
|
6877
|
+
return function (target, propertyKey, descriptor) {
|
|
6878
|
+
metaReq('patch', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6879
|
+
};
|
|
6880
|
+
}
|
|
6881
|
+
function DELETE(pathOrOptions, pathIsGlobal = false) {
|
|
6882
|
+
return function (target, propertyKey, descriptor) {
|
|
6883
|
+
metaReq('delete', pathOrOptions, target, propertyKey, descriptor, pathOrOptions, pathIsGlobal);
|
|
6884
|
+
};
|
|
6885
|
+
}
|
|
6886
|
+
|
|
6887
|
+
function metaParam(param, name, expire, defaultValue = undefined, target, propertyKey, parameterIndex) {
|
|
6888
|
+
const methodCfg = ClassHelpers.ensureMethodConfig(target, propertyKey);
|
|
6889
|
+
const nameKey = name ? name : param;
|
|
6890
|
+
// const key = name || `${param}_${parameterIndex}`;
|
|
6891
|
+
methodCfg.parameters[nameKey] = {
|
|
6892
|
+
index: parameterIndex,
|
|
6893
|
+
paramName: name,
|
|
6894
|
+
paramType: param,
|
|
6895
|
+
defaultType: defaultValue,
|
|
6896
|
+
expireInSeconds: expire,
|
|
6897
|
+
};
|
|
6898
|
+
// console.log('params updated', methodConfig);
|
|
6899
|
+
}
|
|
6900
|
+
/**
|
|
6901
|
+
* @deprecated use Taon.Http.Param.Path (is more safe and cleaner)
|
|
6902
|
+
*/
|
|
6903
|
+
function Path(name) {
|
|
6904
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6905
|
+
metaParam('Path', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6906
|
+
};
|
|
6907
|
+
}
|
|
6908
|
+
function Query(name) {
|
|
6909
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6910
|
+
metaParam('Query', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6911
|
+
};
|
|
6912
|
+
}
|
|
6913
|
+
function Cookie(name, expireInSecond = 3600) {
|
|
6914
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6915
|
+
metaParam('Cookie', name, expireInSecond, {}, target, propertyKey, parameterIndex);
|
|
6916
|
+
};
|
|
6917
|
+
}
|
|
6918
|
+
function Header(name) {
|
|
6919
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6920
|
+
metaParam('Header', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6921
|
+
};
|
|
6922
|
+
}
|
|
6923
|
+
function Body(name) {
|
|
6924
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6925
|
+
metaParam('Body', name, undefined, {}, target, propertyKey, parameterIndex);
|
|
6926
|
+
};
|
|
6927
|
+
}
|
|
6928
|
+
|
|
6929
|
+
let TaonBaseController = class TaonBaseController extends TaonBaseInjector {
|
|
7286
6930
|
/**
|
|
7287
|
-
*
|
|
7288
|
-
*
|
|
7289
|
-
*
|
|
7290
|
-
* @deprecated use `findBy` method instead in conjunction with `In` operator, for example:
|
|
7291
|
-
*
|
|
7292
|
-
* .findBy({
|
|
7293
|
-
* id: In([1, 2, 3])
|
|
7294
|
-
* })
|
|
6931
|
+
* Hook that is called when taon app is inited
|
|
6932
|
+
* (all contexts are created and inited)
|
|
7295
6933
|
*/
|
|
7296
|
-
|
|
7297
|
-
|
|
6934
|
+
async afterAllCtxInited(options) { }
|
|
6935
|
+
//#region upload form data to server
|
|
6936
|
+
uploadFormDataToServer(formData, queryParams) {
|
|
6937
|
+
/* */
|
|
6938
|
+
/* */
|
|
6939
|
+
/* */
|
|
6940
|
+
/* */
|
|
6941
|
+
/* */
|
|
6942
|
+
/* */
|
|
6943
|
+
/* */
|
|
6944
|
+
/* */
|
|
6945
|
+
/* */
|
|
6946
|
+
/* */
|
|
6947
|
+
/* */
|
|
6948
|
+
/* */
|
|
6949
|
+
/* */
|
|
6950
|
+
/* */
|
|
6951
|
+
/* */
|
|
6952
|
+
/* */
|
|
6953
|
+
/* */
|
|
6954
|
+
/* */
|
|
6955
|
+
/* */
|
|
6956
|
+
/* */
|
|
6957
|
+
/* */
|
|
6958
|
+
/* */
|
|
6959
|
+
/* */
|
|
6960
|
+
/* */
|
|
6961
|
+
/* */
|
|
6962
|
+
/* */
|
|
6963
|
+
return (void 0);
|
|
7298
6964
|
}
|
|
7299
6965
|
//#endregion
|
|
7300
|
-
//#region
|
|
6966
|
+
//#region after file upload hook
|
|
7301
6967
|
/**
|
|
7302
|
-
*
|
|
7303
|
-
*
|
|
6968
|
+
* Hook after file is uploaded
|
|
6969
|
+
* through `uploadFormDataToServer` or `uploadLocalFileToServer`
|
|
7304
6970
|
*/
|
|
7305
|
-
|
|
7306
|
-
|
|
6971
|
+
afterFileUploadAction(file, queryParams) {
|
|
6972
|
+
// empty
|
|
7307
6973
|
}
|
|
7308
|
-
//#
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
6974
|
+
//#region upload local file to server
|
|
6975
|
+
async uploadLocalFileToServer(absFilePath, options, queryParams) {
|
|
6976
|
+
/* */
|
|
6977
|
+
/* */
|
|
6978
|
+
/* */
|
|
6979
|
+
/* */
|
|
6980
|
+
/* */
|
|
6981
|
+
/* */
|
|
6982
|
+
/* */
|
|
6983
|
+
/* */
|
|
6984
|
+
/* */
|
|
6985
|
+
/* */
|
|
6986
|
+
/* */
|
|
6987
|
+
/* */
|
|
6988
|
+
/* */
|
|
6989
|
+
/* */
|
|
6990
|
+
return (void 0);
|
|
7316
6991
|
}
|
|
7317
6992
|
//#endregion
|
|
7318
|
-
|
|
6993
|
+
// async check() {
|
|
6994
|
+
// await this._waitForProperStatusChange({
|
|
6995
|
+
// request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
6996
|
+
// statusCheck: resp => resp.body.json[0].ok,
|
|
6997
|
+
// });
|
|
6998
|
+
// }
|
|
7319
6999
|
/**
|
|
7320
|
-
*
|
|
7321
|
-
* If entity was not found in the database - returns null.
|
|
7322
|
-
*
|
|
7323
|
-
* @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:
|
|
7000
|
+
* Easy way to wait for status change with http (1s default) pooling.
|
|
7324
7001
|
*
|
|
7325
|
-
*
|
|
7326
|
-
*
|
|
7327
|
-
|
|
7002
|
+
* example (in sub class):
|
|
7003
|
+
* ```ts
|
|
7004
|
+
async check() {
|
|
7005
|
+
await this.waitForProperStatusChange({
|
|
7006
|
+
request: () => this.uploadFormDataToServer(void 0, void 0).request(),
|
|
7007
|
+
statusCheck: resp => resp.body.json[0].ok,
|
|
7008
|
+
});
|
|
7009
|
+
}
|
|
7010
|
+
* ```
|
|
7328
7011
|
*/
|
|
7329
|
-
|
|
7330
|
-
|
|
7012
|
+
async _waitForProperStatusChange(options) {
|
|
7013
|
+
const poolingInterval = options.poolingInterval || 1000;
|
|
7014
|
+
const taonRequest = options.request;
|
|
7015
|
+
let maxTries = options.maxTries || Number.POSITIVE_INFINITY;
|
|
7016
|
+
let i = 0;
|
|
7017
|
+
let httpErrorsCount = 0;
|
|
7018
|
+
while (true) {
|
|
7019
|
+
await UtilsTerminal.waitMilliseconds(poolingInterval);
|
|
7020
|
+
try {
|
|
7021
|
+
const resp = await taonRequest({
|
|
7022
|
+
reqIndexNum: i,
|
|
7023
|
+
httpErrorsCount,
|
|
7024
|
+
});
|
|
7025
|
+
if (options.statusCheck && options.statusCheck(resp)) {
|
|
7026
|
+
return;
|
|
7027
|
+
}
|
|
7028
|
+
}
|
|
7029
|
+
catch (error) {
|
|
7030
|
+
httpErrorsCount++;
|
|
7031
|
+
if (options.loopRequestsOnBackendError) {
|
|
7032
|
+
const isProperTaonError = error instanceof HttpResponseError &&
|
|
7033
|
+
error.body.json[CoreModels.TaonHttpErrorCustomProp];
|
|
7034
|
+
const isHttpError = error instanceof HttpResponseError && !isProperTaonError;
|
|
7035
|
+
const isUnknownError = !(error instanceof HttpResponseError);
|
|
7036
|
+
const resBool = await options.loopRequestsOnBackendError({
|
|
7037
|
+
taonError: isProperTaonError ? error : void 0,
|
|
7038
|
+
unknownHttpError: isHttpError ? error : void 0,
|
|
7039
|
+
unknownError: isUnknownError ? error : void 0,
|
|
7040
|
+
reqIndexNum: i,
|
|
7041
|
+
httpErrorsCount,
|
|
7042
|
+
});
|
|
7043
|
+
if (resBool) {
|
|
7044
|
+
i++;
|
|
7045
|
+
continue;
|
|
7046
|
+
}
|
|
7047
|
+
else {
|
|
7048
|
+
return;
|
|
7049
|
+
}
|
|
7050
|
+
}
|
|
7051
|
+
if (httpErrorsCount >
|
|
7052
|
+
(options.allowedHttpErrors || Number.POSITIVE_INFINITY)) {
|
|
7053
|
+
throw new Error(`Too many http errors (${httpErrorsCount}) for "${options.actionName}".`);
|
|
7054
|
+
}
|
|
7055
|
+
}
|
|
7056
|
+
if (i++ > maxTries) {
|
|
7057
|
+
throw new Error(`Timeout waiting for "${options.actionName}" to be finished. Waited for ${maxTries} seconds`);
|
|
7058
|
+
}
|
|
7059
|
+
}
|
|
7331
7060
|
}
|
|
7061
|
+
};
|
|
7062
|
+
__decorate([
|
|
7063
|
+
POST({
|
|
7064
|
+
overrideContentType: 'multipart/form-data',
|
|
7065
|
+
middlewares: ({ parentMiddlewares }) => ({
|
|
7066
|
+
...parentMiddlewares,
|
|
7067
|
+
TaonBaseFileUploadMiddleware,
|
|
7068
|
+
}),
|
|
7069
|
+
}),
|
|
7070
|
+
__param(0, Body()),
|
|
7071
|
+
__param(1, Query()),
|
|
7072
|
+
__metadata("design:type", Function),
|
|
7073
|
+
__metadata("design:paramtypes", [FormData, Object]),
|
|
7074
|
+
__metadata("design:returntype", Object)
|
|
7075
|
+
], TaonBaseController.prototype, "uploadFormDataToServer", null);
|
|
7076
|
+
TaonBaseController = __decorate([
|
|
7077
|
+
TaonController({
|
|
7078
|
+
className: 'TaonBaseController',
|
|
7079
|
+
})
|
|
7080
|
+
], TaonBaseController);
|
|
7081
|
+
|
|
7082
|
+
//#endregion
|
|
7083
|
+
/**
|
|
7084
|
+
* Please override property entityClassFn with entity class.
|
|
7085
|
+
*/
|
|
7086
|
+
let TaonBaseCrudController = class TaonBaseCrudController extends TaonBaseController {
|
|
7332
7087
|
//#endregion
|
|
7333
|
-
//#region
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7088
|
+
//#region init
|
|
7089
|
+
async _() {
|
|
7090
|
+
if (!_.isFunction(this.entityClassResolveFn)) {
|
|
7091
|
+
Helpers.warn(`Skipping initing CRUD controller ${ClassHelpers.getName(this)} because entityClassResolveFn is not provided.`);
|
|
7092
|
+
return;
|
|
7093
|
+
}
|
|
7094
|
+
let entityClassFn = this.entityClassResolveFn();
|
|
7095
|
+
this.db = this.injectRepo(entityClassFn);
|
|
7096
|
+
if (entityClassFn) {
|
|
7097
|
+
const configEntity = Reflect.getMetadata(Symbols.metadata.options.entity, ClassHelpers.getClassFnFromObject(this));
|
|
7098
|
+
if (configEntity?.createTable === false) {
|
|
7099
|
+
Helpers.warn(`Table for entity ${ClassHelpers.getName(entityClassFn)} will not be created. Crud will not work properly.`);
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
7102
|
+
else {
|
|
7103
|
+
Helpers.error(`Entity class not provided for controller ${ClassHelpers.getName(this)}.
|
|
7104
|
+
|
|
7105
|
+
Please provide entity as class property entityClassFn:
|
|
7106
|
+
|
|
7107
|
+
class ${ClassHelpers.getName(this)} extends TaonBaseCrudController<Entity> {
|
|
7108
|
+
// ...
|
|
7109
|
+
entityClassResolveFn = ()=> MyEntityClass;
|
|
7110
|
+
// ...
|
|
7111
|
+
}
|
|
7112
|
+
|
|
7113
|
+
`);
|
|
7114
|
+
}
|
|
7115
|
+
await super._();
|
|
7340
7116
|
}
|
|
7341
7117
|
//#endregion
|
|
7342
|
-
//#region
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7118
|
+
//#region bufferd changes
|
|
7119
|
+
bufforedChanges(id, property, alreadyLength) {
|
|
7120
|
+
//#region @websqlFunc
|
|
7121
|
+
return async (request, response) => {
|
|
7122
|
+
const model = await this.db.getBy(id);
|
|
7123
|
+
if (model === void 0) {
|
|
7124
|
+
return;
|
|
7125
|
+
}
|
|
7126
|
+
Validators.preventUndefinedModel(model, id);
|
|
7127
|
+
let value = model[property];
|
|
7128
|
+
let result;
|
|
7129
|
+
if (_.isString(value) || _.isArray(value)) {
|
|
7130
|
+
result = value.slice(alreadyLength);
|
|
7131
|
+
}
|
|
7132
|
+
return result;
|
|
7133
|
+
};
|
|
7134
|
+
//#endregion
|
|
7349
7135
|
}
|
|
7350
7136
|
//#endregion
|
|
7351
|
-
//#region
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7137
|
+
//#region pagintation
|
|
7138
|
+
pagination(pageNumber = 1, pageSize = 10, search = '') {
|
|
7139
|
+
//#region @websqlFunc
|
|
7140
|
+
return async (request, response) => {
|
|
7141
|
+
if (this.db.repositoryExists) {
|
|
7142
|
+
const query = {
|
|
7143
|
+
page: pageNumber,
|
|
7144
|
+
take: pageSize,
|
|
7145
|
+
keyword: search,
|
|
7146
|
+
};
|
|
7147
|
+
// console.log({
|
|
7148
|
+
// query
|
|
7149
|
+
// })
|
|
7150
|
+
const take = query.take || 10;
|
|
7151
|
+
const page = query.page || 1;
|
|
7152
|
+
const skip = (page - 1) * take;
|
|
7153
|
+
const keyword = query.keyword || '';
|
|
7154
|
+
const [result, total] = await this.db.findAndCount({
|
|
7155
|
+
// where: { name: Like('%' + keyword + '%') },
|
|
7156
|
+
// order: { name: "DESC" },
|
|
7157
|
+
take: take,
|
|
7158
|
+
skip: skip,
|
|
7159
|
+
});
|
|
7160
|
+
response?.setHeader(Symbols.old.X_TOTAL_COUNT, total);
|
|
7161
|
+
// const lastPage = Math.ceil(total / take);
|
|
7162
|
+
// const nextPage = page + 1 > lastPage ? null : page + 1;
|
|
7163
|
+
// const prevPage = page - 1 < 1 ? null : page - 1;
|
|
7164
|
+
// console.log({
|
|
7165
|
+
// result,
|
|
7166
|
+
// total
|
|
7167
|
+
// })
|
|
7168
|
+
return result;
|
|
7169
|
+
}
|
|
7170
|
+
return [];
|
|
7171
|
+
};
|
|
7172
|
+
//#endregion
|
|
7358
7173
|
}
|
|
7359
7174
|
//#endregion
|
|
7360
|
-
//#region
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7175
|
+
//#region get all
|
|
7176
|
+
getAll() {
|
|
7177
|
+
//#region @websqlFunc
|
|
7178
|
+
return async (request, response) => {
|
|
7179
|
+
if (this.db.repositoryExists) {
|
|
7180
|
+
const { models, totalCount } = await this.db.getAll();
|
|
7181
|
+
response?.setHeader(Symbols.old.X_TOTAL_COUNT, totalCount);
|
|
7182
|
+
return models;
|
|
7183
|
+
}
|
|
7184
|
+
return [];
|
|
7185
|
+
};
|
|
7186
|
+
//#endregion
|
|
7367
7187
|
}
|
|
7368
7188
|
//#endregion
|
|
7369
|
-
//#region
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
return this.repo.clear();
|
|
7189
|
+
//#region get by id
|
|
7190
|
+
getBy(id) {
|
|
7191
|
+
//#region @websqlFunc
|
|
7192
|
+
return async () => {
|
|
7193
|
+
const model = await this.db.getBy(id);
|
|
7194
|
+
return model;
|
|
7195
|
+
};
|
|
7196
|
+
//#endregion
|
|
7378
7197
|
}
|
|
7379
7198
|
//#endregion
|
|
7380
|
-
//#region
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7199
|
+
//#region update by id
|
|
7200
|
+
updateById(id, item) {
|
|
7201
|
+
//#region @websqlFunc
|
|
7202
|
+
return async () => {
|
|
7203
|
+
const model = await this.db.updateById(id, item);
|
|
7204
|
+
return model;
|
|
7205
|
+
};
|
|
7206
|
+
//#endregion
|
|
7386
7207
|
}
|
|
7387
7208
|
//#endregion
|
|
7388
|
-
//#region
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7209
|
+
//#region patch by id
|
|
7210
|
+
patchById(id, item) {
|
|
7211
|
+
//#region @websqlFunc
|
|
7212
|
+
return async () => {
|
|
7213
|
+
const model = await this.db.updateById(id, item);
|
|
7214
|
+
return model;
|
|
7215
|
+
};
|
|
7216
|
+
//#endregion
|
|
7394
7217
|
}
|
|
7395
7218
|
//#endregion
|
|
7396
|
-
//#region
|
|
7397
|
-
|
|
7398
|
-
* @deprecated use findAndCount instead
|
|
7399
|
-
*/
|
|
7400
|
-
async getAll() {
|
|
7219
|
+
//#region bulk update
|
|
7220
|
+
bulkUpdate(items) {
|
|
7401
7221
|
//#region @websqlFunc
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
// console.log('models', models);
|
|
7410
|
-
// console.log('totalCount', totalCount);
|
|
7411
|
-
return { models, totalCount };
|
|
7222
|
+
return async () => {
|
|
7223
|
+
if (!Array.isArray(items) || items?.length === 0) {
|
|
7224
|
+
return [];
|
|
7225
|
+
}
|
|
7226
|
+
const { models } = await this.db.bulkUpdate(items);
|
|
7227
|
+
return models;
|
|
7228
|
+
};
|
|
7412
7229
|
//#endregion
|
|
7413
7230
|
}
|
|
7414
7231
|
//#endregion
|
|
7415
|
-
//#region
|
|
7416
|
-
|
|
7232
|
+
//#region delete by id
|
|
7233
|
+
deleteById(id) {
|
|
7417
7234
|
//#region @websqlFunc
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7235
|
+
return async () => {
|
|
7236
|
+
const model = await this.db.deleteById(id);
|
|
7237
|
+
return model;
|
|
7238
|
+
};
|
|
7422
7239
|
//#endregion
|
|
7423
7240
|
}
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
__metadata("design:paramtypes", [Function])
|
|
7428
|
-
], TaonBaseRepository);
|
|
7429
|
-
|
|
7430
|
-
var TaonGlobalStateUtils;
|
|
7431
|
-
(function (TaonGlobalStateUtils) {
|
|
7432
|
-
// export function isActive(state: string): state is TaonGlobalStateStatus {
|
|
7433
|
-
// return state === 'active';
|
|
7434
|
-
// }
|
|
7435
|
-
TaonGlobalStateUtils.assertAllowedTransition = (from, to) => {
|
|
7436
|
-
if (!allowedTaonGlobalStatusOrders[from]?.includes(to)) {
|
|
7437
|
-
throw new Error(`Invalid state transition: ${from} → ${to}`);
|
|
7438
|
-
}
|
|
7439
|
-
};
|
|
7440
|
-
})(TaonGlobalStateUtils || (TaonGlobalStateUtils = {}));
|
|
7441
|
-
|
|
7442
|
-
//#region imports
|
|
7443
|
-
//#endregion
|
|
7444
|
-
let TaonGlobalStateRepository = class TaonGlobalStateRepository extends TaonBaseRepository {
|
|
7445
|
-
constructor() {
|
|
7446
|
-
super(...arguments);
|
|
7447
|
-
this.entityClassResolveFn = () => TAON_GLOBAL_STATE;
|
|
7448
|
-
}
|
|
7449
|
-
async getLastStatus() {
|
|
7241
|
+
//#endregion
|
|
7242
|
+
//#region bulk delete
|
|
7243
|
+
bulkDelete(ids) {
|
|
7450
7244
|
//#region @websqlFunc
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7245
|
+
return async () => {
|
|
7246
|
+
const models = await this.db.bulkDelete(ids);
|
|
7247
|
+
return models;
|
|
7248
|
+
};
|
|
7455
7249
|
//#endregion
|
|
7456
7250
|
}
|
|
7457
|
-
|
|
7251
|
+
//#endregion
|
|
7252
|
+
//#region bulk delete
|
|
7253
|
+
clearTable() {
|
|
7458
7254
|
//#region @websqlFunc
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
await this.transitionTo(TaonGlobalStateStatus.READONLY);
|
|
7463
|
-
}, secondsBeforeReadonly);
|
|
7464
|
-
}
|
|
7255
|
+
return async () => {
|
|
7256
|
+
await this.db.clear();
|
|
7257
|
+
};
|
|
7465
7258
|
//#endregion
|
|
7466
7259
|
}
|
|
7467
|
-
|
|
7260
|
+
//#endregion
|
|
7261
|
+
//#region create
|
|
7262
|
+
save(item) {
|
|
7468
7263
|
//#region @websqlFunc
|
|
7469
|
-
const current = await this.getLastStatus();
|
|
7470
|
-
TaonGlobalStateUtils.assertAllowedTransition(current.status, next);
|
|
7471
|
-
const newState = this.create({ status: next });
|
|
7472
|
-
await this.save(newState);
|
|
7473
|
-
return newState;
|
|
7474
|
-
//#endregion
|
|
7475
|
-
}
|
|
7476
|
-
};
|
|
7477
|
-
TaonGlobalStateRepository = __decorate([
|
|
7478
|
-
TaonRepository({
|
|
7479
|
-
className: 'TaonGlobalStateRepository',
|
|
7480
|
-
})
|
|
7481
|
-
], TaonGlobalStateRepository);
|
|
7482
|
-
|
|
7483
|
-
//#region imports
|
|
7484
|
-
//#endregion
|
|
7485
|
-
let TaonGlobalStateController = class TaonGlobalStateController extends TaonBaseCrudController {
|
|
7486
|
-
constructor() {
|
|
7487
|
-
super(...arguments);
|
|
7488
|
-
this.entityClassResolveFn = () => TAON_GLOBAL_STATE;
|
|
7489
|
-
this.taonGlobalStateRepository = this.injectCustomRepo(TaonGlobalStateRepository);
|
|
7490
|
-
}
|
|
7491
|
-
getStatus() {
|
|
7492
7264
|
return async () => {
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
return stateEntity.status;
|
|
7496
|
-
//#endregion
|
|
7265
|
+
const model = await this.db.save(item);
|
|
7266
|
+
return model;
|
|
7497
7267
|
};
|
|
7268
|
+
//#endregion
|
|
7498
7269
|
}
|
|
7499
|
-
|
|
7270
|
+
//#endregion
|
|
7271
|
+
//#region bulk create
|
|
7272
|
+
bulkCreate(items) {
|
|
7273
|
+
//#region @websqlFunc
|
|
7500
7274
|
return async () => {
|
|
7501
|
-
await this.
|
|
7275
|
+
const models = await this.db.bulkCreate(items);
|
|
7276
|
+
return models;
|
|
7502
7277
|
};
|
|
7278
|
+
//#endregion
|
|
7503
7279
|
}
|
|
7504
7280
|
};
|
|
7505
7281
|
__decorate([
|
|
7506
7282
|
GET(),
|
|
7283
|
+
__param(0, Query(`id`)),
|
|
7284
|
+
__param(1, Query(`property`)),
|
|
7285
|
+
__param(2, Query('alreadyLength')),
|
|
7286
|
+
__metadata("design:type", Function),
|
|
7287
|
+
__metadata("design:paramtypes", [Object, String, Number]),
|
|
7288
|
+
__metadata("design:returntype", Object)
|
|
7289
|
+
], TaonBaseCrudController.prototype, "bufforedChanges", null);
|
|
7290
|
+
__decorate([
|
|
7291
|
+
GET(),
|
|
7292
|
+
__param(0, Query('pageNumber')),
|
|
7293
|
+
__param(1, Query('pageSize')),
|
|
7294
|
+
__param(2, Query('search')),
|
|
7295
|
+
__metadata("design:type", Function),
|
|
7296
|
+
__metadata("design:paramtypes", [Number, Number, String]),
|
|
7297
|
+
__metadata("design:returntype", Object)
|
|
7298
|
+
], TaonBaseCrudController.prototype, "pagination", null);
|
|
7299
|
+
__decorate([
|
|
7300
|
+
GET(),
|
|
7301
|
+
__metadata("design:type", Function),
|
|
7302
|
+
__metadata("design:paramtypes", []),
|
|
7303
|
+
__metadata("design:returntype", Object)
|
|
7304
|
+
], TaonBaseCrudController.prototype, "getAll", null);
|
|
7305
|
+
__decorate([
|
|
7306
|
+
GET(),
|
|
7307
|
+
__param(0, Query(`id`)),
|
|
7308
|
+
__metadata("design:type", Function),
|
|
7309
|
+
__metadata("design:paramtypes", [Object]),
|
|
7310
|
+
__metadata("design:returntype", Object)
|
|
7311
|
+
], TaonBaseCrudController.prototype, "getBy", null);
|
|
7312
|
+
__decorate([
|
|
7313
|
+
PUT(),
|
|
7314
|
+
__param(0, Query(`id`)),
|
|
7315
|
+
__param(1, Body()),
|
|
7316
|
+
__metadata("design:type", Function),
|
|
7317
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
7318
|
+
__metadata("design:returntype", Object)
|
|
7319
|
+
], TaonBaseCrudController.prototype, "updateById", null);
|
|
7320
|
+
__decorate([
|
|
7321
|
+
PATCH(),
|
|
7322
|
+
__param(0, Query(`id`)),
|
|
7323
|
+
__param(1, Body()),
|
|
7324
|
+
__metadata("design:type", Function),
|
|
7325
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
7326
|
+
__metadata("design:returntype", Object)
|
|
7327
|
+
], TaonBaseCrudController.prototype, "patchById", null);
|
|
7328
|
+
__decorate([
|
|
7329
|
+
PUT(),
|
|
7330
|
+
__param(0, Body()),
|
|
7331
|
+
__metadata("design:type", Function),
|
|
7332
|
+
__metadata("design:paramtypes", [Array]),
|
|
7333
|
+
__metadata("design:returntype", Object)
|
|
7334
|
+
], TaonBaseCrudController.prototype, "bulkUpdate", null);
|
|
7335
|
+
__decorate([
|
|
7336
|
+
DELETE(),
|
|
7337
|
+
__param(0, Query(`id`)),
|
|
7338
|
+
__metadata("design:type", Function),
|
|
7339
|
+
__metadata("design:paramtypes", [Object]),
|
|
7340
|
+
__metadata("design:returntype", Object)
|
|
7341
|
+
], TaonBaseCrudController.prototype, "deleteById", null);
|
|
7342
|
+
__decorate([
|
|
7343
|
+
DELETE(),
|
|
7344
|
+
__param(0, Query(`ids`)),
|
|
7345
|
+
__metadata("design:type", Function),
|
|
7346
|
+
__metadata("design:paramtypes", [Array]),
|
|
7347
|
+
__metadata("design:returntype", Object)
|
|
7348
|
+
], TaonBaseCrudController.prototype, "bulkDelete", null);
|
|
7349
|
+
__decorate([
|
|
7350
|
+
DELETE(),
|
|
7507
7351
|
__metadata("design:type", Function),
|
|
7508
7352
|
__metadata("design:paramtypes", []),
|
|
7509
7353
|
__metadata("design:returntype", Object)
|
|
7510
|
-
],
|
|
7354
|
+
], TaonBaseCrudController.prototype, "clearTable", null);
|
|
7511
7355
|
__decorate([
|
|
7512
7356
|
POST(),
|
|
7513
|
-
__param(0,
|
|
7357
|
+
__param(0, Body()),
|
|
7514
7358
|
__metadata("design:type", Function),
|
|
7515
7359
|
__metadata("design:paramtypes", [Object]),
|
|
7516
7360
|
__metadata("design:returntype", Object)
|
|
7517
|
-
],
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7361
|
+
], TaonBaseCrudController.prototype, "save", null);
|
|
7362
|
+
__decorate([
|
|
7363
|
+
POST(),
|
|
7364
|
+
__param(0, Body()),
|
|
7365
|
+
__metadata("design:type", Function),
|
|
7366
|
+
__metadata("design:paramtypes", [Object]),
|
|
7367
|
+
__metadata("design:returntype", Object)
|
|
7368
|
+
], TaonBaseCrudController.prototype, "bulkCreate", null);
|
|
7369
|
+
TaonBaseCrudController = __decorate([
|
|
7370
|
+
TaonController({ className: 'TaonBaseCrudController' })
|
|
7371
|
+
], TaonBaseCrudController);
|
|
7372
|
+
|
|
7373
|
+
class TaonBaseMigration extends TaonBaseInjector {
|
|
7374
|
+
/**
|
|
7375
|
+
* by default is READY to run
|
|
7376
|
+
*/
|
|
7377
|
+
isReadyToRun() {
|
|
7378
|
+
return true;
|
|
7379
|
+
}
|
|
7380
|
+
getDescription() {
|
|
7381
|
+
return _.startCase(ClassHelpers.getName(this));
|
|
7382
|
+
}
|
|
7383
|
+
async up(queryRunner) {
|
|
7384
|
+
console.log(`[TaonBaseMigration] Running migration UP "${ClassHelpers.getName(this)}"`);
|
|
7385
|
+
}
|
|
7386
|
+
async down(queryRunner) {
|
|
7387
|
+
console.log(`[TaonBaseMigration] Running migration DOWN "${ClassHelpers.getName(this)}"`);
|
|
7388
|
+
}
|
|
7389
|
+
}
|
|
7523
7390
|
|
|
7524
7391
|
/**
|
|
7525
7392
|
* TODO
|
|
@@ -7529,39 +7396,6 @@ TaonGlobalStateController = __decorate([
|
|
|
7529
7396
|
class TaonBaseProvider extends TaonBaseInjector {
|
|
7530
7397
|
}
|
|
7531
7398
|
|
|
7532
|
-
/**
|
|
7533
|
-
* Provider decorator
|
|
7534
|
-
*/
|
|
7535
|
-
function TaonProvider(options) {
|
|
7536
|
-
return function (constructor) {
|
|
7537
|
-
Reflect.defineMetadata(Symbols.metadata.options.provider, options, constructor);
|
|
7538
|
-
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
7539
|
-
ClassHelpers.setName(constructor, options?.className || constructor.name);
|
|
7540
|
-
};
|
|
7541
|
-
}
|
|
7542
|
-
class TaonProviderOptions extends DecoratorAbstractOpt {
|
|
7543
|
-
}
|
|
7544
|
-
|
|
7545
|
-
//#region imports
|
|
7546
|
-
//#endregion
|
|
7547
|
-
let TaonGlobalStateProvider = class TaonGlobalStateProvider extends TaonBaseProvider {
|
|
7548
|
-
};
|
|
7549
|
-
TaonGlobalStateProvider = __decorate([
|
|
7550
|
-
TaonProvider({
|
|
7551
|
-
className: 'TaonGlobalStateProvider',
|
|
7552
|
-
})
|
|
7553
|
-
], TaonGlobalStateProvider);
|
|
7554
|
-
|
|
7555
|
-
//#region imports
|
|
7556
|
-
//#endregion
|
|
7557
|
-
let TaonGlobalStateMiddleware = class TaonGlobalStateMiddleware extends TaonBaseMiddleware {
|
|
7558
|
-
};
|
|
7559
|
-
TaonGlobalStateMiddleware = __decorate([
|
|
7560
|
-
TaonMiddleware({
|
|
7561
|
-
className: 'TaonGlobalStateMiddleware',
|
|
7562
|
-
})
|
|
7563
|
-
], TaonGlobalStateMiddleware);
|
|
7564
|
-
|
|
7565
7399
|
/**
|
|
7566
7400
|
* Subscriber decorator
|
|
7567
7401
|
*/
|
|
@@ -7718,75 +7552,6 @@ TaonBaseSubscriberForEntity = __decorate([
|
|
|
7718
7552
|
})
|
|
7719
7553
|
], TaonBaseSubscriberForEntity);
|
|
7720
7554
|
|
|
7721
|
-
//#region imports
|
|
7722
|
-
//#endregion
|
|
7723
|
-
let TaonGlobalStateSubscriber = class TaonGlobalStateSubscriber extends TaonBaseSubscriberForEntity {
|
|
7724
|
-
constructor() {
|
|
7725
|
-
super(...arguments);
|
|
7726
|
-
this.taonGlobalStateProvider = this.injectProvider(TaonGlobalStateProvider);
|
|
7727
|
-
}
|
|
7728
|
-
listenTo() {
|
|
7729
|
-
return TAON_GLOBAL_STATE;
|
|
7730
|
-
}
|
|
7731
|
-
};
|
|
7732
|
-
TaonGlobalStateSubscriber = __decorate([
|
|
7733
|
-
TaonSubscriber({
|
|
7734
|
-
className: 'TaonGlobalStateSubscriber',
|
|
7735
|
-
// allowedEvents: ['afterUpdate'],
|
|
7736
|
-
})
|
|
7737
|
-
], TaonGlobalStateSubscriber);
|
|
7738
|
-
|
|
7739
|
-
//#region imports
|
|
7740
|
-
//#endregion
|
|
7741
|
-
const TaonGlobalStateContext = createContext(() => ({
|
|
7742
|
-
contextName: 'TaonGlobalStateContext',
|
|
7743
|
-
abstract: true,
|
|
7744
|
-
entities: { TAON_GLOBAL_STATE },
|
|
7745
|
-
controllers: { TaonGlobalStateController },
|
|
7746
|
-
repositories: { TaonGlobalStateRepository },
|
|
7747
|
-
providers: { TaonGlobalStateProvider },
|
|
7748
|
-
middlewares: { TaonGlobalStateMiddleware },
|
|
7749
|
-
subscribers: { TaonGlobalStateSubscriber },
|
|
7750
|
-
}));
|
|
7751
|
-
|
|
7752
|
-
const TaonBaseContext = createContext(() => ({
|
|
7753
|
-
contextName: 'TaonBaseContext',
|
|
7754
|
-
abstract: true,
|
|
7755
|
-
contexts: {
|
|
7756
|
-
TaonGlobalStateContext,
|
|
7757
|
-
},
|
|
7758
|
-
middlewares: {
|
|
7759
|
-
TaonBaseFileUploadMiddleware,
|
|
7760
|
-
},
|
|
7761
|
-
repositories: {
|
|
7762
|
-
// @ts-ignore
|
|
7763
|
-
TaonBaseRepository,
|
|
7764
|
-
},
|
|
7765
|
-
}));
|
|
7766
|
-
|
|
7767
|
-
var baseContext = /*#__PURE__*/Object.freeze({
|
|
7768
|
-
__proto__: null,
|
|
7769
|
-
TaonBaseContext: TaonBaseContext
|
|
7770
|
-
});
|
|
7771
|
-
|
|
7772
|
-
class TaonBaseMigration extends TaonBaseInjector {
|
|
7773
|
-
/**
|
|
7774
|
-
* by default is READY to run
|
|
7775
|
-
*/
|
|
7776
|
-
isReadyToRun() {
|
|
7777
|
-
return true;
|
|
7778
|
-
}
|
|
7779
|
-
getDescription() {
|
|
7780
|
-
return _.startCase(ClassHelpers.getName(this));
|
|
7781
|
-
}
|
|
7782
|
-
async up(queryRunner) {
|
|
7783
|
-
console.log(`[TaonBaseMigration] Running migration UP "${ClassHelpers.getName(this)}"`);
|
|
7784
|
-
}
|
|
7785
|
-
async down(queryRunner) {
|
|
7786
|
-
console.log(`[TaonBaseMigration] Running migration DOWN "${ClassHelpers.getName(this)}"`);
|
|
7787
|
-
}
|
|
7788
|
-
}
|
|
7789
|
-
|
|
7790
7555
|
//#region models / method config
|
|
7791
7556
|
/**
|
|
7792
7557
|
* @link './decorators/http/http-methods-decorators.ts' TaonHttpDecoratorOptions
|
|
@@ -8183,6 +7948,39 @@ function getFromlyConfigFor(target, options = {}) {
|
|
|
8183
7948
|
return fields.filter(f => !!f);
|
|
8184
7949
|
}
|
|
8185
7950
|
|
|
7951
|
+
/**
|
|
7952
|
+
* Entity decorator
|
|
7953
|
+
*/
|
|
7954
|
+
function TaonEntity(options) {
|
|
7955
|
+
return function (constructor) {
|
|
7956
|
+
options = options || {};
|
|
7957
|
+
options.uniqueKeyProp = options.uniqueKeyProp || 'id';
|
|
7958
|
+
if (!options.className) {
|
|
7959
|
+
const nameForClass = constructor?.name || 'AnyClass';
|
|
7960
|
+
throw `Please define 'classname' property inside decorator of class '${nameForClass}':
|
|
7961
|
+
|
|
7962
|
+
@TaonEntity({
|
|
7963
|
+
className: '${nameForClass}'
|
|
7964
|
+
})
|
|
7965
|
+
class ${constructor?.name} {
|
|
7966
|
+
//...
|
|
7967
|
+
|
|
7968
|
+
`;
|
|
7969
|
+
}
|
|
7970
|
+
ClassHelpers.setName(constructor, options?.className);
|
|
7971
|
+
DefaultMapping(options?.defaultModelMapping)(constructor);
|
|
7972
|
+
DefaultModel(options.defaultModelMapping)(constructor);
|
|
7973
|
+
Reflect.defineMetadata(Symbols.metadata.options.entity, options, constructor);
|
|
7974
|
+
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
7975
|
+
//#region @websql
|
|
7976
|
+
Entity(options?.className)(constructor);
|
|
7977
|
+
//#endregion
|
|
7978
|
+
CLASS.setName(constructor, options?.className); // TODO QUICK_FIX for ng2-rest
|
|
7979
|
+
};
|
|
7980
|
+
}
|
|
7981
|
+
class TaonEntityOptions extends DecoratorAbstractOpt {
|
|
7982
|
+
}
|
|
7983
|
+
|
|
8186
7984
|
/**
|
|
8187
7985
|
* Migration decorator
|
|
8188
7986
|
*/
|
|
@@ -8196,6 +7994,19 @@ function TaonMigration(options) {
|
|
|
8196
7994
|
class TaonMigrationOptions extends DecoratorAbstractOpt {
|
|
8197
7995
|
}
|
|
8198
7996
|
|
|
7997
|
+
/**
|
|
7998
|
+
* Provider decorator
|
|
7999
|
+
*/
|
|
8000
|
+
function TaonProvider(options) {
|
|
8001
|
+
return function (constructor) {
|
|
8002
|
+
Reflect.defineMetadata(Symbols.metadata.options.provider, options, constructor);
|
|
8003
|
+
Reflect.defineMetadata(Symbols.metadata.className, options?.className || constructor.name, constructor);
|
|
8004
|
+
ClassHelpers.setName(constructor, options?.className || constructor.name);
|
|
8005
|
+
};
|
|
8006
|
+
}
|
|
8007
|
+
class TaonProviderOptions extends DecoratorAbstractOpt {
|
|
8008
|
+
}
|
|
8009
|
+
|
|
8199
8010
|
// TODO export all things
|
|
8200
8011
|
var Taon;
|
|
8201
8012
|
(function (Taon) {
|