@tstdl/base 0.93.1 → 0.93.3

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 (181) hide show
  1. package/api/server/api-request-token.provider.d.ts +5 -3
  2. package/api/server/api-request-token.provider.js +12 -4
  3. package/api/server/gateway.d.ts +1 -9
  4. package/api/server/gateway.js +67 -36
  5. package/api/types.d.ts +5 -1
  6. package/application/application.d.ts +2 -0
  7. package/application/application.js +3 -1
  8. package/application/providers.d.ts +1 -1
  9. package/application/providers.js +1 -1
  10. package/audit/audit.model.d.ts +106 -6
  11. package/audit/audit.model.js +156 -13
  12. package/audit/auditor.d.ts +115 -30
  13. package/audit/auditor.js +160 -19
  14. package/audit/drizzle/0000_bored_stick.sql +26 -0
  15. package/audit/drizzle/meta/0000_snapshot.json +195 -0
  16. package/audit/drizzle/meta/_journal.json +13 -0
  17. package/audit/drizzle.config.d.ts +2 -0
  18. package/audit/drizzle.config.js +11 -0
  19. package/audit/index.d.ts +3 -1
  20. package/audit/index.js +3 -1
  21. package/audit/module.d.ts +22 -0
  22. package/audit/module.js +33 -0
  23. package/audit/schemas.d.ts +6 -0
  24. package/audit/schemas.js +8 -0
  25. package/audit/types.d.ts +2 -1
  26. package/audit/types.js +2 -1
  27. package/authentication/models/authentication-credentials.model.js +1 -2
  28. package/authentication/models/authentication-session.model.d.ts +2 -2
  29. package/authentication/models/authentication-session.model.js +3 -5
  30. package/authentication/models/index.d.ts +0 -1
  31. package/authentication/models/index.js +0 -1
  32. package/authentication/server/authentication-api-request-token.provider.d.ts +2 -2
  33. package/authentication/server/authentication-api-request-token.provider.js +8 -5
  34. package/authentication/server/authentication.api-controller.d.ts +8 -8
  35. package/authentication/server/authentication.api-controller.js +16 -16
  36. package/authentication/server/authentication.audit.d.ts +34 -0
  37. package/authentication/server/authentication.audit.js +1 -0
  38. package/authentication/server/authentication.service.d.ts +19 -10
  39. package/authentication/server/authentication.service.js +158 -43
  40. package/authentication/server/drizzle.config.js +1 -1
  41. package/authentication/server/index.d.ts +1 -0
  42. package/authentication/server/index.js +1 -0
  43. package/authentication/server/module.d.ts +1 -1
  44. package/authentication/{models → server}/schemas.d.ts +2 -3
  45. package/authentication/{models → server}/schemas.js +2 -3
  46. package/constants.d.ts +1 -0
  47. package/constants.js +1 -0
  48. package/document-management/api/document-management.api.d.ts +74 -74
  49. package/document-management/models/document-assignment-scope.model.d.ts +1 -2
  50. package/document-management/models/document-assignment-scope.model.js +4 -6
  51. package/document-management/models/document-assignment-task.model.d.ts +1 -2
  52. package/document-management/models/document-assignment-task.model.js +3 -5
  53. package/document-management/models/document-category.model.d.ts +1 -2
  54. package/document-management/models/document-category.model.js +3 -4
  55. package/document-management/models/document-collection-assignment.model.d.ts +1 -2
  56. package/document-management/models/document-collection-assignment.model.js +5 -7
  57. package/document-management/models/document-collection.model.d.ts +1 -2
  58. package/document-management/models/document-collection.model.js +3 -4
  59. package/document-management/models/document-management-table.d.ts +1 -1
  60. package/document-management/models/document-management-table.js +1 -1
  61. package/document-management/models/document-property-value.model.d.ts +1 -2
  62. package/document-management/models/document-property-value.model.js +5 -8
  63. package/document-management/models/document-property.model.d.ts +1 -2
  64. package/document-management/models/document-property.model.js +2 -3
  65. package/document-management/models/document-request-collection-assignment.model.d.ts +1 -2
  66. package/document-management/models/document-request-collection-assignment.model.js +4 -6
  67. package/document-management/models/document-request-template.d.ts +1 -2
  68. package/document-management/models/document-request-template.js +4 -6
  69. package/document-management/models/document-request.model.d.ts +1 -1
  70. package/document-management/models/document-request.model.js +4 -5
  71. package/document-management/models/document-requests-template.d.ts +1 -1
  72. package/document-management/models/document-requests-template.js +2 -3
  73. package/document-management/models/document-tag-assignment.model.d.ts +1 -2
  74. package/document-management/models/document-tag-assignment.model.js +4 -6
  75. package/document-management/models/document-tag.model.d.ts +1 -1
  76. package/document-management/models/document-tag.model.js +2 -3
  77. package/document-management/models/document-type-property.model.d.ts +1 -2
  78. package/document-management/models/document-type-property.model.js +4 -6
  79. package/document-management/models/document-type-validation.model.d.ts +1 -2
  80. package/document-management/models/document-type-validation.model.js +4 -6
  81. package/document-management/models/document-type.model.d.ts +1 -2
  82. package/document-management/models/document-type.model.js +3 -5
  83. package/document-management/models/document-validation-definition.model.d.ts +1 -2
  84. package/document-management/models/document-validation-definition.model.js +3 -4
  85. package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -2
  86. package/document-management/models/document-validation-execution-related-document.model.js +4 -6
  87. package/document-management/models/document-validation-execution.model.d.ts +1 -2
  88. package/document-management/models/document-validation-execution.model.js +6 -8
  89. package/document-management/models/document-workflow.model.d.ts +1 -2
  90. package/document-management/models/document-workflow.model.js +5 -7
  91. package/document-management/models/document.model.d.ts +1 -2
  92. package/document-management/models/document.model.js +5 -7
  93. package/document-management/server/api/document-management.api.js +1 -1
  94. package/document-management/server/module.d.ts +1 -1
  95. package/document-management/server/module.js +1 -1
  96. package/document-management/server/schemas.d.ts +1 -1
  97. package/document-management/server/schemas.js +1 -1
  98. package/document-management/server/services/document-category-type.service.d.ts +2 -2
  99. package/document-management/server/services/document-category-type.service.js +1 -2
  100. package/document-management/server/services/document-collection.service.d.ts +1 -1
  101. package/document-management/server/services/document-collection.service.js +1 -2
  102. package/document-management/server/services/document-management.service.js +6 -6
  103. package/document-management/server/services/document-property.service.d.ts +1 -1
  104. package/document-management/server/services/document-property.service.js +1 -2
  105. package/document-management/server/services/document-validation.service.js +2 -2
  106. package/document-management/server/services/document-workflow.service.d.ts +2 -2
  107. package/document-management/server/services/document-workflow.service.js +1 -2
  108. package/document-management/server/services/document.service.d.ts +1 -1
  109. package/document-management/server/services/document.service.js +1 -2
  110. package/document-management/server/services/singleton.js +1 -1
  111. package/document-management/service-models/document.service-model.d.ts +62 -62
  112. package/document-management/service-models/document.service-model.js +1 -1
  113. package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
  114. package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
  115. package/examples/api/authentication.js +2 -2
  116. package/examples/api/basic-overview.js +2 -2
  117. package/examples/api/custom-authentication.js +2 -2
  118. package/examples/api/streaming.js +2 -2
  119. package/examples/browser/basic.js +2 -2
  120. package/examples/document-management/main.js +2 -2
  121. package/examples/http/client.js +2 -2
  122. package/examples/mail/basic.js +2 -2
  123. package/examples/pdf/basic.js +2 -2
  124. package/examples/template/basic.js +2 -2
  125. package/http/server/http-server-request.d.ts +3 -3
  126. package/key-value-store/postgres/key-value-store.service.js +1 -2
  127. package/key-value-store/postgres/models/key-value.model.d.ts +1 -2
  128. package/key-value-store/postgres/models/key-value.model.js +2 -4
  129. package/key-value-store/postgres/models/schemas.d.ts +1 -1
  130. package/key-value-store/postgres/models/schemas.js +1 -1
  131. package/lock/postgres/lock.js +1 -1
  132. package/lock/postgres/models/lock.model.d.ts +1 -2
  133. package/lock/postgres/models/lock.model.js +3 -5
  134. package/lock/postgres/models/schemas.d.ts +1 -1
  135. package/lock/postgres/models/schemas.js +1 -1
  136. package/lock/postgres/provider.js +1 -2
  137. package/mail/models/mail-log.model.d.ts +1 -1
  138. package/mail/models/mail-log.model.js +4 -5
  139. package/mail/models/schemas.d.ts +1 -1
  140. package/mail/models/schemas.js +1 -1
  141. package/openid-connect/oidc-state.model.d.ts +1 -1
  142. package/openid-connect/oidc-state.model.js +2 -3
  143. package/openid-connect/oidc.service.js +1 -1
  144. package/orm/data-types/bytea.js +1 -1
  145. package/orm/data-types/numeric-date.js +1 -1
  146. package/orm/decorators.d.ts +65 -72
  147. package/orm/decorators.js +42 -40
  148. package/orm/entity.d.ts +7 -1
  149. package/orm/entity.js +25 -11
  150. package/orm/index.d.ts +2 -1
  151. package/orm/index.js +2 -1
  152. package/orm/schemas/json.d.ts +1 -1
  153. package/orm/schemas/json.js +1 -1
  154. package/orm/schemas/numeric-date.d.ts +1 -1
  155. package/orm/schemas/numeric-date.js +1 -1
  156. package/orm/schemas/timestamp.d.ts +1 -1
  157. package/orm/schemas/timestamp.js +1 -1
  158. package/orm/schemas/uuid.d.ts +2 -2
  159. package/orm/schemas/uuid.js +1 -1
  160. package/orm/server/drizzle/schema-converter.ts +408 -0
  161. package/orm/server/repository.d.ts +1 -1
  162. package/orm/server/repository.js +12 -9
  163. package/orm/sqls.d.ts +1 -1
  164. package/orm/sqls.js +1 -1
  165. package/orm/types.d.ts +2 -6
  166. package/orm/types.js +1 -4
  167. package/package.json +15 -24
  168. package/queue/postgres/job.model.d.ts +3 -3
  169. package/queue/postgres/job.model.js +5 -6
  170. package/queue/postgres/queue.js +2 -2
  171. package/queue/postgres/schemas.d.ts +1 -1
  172. package/queue/postgres/schemas.js +1 -1
  173. package/supports.d.ts +1 -0
  174. package/supports.js +2 -1
  175. package/types/types.d.ts +12 -1
  176. package/utils/object/object.d.ts +3 -1
  177. package/utils/object/object.js +7 -1
  178. package/orm/server/drizzle/index.js +0 -1
  179. package/orm/server/drizzle/schema-converter.d.ts +0 -15
  180. package/orm/server/drizzle/schema-converter.js +0 -300
  181. /package/orm/server/drizzle/{index.d.ts → index.ts} +0 -0
