taon 21.0.52 → 21.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/browser/package.json +1 -1
  2. package/browser-prod/package.json +1 -1
  3. package/icon-menu-taon.svg +15 -15
  4. package/lib/build-info._auto-generated_.d.ts +1 -1
  5. package/lib/build-info._auto-generated_.js +1 -1
  6. package/lib/package.json +1 -1
  7. package/lib/ui/index.js +2 -2
  8. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  9. package/lib-prod/base-classes/base-abstract-entity.js +19 -0
  10. package/lib-prod/base-classes/base-angular-service.js +84 -0
  11. package/lib-prod/base-classes/base-class.js +35 -0
  12. package/lib-prod/base-classes/{base-context.ts → base-context.js} +13 -15
  13. package/lib-prod/base-classes/base-controller.js +154 -0
  14. package/lib-prod/base-classes/base-crud-controller.js +264 -0
  15. package/lib-prod/base-classes/base-custom-repository.js +9 -0
  16. package/lib-prod/base-classes/{base-electron-service.ts → base-electron-service.js} +1 -12
  17. package/lib-prod/base-classes/base-entity.js +22 -0
  18. package/lib-prod/base-classes/base-file-upload.middleware.js +75 -0
  19. package/lib-prod/base-classes/base-injector.js +184 -0
  20. package/lib-prod/base-classes/base-middleware.js +9 -0
  21. package/lib-prod/base-classes/base-migration.js +20 -0
  22. package/lib-prod/base-classes/{base-provider.ts → base-provider.js} +2 -2
  23. package/lib-prod/base-classes/base-repository.js +617 -0
  24. package/lib-prod/base-classes/base-subscriber-for-entity.js +145 -0
  25. package/lib-prod/base-classes/{base.ts → base.js} +2 -15
  26. package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
  27. package/lib-prod/config/controller-config.js +28 -0
  28. package/lib-prod/config/controller-options.js +3 -0
  29. package/lib-prod/config/method-config.js +7 -0
  30. package/lib-prod/config/param-config.js +3 -0
  31. package/lib-prod/constants.js +33 -0
  32. package/lib-prod/context-db-migrations.js +342 -0
  33. package/lib-prod/create-context.js +217 -0
  34. package/lib-prod/decorators/classes/controller-decorator.js +17 -0
  35. package/lib-prod/decorators/classes/entity-decorator.js +28 -0
  36. package/lib-prod/decorators/classes/middleware-decorator.js +16 -0
  37. package/lib-prod/decorators/classes/migration-decorator.js +15 -0
  38. package/lib-prod/decorators/classes/provider-decorator.js +15 -0
  39. package/lib-prod/decorators/classes/repository-decorator.js +15 -0
  40. package/lib-prod/decorators/classes/subscriber-decorator.js +15 -0
  41. package/lib-prod/decorators/decorator-abstract-opt.js +2 -0
  42. package/lib-prod/decorators/http/http-decorators.js +20 -0
  43. package/lib-prod/decorators/http/http-methods-decorators.js +102 -0
  44. package/lib-prod/decorators/http/http-params-decorators.js +42 -0
  45. package/lib-prod/dependency-injection/di-container.js +30 -0
  46. package/lib-prod/endpoint-context-storage.js +31 -0
  47. package/lib-prod/endpoint-context.js +2397 -0
  48. package/lib-prod/entity-process.js +225 -0
  49. package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
  50. package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
  51. package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
  52. package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
  53. package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
  54. package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
  55. package/lib-prod/express-types.js +1 -0
  56. package/lib-prod/formly/formly.models.js +1 -0
  57. package/lib-prod/formly/fromly.js +205 -0
  58. package/lib-prod/formly/type-from-entity.js +51 -0
  59. package/lib-prod/get-response-value.js +22 -0
  60. package/lib-prod/global-state/taon-global-state/{index.ts → index.js} +2 -2
  61. package/lib-prod/global-state/taon-global-state/{taon-global-state.abstract.context.ts → taon-global-state.abstract.context.js} +9 -11
  62. package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +7 -0
  63. package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +42 -0
  64. package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +35 -0
  65. package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +12 -0
  66. package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +44 -0
  67. package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +12 -0
  68. package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +46 -0
  69. package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +22 -0
  70. package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +11 -0
  71. package/lib-prod/global-state/taon-transaction-registry/{index.ts → index.js} +2 -2
  72. package/lib-prod/global-state/taon-transaction-registry/{taon-transaction-registry.abstract.context.ts → taon-transaction-registry.abstract.context.js} +10 -12
  73. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +5 -0
  74. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +36 -0
  75. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +36 -0
  76. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +12 -0
  77. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +7 -0
  78. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +12 -0
  79. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +31 -0
  80. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +22 -0
  81. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +5 -0
  82. package/lib-prod/helpers/class-helpers.js +228 -0
  83. package/lib-prod/helpers/clone-obj.js +17 -0
  84. package/lib-prod/helpers/taon-helpers.js +147 -0
  85. package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
  86. package/lib-prod/index.js +252 -0
  87. package/lib-prod/{inject.ts → inject.js} +35 -57
  88. package/lib-prod/migrations/index.js +2 -0
  89. package/lib-prod/migrations/{migrations_index._auto-generated_.ts → migrations_index._auto-generated_.js} +0 -2
  90. package/lib-prod/models.js +78 -0
  91. package/lib-prod/orm/columns.js +64 -0
  92. package/lib-prod/orm/index.js +56 -0
  93. package/lib-prod/package.json +1 -1
  94. package/lib-prod/realtime/realtime-client.js +198 -0
  95. package/lib-prod/realtime/realtime-core.js +81 -0
  96. package/lib-prod/realtime/realtime-server.js +237 -0
  97. package/lib-prod/realtime/realtime-strategy/{index.ts → index.js} +1 -1
  98. package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +280 -0
  99. package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +289 -0
  100. package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +27 -0
  101. package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +11 -0
  102. package/lib-prod/realtime/realtime-subs-manager.js +88 -0
  103. package/lib-prod/realtime/realtime.models.js +2 -0
  104. package/lib-prod/symbols.js +108 -0
  105. package/lib-prod/ui/index.js +1 -0
  106. package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -0
  107. package/lib-prod/validators.js +80 -0
  108. package/lib-prod.split-namespaces.json +31 -91
  109. package/package.json +1 -1
  110. package/websql/package.json +1 -1
  111. package/websql-prod/package.json +1 -1
  112. package/lib-prod/base-classes/base-abstract-entity.ts +0 -34
  113. package/lib-prod/base-classes/base-angular-service.ts +0 -107
  114. package/lib-prod/base-classes/base-class.ts +0 -46
  115. package/lib-prod/base-classes/base-controller.ts +0 -240
  116. package/lib-prod/base-classes/base-crud-controller.ts +0 -298
  117. package/lib-prod/base-classes/base-custom-repository.ts +0 -10
  118. package/lib-prod/base-classes/base-entity.ts +0 -28
  119. package/lib-prod/base-classes/base-file-upload.middleware.ts +0 -92
  120. package/lib-prod/base-classes/base-injector.ts +0 -278
  121. package/lib-prod/base-classes/base-middleware.ts +0 -71
  122. package/lib-prod/base-classes/base-migration.ts +0 -26
  123. package/lib-prod/base-classes/base-repository.ts +0 -942
  124. package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
  125. package/lib-prod/config/controller-config.ts +0 -58
  126. package/lib-prod/config/controller-options.ts +0 -19
  127. package/lib-prod/config/method-config.ts +0 -55
  128. package/lib-prod/config/param-config.ts +0 -16
  129. package/lib-prod/constants.ts +0 -63
  130. package/lib-prod/context-db-migrations.ts +0 -488
  131. package/lib-prod/create-context.ts +0 -345
  132. package/lib-prod/decorators/classes/controller-decorator.ts +0 -25
  133. package/lib-prod/decorators/classes/entity-decorator.ts +0 -57
  134. package/lib-prod/decorators/classes/middleware-decorator.ts +0 -29
  135. package/lib-prod/decorators/classes/migration-decorator.ts +0 -27
  136. package/lib-prod/decorators/classes/provider-decorator.ts +0 -28
  137. package/lib-prod/decorators/classes/repository-decorator.ts +0 -26
  138. package/lib-prod/decorators/classes/subscriber-decorator.ts +0 -28
  139. package/lib-prod/decorators/decorator-abstract-opt.ts +0 -4
  140. package/lib-prod/decorators/http/http-decorators.ts +0 -26
  141. package/lib-prod/decorators/http/http-methods-decorators.ts +0 -275
  142. package/lib-prod/decorators/http/http-params-decorators.ts +0 -105
  143. package/lib-prod/dependency-injection/di-container.ts +0 -39
  144. package/lib-prod/endpoint-context-storage.ts +0 -47
  145. package/lib-prod/endpoint-context.ts +0 -3110
  146. package/lib-prod/entity-process.ts +0 -286
  147. package/lib-prod/express-types.ts +0 -4
  148. package/lib-prod/formly/formly.models.ts +0 -7
  149. package/lib-prod/formly/fromly.ts +0 -261
  150. package/lib-prod/formly/type-from-entity.ts +0 -80
  151. package/lib-prod/get-response-value.ts +0 -30
  152. package/lib-prod/global-state/taon-global-state/taon-global-state.constants.ts +0 -9
  153. package/lib-prod/global-state/taon-global-state/taon-global-state.controller.ts +0 -44
  154. package/lib-prod/global-state/taon-global-state/taon-global-state.entity.ts +0 -40
  155. package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.ts +0 -12
  156. package/lib-prod/global-state/taon-global-state/taon-global-state.models.ts +0 -48
  157. package/lib-prod/global-state/taon-global-state/taon-global-state.provider.ts +0 -16
  158. package/lib-prod/global-state/taon-global-state/taon-global-state.repository.ts +0 -47
  159. package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.ts +0 -18
  160. package/lib-prod/global-state/taon-global-state/taon-global-state.utils.ts +0 -21
  161. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.ts +0 -7
  162. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.ts +0 -38
  163. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.ts +0 -54
  164. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.ts +0 -12
  165. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.ts +0 -6
  166. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.ts +0 -16
  167. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.ts +0 -29
  168. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.ts +0 -20
  169. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.ts +0 -9
  170. package/lib-prod/helpers/class-helpers.ts +0 -315
  171. package/lib-prod/helpers/clone-obj.ts +0 -24
  172. package/lib-prod/helpers/taon-helpers.ts +0 -181
  173. package/lib-prod/index.ts +0 -323
  174. package/lib-prod/lib-info.md +0 -8
  175. package/lib-prod/migrations/index.ts +0 -2
  176. package/lib-prod/migrations/migrations-info.md +0 -6
  177. package/lib-prod/models.ts +0 -427
  178. package/lib-prod/orm/columns.ts +0 -121
  179. package/lib-prod/orm/index.ts +0 -62
  180. package/lib-prod/realtime/realtime-client.ts +0 -288
  181. package/lib-prod/realtime/realtime-core.ts +0 -134
  182. package/lib-prod/realtime/realtime-server.ts +0 -398
  183. package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.ts +0 -344
  184. package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.ts +0 -349
  185. package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.ts +0 -30
  186. package/lib-prod/realtime/realtime-strategy/realtime-strategy.ts +0 -21
  187. package/lib-prod/realtime/realtime-subs-manager.ts +0 -127
  188. package/lib-prod/realtime/realtime.models.ts +0 -33
  189. package/lib-prod/symbols.ts +0 -136
  190. package/lib-prod/ui/index.ts +0 -1
  191. package/lib-prod/ui/taon-admin-mode-configuration/index.ts +0 -1
  192. package/lib-prod/validators.ts +0 -103
  193. /package/lib-prod/env/{index.ts → index.js} +0 -0
