@tstdl/base 0.93.87 → 0.93.90

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 (314) hide show
  1. package/ai/genkit/helpers.d.ts +3 -1
  2. package/ai/genkit/helpers.js +3 -3
  3. package/api/server/gateway.d.ts +3 -0
  4. package/api/server/gateway.js +15 -4
  5. package/api/server/middlewares/catch-error.middleware.js +2 -4
  6. package/api/server/middlewares/cors.middleware.js +2 -3
  7. package/api/server/middlewares/csrf.middleware.d.ts +41 -0
  8. package/api/server/middlewares/csrf.middleware.js +108 -0
  9. package/api/server/middlewares/index.d.ts +1 -0
  10. package/api/server/middlewares/index.js +1 -0
  11. package/api/server/module.d.ts +8 -2
  12. package/api/server/module.js +14 -8
  13. package/api/server/tests/csrf.middleware.test.js +91 -0
  14. package/audit/drizzle/{0000_bored_stick.sql → 0000_lumpy_thunderball.sql} +3 -3
  15. package/audit/drizzle/meta/0000_snapshot.json +4 -4
  16. package/audit/drizzle/meta/_journal.json +2 -9
  17. package/audit/module.d.ts +4 -1
  18. package/audit/module.js +3 -2
  19. package/audit/schemas.d.ts +1 -1
  20. package/audit/types.d.ts +1 -1
  21. package/audit/types.js +1 -1
  22. package/authentication/client/authentication.service.d.ts +14 -1
  23. package/authentication/client/authentication.service.js +82 -23
  24. package/authentication/client/http-client.middleware.d.ts +6 -0
  25. package/authentication/client/http-client.middleware.js +36 -0
  26. package/authentication/client/module.js +8 -2
  27. package/authentication/models/service-account.model.d.ts +2 -2
  28. package/authentication/models/service-account.model.js +10 -5
  29. package/authentication/models/subject.model.d.ts +20 -5
  30. package/authentication/models/subject.model.js +34 -29
  31. package/authentication/models/system-account.model.d.ts +3 -2
  32. package/authentication/models/system-account.model.js +11 -5
  33. package/authentication/models/user.model.d.ts +2 -11
  34. package/authentication/models/user.model.js +5 -16
  35. package/authentication/server/authentication-api-request-token.provider.d.ts +0 -2
  36. package/authentication/server/authentication-api-request-token.provider.js +3 -11
  37. package/authentication/server/authentication.api-controller.d.ts +1 -2
  38. package/authentication/server/authentication.api-controller.js +8 -9
  39. package/authentication/server/authentication.audit.d.ts +3 -2
  40. package/authentication/server/authentication.service.d.ts +27 -1
  41. package/authentication/server/authentication.service.js +67 -18
  42. package/authentication/server/drizzle/{0000_normal_paper_doll.sql → 0000_soft_tag.sql} +25 -32
  43. package/authentication/server/drizzle/meta/0000_snapshot.json +180 -205
  44. package/authentication/server/drizzle/meta/_journal.json +2 -2
  45. package/authentication/server/helper.js +9 -2
  46. package/authentication/server/module.d.ts +4 -1
  47. package/authentication/server/module.js +9 -5
  48. package/authentication/server/schemas.d.ts +2 -1
  49. package/authentication/server/schemas.js +2 -2
  50. package/authentication/server/subject.service.d.ts +17 -11
  51. package/authentication/server/subject.service.js +86 -84
  52. package/authentication/tests/authentication-ancillary.service.test.d.ts +1 -0
  53. package/authentication/tests/authentication-ancillary.service.test.js +13 -0
  54. package/authentication/tests/authentication-secret-requirements.validator.test.d.ts +1 -0
  55. package/authentication/tests/authentication-secret-requirements.validator.test.js +29 -0
  56. package/authentication/tests/authentication.api-controller.test.d.ts +1 -0
  57. package/authentication/tests/authentication.api-controller.test.js +88 -0
  58. package/authentication/tests/authentication.api-request-token.provider.test.d.ts +1 -0
  59. package/authentication/tests/authentication.api-request-token.provider.test.js +48 -0
  60. package/authentication/tests/authentication.client-middleware.test.d.ts +1 -0
  61. package/authentication/tests/authentication.client-middleware.test.js +23 -0
  62. package/authentication/tests/authentication.client-service.test.d.ts +1 -0
  63. package/authentication/tests/authentication.client-service.test.js +70 -0
  64. package/authentication/tests/authentication.service.test.d.ts +1 -0
  65. package/authentication/tests/authentication.service.test.js +186 -0
  66. package/authentication/tests/authentication.test-ancillary-service.d.ts +9 -0
  67. package/authentication/tests/authentication.test-ancillary-service.js +27 -0
  68. package/authentication/tests/helper.test.d.ts +1 -0
  69. package/authentication/tests/helper.test.js +107 -0
  70. package/authentication/tests/secret-requirements.error.test.d.ts +1 -0
  71. package/authentication/tests/secret-requirements.error.test.js +14 -0
  72. package/authentication/tests/subject.service.test.d.ts +1 -0
  73. package/authentication/tests/subject.service.test.js +140 -0
  74. package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +1 -1
  75. package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
  76. package/circuit-breaker/postgres/module.d.ts +7 -1
  77. package/circuit-breaker/postgres/module.js +8 -6
  78. package/circuit-breaker/tests/circuit-breaker.test.js +2 -22
  79. package/document-management/api/document-management.api.js +2 -6
  80. package/document-management/server/services/document-validation.service.js +6 -5
  81. package/document-management/server/services/document-workflow.service.js +5 -5
  82. package/document-management/service-models/document-folders.view-model.d.ts +5 -2
  83. package/document-management/service-models/document-folders.view-model.js +42 -9
  84. package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
  85. package/examples/document-management/main.js +4 -4
  86. package/http/client/adapters/undici.adapter.d.ts +7 -5
  87. package/http/client/adapters/undici.adapter.js +13 -10
  88. package/http/client/module.d.ts +3 -1
  89. package/http/client/module.js +8 -9
  90. package/http/server/http-server.d.ts +2 -0
  91. package/http/server/node/module.d.ts +6 -2
  92. package/http/server/node/module.js +6 -4
  93. package/http/server/node/node-http-server.d.ts +2 -0
  94. package/http/server/node/node-http-server.js +7 -0
  95. package/http/types.d.ts +1 -1
  96. package/key-value-store/postgres/module.d.ts +7 -1
  97. package/key-value-store/postgres/module.js +7 -3
  98. package/lock/postgres/lock.js +0 -1
  99. package/lock/postgres/module.d.ts +7 -1
  100. package/lock/postgres/module.js +9 -5
  101. package/logger/formatter.d.ts +2 -0
  102. package/logger/formatters/json.js +2 -2
  103. package/logger/formatters/pretty-print.js +8 -10
  104. package/logger/logger.d.ts +1 -1
  105. package/logger/logger.js +15 -12
  106. package/message-bus/local/module.d.ts +5 -2
  107. package/message-bus/local/module.js +5 -4
  108. package/module/module.d.ts +2 -1
  109. package/module/module.js +3 -0
  110. package/module/modules/web-server.module.d.ts +11 -6
  111. package/module/modules/web-server.module.js +15 -10
  112. package/orm/decorators.d.ts +24 -1
  113. package/orm/decorators.js +40 -4
  114. package/orm/query/base.d.ts +17 -17
  115. package/orm/query/base.js +1 -1
  116. package/orm/repository.types.d.ts +45 -1
  117. package/orm/schemas/tsvector.js +1 -1
  118. package/orm/server/drizzle/schema-converter.d.ts +3 -1
  119. package/orm/server/drizzle/schema-converter.js +120 -14
  120. package/orm/server/index.d.ts +1 -0
  121. package/orm/server/index.js +1 -0
  122. package/orm/server/module.d.ts +4 -2
  123. package/orm/server/module.js +6 -5
  124. package/orm/server/query-converter.d.ts +6 -3
  125. package/orm/server/query-converter.js +32 -20
  126. package/orm/server/repository-config.d.ts +8 -0
  127. package/orm/server/repository-config.js +8 -0
  128. package/orm/server/repository.d.ts +117 -43
  129. package/orm/server/repository.js +757 -253
  130. package/orm/server/transaction.d.ts +4 -2
  131. package/orm/server/transaction.js +14 -5
  132. package/orm/server/transactional.d.ts +6 -2
  133. package/orm/server/transactional.js +39 -9
  134. package/orm/server/types.d.ts +2 -0
  135. package/orm/sqls/case-when.d.ts +3 -3
  136. package/orm/sqls/case-when.js +2 -2
  137. package/orm/sqls/sqls.d.ts +31 -5
  138. package/orm/sqls/sqls.js +69 -6
  139. package/orm/tests/data-types.test.d.ts +1 -0
  140. package/orm/tests/data-types.test.js +39 -0
  141. package/orm/tests/decorators.test.d.ts +1 -0
  142. package/orm/tests/decorators.test.js +77 -0
  143. package/orm/tests/encryption.test.d.ts +1 -0
  144. package/orm/tests/encryption.test.js +34 -0
  145. package/orm/tests/query-complex.test.d.ts +1 -0
  146. package/orm/tests/query-complex.test.js +203 -0
  147. package/orm/tests/query-converter-complex.test.d.ts +1 -0
  148. package/orm/tests/query-converter-complex.test.js +126 -0
  149. package/orm/tests/query-converter.test.d.ts +1 -0
  150. package/orm/tests/query-converter.test.js +123 -0
  151. package/orm/tests/repository-advanced.test.d.ts +1 -0
  152. package/orm/tests/repository-advanced.test.js +232 -0
  153. package/orm/tests/repository-attributes.test.d.ts +1 -0
  154. package/orm/tests/repository-attributes.test.js +99 -0
  155. package/orm/tests/repository-comprehensive.test.d.ts +1 -0
  156. package/orm/tests/repository-comprehensive.test.js +187 -0
  157. package/orm/tests/repository-coverage.test.d.ts +1 -0
  158. package/orm/tests/repository-coverage.test.js +303 -0
  159. package/orm/tests/repository-cti-complex.test.d.ts +1 -0
  160. package/orm/tests/repository-cti-complex.test.js +170 -0
  161. package/orm/tests/repository-cti-embedded.test.d.ts +1 -0
  162. package/orm/tests/repository-cti-embedded.test.js +188 -0
  163. package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
  164. package/orm/tests/repository-cti-extensive.test.js +308 -0
  165. package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
  166. package/orm/tests/repository-cti-mapping.test.js +121 -0
  167. package/orm/tests/repository-cti-search.test.d.ts +1 -0
  168. package/orm/tests/repository-cti-search.test.js +152 -0
  169. package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
  170. package/orm/tests/repository-cti-soft-delete.test.js +115 -0
  171. package/orm/tests/repository-cti-transactions.test.d.ts +1 -0
  172. package/orm/tests/repository-cti-transactions.test.js +126 -0
  173. package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
  174. package/orm/tests/repository-cti-upsert-many.test.js +127 -0
  175. package/orm/tests/repository-cti.test.d.ts +1 -0
  176. package/orm/tests/repository-cti.test.js +456 -0
  177. package/orm/tests/repository-edge-cases.test.d.ts +1 -0
  178. package/orm/tests/repository-edge-cases.test.js +216 -0
  179. package/orm/tests/repository-expiration.test.d.ts +1 -0
  180. package/orm/tests/repository-expiration.test.js +153 -0
  181. package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
  182. package/orm/tests/repository-extra-coverage.test.js +546 -0
  183. package/orm/tests/repository-mapping.test.d.ts +1 -0
  184. package/orm/tests/repository-mapping.test.js +71 -0
  185. package/orm/tests/repository-regression.test.d.ts +1 -0
  186. package/orm/tests/repository-regression.test.js +330 -0
  187. package/orm/tests/repository-search-coverage.test.d.ts +1 -0
  188. package/orm/tests/repository-search-coverage.test.js +129 -0
  189. package/orm/tests/repository-search.test.d.ts +1 -0
  190. package/orm/tests/repository-search.test.js +116 -0
  191. package/orm/tests/repository-soft-delete.test.d.ts +1 -0
  192. package/orm/tests/repository-soft-delete.test.js +143 -0
  193. package/orm/tests/repository-transactions-nested.test.d.ts +1 -0
  194. package/orm/tests/repository-transactions-nested.test.js +202 -0
  195. package/orm/tests/repository-types.test.d.ts +1 -0
  196. package/orm/tests/repository-types.test.js +218 -0
  197. package/orm/tests/schema-converter.test.d.ts +1 -0
  198. package/orm/tests/schema-converter.test.js +81 -0
  199. package/orm/tests/schema-generation.test.d.ts +1 -0
  200. package/orm/tests/schema-generation.test.js +127 -0
  201. package/orm/tests/sql-helpers.test.d.ts +1 -0
  202. package/orm/tests/sql-helpers.test.js +67 -0
  203. package/orm/tests/transaction-safety.test.d.ts +1 -0
  204. package/orm/tests/transaction-safety.test.js +81 -0
  205. package/orm/tests/transactional.test.d.ts +1 -0
  206. package/orm/tests/transactional.test.js +224 -0
  207. package/orm/tests/utils.test.d.ts +1 -0
  208. package/orm/tests/utils.test.js +70 -0
  209. package/orm/utils.d.ts +7 -0
  210. package/orm/utils.js +26 -6
  211. package/package.json +12 -7
  212. package/pool/pool.js +1 -1
  213. package/rate-limit/index.d.ts +2 -0
  214. package/rate-limit/index.js +2 -0
  215. package/rate-limit/postgres/drizzle/0000_watery_rage.sql +7 -0
  216. package/{queue → rate-limit}/postgres/drizzle/meta/0000_snapshot.json +14 -39
  217. package/rate-limit/postgres/drizzle/meta/_journal.json +13 -0
  218. package/{queue → rate-limit}/postgres/drizzle.config.js +1 -1
  219. package/rate-limit/postgres/index.d.ts +4 -0
  220. package/rate-limit/postgres/index.js +4 -0
  221. package/rate-limit/postgres/module.d.ts +12 -0
  222. package/rate-limit/postgres/module.js +28 -0
  223. package/rate-limit/postgres/postgres-rate-limiter.d.ts +9 -0
  224. package/rate-limit/postgres/postgres-rate-limiter.js +56 -0
  225. package/rate-limit/postgres/rate-limit.model.d.ts +8 -0
  226. package/rate-limit/postgres/rate-limit.model.js +35 -0
  227. package/rate-limit/postgres/rate-limiter.provider.d.ts +6 -0
  228. package/rate-limit/postgres/rate-limiter.provider.js +21 -0
  229. package/rate-limit/postgres/schemas.d.ts +3 -0
  230. package/rate-limit/postgres/schemas.js +4 -0
  231. package/rate-limit/provider.d.ts +9 -0
  232. package/rate-limit/provider.js +2 -0
  233. package/rate-limit/rate-limiter.d.ts +35 -0
  234. package/rate-limit/rate-limiter.js +3 -0
  235. package/rate-limit/tests/postgres-rate-limiter.test.d.ts +1 -0
  236. package/rate-limit/tests/postgres-rate-limiter.test.js +92 -0
  237. package/signals/implementation/configure.d.ts +3 -0
  238. package/signals/implementation/configure.js +3 -0
  239. package/sse/data-stream-source.d.ts +1 -1
  240. package/sse/data-stream-source.js +6 -6
  241. package/task-queue/enqueue-batch.d.ts +17 -0
  242. package/task-queue/enqueue-batch.js +24 -0
  243. package/{queue → task-queue}/index.d.ts +1 -1
  244. package/{queue → task-queue}/index.js +1 -1
  245. package/task-queue/postgres/drizzle/0000_thin_black_panther.sql +74 -0
  246. package/task-queue/postgres/drizzle/meta/0000_snapshot.json +592 -0
  247. package/task-queue/postgres/drizzle/meta/_journal.json +13 -0
  248. package/task-queue/postgres/drizzle.config.d.ts +2 -0
  249. package/task-queue/postgres/drizzle.config.js +11 -0
  250. package/task-queue/postgres/index.d.ts +4 -0
  251. package/task-queue/postgres/index.js +4 -0
  252. package/task-queue/postgres/module.d.ts +12 -0
  253. package/task-queue/postgres/module.js +28 -0
  254. package/task-queue/postgres/schemas.d.ts +16 -0
  255. package/task-queue/postgres/schemas.js +8 -0
  256. package/task-queue/postgres/task-queue.d.ts +83 -0
  257. package/task-queue/postgres/task-queue.js +1054 -0
  258. package/task-queue/postgres/task-queue.provider.d.ts +7 -0
  259. package/{queue/postgres/queue.provider.js → task-queue/postgres/task-queue.provider.js} +8 -8
  260. package/task-queue/postgres/task.model.d.ts +39 -0
  261. package/task-queue/postgres/task.model.js +178 -0
  262. package/{queue → task-queue}/provider.d.ts +3 -3
  263. package/task-queue/provider.js +2 -0
  264. package/{queue → task-queue}/task-context.d.ts +7 -7
  265. package/{queue → task-queue}/task-context.js +8 -8
  266. package/{queue/queue.d.ts → task-queue/task-queue.d.ts} +128 -59
  267. package/task-queue/task-queue.js +200 -0
  268. package/task-queue/tests/complex.test.d.ts +1 -0
  269. package/task-queue/tests/complex.test.js +299 -0
  270. package/task-queue/tests/dependencies.test.d.ts +1 -0
  271. package/task-queue/tests/dependencies.test.js +174 -0
  272. package/task-queue/tests/queue.test.d.ts +1 -0
  273. package/task-queue/tests/queue.test.js +334 -0
  274. package/task-queue/tests/worker.test.d.ts +1 -0
  275. package/task-queue/tests/worker.test.js +163 -0
  276. package/test1.js +1 -1
  277. package/test4.js +2 -2
  278. package/unit-test/index.d.ts +1 -0
  279. package/unit-test/index.js +1 -0
  280. package/unit-test/integration-setup.d.ts +55 -0
  281. package/unit-test/integration-setup.js +182 -0
  282. package/utils/patterns.d.ts +3 -0
  283. package/utils/patterns.js +6 -1
  284. package/audit/drizzle/0001_previous_network.sql +0 -2
  285. package/audit/drizzle/meta/0001_snapshot.json +0 -195
  286. package/queue/enqueue-batch.d.ts +0 -17
  287. package/queue/enqueue-batch.js +0 -18
  288. package/queue/postgres/drizzle/0000_zippy_moondragon.sql +0 -11
  289. package/queue/postgres/drizzle/0001_certain_wild_pack.sql +0 -2
  290. package/queue/postgres/drizzle/0002_dear_meggan.sql +0 -2
  291. package/queue/postgres/drizzle/0003_tricky_venom.sql +0 -30
  292. package/queue/postgres/drizzle/meta/0001_snapshot.json +0 -103
  293. package/queue/postgres/drizzle/meta/0002_snapshot.json +0 -90
  294. package/queue/postgres/drizzle/meta/0003_snapshot.json +0 -288
  295. package/queue/postgres/drizzle/meta/_journal.json +0 -34
  296. package/queue/postgres/index.d.ts +0 -4
  297. package/queue/postgres/index.js +0 -4
  298. package/queue/postgres/module.d.ts +0 -9
  299. package/queue/postgres/module.js +0 -29
  300. package/queue/postgres/queue.d.ts +0 -60
  301. package/queue/postgres/queue.js +0 -681
  302. package/queue/postgres/queue.provider.d.ts +0 -7
  303. package/queue/postgres/schemas.d.ts +0 -14
  304. package/queue/postgres/schemas.js +0 -6
  305. package/queue/postgres/task.model.d.ts +0 -24
  306. package/queue/postgres/task.model.js +0 -115
  307. package/queue/provider.js +0 -2
  308. package/queue/queue.js +0 -131
  309. package/queue/tests/queue.test.js +0 -623
  310. package/test3.d.ts +0 -1
  311. package/test3.js +0 -47
  312. /package/{queue/tests/queue.test.d.ts → api/server/tests/csrf.middleware.test.d.ts} +0 -0
  313. /package/circuit-breaker/postgres/drizzle/{0000_hard_shocker.sql → 0000_cooing_korath.sql} +0 -0
  314. /package/{queue → rate-limit}/postgres/drizzle.config.d.ts +0 -0
