ts-prorm-orm 2.0.0 → 2.1.0

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 (83) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/dist/compliance/data-classifier.d.ts +6 -0
  3. package/dist/compliance/data-classifier.js +6 -0
  4. package/dist/compliance/data-lineage.d.ts +4 -0
  5. package/dist/compliance/data-lineage.js +4 -0
  6. package/dist/compliance/data-masker.d.ts +4 -0
  7. package/dist/compliance/data-masker.js +4 -0
  8. package/dist/compliance/index.d.ts +2 -0
  9. package/dist/compliance/index.js +2 -0
  10. package/dist/compliance/pseudonymization.d.ts +4 -0
  11. package/dist/compliance/pseudonymization.js +4 -0
  12. package/dist/compliance/query-firewall.d.ts +9 -9
  13. package/dist/compliance/query-firewall.js +9 -9
  14. package/dist/compliance/rate-limiter.d.ts +4 -0
  15. package/dist/compliance/rate-limiter.js +4 -0
  16. package/dist/compliance/row-level-security.d.ts +2 -0
  17. package/dist/compliance/row-level-security.js +2 -0
  18. package/dist/compliance/security-decorator.d.ts +8 -0
  19. package/dist/compliance/security-decorator.js +8 -0
  20. package/dist/compliance/session-isolation.d.ts +4 -0
  21. package/dist/compliance/session-isolation.js +4 -0
  22. package/dist/compliance/worm-storage.d.ts +4 -0
  23. package/dist/compliance/worm-storage.js +4 -0
  24. package/dist/decorators/audit.d.ts +3 -1
  25. package/dist/decorators/audit.js +3 -1
  26. package/dist/decorators/check.d.ts +15 -15
  27. package/dist/decorators/check.js +15 -15
  28. package/dist/decorators/collate.d.ts +16 -0
  29. package/dist/decorators/collate.js +16 -0
  30. package/dist/decorators/comment.d.ts +3 -1
  31. package/dist/decorators/comment.js +3 -1
  32. package/dist/decorators/database-settings.d.ts +6 -0
  33. package/dist/decorators/database-settings.js +6 -0
  34. package/dist/decorators/default.d.ts +2 -0
  35. package/dist/decorators/default.js +2 -0
  36. package/dist/decorators/encryption.d.ts +7 -1
  37. package/dist/decorators/encryption.js +7 -1
  38. package/dist/decorators/engine.d.ts +4 -0
  39. package/dist/decorators/engine.js +4 -0
  40. package/dist/decorators/fk-constraints.d.ts +32 -32
  41. package/dist/decorators/fk-constraints.js +32 -32
  42. package/dist/decorators/foreign-table.d.ts +1 -1
  43. package/dist/decorators/generated.d.ts +8 -0
  44. package/dist/decorators/generated.js +8 -0
  45. package/dist/decorators/hstore.d.ts +6 -0
  46. package/dist/decorators/hstore.js +6 -0
  47. package/dist/decorators/json-column.d.ts +2 -0
  48. package/dist/decorators/json-column.js +2 -0
  49. package/dist/decorators/jsonb.d.ts +6 -0
  50. package/dist/decorators/jsonb.js +6 -0
  51. package/dist/decorators/permissions.d.ts +12 -0
  52. package/dist/decorators/permissions.js +12 -0
  53. package/dist/decorators/procedure.d.ts +4 -2
  54. package/dist/decorators/procedure.js +4 -2
  55. package/dist/decorators/query-options.d.ts +24 -0
  56. package/dist/decorators/query-options.js +24 -0
  57. package/dist/decorators/range.d.ts +8 -0
  58. package/dist/decorators/range.js +8 -0
  59. package/dist/decorators/set-column.d.ts +2 -0
  60. package/dist/decorators/set-column.js +2 -0
  61. package/dist/decorators/spatial.d.ts +2 -0
  62. package/dist/decorators/spatial.js +2 -0
  63. package/dist/decorators/storage.d.ts +24 -0
  64. package/dist/decorators/storage.js +24 -0
  65. package/dist/decorators/timezone.d.ts +7 -7
  66. package/dist/decorators/timezone.js +7 -7
  67. package/dist/decorators/trigger.d.ts +3 -1
  68. package/dist/decorators/trigger.js +3 -1
  69. package/dist/decorators/uuid.d.ts +6 -0
  70. package/dist/decorators/uuid.js +6 -0
  71. package/dist/decorators/view.d.ts +7 -1
  72. package/dist/decorators/view.js +7 -1
  73. package/dist/dialects/dialect.d.ts +112 -0
  74. package/dist/external-fields/decorator.d.ts +2 -0
  75. package/dist/external-fields/decorator.js +2 -0
  76. package/dist/models/associations.d.ts +38 -0
  77. package/dist/models/associations.js +16 -0
  78. package/dist/models/decorators.d.ts +16 -16
  79. package/dist/models/decorators.js +21 -19
  80. package/dist/schema-objects.d.ts +42 -0
  81. package/dist/schema-objects.js +28 -0
  82. package/dist/types/index.d.ts +334 -0
  83. package/package.json +8 -4
