@tstdl/base 0.92.85 → 0.92.87

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 (152) hide show
  1. package/ai/ai.service.d.ts +4 -4
  2. package/ai/ai.service.js +27 -14
  3. package/ai/types.d.ts +5 -4
  4. package/api/server/gateway.js +1 -1
  5. package/authentication/authentication.api.d.ts +9 -9
  6. package/authentication/models/schemas.d.ts +2 -2
  7. package/authentication/server/authentication-ancillary.service.d.ts +6 -4
  8. package/authentication/server/authentication-ancillary.service.js +5 -5
  9. package/cancellation/token.d.ts +1 -1
  10. package/context/context.d.ts +1 -9
  11. package/context/context.js +8 -5
  12. package/document-management/api/document-management.api.d.ts +142 -110
  13. package/document-management/models/document-category.model.d.ts +1 -0
  14. package/document-management/models/document-category.model.js +2 -0
  15. package/document-management/models/document-collection-document.model.js +7 -3
  16. package/document-management/models/document-property-value.model.d.ts +13 -14
  17. package/document-management/models/document-property-value.model.js +60 -27
  18. package/document-management/models/document-property.model.d.ts +2 -0
  19. package/document-management/models/document-property.model.js +4 -1
  20. package/document-management/models/document-request-assignment-task-collection.model.d.ts +7 -0
  21. package/document-management/models/document-request-assignment-task-collection.model.js +32 -0
  22. package/document-management/models/document-request-assignment-task.model.d.ts +14 -0
  23. package/document-management/models/document-request-assignment-task.model.js +72 -0
  24. package/document-management/models/document-request-collection.model.d.ts +1 -0
  25. package/document-management/models/document-request-collection.model.js +7 -3
  26. package/document-management/models/document-request-file.model.d.ts +7 -2
  27. package/document-management/models/document-request-file.model.js +29 -4
  28. package/document-management/models/document-request.model.d.ts +1 -0
  29. package/document-management/models/document-requests-template.js +2 -0
  30. package/document-management/models/document-type-property.model.js +7 -3
  31. package/document-management/models/document-type.model.d.ts +1 -0
  32. package/document-management/models/document-type.model.js +7 -3
  33. package/document-management/models/document.model.d.ts +5 -2
  34. package/document-management/models/document.model.js +21 -6
  35. package/document-management/models/index.d.ts +2 -0
  36. package/document-management/models/index.js +2 -0
  37. package/document-management/models/service-models/document.service-model.d.ts +84 -65
  38. package/document-management/models/service-models/document.service-model.js +11 -6
  39. package/document-management/models/service-models/document.view-model.d.ts +1 -1
  40. package/document-management/models/service-models/document.view-model.js +2 -2
  41. package/document-management/server/drizzle/{0000_sloppy_fenris.sql → 0000_cool_victor_mancha.sql} +99 -43
  42. package/document-management/server/drizzle/meta/0000_snapshot.json +518 -130
  43. package/document-management/server/drizzle/meta/_journal.json +2 -2
  44. package/document-management/server/drizzle.config.js +1 -1
  45. package/document-management/server/module.d.ts +3 -2
  46. package/document-management/server/module.js +4 -2
  47. package/document-management/server/schemas.d.ts +36 -0
  48. package/document-management/server/schemas.js +37 -0
  49. package/document-management/server/services/document-management-ancillary.service.d.ts +4 -0
  50. package/document-management/server/services/document-management-ancillary.service.js +13 -0
  51. package/document-management/server/services/document-management.service.d.ts +71 -22
  52. package/document-management/server/services/document-management.service.js +528 -81
  53. package/document-management/server/services/index.d.ts +1 -0
  54. package/document-management/server/services/index.js +1 -0
  55. package/eslint.config.js +1 -0
  56. package/examples/document-management/main.d.ts +5 -0
  57. package/examples/document-management/main.js +20 -2
  58. package/examples/orm/schemas.d.ts +1 -1
  59. package/file/index.d.ts +1 -0
  60. package/file/index.js +1 -0
  61. package/file/temporary-file.d.ts +17 -0
  62. package/file/temporary-file.js +49 -0
  63. package/http/server/http-server-response.d.ts +2 -0
  64. package/http/server/http-server-response.js +13 -0
  65. package/injector/index.d.ts +1 -0
  66. package/injector/index.js +1 -0
  67. package/injector/injector.js +19 -7
  68. package/injector/interfaces.d.ts +1 -1
  69. package/injector/interfaces.js +1 -1
  70. package/injector/resolution.d.ts +15 -0
  71. package/injector/resolution.js +6 -0
  72. package/logger/console/logger.d.ts +1 -1
  73. package/logger/logger.d.ts +1 -1
  74. package/mail/drizzle.config.js +1 -1
  75. package/mail/models/schemas.d.ts +1 -1
  76. package/object-storage/object-storage.d.ts +5 -7
  77. package/object-storage/s3/s3.object-storage.d.ts +0 -1
  78. package/object-storage/s3/s3.object-storage.js +0 -3
  79. package/orm/{server/data-types → data-types}/numeric-date.js +2 -3
  80. package/orm/decorators.d.ts +17 -8
  81. package/orm/decorators.js +13 -7
  82. package/orm/entity.d.ts +5 -7
  83. package/orm/entity.js +11 -7
  84. package/orm/index.d.ts +2 -0
  85. package/orm/index.js +2 -0
  86. package/orm/query.d.ts +1 -3
  87. package/orm/query.js +0 -1
  88. package/orm/repository.types.d.ts +32 -0
  89. package/orm/repository.types.js +1 -0
  90. package/orm/server/database-schema.d.ts +4 -4
  91. package/orm/server/drizzle/schema-converter.d.ts +1 -1
  92. package/orm/server/drizzle/schema-converter.js +48 -19
  93. package/orm/server/index.d.ts +1 -0
  94. package/orm/server/index.js +1 -0
  95. package/orm/server/query-converter.d.ts +1 -2
  96. package/orm/server/query-converter.js +66 -61
  97. package/orm/server/repository.d.ts +80 -43
  98. package/orm/server/repository.js +219 -112
  99. package/orm/server/sqls.d.ts +15 -0
  100. package/orm/server/sqls.js +19 -0
  101. package/orm/server/types.d.ts +3 -3
  102. package/orm/types.d.ts +4 -4
  103. package/orm/utils.d.ts +3 -0
  104. package/orm/utils.js +6 -0
  105. package/package.json +23 -19
  106. package/pdf/pdf.service.d.ts +0 -1
  107. package/pdf/pdf.service.js +1 -95
  108. package/pdf/utils.d.ts +3 -1
  109. package/pdf/utils.js +129 -4
  110. package/promise/lazy-promise.d.ts +3 -3
  111. package/queue/enqueue-batch.d.ts +1 -0
  112. package/queue/enqueue-batch.js +1 -1
  113. package/queue/mongo/queue.d.ts +9 -4
  114. package/queue/mongo/queue.js +5 -6
  115. package/queue/postgres/drizzle/0000_zippy_moondragon.sql +11 -0
  116. package/queue/postgres/drizzle/meta/0000_snapshot.json +90 -0
  117. package/queue/postgres/drizzle/meta/_journal.json +13 -0
  118. package/queue/postgres/drizzle.config.d.ts +2 -0
  119. package/queue/postgres/drizzle.config.js +11 -0
  120. package/queue/postgres/index.d.ts +4 -0
  121. package/queue/postgres/index.js +4 -0
  122. package/queue/postgres/job.model.d.ts +13 -0
  123. package/queue/postgres/job.model.js +55 -0
  124. package/queue/postgres/module.d.ts +9 -0
  125. package/queue/postgres/module.js +29 -0
  126. package/queue/postgres/queue.d.ts +28 -0
  127. package/queue/postgres/queue.js +147 -0
  128. package/queue/postgres/queue.provider.d.ts +7 -0
  129. package/queue/postgres/queue.provider.js +21 -0
  130. package/queue/postgres/schemas.d.ts +3 -0
  131. package/queue/postgres/schemas.js +4 -0
  132. package/queue/provider.d.ts +2 -1
  133. package/queue/queue.d.ts +32 -6
  134. package/queue/queue.js +43 -0
  135. package/schema/schemas/object.d.ts +1 -1
  136. package/utils/date-time.d.ts +4 -2
  137. package/utils/date-time.js +10 -3
  138. package/utils/format-error.js +0 -1
  139. package/utils/object/lazy-property.js +0 -1
  140. package/utils/timing.d.ts +4 -3
  141. package/utils/timing.js +3 -1
  142. package/utils/try-ignore.d.ts +9 -2
  143. package/utils/try-ignore.js +30 -6
  144. package/document-management/models/schemas.d.ts +0 -33
  145. package/document-management/models/schemas.js +0 -34
  146. /package/orm/{server/data-types → data-types}/bytea.d.ts +0 -0
  147. /package/orm/{server/data-types → data-types}/bytea.js +0 -0
  148. /package/orm/{server/data-types → data-types}/index.d.ts +0 -0
  149. /package/orm/{server/data-types → data-types}/index.js +0 -0
  150. /package/orm/{server/data-types → data-types}/numeric-date.d.ts +0 -0
  151. /package/orm/{server/data-types → data-types}/timestamp.d.ts +0 -0
  152. /package/orm/{server/data-types → data-types}/timestamp.js +0 -0
