@tstdl/base 0.93.145 → 0.93.147

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 (44) hide show
  1. package/authentication/tests/authentication.client-service.test.js +15 -19
  2. package/authentication/tests/authentication.service.test.js +92 -119
  3. package/notification/tests/notification-client.test.js +39 -50
  4. package/notification/tests/notification-flow.test.js +204 -238
  5. package/notification/tests/notification-sse.service.test.js +20 -27
  6. package/notification/tests/notification-type.service.test.js +17 -20
  7. package/orm/repository.types.d.ts +13 -2
  8. package/orm/server/repository.d.ts +60 -4
  9. package/orm/server/repository.js +126 -25
  10. package/orm/tests/query-complex.test.js +80 -111
  11. package/orm/tests/repository-advanced.test.js +100 -143
  12. package/orm/tests/repository-attributes.test.js +30 -39
  13. package/orm/tests/repository-compound-primary-key.test.js +67 -75
  14. package/orm/tests/repository-comprehensive.test.js +76 -101
  15. package/orm/tests/repository-coverage.test.d.ts +1 -0
  16. package/orm/tests/repository-coverage.test.js +88 -149
  17. package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
  18. package/orm/tests/repository-cti-extensive.test.js +118 -147
  19. package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
  20. package/orm/tests/repository-cti-mapping.test.js +29 -42
  21. package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
  22. package/orm/tests/repository-cti-soft-delete.test.js +25 -37
  23. package/orm/tests/repository-cti-transactions.test.js +19 -33
  24. package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
  25. package/orm/tests/repository-cti-upsert-many.test.js +38 -50
  26. package/orm/tests/repository-cti.test.d.ts +1 -0
  27. package/orm/tests/repository-cti.test.js +195 -247
  28. package/orm/tests/repository-expiration.test.d.ts +1 -0
  29. package/orm/tests/repository-expiration.test.js +46 -59
  30. package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
  31. package/orm/tests/repository-extra-coverage.test.js +195 -337
  32. package/orm/tests/repository-mapping.test.d.ts +1 -0
  33. package/orm/tests/repository-mapping.test.js +20 -20
  34. package/orm/tests/repository-regression.test.js +124 -163
  35. package/orm/tests/repository-search.test.js +30 -44
  36. package/orm/tests/repository-soft-delete.test.js +54 -79
  37. package/orm/tests/repository-types.test.js +77 -111
  38. package/orm/tests/repository-undelete.test.d.ts +2 -0
  39. package/orm/tests/repository-undelete.test.js +201 -0
  40. package/package.json +3 -3
  41. package/task-queue/tests/worker.test.js +5 -5
  42. package/testing/README.md +38 -16
  43. package/testing/integration-setup.d.ts +11 -0
  44. package/testing/integration-setup.js +57 -30
@@ -7,19 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { beforeAll, describe, expect, test } from 'vitest';
11
10
  import { sql } from 'drizzle-orm';
11
+ import { beforeAll, describe, expect, test } from 'vitest';
12
+ import { Singleton } from '../../injector/decorators.js';
12
13
  import { StringProperty } from '../../schema/index.js';