@@ -0,0 +1,115 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injector, runInInjectionContext } from '../../injector/index.js';
11
+ import { StringProperty } from '../../schema/index.js';
12
+ import { sql } from 'drizzle-orm';
13
+ import { beforeAll, describe, expect, test } from 'vitest';
14
+ import { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
15
+ import { Entity } from '../entity.js';
16
+ import { configureOrm, Database } from '../server/index.js';
17
+ import { injectRepository } from '../server/repository.js';
18
+ describe('ORM Repository CTI Soft Delete (Integration)', () => {
19
+ let injector;
20
+ let db;
21
+ const schema = 'test_orm_cti_soft_delete';
22
+ let Base = class Base extends Entity {
23
+ type;
24
+ baseName;
25
+ };
26
+ __decorate([
27
+ StringProperty(),
28
+ Column({ name: 'type' }),
29
+ __metadata("design:type", String)
30
+ ], Base.prototype, "type", void 0);
31
+ __decorate([
32
+ StringProperty(),
33
+ __metadata("design:type", String)
34
+ ], Base.prototype, "baseName", void 0);
35
+ Base = __decorate([
36
+ Table('bases', { schema }),
37
+ Inheritance({ strategy: 'joined', discriminatorColumn: 'type' })
38
+ ], Base);
39
+ let Subtype = class Subtype extends Base {
40
+ subData;
41
+ };
42
+ __decorate([
43
+ StringProperty(),
44
+ __metadata("design:type", String)
45
+ ], Subtype.prototype, "subData", void 0);
46
+ Subtype = __decorate([
47
+ Table('subtypes', { schema }),
48
+ ChildEntity('subtype')
49
+ ], Subtype);
50
+ beforeAll(async () => {
51
+ injector = new Injector('Test');
52
+ configureOrm({
53
+ repositoryConfig: { schema },
54
+ connection: {
55
+ host: '127.0.0.1',
56
+ port: 5432,
57
+ user: 'tstdl',
58
+ password: 'wf7rq6glrk5jykne',
59
+ database: 'tstdl',
60
+ }
61
+ });
62
+ db = injector.resolve(Database);
63
+ await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
64
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('subtypes')} CASCADE`);
65
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('bases')} CASCADE`);
66
+ await db.execute(sql `
67
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('bases')} (
68
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
69
+ type TEXT NOT NULL,
70
+ base_name TEXT NOT NULL,
71
+ revision INTEGER NOT NULL,
72
+ revision_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
73
+ create_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
74
+ delete_timestamp TIMESTAMP WITH TIME ZONE,
75
+ attributes JSONB NOT NULL DEFAULT '{}',
76
+ UNIQUE (id, type)
77
+ )
78
+ `);
79
+ await db.execute(sql `
80
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('subtypes')} (
81
+ id UUID PRIMARY KEY,
82
+ type TEXT NOT NULL CHECK (type = 'subtype'),
83
+ sub_data TEXT NOT NULL,
84
+ FOREIGN KEY (id, type) REFERENCES ${sql.identifier(schema)}.${sql.identifier('bases')} (id, type) ON DELETE CASCADE
85
+ )
86
+ `);
87
+ });
88
+ test('should soft delete from subtype repository', async () => {
89
+ await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('bases')} CASCADE`);
90
+ await runInInjectionContext(injector, async () => {
91
+ const repo = injectRepository(Subtype);
92
+ const entity = await repo.insert(Object.assign(new Subtype(), { baseName: 'B1', subData: 'S1' }));
93
+ await repo.delete(entity.id);
94
+ const { rows } = await db.execute(sql `SELECT delete_timestamp FROM ${sql.identifier(schema)}.${sql.identifier('bases')} WHERE id = ${entity.id}`);
95
+ expect(rows[0].delete_timestamp).not.toBeNull();
96
+ expect(await repo.has(entity.id)).toBe(false);
97
+ expect(await repo.loadManyByQuery({ id: entity.id }).then((r) => r[0])).toBeUndefined();
98
+ });
99
+ });
100
+ test('should polymorphically filter soft deleted entities', async () => {
101
+ await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('bases')} CASCADE`);
102
+ await runInInjectionContext(injector, async () => {
103
+ const baseRepo = injectRepository(Base);
104
+ const subRepo = injectRepository(Subtype);
105
+ const s1 = await subRepo.insert(Object.assign(new Subtype(), { baseName: 'Active', subData: 'S1' }));
106
+ const s2 = await subRepo.insert(Object.assign(new Subtype(), { baseName: 'Deleted', subData: 'S2' }));
107
+ await subRepo.delete(s2.id);
108
+ const allActive = await baseRepo.loadAll({ includeSubclasses: true });
109
+ expect(allActive).toHaveLength(1);
110
+ expect(allActive[0].id).toBe(s1.id);
111
+ const allIncludingDeleted = await baseRepo.loadAll({ includeSubclasses: true, withDeleted: true });
112
+ expect(allIncludingDeleted).toHaveLength(2);
113
+ });
114
+ });
115
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { beforeAll, describe, expect, test } from 'vitest';
11
+ import { sql } from 'drizzle-orm';
12
+ import { StringProperty } from '../../schema/index.js';
13
+ import { Entity } from '../entity.js';
14
+ import { Column, Inheritance, ChildEntity, Table } from '../decorators.js';
15
+ import { getRepository } from '../server/repository.js';
16
+ import { configureOrm, Database } from '../server/index.js';
17
+ import { Injector, runInInjectionContext } from '../../injector/index.js';
18
+ import { Transactional } from '../server/transactional.js';
19
+ import { Singleton } from '../../injector/decorators.js';
20
+ describe('ORM Repository CTI Transactions (Integration)', () => {
21
+ let injector;
22
+ let db;
23
+ const schema = 'test_orm_cti_transactions';
24
+ let Parent = class Parent extends Entity {
25
+ type;
26
+ name;
27
+ };
28
+ __decorate([
29
+ StringProperty(),
30
+ Column({ name: 'type' }),
31
+ __metadata("design:type", String)
32
+ ], Parent.prototype, "type", void 0);
33
+ __decorate([
34
+ StringProperty(),
35
+ __metadata("design:type", String)
36
+ ], Parent.prototype, "name", void 0);
37
+ Parent = __decorate([
38
+ Table('parents', { schema }),
39
+ Inheritance({ strategy: 'joined', discriminatorColumn: 'type' })
40
+ ], Parent);
41
+ let Child = class Child extends Parent {
42
+ childData;
43
+ };
44
+ __decorate([
45
+ StringProperty(),
46
+ __metadata("design:type", String)
47
+ ], Child.prototype, "childData", void 0);
48
+ Child = __decorate([
49
+ Table('children', { schema }),
50
+ ChildEntity('child')
51
+ ], Child);
52
+ let TestService = class TestService extends Transactional {
53
+ #childRepo = getRepository(Child);
54
+ async createTwo(name1, name2, failSecond) {
55
+ await this.transaction(async (tx) => {
56
+ const repo = injector.resolve(this.#childRepo).withTransaction(tx);
57
+ await repo.insert(Object.assign(new Child(), { name: name1, childData: 'data1' }));
58
+ if (failSecond) {
59
+ throw new Error('Planned failure');
60
+ }
61
+ await repo.insert(Object.assign(new Child(), { name: name2, childData: 'data2' }));
62
+ });
63
+ }
64
+ };
65
+ TestService = __decorate([
66
+ Singleton()
67
+ ], TestService);
68
+ beforeAll(async () => {
69
+ injector = new Injector('Test');
70
+ configureOrm({
71
+ repositoryConfig: { schema },
72
+ connection: {
73
+ host: '127.0.0.1',
74
+ port: 5432,
75
+ user: 'tstdl',
76
+ password: 'wf7rq6glrk5jykne',
77
+ database: 'tstdl',
78
+ }
79
+ });
80
+ db = injector.resolve(Database);
81
+ await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
82
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('children')} CASCADE`);
83
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('parents')} CASCADE`);
84
+ await db.execute(sql `
85
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('parents')} (
86
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
87
+ type TEXT NOT NULL,
88
+ name TEXT NOT NULL,
89
+ revision INTEGER NOT NULL,
90
+ revision_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
91
+ create_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
92
+ delete_timestamp TIMESTAMP WITH TIME ZONE,
93
+ attributes JSONB NOT NULL DEFAULT '{}',
94
+ UNIQUE (id, type)
95
+ )
96
+ `);
97
+ await db.execute(sql `
98
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('children')} (
99
+ id UUID PRIMARY KEY,
100
+ type TEXT NOT NULL CHECK (type = 'child'),
101
+ child_data TEXT NOT NULL,
102
+ FOREIGN KEY (id, type) REFERENCES ${sql.identifier(schema)}.${sql.identifier('parents')} (id, type) ON DELETE CASCADE
103
+ )
104
+ `);
105
+ });
106
+ test('should rollback inheritance inserts across multiple tables on service error', async () => {
107
+ await runInInjectionContext(injector, async () => {
108
+ const service = injector.resolve(TestService);
109
+ await expect(service.createTwo('ShouldRollback', 'Fails', true)).rejects.toThrow('Planned failure');
110
+ const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
111
+ const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
112
+ expect(parentRows).toHaveLength(0);
113
+ expect(childRows).toHaveLength(0);
114
+ });
115
+ });
116
+ test('should commit inheritance inserts across multiple tables on success', async () => {
117
+ await runInInjectionContext(injector, async () => {
118
+ const service = injector.resolve(TestService);
119
+ await service.createTwo('C1', 'C2', false);
120
+ const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
121
+ const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
122
+ expect(parentRows).toHaveLength(2);
123
+ expect(childRows).toHaveLength(2);
124
+ });
125
+ });
126
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { sql } from 'drizzle-orm';
11
+ import { beforeAll, describe, expect, test } from 'vitest';
12
+ import { Injector, runInInjectionContext } from '../../injector/index.js';
13
+ import { StringProperty } from '../../schema/index.js';
14
+ import { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
15
+ import { Entity } from '../entity.js';
16
+ import { configureOrm, Database } from '../server/index.js';
17
+ import { injectRepository } from '../server/repository.js';
18
+ describe('ORM Repository CTI UpsertMany (Integration)', () => {
19
+ let injector;
20
+ let db;
21
+ const schema = 'test_orm_cti_upsert_many';
22
+ let Item = class Item extends Entity {
23
+ type;
24
+ title;
25
+ };
26
+ __decorate([
27
+ StringProperty(),
28
+ Column({ name: 'type' }),
29
+ __metadata("design:type", String)
30
+ ], Item.prototype, "type", void 0);
31
+ __decorate([
32
+ StringProperty(),
33
+ __metadata("design:type", String)
34
+ ], Item.prototype, "title", void 0);
35
+ Item = __decorate([
36
+ Table('items', { schema }),
37
+ Inheritance({ strategy: 'joined', discriminatorColumn: 'type' })
38
+ ], Item);
39
+ let Book = class Book extends Item {
40
+ author;
41
+ };
42
+ __decorate([
43
+ StringProperty(),
44
+ __metadata("design:type", String)
45
+ ], Book.prototype, "author", void 0);
46
+ Book = __decorate([
47
+ Table('books', { schema }),
48
+ ChildEntity('book')
49
+ ], Book);
50
+ beforeAll(async () => {
51
+ injector = new Injector('Test');
52
+ configureOrm({
53
+ repositoryConfig: { schema },
54
+ connection: {
55
+ host: '127.0.0.1',
56
+ port: 5432,
57
+ user: 'tstdl',
58
+ password: 'wf7rq6glrk5jykne',
59
+ database: 'tstdl',
60
+ }
61
+ });
62
+ db = injector.resolve(Database);
63
+ await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
64
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('books')} CASCADE`);
65
+ await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('items')} CASCADE`);
66
+ await db.execute(sql `
67
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('items')} (
68
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
69
+ type TEXT NOT NULL,
70
+ title TEXT NOT NULL,
71
+ revision INTEGER NOT NULL,
72
+ revision_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
73
+ create_timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
74
+ delete_timestamp TIMESTAMP WITH TIME ZONE,
75
+ attributes JSONB NOT NULL DEFAULT '{}',
76
+ UNIQUE (id, type)
77
+ )
78
+ `);
79
+ await db.execute(sql `
80
+ CREATE TABLE ${sql.identifier(schema)}.${sql.identifier('books')} (
81
+ id UUID PRIMARY KEY,
82
+ type TEXT NOT NULL CHECK (type = 'book'),
83
+ author TEXT NOT NULL,
84
+ FOREIGN KEY (id, type) REFERENCES ${sql.identifier(schema)}.${sql.identifier('items')} (id, type) ON DELETE CASCADE
85
+ )
86
+ `);
87
+ });
88
+ test('should upsertMany child entities (insert and update mixed)', async () => {
89
+ await runInInjectionContext(injector, async () => {
90
+ const bookRepo = injectRepository(Book);
91
+ // 1. Insert initial books
92
+ const book1 = Object.assign(new Book(), { title: 'Book 1', author: 'Author 1' });
93
+ const book2 = Object.assign(new Book(), { title: 'Book 2', author: 'Author 2' });
94
+ const [inserted1, inserted2] = await bookRepo.insertMany([book1, book2]);
95
+ // 2. Prepare upsert payload: update book1, new book3
96
+ const update1 = Object.assign(new Book(), { id: inserted1.id, title: 'Book 1 Updated', author: 'Author 1 Updated' });
97
+ const book3 = Object.assign(new Book(), { title: 'Book 3', author: 'Author 3' });
98
+ const results = await bookRepo.upsertMany('id', [update1, book3]);
99
+ expect(results).toHaveLength(2);
100
+ const updated1 = results.find((b) => b.id === inserted1.id);
101
+ const inserted3 = results.find((b) => b.title === 'Book 3');
102
+ expect(updated1).toBeDefined();
103
+ expect(updated1.title).toBe('Book 1 Updated');
104
+ expect(updated1.author).toBe('Author 1 Updated');
105
+ expect(inserted3).toBeDefined();
106
+ expect(inserted3.id).toBeDefined();
107
+ expect(inserted3.author).toBe('Author 3');
108
+ // Verify book2 is untouched
109
+ const loaded2 = await bookRepo.load(inserted2.id);
110
+ expect(loaded2.title).toBe('Book 2');
111
+ });
112
+ });
113
+ test('should polymorphic tryLoadByQuery', async () => {
114
+ await runInInjectionContext(injector, async () => {
115
+ const itemRepo = injectRepository(Item);
116
+ const bookRepo = injectRepository(Book);
117
+ await bookRepo.insert(Object.assign(new Book(), { title: 'Unique Book', author: 'Unique Author' }));
118
+ // Load via Item repo using a book-specific property (should fail if not joined, but here we query by title)
119
+ // Querying by book-specific property requires casting query or using raw sql if repository type doesn't have it.
120
+ // But we can query by base property 'title'.
121
+ const loaded = await itemRepo.tryLoadByQuery({ title: 'Unique Book' }, { includeSubclasses: true });
122
+ expect(loaded).toBeDefined();
123
+ expect(loaded).toBeInstanceOf(Book);
124
+ expect(loaded.author).toBe('Unique Author');
125
+ });
126
+ });
127
+ });
@@ -0,0 +1 @@
1
+ export {};