@@ -1 +1,2 @@
1
+ export * from './document-management-ancillary.service.js';
1
2
  export * from './document-management.service.js';
@@ -1 +1,2 @@
1
+ export * from './document-management-ancillary.service.js';
1
2
  export * from './document-management.service.js';
package/eslint.config.js CHANGED
@@ -42,6 +42,7 @@ export default [
42
42
  '@typescript-eslint/no-floating-promises': 'error',
43
43
  '@typescript-eslint/no-import-type-side-effects': 'error',
44
44
  '@typescript-eslint/no-inferrable-types': ['warn', { ignoreParameters: true, ignoreProperties: true }],
45
+ '@typescript-eslint/no-misused-spread': 'off',
45
46
  '@typescript-eslint/no-non-null-assertion': 'off',
46
47
  '@typescript-eslint/no-unnecessary-condition': ['warn', { allowConstantLoopConditions: 'only-allowed-literals', checkTypePredicates: true }],
47
48
  '@typescript-eslint/no-unsafe-assignment': 'off',
@@ -1 +1,6 @@
1
1
  import '../../polyfills.js';
2
+ import type { DocumentCollection } from '../../document-management/index.js';
3
+ import { DocumentManagementAncillaryService } from '../../document-management/server/index.js';
4
+ export declare class TestDocumentManagementAncillaryService extends DocumentManagementAncillaryService {
5
+ resolveNames(collections: DocumentCollection[]): Promise<string[]>;
6
+ }
@@ -1,19 +1,37 @@
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
+ };
1
7
  import '../../polyfills.js';