@@ -0,0 +1,617 @@
1
+ //#region imports
2
+ import { MySqlQuerySource } from 'taon-type-sql/lib-prod';
3
+ import { Helpers__NS__warn } from 'tnp-core/lib-prod';
4
+ import { ___NS__isObject, ___NS__isUndefined, ___NS__lowerFirst } from 'tnp-core/lib-prod';
5
+ import { TaonRepository } from '../decorators/classes/repository-decorator';
6
+ import { ClassHelpers__NS__getName } from '../helpers/class-helpers';
7
+ import { TaonBaseCustomRepository } from './base-custom-repository';
8
+ //#endregion
9
+ const INDEX_KEYS_NO_FOR_UPDATE = ['id'];
10
+ let TaonBaseRepository = class TaonBaseRepository extends TaonBaseCustomRepository {
11
+ constructor(
12
+ // Injected through TaonBaseCrudController
13
+ __entityClassResolveFn) {
14
+ super();
15
+ this.REPOS_CACHE_KEY = Symbol('repository cache inside instance');
16
+ this.allowedTypesToUpdate = ['simple-json', 'simple-array', 'json'];
17
+ // @ts-ignore
18
+ this.entityClassResolveFn = __entityClassResolveFn;
19
+ }
20
+ get dbQuery() {
21
+ //#region @websqlFunc
22
+ if (!this.__dbQuery) {
23
+ if (!this.ctx) {
24
+ return; // TODO
25
+ throw new Error(`[TaonBaseRepository] Context not inited for class ${ClassHelpers__NS__getName(this)}`);
26
+ }
27
+ const connection = this.ctx?.connection;
28
+ if (!connection) {
29
+ throw new Error(`[TaonBaseRepository] Database not inited for context ${this.ctx?.contextName}`);
30
+ }
31
+ this.__dbQuery = new MySqlQuerySource(connection);
32
+ }
33
+ return this.__dbQuery;
34
+ //#endregion
35
+ }
36
+ //#endregion
37
+ //#region connection
38
+ get connection() {
39
+ //#region @websqlFunc
40
+ return this.ctx?.connection;
41
+ //#endregion
42
+ }
43
+ //#endregion
44
+ //#region repository
45
+ get repository() {
46
+ //#region @websqlFunc
47
+ if (this[this.REPOS_CACHE_KEY]) {
48
+ return this[this.REPOS_CACHE_KEY];
49
+ }
50
+ const resolvedRepoClass = this.entityClassResolveFn();
51
+ const resolvedRepoName = ClassHelpers__NS__getName(resolvedRepoClass);
52
+ const repo = this.ctx.repos.get(resolvedRepoName);
53
+ // TODO better recognize what is class in context
54
+ if (!repo) {
55
+ throw `[TaonBaseRepository] Repository for entity "${resolvedRepoName}"
56
+ not found in context "${this.ctx?.contextName}".
57
+
58
+ Is ${resolvedRepoName} a Taon entity class ?
59
+
60
+ OR
61
+
62
+ If ${resolvedRepoName} is a Taon Custom Repository, then use this:
63
+
64
+ ...
65
+ ${___NS__lowerFirst(resolvedRepoName)} = injectCustomRepository(${resolvedRepoName});
66
+ ...
67
+
68
+ `;
69
+ }
70
+ this[this.REPOS_CACHE_KEY] = repo;
71
+ return this[this.REPOS_CACHE_KEY];
72
+ //#endregion
73
+ }
74
+ /**
75
+ * target for repository
76
+ */
77
+ get target() {
78
+ //#region @websqlFunc
79
+ return this?.repository?.target;
80
+ //#endregion
81
+ }
82
+ /**
83
+ * alias to repository
84
+ */
85
+ get repo() {
86
+ //#region @websqlFunc
87
+ return this.repository;
88
+ //#endregion
89
+ }
90
+ get repositoryExists() {
91
+ //#region @websqlFunc
92
+ return !!this.repository;
93
+ //#endregion
94
+ }
95
+ //#endregion
96
+ //#region crud operations / typeorm / has id
97
+ /**
98
+ * Checks if entity has an id.
99
+ * If entity composite compose ids, it will check them all.
100
+ */
101
+ hasId(entity) {
102
+ return this.repo.hasId(entity);
103
+ }
104
+ //#endregion
105
+ //#region crud operations / typeorm / get id
106
+ /**
107
+ * Gets entity mixed id.
108
+ */
109
+ getId(entity) {
110
+ return this.repo.getId(entity);
111
+ }
112
+ //#endregion
113
+ //#region crud operations / typeorm / create & bulk create
114
+ /**
115
+ Saves a given entity in the database.
116
+ * If entity does not exist in the database then inserts, otherwise updates.
117
+ */
118
+ async save(item, options) {
119
+ //#region @websqlFunc
120
+ // if (!this.repo) {
121
+ // debugger;
122
+ // }
123
+ let model = await this.repo.create(item);
124
+ model = await this.repo.save(model, options);
125
+ const { id } = model;
126
+ model = await this.repo.findOne({
127
+ where: { id },
128
+ });
129
+ return model;
130
+ //#endregion
131
+ }
132
+ /**
133
+ * Creates a new entity instance or instances.
134
+ * Can copy properties from the given object into new entities.
135
+ */
136
+ create(plainEntityLikeOrPlainEntityLikes) {
137
+ return this.repo.create(plainEntityLikeOrPlainEntityLikes);
138
+ }
139
+ async bulkSave(items, options) {
140
+ //#region @websqlFunc
141
+ const models = [];
142
+ for (let index = 0; index < items.length; index++) {
143
+ const item = items[index];
144
+ // TODO FIX THIS / REFACTOR
145
+ const model = await this.save(item, options);
146
+ models.push(model);
147
+ }
148
+ return models;
149
+ //#endregion
150
+ }
151
+ /**
152
+ * @deprecated use bulkSave instead
153
+ */
154
+ async bulkCreate(items, options) {
155
+ return this.bulkSave(items, options);
156
+ }
157
+ //#region old typeorm version
158
+ /**
159
+ * Saves all given entities in the database.
160
+ * If entities do not exist in the database then inserts, otherwise updates.
161
+ */
162
+ // save<T extends DeepPartial<Entity>>(
163
+ // entities: T[],
164
+ // options: SaveOptions & {
165
+ // reload: false;
166
+ // },
167
+ // ): Promise<T[]>;
168
+ // /**
169
+ // * Saves all given entities in the database.
170
+ // * If entities do not exist in the database then inserts, otherwise updates.
171
+ // */
172
+ // save<T extends DeepPartial<Entity>>(
173
+ // entities: T[],
174
+ // options?: SaveOptions,
175
+ // ): Promise<(T & Entity)[]>;
176
+ // /**
177
+ // * Saves a given entity in the database.
178
+ // * If entity does not exist in the database then inserts, otherwise updates.
179
+ // */
180
+ // save<T extends DeepPartial<Entity>>(
181
+ // entity: T,
182
+ // options: SaveOptions & {
183
+ // reload: false;
184
+ // },
185
+ // ): Promise<T>;
186
+ // /**
187
+ // * Saves a given entity in the database.
188
+ // * If entity does not exist in the database then inserts, otherwise updates.
189
+ // */
190
+ // save<T extends DeepPartial<Entity>>(
191
+ // entity: T,
192
+ // options?: SaveOptions,
193
+ // ): Promise<T & Entity> {
194
+ // return this.repo.save(entity, options);
195
+ // }
196
+ //#endregion
197
+ //#endregion
198
+ //#region crud operations / typeorm / merge
199
+ /**
200
+ * Merges multiple entities (or entity-like objects) into a given entity.
201
+ */
202
+ merge(mergeIntoEntity, ...entityLikes) {
203
+ return this.repo.merge(mergeIntoEntity, ...entityLikes);
204
+ }
205
+ //#endregion
206
+ //#region crud operations / typeorm / preload
207
+ /**
208
+ * Creates a new entity from the given plain javascript object. If entity already exist in the database, then
209
+ * it loads it (and everything related to it), replaces all values with the new ones from the given object
210
+ * and returns this new entity. This new entity is actually a loaded from the db entity with all properties
211
+ * replaced from the new object.
212
+ *
213
+ * Note that given entity-like object must have an entity id / primary key to find entity by.
214
+ * Returns undefined if entity with given id was not found.
215
+ */
216
+ preload(entityLike) {
217
+ return this.repo.preload(entityLike);
218
+ }
219
+ //#endregion
220
+ //#region crud operations / typeorm / remove (delete) & bulk remove (delete)
221
+ /**
222
+ * Removes a given entities from the database.
223
+ */
224
+ async remove(idOrEntity) {
225
+ //#region @websqlFunc
226
+ if (___NS__isObject(idOrEntity)) {
227
+ idOrEntity = idOrEntity.id;
228
+ }
229
+ const deletedEntity = await this.repo.findOne({
230
+ where: { id: idOrEntity },
231
+ });
232
+ if (!deletedEntity) {
233
+ Helpers__NS__warn(`[TaonBaseRepository] Entity "${ClassHelpers__NS__getName(this.repo.target)}" ` + `with id ${idOrEntity} not found, cannot remove`);
234
+ return;
235
+ }
236
+ const idCopy = deletedEntity.id;
237
+ await this.repo.remove(deletedEntity);
238
+ deletedEntity.id = idCopy;
239
+ return deletedEntity;
240
+ //#endregion
241
+ }
242
+ /**
243
+ * alias to remove
244
+ */
245
+ async delete(idOrEntity) {
246
+ return this.remove(idOrEntity);
247
+ }
248
+ /**
249
+ * alias to removeById
250
+ */
251
+ async deleteById(id) {
252
+ return this.remove(id);
253
+ }
254
+ async bulkRemove(idsOrEntities) {
255
+ //#region @websqlFunc
256
+ idsOrEntities = idsOrEntities.map(id => {
257
+ return ___NS__isObject(id) ? id.id : id;
258
+ });
259
+ const models = [];
260
+ for (let index = 0; index < idsOrEntities.length; index++) {
261
+ const id = idsOrEntities[index];
262
+ const model = await this.remove(id);
263
+ models.push(model);
264
+ }
265
+ return models;
266
+ //#endregion
267
+ }
268
+ async bulkDelete(ids) {
269
+ return this.bulkRemove(ids);
270
+ }
271
+ /**
272
+ * Records the delete date of a given entity.
273
+ */
274
+ softRemove(entity, options) {
275
+ return this.repo.softRemove(entity, options);
276
+ }
277
+ /**
278
+ * Recovers a given entity in the database.
279
+ */
280
+ recover(entity, options) {
281
+ return this.repo.recover(entity, options);
282
+ }
283
+ //#endregion
284
+ //#region crud operations / typeorm / insert
285
+ /**
286
+ * Inserts a given entity into the database.
287
+ * Unlike save method executes a primitive operation without cascades, relations and other operations included.
288
+ * Executes fast and efficient INSERT query.
289
+ * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
290
+ */
291
+ insert(entity) {
292
+ // debugger;
293
+ return this.repo.insert(entity);
294
+ }
295
+ //#endregion
296
+ //#region crud operations / typeorm / update & build update
297
+ async update(item) {
298
+ //#region @websqlFunc
299
+ const { id } = item;
300
+ return await this.updateById(id, item);
301
+ //#endregion
302
+ }
303
+ async updateById(id, item) {
304
+ //#region @websqlFunc
305
+ const allowedPropsToUpdate = [];
306
+ for (const key in item) {
307
+ const metadataColumn = this.repo.metadata.ownColumns.find(c => c.propertyName === key);
308
+ if (___NS__isObject(item) &&
309
+ item.hasOwnProperty(key) &&
310
+ (typeof item[key] !== 'object' ||
311
+ this.allowedTypesToUpdate.includes(metadataColumn?.type)) &&
312
+ !___NS__isUndefined(metadataColumn)) {
313
+ allowedPropsToUpdate.push(key);
314
+ }
315
+ }
316
+ for (let i = 0; i < allowedPropsToUpdate.length; i++) {
317
+ const key = allowedPropsToUpdate[i];
318
+ if (!INDEX_KEYS_NO_FOR_UPDATE.includes(key.toLowerCase())) {
319
+ // const raw = ___NS__isBoolean(item[key]) || ___NS__isNumber(item[key]) || ___NS__isNull(item[key]); // TODO does this make any sense ?
320
+ const toSet = item[key];
321
+ // const tableName = tableNameFrom(this.entity as any);
322
+ await this.repo.update({
323
+ id,
324
+ }, {
325
+ [key]: toSet,
326
+ });
327
+ // await this.repo.query(
328
+ // `UPDATE '${tableName}' as ${table}
329
+ // SET ${key}=${toSet}
330
+ // WHERE ${table}.id='${id}'
331
+ // `);
332
+ }
333
+ }
334
+ let model = await this.repo.findOne({
335
+ where: { id },
336
+ });
337
+ return model;
338
+ //#endregion
339
+ }
340
+ async bulkUpdate(items) {
341
+ //#region @websqlFunc
342
+ const models = [];
343
+ for (let index = 0; index < items.length; index++) {
344
+ const item = items[index];
345
+ const { id } = item; // TOOD
346
+ const model = await this.updateById(id, item);
347
+ models.push(model);
348
+ }
349
+ return { models };
350
+ //#endregion
351
+ }
352
+ //#region tpeorm update version
353
+ // this version suck and will not return update entity
354
+ // /**
355
+ // * Updates entity partially. Entity can be found by a given conditions.
356
+ // * Unlike save method executes a primitive operation without cascades, relations and other operations included.
357
+ // * Executes fast and efficient UPDATE query.
358
+ // * Does not check if entity exist in the database.
359
+ // */
360
+ // update(
361
+ // criteria:
362
+ // | string
363
+ // | string[]
364
+ // | number
365
+ // | number[]
366
+ // | Date
367
+ // | Date[]
368
+ // | ObjectID
369
+ // | ObjectID[]
370
+ // | FindOptionsWhere<Entity>,
371
+ // partialEntity: QueryDeepPartialEntity<Entity>,
372
+ // ): Promise<UpdateResult> {
373
+ // return this.repo.update(criteria, partialEntity);
374
+ // }
375
+ //#endregion
376
+ //#endregion
377
+ //#region crud operations / typeorm / upsert
378
+ /**
379
+ * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
380
+ * Unlike save method executes a primitive operation without cascades, relations and other operations included.
381
+ * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
382
+ */
383
+ upsert(entityOrEntities, conflictPathsOrOptions) {
384
+ return this.repo.upsert(entityOrEntities, conflictPathsOrOptions);
385
+ }
386
+ //#endregion
387
+ //#region crud operations / typeorm / soft delete
388
+ /**
389
+ * Records the delete date of entities by a given criteria.
390
+ * Unlike save method executes a primitive operation without cascades, relations and other operations included.
391
+ * Executes fast and efficient SOFT-DELETE query.
392
+ * Does not check if entity exist in the database.
393
+ */
394
+ softDelete(criteria) {
395
+ return this.repo.softDelete(criteria);
396
+ }
397
+ //#endregion
398
+ //#region crud operations / typeorm / restore
399
+ /**
400
+ * Restores entities by a given criteria.
401
+ * Unlike save method executes a primitive operation without cascades, relations and other operations included.
402
+ * Executes fast and efficient SOFT-DELETE query.
403
+ * Does not check if entity exist in the database.
404
+ */
405
+ restore(criteria) {
406
+ return this.repo.restore(criteria);
407
+ }
408
+ //#endregion
409
+ //#region crud operations / typeorm / count
410
+ /**
411
+ * Counts entities that match given options.
412
+ * Useful for pagination.
413
+ */
414
+ count(options) {
415
+ return this.repo.count(options);
416
+ }
417
+ //#endregion
418
+ //#region crud operations / typeorm / count by
419
+ /**
420
+ * Counts entities that match given conditions.
421
+ * Useful for pagination.
422
+ */
423
+ countBy(where) {
424
+ return this.repo.countBy(where);
425
+ }
426
+ //#endregion
427
+ //#region crud operations / typeorm / find
428
+ /**
429
+ * Finds entities that match given find options.
430
+ */
431
+ find(options) {
432
+ return this.repo.find(options);
433
+ }
434
+ //#endregion
435
+ //#region crud operations / typeorm / find by
436
+ /**
437
+ * Finds entities that match given find options.
438
+ */
439
+ findBy(where) {
440
+ return this.repo.findBy(where);
441
+ }
442
+ //#endregion
443
+ //#region crud operations / typeorm / find and count
444
+ // async findAndCount(options: { take: number; skip: number }) {
445
+ // const { take, skip } = options;
446
+ // const [result, total] = await this.repo.findAndCount({
447
+ // // where: { name: Like('%' + keyword + '%') },
448
+ // // order: { name: "DESC" },
449
+ // take: take,
450
+ // skip: skip,
451
+ // });
452
+ // return { result, total };
453
+ // }
454
+ //
455
+ /**
456
+ * Finds entities that match given find options.
457
+ * Also counts all entities that match given conditions,
458
+ * but ignores pagination settings (from and take options).
459
+ */
460
+ findAndCount(options) {
461
+ return this.repo.findAndCount(options);
462
+ }
463
+ //#endregion
464
+ //#region crud operations / typeorm / find and count by
465
+ /**
466
+ * Finds entities that match given WHERE conditions.
467
+ * Also counts all entities that match given conditions,
468
+ * but ignores pagination settings (from and take options).
469
+ */
470
+ findAndCountBy(where) {
471
+ return this.repo.findAndCountBy(where);
472
+ }
473
+ //#endregion
474
+ //#region crud operations / typeorm / find by ids
475
+ /**
476
+ * Finds entities with ids.
477
+ * Optionally find options or conditions can be applied.
478
+ *
479
+ * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:
480
+ *
481
+ * .findBy({
482
+ * id: In([1, 2, 3])
483
+ * })
484
+ */
485
+ findByIds(ids) {
486
+ return this.repo.findByIds(ids);
487
+ }
488
+ //#endregion
489
+ //#region crud operations / typeorm / find one
490
+ /**
491
+ * Finds first entity by a given find options.
492
+ * If entity was not found in the database - returns null.
493
+ */
494
+ findOne(options) {
495
+ return this.repo.findOne(options);
496
+ }
497
+ //#endregion
498
+ //#region crud operations / typeorm / find one by
499
+ /**
500
+ * Finds first entity that matches given where condition.
501
+ * If entity was not found in the database - returns null.
502
+ */
503
+ findOneBy(where) {
504
+ return this.repo.findOneBy(where);
505
+ }
506
+ //#endregion
507
+ //#region crud operations / typeorm / find one or fail
508
+ /**
509
+ * Finds first entity that matches given id.
510
+ * If entity was not found in the database - returns null.
511
+ *
512
+ * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:
513
+ *
514
+ * .findOneBy({
515
+ * id: 1 // where "id" is your primary column name
516
+ * })
517
+ */
518
+ findOneById(id) {
519
+ return this.repo.findOneById(id);
520
+ }
521
+ //#endregion
522
+ //#region crud operations / typeorm / find one or fail
523
+ /**
524
+ * Finds first entity by a given find options.
525
+ * If entity was not found in the database - rejects with error.
526
+ */
527
+ findOneOrFail(options) {
528
+ return this.repo.findOneOrFail(options);
529
+ }
530
+ //#endregion
531
+ //#region crud operations / typeorm / find one by or fail
532
+ /**
533
+ * Finds first entity that matches given where condition.
534
+ * If entity was not found in the database - rejects with error.
535
+ */
536
+ findOneByOrFail(where) {
537
+ return this.repo.findOneByOrFail(where);
538
+ }
539
+ //#endregion
540
+ //#region crud operations / typeorm / query
541
+ /**
542
+ * Executes a raw SQL query and returns a raw database results.
543
+ * Raw query execution is supported only by relational databases (MongoDB is not supported).
544
+ */
545
+ query(query, parameters) {
546
+ return this.repo.query(query, parameters);
547
+ }
548
+ //#endregion
549
+ //#region crud operations / typeorm / query
550
+ /**
551
+ * Executes a raw SQL query and returns a raw database results.
552
+ * Raw query execution is supported only by relational databases (MongoDB is not supported).
553
+ */
554
+ createQueryBuilder(alias, queryRunner) {
555
+ return this.repo.createQueryBuilder(alias, queryRunner);
556
+ }
557
+ //#endregion
558
+ //#region crud operations / typeorm / clear
559
+ /**
560
+ * Clears all the data from the given table/collection (truncates/drops it).
561
+ *
562
+ * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
563
+ * @see https://stackoverflow.com/a/5972738/925151
564
+ */
565
+ clear() {
566
+ return this.repo.clear();
567
+ }
568
+ //#endregion
569
+ //#region crud operations / typeorm / increment
570
+ /**
571
+ * Increments some column by provided value of the entities matched given conditions.
572
+ */
573
+ increment(conditions, propertyPath, value) {
574
+ return this.repo.increment(conditions, propertyPath, value);
575
+ }
576
+ //#endregion
577
+ //#region crud operations / typeorm / decrement
578
+ /**
579
+ * Decrements some column by provided value of the entities matched given conditions.
580
+ */
581
+ decrement(conditions, propertyPath, value) {
582
+ return this.repo.decrement(conditions, propertyPath, value);
583
+ }
584
+ //#endregion
585
+ //#region crud operations / get all
586
+ /**
587
+ * @deprecated use findAndCount instead
588
+ */
589
+ async getAll() {
590
+ //#region @websqlFunc
591
+ // console.log('repo', this.__repository);
592
+ // console.log(
593
+ // `repo taget name "${ClassHelpers__NS__getName(this.__repository.target)}"`,
594
+ // );
595
+ // debugger;
596
+ const totalCount = await this.repo.count();
597
+ const models = await this.repo.find();
598
+ // console.log('models', models);
599
+ // console.log('totalCount', totalCount);
600
+ return { models, totalCount };
601
+ //#endregion
602
+ }
603
+ //#endregion
604
+ //#region crud operations / get by id
605
+ async getBy(id) {
606
+ //#region @websqlFunc
607
+ const model = await await this.repo.findOne({
608
+ where: { id },
609
+ });
610
+ return model;
611
+ //#endregion
612
+ }
613
+ };
614
+ TaonBaseRepository = __decorate([
615
+ TaonRepository({ className: 'TaonBaseRepository' })
616
+ ], TaonBaseRepository);
617
+ export { TaonBaseRepository };