@tstdl/base 0.93.144 → 0.93.146

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 (45) hide show
  1. package/authentication/authentication.api.d.ts +9 -0
  2. package/authentication/authentication.api.js +3 -0
  3. package/authentication/client/authentication.service.js +5 -5
  4. package/authentication/client/http-client.middleware.js +6 -2
  5. package/authentication/tests/authentication.client-middleware.test.js +35 -0
  6. package/authentication/tests/authentication.client-service-refresh.test.js +7 -0
  7. package/authentication/tests/authentication.client-service.test.js +15 -19
  8. package/authentication/tests/authentication.service.test.js +92 -119
  9. package/notification/tests/notification-client.test.js +39 -50
  10. package/notification/tests/notification-flow.test.js +204 -238
  11. package/notification/tests/notification-sse.service.test.js +20 -27
  12. package/notification/tests/notification-type.service.test.js +17 -20
  13. package/orm/tests/query-complex.test.js +80 -111
  14. package/orm/tests/repository-advanced.test.js +100 -143
  15. package/orm/tests/repository-attributes.test.js +30 -39
  16. package/orm/tests/repository-compound-primary-key.test.js +67 -75
  17. package/orm/tests/repository-comprehensive.test.js +76 -101
  18. package/orm/tests/repository-coverage.test.d.ts +1 -0
  19. package/orm/tests/repository-coverage.test.js +88 -149
  20. package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
  21. package/orm/tests/repository-cti-extensive.test.js +118 -147
  22. package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
  23. package/orm/tests/repository-cti-mapping.test.js +29 -42
  24. package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
  25. package/orm/tests/repository-cti-soft-delete.test.js +25 -37
  26. package/orm/tests/repository-cti-transactions.test.js +19 -33
  27. package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
  28. package/orm/tests/repository-cti-upsert-many.test.js +38 -50
  29. package/orm/tests/repository-cti.test.d.ts +1 -0
  30. package/orm/tests/repository-cti.test.js +195 -247
  31. package/orm/tests/repository-expiration.test.d.ts +1 -0
  32. package/orm/tests/repository-expiration.test.js +46 -59
  33. package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
  34. package/orm/tests/repository-extra-coverage.test.js +195 -337
  35. package/orm/tests/repository-mapping.test.d.ts +1 -0
  36. package/orm/tests/repository-mapping.test.js +20 -20
  37. package/orm/tests/repository-regression.test.js +124 -163
  38. package/orm/tests/repository-search.test.js +30 -44
  39. package/orm/tests/repository-soft-delete.test.js +54 -79
  40. package/orm/tests/repository-types.test.js +77 -111
  41. package/package.json +1 -1
  42. package/task-queue/tests/worker.test.js +5 -5
  43. package/testing/README.md +38 -16
  44. package/testing/integration-setup.d.ts +11 -0
  45. package/testing/integration-setup.js +57 -30
@@ -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,16 +10,17 @@ 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 { Expires, Table, TimeToLive } from '../decorators.js';
15
16
  import { Entity } from '../entity.js';
16
17
  import { TimestampProperty } from '../schemas/index.js';