2
8
  import { Application } from '../../application/application.js';
9
+ import { DocumentManagementAncillaryService } from '../../document-management/server/index.js';
3
10
  import { configureDocumentManagement, migrateDocumentManagementSchema } from '../../document-management/server/module.js';
4
11
  import { DocumentManagementService } from '../../document-management/server/services/document-management.service.js';
12
+ import { Singleton } from '../../injector/index.js';
5
13
  import { injectAsync } from '../../injector/inject.js';
6
14
  import { configureS3ObjectStorage } from '../../object-storage/index.js';
15
+ let TestDocumentManagementAncillaryService = class TestDocumentManagementAncillaryService extends DocumentManagementAncillaryService {
16
+ async resolveNames(collections) {
17
+ return collections.map((collection) => collection.metadata.attributes['name']);
18
+ }
19
+ };
20
+ TestDocumentManagementAncillaryService = __decorate([
21
+ Singleton()
22
+ ], TestDocumentManagementAncillaryService);
23
+ export { TestDocumentManagementAncillaryService };
7
24
  async function bootstrap() {
8
25
  configureDocumentManagement({
26
+ ancillaryService: TestDocumentManagementAncillaryService,
27
+ fileObjectStorageModule: 'documents',
9
28
  database: {
10
29
  connection: {
11
30
  database: 'xxx',
12
31
  user: 'xxx',
13
32
  password: 'xxx'
14
33
  }
15
- },
16
- fileObjectStorageModule: 'documents'
34
+ }
17
35
  });
18
36
  configureS3ObjectStorage({ endpoint: 'http://localhost:10000', accessKey: 'tstdl-dev', secretKey: 'tstdl-dev', bucketPerModule: true });
19
37
  await migrateDocumentManagementSchema();
@@ -1,3 +1,3 @@
1
1
  import { User } from './user.model.js';
2
2
  export declare const mySchema: import("../../orm/server/database-schema.js").DatabaseSchema<"my_application">;
3
- export declare const user: import("../../orm/server/types.js").PgTableFromType<"my_application", typeof User>;
3
+ export declare const user: import("../../orm/server/types.js").PgTableFromType<typeof User, "my_application">;
package/file/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './mime-type.js';
2
2
  export * from './mime-types.js';
3
+ export * from './temporary-file.js';
package/file/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './mime-type.js';
2
2
  export * from './mime-types.js';
