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
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
11
|
*
|
|
12
|
+
* ```ts
|
|
12
13
|
* // Virtual computed column (default)
|
|
13
14
|
* @Generated()
|
|
14
15
|
* get fullName() {
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
* cache: 1000
|
|
38
39
|
* })
|
|
39
40
|
* id: number;
|
|
41
|
+
* ```
|
|
40
42
|
*/
|
|
41
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
44
|
exports.Generated = Generated;
|
|
@@ -65,21 +67,25 @@ const IDENTITY_METADATA_KEY = Symbol('prorm:identity');
|
|
|
65
67
|
*
|
|
66
68
|
* Usage with getter (for computed properties):
|
|
67
69
|
*
|
|
70
|
+
* ```ts
|
|
68
71
|
* class User extends Model {
|
|
69
72
|
* @Generated()
|
|
70
73
|
* get fullName() {
|
|
71
74
|
* return `${this.firstName} ${this.lastName}`;
|
|
72
75
|
* }
|
|
73
76
|
* }
|
|
77
|
+
* ```
|
|
74
78
|
*
|
|
75
79
|
* Usage with options:
|
|
76
80
|
*
|
|
81
|
+
* ```ts
|
|
77
82
|
* @Generated({
|
|
78
83
|
* as: 'CONCAT(first_name, " ", last_name)',
|
|
79
84
|
* type: 'varchar(255)',
|
|
80
85
|
* stored: true
|
|
81
86
|
* })
|
|
82
87
|
* fullName: string;
|
|
88
|
+
* ```
|
|
83
89
|
*
|
|
84
90
|
* @param options - Generated column options or just storage type
|
|
85
91
|
*/
|
|
@@ -103,6 +109,7 @@ function Generated(options) {
|
|
|
103
109
|
*
|
|
104
110
|
* Usage:
|
|
105
111
|
*
|
|
112
|
+
* ```ts
|
|
106
113
|
* @Generated({
|
|
107
114
|
* identity: true,
|
|
108
115
|
* start: 1,
|
|
@@ -110,6 +117,7 @@ function Generated(options) {
|
|
|
110
117
|
* cache: 1000
|
|
111
118
|
* })
|
|
112
119
|
* id: number;
|
|
120
|
+
* ```
|
|
113
121
|
*
|
|
114
122
|
* @param options - Identity configuration options
|
|
115
123
|
*/
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
*
|
|
9
|
+
* ```ts
|
|
9
10
|
* // Basic HStore column
|
|
10
11
|
* @HStore()
|
|
11
12
|
* attributes: Record<string, string>;
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
* // With options
|
|
14
15
|
* @HStore({ allowNull: false })
|
|
15
16
|
* metadata: Record<string, any>;
|
|
17
|
+
* ```
|
|
16
18
|
*/
|
|
17
19
|
/**
|
|
18
20
|
* Options for HStore column type
|
|
@@ -43,14 +45,18 @@ export interface HStoreMetadata {
|
|
|
43
45
|
* @example
|
|
44
46
|
* // Basic HStore column
|
|
45
47
|
* class Product extends Model {
|
|
48
|
+
* ```ts
|
|
46
49
|
* @HStore()
|
|
47
50
|
* attributes: Record<string, string>;
|
|
51
|
+
* ```
|
|
48
52
|
* }
|
|
49
53
|
*
|
|
50
54
|
* // With options
|
|
51
55
|
* class Product extends Model {
|
|
56
|
+
* ```ts
|
|
52
57
|
* @HStore({ allowNull: false })
|
|
53
58
|
* metadata: Record<string, any>;
|
|
59
|
+
* ```
|
|
54
60
|
* }
|
|
55
61
|
*/
|
|
56
62
|
export declare function HStore(options?: HStoreDecoratorOptions): PropertyDecorator;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* // Basic HStore column
|
|
11
12
|
* @HStore()
|
|
12
13
|
* attributes: Record<string, string>;
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
* // With options
|
|
15
16
|
* @HStore({ allowNull: false })
|
|
16
17
|
* metadata: Record<string, any>;
|
|
18
|
+
* ```
|
|
17
19
|
*/
|
|
18
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
21
|
exports.HStore = HStore;
|
|
@@ -33,14 +35,18 @@ const hstoreMetadataMap = new Map();
|
|
|
33
35
|
* @example
|
|
34
36
|
* // Basic HStore column
|
|
35
37
|
* class Product extends Model {
|
|
38
|
+
* ```ts
|
|
36
39
|
* @HStore()
|
|
37
40
|
* attributes: Record<string, string>;
|
|
41
|
+
* ```
|
|
38
42
|
* }
|
|
39
43
|
*
|
|
40
44
|
* // With options
|
|
41
45
|
* class Product extends Model {
|
|
46
|
+
* ```ts
|
|
42
47
|
* @HStore({ allowNull: false })
|
|
43
48
|
* metadata: Record<string, any>;
|
|
49
|
+
* ```
|
|
44
50
|
* }
|
|
45
51
|
*/
|
|
46
52
|
function HStore(options) {
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* class Document extends Model {
|
|
6
|
+
* ```ts
|
|
6
7
|
* @JSONColumn()
|
|
7
8
|
* data: DataTypes.JSONCOLUMN;
|
|
8
9
|
*
|
|
9
10
|
* @JSONColumn({ validate: true })
|
|
10
11
|
* config: DataTypes.JSONCOLUMN;
|
|
12
|
+
* ```
|
|
11
13
|
* }
|
|
12
14
|
*/
|
|
13
15
|
import { JSONColumnOptions } from '../types';
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* class Document extends Model {
|
|
7
|
+
* ```ts
|
|
7
8
|
* @JSONColumn()
|
|
8
9
|
* data: DataTypes.JSONCOLUMN;
|
|
9
10
|
*
|
|
10
11
|
* @JSONColumn({ validate: true })
|
|
11
12
|
* config: DataTypes.JSONCOLUMN;
|
|
13
|
+
* ```
|
|
12
14
|
* }
|
|
13
15
|
*/
|
|
14
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
*
|
|
9
|
+
* ```ts
|
|
9
10
|
* // Basic JSONB column
|
|
10
11
|
* @JSONB()
|
|
11
12
|
* metadata: object;
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
* // With validation
|
|
14
15
|
* @JSONB({ validate: true })
|
|
15
16
|
* config: object;
|
|
17
|
+
* ```
|
|
16
18
|
*/
|
|
17
19
|
/**
|
|
18
20
|
* Options for JSONB column type
|
|
@@ -43,14 +45,18 @@ export interface JSONBMetadata {
|
|
|
43
45
|
* @example
|
|
44
46
|
* // Basic JSONB column
|
|
45
47
|
* class Document extends Model {
|
|
48
|
+
* ```ts
|
|
46
49
|
* @JSONB()
|
|
47
50
|
* data: object;
|
|
51
|
+
* ```
|
|
48
52
|
* }
|
|
49
53
|
*
|
|
50
54
|
* // With validation
|
|
51
55
|
* class Config extends Model {
|
|
56
|
+
* ```ts
|
|
52
57
|
* @JSONB({ validate: true })
|
|
53
58
|
* settings: object;
|
|
59
|
+
* ```
|
|
54
60
|
* }
|
|
55
61
|
*/
|
|
56
62
|
export declare function JSONB(options?: JSONBDecoratorOptions): PropertyDecorator;
|
package/dist/decorators/jsonb.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* // Basic JSONB column
|
|
11
12
|
* @JSONB()
|
|
12
13
|
* metadata: object;
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
* // With validation
|
|
15
16
|
* @JSONB({ validate: true })
|
|
16
17
|
* config: object;
|
|
18
|
+
* ```
|
|
17
19
|
*/
|
|
18
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
21
|
exports.JSONB = JSONB;
|
|
@@ -31,14 +33,18 @@ const jsonbMetadataMap = new Map();
|
|
|
31
33
|
* @example
|
|
32
34
|
* // Basic JSONB column
|
|
33
35
|
* class Document extends Model {
|
|
36
|
+
* ```ts
|
|
34
37
|
* @JSONB()
|
|
35
38
|
* data: object;
|
|
39
|
+
* ```
|
|
36
40
|
* }
|
|
37
41
|
*
|
|
38
42
|
* // With validation
|
|
39
43
|
* class Config extends Model {
|
|
44
|
+
* ```ts
|
|
40
45
|
* @JSONB({ validate: true })
|
|
41
46
|
* settings: object;
|
|
47
|
+
* ```
|
|
42
48
|
* }
|
|
43
49
|
*/
|
|
44
50
|
function JSONB(options) {
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
* Quick Reference
|
|
11
11
|
* ──────────────────────────────────────────────────────────────────────────
|
|
12
12
|
*
|
|
13
|
+
* ```ts
|
|
13
14
|
* @CanView('admin', 'manager') — only these roles can read the field/model
|
|
14
15
|
* @CannotView('guest') — these roles are DENIED read access
|
|
15
16
|
* @CanWrite('admin') — only these roles can write the field
|
|
16
17
|
* @CannotWrite('guest') — these roles are DENIED write access
|
|
17
18
|
* @Permission({ ... }) — full control with explicit allow/deny lists
|
|
19
|
+
* ```
|
|
18
20
|
*
|
|
19
21
|
* ──────────────────────────────────────────────────────────────────────────
|
|
20
22
|
* Example
|
|
@@ -25,6 +27,7 @@
|
|
|
25
27
|
* PermissionRegistry.addFieldRule(User, 'salary', { canView: ['admin', 'hr'] });
|
|
26
28
|
* PermissionRegistry.addFieldRule(User, 'password', { canView: [] }); // nobody
|
|
27
29
|
*
|
|
30
|
+
* ```ts
|
|
28
31
|
* // Class-level permission (applied via decorator):
|
|
29
32
|
* @CanView('admin', 'manager')
|
|
30
33
|
* class AuditLog extends Model { ... }
|
|
@@ -38,6 +41,7 @@
|
|
|
38
41
|
* // Or get the allowed attribute list for a findAll() call:
|
|
39
42
|
* const attrs = getAllowedAttributes(User, currentRole);
|
|
40
43
|
* const users = await User.findAll({ attributes: attrs });
|
|
44
|
+
* ```
|
|
41
45
|
*/
|
|
42
46
|
export interface PermissionRule {
|
|
43
47
|
/**
|
|
@@ -144,22 +148,28 @@ export declare function filterWriteByPermissions(data: Record<string, any>, role
|
|
|
144
148
|
* Allow only the listed roles to VIEW the decorated class (all fields) or
|
|
145
149
|
* use PermissionRegistry.addFieldRule() for per-field control.
|
|
146
150
|
*
|
|
151
|
+
* ```ts
|
|
147
152
|
* @CanView('admin', 'manager')
|
|
148
153
|
* class AuditLog extends Model { ... }
|
|
154
|
+
* ```
|
|
149
155
|
*/
|
|
150
156
|
export declare function CanView(...roles: string[]): (target: Function) => void;
|
|
151
157
|
/**
|
|
152
158
|
* Deny the listed roles from viewing the decorated class.
|
|
153
159
|
*
|
|
160
|
+
* ```ts
|
|
154
161
|
* @CannotView('guest', 'public')
|
|
155
162
|
* class SensitiveReport extends Model { ... }
|
|
163
|
+
* ```
|
|
156
164
|
*/
|
|
157
165
|
export declare function CannotView(...roles: string[]): (target: Function) => void;
|
|
158
166
|
/**
|
|
159
167
|
* Allow only the listed roles to WRITE to the decorated class.
|
|
160
168
|
*
|
|
169
|
+
* ```ts
|
|
161
170
|
* @CanWrite('admin')
|
|
162
171
|
* class Settings extends Model { ... }
|
|
172
|
+
* ```
|
|
163
173
|
*/
|
|
164
174
|
export declare function CanWrite(...roles: string[]): (target: Function) => void;
|
|
165
175
|
/**
|
|
@@ -169,8 +179,10 @@ export declare function CannotWrite(...roles: string[]): (target: Function) => v
|
|
|
169
179
|
/**
|
|
170
180
|
* Full permission decorator — applies read and write rules at the model level.
|
|
171
181
|
*
|
|
182
|
+
* ```ts
|
|
172
183
|
* @Permission({ canView: ['admin', 'manager'], canWrite: ['admin'] })
|
|
173
184
|
* class Invoice extends Model { ... }
|
|
185
|
+
* ```
|
|
174
186
|
*/
|
|
175
187
|
export declare function Permission(options: PermissionOptions): (target: Function) => void;
|
|
176
188
|
/**
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
* Quick Reference
|
|
12
12
|
* ──────────────────────────────────────────────────────────────────────────
|
|
13
13
|
*
|
|
14
|
+
* ```ts
|
|
14
15
|
* @CanView('admin', 'manager') — only these roles can read the field/model
|
|
15
16
|
* @CannotView('guest') — these roles are DENIED read access
|
|
16
17
|
* @CanWrite('admin') — only these roles can write the field
|
|
17
18
|
* @CannotWrite('guest') — these roles are DENIED write access
|
|
18
19
|
* @Permission({ ... }) — full control with explicit allow/deny lists
|
|
20
|
+
* ```
|
|
19
21
|
*
|
|
20
22
|
* ──────────────────────────────────────────────────────────────────────────
|
|
21
23
|
* Example
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
* PermissionRegistry.addFieldRule(User, 'salary', { canView: ['admin', 'hr'] });
|
|
27
29
|
* PermissionRegistry.addFieldRule(User, 'password', { canView: [] }); // nobody
|
|
28
30
|
*
|
|
31
|
+
* ```ts
|
|
29
32
|
* // Class-level permission (applied via decorator):
|
|
30
33
|
* @CanView('admin', 'manager')
|
|
31
34
|
* class AuditLog extends Model { ... }
|
|
@@ -39,6 +42,7 @@
|
|
|
39
42
|
* // Or get the allowed attribute list for a findAll() call:
|
|
40
43
|
* const attrs = getAllowedAttributes(User, currentRole);
|
|
41
44
|
* const users = await User.findAll({ attributes: attrs });
|
|
45
|
+
* ```
|
|
42
46
|
*/
|
|
43
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
48
|
exports.PermissionRegistry = void 0;
|
|
@@ -213,8 +217,10 @@ function filterWriteByPermissions(data, role, ModelClass) {
|
|
|
213
217
|
* Allow only the listed roles to VIEW the decorated class (all fields) or
|
|
214
218
|
* use PermissionRegistry.addFieldRule() for per-field control.
|
|
215
219
|
*
|
|
220
|
+
* ```ts
|
|
216
221
|
* @CanView('admin', 'manager')
|
|
217
222
|
* class AuditLog extends Model { ... }
|
|
223
|
+
* ```
|
|
218
224
|
*/
|
|
219
225
|
function CanView(...roles) {
|
|
220
226
|
return function (target) {
|
|
@@ -224,8 +230,10 @@ function CanView(...roles) {
|
|
|
224
230
|
/**
|
|
225
231
|
* Deny the listed roles from viewing the decorated class.
|
|
226
232
|
*
|
|
233
|
+
* ```ts
|
|
227
234
|
* @CannotView('guest', 'public')
|
|
228
235
|
* class SensitiveReport extends Model { ... }
|
|
236
|
+
* ```
|
|
229
237
|
*/
|
|
230
238
|
function CannotView(...roles) {
|
|
231
239
|
return function (target) {
|
|
@@ -235,8 +243,10 @@ function CannotView(...roles) {
|
|
|
235
243
|
/**
|
|
236
244
|
* Allow only the listed roles to WRITE to the decorated class.
|
|
237
245
|
*
|
|
246
|
+
* ```ts
|
|
238
247
|
* @CanWrite('admin')
|
|
239
248
|
* class Settings extends Model { ... }
|
|
249
|
+
* ```
|
|
240
250
|
*/
|
|
241
251
|
function CanWrite(...roles) {
|
|
242
252
|
return function (target) {
|
|
@@ -254,8 +264,10 @@ function CannotWrite(...roles) {
|
|
|
254
264
|
/**
|
|
255
265
|
* Full permission decorator — applies read and write rules at the model level.
|
|
256
266
|
*
|
|
267
|
+
* ```ts
|
|
257
268
|
* @Permission({ canView: ['admin', 'manager'], canWrite: ['admin'] })
|
|
258
269
|
* class Invoice extends Model { ... }
|
|
270
|
+
* ```
|
|
259
271
|
*/
|
|
260
272
|
function Permission(options) {
|
|
261
273
|
return function (target) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TypeScript decorators for SQL Stored Procedures and SQL Functions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* `@Procedure` — annotate a class method (or standalone function wrapper) so
|
|
5
5
|
* it is understood by the ORM as a stored procedure.
|
|
6
6
|
* The ORM can generate the CREATE PROCEDURE SQL and register
|
|
7
7
|
* a callable wrapper on your Prorm instance.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* `@SqlFunction` — like @Procedure but for database functions that RETURN a
|
|
10
10
|
* value and can be called inside SELECT / WHERE clauses.
|
|
11
11
|
*
|
|
12
12
|
* Both decorators store metadata in a registry. Register the class with
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* Example:
|
|
26
26
|
*
|
|
27
|
+
* ```ts
|
|
27
28
|
* class UserProcedures {
|
|
28
29
|
* @Procedure({
|
|
29
30
|
* name: 'get_user_by_email',
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
*
|
|
54
55
|
* // Or use the auto-call helper
|
|
55
56
|
* const rows = await ProcedureRegistry.call(prorm, UserProcedures, 'getUserByEmail', ['john@example.com']);
|
|
57
|
+
* ```
|
|
56
58
|
*/
|
|
57
59
|
import type { Prorm } from '../prorm';
|
|
58
60
|
export type ProcedureParamMode = 'IN' | 'OUT' | 'INOUT';
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* TypeScript decorators for SQL Stored Procedures and SQL Functions.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* `@Procedure` — annotate a class method (or standalone function wrapper) so
|
|
6
6
|
* it is understood by the ORM as a stored procedure.
|
|
7
7
|
* The ORM can generate the CREATE PROCEDURE SQL and register
|
|
8
8
|
* a callable wrapper on your Prorm instance.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* `@SqlFunction` — like @Procedure but for database functions that RETURN a
|
|
11
11
|
* value and can be called inside SELECT / WHERE clauses.
|
|
12
12
|
*
|
|
13
13
|
* Both decorators store metadata in a registry. Register the class with
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* Example:
|
|
27
27
|
*
|
|
28
|
+
* ```ts
|
|
28
29
|
* class UserProcedures {
|
|
29
30
|
* @Procedure({
|
|
30
31
|
* name: 'get_user_by_email',
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
*
|
|
55
56
|
* // Or use the auto-call helper
|
|
56
57
|
* const rows = await ProcedureRegistry.call(prorm, UserProcedures, 'getUserByEmail', ['john@example.com']);
|
|
58
|
+
* ```
|
|
57
59
|
*/
|
|
58
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
61
|
exports.ProcedureRegistry = void 0;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Usage:
|
|
15
15
|
*
|
|
16
|
+
* ```ts
|
|
16
17
|
* // Index hints
|
|
17
18
|
* @UseIndex('idx_name')
|
|
18
19
|
* @ForceIndex('idx_name')
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
* // TABLESAMPLE
|
|
40
41
|
* @Tablesample({ method: 'BERNOULLI', percentage: 50 })
|
|
41
42
|
* async *getSampleUsers() { ... }
|
|
43
|
+
* ```
|
|
42
44
|
*/
|
|
43
45
|
import 'reflect-metadata';
|
|
44
46
|
/**
|
|
@@ -238,9 +240,11 @@ export interface QueryOptions {
|
|
|
238
240
|
*
|
|
239
241
|
* Usage:
|
|
240
242
|
*
|
|
243
|
+
* ```ts
|
|
241
244
|
* @UseIndex('idx_user_email')
|
|
242
245
|
* @UseIndex(['idx_user_email', 'idx_user_status'])
|
|
243
246
|
* class User extends Model {}
|
|
247
|
+
* ```
|
|
244
248
|
*
|
|
245
249
|
* @param index - Index name or array of index names
|
|
246
250
|
*/
|
|
@@ -251,8 +255,10 @@ export declare function UseIndex(index: string | string[]): ClassDecorator;
|
|
|
251
255
|
*
|
|
252
256
|
* Usage:
|
|
253
257
|
*
|
|
258
|
+
* ```ts
|
|
254
259
|
* @ForceIndex('idx_user_email')
|
|
255
260
|
* class User extends Model {}
|
|
261
|
+
* ```
|
|
256
262
|
*
|
|
257
263
|
* @param index - Index name
|
|
258
264
|
*/
|
|
@@ -263,8 +269,10 @@ export declare function ForceIndex(index: string | string[]): ClassDecorator;
|
|
|
263
269
|
*
|
|
264
270
|
* Usage:
|
|
265
271
|
*
|
|
272
|
+
* ```ts
|
|
266
273
|
* @IgnoreIndex('idx_user_email')
|
|
267
274
|
* class User extends Model {}
|
|
275
|
+
* ```
|
|
268
276
|
*
|
|
269
277
|
* @param index - Index name
|
|
270
278
|
*/
|
|
@@ -275,11 +283,13 @@ export declare function IgnoreIndex(index: string | string[]): ClassDecorator;
|
|
|
275
283
|
*
|
|
276
284
|
* Usage:
|
|
277
285
|
*
|
|
286
|
+
* ```ts
|
|
278
287
|
* @Tablesample({ method: 'BERNOULLI', percentage: 50 })
|
|
279
288
|
* class User extends Model {}
|
|
280
289
|
*
|
|
281
290
|
* @Tablesample({ method: 'SYSTEM', pages: 100 })
|
|
282
291
|
* class User extends Model {}
|
|
292
|
+
* ```
|
|
283
293
|
*
|
|
284
294
|
* @param options - Tablesample options
|
|
285
295
|
*/
|
|
@@ -289,11 +299,13 @@ export declare function Tablesample(options: TablesampleOptions): ClassDecorator
|
|
|
289
299
|
*
|
|
290
300
|
* Usage:
|
|
291
301
|
*
|
|
302
|
+
* ```ts
|
|
292
303
|
* @Distinct
|
|
293
304
|
* class User extends Model {}
|
|
294
305
|
*
|
|
295
306
|
* @DistinctOn(['email'])
|
|
296
307
|
* class User extends Model {}
|
|
308
|
+
* ```
|
|
297
309
|
*
|
|
298
310
|
* @param columns - Columns for DISTINCT ON (optional)
|
|
299
311
|
*/
|
|
@@ -308,11 +320,13 @@ export declare const DistinctOn: typeof Distinct;
|
|
|
308
320
|
*
|
|
309
321
|
* Usage:
|
|
310
322
|
*
|
|
323
|
+
* ```ts
|
|
311
324
|
* @WithLock({ mode: 'UPDATE', timeout: 5000, skipLocked: true })
|
|
312
325
|
* async processOrder(id: number) {
|
|
313
326
|
* const order = await Order.findByPk(id, { lock: 'UPDATE' });
|
|
314
327
|
* // process order
|
|
315
328
|
* }
|
|
329
|
+
* ```
|
|
316
330
|
*
|
|
317
331
|
* @param options - Lock options
|
|
318
332
|
*/
|
|
@@ -323,10 +337,12 @@ export declare function WithLock(options?: WithLockOptions): MethodDecorator;
|
|
|
323
337
|
*
|
|
324
338
|
* Usage:
|
|
325
339
|
*
|
|
340
|
+
* ```ts
|
|
326
341
|
* @StatementTimeout(30000) // 30 seconds
|
|
327
342
|
* async runLongQuery() {
|
|
328
343
|
* return await this.query('SELECT * FROM large_table');
|
|
329
344
|
* }
|
|
345
|
+
* ```
|
|
330
346
|
*
|
|
331
347
|
* @param timeout - Timeout in milliseconds
|
|
332
348
|
*/
|
|
@@ -337,10 +353,12 @@ export declare function StatementTimeout(timeout: number): MethodDecorator;
|
|
|
337
353
|
*
|
|
338
354
|
* Usage:
|
|
339
355
|
*
|
|
356
|
+
* ```ts
|
|
340
357
|
* @IdleInTransactionTimeout(60000) // 1 minute
|
|
341
358
|
* async runTransaction() {
|
|
342
359
|
* // long running transaction
|
|
343
360
|
* }
|
|
361
|
+
* ```
|
|
344
362
|
*
|
|
345
363
|
* @param timeout - Timeout in milliseconds
|
|
346
364
|
*/
|
|
@@ -351,12 +369,14 @@ export declare function IdleInTransactionTimeout(timeout: number): MethodDecorat
|
|
|
351
369
|
*
|
|
352
370
|
* Usage:
|
|
353
371
|
*
|
|
372
|
+
* ```ts
|
|
354
373
|
* @Cursor({ holdable: true })
|
|
355
374
|
* async *getAllUsers() {
|
|
356
375
|
* for await (const user of this.findAll({ cursor: true })) {
|
|
357
376
|
* yield user;
|
|
358
377
|
* }
|
|
359
378
|
* }
|
|
379
|
+
* ```
|
|
360
380
|
*
|
|
361
381
|
* @param options - Cursor options
|
|
362
382
|
*/
|
|
@@ -367,10 +387,12 @@ export declare function Cursor(options?: CursorOptions): MethodDecorator;
|
|
|
367
387
|
*
|
|
368
388
|
* Usage:
|
|
369
389
|
*
|
|
390
|
+
* ```ts
|
|
370
391
|
* @Fetch(100)
|
|
371
392
|
* async *getTopUsers() {
|
|
372
393
|
* return await User.findAll({ limit: 100 });
|
|
373
394
|
* }
|
|
395
|
+
* ```
|
|
374
396
|
*
|
|
375
397
|
* @param limit - Number of rows to fetch
|
|
376
398
|
*/
|
|
@@ -381,10 +403,12 @@ export declare function Fetch(limit: number): MethodDecorator;
|
|
|
381
403
|
*
|
|
382
404
|
* Usage:
|
|
383
405
|
*
|
|
406
|
+
* ```ts
|
|
384
407
|
* @Fetch({ first: 100, offset: 50 })
|
|
385
408
|
* async *getPageUsers() {
|
|
386
409
|
* return await User.findAll({ offset: 50, limit: 100 });
|
|
387
410
|
* }
|
|
411
|
+
* ```
|
|
388
412
|
*
|
|
389
413
|
* @param options - Fetch options with limit and optional offset
|
|
390
414
|
*/
|