17
- import { configureOrm, Database } from '../server/index.js';
18
- import { injectRepository } from '../server/repository.js';
18
+ import { getRepository } from '../server/index.js';
19
19
  describe('ORM Repository Expiration', () => {
20
20
  let injector;
21
21
  let db;
22
+ let expirationRepo;
23
+ let ttlRepo;
22
24
  const schema = 'test_orm_expiration';
23
25
  let ExpirationEntity = class ExpirationEntity extends Entity {
24
26
  name;
@@ -54,14 +56,11 @@ describe('ORM Repository Expiration', () => {
54
56
  TimeToLive(100, 'hard') // 100ms TTL
55
57
  ], TtlEntity);
56
58
  beforeAll(async () => {
57
- injector = new Injector('Test');
58
- configureOrm({
59
- repositoryConfig: { schema },
60
- connection: {
61
- host: '127.0.0.1', port: 5432, user: 'tstdl', password: 'wf7rq6glrk5jykne', database: 'tstdl',
62
- },
63
- });
64
- db = injector.resolve(Database);
59
+ ({ injector, database: db } = await setupIntegrationTest({
60
+ orm: { schema },
61
+ }));
62
+ expirationRepo = injector.resolve(getRepository(ExpirationEntity));
63
+ ttlRepo = injector.resolve(getRepository(TtlEntity));
65
64
  await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
66
65
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
67
66
  await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('ttl_entities')} CASCADE`);
@@ -92,62 +91,50 @@ describe('ORM Repository Expiration', () => {
92
91
  });
93
92
  test('should support TimeToLive decorator', async () => {
94
93
  await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('ttl_entities')} CASCADE`);
95
- await runInInjectionContext(injector, async () => {
96
- const repository = injectRepository(TtlEntity);
97
- const e1 = await repository.insert(Object.assign(new TtlEntity(), { name: 'Valid' }));
98
- // Wait 150ms for expiration
99
- await new Promise((resolve) => setTimeout(resolve, 150));
100
- await repository.processExpirations();
101
- const all = await repository.loadAll({ withDeleted: true });
102
- expect(all).toHaveLength(0);
103
- });
94
+ const e1 = await ttlRepo.insert(Object.assign(new TtlEntity(), { name: 'Valid' }));
95
+ // Wait 150ms for expiration
96
+ await new Promise((resolve) => setTimeout(resolve, 150));
97
+ await ttlRepo.processExpirations();
98
+ const all = await ttlRepo.loadAll({ withDeleted: true });
99
+ expect(all).toHaveLength(0);
104
100
  });
105
101
  test('should soft delete expired entities', async () => {
106
102
  await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
107
- await runInInjectionContext(injector, async () => {
108
- const repository = injectRepository(ExpirationEntity);
109
- const now = Date.now();
110
- const past = now - 10000; // 10s ago
111
- const future = now + 10000; // 10s in future
112
- const e1 = await repository.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', softExpireAt: past }));
113
- const e2 = await repository.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', softExpireAt: future }));
114
- await repository.processExpirations();
115
- const all = await repository.loadAll();
116
- expect(all).toHaveLength(1);
117
- expect(all[0].name).toBe('Valid');
118
- const withDeleted = await repository.loadAll({ withDeleted: true });
119
- expect(withDeleted).toHaveLength(2);
120
- expect(withDeleted.find((e) => e.id === e1.id).metadata.deleteTimestamp).toBeDefined();
121
- });
103
+ const now = Date.now();
104
+ const past = now - 10000; // 10s ago
105
+ const future = now + 10000; // 10s in future
106
+ const e1 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', softExpireAt: past }));
107
+ const e2 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', softExpireAt: future }));
108
+ await expirationRepo.processExpirations();
109
+ const all = await expirationRepo.loadAll();
110
+ expect(all).toHaveLength(1);
111
+ expect(all[0].name).toBe('Valid');
112
+ const withDeleted = await expirationRepo.loadAll({ withDeleted: true });
113
+ expect(withDeleted).toHaveLength(2);
114
+ expect(withDeleted.find((e) => e.id === e1.id).metadata.deleteTimestamp).toBeDefined();
122
115
  });
123
116
  test('should hard delete expired entities', async () => {
124
117
  await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
125
- await runInInjectionContext(injector, async () => {
126
- const repository = injectRepository(ExpirationEntity);
127
- const now = Date.now();
128
- const past = now - 10000;
129
- const future = now + 10000;
130
- const e1 = await repository.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', hardExpireAt: past }));
131
- const e2 = await repository.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', hardExpireAt: future }));
132
- await repository.processExpirations();
133
- const all = await repository.loadAll({ withDeleted: true });
134
- expect(all).toHaveLength(1);
135
- expect(all[0].name).toBe('Valid');
136
- });
118
+ const now = Date.now();
119
+ const past = now - 10000;
120
+ const future = now + 10000;
121
+ const e1 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', hardExpireAt: past }));
122
+ const e2 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', hardExpireAt: future }));
123
+ await expirationRepo.processExpirations();
124
+ const all = await expirationRepo.loadAll({ withDeleted: true });
125
+ expect(all).toHaveLength(1);
126
+ expect(all[0].name).toBe('Valid');
137
127
  });
138
128
  test('should handle mixed expiration', async () => {
139
129
  await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
140
- await runInInjectionContext(injector, async () => {
141
- const repository = injectRepository(ExpirationEntity);
142
- const past = Date.now() - 10000;
143
- await repository.insert(Object.assign(new ExpirationEntity(), {
144
- name: 'BothExpired',
145
- softExpireAt: past,
146
- hardExpireAt: past,
147
- }));
148
- await repository.processExpirations();
149
- const all = await repository.loadAll({ withDeleted: true });
150
- expect(all).toHaveLength(0);
151
- });
130
+ const past = Date.now() - 10000;
131
+ await expirationRepo.insert(Object.assign(new ExpirationEntity(), {
132
+ name: 'BothExpired',
133
+ softExpireAt: past,
134
+ hardExpireAt: past,
135
+ }));
136
+ await expirationRepo.processExpirations();
137
+ const all = await expirationRepo.loadAll({ withDeleted: true });
138
+ expect(all).toHaveLength(0);
152
139
  });
153
140
  });
@@ -1 +1,2 @@
1
+ /** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
1
2
  export {};