3
+ export * from './temporary-file.js';
@@ -0,0 +1,17 @@
1
+ export declare class TemporaryFile implements AsyncDisposable {
2
+ #private;
3
+ get path(): string;
4
+ static create(): TemporaryFile;
5
+ /**
6
+ * Use an existing file as a temporary file which gets deleted on disposal.
7
+ * @param path path to adopt
8
+ */
9
+ static adopt(path: string): TemporaryFile;
10
+ static from(content: string | Uint8Array | ReadableStream<Uint8Array>): Promise<TemporaryFile>;
11
+ read(): Promise<Uint8Array>;
12
+ readText(): Promise<string>;
13
+ readStream(): ReadableStream<Uint8Array>;
14
+ write(content: string | Uint8Array | ReadableStream<Uint8Array>): Promise<void>;
15
+ delete(): Promise<void>;
16
+ [Symbol.asyncDispose](): Promise<void>;
17
+ }
@@ -0,0 +1,49 @@
1
+ import { createReadStream } from 'node:fs';
2
+ import { readFile, unlink, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { Readable } from 'node:stream';
5
+ export class TemporaryFile {
6
+ #path = `${tmpdir()}/${crypto.randomUUID()}`;
7
+ get path() {
8
+ return this.#path;
9
+ }
10
+ static create() {
11
+ return new TemporaryFile();
12
+ }
13
+ /**
14
+ * Use an existing file as a temporary file which gets deleted on disposal.
15
+ * @param path path to adopt
16
+ */
17
+ static adopt(path) {
18
+ const file = new TemporaryFile();
19
+ file.#path = path;
20
+ return file;
21
+ }
22
+ static async from(content) {
23
+ const file = new TemporaryFile();
24
+ await file.write(content);
25
+ return file;
26
+ }
27
+ async read() {
28
+ return readFile(this.#path);
29
+ }
30
+ async readText() {
31
+ return readFile(this.#path, { encoding: 'utf8' });
32
+ }
33
+ readStream() {
34
+ const stream = createReadStream(this.#path);
35
+ return Readable.toWeb(stream);
36
+ }
37
+ async write(content) {
38
+ await writeFile(this.#path, content);
39
+ }
40
+ async delete() {
41
+ await unlink(this.#path);
42
+ }
43
+ async [Symbol.asyncDispose]() {
44
+ try {
45
+ await this.delete();
46
+ }
47
+ catch { }
48
+ }
49
+ }
@@ -32,5 +32,7 @@ export declare class HttpServerResponse {
32
32
  };
33
33
  constructor(response?: HttpServerResponseOptions);
34
34
  static fromObject(options?: HttpServerResponseOptions): HttpServerResponse;
35
+ static redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse;
35
36
  update(options: HttpServerResponseOptions): void;
36
37
  }
38
+ export declare function redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse;
@@ -13,6 +13,16 @@ export class HttpServerResponse {
13
13
  static fromObject(options) {
14
14
  return new HttpServerResponse(options);
15
15
  }
16
+ static redirect(url, options) {
17
+ return new HttpServerResponse({
18
+ statusCode: 303,
19
+ ...options,
20
+ headers: {
21
+ Location: url,
22
+ ...options?.headers
23
+ }
24
+ });
25
+ }
16
26
  update(options) {
17
27
  this.statusCode = options.statusCode;
18
28
  this.statusMessage = options.statusMessage;
@@ -25,3 +35,6 @@ export class HttpServerResponse {
25
35
  }
26
36
  }
27
37
  }
38
+ export function redirect(url, options) {
39
+ return HttpServerResponse.redirect(url, options);
40
+ }
@@ -8,6 +8,7 @@ export * from './inject.js';
8
8
  export * from './injector.js';
9
9
  export * from './interfaces.js';
10
10
  export * from './provider.js';
11
+ export * from './resolution.js';
11
12
  export * from './resolve-chain.js';
12
13
  export * from './resolve.error.js';
13
14
  export * from './symbols.js';
package/injector/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './inject.js';
8
8
  export * from './injector.js';
9
9
  export * from './interfaces.js';
10
10
  export * from './provider.js';
11
+ export * from './resolution.js';
11
12
  export * from './resolve-chain.js';
12
13
  export * from './resolve.error.js';
13
14
  export * from './symbols.js';
@@ -12,6 +12,7 @@ import { assert, isArray, isBoolean, isDefined, isFunction, isNotNull, isNull, i
12
12
  import { setCurrentInjectionContext } from './inject.js';
13
13
  import { afterResolve } from './interfaces.js';
14
14
  import { isClassProvider, isFactoryProvider, isProviderWithInitializer, isTokenProvider, isValueProvider } from './provider.js';
15
+ import { runInResolutionContext } from './resolution.js';
15
16
  import { ResolveChain } from './resolve-chain.js';
16
17
  import { ResolveError } from './resolve.error.js';
17
18
  import { injectMetadataSymbol, injectableMetadataSymbol } from './symbols.js';
@@ -264,7 +265,7 @@ export class Injector {
264
265
  }
265
266
  const injectionContext = injector.getInjectionContext(context, argument, chain);
266
267
  const previousInjectionContext = setCurrentInjectionContext(injectionContext);
267
- const resolutionTag = Symbol(); // eslint-disable-line symbol-description
268
+ const resolutionTag = Symbol('ResolutionTag');
268
269
  try {
269
270
  const resolutionScoped = registration.options.lifecycle == 'resolution';
270
271
  const injectorScoped = registration.options.lifecycle == 'injector';
@@ -280,12 +281,16 @@ export class Injector {
280
281
  else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
281
282
  return registration.resolutions.get(argumentIdentity);
282
283
  }
283
- const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain);
284
+ const resolutionContext = {
285
+ afterResolveRegistrations: []
286
+ };
287
+ const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain);
284
288
  const resolution = {
285
289
  tag: resolutionTag,
286
290
  registration,
287
291
  value,
288
292
  argument: injectionContext.argument,
293
+ afterResolveRegistrations: resolutionContext.afterResolveRegistrations,
289
294
  afterResolveContext: injector.getAfterResolveContext(resolutionTag, context),
290
295
  chain
291
296
  };
@@ -305,7 +310,7 @@ export class Injector {
305
310
  setCurrentInjectionContext(previousInjectionContext);
306
311
  }
307
312
  }
308
- _resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain) {
313
+ _resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain) {
309
314
  try {
310
315
  setResolving(registration.token, context, chain);
311
316
  const { provider } = registration;
@@ -319,7 +324,7 @@ export class Injector {
319
324
  }
320
325
  const parameters = (typeMetadata?.parameters ?? []).map((metadata) => this.resolveClassInjection(resolutionTag, context, provider.useClass, metadata, arg, chain));
321
326
  try {
322
- result = { value: new provider.useClass(...parameters) };
327
+ result = { value: runInResolutionContext(resolutionContext, () => Reflect.construct(provider.useClass, parameters)) };
323
328
  }
324
329
  catch (error) {
325
330
  if (error instanceof ResolveError) {
@@ -344,7 +349,7 @@ export class Injector {
344
349
  const arg = resolveArgument ?? provider.defaultArgument ?? provider.defaultArgumentProvider?.();
345
350
  injectionContext.argument = arg;
346
351
  try {
347
- result = { value: provider.useFactory(arg, this.getResolveContext(resolutionTag, context, chain)) };
352
+ result = { value: runInResolutionContext(resolutionContext, () => provider.useFactory(arg, this.getResolveContext(resolutionTag, context, chain))) };
348
353
  }
349
354
  catch (error) {
350
355
  throw new ResolveError('Error in provider factory.', chain, error);
@@ -484,7 +489,11 @@ function postProcess(context) {
484
489
  }
485
490
  derefForwardRefs(context);
486
491
  for (const resolution of context.resolutions) {
487
- if (isFunction(resolution.value?.[afterResolve])) {
492
+ for (const afterResolveHandler of resolution.afterResolveRegistrations) {
493
+ const returnValue = afterResolveHandler(resolution.argument, resolution.afterResolveContext);
494
+ throwOnPromise(returnValue, 'registerAfterResolve()', resolution.chain);
495
+ }
496
+ if (!isTokenProvider(resolution.registration.provider) && isFunction(resolution.value?.[afterResolve])) {
488
497
  const returnValue = resolution.value[afterResolve](resolution.argument, resolution.afterResolveContext);
489
498
  throwOnPromise(returnValue, '[afterResolve]', resolution.chain);
490
499
  }
@@ -504,7 +513,10 @@ async function postProcessAsync(context) {
504
513
  }
505
514
  derefForwardRefs(context);
506
515
  for (const resolution of context.resolutions) {
507
- if (isFunction(resolution.value?.[afterResolve])) {
516
+ for (const afterResolveHandler of resolution.afterResolveRegistrations) {
517
+ await afterResolveHandler(resolution.argument, resolution.afterResolveContext);
518
+ }
519
+ if (!isTokenProvider(resolution.registration.provider) && isFunction(resolution.value?.[afterResolve])) {
508
520
  await resolution.value[afterResolve](resolution.argument, resolution.afterResolveContext);
509
521
  }
510
522
  if (isProviderWithInitializer(resolution.registration.provider)) {
@@ -13,5 +13,5 @@ export interface Resolvable<A = unknown, D extends Record = Record> extends Part
13
13
  readonly [resolveArgumentType]?: A;
14
14
  }
15
15
  export interface AfterResolve<A = unknown, D extends Record = Record> {
16
- [afterResolve](argument: A, context: AfterResolveContext<D>): void | Promise<void>;
16
+ [afterResolve](argument: NoInfer<A>, context: AfterResolveContext<NoInfer<D>>): void | Promise<void>;
17
17
  }
@@ -1,2 +1,2 @@
1
1
  export const resolveArgumentType = Symbol('resolveArgumentType');
2
- export const afterResolve = Symbol('after resolve');
2
+ export const afterResolve = Symbol('afterResolve');
@@ -0,0 +1,15 @@
1
+ import type { Record } from '../types.js';
2
+ import type { Resolvable } from './interfaces.js';
3
+ import type { AfterResolveContext } from './types.js';
4
+ export type AfterResolveHandler<A, D extends Record> = (argument: A, context: AfterResolveContext<D>) => void | Promise<void>;
5
+ export type ResolutionContext<A> = {
6
+ afterResolveRegistrations: AfterResolveHandler<A, any>[];
7
+ };
8
+ declare const assertInResolutionContext: (debugFnOrMessage: import("../types.js").Function | string) => void, getCurrentResolutionContext: {
9
+ (required: true, debugFn: import("../types.js").Function): ResolutionContext<any>;
10
+ (required?: false, debugFn?: import("../types.js").Function): ResolutionContext<any> | null;
11
+ (required: boolean, debugFn: import("../types.js").Function): ResolutionContext<any> | null;
12
+ }, runInResolutionContext: <ReturnT>(context: ResolutionContext<any>, fn: () => ReturnT) => ReturnT;
13
+ export declare function registerAfterResolve(handler: AfterResolveHandler<unknown, Record>): void;
14
+ export declare function registerAfterResolve<A, D extends Record>(_this: Resolvable<A, D>, handler: AfterResolveHandler<A, D>): void;
15
+ export { assertInResolutionContext, getCurrentResolutionContext, runInResolutionContext };
@@ -0,0 +1,6 @@
1
+ import { createContextProvider } from '../context/index.js';
2
+ const { assertInResolutionContext, getCurrentResolutionContext, runInResolutionContext } = createContextProvider('Resolution');
3
+ export function registerAfterResolve(thisOrHandler, handlerOrNothing) {
4
+ getCurrentResolutionContext(true, registerAfterResolve).afterResolveRegistrations.push(handlerOrNothing ?? thisOrHandler);
5
+ }
6
+ export { assertInResolutionContext, getCurrentResolutionContext, runInResolutionContext };
@@ -7,5 +7,5 @@ export declare class ConsoleLogger extends Logger {
7
7
  fork(options: LoggerForkOptions): ConsoleLogger;
8
8
  subModule(subModule: string): ConsoleLogger;
9
9
  prefix(prefix: string): ConsoleLogger;
10
- protected log(level: LogLevel, entryOrError: string | Error, errorOptions?: LogErrorOptions): void;
10
+ protected log(level: LogLevel, entryOrError: string | unknown, errorOptions?: LogErrorOptions): void;
11
11
  }
@@ -26,8 +26,8 @@ export declare abstract class Logger implements Resolvable<LoggerArgument> {
26
26
  readonly logPrefix: string;
27
27
  readonly [resolveArgumentType]: LoggerArgument;
28
28
  constructor(level: LogLevel, module?: string | string[], prefix?: string);
29
- error(error: Error, options?: LogErrorOptions): void;
30
29
  error(entry: LogEntryOrProvider): void;
30
+ error(error: unknown, options?: LogErrorOptions): void;
31
31
  warn(entry: LogEntryOrProvider): void;
32
32
  info(entry: LogEntryOrProvider): void;
33
33
  verbose(entry: LogEntryOrProvider): void;
@@ -5,7 +5,7 @@ export default defineConfig({
5
5
  out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
6
  schema: resolve(__dirname, './models/schemas.js'),
7
7
  migrations: {
8
- schema: 'authentication',
8
+ schema: 'mail',
9
9
  table: '_migrations'
10
10
  }
11
11
  });
@@ -1,3 +1,3 @@
1
1
  import { MailLog } from './mail-log.model.js';
2
2
  export declare const mailSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"mail">;
3
- export declare const mailLog: import("../../orm/server/types.js").PgTableFromType<"mail", typeof MailLog>;
3
+ export declare const mailLog: import("../../orm/server/types.js").PgTableFromType<typeof MailLog, "mail">;
@@ -21,13 +21,6 @@ export declare abstract class ObjectStorage implements Resolvable<ObjectStorageA
21
21
  * @param content content of object
22
22
  */
23
23
  abstract uploadObject(key: string, content: Uint8Array | ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
24
- /**
25
- * Uploads an object stream
26
- * @param key object key
27
- * @param stream stream of object
28
- * @deprecated use {@link uploadObject} instead
29
- */
30
- abstract uploadObjectStream(key: string, stream: ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
31
24
  /**
32
25
  * Get an url which can be used to upload the object without further authorization
33
26
  * @param key object key
@@ -52,6 +45,11 @@ export declare abstract class ObjectStorage implements Resolvable<ObjectStorageA
52
45
  * @param key object key
53
46
  */
54
47
  abstract getResourceUri(key: string): Promise<string>;
48
+ /**
49
+ * Get object content
50
+ * @param key object key
51
+ */
52
+ abstract getContent(key: string): Promise<Uint8Array>;
55
53
  /**
56
54
  * Get stream of object content
57
55
  * @param key object key
@@ -12,7 +12,6 @@ export declare class S3ObjectStorage extends ObjectStorage {
12
12
  exists(key: string): Promise<boolean>;
13
13
  statObject(key: string): Promise<BucketItemStat>;
14
14
  uploadObject(key: string, content: Uint8Array | ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
15
- uploadObjectStream(key: string, stream: ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
16
15
  getContent(key: string): Promise<Uint8Array>;
17
16
  getContentStream(key: string): ReadableStream<Uint8Array>;
18
17
  getObjects(): Promise<S3Object[]>;
@@ -66,9 +66,6 @@ let S3ObjectStorage = class S3ObjectStorage extends ObjectStorage {
66
66
  ]);
67
67
  }
68
68
  }
69
- async uploadObjectStream(key, stream, options) {
70
- return this.uploadObject(key, stream, options);
71
- }
72
69
  async getContent(key) {
73
70
  const bucketKey = this.getBucketKey(key);
74
71
  const result = await this.client.getObject(this.bucket, bucketKey);
@@ -1,12 +1,11 @@
1
1
  import { customType } from 'drizzle-orm/pg-core';
2
- import { dateToNumericDate, numericDateToDate } from '../../../utils/date-time.js';
2
+ import { dateToNumericDate, numericDateToDate } from '../../utils/date-time.js';
3
3
  export const numericDate = customType({
4
4
  dataType() {
5
5
  return 'date';
6
6
  },
7
7
  toDriver(value) {
8
- const { year, month, day } = numericDateToDate(value);
9
- return new Date(year, month - 1, day).toISOString();
8
+ return numericDateToDate(value).toISOString();
10
9
  },
11
10
  fromDriver(value) {
12
11
  const date = new Date(value);
@@ -4,16 +4,16 @@ import type { AbstractConstructor, TypedOmit } from '../types.js';
4
4
  import type { Entity, EntityType } from './entity.js';
5
5
  import type { PgTableFromType } from './server/types.js';
6
6
  type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat', string>;
7
- export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<string, EntityType<T>>) => SQL;
7
+ type NamingStrategy = 'abbreviated-table';
8
+ export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<EntityType<T>>) => SQL;
8
9
  export type OrmTableReflectionData = {
9
10
  name?: string;
10
11
  schema?: string;
12
+ compundPrimaryKeyName?: string;
13
+ compundPrimaryKeyNaming?: NamingStrategy;
11
14
  unique?: UniqueReflectionData[];
12
15
  index?: IndexReflectionData[];
13
- checks?: {
14
- name: string;
15
- builder: CheckBuilder;
16
- }[];
16
+ checks?: CheckReflectionData[];
17
17
  };
18
18
  export type OrmColumnReflectionData = {
19
19
  name?: string;
@@ -35,6 +35,7 @@ export type UniqueReflectionData = {
35
35
  columns?: string[];
36
36
  options?: {
37
37
  nulls?: 'distinct' | 'not distinct';
38
+ naming?: NamingStrategy;
38
39
  };
39
40
  };
40
41
  export type IndexReflectionData = {
@@ -45,6 +46,14 @@ export type IndexReflectionData = {
45
46
  using?: IndexMethod;
46
47
  unique?: boolean;
47
48
  nulls?: 'first' | 'last';
49
+ naming?: NamingStrategy;
50
+ };
51
+ };
52
+ type CheckReflectionData = {
53
+ name: string;
54
+ builder: CheckBuilder;
55
+ options?: {
56
+ naming?: NamingStrategy;
48
57
  };
49
58
  };
50
59
  export declare function createTableDecorator(data?: OrmTableReflectionData): ClassDecorator;
@@ -60,9 +69,9 @@ type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
60
69
  export declare function Table(name?: string, options?: TypedOmit<TableOptions, 'schema'>): ClassDecorator;
61
70
  export declare function Table(options?: TableOptions): ClassDecorator;
62
71
  export declare function Unique(name?: string, options?: UniqueReflectionData['options']): PropertyDecorator;
63
- export declare function Unique(name: string | undefined, columns: [string, ...string[]], options?: UniqueReflectionData['options']): ClassDecorator;
64
- export declare function Unique(columns: [string, ...string[]], options?: UniqueReflectionData['options']): ClassDecorator;
72
+ export declare function Unique<T>(name: string | undefined, columns: [Extract<keyof T, string>, ...Extract<keyof T, string>[]], options?: UniqueReflectionData['options']): ClassDecorator;
73
+ export declare function Unique<T>(columns: [Extract<keyof T, string>, ...Extract<keyof T, string>[]], options?: UniqueReflectionData['options']): ClassDecorator;
65
74
  export declare function Index(name?: string, options?: IndexReflectionData['options']): PropertyDecorator;
66
- export declare function Index(name: string | undefined, columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
75
+ export declare function Index(name: string, columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
67
76
  export declare function Index(columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
68
77
  export {};
package/orm/decorators.js CHANGED
@@ -1,20 +1,23 @@
1
1
  import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
2
2
  import { Property } from '../schema/index.js';
3
- import { objectEntries } from '../utils/object/object.js';
3
+ import { filterUndefinedObjectProperties, objectEntries } from '../utils/object/object.js';
4
4
  import { assertNotArrayPass, isArray, isString, isUndefined } from '../utils/type-guards.js';
5
5
  export function createTableDecorator(data = {}) {
6
6
  return createClassDecorator({
7
7
  handler: (_, metadata) => {
8
8
  const reflectionData = metadata.data.tryGet('orm') ?? {};
9
9
  const dataEntries = objectEntries(data);
10
+ if (dataEntries.length == 0) {
11
+ return;
12
+ }
10
13
  for (const [key, value] of dataEntries) {
11
14
  const existingValue = reflectionData[key];
12
- if (isUndefined(existingValue)) {
13
- reflectionData[key] = value;
14
- }
15
- else if (isArray(existingValue)) {
15
+ if (isArray(existingValue)) {
16
16
  reflectionData[key] = [...existingValue, ...value];
17
17
  }
18
+ else {
19
+ reflectionData[key] = value;
20
+ }
18
21
  }
19
22
  metadata.data.set('orm', reflectionData, true);
20
23
  }
@@ -49,7 +52,10 @@ export function Embedded(type, options) {
49
52
  export function Table(nameOrOptions, optionsOrNothing) {
50
53
  const name = isString(nameOrOptions) ? nameOrOptions : nameOrOptions?.name;
51
54
  const schema = isString(nameOrOptions) ? optionsOrNothing?.schema : nameOrOptions?.schema;
52
- return createTableDecorator({ name, schema });
55
+ const data = (isUndefined(name) && isUndefined(schema))
56
+ ? undefined
57
+ : filterUndefinedObjectProperties({ name, schema });
58
+ return createTableDecorator(data);
53
59
  }
54
60
  export function Unique(nameOrColumns, columnsOrOptions, options) {
55
61
  if (isArray(nameOrColumns)) {
@@ -58,7 +64,7 @@ export function Unique(nameOrColumns, columnsOrOptions, options) {
58
64
  if (isArray(columnsOrOptions)) {
59
65
  return createTableDecorator({ unique: [{ name: nameOrColumns, columns: columnsOrOptions, options }] });
60
66
  }
61
- return createColumnDecorator({ unique: { name: nameOrColumns, options: columnsOrOptions ?? options } });
67
+ return createColumnDecorator({ unique: { name: nameOrColumns, options: columnsOrOptions } });
62
68
  }
63
69
  export function Index(nameOrColumns, columnsOrOptions, options) {
64
70
  if (isArray(nameOrColumns)) {
package/orm/entity.d.ts CHANGED
@@ -1,13 +1,8 @@
1
- import type { Type, TypedOmit } from '../types.js';
2
- import type { UntaggedDeep } from '../types/index.js';
1
+ import type { Type } from '../types.js';
3
2
  import { Embedded, type HasDefault, type IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
4
- export interface EntityType<T extends Entity = Entity> extends Type<T> {
3
+ export interface EntityType<T extends Entity | EntityWithoutMetadata = Entity | EntityWithoutMetadata> extends Type<T> {
5
4
  readonly entityName?: string;
6
5
  }
7
- export type NewEntity<T extends Entity> = UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
8
- id?: string;
9
- metadata?: Partial<Pick<EntityMetadata, 'attributes'>>;
10
- }>;
11
6
  export declare abstract class EntityMetadataAttributes {
12
7
  [key: string]: unknown;
13
8
  }
@@ -22,3 +17,6 @@ export declare abstract class Entity {
22
17
  id: IsPrimaryKey<HasDefault<Uuid>>;
23
18
  metadata: Embedded<EntityMetadata>;
24
19
  }
20
+ export declare abstract class EntityWithoutMetadata {
21
+ id: IsPrimaryKey<HasDefault<Uuid>>;
22
+ }
package/orm/entity.js CHANGED
@@ -8,7 +8,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
10
  import { Defaulted, Integer } from '../schema/index.js';
11
- import { Index, PrimaryKey } from './decorators.js';
11
+ import { PrimaryKey } from './decorators.js';
12
12
  import { Embedded, Json, Timestamp, Uuid } from './types.js';
13
13
  let EntityMetadataAttributes = class EntityMetadataAttributes {
14
14
  };
@@ -16,13 +16,13 @@ EntityMetadataAttributes = __decorate([
16
16
  Json()
17
17
  ], EntityMetadataAttributes);
18
18
  export { EntityMetadataAttributes };
19
- let EntityMetadata = class EntityMetadata {
19
+ export class EntityMetadata {
20
20
  revision;
21
21
  revisionTimestamp;
22
22
  createTimestamp;
23
23
  deleteTimestamp;
24
24
  attributes;
25
- };
25
+ }
26
26
  __decorate([
27
27
  Integer(),
28
28
  __metadata("design:type", Number)
@@ -43,10 +43,6 @@ __decorate([
43
43
  Defaulted(EntityMetadataAttributes, {}),
44
44
  __metadata("design:type", Object)
45
45
  ], EntityMetadata.prototype, "attributes", void 0);
46
- EntityMetadata = __decorate([
47
- Index(undefined, ['revision', 'revisionTimestamp'])
48
- ], EntityMetadata);
49
- export { EntityMetadata };
50
46
  export class Entity {
51
47
  id;
52
48
  metadata;
@@ -60,3 +56,11 @@ __decorate([
60
56
  Embedded(EntityMetadata, { prefix: null }),
61
57
  __metadata("design:type", Object)
62
58
  ], Entity.prototype, "metadata", void 0);
59
+ export class EntityWithoutMetadata {
60
+ id;
61
+ }
62
+ __decorate([
63
+ PrimaryKey(),
64
+ Uuid({ defaultRandom: true }),
65
+ __metadata("design:type", Object)
66
+ ], EntityWithoutMetadata.prototype, "id", void 0);
package/orm/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './entity.js';
2
2
  export * from './query.js';
3
+ export * from './repository.types.js';
3
4
  export * from './types.js';
5
+ export * from './utils.js';
package/orm/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './entity.js';
2
2
  export * from './query.js';
3
+ export * from './repository.types.js';
3
4
  export * from './types.js';
5
+ export * from './utils.js';
package/orm/query.d.ts CHANGED
@@ -19,8 +19,6 @@ export type Query<T = any> = SQLWrapper | QueryObject<T>;
19
19
  export type QueryObject<T> = LogicalQuery<T> | (ComparisonQueryBody<T> & SpecialQuery<T>);
20
20
  export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
21
21
  export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$text" | "$geoShape" | "$geoDistance" | "$textSpan")[];
22
- export type Order = 'asc' | 'desc';
23
- export declare const allOrders: Order[];
24
22
  export type Operator = 'and' | 'or';
25
23
  export declare const allOperators: Operator[];
26
24
  export type LogicalAndQuery<T = any> = {
@@ -32,7 +30,7 @@ export type LogicalOrQuery<T = any> = {
32
30
  export type LogicalNorQuery<T = any> = {
33
31
  $nor: readonly Query<T>[];
34
32
  };
35
- export type ComparisonValue<T> = Untagged<T | Flatten<T>>;
33
+ export type ComparisonValue<T> = Untagged<T | Flatten<T>> | SQLWrapper;
36
34
  export type ComparisonValueWithRegex<T> = T extends string ? ComparisonValue<T | RegExp> : T extends readonly string[] ? ComparisonValue<readonly (Flatten<T> | RegExp)[]> : (T | Flatten<T>);
37
35
  export type ComparisonNotQuery<T = any> = {
38
36
  $not: ComparisonQuery<T>;