@@ -7,9 +7,7 @@ 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 { ExpiresAt, Table } from '../../../orm/decorators.js';
11
- import { EntityWithoutMetadata } from '../../../orm/entity.js';
12
- import { Timestamp, Unique } from '../../../orm/types.js';
10
+ import { EntityWithoutMetadata, Expires, Table, TimestampProperty, Unique } from '../../../orm/index.js';
13
11
  import { StringProperty } from '../../../schema/index.js';
14
12
  let PostgresLock = class PostgresLock extends EntityWithoutMetadata {
15
13
  resource;
@@ -26,8 +24,8 @@ __decorate([
26
24
  __metadata("design:type", String)
27
25
  ], PostgresLock.prototype, "key", void 0);
28
26
  __decorate([
29
- ExpiresAt(),
30
- Timestamp(),
27
+ Expires(),
28
+ TimestampProperty(),
31
29
  __metadata("design:type", Number)
32
30
  ], PostgresLock.prototype, "expiration", void 0);
33
31
  PostgresLock = __decorate([
@@ -1,3 +1,3 @@
1
1
  import { PostgresLock } from './lock.model.js';
2
- export declare const lockSchema: import("../../../orm/server/database-schema.js").DatabaseSchema<"lock">;
2
+ export declare const lockSchema: import("../../../orm/server/index.js").DatabaseSchema<"lock">;
3
3
  export declare const lock: import("../../../orm/server/types.js").PgTableFromType<typeof PostgresLock, "lock">;
@@ -1,4 +1,4 @@
1
- import { databaseSchema } from '../../../orm/server/database-schema.js';
1
+ import { databaseSchema } from '../../../orm/server/index.js';
2
2
  import { PostgresLock } from './lock.model.js';
3
3
  export const lockSchema = databaseSchema('lock');
4
4
  export const lock = lockSchema.getTable(PostgresLock);
@@ -5,8 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Singleton, provide } from '../../injector/index.js';
8
- import { DatabaseConfig } from '../../orm/server/index.js';
9
- import { EntityRepositoryConfig, injectRepository } from '../../orm/server/repository.js';
8
+ import { DatabaseConfig, EntityRepositoryConfig, injectRepository } from '../../orm/server/index.js';
10
9
  import { LockProvider } from '../provider.js';
11
10
  import { PostgresLockAdapter } from './lock.js';
12
11
  import { PostgresLock } from './models/lock.model.js';
@@ -1,4 +1,4 @@
1
- import { Entity, Json, Timestamp } from '../../orm/index.js';
1
+ import { Entity, type Json, type Timestamp } from '../../orm/index.js';
2
2
  import type { MailData } from './mail-data.model.js';
3
3
  import type { MailSendResult } from './mail-send-result.model.js';
4
4
  export declare class MailLog extends Entity {
@@ -7,8 +7,7 @@ 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 { Table } from '../../orm/decorators.js';
11
- import { Entity, Json, Timestamp } from '../../orm/index.js';
10
+ import { Entity, JsonProperty, Table, TimestampProperty } from '../../orm/index.js';
12
11
  import { StringProperty } from '../../schema/index.js';
13
12
  let MailLog = class MailLog extends Entity {
14
13
  timestamp;
@@ -18,7 +17,7 @@ let MailLog = class MailLog extends Entity {
18
17
  errors;
19
18
  };
20
19
  __decorate([
21
- Timestamp(),
20
+ TimestampProperty(),
22
21
  __metadata("design:type", Number)
23
22
  ], MailLog.prototype, "timestamp", void 0);
24
23
  __decorate([
@@ -26,11 +25,11 @@ __decorate([
26
25
  __metadata("design:type", Object)
27
26
  ], MailLog.prototype, "template", void 0);
28
27
  __decorate([
29
- Json(),
28
+ JsonProperty(),
30
29
  __metadata("design:type", Object)
31
30
  ], MailLog.prototype, "data", void 0);
32
31
  __decorate([
33
- Json({ nullable: true }),
32
+ JsonProperty({ nullable: true }),
34
33
  __metadata("design:type", Object)
35
34
  ], MailLog.prototype, "sendResult", void 0);
36
35
  __decorate([
@@ -1,3 +1,3 @@
1
1
  import { MailLog } from './mail-log.model.js';
2
- export declare const mailSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"mail">;
2
+ export declare const mailSchema: import("../../orm/server/index.js").DatabaseSchema<"mail">;
3
3
  export declare const mailLog: import("../../orm/server/types.js").PgTableFromType<typeof MailLog, "mail">;
@@ -1,4 +1,4 @@
1
- import { databaseSchema } from '../../orm/server/database-schema.js';
1
+ import { databaseSchema } from '../../orm/server/index.js';
2
2
  import { MailLog } from './mail-log.model.js';
3
3
  export const mailSchema = databaseSchema('mail');
4
4
  export const mailLog = mailSchema.getTable(MailLog);
@@ -1,4 +1,4 @@
1
- import { EntityWithoutMetadata, Json } from '../orm/index.js';
1
+ import { EntityWithoutMetadata, type Json } from '../orm/index.js';
2
2
  export declare class OidcState<Data> extends EntityWithoutMetadata {
3
3
  value: string;
4
4
  codeVerifier: string;
@@ -7,8 +7,7 @@ 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 { ExpiresAt as Expires } from '../orm/decorators.js';
11
- import { EntityWithoutMetadata, Json, Unique } from '../orm/index.js';
10
+ import { EntityWithoutMetadata, Expires, JsonProperty, Unique } from '../orm/index.js';
12
11
  import { any, NumberProperty, StringProperty } from '../schema/index.js';
13
12
  export class OidcState extends EntityWithoutMetadata {
14
13
  value;
@@ -46,6 +45,6 @@ __decorate([
46
45
  __metadata("design:type", Number)
47
46
  ], OidcState.prototype, "expiration", void 0);
48
47
  __decorate([
49
- Json({ schema: any() }),
48
+ JsonProperty({ schema: any() }),
50
49
  __metadata("design:type", Object)
51
50
  ], OidcState.prototype, "data", void 0);
@@ -9,7 +9,7 @@ import { NotImplementedError } from '../errors/not-implemented.error.js';
9
9
  import { HttpClient } from '../http/client/index.js';
10
10
  import { HttpHeaders } from '../http/http-headers.js';
11
11
  import { inject, Singleton } from '../injector/index.js';
12
- import { injectRepository } from '../orm/server/repository.js';
12
+ import { injectRepository } from '../orm/server/index.js';
13
13
  import { object, optional, Schema, string } from '../schema/index.js';
14
14
  import { Alphabet } from '../utils/alphabet.js';
15
15
  import { digest } from '../utils/cryptography.js';
@@ -16,5 +16,5 @@ export const bytea = customType({
16
16
  },
17
17
  fromDriver(value) {
18
18
  return value;
19
- }
19
+ },
20
20
  });
@@ -19,5 +19,5 @@ export const numericDate = customType({
19
19
  fromDriver(value) {
20
20
  const date = new Date(value);
21
21
  return dateToNumericDate(date);
22
- }
22
+ },
23
23
  });
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type { SQL } from 'drizzle-orm';
6
6
  import type { LiteralUnion } from 'type-fest';
7
+ import { type SpecificCreateDecoratorOptions } from '../reflection/index.js';
7
8
  import type { AbstractConstructor, TypedOmit } from '../types/index.js';
8
9
  import type { AnyEntity, Entity, EntityType, EntityWithoutMetadata } from './entity.js';
9
10
  import type { Query } from './query.js';
@@ -14,14 +15,12 @@ type NamingStrategy = 'abbreviated-table';
14
15
  type Columns<T> = [Extract<keyof T, string>, ...Extract<keyof T, string>[]];
15
16
  /**
16
17
  * Builder function type for creating SQL check constraints.
17
- * @param table - The Drizzle table object.
18
- * @returns The SQL check constraint expression.
18
+ * @param table The Drizzle table object.
19
19
  */
20
20
  export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<EntityType<T>>) => SQL;
21
21
  /**
22
22
  * Builder function type for creating partial index WHERE clauses.
23
- * @param table - The Drizzle table object.
24
- * @returns The query object representing the WHERE clause.
23
+ * @param table The Drizzle table object.
25
24
  */
26
25
  export type WhereBuilder<T extends Entity | EntityWithoutMetadata = any> = (table: PgTableFromType<EntityType<T>>) => Query<T>;
27
26
  /**
@@ -58,6 +57,7 @@ export type OrmColumnReflectionData = {
58
57
  }[];
59
58
  encrypted?: boolean;
60
59
  expirationField?: {
60
+ after: number;
61
61
  mode: 'soft' | 'hard';
62
62
  };
63
63
  };
@@ -74,7 +74,7 @@ export type UniqueReflectionData = {
74
74
  };
75
75
  /**
76
76
  * Reflection data for index definitions.
77
- * @template T - The entity type.
77
+ * @template T The entity type.
78
78
  */
79
79
  export type IndexReflectionData<T extends Entity | EntityWithoutMetadata = any> = {
80
80
  columns?: (string | [string, 'asc' | 'desc'])[];
@@ -107,123 +107,116 @@ export type ForeignKeyReflectionData = {
107
107
  /**
108
108
  * Factory function to create a class decorator for ORM table configuration.
109
109
  * Merges provided data with existing ORM reflection data on the class metadata.
110
- * @param data - The ORM table reflection data to add.
111
- * @returns A class decorator.
110
+ * @param data The ORM table reflection data to add.
112
111
  */
113
112
  export declare function createTableDecorator(data?: OrmTableReflectionData): ClassDecorator;
114
113
  /**
115
114
  * Factory function to create a property decorator for ORM column configuration.
116
115
  * Merges provided data with existing ORM reflection data on the property metadata.
117
- * @param data - The ORM column reflection data to add.
118
- * @returns A property decorator.
116
+ * @param data The ORM column reflection data to add.
119
117
  */
120
- export declare function createColumnDecorator(data?: OrmColumnReflectionData): PropertyDecorator;
118
+ export declare function createColumnDecorator(data?: OrmColumnReflectionData, decoratorOptions?: TypedOmit<SpecificCreateDecoratorOptions<'property'>, 'handler'>): PropertyDecorator;
121
119
  /**
122
120
  * Factory function to create a decorator applicable to both classes and properties for ORM configuration.
123
121
  * Merges provided data with existing ORM reflection data on the target's metadata.
124
- * @param data - The ORM reflection data to add.
125
- * @returns A class or property decorator.
122
+ * @param data The ORM reflection data to add.
126
123
  */
127
124
  export declare function createTableAndColumnDecorator(data?: OrmColumnReflectionData): PropertyDecorator & ClassDecorator;
128
125
  /**
129
- * Decorator to specify ORM column options.
130
- * @param options - Column configuration options.
131
- * @returns A property decorator.
126
+ * Specify ORM column options.
127
+ * @param options Column configuration options.
132
128
  */
133
129
  export declare function Column(options: OrmColumnReflectionData): PropertyDecorator;
134
130
  /**
135
- * Decorator to mark a property as the primary key column.
136
- * @returns A property decorator.
131
+ * Mark a property as the primary key column.
137
132
  */
138
- export declare function PrimaryKey(): PropertyDecorator;
133
+ export declare function PrimaryKeyProperty(): PropertyDecorator;
139
134
  /**
140
- * Decorator to define a foreign key relationship.
141
- * @param type - A function returning the referenced entity type.
142
- * @returns A property decorator.
135
+ * Define a foreign key relationship.
136
+ * @param type A function returning the referenced entity type.
143
137
  */
144
138
  export declare function References(target: () => EntityType): PropertyDecorator;
145
139
  export declare function References<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?: TargetColumnPaths<T>): PropertyDecorator;
146
140
  /**
147
- * Decorator to define a table check constraint.
148
- * @template T - The entity type.
149
- * @param name - The name of the check constraint.
150
- * @param builder - A function to build the SQL check expression.
151
- * @returns A class decorator.
141
+ * Define a table check constraint.
142
+ * @template T The entity type.
143
+ * @param name The name of the check constraint.
144
+ * @param builder A function to build the SQL check expression.
152
145
  */
153
146
  export declare function Check<T extends Entity>(name: string, builder: CheckBuilder<T>): ClassDecorator;
154
147
  /**
155
- * Decorator to mark a column for encryption.
148
+ * Mark a column for encryption.
156
149
  * The underlying database type will typically be `bytea`.
157
- * @returns A property decorator.
158
150
  */
159
- export declare function Encrypted(): PropertyDecorator;
151
+ export declare function EncryptedProperty(): PropertyDecorator;
160
152
  /**
161
- * Decorator to embed another class's properties into the current entity's table.
162
- * @param type - The constructor of the class to embed.
163
- * @param options - Embedding options, like prefixing column names.
164
- * @returns A property decorator.
153
+ * Embed another class's properties into the current entity's table.
154
+ * @param type The constructor of the class to embed.
155
+ * @param options Embedding options, like prefixing column names.
165
156
  */
166
- export declare function Embedded(type: AbstractConstructor, options?: TypedOmit<NonNullable<OrmColumnReflectionData['embedded']>, 'type'>): PropertyDecorator;
157
+ export declare function EmbeddedProperty(type: AbstractConstructor, options?: TypedOmit<NonNullable<OrmColumnReflectionData['embedded']>, 'type'>): PropertyDecorator;
167
158
  export type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
168
159
  /**
169
- * Decorator to specify the database table name and optionally the schema.
170
- * @param name - The table name.
171
- * @param options - Additional table options (currently only schema).
172
- * @returns A class decorator.
160
+ * Specify the database table name and optionally the schema.
161
+ * @param name The table name.
162
+ * @param options Additional table options (currently only schema).
173
163
  */
174
164
  export declare function Table(name?: string, options?: TypedOmit<TableOptions, 'schema'>): ClassDecorator;
175
165
  /**
176
- * Decorator to specify database table options like name and schema.
177
- * @param options - Table options including name and schema.
178
- * @returns A class decorator.
166
+ * Specify database table options like name and schema.
167
+ * @param options Table options including name and schema.
179
168
  */
180
169
  export declare function Table(options?: TableOptions): ClassDecorator;
181
170
  /**
182
- * Decorator to define a foreign key relationship.
183
- * @param target - A function returning the referenced entity type.
184
- * @param columns - The columns in the current entity that form the foreign key.
185
- * @param foreignColumns - The columns in the referenced entity that the foreign key points to.
186
- * @param options - Additional foreign key options (e.g., name, naming strategy).
187
- * @template TThis - The entity type of the current entity.
188
- * @template TTarget - The entity type of the referenced entity.
189
- * @returns A property decorator.
171
+ * Define a foreign key relationship.
172
+ * @param target A function returning the referenced entity type.
173
+ * @param columns The columns in the current entity that form the foreign key.
174
+ * @param foreignColumns The columns in the referenced entity that the foreign key points to.
175
+ * @param options Additional foreign key options (e.g., name, naming strategy).
176
+ * @template TThis The entity type of the current entity.
177
+ * @template TTarget The entity type of the referenced entity.
190
178
  */
191
179
  export declare function ForeignKey<TThis extends AnyEntity, TTarget extends AnyEntity>(target: () => EntityType<TTarget>, columns: Columns<TThis>, foreignColumns: Columns<TTarget>, options?: ForeignKeyReflectionData['options']): ClassDecorator;
192
180
  /**
193
- * Decorator to define a unique constraint on a single column.
194
- * @param name - Optional name for the unique constraint.
195
- * @param options - Additional unique constraint options.
196
- * @returns A property decorator.
181
+ * Define a unique constraint on a single column.
182
+ * @param name Optional name for the unique constraint.
183
+ * @param options Additional unique constraint options.
197
184
  */
198
185
  export declare function Unique(options?: UniqueReflectionData['options']): PropertyDecorator;
199
186
  /**
200
- * Decorator to define a composite unique constraint on multiple columns.
201
- * @template T - The entity type.
202
- * @param columns - An array of property names included in the constraint.
203
- * @param options - Additional unique constraint options.
204
- * @returns A class decorator.
187
+ * Define a composite unique constraint on multiple columns.
188
+ * @template T The entity type.
189
+ * @param columns An array of property names included in the constraint.
190
+ * @param options Additional unique constraint options.
205
191
  */
206
192
  export declare function Unique<T extends AnyEntity>(columns: Columns<T>, options?: UniqueReflectionData['options']): ClassDecorator;
207
193
  /**
208
- * Decorator to define an index on a single column.
209
- * @template T - The entity type.
210
- * @param name - Optional name for the index.
211
- * @param options - Additional index options (e.g., method, uniqueness, conditions).
212
- * @returns A property decorator.
194
+ * Define an index on a single column.
195
+ * @template T The entity type.
196
+ * @param name Optional name for the index.
197
+ * @param options Additional index options (e.g., method, uniqueness, conditions).
213
198
  */
214
199
  export declare function Index<T extends Entity | EntityWithoutMetadata = any>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
215
200
  /**
216
- * Decorator to define a composite index on multiple columns.
217
- * @template T - The entity type.
218
- * @param columns - An array of property names (or tuples with direction) included in the index.
219
- * @param options - Additional index options.
220
- * @returns A class decorator.
201
+ * Define a composite index on multiple columns.
202
+ * @template T The entity type.
203
+ * @param columns An array of property names (or tuples with direction) included in the index.
204
+ * @param options Additional index options.
221
205
  */
222
206
  export declare function Index<T extends Entity | EntityWithoutMetadata = any>(columns: Columns<T>, options?: IndexReflectionData<T>['options']): ClassDecorator;
223
207
  /**
224
- * Decorator to mark a column as an expiration field. This will be used to automatically delete records when expired.
225
- * @param mode - Whether to delete soft or hard.
226
- * @returns A property decorator.
208
+ * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link EntityWithoutMetadata}.
209
+ * @param ttl Time To Live in milliseconds.
210
+ * @param mode Whether to delete soft or hard.
227
211
  */
228
- export declare function ExpiresAt(mode?: 'soft' | 'hard'): PropertyDecorator;
212
+ export declare function TimeToLive(ttl: number, mode: 'soft' | 'hard'): ClassDecorator;
213
+ /**
214
+ * Mark a column as an expiration field, automatically deleting records after the specified duration after the column value.
215
+ * @param options.after Time in milliseconds after which the record expires.
216
+ * @param options.mode Whether to delete soft or hard.
217
+ */
218
+ export declare function Expires(options?: {
219
+ after?: number;
220
+ mode?: 'soft' | 'hard';
221
+ }): PropertyDecorator;
229
222
  export {};
package/orm/decorators.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
2
2
  import { Property } from '../schema/index.js';
3
- import { filterUndefinedObjectProperties, objectEntries } from '../utils/object/object.js';
3
+ import { filterUndefinedObjectProperties, objectEntries, propertyNameOf } from '../utils/object/index.js';
4
4
  import { isArray, isString, isUndefined } from '../utils/type-guards.js';
5
5
  /**
6
6
  * Factory function to create a class decorator for ORM table configuration.
7
7
  * Merges provided data with existing ORM reflection data on the class metadata.
8
- * @param data - The ORM table reflection data to add.
9
- * @returns A class decorator.
8
+ * @param data The ORM table reflection data to add.
10
9
  */
11
10
  export function createTableDecorator(data = {}) {
12
11
  return createClassDecorator({
@@ -32,10 +31,9 @@ export function createTableDecorator(data = {}) {
32
31
  /**
33
32
  * Factory function to create a property decorator for ORM column configuration.
34
33
  * Merges provided data with existing ORM reflection data on the property metadata.
35
- * @param data - The ORM column reflection data to add.
36
- * @returns A property decorator.
34
+ * @param data The ORM column reflection data to add.
37
35
  */
38
- export function createColumnDecorator(data = {}) {
36
+ export function createColumnDecorator(data = {}, decoratorOptions) {
39
37
  return createPropertyDecorator({
40
38
  handler: (_, metadata) => {
41
39
  const reflectionData = metadata.data.tryGet('orm') ?? {};
@@ -54,60 +52,55 @@ export function createColumnDecorator(data = {}) {
54
52
  }
55
53
  metadata.data.set('orm', reflectionData, true);
56
54
  },
55
+ ...decoratorOptions,
57
56
  });
58
57
  }
59
58
  /**
60
59
  * Factory function to create a decorator applicable to both classes and properties for ORM configuration.
61
60
  * Merges provided data with existing ORM reflection data on the target's metadata.
62
- * @param data - The ORM reflection data to add.
63
- * @returns A class or property decorator.
61
+ * @param data The ORM reflection data to add.
64
62
  */
65
63
  export function createTableAndColumnDecorator(data) {
66
64
  return createDecorator({ class: true, property: true, data: { orm: data }, mergeData: true });
67
65
  }
68
66
  /**
69
- * Decorator to specify ORM column options.
70
- * @param options - Column configuration options.
71
- * @returns A property decorator.
67
+ * Specify ORM column options.
68
+ * @param options Column configuration options.
72
69
  */
73
70
  export function Column(options) {
74
71
  return createColumnDecorator({ ...options });
75
72
  }
76
73
  /**
77
- * Decorator to mark a property as the primary key column.
78
- * @returns A property decorator.
74
+ * Mark a property as the primary key column.
79
75
  */
80
- export function PrimaryKey() {
76
+ export function PrimaryKeyProperty() {
81
77
  return createColumnDecorator({ primaryKey: true });
82
78
  }
83
79
  export function References(target, targetColumn) {
84
80
  return createColumnDecorator({ references: [{ target, targetColumn }] });
85
81
  }
86
82
  /**
87
- * Decorator to define a table check constraint.
88
- * @template T - The entity type.
89
- * @param name - The name of the check constraint.
90
- * @param builder - A function to build the SQL check expression.
91
- * @returns A class decorator.
83
+ * Define a table check constraint.
84
+ * @template T The entity type.
85
+ * @param name The name of the check constraint.
86
+ * @param builder A function to build the SQL check expression.
92
87
  */
93
88
  export function Check(name, builder) {
94
89
  return createTableDecorator({ checks: [{ name, builder }] });
95
90
  }
96
91
  /**
97
- * Decorator to mark a column for encryption.
92
+ * Mark a column for encryption.
98
93
  * The underlying database type will typically be `bytea`.
99
- * @returns A property decorator.
100
94
  */
101
- export function Encrypted() {
95
+ export function EncryptedProperty() {
102
96
  return createColumnDecorator({ encrypted: true });
103
97
  }
104
98
  /**
105
- * Decorator to embed another class's properties into the current entity's table.
106
- * @param type - The constructor of the class to embed.
107
- * @param options - Embedding options, like prefixing column names.
108
- * @returns A property decorator.
99
+ * Embed another class's properties into the current entity's table.
100
+ * @param type The constructor of the class to embed.
101
+ * @param options Embedding options, like prefixing column names.
109
102
  */
110
- export function Embedded(type, options) {
103
+ export function EmbeddedProperty(type, options) {
111
104
  return createPropertyDecorator({
112
105
  include: [Property(type), createColumnDecorator({ embedded: { type, ...options } })],
113
106
  });
@@ -121,14 +114,13 @@ export function Table(nameOrOptions, optionsOrNothing) {
121
114
  return createTableDecorator(data);
122
115
  }
123
116
  /**
124
- * Decorator to define a foreign key relationship.
125
- * @param target - A function returning the referenced entity type.
126
- * @param columns - The columns in the current entity that form the foreign key.
127
- * @param foreignColumns - The columns in the referenced entity that the foreign key points to.
128
- * @param options - Additional foreign key options (e.g., name, naming strategy).
129
- * @template TThis - The entity type of the current entity.
130
- * @template TTarget - The entity type of the referenced entity.
131
- * @returns A property decorator.
117
+ * Define a foreign key relationship.
118
+ * @param target A function returning the referenced entity type.
119
+ * @param columns The columns in the current entity that form the foreign key.
120
+ * @param foreignColumns The columns in the referenced entity that the foreign key points to.
121
+ * @param options Additional foreign key options (e.g., name, naming strategy).
122
+ * @template TThis The entity type of the current entity.
123
+ * @template TTarget The entity type of the referenced entity.
132
124
  */
133
125
  export function ForeignKey(target, columns, foreignColumns, options) {
134
126
  return createTableDecorator({ foreignKeys: [{ target, columns, foreignColumns, options }] });
@@ -146,10 +138,20 @@ export function Index(columnsOrOptions, options) {
146
138
  return createColumnDecorator({ index: { options: columnsOrOptions } });
147
139
  }
148
140
  /**
149
- * Decorator to mark a column as an expiration field. This will be used to automatically delete records when expired.
150
- * @param mode - Whether to delete soft or hard.
151
- * @returns A property decorator.
141
+ * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link EntityWithoutMetadata}.
142
+ * @param ttl Time To Live in milliseconds.
143
+ * @param mode Whether to delete soft or hard.
152
144
  */
153
- export function ExpiresAt(mode = 'soft') {
154
- return createColumnDecorator({ expirationField: { mode } });
145
+ export function TimeToLive(ttl, mode) {
146
+ return createClassDecorator({
147
+ handler: (data) => Expires({ after: ttl, mode })(data.prototype, propertyNameOf((entity) => entity.metadata.createTimestamp)),
148
+ });
149
+ }
150
+ /**
151
+ * Mark a column as an expiration field, automatically deleting records after the specified duration after the column value.
152
+ * @param options.after Time in milliseconds after which the record expires.
153
+ * @param options.mode Whether to delete soft or hard.
154
+ */
155
+ export function Expires(options) {
156
+ return createColumnDecorator({ expirationField: { after: options?.after ?? 0, mode: options?.mode ?? 'soft' } });
155
157
  }
package/orm/entity.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Type } from '../types/index.js';
2
- import { Embedded, type HasDefault, type IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
2
+ import type { Embedded, HasDefault, IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
3
3
  /**
4
4
  * Represents the type (constructor) of an entity, potentially holding an entity name.
5
5
  * @template T - The entity class type.
@@ -40,3 +40,9 @@ export declare abstract class Entity {
40
40
  export declare abstract class EntityWithoutMetadata {
41
41
  id: IsPrimaryKey<HasDefault<Uuid>>;
42
42
  }
43
+ export declare abstract class TenantEntity extends Entity {
44
+ tenantId: Uuid;
45
+ }
46
+ export declare abstract class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
47
+ tenantId: Uuid;
48
+ }
package/orm/entity.js CHANGED
@@ -12,8 +12,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
12
12
  * Defines base entity classes and related types for the ORM.
13
13
  */
14
14
  import { Defaulted, Integer } from '../schema/index.js';
15
- import { PrimaryKey } from './decorators.js';
16
- import { Embedded, Json, Timestamp, Uuid } from './types.js';
15
+ import { EmbeddedProperty, PrimaryKeyProperty } from './decorators.js';
16
+ import { JsonProperty, TimestampProperty, UuidProperty } from './schemas/index.js';
17
17
  /**
18
18
  * Base class for extensible metadata attributes associated with an entity.
19
19
  * Allows storing arbitrary key-value pairs.
@@ -21,7 +21,7 @@ import { Embedded, Json, Timestamp, Uuid } from './types.js';
21
21
  let EntityMetadataAttributes = class EntityMetadataAttributes {
22
22
  };
23
23
  EntityMetadataAttributes = __decorate([
24
- Json()
24
+ JsonProperty()
25
25
  ], EntityMetadataAttributes);
26
26
  export { EntityMetadataAttributes };
27
27
  /**
@@ -39,15 +39,15 @@ __decorate([
39
39
  __metadata("design:type", Number)
40
40
  ], EntityMetadata.prototype, "revision", void 0);
41
41
  __decorate([
42
- Timestamp(),
42
+ TimestampProperty(),
43
43
  __metadata("design:type", Number)
44
44
  ], EntityMetadata.prototype, "revisionTimestamp", void 0);
45
45
  __decorate([
46
- Timestamp(),
46
+ TimestampProperty(),
47
47
  __metadata("design:type", Number)
48
48
  ], EntityMetadata.prototype, "createTimestamp", void 0);
49
49
  __decorate([
50
- Timestamp({ nullable: true }),
50
+ TimestampProperty({ nullable: true }),
51
51
  __metadata("design:type", Object)
52
52
  ], EntityMetadata.prototype, "deleteTimestamp", void 0);
53
53
  __decorate([
@@ -63,12 +63,12 @@ export class Entity {
63
63
  metadata;
64
64
  }
65
65
  __decorate([
66
- PrimaryKey(),
67
- Uuid({ defaultRandom: true }),
66
+ PrimaryKeyProperty(),
67
+ UuidProperty({ defaultRandom: true }),
68
68
  __metadata("design:type", Object)
69
69
  ], Entity.prototype, "id", void 0);
70
70
  __decorate([
71
- Embedded(EntityMetadata, { prefix: null }),
71
+ EmbeddedProperty(EntityMetadata, { prefix: null }),
72
72
  __metadata("design:type", Object)
73
73
  ], Entity.prototype, "metadata", void 0);
74
74
  /**
@@ -79,7 +79,21 @@ export class EntityWithoutMetadata {
79
79
  id;
80
80
  }
81
81
  __decorate([
82
- PrimaryKey(),
83
- Uuid({ defaultRandom: true }),
82
+ PrimaryKeyProperty(),
83
+ UuidProperty({ defaultRandom: true }),
84
84
  __metadata("design:type", Object)
85
85
  ], EntityWithoutMetadata.prototype, "id", void 0);
86
+ export class TenantEntity extends Entity {
87
+ tenantId;
88
+ }
89
+ __decorate([
90
+ UuidProperty(),
91
+ __metadata("design:type", String)
92
+ ], TenantEntity.prototype, "tenantId", void 0);
93
+ export class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
94
+ tenantId;
95
+ }
96
+ __decorate([
97
+ UuidProperty(),
98
+ __metadata("design:type", String)
99
+ ], TenantEntityWithoutMetadata.prototype, "tenantId", void 0);
package/orm/index.d.ts CHANGED
@@ -3,10 +3,11 @@
3
3
  *
4
4
  * @module ORM
5
5
  */
6
- export * from './data-types/index.js';
6
+ export * from './decorators.js';
7
7
  export * from './entity.js';
8
8
  export * from './query.js';
9
9
  export * from './repository.types.js';
10
+ export * from './schemas/index.js';
10
11
  export * from './sqls.js';
11
12
  export * from './types.js';
12
13
  export * from './utils.js';