@@ -215,55 +215,55 @@ export declare function AllowNull(allowNull?: boolean): PropertyDecorator;
215
215
  * Mark attribute as primary key
216
216
  *
217
217
  * @example
218
- * @Attribute(DataTypes.INTEGER)
219
- * @PrimaryKey
218
+ * `@Attribute`(DataTypes.INTEGER)
219
+ * `@PrimaryKey`
220
220
  */
221
221
  export declare function PrimaryKey(): PropertyDecorator;
222
222
  /**
223
223
  * Enable auto-increment on attribute
224
224
  *
225
225
  * @example
226
- * @Attribute(DataTypes.INTEGER)
227
- * @AutoIncrement
226
+ * `@Attribute`(DataTypes.INTEGER)
227
+ * `@AutoIncrement`
228
228
  */
229
229
  export declare function AutoIncrement(): PropertyDecorator;
230
230
  /**
231
231
  * Add NOT NULL constraint
232
232
  *
233
233
  * @example
234
- * @Attribute(DataTypes.STRING)
235
- * @NotNull
234
+ * `@Attribute`(DataTypes.STRING)
235
+ * `@NotNull`
236
236
  */
237
237
  export declare function NotNull(): PropertyDecorator;
238
238
  /**
239
239
  * Set default value
240
240
  *
241
241
  * @example
242
- * @Default('value')
243
- * @Default(DataTypes.NOW)
244
- * @Default(() => Math.random())
242
+ * `@Default`('value')
243
+ * `@Default`(DataTypes.NOW)
244
+ * `@Default`(() => Math.random())
245
245
  */
246
246
  export declare function Default(value: any): PropertyDecorator;
247
247
  /**
248
248
  * Add UNIQUE constraint
249
249
  *
250
250
  * @example
251
- * @Unique
252
- * @Unique('unique_name')
251
+ * `@Unique`
252
+ * `@Unique`('unique_name')
253
253
  */
254
254
  export declare function Unique(nameOrOptions?: string | boolean): PropertyDecorator;
255
255
  /**
256
256
  * Add comment to column
257
257
  *
258
258
  * @example
259
- * @Comment('User email address')
259
+ * `@Comment`('User email address')
260
260
  */
261
261
  export declare function Comment(text: string): PropertyDecorator;
262
262
  /**
263
263
  * Define a hasOne association
264
264
  *
265
265
  * @example
266
- * @HasOne(() => Profile)
266
+ * `@HasOne`(() => Profile)
267
267
  * declare profile: HasOne<Profile>;
268
268
  */
269
269
  export declare function HasOne(targetFn: () => any, options?: HasOneOptions): PropertyDecorator;
@@ -271,7 +271,7 @@ export declare function HasOne(targetFn: () => any, options?: HasOneOptions): Pr
271
271
  * Define a hasMany association
272
272
  *
273
273
  * @example
274
- * @HasMany(() => Post)
274
+ * `@HasMany`(() => Post)
275
275
  * declare posts: HasMany<Post>;
276
276
  */
277
277
  export declare function HasMany(targetFn: () => any, options?: HasManyOptions): PropertyDecorator;
