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.
- package/CHANGELOG.md +132 -0
- package/dist/compliance/data-classifier.d.ts +6 -0
- package/dist/compliance/data-classifier.js +6 -0
- package/dist/compliance/data-lineage.d.ts +4 -0
- package/dist/compliance/data-lineage.js +4 -0
- package/dist/compliance/data-masker.d.ts +4 -0
- package/dist/compliance/data-masker.js +4 -0
- package/dist/compliance/index.d.ts +2 -0
- package/dist/compliance/index.js +2 -0
- package/dist/compliance/pseudonymization.d.ts +4 -0
- package/dist/compliance/pseudonymization.js +4 -0
- package/dist/compliance/query-firewall.d.ts +9 -9
- package/dist/compliance/query-firewall.js +9 -9
- package/dist/compliance/rate-limiter.d.ts +4 -0
- package/dist/compliance/rate-limiter.js +4 -0
- package/dist/compliance/row-level-security.d.ts +2 -0
- package/dist/compliance/row-level-security.js +2 -0
- package/dist/compliance/security-decorator.d.ts +8 -0
- package/dist/compliance/security-decorator.js +8 -0
- package/dist/compliance/session-isolation.d.ts +4 -0
- package/dist/compliance/session-isolation.js +4 -0
- package/dist/compliance/worm-storage.d.ts +4 -0
- package/dist/compliance/worm-storage.js +4 -0
- package/dist/decorators/audit.d.ts +3 -1
- package/dist/decorators/audit.js +3 -1
- package/dist/decorators/check.d.ts +15 -15
- package/dist/decorators/check.js +15 -15
- package/dist/decorators/collate.d.ts +16 -0
- package/dist/decorators/collate.js +16 -0
- package/dist/decorators/comment.d.ts +3 -1
- package/dist/decorators/comment.js +3 -1
- package/dist/decorators/database-settings.d.ts +6 -0
- package/dist/decorators/database-settings.js +6 -0
- package/dist/decorators/default.d.ts +2 -0
- package/dist/decorators/default.js +2 -0
- package/dist/decorators/encryption.d.ts +7 -1
- package/dist/decorators/encryption.js +7 -1
- package/dist/decorators/engine.d.ts +4 -0
- package/dist/decorators/engine.js +4 -0
- package/dist/decorators/fk-constraints.d.ts +32 -32
- package/dist/decorators/fk-constraints.js +32 -32
- package/dist/decorators/foreign-table.d.ts +1 -1
- package/dist/decorators/generated.d.ts +8 -0
- package/dist/decorators/generated.js +8 -0
- package/dist/decorators/hstore.d.ts +6 -0
- package/dist/decorators/hstore.js +6 -0
- package/dist/decorators/json-column.d.ts +2 -0
- package/dist/decorators/json-column.js +2 -0
- package/dist/decorators/jsonb.d.ts +6 -0
- package/dist/decorators/jsonb.js +6 -0
- package/dist/decorators/permissions.d.ts +12 -0
- package/dist/decorators/permissions.js +12 -0
- package/dist/decorators/procedure.d.ts +4 -2
- package/dist/decorators/procedure.js +4 -2
- package/dist/decorators/query-options.d.ts +24 -0
- package/dist/decorators/query-options.js +24 -0
- package/dist/decorators/range.d.ts +8 -0
- package/dist/decorators/range.js +8 -0
- package/dist/decorators/set-column.d.ts +2 -0
- package/dist/decorators/set-column.js +2 -0
- package/dist/decorators/spatial.d.ts +2 -0
- package/dist/decorators/spatial.js +2 -0
- package/dist/decorators/storage.d.ts +24 -0
- package/dist/decorators/storage.js +24 -0
- package/dist/decorators/timezone.d.ts +7 -7
- package/dist/decorators/timezone.js +7 -7
- package/dist/decorators/trigger.d.ts +3 -1
- package/dist/decorators/trigger.js +3 -1
- package/dist/decorators/uuid.d.ts +6 -0
- package/dist/decorators/uuid.js +6 -0
- package/dist/decorators/view.d.ts +7 -1
- package/dist/decorators/view.js +7 -1
- package/dist/dialects/dialect.d.ts +112 -0
- package/dist/external-fields/decorator.d.ts +2 -0
- package/dist/external-fields/decorator.js +2 -0
- package/dist/models/associations.d.ts +38 -0
- package/dist/models/associations.js +16 -0
- package/dist/models/decorators.d.ts +16 -16
- package/dist/models/decorators.js +21 -19
- package/dist/schema-objects.d.ts +42 -0
- package/dist/schema-objects.js +28 -0
- package/dist/types/index.d.ts +334 -0
- package/package.json +8 -4
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
12
|
*
|
|
13
|
+
* ```ts
|
|
13
14
|
* // Disable FK checks for entire model
|
|
14
15
|
* @ForeignKeyChecks({ enabled: false })
|
|
15
16
|
* class ImportData extends Model {}
|
|
@@ -30,6 +31,7 @@
|
|
|
30
31
|
* // Bulk import without FK validation
|
|
31
32
|
* await prorm.setForeignKeyChecks(true);
|
|
32
33
|
* });
|
|
34
|
+
* ```
|
|
33
35
|
*/
|
|
34
36
|
import 'reflect-metadata';
|
|
35
37
|
/**
|
|
@@ -106,10 +108,12 @@ export interface ModelDatabaseSettings {
|
|
|
106
108
|
*
|
|
107
109
|
* Usage:
|
|
108
110
|
*
|
|
111
|
+
* ```ts
|
|
109
112
|
* @ForeignKeyChecks({ enabled: false })
|
|
110
113
|
* class ImportData extends Model {
|
|
111
114
|
* // fields...
|
|
112
115
|
* }
|
|
116
|
+
* ```
|
|
113
117
|
*
|
|
114
118
|
* @param options - Foreign key check options
|
|
115
119
|
*/
|
|
@@ -122,12 +126,14 @@ export declare function ForeignKeyChecks(options?: ForeignKeyChecksOptions): Cla
|
|
|
122
126
|
*
|
|
123
127
|
* Usage:
|
|
124
128
|
*
|
|
129
|
+
* ```ts
|
|
125
130
|
* @DatabaseSetting('unique_checks', false)
|
|
126
131
|
* @DatabaseSetting('autocommit', false)
|
|
127
132
|
* @DatabaseSetting('sql_mode', 'STRICT_TRANS_TABLES')
|
|
128
133
|
* class ImportData extends Model {
|
|
129
134
|
* // fields...
|
|
130
135
|
* }
|
|
136
|
+
* ```
|
|
131
137
|
*
|
|
132
138
|
* @param name - The setting name
|
|
133
139
|
* @param value - The value to set
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Usage:
|
|
13
13
|
*
|
|
14
|
+
* ```ts
|
|
14
15
|
* // Disable FK checks for entire model
|
|
15
16
|
* @ForeignKeyChecks({ enabled: false })
|
|
16
17
|
* class ImportData extends Model {}
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
* // Bulk import without FK validation
|
|
32
33
|
* await prorm.setForeignKeyChecks(true);
|
|
33
34
|
* });
|
|
35
|
+
* ```
|
|
34
36
|
*/
|
|
35
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
38
|
exports.ForeignKeyChecks = ForeignKeyChecks;
|
|
@@ -54,10 +56,12 @@ const DATABASE_SETTINGS_KEY = Symbol('prorm:databaseSettings');
|
|
|
54
56
|
*
|
|
55
57
|
* Usage:
|
|
56
58
|
*
|
|
59
|
+
* ```ts
|
|
57
60
|
* @ForeignKeyChecks({ enabled: false })
|
|
58
61
|
* class ImportData extends Model {
|
|
59
62
|
* // fields...
|
|
60
63
|
* }
|
|
64
|
+
* ```
|
|
61
65
|
*
|
|
62
66
|
* @param options - Foreign key check options
|
|
63
67
|
*/
|
|
@@ -74,12 +78,14 @@ function ForeignKeyChecks(options = { enabled: true }) {
|
|
|
74
78
|
*
|
|
75
79
|
* Usage:
|
|
76
80
|
*
|
|
81
|
+
* ```ts
|
|
77
82
|
* @DatabaseSetting('unique_checks', false)
|
|
78
83
|
* @DatabaseSetting('autocommit', false)
|
|
79
84
|
* @DatabaseSetting('sql_mode', 'STRICT_TRANS_TABLES')
|
|
80
85
|
* class ImportData extends Model {
|
|
81
86
|
* // fields...
|
|
82
87
|
* }
|
|
88
|
+
* ```
|
|
83
89
|
*
|
|
84
90
|
* @param name - The setting name
|
|
85
91
|
* @param value - The value to set
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
*
|
|
9
|
+
* ```ts
|
|
9
10
|
* // Static values
|
|
10
11
|
* @Default(18)
|
|
11
12
|
* age: number;
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
* // Raw SQL only when needed
|
|
47
48
|
* @Default({ literal: "CURRENT_TIMESTAMP" })
|
|
48
49
|
* updatedAt: Date;
|
|
50
|
+
* ```
|
|
49
51
|
*/
|
|
50
52
|
/**
|
|
51
53
|
* Options for default value configuration.
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* // Static values
|
|
11
12
|
* @Default(18)
|
|
12
13
|
* age: number;
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
* // Raw SQL only when needed
|
|
48
49
|
* @Default({ literal: "CURRENT_TIMESTAMP" })
|
|
49
50
|
* updatedAt: Date;
|
|
51
|
+
* ```
|
|
50
52
|
*/
|
|
51
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
54
|
exports.getDefaultFields = getDefaultFields;
|
|
@@ -23,9 +23,11 @@
|
|
|
23
23
|
* }, { prorm });
|
|
24
24
|
* Secure('password')(User); // field decorator style
|
|
25
25
|
*
|
|
26
|
+
* ```ts
|
|
26
27
|
* // Or use the decorator on the class definition (requires experimentalDecorators):
|
|
27
28
|
* @SecureField('password')
|
|
28
29
|
* class User extends Model { ... }
|
|
30
|
+
* ```
|
|
29
31
|
*/
|
|
30
32
|
/**
|
|
31
33
|
* Pluggable encryption adapter.
|
|
@@ -98,9 +100,11 @@ export declare function getSecureFields(target: Function): SecureFieldMeta[];
|
|
|
98
100
|
*
|
|
99
101
|
* This is a class decorator factory — pass the field name(s):
|
|
100
102
|
*
|
|
103
|
+
* ```ts
|
|
101
104
|
* @SecureField('password')
|
|
102
105
|
* @SecureField('pin', { algorithm: 'bcrypt', adapter: myAdapter })
|
|
103
106
|
* class User extends Model { ... }
|
|
107
|
+
* ```
|
|
104
108
|
*
|
|
105
109
|
* The ORM will call hashSecureFields(instance) in a beforeCreate /
|
|
106
110
|
* beforeUpdate hook to encrypt the field before it reaches the database.
|
|
@@ -109,8 +113,10 @@ export declare function SecureField(field: string, options?: SecureOptions): (ta
|
|
|
109
113
|
/**
|
|
110
114
|
* Alias for SecureField — preferred shorthand.
|
|
111
115
|
*
|
|
116
|
+
* ```ts
|
|
112
117
|
* @Secure('password')
|
|
113
118
|
* class User extends Model { ... }
|
|
119
|
+
* ```
|
|
114
120
|
*/
|
|
115
121
|
export declare const Secure: typeof SecureField;
|
|
116
122
|
/**
|
|
@@ -133,7 +139,7 @@ export declare function hashSecureFields(instance: any): Promise<void>;
|
|
|
133
139
|
export declare function verifySecureField(instance: any, field: string, plainText: string): Promise<boolean>;
|
|
134
140
|
/**
|
|
135
141
|
* Register beforeCreate and beforeUpdate hooks on a model so that
|
|
136
|
-
*
|
|
142
|
+
* `@Secure` fields are automatically hashed whenever an instance is saved.
|
|
137
143
|
*
|
|
138
144
|
* Call once per model after Model.init():
|
|
139
145
|
*
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
* }, { prorm });
|
|
25
25
|
* Secure('password')(User); // field decorator style
|
|
26
26
|
*
|
|
27
|
+
* ```ts
|
|
27
28
|
* // Or use the decorator on the class definition (requires experimentalDecorators):
|
|
28
29
|
* @SecureField('password')
|
|
29
30
|
* class User extends Model { ... }
|
|
31
|
+
* ```
|
|
30
32
|
*/
|
|
31
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
34
|
exports.Secure = void 0;
|
|
@@ -77,9 +79,11 @@ function getSecureFields(target) {
|
|
|
77
79
|
*
|
|
78
80
|
* This is a class decorator factory — pass the field name(s):
|
|
79
81
|
*
|
|
82
|
+
* ```ts
|
|
80
83
|
* @SecureField('password')
|
|
81
84
|
* @SecureField('pin', { algorithm: 'bcrypt', adapter: myAdapter })
|
|
82
85
|
* class User extends Model { ... }
|
|
86
|
+
* ```
|
|
83
87
|
*
|
|
84
88
|
* The ORM will call hashSecureFields(instance) in a beforeCreate /
|
|
85
89
|
* beforeUpdate hook to encrypt the field before it reaches the database.
|
|
@@ -95,8 +99,10 @@ function SecureField(field, options = {}) {
|
|
|
95
99
|
/**
|
|
96
100
|
* Alias for SecureField — preferred shorthand.
|
|
97
101
|
*
|
|
102
|
+
* ```ts
|
|
98
103
|
* @Secure('password')
|
|
99
104
|
* class User extends Model { ... }
|
|
105
|
+
* ```
|
|
100
106
|
*/
|
|
101
107
|
exports.Secure = SecureField;
|
|
102
108
|
// ==================== Runtime Helpers ====================
|
|
@@ -161,7 +167,7 @@ async function verifySecureField(instance, field, plainText) {
|
|
|
161
167
|
}
|
|
162
168
|
/**
|
|
163
169
|
* Register beforeCreate and beforeUpdate hooks on a model so that
|
|
164
|
-
*
|
|
170
|
+
* `@Secure` fields are automatically hashed whenever an instance is saved.
|
|
165
171
|
*
|
|
166
172
|
* Call once per model after Model.init():
|
|
167
173
|
*
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Example:
|
|
17
17
|
*
|
|
18
|
+
* ```ts
|
|
18
19
|
* @Engine({
|
|
19
20
|
* mergeTreeEngine: { type: 'ReplacingMergeTree', version: 'updatedAt' },
|
|
20
21
|
* orderBy: ['id', 'createdAt'],
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
* await dialect.createTable('events', columns, {
|
|
32
33
|
* ...EngineRegistry.getTableOptions(Event),
|
|
33
34
|
* });
|
|
35
|
+
* ```
|
|
34
36
|
*/
|
|
35
37
|
import type { MergeTreeEngineConfig, ProjectionDefinition } from '../dialects/clickhouse';
|
|
36
38
|
export interface EngineOptions {
|
|
@@ -76,8 +78,10 @@ export declare function getEngineOptions(target: Function): EngineOptions | unde
|
|
|
76
78
|
* Annotate a Model subclass with dialect-specific storage-engine
|
|
77
79
|
* configuration.
|
|
78
80
|
*
|
|
81
|
+
* ```ts
|
|
79
82
|
* @Engine({ mergeTreeEngine: { type: 'AggregatingMergeTree' }, orderBy: ['id'] })
|
|
80
83
|
* class Metrics extends Model { ... }
|
|
84
|
+
* ```
|
|
81
85
|
*/
|
|
82
86
|
export declare function Engine(options: EngineOptions): (target: Function) => void;
|
|
83
87
|
export declare const EngineRegistry: {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* Example:
|
|
18
18
|
*
|
|
19
|
+
* ```ts
|
|
19
20
|
* @Engine({
|
|
20
21
|
* mergeTreeEngine: { type: 'ReplacingMergeTree', version: 'updatedAt' },
|
|
21
22
|
* orderBy: ['id', 'createdAt'],
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
* await dialect.createTable('events', columns, {
|
|
33
34
|
* ...EngineRegistry.getTableOptions(Event),
|
|
34
35
|
* });
|
|
36
|
+
* ```
|
|
35
37
|
*/
|
|
36
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
39
|
exports.EngineRegistry = void 0;
|
|
@@ -51,8 +53,10 @@ function getEngineOptions(target) {
|
|
|
51
53
|
* Annotate a Model subclass with dialect-specific storage-engine
|
|
52
54
|
* configuration.
|
|
53
55
|
*
|
|
56
|
+
* ```ts
|
|
54
57
|
* @Engine({ mergeTreeEngine: { type: 'AggregatingMergeTree' }, orderBy: ['id'] })
|
|
55
58
|
* class Metrics extends Model { ... }
|
|
59
|
+
* ```
|
|
56
60
|
*/
|
|
57
61
|
function Engine(options) {
|
|
58
62
|
return function (target) {
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
* Usage Examples:
|
|
14
14
|
*
|
|
15
15
|
* // Foreign Key cascade options
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* `@OnDelete`('CASCADE')
|
|
17
|
+
* `@OnUpdate`('CASCADE')
|
|
18
|
+
* `@References`({ model: Role, key: 'id' })
|
|
19
19
|
* roleId: number;
|
|
20
20
|
*
|
|
21
21
|
* // Multiple FK options with deferrable
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* `@OnDelete`('RESTRICT')
|
|
23
|
+
* `@OnUpdate`('SET NULL')
|
|
24
|
+
* `@References`({
|
|
25
25
|
* model: User,
|
|
26
26
|
* key: 'id',
|
|
27
27
|
* deferrable: 'INITIALLY DEFERRED'
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
* assignedTo: number;
|
|
30
30
|
*
|
|
31
31
|
* // Deferrable constraint
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* `@Deferrable`('INITIALLY DEFERRED')
|
|
33
|
+
* `@Unique`('user_email')
|
|
34
34
|
* email: string;
|
|
35
35
|
*
|
|
36
36
|
* // AutoIncrement with custom settings
|
|
37
|
-
*
|
|
37
|
+
* `@AutoIncrement`({
|
|
38
38
|
* start: 1000,
|
|
39
39
|
* increment: 1,
|
|
40
40
|
* cache: 1000,
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* id: number;
|
|
47
47
|
*
|
|
48
48
|
* // Sequence-based identity (PostgreSQL)
|
|
49
|
-
*
|
|
49
|
+
* `@Identity`({
|
|
50
50
|
* type: 'ALWAYS',
|
|
51
51
|
* start: 1,
|
|
52
52
|
* increment: 1
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
* id: number;
|
|
55
55
|
*
|
|
56
56
|
* // Generated column (PostgreSQL 12+)
|
|
57
|
-
*
|
|
57
|
+
* `@GeneratedAlways`({
|
|
58
58
|
* as: 'id + 1',
|
|
59
59
|
* stored: true
|
|
60
60
|
* })
|
|
61
61
|
* sequenceNumber: number;
|
|
62
62
|
*
|
|
63
63
|
* // Exclusion constraint (PostgreSQL)
|
|
64
|
-
*
|
|
64
|
+
* `@Exclusion`({
|
|
65
65
|
* using: 'daterange',
|
|
66
66
|
* elements: ['daterange WITH &&']
|
|
67
67
|
* })
|
|
@@ -193,30 +193,30 @@ export interface ExclusionMetadata {
|
|
|
193
193
|
options: ExclusionOptions;
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
|
-
*
|
|
196
|
+
* `@OnDelete` - Specify foreign key ON DELETE action
|
|
197
197
|
*
|
|
198
|
-
*
|
|
198
|
+
* `@OnDelete`('CASCADE')
|
|
199
199
|
* roleId: number;
|
|
200
200
|
*
|
|
201
201
|
* @param action - The delete action (CASCADE, RESTRICT, SET NULL, SET DEFAULT, NO ACTION)
|
|
202
202
|
*/
|
|
203
203
|
export declare function OnDelete(action: ForeignKeyAction): PropertyDecorator;
|
|
204
204
|
/**
|
|
205
|
-
*
|
|
205
|
+
* `@OnUpdate` - Specify foreign key ON UPDATE action
|
|
206
206
|
*
|
|
207
|
-
*
|
|
207
|
+
* `@OnUpdate`('CASCADE')
|
|
208
208
|
* roleId: number;
|
|
209
209
|
*
|
|
210
210
|
* @param action - The update action (CASCADE, RESTRICT, SET NULL, SET DEFAULT, NO ACTION)
|
|
211
211
|
*/
|
|
212
212
|
export declare function OnUpdate(action: ForeignKeyAction): PropertyDecorator;
|
|
213
213
|
/**
|
|
214
|
-
*
|
|
214
|
+
* `@References` - Define foreign key references
|
|
215
215
|
*
|
|
216
|
-
*
|
|
216
|
+
* `@References`({ model: Role, key: 'id' })
|
|
217
217
|
* roleId: number;
|
|
218
218
|
*
|
|
219
|
-
*
|
|
219
|
+
* `@References`({
|
|
220
220
|
* model: User,
|
|
221
221
|
* key: 'id',
|
|
222
222
|
* deferrable: 'INITIALLY DEFERRED'
|
|
@@ -227,13 +227,13 @@ export declare function OnUpdate(action: ForeignKeyAction): PropertyDecorator;
|
|
|
227
227
|
*/
|
|
228
228
|
export declare function References(options: ReferencesOptions): PropertyDecorator;
|
|
229
229
|
/**
|
|
230
|
-
*
|
|
230
|
+
* `@Deferrable` - Make constraint deferrable
|
|
231
231
|
*
|
|
232
|
-
*
|
|
232
|
+
* `@Deferrable`('INITIALLY DEFERRED')
|
|
233
233
|
* email: string;
|
|
234
234
|
*
|
|
235
235
|
* // With operation override
|
|
236
|
-
*
|
|
236
|
+
* `@Deferrable`({
|
|
237
237
|
* deferrable: 'INITIALLY IMMEDIATE',
|
|
238
238
|
* deferFor: 'NOT DEFERRABLE'
|
|
239
239
|
* })
|
|
@@ -243,18 +243,18 @@ export declare function References(options: ReferencesOptions): PropertyDecorato
|
|
|
243
243
|
*/
|
|
244
244
|
export declare function Deferrable(options: DeferrableType | DeferrableOptions): PropertyDecorator;
|
|
245
245
|
/**
|
|
246
|
-
*
|
|
246
|
+
* `@Unique` - Add unique constraint to a column
|
|
247
247
|
*
|
|
248
|
-
*
|
|
248
|
+
* `@Unique`('user_email')
|
|
249
249
|
* email: string;
|
|
250
250
|
*
|
|
251
251
|
* @param name - Optional constraint name
|
|
252
252
|
*/
|
|
253
253
|
export declare function Unique(name?: string): PropertyDecorator;
|
|
254
254
|
/**
|
|
255
|
-
*
|
|
255
|
+
* `@AutoIncrement` - Configure auto-increment with custom settings
|
|
256
256
|
*
|
|
257
|
-
*
|
|
257
|
+
* `@AutoIncrement`({
|
|
258
258
|
* start: 1000,
|
|
259
259
|
* increment: 1,
|
|
260
260
|
* cache: 1000,
|
|
@@ -269,9 +269,9 @@ export declare function Unique(name?: string): PropertyDecorator;
|
|
|
269
269
|
*/
|
|
270
270
|
export declare function AutoIncrement(options: AutoIncrementOptions): PropertyDecorator;
|
|
271
271
|
/**
|
|
272
|
-
*
|
|
272
|
+
* `@Identity` - Configure sequence-based identity (PostgreSQL)
|
|
273
273
|
*
|
|
274
|
-
*
|
|
274
|
+
* `@Identity`({
|
|
275
275
|
* type: 'ALWAYS',
|
|
276
276
|
* start: 1,
|
|
277
277
|
* increment: 1
|
|
@@ -282,9 +282,9 @@ export declare function AutoIncrement(options: AutoIncrementOptions): PropertyDe
|
|
|
282
282
|
*/
|
|
283
283
|
export declare function Identity(options: IdentityOptions): PropertyDecorator;
|
|
284
284
|
/**
|
|
285
|
-
*
|
|
285
|
+
* `@GeneratedAlways` - Define a generated column (PostgreSQL 12+)
|
|
286
286
|
*
|
|
287
|
-
*
|
|
287
|
+
* `@GeneratedAlways`({
|
|
288
288
|
* as: 'id + 1',
|
|
289
289
|
* stored: true
|
|
290
290
|
* })
|
|
@@ -294,9 +294,9 @@ export declare function Identity(options: IdentityOptions): PropertyDecorator;
|
|
|
294
294
|
*/
|
|
295
295
|
export declare function GeneratedAlways(options: GeneratedAlwaysOptions): PropertyDecorator;
|
|
296
296
|
/**
|
|
297
|
-
*
|
|
297
|
+
* `@Exclusion` - Define exclusion constraint (PostgreSQL)
|
|
298
298
|
*
|
|
299
|
-
*
|
|
299
|
+
* `@Exclusion`({
|
|
300
300
|
* using: 'daterange',
|
|
301
301
|
* elements: ['daterange WITH &&']
|
|
302
302
|
* })
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
* Usage Examples:
|
|
15
15
|
*
|
|
16
16
|
* // Foreign Key cascade options
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* `@OnDelete`('CASCADE')
|
|
18
|
+
* `@OnUpdate`('CASCADE')
|
|
19
|
+
* `@References`({ model: Role, key: 'id' })
|
|
20
20
|
* roleId: number;
|
|
21
21
|
*
|
|
22
22
|
* // Multiple FK options with deferrable
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* `@OnDelete`('RESTRICT')
|
|
24
|
+
* `@OnUpdate`('SET NULL')
|
|
25
|
+
* `@References`({
|
|
26
26
|
* model: User,
|
|
27
27
|
* key: 'id',
|
|
28
28
|
* deferrable: 'INITIALLY DEFERRED'
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
* assignedTo: number;
|
|
31
31
|
*
|
|
32
32
|
* // Deferrable constraint
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* `@Deferrable`('INITIALLY DEFERRED')
|
|
34
|
+
* `@Unique`('user_email')
|
|
35
35
|
* email: string;
|
|
36
36
|
*
|
|
37
37
|
* // AutoIncrement with custom settings
|
|
38
|
-
*
|
|
38
|
+
* `@AutoIncrement`({
|
|
39
39
|
* start: 1000,
|
|
40
40
|
* increment: 1,
|
|
41
41
|
* cache: 1000,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
* id: number;
|
|
48
48
|
*
|
|
49
49
|
* // Sequence-based identity (PostgreSQL)
|
|
50
|
-
*
|
|
50
|
+
* `@Identity`({
|
|
51
51
|
* type: 'ALWAYS',
|
|
52
52
|
* start: 1,
|
|
53
53
|
* increment: 1
|
|
@@ -55,14 +55,14 @@
|
|
|
55
55
|
* id: number;
|
|
56
56
|
*
|
|
57
57
|
* // Generated column (PostgreSQL 12+)
|
|
58
|
-
*
|
|
58
|
+
* `@GeneratedAlways`({
|
|
59
59
|
* as: 'id + 1',
|
|
60
60
|
* stored: true
|
|
61
61
|
* })
|
|
62
62
|
* sequenceNumber: number;
|
|
63
63
|
*
|
|
64
64
|
* // Exclusion constraint (PostgreSQL)
|
|
65
|
-
*
|
|
65
|
+
* `@Exclusion`({
|
|
66
66
|
* using: 'daterange',
|
|
67
67
|
* elements: ['daterange WITH &&']
|
|
68
68
|
* })
|
|
@@ -108,9 +108,9 @@ const GENERATED_ALWAYS_META_KEY = Symbol('orm:generatedAlways');
|
|
|
108
108
|
const EXCLUSION_META_KEY = Symbol('orm:exclusion');
|
|
109
109
|
// ==================== OnDelete Decorator ====================
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* `@OnDelete` - Specify foreign key ON DELETE action
|
|
112
112
|
*
|
|
113
|
-
*
|
|
113
|
+
* `@OnDelete`('CASCADE')
|
|
114
114
|
* roleId: number;
|
|
115
115
|
*
|
|
116
116
|
* @param action - The delete action (CASCADE, RESTRICT, SET NULL, SET DEFAULT, NO ACTION)
|
|
@@ -126,9 +126,9 @@ function OnDelete(action) {
|
|
|
126
126
|
}
|
|
127
127
|
// ==================== OnUpdate Decorator ====================
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
129
|
+
* `@OnUpdate` - Specify foreign key ON UPDATE action
|
|
130
130
|
*
|
|
131
|
-
*
|
|
131
|
+
* `@OnUpdate`('CASCADE')
|
|
132
132
|
* roleId: number;
|
|
133
133
|
*
|
|
134
134
|
* @param action - The update action (CASCADE, RESTRICT, SET NULL, SET DEFAULT, NO ACTION)
|
|
@@ -144,12 +144,12 @@ function OnUpdate(action) {
|
|
|
144
144
|
}
|
|
145
145
|
// ==================== References Decorator ====================
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
147
|
+
* `@References` - Define foreign key references
|
|
148
148
|
*
|
|
149
|
-
*
|
|
149
|
+
* `@References`({ model: Role, key: 'id' })
|
|
150
150
|
* roleId: number;
|
|
151
151
|
*
|
|
152
|
-
*
|
|
152
|
+
* `@References`({
|
|
153
153
|
* model: User,
|
|
154
154
|
* key: 'id',
|
|
155
155
|
* deferrable: 'INITIALLY DEFERRED'
|
|
@@ -169,13 +169,13 @@ function References(options) {
|
|
|
169
169
|
}
|
|
170
170
|
// ==================== Deferrable Decorator ====================
|
|
171
171
|
/**
|
|
172
|
-
*
|
|
172
|
+
* `@Deferrable` - Make constraint deferrable
|
|
173
173
|
*
|
|
174
|
-
*
|
|
174
|
+
* `@Deferrable`('INITIALLY DEFERRED')
|
|
175
175
|
* email: string;
|
|
176
176
|
*
|
|
177
177
|
* // With operation override
|
|
178
|
-
*
|
|
178
|
+
* `@Deferrable`({
|
|
179
179
|
* deferrable: 'INITIALLY IMMEDIATE',
|
|
180
180
|
* deferFor: 'NOT DEFERRABLE'
|
|
181
181
|
* })
|
|
@@ -195,9 +195,9 @@ function Deferrable(options) {
|
|
|
195
195
|
}
|
|
196
196
|
// ==================== Unique Decorator ====================
|
|
197
197
|
/**
|
|
198
|
-
*
|
|
198
|
+
* `@Unique` - Add unique constraint to a column
|
|
199
199
|
*
|
|
200
|
-
*
|
|
200
|
+
* `@Unique`('user_email')
|
|
201
201
|
* email: string;
|
|
202
202
|
*
|
|
203
203
|
* @param name - Optional constraint name
|
|
@@ -214,9 +214,9 @@ function Unique(name) {
|
|
|
214
214
|
}
|
|
215
215
|
// ==================== AutoIncrement Decorator ====================
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
217
|
+
* `@AutoIncrement` - Configure auto-increment with custom settings
|
|
218
218
|
*
|
|
219
|
-
*
|
|
219
|
+
* `@AutoIncrement`({
|
|
220
220
|
* start: 1000,
|
|
221
221
|
* increment: 1,
|
|
222
222
|
* cache: 1000,
|
|
@@ -241,9 +241,9 @@ function AutoIncrement(options) {
|
|
|
241
241
|
}
|
|
242
242
|
// ==================== Identity Decorator ====================
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* `@Identity` - Configure sequence-based identity (PostgreSQL)
|
|
245
245
|
*
|
|
246
|
-
*
|
|
246
|
+
* `@Identity`({
|
|
247
247
|
* type: 'ALWAYS',
|
|
248
248
|
* start: 1,
|
|
249
249
|
* increment: 1
|
|
@@ -264,9 +264,9 @@ function Identity(options) {
|
|
|
264
264
|
}
|
|
265
265
|
// ==================== GeneratedAlways Decorator ====================
|
|
266
266
|
/**
|
|
267
|
-
*
|
|
267
|
+
* `@GeneratedAlways` - Define a generated column (PostgreSQL 12+)
|
|
268
268
|
*
|
|
269
|
-
*
|
|
269
|
+
* `@GeneratedAlways`({
|
|
270
270
|
* as: 'id + 1',
|
|
271
271
|
* stored: true
|
|
272
272
|
* })
|
|
@@ -286,9 +286,9 @@ function GeneratedAlways(options) {
|
|
|
286
286
|
}
|
|
287
287
|
// ==================== Exclusion Decorator ====================
|
|
288
288
|
/**
|
|
289
|
-
*
|
|
289
|
+
* `@Exclusion` - Define exclusion constraint (PostgreSQL)
|
|
290
290
|
*
|
|
291
|
-
*
|
|
291
|
+
* `@Exclusion`({
|
|
292
292
|
* using: 'daterange',
|
|
293
293
|
* elements: ['daterange WITH &&']
|
|
294
294
|
* })
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
*
|
|
11
|
+
* ```ts
|
|
11
12
|
* // Virtual computed column (default)
|
|
12
13
|
* @Generated()
|
|
13
14
|
* get fullName() {
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
* cache: 1000
|
|
37
38
|
* })
|
|
38
39
|
* id: number;
|
|
40
|
+
* ```
|
|
39
41
|
*/
|
|
40
42
|
import 'reflect-metadata';
|
|
41
43
|
/**
|
|
@@ -125,21 +127,25 @@ export interface GeneratedMetadata {
|
|
|
125
127
|
*
|
|
126
128
|
* Usage with getter (for computed properties):
|
|
127
129
|
*
|
|
130
|
+
* ```ts
|
|
128
131
|
* class User extends Model {
|
|
129
132
|
* @Generated()
|
|
130
133
|
* get fullName() {
|
|
131
134
|
* return `${this.firstName} ${this.lastName}`;
|
|
132
135
|
* }
|
|
133
136
|
* }
|
|
137
|
+
* ```
|
|
134
138
|
*
|
|
135
139
|
* Usage with options:
|
|
136
140
|
*
|
|
141
|
+
* ```ts
|
|
137
142
|
* @Generated({
|
|
138
143
|
* as: 'CONCAT(first_name, " ", last_name)',
|
|
139
144
|
* type: 'varchar(255)',
|
|
140
145
|
* stored: true
|
|
141
146
|
* })
|
|
142
147
|
* fullName: string;
|
|
148
|
+
* ```
|
|
143
149
|
*
|
|
144
150
|
* @param options - Generated column options or just storage type
|
|
145
151
|
*/
|
|
@@ -149,6 +155,7 @@ export declare function Generated(options?: GeneratedOptions | GeneratedType): P
|
|
|
149
155
|
*
|
|
150
156
|
* Usage:
|
|
151
157
|
*
|
|
158
|
+
* ```ts
|
|
152
159
|
* @Generated({
|
|
153
160
|
* identity: true,
|
|
154
161
|
* start: 1,
|
|
@@ -156,6 +163,7 @@ export declare function Generated(options?: GeneratedOptions | GeneratedType): P
|
|
|
156
163
|
* cache: 1000
|
|
157
164
|
* })
|
|
158
165
|
* id: number;
|
|
166
|
+
* ```
|
|
159
167
|
*
|
|
160
168
|
* @param options - Identity configuration options
|
|
161
169
|
*/
|