taon 18.0.24 → 18.0.26
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 +175 -114
- package/assets/shared/shared_folder_info.txt +1 -1
- package/bin/start.js +279 -279
- 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/esm2022/lib/endpoint-context.mjs +4 -1
- package/browser/esm2022/lib/index.mjs +2 -2
- package/browser/esm2022/lib/models.mjs +1 -1
- package/browser/esm2022/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.mjs +11 -11
- package/browser/fesm2022/taon.mjs +3 -0
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/models.d.ts +5 -0
- package/browser/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +4 -4
- package/cli.js +11 -17
- package/cli.js.map +1 -1
- package/client/README.md +24 -24
- package/client/esm2022/lib/endpoint-context.mjs +4 -1
- package/client/esm2022/lib/index.mjs +2 -2
- package/client/esm2022/lib/models.mjs +1 -1
- package/client/esm2022/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.mjs +11 -11
- package/client/fesm2022/taon.mjs +3 -0
- package/client/fesm2022/taon.mjs.map +1 -1
- package/client/lib/models.d.ts +5 -0
- package/client/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +4 -4
- package/index.js +15 -2
- package/index.js.map +1 -1
- package/lib/base-classes/base-abstract-entity.js +30 -28
- package/lib/base-classes/base-abstract-entity.js.map +1 -1
- package/lib/base-classes/base-class.js +9 -17
- package/lib/base-classes/base-class.js.map +1 -1
- package/lib/base-classes/base-context.js +4 -4
- package/lib/base-classes/base-context.js.map +1 -1
- package/lib/base-classes/base-controller.js +15 -15
- package/lib/base-classes/base-controller.js.map +1 -1
- package/lib/base-classes/base-crud-controller.js +211 -329
- package/lib/base-classes/base-crud-controller.js.map +1 -1
- package/lib/base-classes/base-entity.js +15 -15
- package/lib/base-classes/base-entity.js.map +1 -1
- package/lib/base-classes/base-injector.js +99 -124
- package/lib/base-classes/base-injector.js.map +1 -1
- package/lib/base-classes/base-migration.js +15 -31
- package/lib/base-classes/base-migration.js.map +1 -1
- package/lib/base-classes/base-provider.js +3 -9
- package/lib/base-classes/base-provider.js.map +1 -1
- package/lib/base-classes/base-repository.js +310 -444
- package/lib/base-classes/base-repository.js.map +1 -1
- package/lib/base-classes/base-subscriber-for-entity.js +73 -73
- package/lib/base-classes/base-subscriber-for-entity.js.map +1 -1
- package/lib/base-classes/base.js +10 -10
- package/lib/base-classes/base.js.map +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/constants.js.map +1 -1
- package/lib/context-db-migrations.js +325 -581
- package/lib/context-db-migrations.js.map +1 -1
- package/lib/create-context.js +80 -109
- package/lib/create-context.js.map +1 -1
- package/lib/decorators/classes/controller-decorator.js +15 -13
- package/lib/decorators/classes/controller-decorator.js.map +1 -1
- package/lib/decorators/classes/entity-decorator.js +23 -20
- package/lib/decorators/classes/entity-decorator.js.map +1 -1
- package/lib/decorators/classes/migration-decorator.js +7 -13
- package/lib/decorators/classes/migration-decorator.js.map +1 -1
- package/lib/decorators/classes/provider-decorator.js +7 -13
- package/lib/decorators/classes/provider-decorator.js.map +1 -1
- package/lib/decorators/classes/repository-decorator.js +7 -13
- package/lib/decorators/classes/repository-decorator.js.map +1 -1
- package/lib/decorators/classes/subscriber-decorator.js +8 -13
- package/lib/decorators/classes/subscriber-decorator.js.map +1 -1
- package/lib/decorators/http/http-decorators.js +4 -4
- package/lib/decorators/http/http-decorators.js.map +1 -1
- package/lib/decorators/http/http-methods-decorators.js +19 -25
- package/lib/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib/decorators/http/http-params-decorators.js +7 -9
- package/lib/decorators/http/http-params-decorators.js.map +1 -1
- package/lib/dependency-injection/di-container.js +13 -18
- package/lib/dependency-injection/di-container.js.map +1 -1
- package/lib/endpoint-context.js +1196 -1543
- package/lib/endpoint-context.js.map +1 -1
- package/lib/entity-process.js +102 -112
- package/lib/entity-process.js.map +1 -1
- package/lib/env.js +2 -2
- package/lib/env.js.map +1 -1
- package/lib/formly/formly-group-wrapper-component.js +45 -23
- package/lib/formly/formly-group-wrapper-component.js.map +1 -1
- package/lib/formly/formly-repeat-component.js +74 -27
- package/lib/formly/formly-repeat-component.js.map +1 -1
- package/lib/formly/formly.models.js.map +1 -1
- package/lib/formly/fromly.js +57 -61
- package/lib/formly/fromly.js.map +1 -1
- package/lib/formly/type-from-entity.js +11 -16
- package/lib/formly/type-from-entity.js.map +1 -1
- package/lib/get-response-value.js +22 -33
- package/lib/get-response-value.js.map +1 -1
- package/lib/helpers/class-helpers.js +62 -73
- package/lib/helpers/class-helpers.js.map +1 -1
- package/lib/helpers/taon-helpers.js +33 -31
- package/lib/helpers/taon-helpers.js.map +1 -1
- package/lib/index._auto-generated_.d.ts +1 -0
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.d.ts +1 -25
- package/lib/index.js +44 -41
- package/lib/index.js.map +1 -1
- package/lib/inject.js +15 -15
- package/lib/inject.js.map +1 -1
- package/lib/models.d.ts +5 -0
- package/lib/models.js +124 -100
- package/lib/models.js.map +1 -1
- package/lib/orm.js +13 -27
- package/lib/orm.js.map +1 -1
- package/lib/realtime/realtime-client.js +70 -65
- package/lib/realtime/realtime-client.js.map +1 -1
- package/lib/realtime/realtime-core.js +48 -29
- package/lib/realtime/realtime-core.js.map +1 -1
- package/lib/realtime/realtime-server.js +81 -80
- package/lib/realtime/realtime-server.js.map +1 -1
- package/lib/realtime/realtime-strategy/index.js +18 -5
- package/lib/realtime/realtime-strategy/index.js.map +1 -1
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc.js +132 -172
- package/lib/realtime/realtime-strategy/realtime-strategy-ipc.js.map +1 -1
- package/lib/realtime/realtime-strategy/realtime-strategy-mock.js +158 -241
- package/lib/realtime/realtime-strategy/realtime-strategy-mock.js.map +1 -1
- package/lib/realtime/realtime-strategy/realtime-strategy-socket-io.js +18 -29
- package/lib/realtime/realtime-strategy/realtime-strategy-socket-io.js.map +1 -1
- package/lib/realtime/realtime-strategy/realtime-strategy.js +9 -13
- package/lib/realtime/realtime-strategy/realtime-strategy.js.map +1 -1
- package/lib/realtime/realtime-subs-manager.js +29 -30
- package/lib/realtime/realtime-subs-manager.js.map +1 -1
- package/lib/realtime/realtime.models.js.map +1 -1
- package/lib/storage.js +1 -1
- package/lib/storage.js.map +1 -1
- package/lib/symbols.js +62 -66
- package/lib/symbols.js.map +1 -1
- package/lib/ui/directives/index.js +2 -2
- package/lib/ui/directives/index.js.map +1 -1
- package/lib/ui/directives/view-mode.js.map +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/index.js.map +1 -1
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/taon-admin-edit-mode.component.d.ts +29 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-admin-edit-mode/taon-admin-edit-mode.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.d.ts +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-db-admin/taon-db-admin.component.d.ts +8 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.js +5 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/index.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/taon-file-general-opt.component.d.ts +13 -0
- package/lib/ui/taon-admin-mode-configuration/components/taon-file-general-opt/taon-file-general-opt.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js.map +1 -1
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.d.ts +5 -0
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.js +3 -0
- package/lib/ui/taon-admin-mode-configuration/models/taon-admin-mode-tabs.js.map +1 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin-control.service.d.ts +14 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +4 -4
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.module.d.ts +2 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +1 -1
- package/lib/ui/taon-github-fork-me-corner/index.js +2 -2
- package/lib/ui/taon-github-fork-me-corner/index.js.map +1 -1
- package/lib/ui/taon-github-fork-me-ribbon/index.js +2 -2
- package/lib/ui/taon-github-fork-me-ribbon/index.js.map +1 -1
- package/lib/ui/taon-notifications/index.js +15 -2
- package/lib/ui/taon-notifications/index.js.map +1 -1
- package/lib/ui/taon-notifications/taon-notifications.models.js +2 -2
- package/lib/ui/taon-notifications/taon-notifications.models.js.map +1 -1
- package/lib/ui/taon-progress-bar/index.js +2 -2
- package/lib/ui/taon-progress-bar/index.js.map +1 -1
- package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +2 -1
- package/lib/ui/taon-session-passcode/index.js +2 -2
- package/lib/ui/taon-session-passcode/index.js.map +1 -1
- package/lib/ui/taon-table/index.js +2 -2
- package/lib/ui/taon-table/index.js.map +1 -1
- package/lib/ui/taon.models.js.map +1 -1
- package/lib/validators.js +48 -16
- package/lib/validators.js.map +1 -1
- package/migrations/index.js +15 -2
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.d.ts +1 -0
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/old-app .d.ts +1 -0
- package/old-app .js +67 -78
- package/old-app .js.map +1 -1
- package/package.json +18 -65
- package/playground.d.ts +1 -0
- package/playground.js.map +1 -1
- package/src.d.ts +1 -1
- package/taon.jsonc +44 -47
- package/tmp-environment.json +8 -401
- package/websql/README.md +24 -24
- package/websql/esm2022/lib/endpoint-context.mjs +4 -1
- package/websql/esm2022/lib/index.mjs +2 -2
- package/websql/esm2022/lib/models.mjs +1 -1
- package/websql/esm2022/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.mjs +11 -11
- package/websql/fesm2022/taon.mjs +3 -0
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/models.d.ts +5 -0
- package/websql/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +4 -4
- package/browser/package.json +0 -25
- package/websql/package.json +0 -25
|
@@ -1,230 +1,189 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.BaseRepository = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var base_injector_1 = require("./base-injector");
|
|
10
|
+
const tnp_core_1 = require("tnp-core");
|
|
11
|
+
const tnp_core_2 = require("tnp-core");
|
|
12
|
+
const class_helpers_1 = require("../helpers/class-helpers");
|
|
13
|
+
const taon_type_sql_1 = require("taon-type-sql");
|
|
14
|
+
const repository_decorator_1 = require("../decorators/classes/repository-decorator");
|
|
15
|
+
const base_injector_1 = require("./base-injector");
|
|
11
16
|
//#endregion
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const INDEX_KEYS_NO_FOR_UPDATE = ['id'];
|
|
18
|
+
let BaseRepository = class BaseRepository extends base_injector_1.BaseInjector {
|
|
19
|
+
__entityClassResolveFn;
|
|
20
|
+
constructor(
|
|
16
21
|
// Injected through BaseCrudController
|
|
17
22
|
__entityClassResolveFn) {
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
super();
|
|
24
|
+
this.__entityClassResolveFn = __entityClassResolveFn;
|
|
20
25
|
// @ts-ignore
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
this.__dbQuery = new taon_type_sql_1.MySqlQuerySource(connection);
|
|
26
|
+
this.entityClassResolveFn = __entityClassResolveFn;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region db query
|
|
30
|
+
__dbQuery;
|
|
31
|
+
get dbQuery() {
|
|
32
|
+
//#region @websqlFunc
|
|
33
|
+
if (!this.__dbQuery) {
|
|
34
|
+
if (!this.ctx) {
|
|
35
|
+
return; // TODO
|
|
36
|
+
throw new Error(`[BaseRepository] Context not inited for class ${class_helpers_1.ClassHelpers.getName(this)}`);
|
|
37
|
+
}
|
|
38
|
+
const connection = this.ctx?.connection;
|
|
39
|
+
if (!connection) {
|
|
40
|
+
throw new Error(`[BaseRepository] Database not inited for context ${this.ctx?.contextName}`);
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
this.__dbQuery = new taon_type_sql_1.MySqlQuerySource(connection);
|
|
43
|
+
}
|
|
44
|
+
return this.__dbQuery;
|
|
45
|
+
//#endregion
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region connection
|
|
49
|
+
get connection() {
|
|
50
|
+
//#region @websqlFunc
|
|
51
|
+
return this.ctx?.connection;
|
|
52
|
+
//#endregion
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region repository
|
|
56
|
+
//#region @websql
|
|
57
|
+
__repository;
|
|
58
|
+
//#endregion
|
|
59
|
+
get repository() {
|
|
60
|
+
//#region @websqlFunc
|
|
61
|
+
return this.__repository;
|
|
62
|
+
//#endregion
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* target for repository
|
|
66
|
+
*/
|
|
67
|
+
get target() {
|
|
68
|
+
//#region @websqlFunc
|
|
69
|
+
return this?.repository?.target;
|
|
70
|
+
//#endregion
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* alias to repository
|
|
74
|
+
*/
|
|
75
|
+
get repo() {
|
|
76
|
+
//#region @websqlFunc
|
|
77
|
+
return this.repository;
|
|
46
78
|
//#endregion
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return (_a = this.ctx) === null || _a === void 0 ? void 0 : _a.connection;
|
|
52
|
-
//#endregion
|
|
53
|
-
},
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(BaseRepository.prototype, "repository", {
|
|
79
|
+
}
|
|
80
|
+
get repositoryExists() {
|
|
81
|
+
//#region @websqlFunc
|
|
82
|
+
return !!this.__repository;
|
|
58
83
|
//#endregion
|
|
59
|
-
|
|
60
|
-
//#region @websqlFunc
|
|
61
|
-
return this.__repository;
|
|
62
|
-
//#endregion
|
|
63
|
-
},
|
|
64
|
-
enumerable: false,
|
|
65
|
-
configurable: true
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(BaseRepository.prototype, "target", {
|
|
68
|
-
/**
|
|
69
|
-
* target for repository
|
|
70
|
-
*/
|
|
71
|
-
get: function () {
|
|
72
|
-
var _a;
|
|
73
|
-
//#region @websqlFunc
|
|
74
|
-
return (_a = this === null || this === void 0 ? void 0 : this.repository) === null || _a === void 0 ? void 0 : _a.target;
|
|
75
|
-
//#endregion
|
|
76
|
-
},
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
Object.defineProperty(BaseRepository.prototype, "repo", {
|
|
81
|
-
/**
|
|
82
|
-
* alias to repository
|
|
83
|
-
*/
|
|
84
|
-
get: function () {
|
|
85
|
-
//#region @websqlFunc
|
|
86
|
-
return this.repository;
|
|
87
|
-
//#endregion
|
|
88
|
-
},
|
|
89
|
-
enumerable: false,
|
|
90
|
-
configurable: true
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(BaseRepository.prototype, "repositoryExists", {
|
|
93
|
-
get: function () {
|
|
94
|
-
//#region @websqlFunc
|
|
95
|
-
return !!this.__repository;
|
|
96
|
-
//#endregion
|
|
97
|
-
},
|
|
98
|
-
enumerable: false,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
84
|
+
}
|
|
101
85
|
//#endregion
|
|
102
86
|
//#region init
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
87
|
+
async __init(context) {
|
|
88
|
+
//#region @websql
|
|
89
|
+
if (this.__repository) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let entityClassFn = this.entityClassResolveFn();
|
|
93
|
+
if (!entityClassFn) {
|
|
94
|
+
tnp_core_1.Helpers.warn(`Entity class not provided for repository ${class_helpers_1.ClassHelpers.getName(this)}`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const ctx = this.__endpoint_context__;
|
|
98
|
+
if (ctx.remoteHost) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const connection = ctx.connection;
|
|
102
|
+
if (!connection) {
|
|
103
|
+
throw new Error(`
|
|
104
|
+
|
|
105
|
+
Connection not found for context ${ctx.contextName}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
Maybe you forgot to init database ?
|
|
109
|
+
|
|
110
|
+
Taon.createContext({
|
|
111
|
+
...
|
|
112
|
+
database:true
|
|
113
|
+
...
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
`);
|
|
117
|
+
}
|
|
118
|
+
if (!entityClassFn) {
|
|
119
|
+
tnp_core_1.Helpers.warn(`Entity class not found for repository ${class_helpers_1.ClassHelpers.getName(this)}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.__repository = (await connection.getRepository(class_helpers_1.ClassHelpers.getOrginalClass(entityClassFn)));
|
|
123
|
+
// console.log(
|
|
124
|
+
// `Inited repository for (${ClassHelpers.getName(this)}/` +
|
|
125
|
+
// `${ClassHelpers.getName(entityClassFn)}/${ClassHelpers.getName(context)}`,
|
|
126
|
+
// this.repository,
|
|
127
|
+
// );
|
|
128
|
+
//#endregion
|
|
129
|
+
}
|
|
139
130
|
//#endregion
|
|
140
131
|
//#region crud operations / typeorm / has id
|
|
141
132
|
/**
|
|
142
133
|
* Checks if entity has an id.
|
|
143
134
|
* If entity composite compose ids, it will check them all.
|
|
144
135
|
*/
|
|
145
|
-
|
|
136
|
+
hasId(entity) {
|
|
146
137
|
return this.repo.hasId(entity);
|
|
147
|
-
}
|
|
138
|
+
}
|
|
148
139
|
//#endregion
|
|
149
140
|
//#region crud operations / typeorm / get id
|
|
150
141
|
/**
|
|
151
142
|
* Gets entity mixed id.
|
|
152
143
|
*/
|
|
153
|
-
|
|
144
|
+
getId(entity) {
|
|
154
145
|
return this.repo.getId(entity);
|
|
155
|
-
}
|
|
146
|
+
}
|
|
156
147
|
//#endregion
|
|
157
148
|
//#region crud operations / typeorm / create & bulk create
|
|
158
149
|
/**
|
|
159
150
|
Saves a given entity in the database.
|
|
160
151
|
* If entity does not exist in the database then inserts, otherwise updates.
|
|
161
152
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
model = _a.sent();
|
|
170
|
-
return [4 /*yield*/, this.repo.save(model, options)];
|
|
171
|
-
case 2:
|
|
172
|
-
model = _a.sent();
|
|
173
|
-
id = model.id;
|
|
174
|
-
return [4 /*yield*/, this.repo.findOne({
|
|
175
|
-
where: { id: id },
|
|
176
|
-
})];
|
|
177
|
-
case 3:
|
|
178
|
-
model = _a.sent();
|
|
179
|
-
return [2 /*return*/, model];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
153
|
+
async save(item, options) {
|
|
154
|
+
//#region @websqlFunc
|
|
155
|
+
let model = await this.repo.create(item);
|
|
156
|
+
model = await this.repo.save(model, options);
|
|
157
|
+
const { id } = model;
|
|
158
|
+
model = await this.repo.findOne({
|
|
159
|
+
where: { id },
|
|
182
160
|
});
|
|
183
|
-
|
|
161
|
+
return model;
|
|
162
|
+
//#endregion
|
|
163
|
+
}
|
|
184
164
|
/**
|
|
185
165
|
* alias to save
|
|
186
166
|
* -> it will actuall create new entity in db
|
|
187
167
|
* in oposite to typeorm create method
|
|
188
168
|
*/
|
|
189
|
-
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
item = items[index];
|
|
208
|
-
return [4 /*yield*/, this.save(item, options)];
|
|
209
|
-
case 2:
|
|
210
|
-
model = _a.sent();
|
|
211
|
-
models.push(model);
|
|
212
|
-
_a.label = 3;
|
|
213
|
-
case 3:
|
|
214
|
-
index++;
|
|
215
|
-
return [3 /*break*/, 1];
|
|
216
|
-
case 4: return [2 /*return*/, models];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
};
|
|
221
|
-
BaseRepository.prototype.bulkCreate = function (items, options) {
|
|
222
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
223
|
-
return tslib_1.__generator(this, function (_a) {
|
|
224
|
-
return [2 /*return*/, this.bulkSave(items, options)];
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
};
|
|
169
|
+
async create(item, options) {
|
|
170
|
+
return this.save(item, options);
|
|
171
|
+
}
|
|
172
|
+
async bulkSave(items, options) {
|
|
173
|
+
//#region @websqlFunc
|
|
174
|
+
const models = [];
|
|
175
|
+
for (let index = 0; index < items.length; index++) {
|
|
176
|
+
const item = items[index];
|
|
177
|
+
// TODO FIX THIS / REFACTOR
|
|
178
|
+
const model = await this.save(item, options);
|
|
179
|
+
models.push(model);
|
|
180
|
+
}
|
|
181
|
+
return models;
|
|
182
|
+
//#endregion
|
|
183
|
+
}
|
|
184
|
+
async bulkCreate(items, options) {
|
|
185
|
+
return this.bulkSave(items, options);
|
|
186
|
+
}
|
|
228
187
|
//#region old typeorm version
|
|
229
188
|
// /**
|
|
230
189
|
// * Creates a new entity instance.
|
|
@@ -284,14 +243,9 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
284
243
|
/**
|
|
285
244
|
* Merges multiple entities (or entity-like objects) into a given entity.
|
|
286
245
|
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
291
|
-
entityLikes[_i - 1] = arguments[_i];
|
|
292
|
-
}
|
|
293
|
-
return (_a = this.repo).merge.apply(_a, tslib_1.__spreadArray([mergeIntoEntity], tslib_1.__read(entityLikes), false));
|
|
294
|
-
};
|
|
246
|
+
merge(mergeIntoEntity, ...entityLikes) {
|
|
247
|
+
return this.repo.merge(mergeIntoEntity, ...entityLikes);
|
|
248
|
+
}
|
|
295
249
|
//#endregion
|
|
296
250
|
//#region crud operations / typeorm / preload
|
|
297
251
|
/**
|
|
@@ -303,107 +257,69 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
303
257
|
* Note that given entity-like object must have an entity id / primary key to find entity by.
|
|
304
258
|
* Returns undefined if entity with given id was not found.
|
|
305
259
|
*/
|
|
306
|
-
|
|
260
|
+
preload(entityLike) {
|
|
307
261
|
return this.repo.preload(entityLike);
|
|
308
|
-
}
|
|
262
|
+
}
|
|
309
263
|
//#endregion
|
|
310
264
|
//#region crud operations / typeorm / remove (delete) & bulk remove (delete)
|
|
311
265
|
/**
|
|
312
266
|
* Removes a given entities from the database.
|
|
313
267
|
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (tnp_core_2._.isObject(idOrEntity)) {
|
|
322
|
-
idOrEntity = idOrEntity.id;
|
|
323
|
-
}
|
|
324
|
-
return [4 /*yield*/, this.repo.findOne({
|
|
325
|
-
where: { id: idOrEntity },
|
|
326
|
-
})];
|
|
327
|
-
case 1:
|
|
328
|
-
deletedEntity = _a.sent();
|
|
329
|
-
idCopy = deletedEntity.id;
|
|
330
|
-
return [4 /*yield*/, this.repo.remove(deletedEntity)];
|
|
331
|
-
case 2:
|
|
332
|
-
_a.sent();
|
|
333
|
-
deletedEntity.id = idCopy;
|
|
334
|
-
return [2 /*return*/, deletedEntity];
|
|
335
|
-
}
|
|
336
|
-
});
|
|
268
|
+
async remove(idOrEntity) {
|
|
269
|
+
//#region @websqlFunc
|
|
270
|
+
if (tnp_core_2._.isObject(idOrEntity)) {
|
|
271
|
+
idOrEntity = idOrEntity.id;
|
|
272
|
+
}
|
|
273
|
+
const deletedEntity = await this.repo.findOne({
|
|
274
|
+
where: { id: idOrEntity },
|
|
337
275
|
});
|
|
338
|
-
|
|
276
|
+
const idCopy = deletedEntity.id;
|
|
277
|
+
await this.repo.remove(deletedEntity);
|
|
278
|
+
deletedEntity.id = idCopy;
|
|
279
|
+
return deletedEntity;
|
|
280
|
+
//#endregion
|
|
281
|
+
}
|
|
339
282
|
/**
|
|
340
283
|
* alias to remove
|
|
341
284
|
*/
|
|
342
|
-
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
return [2 /*return*/, this.remove(idOrEntity)];
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
};
|
|
285
|
+
async delete(idOrEntity) {
|
|
286
|
+
return this.remove(idOrEntity);
|
|
287
|
+
}
|
|
349
288
|
/**
|
|
350
289
|
* alias to removeById
|
|
351
290
|
*/
|
|
352
|
-
|
|
353
|
-
return
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
BaseRepository.prototype.bulkRemove = function (idsOrEntities) {
|
|
360
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
361
|
-
var models, index, id, model;
|
|
362
|
-
return tslib_1.__generator(this, function (_a) {
|
|
363
|
-
switch (_a.label) {
|
|
364
|
-
case 0:
|
|
365
|
-
//#region @websqlFunc
|
|
366
|
-
idsOrEntities = idsOrEntities.map(function (id) {
|
|
367
|
-
return tnp_core_2._.isObject(id) ? id.id : id;
|
|
368
|
-
});
|
|
369
|
-
models = [];
|
|
370
|
-
index = 0;
|
|
371
|
-
_a.label = 1;
|
|
372
|
-
case 1:
|
|
373
|
-
if (!(index < idsOrEntities.length)) return [3 /*break*/, 4];
|
|
374
|
-
id = idsOrEntities[index];
|
|
375
|
-
return [4 /*yield*/, this.remove(id)];
|
|
376
|
-
case 2:
|
|
377
|
-
model = _a.sent();
|
|
378
|
-
models.push(model);
|
|
379
|
-
_a.label = 3;
|
|
380
|
-
case 3:
|
|
381
|
-
index++;
|
|
382
|
-
return [3 /*break*/, 1];
|
|
383
|
-
case 4: return [2 /*return*/, models];
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
};
|
|
388
|
-
BaseRepository.prototype.bulkDelete = function (ids) {
|
|
389
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
390
|
-
return tslib_1.__generator(this, function (_a) {
|
|
391
|
-
return [2 /*return*/, this.bulkRemove(ids)];
|
|
392
|
-
});
|
|
291
|
+
async deleteById(id) {
|
|
292
|
+
return this.remove(id);
|
|
293
|
+
}
|
|
294
|
+
async bulkRemove(idsOrEntities) {
|
|
295
|
+
//#region @websqlFunc
|
|
296
|
+
idsOrEntities = idsOrEntities.map(id => {
|
|
297
|
+
return tnp_core_2._.isObject(id) ? id.id : id;
|
|
393
298
|
});
|
|
394
|
-
|
|
299
|
+
const models = [];
|
|
300
|
+
for (let index = 0; index < idsOrEntities.length; index++) {
|
|
301
|
+
const id = idsOrEntities[index];
|
|
302
|
+
const model = await this.remove(id);
|
|
303
|
+
models.push(model);
|
|
304
|
+
}
|
|
305
|
+
return models;
|
|
306
|
+
//#endregion
|
|
307
|
+
}
|
|
308
|
+
async bulkDelete(ids) {
|
|
309
|
+
return this.bulkRemove(ids);
|
|
310
|
+
}
|
|
395
311
|
/**
|
|
396
312
|
* Records the delete date of a given entity.
|
|
397
313
|
*/
|
|
398
|
-
|
|
314
|
+
softRemove(entity, options) {
|
|
399
315
|
return this.repo.softRemove(entity, options);
|
|
400
|
-
}
|
|
316
|
+
}
|
|
401
317
|
/**
|
|
402
318
|
* Recovers a given entity in the database.
|
|
403
319
|
*/
|
|
404
|
-
|
|
320
|
+
recover(entity, options) {
|
|
405
321
|
return this.repo.recover(entity, options);
|
|
406
|
-
}
|
|
322
|
+
}
|
|
407
323
|
//#endregion
|
|
408
324
|
//#region crud operations / typeorm / insert
|
|
409
325
|
/**
|
|
@@ -412,100 +328,64 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
412
328
|
* Executes fast and efficient INSERT query.
|
|
413
329
|
* Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
|
|
414
330
|
*/
|
|
415
|
-
|
|
331
|
+
insert(entity) {
|
|
416
332
|
return this.repo.insert(entity);
|
|
417
|
-
}
|
|
333
|
+
}
|
|
418
334
|
//#endregion
|
|
419
335
|
//#region crud operations / typeorm / update & build update
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
key = allowedPropsToUpdate[i];
|
|
458
|
-
if (!!INDEX_KEYS_NO_FOR_UPDATE.includes(key.toLowerCase())) return [3 /*break*/, 3];
|
|
459
|
-
toSet = item[key];
|
|
460
|
-
// const tableName = tableNameFrom(this.entity as any);
|
|
461
|
-
return [4 /*yield*/, this.repo.update({
|
|
462
|
-
id: id,
|
|
463
|
-
}, (_a = {},
|
|
464
|
-
_a[key] = toSet,
|
|
465
|
-
_a))];
|
|
466
|
-
case 2:
|
|
467
|
-
// const tableName = tableNameFrom(this.entity as any);
|
|
468
|
-
_b.sent();
|
|
469
|
-
_b.label = 3;
|
|
470
|
-
case 3:
|
|
471
|
-
i++;
|
|
472
|
-
return [3 /*break*/, 1];
|
|
473
|
-
case 4: return [4 /*yield*/, this.repo.findOne({
|
|
474
|
-
where: { id: id },
|
|
475
|
-
})];
|
|
476
|
-
case 5:
|
|
477
|
-
model = _b.sent();
|
|
478
|
-
return [2 /*return*/, model];
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
BaseRepository.prototype.bulkUpdate = function (items) {
|
|
484
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
485
|
-
var models, index, item, id, model;
|
|
486
|
-
return tslib_1.__generator(this, function (_a) {
|
|
487
|
-
switch (_a.label) {
|
|
488
|
-
case 0:
|
|
489
|
-
models = [];
|
|
490
|
-
index = 0;
|
|
491
|
-
_a.label = 1;
|
|
492
|
-
case 1:
|
|
493
|
-
if (!(index < items.length)) return [3 /*break*/, 4];
|
|
494
|
-
item = items[index];
|
|
495
|
-
id = item.id;
|
|
496
|
-
return [4 /*yield*/, this.updateById(id, item)];
|
|
497
|
-
case 2:
|
|
498
|
-
model = _a.sent();
|
|
499
|
-
models.push(model);
|
|
500
|
-
_a.label = 3;
|
|
501
|
-
case 3:
|
|
502
|
-
index++;
|
|
503
|
-
return [3 /*break*/, 1];
|
|
504
|
-
case 4: return [2 /*return*/, { models: models }];
|
|
505
|
-
}
|
|
506
|
-
});
|
|
336
|
+
async update(item) {
|
|
337
|
+
//#region @websqlFunc
|
|
338
|
+
const { id } = item;
|
|
339
|
+
return await this.updateById(id, item);
|
|
340
|
+
//#endregion
|
|
341
|
+
}
|
|
342
|
+
async updateById(id, item) {
|
|
343
|
+
//#region @websqlFunc
|
|
344
|
+
const allowedPropsToUpdate = [];
|
|
345
|
+
for (const key in item) {
|
|
346
|
+
if (tnp_core_2._.isObject(item) &&
|
|
347
|
+
item.hasOwnProperty(key) &&
|
|
348
|
+
typeof item[key] !== 'object' &&
|
|
349
|
+
!tnp_core_2._.isUndefined(this.repo.metadata.ownColumns.find(c => c.propertyName === key))) {
|
|
350
|
+
allowedPropsToUpdate.push(key);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
for (let i = 0; i < allowedPropsToUpdate.length; i++) {
|
|
354
|
+
const key = allowedPropsToUpdate[i];
|
|
355
|
+
if (!INDEX_KEYS_NO_FOR_UPDATE.includes(key.toLowerCase())) {
|
|
356
|
+
// const raw = _.isBoolean(item[key]) || _.isNumber(item[key]) || _.isNull(item[key]); // TODO does this make any sense ?
|
|
357
|
+
const toSet = item[key];
|
|
358
|
+
// const tableName = tableNameFrom(this.entity as any);
|
|
359
|
+
await this.repo.update({
|
|
360
|
+
id,
|
|
361
|
+
}, {
|
|
362
|
+
[key]: toSet,
|
|
363
|
+
});
|
|
364
|
+
// await this.repo.query(
|
|
365
|
+
// `UPDATE '${tableName}' as ${table}
|
|
366
|
+
// SET ${key}=${toSet}
|
|
367
|
+
// WHERE ${table}.id='${id}'
|
|
368
|
+
// `);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
let model = await this.repo.findOne({
|
|
372
|
+
where: { id },
|
|
507
373
|
});
|
|
508
|
-
|
|
374
|
+
return model;
|
|
375
|
+
//#endregion
|
|
376
|
+
}
|
|
377
|
+
async bulkUpdate(items) {
|
|
378
|
+
//#region @websqlFunc
|
|
379
|
+
const models = [];
|
|
380
|
+
for (let index = 0; index < items.length; index++) {
|
|
381
|
+
const item = items[index];
|
|
382
|
+
const { id } = item; // TOOD
|
|
383
|
+
const model = await this.updateById(id, item);
|
|
384
|
+
models.push(model);
|
|
385
|
+
}
|
|
386
|
+
return { models };
|
|
387
|
+
//#endregion
|
|
388
|
+
}
|
|
509
389
|
//#region tpeorm update version
|
|
510
390
|
// this version suck and will not return update entity
|
|
511
391
|
// /**
|
|
@@ -537,9 +417,9 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
537
417
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
538
418
|
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
539
419
|
*/
|
|
540
|
-
|
|
420
|
+
upsert(entityOrEntities, conflictPathsOrOptions) {
|
|
541
421
|
return this.repo.upsert(entityOrEntities, conflictPathsOrOptions);
|
|
542
|
-
}
|
|
422
|
+
}
|
|
543
423
|
//#endregion
|
|
544
424
|
//#region crud operations / typeorm / soft delete
|
|
545
425
|
/**
|
|
@@ -548,9 +428,9 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
548
428
|
* Executes fast and efficient SOFT-DELETE query.
|
|
549
429
|
* Does not check if entity exist in the database.
|
|
550
430
|
*/
|
|
551
|
-
|
|
431
|
+
softDelete(criteria) {
|
|
552
432
|
return this.repo.softDelete(criteria);
|
|
553
|
-
}
|
|
433
|
+
}
|
|
554
434
|
//#endregion
|
|
555
435
|
//#region crud operations / typeorm / restore
|
|
556
436
|
/**
|
|
@@ -559,43 +439,43 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
559
439
|
* Executes fast and efficient SOFT-DELETE query.
|
|
560
440
|
* Does not check if entity exist in the database.
|
|
561
441
|
*/
|
|
562
|
-
|
|
442
|
+
restore(criteria) {
|
|
563
443
|
return this.repo.restore(criteria);
|
|
564
|
-
}
|
|
444
|
+
}
|
|
565
445
|
//#endregion
|
|
566
446
|
//#region crud operations / typeorm / count
|
|
567
447
|
/**
|
|
568
448
|
* Counts entities that match given options.
|
|
569
449
|
* Useful for pagination.
|
|
570
450
|
*/
|
|
571
|
-
|
|
451
|
+
count(options) {
|
|
572
452
|
return this.repo.count(options);
|
|
573
|
-
}
|
|
453
|
+
}
|
|
574
454
|
//#endregion
|
|
575
455
|
//#region crud operations / typeorm / count by
|
|
576
456
|
/**
|
|
577
457
|
* Counts entities that match given conditions.
|
|
578
458
|
* Useful for pagination.
|
|
579
459
|
*/
|
|
580
|
-
|
|
460
|
+
countBy(where) {
|
|
581
461
|
return this.repo.countBy(where);
|
|
582
|
-
}
|
|
462
|
+
}
|
|
583
463
|
//#endregion
|
|
584
464
|
//#region crud operations / typeorm / find
|
|
585
465
|
/**
|
|
586
466
|
* Finds entities that match given find options.
|
|
587
467
|
*/
|
|
588
|
-
|
|
468
|
+
find(options) {
|
|
589
469
|
return this.repo.find(options);
|
|
590
|
-
}
|
|
470
|
+
}
|
|
591
471
|
//#endregion
|
|
592
472
|
//#region crud operations / typeorm / find by
|
|
593
473
|
/**
|
|
594
474
|
* Finds entities that match given find options.
|
|
595
475
|
*/
|
|
596
|
-
|
|
476
|
+
findBy(where) {
|
|
597
477
|
return this.repo.findBy(where);
|
|
598
|
-
}
|
|
478
|
+
}
|
|
599
479
|
//#endregion
|
|
600
480
|
//#region crud operations / typeorm / find and count
|
|
601
481
|
// async findAndCount(options: { take: number; skip: number }) {
|
|
@@ -614,9 +494,9 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
614
494
|
* Also counts all entities that match given conditions,
|
|
615
495
|
* but ignores pagination settings (from and take options).
|
|
616
496
|
*/
|
|
617
|
-
|
|
497
|
+
findAndCount(options) {
|
|
618
498
|
return this.repo.findAndCount(options);
|
|
619
|
-
}
|
|
499
|
+
}
|
|
620
500
|
//#endregion
|
|
621
501
|
//#region crud operations / typeorm / find and count by
|
|
622
502
|
/**
|
|
@@ -624,9 +504,9 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
624
504
|
* Also counts all entities that match given conditions,
|
|
625
505
|
* but ignores pagination settings (from and take options).
|
|
626
506
|
*/
|
|
627
|
-
|
|
507
|
+
findAndCountBy(where) {
|
|
628
508
|
return this.repo.findAndCountBy(where);
|
|
629
|
-
}
|
|
509
|
+
}
|
|
630
510
|
//#endregion
|
|
631
511
|
//#region crud operations / typeorm / find by ids
|
|
632
512
|
/**
|
|
@@ -639,27 +519,27 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
639
519
|
* id: In([1, 2, 3])
|
|
640
520
|
* })
|
|
641
521
|
*/
|
|
642
|
-
|
|
522
|
+
findByIds(ids) {
|
|
643
523
|
return this.repo.findByIds(ids);
|
|
644
|
-
}
|
|
524
|
+
}
|
|
645
525
|
//#endregion
|
|
646
526
|
//#region crud operations / typeorm / find one
|
|
647
527
|
/**
|
|
648
528
|
* Finds first entity by a given find options.
|
|
649
529
|
* If entity was not found in the database - returns null.
|
|
650
530
|
*/
|
|
651
|
-
|
|
531
|
+
findOne(options) {
|
|
652
532
|
return this.repo.findOne(options);
|
|
653
|
-
}
|
|
533
|
+
}
|
|
654
534
|
//#endregion
|
|
655
535
|
//#region crud operations / typeorm / find one by
|
|
656
536
|
/**
|
|
657
537
|
* Finds first entity that matches given where condition.
|
|
658
538
|
* If entity was not found in the database - returns null.
|
|
659
539
|
*/
|
|
660
|
-
|
|
540
|
+
findOneBy(where) {
|
|
661
541
|
return this.repo.findOneBy(where);
|
|
662
|
-
}
|
|
542
|
+
}
|
|
663
543
|
//#endregion
|
|
664
544
|
//#region crud operations / typeorm / find one or fail
|
|
665
545
|
/**
|
|
@@ -672,36 +552,36 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
672
552
|
* id: 1 // where "id" is your primary column name
|
|
673
553
|
* })
|
|
674
554
|
*/
|
|
675
|
-
|
|
555
|
+
findOneById(id) {
|
|
676
556
|
return this.repo.findOneById(id);
|
|
677
|
-
}
|
|
557
|
+
}
|
|
678
558
|
//#endregion
|
|
679
559
|
//#region crud operations / typeorm / find one or fail
|
|
680
560
|
/**
|
|
681
561
|
* Finds first entity by a given find options.
|
|
682
562
|
* If entity was not found in the database - rejects with error.
|
|
683
563
|
*/
|
|
684
|
-
|
|
564
|
+
findOneOrFail(options) {
|
|
685
565
|
return this.repo.findOneOrFail(options);
|
|
686
|
-
}
|
|
566
|
+
}
|
|
687
567
|
//#endregion
|
|
688
568
|
//#region crud operations / typeorm / find one by or fail
|
|
689
569
|
/**
|
|
690
570
|
* Finds first entity that matches given where condition.
|
|
691
571
|
* If entity was not found in the database - rejects with error.
|
|
692
572
|
*/
|
|
693
|
-
|
|
573
|
+
findOneByOrFail(where) {
|
|
694
574
|
return this.repo.findOneByOrFail(where);
|
|
695
|
-
}
|
|
575
|
+
}
|
|
696
576
|
//#endregion
|
|
697
577
|
//#region crud operations / typeorm / query
|
|
698
578
|
/**
|
|
699
579
|
* Executes a raw SQL query and returns a raw database results.
|
|
700
580
|
* Raw query execution is supported only by relational databases (MongoDB is not supported).
|
|
701
581
|
*/
|
|
702
|
-
|
|
582
|
+
query(query, parameters) {
|
|
703
583
|
return this.repo.query(query, parameters);
|
|
704
|
-
}
|
|
584
|
+
}
|
|
705
585
|
//#endregion
|
|
706
586
|
//#region crud operations / typeorm / clear
|
|
707
587
|
/**
|
|
@@ -710,71 +590,57 @@ var BaseRepository = /** @class */ (function (_super) {
|
|
|
710
590
|
* Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
|
|
711
591
|
* @see https://stackoverflow.com/a/5972738/925151
|
|
712
592
|
*/
|
|
713
|
-
|
|
593
|
+
clear() {
|
|
714
594
|
return this.repo.clear();
|
|
715
|
-
}
|
|
595
|
+
}
|
|
716
596
|
//#endregion
|
|
717
597
|
//#region crud operations / typeorm / increment
|
|
718
598
|
/**
|
|
719
599
|
* Increments some column by provided value of the entities matched given conditions.
|
|
720
600
|
*/
|
|
721
|
-
|
|
601
|
+
increment(conditions, propertyPath, value) {
|
|
722
602
|
return this.repo.increment(conditions, propertyPath, value);
|
|
723
|
-
}
|
|
603
|
+
}
|
|
724
604
|
//#endregion
|
|
725
605
|
//#region crud operations / typeorm / decrement
|
|
726
606
|
/**
|
|
727
607
|
* Decrements some column by provided value of the entities matched given conditions.
|
|
728
608
|
*/
|
|
729
|
-
|
|
609
|
+
decrement(conditions, propertyPath, value) {
|
|
730
610
|
return this.repo.decrement(conditions, propertyPath, value);
|
|
731
|
-
}
|
|
611
|
+
}
|
|
732
612
|
//#endregion
|
|
733
613
|
//#region crud operations / get all
|
|
734
614
|
/**
|
|
735
615
|
* @deprecated use findAndCount instead
|
|
736
616
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
};
|
|
617
|
+
async getAll() {
|
|
618
|
+
//#region @websqlFunc
|
|
619
|
+
// console.log('repo', this.__repository);
|
|
620
|
+
// console.log(
|
|
621
|
+
// `repo taget name "${ClassHelpers.getName(this.__repository.target)}"`,
|
|
622
|
+
// );
|
|
623
|
+
// debugger;
|
|
624
|
+
const totalCount = await this.repo.count();
|
|
625
|
+
const models = await this.repo.find();
|
|
626
|
+
// console.log('models', models);
|
|
627
|
+
// console.log('totalCount', totalCount);
|
|
628
|
+
return { models, totalCount };
|
|
629
|
+
//#endregion
|
|
630
|
+
}
|
|
755
631
|
//#endregion
|
|
756
632
|
//#region crud operations / get by id
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
switch (_a.label) {
|
|
762
|
-
case 0: return [4 /*yield*/, this.repo.findOne({
|
|
763
|
-
where: { id: id },
|
|
764
|
-
})];
|
|
765
|
-
case 1: return [4 /*yield*/, _a.sent()];
|
|
766
|
-
case 2:
|
|
767
|
-
model = _a.sent();
|
|
768
|
-
return [2 /*return*/, model];
|
|
769
|
-
}
|
|
770
|
-
});
|
|
633
|
+
async getBy(id) {
|
|
634
|
+
//#region @websqlFunc
|
|
635
|
+
const model = await await this.repo.findOne({
|
|
636
|
+
where: { id },
|
|
771
637
|
});
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
], BaseRepository);
|
|
777
|
-
return BaseRepository;
|
|
778
|
-
}(base_injector_1.BaseInjector));
|
|
638
|
+
return model;
|
|
639
|
+
//#endregion
|
|
640
|
+
}
|
|
641
|
+
};
|
|
779
642
|
exports.BaseRepository = BaseRepository;
|
|
643
|
+
exports.BaseRepository = BaseRepository = __decorate([
|
|
644
|
+
(0, repository_decorator_1.TaonRepository)({ className: 'BaseRepository' })
|
|
645
|
+
], BaseRepository);
|
|
780
646
|
//# sourceMappingURL=base-repository.js.map
|