14
+ import { setupIntegrationTest } from '../../testing/index.js';
15
+ import { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
13
16
  import { Entity } from '../entity.js';
14
- import { Column, Inheritance, ChildEntity, Table } from '../decorators.js';
15
17
  import { getRepository } from '../server/repository.js';
16
- import { configureOrm, Database } from '../server/index.js';
17
- import { Injector, runInInjectionContext } from '../../injector/index.js';
18
18
  import { Transactional } from '../server/transactional.js';
19
- import { Singleton } from '../../injector/decorators.js';
20
19
  describe('ORM Repository CTI Transactions (Integration)', () => {
21
20
  let injector;
22
21
  let db;
22
+ let service;
23
23
  const schema = 'test_orm_cti_transactions';
24
24
  let Parent = class Parent extends Entity {
25
25
  type;
@@ -66,18 +66,10 @@ describe('ORM Repository CTI Transactions (Integration)', () => {
66
66
  Singleton()
67
67
  ], TestService);
68
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);
69
+ ({ injector, database: db } = await setupIntegrationTest({
70
+ orm: { schema },
71
+ }));
72
+ service = injector.resolve(TestService);
81
73
  await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
82
74
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('children')} CASCADE`);
83
75
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('parents')} CASCADE`);
@@ -104,23 +96,17 @@ describe('ORM Repository CTI Transactions (Integration)', () => {
104
96
  `);
105
97
  });
106
98
  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
- });
99
+ await expect(service.createTwo('ShouldRollback', 'Fails', true)).rejects.toThrow('Planned failure');
100
+ const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
101
+ const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
102
+ expect(parentRows).toHaveLength(0);
103
+ expect(childRows).toHaveLength(0);
115
104
  });
116
105
  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
- });
106
+ await service.createTwo('C1', 'C2', false);
107
+ const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
108
+ const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
109
+ expect(parentRows).toHaveLength(2);
110
+ expect(childRows).toHaveLength(2);
125
111
  });
126
112
  });
@@ -1 +1,2 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  export {};
@@ -1,3 +1,4 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -9,15 +10,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
10
  };
10
11
  import { sql } from 'drizzle-orm';
11
12
  import { beforeAll, describe, expect, test } from 'vitest';
12
- import { Injector, runInInjectionContext } from '../../injector/index.js';
13
13
  import { StringProperty } from '../../schema/index.js';
14
+ import { setupIntegrationTest } from '../../testing/index.js';
14
15
  import { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
15
16
  import { Entity } from '../entity.js';
16
- import { configureOrm, Database } from '../server/index.js';
17
- import { injectRepository } from '../server/repository.js';
17
+ import { getRepository } from '../server/index.js';
18
18
  describe('ORM Repository CTI UpsertMany (Integration)', () => {
19
19
  let injector;
20
20
  let db;
21
+ let itemRepo;
22
+ let bookRepo;
21
23
  const schema = 'test_orm_cti_upsert_many';
22
24
  let Item = class Item extends Entity {
23
25
  type;
@@ -48,18 +50,11 @@ describe('ORM Repository CTI UpsertMany (Integration)', () => {
48
50
  ChildEntity('book')
49
51
  ], Book);
50
52
  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);
53
+ ({ injector, database: db } = await setupIntegrationTest({
54
+ orm: { schema },
55
+ }));
56
+ itemRepo = injector.resolve(getRepository(Item));
57
+ bookRepo = injector.resolve(getRepository(Book));
63
58
  await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
64
59
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('books')} CASCADE`);
65
60
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('items')} CASCADE`);
@@ -86,42 +81,35 @@ describe('ORM Repository CTI UpsertMany (Integration)', () => {
86
81
  `);
87
82
  });
88
83
  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
- });
84
+ // 1. Insert initial books
85
+ const book1 = Object.assign(new Book(), { title: 'Book 1', author: 'Author 1' });
86
+ const book2 = Object.assign(new Book(), { title: 'Book 2', author: 'Author 2' });
87
+ const [inserted1, inserted2] = await bookRepo.insertMany([book1, book2]);
88
+ // 2. Prepare upsert payload: update book1, new book3
89
+ const update1 = Object.assign(new Book(), { id: inserted1.id, title: 'Book 1 Updated', author: 'Author 1 Updated' });
90
+ const book3 = Object.assign(new Book(), { title: 'Book 3', author: 'Author 3' });
91
+ const results = await bookRepo.upsertMany('id', [update1, book3]);
92
+ expect(results).toHaveLength(2);
93
+ const updated1 = results.find((b) => b.id === inserted1.id);
94
+ const inserted3 = results.find((b) => b.title === 'Book 3');
95
+ expect(updated1).toBeDefined();
96
+ expect(updated1.title).toBe('Book 1 Updated');
97
+ expect(updated1.author).toBe('Author 1 Updated');
98
+ expect(inserted3).toBeDefined();
99
+ expect(inserted3.id).toBeDefined();
100
+ expect(inserted3.author).toBe('Author 3');
101
+ // Verify book2 is untouched
102
+ const loaded2 = await bookRepo.load(inserted2.id);
103
+ expect(loaded2.title).toBe('Book 2');
112
104
  });
113
105
  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
- });
106
+ await bookRepo.insert(Object.assign(new Book(), { title: 'Unique Book', author: 'Unique Author' }));
107
+ // Load via Item repo using a book-specific property (should fail if not joined, but here we query by title)
108
+ // Querying by book-specific property requires casting query or using raw sql if repository type doesn't have it.
109
+ // But we can query by base property 'title'.
110
+ const loaded = await itemRepo.tryLoadByQuery({ title: 'Unique Book' }, { includeSubclasses: true });
111
+ expect(loaded).toBeDefined();
112
+ expect(loaded).toBeInstanceOf(Book);
113
+ expect(loaded.author).toBe('Unique Author');
126
114
  });
127
115
  });
@@ -1 +1,2 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  export {};