taon 21.0.52 → 21.0.53

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