@@ -279,7 +279,7 @@ export declare function HasMany(targetFn: () => any, options?: HasManyOptions):
279
279
  * Define a belongsTo association
280
280
  *
281
281
  * @example
282
- * @BelongsTo(() => User)
282
+ * `@BelongsTo`(() => User)
283
283
  * declare user: BelongsTo<User>;
284
284
  */
285
285
  export declare function BelongsTo(targetFn: () => any, options?: BelongsToOptions): PropertyDecorator;
@@ -287,7 +287,7 @@ export declare function BelongsTo(targetFn: () => any, options?: BelongsToOption
287
287
  * Define a belongsToMany association
288
288
  *
289
289
  * @example
290
- * @BelongsToMany(() => Role, { through: UserRole })
290
+ * `@BelongsToMany`(() => Role, { through: UserRole })
291
291
  * declare roles: BelongsToMany<Role>;
292
292
  */
293
293
  export declare function BelongsToMany(targetFn: () => any, options: BelongsToManyOptions): PropertyDecorator;
@@ -71,7 +71,7 @@ const associationMetadata = new Map();
71
71
  * Define model options (use on model class)
72
72
  *
73
73
  * @example
74
- * @Table({ tableName: 'users', timestamps: true })
74
+ * `@Table`({ tableName: 'users', timestamps: true })
75
75
  */
76
76
  /** Classes marked with `@AbstractModel`, by constructor name. */
77
77
  const abstractModels = new Set();
@@ -181,8 +181,8 @@ function Table(options = {}) {
181
181
  * Define a model attribute/column
182
182
  *
183
183
  * @example
184
- * @Attribute(DataTypes.STRING)
185
- * @Attribute(DataTypes.INTEGER)
184
+ * `@Attribute`(DataTypes.STRING)
185
+ * `@Attribute`(DataTypes.INTEGER)
186
186
  */
187
187
  /**
188
188
  * Get (creating if needed) the attribute entry for a decorated property.
@@ -193,10 +193,12 @@ function Table(options = {}) {
193
193
  * yet, and `@Column` then replaced whatever they had set - so the documented
194
194
  * ordering
195
195
  *
196
+ * ```ts
196
197
  * @Column(DataTypes.INTEGER())
197
198
  * @PrimaryKey()
198
199
  * @AutoIncrement()
199
200
  * declare id: number;
201
+ * ```
200
202
  *
201
203
  * produced a plain nullable INTEGER with no primary key and no auto-increment.
202
204
  * Every decorator now goes through this helper and merges, making the stack
@@ -249,8 +251,8 @@ function AllowNull(allowNull = true) {
249
251
  * Mark attribute as primary key
250
252
  *
251
253
  * @example
252
- * @Attribute(DataTypes.INTEGER)
253
- * @PrimaryKey
254
+ * `@Attribute`(DataTypes.INTEGER)
255
+ * `@PrimaryKey`
254
256
  */
255
257
  function PrimaryKey() {
256
258
  return function (target, propertyKey) {
@@ -265,8 +267,8 @@ function PrimaryKey() {
265
267
  * Enable auto-increment on attribute
266
268
  *
267
269
  * @example
268
- * @Attribute(DataTypes.INTEGER)
269
- * @AutoIncrement
270
+ * `@Attribute`(DataTypes.INTEGER)
271
+ * `@AutoIncrement`
270
272
  */
271
273
  function AutoIncrement() {
272
274
  return function (target, propertyKey) {
@@ -279,8 +281,8 @@ function AutoIncrement() {
279
281
  * Add NOT NULL constraint
280
282
  *
281
283
  * @example
282
- * @Attribute(DataTypes.STRING)
283
- * @NotNull
284
+ * `@Attribute`(DataTypes.STRING)
285
+ * `@NotNull`
284
286
  */
285
287
  function NotNull() {
286
288
  return function (target, propertyKey) {
@@ -298,9 +300,9 @@ function NotNull() {
298
300
  * Set default value
299
301
  *
300
302
  * @example
301
- * @Default('value')
302
- * @Default(DataTypes.NOW)
303
- * @Default(() => Math.random())
303
+ * `@Default`('value')
304
+ * `@Default`(DataTypes.NOW)
305
+ * `@Default`(() => Math.random())
304
306
  */
305
307
  function Default(value) {
306
308
  return function (target, propertyKey) {
@@ -314,8 +316,8 @@ function Default(value) {
314
316
  * Add UNIQUE constraint
315
317
  *
316
318
  * @example
317
- * @Unique
318
- * @Unique('unique_name')
319
+ * `@Unique`
320
+ * `@Unique`('unique_name')
319
321
  */
320
322
  function Unique(nameOrOptions) {
321
323
  return function (target, propertyKey) {
@@ -329,7 +331,7 @@ function Unique(nameOrOptions) {
329
331
  * Add comment to column
330
332
  *
331
333
  * @example
332
- * @Comment('User email address')
334
+ * `@Comment`('User email address')
333
335
  */
334
336
  function Comment(text) {
335
337
  return function (target, propertyKey) {
@@ -344,7 +346,7 @@ function Comment(text) {
344
346
  * Define a hasOne association
345
347
  *
346
348
  * @example
347
- * @HasOne(() => Profile)
349
+ * `@HasOne`(() => Profile)
348
350
  * declare profile: HasOne<Profile>;
349
351
  */
350
352
  function HasOne(targetFn, options = {}) {
@@ -373,7 +375,7 @@ function HasOne(targetFn, options = {}) {
373
375
  * Define a hasMany association
374
376
  *
375
377
  * @example
376
- * @HasMany(() => Post)
378
+ * `@HasMany`(() => Post)
377
379
  * declare posts: HasMany<Post>;
378
380
  */
379
381
  function HasMany(targetFn, options = {}) {
@@ -402,7 +404,7 @@ function HasMany(targetFn, options = {}) {
402
404
  * Define a belongsTo association
403
405
  *
404
406
  * @example
405
- * @BelongsTo(() => User)
407
+ * `@BelongsTo`(() => User)
406
408
  * declare user: BelongsTo<User>;
407
409
  */
408
410
  function BelongsTo(targetFn, options = {}) {
@@ -431,7 +433,7 @@ function BelongsTo(targetFn, options = {}) {
431
433
  * Define a belongsToMany association
432
434
  *
433
435
  * @example
434
- * @BelongsToMany(() => Role, { through: UserRole })
436
+ * `@BelongsToMany`(() => Role, { through: UserRole })
435
437
  * declare roles: BelongsToMany<Role>;
436
438
  */
437
439
  function BelongsToMany(targetFn, options) {
@@ -16,6 +16,9 @@ export type SqlDialectName = 'mysql' | 'mariadb' | 'postgres' | 'cockroachdb' |
16
16
  export declare class UnsupportedSchemaObjectError extends Error {
17
17
  constructor(object: string, dialect: string, hint?: string);
18
18
  }
19
+ /**
20
+ * A named sequence: its start, increment, bounds and caching.
21
+ */
19
22
  export interface SequenceOptions {
20
23
  /** Value the sequence starts at (default 1) */
21
24
  start?: number;
@@ -32,8 +35,18 @@ export interface SequenceOptions {
32
35
  /** Emit IF NOT EXISTS where supported */
33
36
  ifNotExists?: boolean;
34
37
  }
38
+ /**
39
+ * Builds `CREATE SEQUENCE` for the dialect.
40
+ */
35
41
  export declare function buildCreateSequenceSQL(name: string, options: SequenceOptions, dialect: SqlDialectName, quoteId: (id: string) => string): string;
42
+ /**
43
+ * Builds `DROP SEQUENCE` for the dialect.
44
+ */
36
45
  export declare function buildDropSequenceSQL(name: string, dialect: SqlDialectName, quoteId: (id: string) => string, ifExists?: boolean): string;
46
+ /**
47
+ * A row-level security policy: who it applies to, which command, and the
48
+ * expressions that decide visibility (`using`) and writability (`withCheck`).
49
+ */
37
50
  export interface PolicyOptions {
38
51
  /** Table the policy applies to */
39
52
  table: string;
@@ -48,9 +61,23 @@ export interface PolicyOptions {
48
61
  /** Roles the policy applies to */
49
62
  to?: string[];
50
63
  }
64
+ /**
65
+ * Builds the statement that turns row-level security on for a table. Until
66
+ * this runs, policies are defined but not enforced.
67
+ */
51
68
  export declare function buildEnableRowLevelSecuritySQL(table: string, dialect: SqlDialectName, quoteTable: (t: string) => string, enable?: boolean): string;
69
+ /**
70
+ * Builds `CREATE POLICY` for a row-level security rule.
71
+ */
52
72
  export declare function buildCreatePolicySQL(options: PolicyOptions, dialect: SqlDialectName, quoteId: (id: string) => string, quoteTable: (t: string) => string): string;
73
+ /**
74
+ * Builds `DROP POLICY`.
75
+ */
53
76
  export declare function buildDropPolicySQL(name: string, table: string, dialect: SqlDialectName, quoteId: (id: string) => string, quoteTable: (t: string) => string, ifExists?: boolean): string;
77
+ /**
78
+ * A full-text index: the columns it covers, the language configuration, and
79
+ * any per-column weighting the engine supports.
80
+ */
54
81
  export interface FullTextIndexOptions {
55
82
  /** Index name */
56
83
  name: string;
@@ -61,7 +88,14 @@ export interface FullTextIndexOptions {
61
88
  /** Text search configuration (PostgreSQL), e.g. 'english' */
62
89
  language?: string;
63
90
  }
91
+ /**
92
+ * Builds the engine's full-text index statement — a GIN index over a tsvector
93
+ * on PostgreSQL, `FULLTEXT` on MySQL, an FTS5 virtual table on SQLite.
94
+ */
64
95
  export declare function buildCreateFullTextIndexSQL(options: FullTextIndexOptions, dialect: SqlDialectName, quoteId: (id: string) => string, quoteTable: (t: string) => string): string;
96
+ /**
97
+ * A trigger: when it fires, on which events, and the body it runs.
98
+ */
65
99
  export interface TriggerDefinition {
66
100
  name: string;
67
101
  table: string;
@@ -74,5 +108,13 @@ export interface TriggerDefinition {
74
108
  /** Condition guarding the trigger */
75
109
  when?: string;
76
110
  }
111
+ /**
112
+ * Builds the statements a trigger needs. Some engines want a separate
113
+ * function or procedure before the trigger itself, so this returns a list
114
+ * rather than one statement.
115
+ */
77
116
  export declare function buildCreateTriggerStatements(trigger: TriggerDefinition, dialect: SqlDialectName, quoteId: (id: string) => string, quoteTable: (t: string) => string): string[];
117
+ /**
118
+ * Builds `DROP TRIGGER`.
119
+ */
78
120
  export declare function buildDropTriggerSQL(name: string, table: string, dialect: SqlDialectName, quoteId: (id: string) => string, quoteTable: (t: string) => string, ifExists?: boolean): string;
@@ -54,6 +54,9 @@ class UnsupportedSchemaObjectError extends Error {
54
54
  }
55
55
  }
56
56
  exports.UnsupportedSchemaObjectError = UnsupportedSchemaObjectError;
57
+ /**
58
+ * Builds `CREATE SEQUENCE` for the dialect.
59
+ */
57
60
  function buildCreateSequenceSQL(name, options, dialect, quoteId) {
58
61
  if (isSqliteFamily(dialect)) {
59
62
  throw new UnsupportedSchemaObjectError('CREATE SEQUENCE', dialect, 'SQLite has no sequences - use an INTEGER PRIMARY KEY AUTOINCREMENT column instead.');
@@ -83,6 +86,9 @@ function buildCreateSequenceSQL(name, options, dialect, quoteId) {
83
86
  parts.push('CYCLE');
84
87
  return parts.join(' ');
85
88
  }
89
+ /**
90
+ * Builds `DROP SEQUENCE` for the dialect.
91
+ */
86
92
  function buildDropSequenceSQL(name, dialect, quoteId, ifExists = true) {
87
93
  if (isSqliteFamily(dialect) || dialect === 'mysql') {
88
94
  throw new UnsupportedSchemaObjectError('DROP SEQUENCE', dialect);
@@ -91,6 +97,10 @@ function buildDropSequenceSQL(name, dialect, quoteId, ifExists = true) {
91
97
  const guard = ifExists && dialect !== 'oracle' ? 'IF EXISTS ' : '';
92
98
  return `DROP SEQUENCE ${guard}${quoteId(name)}`;
93
99
  }
100
+ /**
101
+ * Builds the statement that turns row-level security on for a table. Until
102
+ * this runs, policies are defined but not enforced.
103
+ */
94
104
  function buildEnableRowLevelSecuritySQL(table, dialect, quoteTable, enable = true) {
95
105
  if (!isPostgresFamily(dialect)) {
96
106
  throw new UnsupportedSchemaObjectError('Row-level security', dialect, dialect === 'mssql'
@@ -99,6 +109,9 @@ function buildEnableRowLevelSecuritySQL(table, dialect, quoteTable, enable = tru
99
109
  }
100
110
  return `ALTER TABLE ${quoteTable(table)} ${enable ? 'ENABLE' : 'DISABLE'} ROW LEVEL SECURITY`;
101
111
  }
112
+ /**
113
+ * Builds `CREATE POLICY` for a row-level security rule.
114
+ */
102
115
  function buildCreatePolicySQL(options, dialect, quoteId, quoteTable) {
103
116
  if (!isPostgresFamily(dialect)) {
104
117
  throw new UnsupportedSchemaObjectError('CREATE POLICY', dialect);
@@ -114,12 +127,19 @@ function buildCreatePolicySQL(options, dialect, quoteId, quoteTable) {
114
127
  sql += ` WITH CHECK (${options.withCheck})`;
115
128
  return sql;
116
129
  }
130
+ /**
131
+ * Builds `DROP POLICY`.
132
+ */
117
133
  function buildDropPolicySQL(name, table, dialect, quoteId, quoteTable, ifExists = true) {
118
134
  if (!isPostgresFamily(dialect)) {
119
135
  throw new UnsupportedSchemaObjectError('DROP POLICY', dialect);
120
136
  }
121
137
  return `DROP POLICY ${ifExists ? 'IF EXISTS ' : ''}${quoteId(name)} ON ${quoteTable(table)}`;
122
138
  }
139
+ /**
140
+ * Builds the engine's full-text index statement — a GIN index over a tsvector
141
+ * on PostgreSQL, `FULLTEXT` on MySQL, an FTS5 virtual table on SQLite.
142
+ */
123
143
  function buildCreateFullTextIndexSQL(options, dialect, quoteId, quoteTable) {
124
144
  const { name, table, columns, language = 'english' } = options;
125
145
  if (!columns.length) {
@@ -145,6 +165,11 @@ function buildCreateFullTextIndexSQL(options, dialect, quoteId, quoteTable) {
145
165
  }
146
166
  throw new UnsupportedSchemaObjectError('Full-text index', dialect);
147
167
  }
168
+ /**
169
+ * Builds the statements a trigger needs. Some engines want a separate
170
+ * function or procedure before the trigger itself, so this returns a list
171
+ * rather than one statement.
172
+ */
148
173
  function buildCreateTriggerStatements(trigger, dialect, quoteId, quoteTable) {
149
174
  const { name, table, timing, event, body, forEach = 'ROW', when } = trigger;
150
175
  if (isPostgresFamily(dialect)) {
@@ -188,6 +213,9 @@ function buildCreateTriggerStatements(trigger, dialect, quoteId, quoteTable) {
188
213
  }
189
214
  throw new UnsupportedSchemaObjectError('CREATE TRIGGER', dialect);
190
215
  }
216
+ /**
217
+ * Builds `DROP TRIGGER`.
218
+ */
191
219
  function buildDropTriggerSQL(name, table, dialect, quoteId, quoteTable, ifExists = true) {
192
220
  const guard = ifExists ? 'IF EXISTS ' : '';
193
221
  if (isMysqlFamily(dialect) || isSqliteFamily(dialect)) {