ts-prorm-orm 1.2.3 → 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 +331 -1
- package/README.md +32 -24
- 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 +4 -0
- package/dist/compliance/index.js +15 -1
- 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/connection-manager.js +13 -1
- package/dist/core/expressions.d.ts +58 -0
- package/dist/core/expressions.js +83 -0
- package/dist/core/hooks-manager.d.ts +179 -0
- package/dist/core/hooks-manager.js +291 -0
- package/dist/core/types.d.ts +235 -0
- package/dist/core/types.js +9 -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/index.d.ts +2 -0
- package/dist/decorators/index.js +11 -1
- 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/diagrams/chen-diagram.d.ts +15 -12
- package/dist/diagrams/chen-diagram.js +76 -85
- package/dist/diagrams/class-diagram.d.ts +9 -8
- package/dist/diagrams/class-diagram.js +60 -82
- package/dist/diagrams/core/index.d.ts +13 -0
- package/dist/diagrams/core/index.js +33 -0
- package/dist/diagrams/core/layout.d.ts +104 -0
- package/dist/diagrams/core/layout.js +223 -0
- package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
- package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
- package/dist/diagrams/core/theme.d.ts +84 -0
- package/dist/diagrams/core/theme.js +62 -0
- package/dist/diagrams/dependency-diagram.d.ts +15 -14
- package/dist/diagrams/dependency-diagram.js +71 -105
- package/dist/diagrams/er-diagram.d.ts +13 -26
- package/dist/diagrams/er-diagram.js +180 -259
- package/dist/diagrams/flow-diagram.d.ts +16 -11
- package/dist/diagrams/flow-diagram.js +96 -91
- package/dist/diagrams/gantt-diagram.d.ts +10 -5
- package/dist/diagrams/gantt-diagram.js +77 -103
- package/dist/diagrams/index-diagram.d.ts +10 -10
- package/dist/diagrams/index-diagram.js +106 -116
- package/dist/diagrams/index.d.ts +6 -9
- package/dist/diagrams/index.js +9 -24
- package/dist/diagrams/migration-diagram.d.ts +8 -4
- package/dist/diagrams/migration-diagram.js +189 -161
- package/dist/diagrams/model-diagram.d.ts +34 -34
- package/dist/diagrams/model-diagram.js +106 -485
- package/dist/diagrams/package-diagram.d.ts +9 -6
- package/dist/diagrams/package-diagram.js +64 -101
- package/dist/diagrams/relational-diagram.d.ts +12 -10
- package/dist/diagrams/relational-diagram.js +87 -114
- package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
- package/dist/diagrams/schemadoc-diagram.js +71 -93
- package/dist/diagrams/sequence-diagram.d.ts +10 -10
- package/dist/diagrams/sequence-diagram.js +64 -89
- package/dist/diagrams/state-diagram.d.ts +10 -9
- package/dist/diagrams/state-diagram.js +69 -92
- package/dist/diagrams/tree-diagram.d.ts +11 -5
- package/dist/diagrams/tree-diagram.js +41 -65
- package/dist/dialects/clickhouse/index.js +15 -0
- package/dist/dialects/cockroachdb/index.d.ts +1 -1
- package/dist/dialects/cockroachdb/index.js +32 -63
- package/dist/dialects/db2/index.js +23 -8
- package/dist/dialects/dialect.d.ts +141 -5
- package/dist/dialects/duckdb/index.js +9 -2
- package/dist/dialects/hana/index.js +22 -5
- package/dist/dialects/lock-clause-helper.d.ts +167 -0
- package/dist/dialects/lock-clause-helper.js +316 -0
- package/dist/dialects/mariadb/index.d.ts +7 -4
- package/dist/dialects/mariadb/index.js +36 -60
- package/dist/dialects/mssql/index.js +34 -3
- package/dist/dialects/mysql/index.d.ts +1 -1
- package/dist/dialects/mysql/index.js +17 -45
- package/dist/dialects/oracle/index.d.ts +14 -3
- package/dist/dialects/oracle/index.js +66 -36
- package/dist/dialects/order-expression-helper.d.ts +72 -0
- package/dist/dialects/order-expression-helper.js +154 -0
- package/dist/dialects/partial-index.d.ts +52 -0
- package/dist/dialects/partial-index.js +251 -0
- package/dist/dialects/postgres/index.d.ts +1 -1
- package/dist/dialects/postgres/index.js +43 -68
- package/dist/dialects/redshift/index.js +9 -2
- package/dist/dialects/snowflake/index.js +17 -0
- package/dist/dialects/spanner/index.js +7 -2
- package/dist/dialects/sqlite/driver.d.ts +55 -0
- package/dist/dialects/sqlite/driver.js +102 -0
- package/dist/dialects/sqlite/index.d.ts +1 -1
- package/dist/dialects/sqlite/index.js +49 -27
- package/dist/external-fields/decorator.d.ts +2 -0
- package/dist/external-fields/decorator.js +2 -0
- package/dist/graph/base-graph-dialect.d.ts +24 -3
- package/dist/graph/base-graph-dialect.js +43 -2
- package/dist/graph/dgraph/index.js +6 -0
- package/dist/graph/gremlin/index.d.ts +6 -0
- package/dist/graph/gremlin/index.js +12 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/neo4j/index.d.ts +2 -0
- package/dist/graph/neo4j/index.js +6 -1
- package/dist/graph/types.d.ts +12 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +53 -7
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.js +23 -0
- package/dist/logging/query-logging.d.ts +82 -0
- package/dist/logging/query-logging.js +102 -0
- package/dist/models/associations.d.ts +38 -0
- package/dist/models/associations.js +16 -0
- package/dist/models/decorators.d.ts +55 -19
- package/dist/models/decorators.js +95 -19
- package/dist/models/eager-load.d.ts +99 -0
- package/dist/models/eager-load.js +348 -5
- package/dist/models/indexes.d.ts +3 -2
- package/dist/models/indexes.js +7 -1
- package/dist/models/model.js +69 -43
- package/dist/prorm.d.ts +175 -409
- package/dist/prorm.js +1132 -553
- package/dist/query-builders/order-limit-builder.js +12 -10
- package/dist/query-builders/sql-compiler.d.ts +10 -3
- package/dist/query-builders/sql-compiler.js +14 -43
- package/dist/query-interface.d.ts +2 -1
- package/dist/schema-objects.d.ts +42 -0
- package/dist/schema-objects.js +28 -0
- package/dist/sql-constants.d.ts +44 -0
- package/dist/sql-constants.js +138 -1
- package/dist/types/index.d.ts +387 -17
- package/dist/types/index.js +10 -15
- package/dist/types/query-types.d.ts +26 -0
- package/dist/types/query-types.js +30 -0
- package/package.json +39 -8
- package/dist/decorators/belongs-to-many.js +0 -115
- package/dist/decorators/belongs-to.js +0 -115
- package/dist/decorators/has-many.js +0 -127
- package/dist/decorators/has-one.js +0 -116
- package/dist/diagrams/palette.d.ts +0 -138
- package/dist/diagrams/palette.js +0 -194
- package/dist/hooks/hooks-manager.d.ts +0 -189
- package/dist/hooks/hooks-manager.js +0 -350
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -37
- /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
- /package/dist/{logging.js → logging/logger.js} +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and interfaces for the Prorm instance API.
|
|
3
|
+
*
|
|
4
|
+
* These were declared inline in prorm.ts, scattered above and below the
|
|
5
|
+
* 7,500-line Prorm class. They are re-exported from prorm.ts so the public API
|
|
6
|
+
* is unchanged.
|
|
7
|
+
*/
|
|
8
|
+
import type { AttributeOptions, ModelStatic } from '../types';
|
|
9
|
+
import type { ModelOptions as ModelOptionsType } from '../types';
|
|
10
|
+
import type { Transaction } from '../transaction';
|
|
11
|
+
import { QueryTypes } from '../types/query-types';
|
|
12
|
+
import type { Col, Literal } from './expressions';
|
|
13
|
+
/**
|
|
14
|
+
* Hook types for the ORM
|
|
15
|
+
*/
|
|
16
|
+
export type HookCallback = (...args: any[]) => void | Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Every model lifecycle hook the ORM fires.
|
|
19
|
+
*
|
|
20
|
+
* Typing hook names as a union rather than `string` makes a misspelled hook a
|
|
21
|
+
* compile error instead of a callback that silently never runs - which is
|
|
22
|
+
* exactly how eleven of these went unnoticed.
|
|
23
|
+
*/
|
|
24
|
+
export type HookName = 'beforeValidate' | 'afterValidate' | 'beforeCreate' | 'afterCreate' | 'beforeUpdate' | 'afterUpdate' | 'beforeDestroy' | 'afterDestroy' | 'beforeSave' | 'afterSave' | 'beforeUpsert' | 'afterUpsert' | 'beforeFind' | 'afterFind' | 'beforeCount' | 'beforeBulkCreate' | 'afterBulkCreate' | 'beforeBulkUpdate' | 'afterBulkUpdate' | 'beforeBulkDestroy' | 'afterBulkDestroy';
|
|
25
|
+
/** A model's hook map, as passed to `define(..., { hooks })`. */
|
|
26
|
+
export type ModelHookMap = Partial<Record<HookName, HookCallback>>;
|
|
27
|
+
/**
|
|
28
|
+
* Connection type for hook callbacks
|
|
29
|
+
*/
|
|
30
|
+
export interface Connection {
|
|
31
|
+
id: string;
|
|
32
|
+
createdAt: number;
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for sync method
|
|
37
|
+
*/
|
|
38
|
+
export interface SyncOptions {
|
|
39
|
+
/**
|
|
40
|
+
* If true, drops all tables and recreates them.
|
|
41
|
+
* WARNING: This will destroy all data in the tables!
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
force?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* If true, alter tables to match model definitions.
|
|
47
|
+
* This will add new columns, remove extra columns, and change column types as needed.
|
|
48
|
+
* Preserves existing data in the table.
|
|
49
|
+
* Can be an object with { drop: false } to prevent dropping columns
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
alter?: boolean | {
|
|
53
|
+
drop?: boolean;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Regular expression to match the database name.
|
|
57
|
+
* Sync will only proceed if the database name matches this pattern.
|
|
58
|
+
* Useful for development vs production environments.
|
|
59
|
+
* Example: /test/ - only syncs if database name contains "test"
|
|
60
|
+
*/
|
|
61
|
+
match?: RegExp;
|
|
62
|
+
/**
|
|
63
|
+
* Custom logging function
|
|
64
|
+
*/
|
|
65
|
+
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
66
|
+
/**
|
|
67
|
+
* If true, run sync hooks (beforeSync, afterSync, etc.)
|
|
68
|
+
* @default true
|
|
69
|
+
*/
|
|
70
|
+
hooks?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If true, also sync indexes
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
indexes?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* If true, also sync foreign key constraints
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
constraints?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for raw query execution
|
|
84
|
+
*/
|
|
85
|
+
export interface RawQueryResult {
|
|
86
|
+
rows: unknown[];
|
|
87
|
+
count: number;
|
|
88
|
+
isSelect: boolean;
|
|
89
|
+
}
|
|
90
|
+
export interface QueryOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Query type - determines how results are processed
|
|
93
|
+
* Forces the query type for result handling
|
|
94
|
+
* - SELECT: Returns array of rows
|
|
95
|
+
* - INSERT: Returns [rows, created]
|
|
96
|
+
* - UPDATE: Returns affected count
|
|
97
|
+
* - DELETE: Returns affected count
|
|
98
|
+
* - BULKDELETE: Returns affected count
|
|
99
|
+
* - UPSERT: Returns [rows, created]
|
|
100
|
+
*/
|
|
101
|
+
type?: QueryTypes | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'BULKDELETE' | 'UPSERT' | 'BULKINSERT' | 'VERSION' | 'SHOWTABLES' | 'DESCRIBE' | 'RAW';
|
|
102
|
+
/**
|
|
103
|
+
* Replacements for named (:param) or positional (?) placeholders
|
|
104
|
+
* For named: { username: 'john' } replaces :username in SQL
|
|
105
|
+
* For positional: ['john', 'smith'] replaces ? in order
|
|
106
|
+
*/
|
|
107
|
+
replacements?: Record<string, unknown> | unknown[];
|
|
108
|
+
/**
|
|
109
|
+
* Return raw results without model instantiation
|
|
110
|
+
*/
|
|
111
|
+
raw?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Whether to log the query
|
|
114
|
+
*/
|
|
115
|
+
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
116
|
+
/**
|
|
117
|
+
* When true, logs query execution time
|
|
118
|
+
*/
|
|
119
|
+
benchmark?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Transaction to use for the query
|
|
122
|
+
*/
|
|
123
|
+
transaction?: Transaction;
|
|
124
|
+
/**
|
|
125
|
+
* Retry configuration for query execution
|
|
126
|
+
* On connection failure or retryable errors, retry up to max times
|
|
127
|
+
* @param max - Maximum number of retry attempts
|
|
128
|
+
* @param match - Array of error message patterns that trigger retry
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // Retry on connection refused or timeout errors
|
|
132
|
+
* await prorm.query('SELECT * FROM users', {
|
|
133
|
+
* retry: { max: 3, match: ['Connection refused', 'Timeout', 'ECONNREFUSED'] }
|
|
134
|
+
* });
|
|
135
|
+
*/
|
|
136
|
+
retry?: {
|
|
137
|
+
max: number;
|
|
138
|
+
match?: string[];
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Map raw query results to a model instance
|
|
142
|
+
* When true, maps the result rows to ModelInstance objects using the provided model
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
mapToModel?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Model to use for mapping raw results to model instances
|
|
148
|
+
* Used together with mapToModel to create ModelInstance objects from raw query results
|
|
149
|
+
*/
|
|
150
|
+
model?: ModelStatic<any>;
|
|
151
|
+
}
|
|
152
|
+
/** The shape stored in `Prorm.modelDefinitions`. */
|
|
153
|
+
export type PrormModelDefinition = {
|
|
154
|
+
attributes: Record<string, AttributeOptions>;
|
|
155
|
+
options: ModelOptionsType;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Represents a SQL function expression
|
|
159
|
+
* Used with prorm.fn() to create SQL functions like COUNT, UPPER, YEAR, etc.
|
|
160
|
+
*/
|
|
161
|
+
export interface Fn {
|
|
162
|
+
/**
|
|
163
|
+
* The SQL function name (e.g., 'COUNT', 'UPPER', 'YEAR')
|
|
164
|
+
*/
|
|
165
|
+
fn: string;
|
|
166
|
+
/**
|
|
167
|
+
* The arguments to the function (can be column references, literals, or other functions)
|
|
168
|
+
*/
|
|
169
|
+
args: (string | Col | Fn | Literal)[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Represents a SQL CAST expression
|
|
173
|
+
* Used to cast a value to a specific data type
|
|
174
|
+
*/
|
|
175
|
+
export interface Cast {
|
|
176
|
+
/**
|
|
177
|
+
* Type identifier for CAST
|
|
178
|
+
*/
|
|
179
|
+
$type: 'cast';
|
|
180
|
+
/**
|
|
181
|
+
* The value to cast (column reference, literal, or function)
|
|
182
|
+
*/
|
|
183
|
+
value: string | Col | Fn | Literal;
|
|
184
|
+
/**
|
|
185
|
+
* The target data type (e.g., 'VARCHAR', 'INTEGER', 'DATE', 'BOOLEAN')
|
|
186
|
+
*/
|
|
187
|
+
type: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Represents a WHERE condition for complex queries
|
|
191
|
+
*/
|
|
192
|
+
export interface WhereObject {
|
|
193
|
+
/**
|
|
194
|
+
* Type identifier for WHERE
|
|
195
|
+
*/
|
|
196
|
+
$type: 'where';
|
|
197
|
+
/**
|
|
198
|
+
* The column or expression to compare
|
|
199
|
+
*/
|
|
200
|
+
col: Col | Fn | Literal;
|
|
201
|
+
/**
|
|
202
|
+
* The value or condition to compare against
|
|
203
|
+
*/
|
|
204
|
+
value: unknown;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Represents an AND or OR combination of conditions
|
|
208
|
+
*/
|
|
209
|
+
export interface AndOrObject {
|
|
210
|
+
/**
|
|
211
|
+
* Type identifier - 'and' or 'or'
|
|
212
|
+
*/
|
|
213
|
+
$type: 'and' | 'or';
|
|
214
|
+
/**
|
|
215
|
+
* The conditions to combine
|
|
216
|
+
*/
|
|
217
|
+
conditions: unknown[];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Represents a JSON path query for JSON columns
|
|
221
|
+
*/
|
|
222
|
+
export interface JsonObject {
|
|
223
|
+
/**
|
|
224
|
+
* Type identifier for JSON
|
|
225
|
+
*/
|
|
226
|
+
$type: 'json';
|
|
227
|
+
/**
|
|
228
|
+
* The JSON path to query (dot notation or array notation)
|
|
229
|
+
*/
|
|
230
|
+
path: string;
|
|
231
|
+
/**
|
|
232
|
+
* Optional value to compare against
|
|
233
|
+
*/
|
|
234
|
+
value?: unknown;
|
|
235
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Types and interfaces for the Prorm instance API.
|
|
4
|
+
*
|
|
5
|
+
* These were declared inline in prorm.ts, scattered above and below the
|
|
6
|
+
* 7,500-line Prorm class. They are re-exported from prorm.ts so the public API
|
|
7
|
+
* is unchanged.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `@Audit` class decorator — automatically record model lifecycle events to an
|
|
3
3
|
* in-memory audit log.
|
|
4
4
|
*
|
|
5
5
|
* When applied to a model class the decorator registers beforeCreate,
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Example:
|
|
10
10
|
*
|
|
11
|
+
* ```ts
|
|
11
12
|
* @Audit({ tableName: 'audit_log', trackFields: ['name', 'email'] })
|
|
12
13
|
* class User extends Model { ... }
|
|
13
14
|
*
|
|
14
15
|
* // After create/update/destroy hooks fire:
|
|
15
16
|
* const log = getAuditLog(User);
|
|
16
17
|
* clearAuditLog(User);
|
|
18
|
+
* ```
|
|
17
19
|
*/
|
|
18
20
|
export interface AuditOptions {
|
|
19
21
|
/** Name of the conceptual audit table (used as label in entries). Default: 'audit_log'. */
|
package/dist/decorators/audit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* `@Audit` class decorator — automatically record model lifecycle events to an
|
|
4
4
|
* in-memory audit log.
|
|
5
5
|
*
|
|
6
6
|
* When applied to a model class the decorator registers beforeCreate,
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Example:
|
|
11
11
|
*
|
|
12
|
+
* ```ts
|
|
12
13
|
* @Audit({ tableName: 'audit_log', trackFields: ['name', 'email'] })
|
|
13
14
|
* class User extends Model { ... }
|
|
14
15
|
*
|
|
15
16
|
* // After create/update/destroy hooks fire:
|
|
16
17
|
* const log = getAuditLog(User);
|
|
17
18
|
* clearAuditLog(User);
|
|
19
|
+
* ```
|
|
18
20
|
*/
|
|
19
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
22
|
exports.getAuditLog = getAuditLog;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `@Check` decorator for the ORM — generates CHECK constraints without writing raw SQL.
|
|
3
3
|
*
|
|
4
4
|
* Supports ORM-native operator syntax that gets converted to SQL CHECK expressions.
|
|
5
5
|
*
|
|
6
6
|
* Usage Examples:
|
|
7
7
|
*
|
|
8
8
|
* // Column-level check with ORM operators
|
|
9
|
-
*
|
|
9
|
+
* `@Check`({ age: { $gte: 18 } })
|
|
10
10
|
* age: number;
|
|
11
11
|
*
|
|
12
12
|
* // Multiple column checks
|
|
13
|
-
*
|
|
13
|
+
* `@Check`({
|
|
14
14
|
* status: { $in: ['active', 'pending', 'draft'] },
|
|
15
15
|
* email: { $regex: '^[^@]+@[^@]+$' }
|
|
16
16
|
* })
|
|
17
17
|
* email: string;
|
|
18
18
|
*
|
|
19
19
|
* // Custom condition with message
|
|
20
|
-
*
|
|
20
|
+
* `@Check`({
|
|
21
21
|
* condition: (row) => row.startDate < row.endDate,
|
|
22
22
|
* message: 'Start date must be before end date'
|
|
23
23
|
* })
|
|
24
24
|
* startDate: Date;
|
|
25
25
|
*
|
|
26
26
|
* // Column-level check (explicit column)
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* `@CheckColumn`('price', { $gte: 0 }, 'Price must be positive')
|
|
28
|
+
* `@CheckColumn`('quantity', { $gt: 0 }, 'Quantity must be greater than zero')
|
|
29
29
|
*
|
|
30
30
|
* // Table-level check (multiple columns)
|
|
31
|
-
*
|
|
31
|
+
* `@CheckTable`({
|
|
32
32
|
* condition: (row) => row.quantity * row.price >= row.minimumOrder,
|
|
33
33
|
* message: 'Total must meet minimum order amount'
|
|
34
34
|
* })
|
|
@@ -155,21 +155,21 @@ export type CheckDialect = 'mysql' | 'mariadb' | 'postgres' | 'mssql' | 'oracle'
|
|
|
155
155
|
*/
|
|
156
156
|
export declare function operatorToSQL(fieldName: string, operator: CheckOperator, dialect?: CheckDialect): string;
|
|
157
157
|
/**
|
|
158
|
-
*
|
|
158
|
+
* `@Check` decorator — attach CHECK constraints to a column or multiple columns.
|
|
159
159
|
*
|
|
160
160
|
* For column-level use (on class property):
|
|
161
|
-
*
|
|
161
|
+
* `@Check`({ age: { $gte: 18 } })
|
|
162
162
|
* age: number;
|
|
163
163
|
*
|
|
164
164
|
* For multiple checks:
|
|
165
|
-
*
|
|
165
|
+
* `@Check`({
|
|
166
166
|
* status: { $in: ['active', 'pending'] },
|
|
167
167
|
* email: { $regex: '^[^@]+@[^@]+$' }
|
|
168
168
|
* })
|
|
169
169
|
* email: string;
|
|
170
170
|
*
|
|
171
171
|
* For row-level condition:
|
|
172
|
-
*
|
|
172
|
+
* `@Check`({
|
|
173
173
|
* condition: (row) => row.startDate < row.endDate,
|
|
174
174
|
* message: 'Start date must be before end date'
|
|
175
175
|
* })
|
|
@@ -177,16 +177,16 @@ export declare function operatorToSQL(fieldName: string, operator: CheckOperator
|
|
|
177
177
|
*/
|
|
178
178
|
export declare function Check(options: CheckConstraintOptions): PropertyDecorator;
|
|
179
179
|
/**
|
|
180
|
-
*
|
|
180
|
+
* `@CheckColumn` decorator — explicit column-level CHECK constraint.
|
|
181
181
|
*
|
|
182
|
-
*
|
|
182
|
+
* `@CheckColumn`('price', { $gte: 0 }, 'Price must be positive')
|
|
183
183
|
* price: number;
|
|
184
184
|
*/
|
|
185
185
|
export declare function CheckColumn(column: string, operator: CheckOperator, message?: string): PropertyDecorator;
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
187
|
+
* `@CheckTable` decorator — table-level CHECK constraint with multi-column conditions.
|
|
188
188
|
*
|
|
189
|
-
*
|
|
189
|
+
* `@CheckTable`({
|
|
190
190
|
* condition: (row) => row.quantity * row.price >= row.minimumOrder,
|
|
191
191
|
* message: 'Total must meet minimum order amount'
|
|
192
192
|
* })
|
package/dist/decorators/check.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* `@Check` decorator for the ORM — generates CHECK constraints without writing raw SQL.
|
|
4
4
|
*
|
|
5
5
|
* Supports ORM-native operator syntax that gets converted to SQL CHECK expressions.
|
|
6
6
|
*
|
|
7
7
|
* Usage Examples:
|
|
8
8
|
*
|
|
9
9
|
* // Column-level check with ORM operators
|
|
10
|
-
*
|
|
10
|
+
* `@Check`({ age: { $gte: 18 } })
|
|
11
11
|
* age: number;
|
|
12
12
|
*
|
|
13
13
|
* // Multiple column checks
|
|
14
|
-
*
|
|
14
|
+
* `@Check`({
|
|
15
15
|
* status: { $in: ['active', 'pending', 'draft'] },
|
|
16
16
|
* email: { $regex: '^[^@]+@[^@]+$' }
|
|
17
17
|
* })
|
|
18
18
|
* email: string;
|
|
19
19
|
*
|
|
20
20
|
* // Custom condition with message
|
|
21
|
-
*
|
|
21
|
+
* `@Check`({
|
|
22
22
|
* condition: (row) => row.startDate < row.endDate,
|
|
23
23
|
* message: 'Start date must be before end date'
|
|
24
24
|
* })
|
|
25
25
|
* startDate: Date;
|
|
26
26
|
*
|
|
27
27
|
* // Column-level check (explicit column)
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* `@CheckColumn`('price', { $gte: 0 }, 'Price must be positive')
|
|
29
|
+
* `@CheckColumn`('quantity', { $gt: 0 }, 'Quantity must be greater than zero')
|
|
30
30
|
*
|
|
31
31
|
* // Table-level check (multiple columns)
|
|
32
|
-
*
|
|
32
|
+
* `@CheckTable`({
|
|
33
33
|
* condition: (row) => row.quantity * row.price >= row.minimumOrder,
|
|
34
34
|
* message: 'Total must meet minimum order amount'
|
|
35
35
|
* })
|
|
@@ -270,21 +270,21 @@ function conditionToSQL(condition, paramNames) {
|
|
|
270
270
|
}
|
|
271
271
|
// ==================== Decorators ====================
|
|
272
272
|
/**
|
|
273
|
-
*
|
|
273
|
+
* `@Check` decorator — attach CHECK constraints to a column or multiple columns.
|
|
274
274
|
*
|
|
275
275
|
* For column-level use (on class property):
|
|
276
|
-
*
|
|
276
|
+
* `@Check`({ age: { $gte: 18 } })
|
|
277
277
|
* age: number;
|
|
278
278
|
*
|
|
279
279
|
* For multiple checks:
|
|
280
|
-
*
|
|
280
|
+
* `@Check`({
|
|
281
281
|
* status: { $in: ['active', 'pending'] },
|
|
282
282
|
* email: { $regex: '^[^@]+@[^@]+$' }
|
|
283
283
|
* })
|
|
284
284
|
* email: string;
|
|
285
285
|
*
|
|
286
286
|
* For row-level condition:
|
|
287
|
-
*
|
|
287
|
+
* `@Check`({
|
|
288
288
|
* condition: (row) => row.startDate < row.endDate,
|
|
289
289
|
* message: 'Start date must be before end date'
|
|
290
290
|
* })
|
|
@@ -328,9 +328,9 @@ function Check(options) {
|
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
|
-
*
|
|
331
|
+
* `@CheckColumn` decorator — explicit column-level CHECK constraint.
|
|
332
332
|
*
|
|
333
|
-
*
|
|
333
|
+
* `@CheckColumn`('price', { $gte: 0 }, 'Price must be positive')
|
|
334
334
|
* price: number;
|
|
335
335
|
*/
|
|
336
336
|
function CheckColumn(column, operator, message) {
|
|
@@ -348,9 +348,9 @@ function CheckColumn(column, operator, message) {
|
|
|
348
348
|
};
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
|
-
*
|
|
351
|
+
* `@CheckTable` decorator — table-level CHECK constraint with multi-column conditions.
|
|
352
352
|
*
|
|
353
|
-
*
|
|
353
|
+
* `@CheckTable`({
|
|
354
354
|
* condition: (row) => row.quantity * row.price >= row.minimumOrder,
|
|
355
355
|
* message: 'Total must meet minimum order amount'
|
|
356
356
|
* })
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
*
|
|
9
|
+
* ```ts
|
|
9
10
|
* // Column-level collation
|
|
10
11
|
* class User extends Model {
|
|
11
12
|
* @SetCollate(CollateEnum.UTF8MB4_UNICODE_CI)
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
* lcCtype: 'es_ES.UTF-8',
|
|
39
40
|
* template: 'template0',
|
|
40
41
|
* });
|
|
42
|
+
* ```
|
|
41
43
|
*/
|
|
42
44
|
/**
|
|
43
45
|
* MySQL/MariaDB collation constants
|
|
@@ -255,33 +257,42 @@ export interface OrderByOptions {
|
|
|
255
257
|
* Decorator to set column-level collation
|
|
256
258
|
*
|
|
257
259
|
* Usage:
|
|
260
|
+
* ```ts
|
|
258
261
|
* @Collate(Collate.UTF8MB4_UNICODE_CI)
|
|
259
262
|
* @Column
|
|
260
263
|
* name: string;
|
|
264
|
+
* ```
|
|
261
265
|
*
|
|
262
266
|
* Or with options:
|
|
267
|
+
* ```ts
|
|
263
268
|
* @Collate({ collate: Collate.UTF8MB4_BIN, unique: true })
|
|
264
269
|
* @Column
|
|
265
270
|
* email: string;
|
|
271
|
+
* ```
|
|
266
272
|
*/
|
|
267
273
|
/**
|
|
268
274
|
* Decorator to set column-level collation
|
|
269
275
|
*
|
|
270
276
|
* Usage:
|
|
277
|
+
* ```ts
|
|
271
278
|
* @SetCollate(CollateEnum.UTF8MB4_UNICODE_CI)
|
|
272
279
|
* @Column
|
|
273
280
|
* name: string;
|
|
281
|
+
* ```
|
|
274
282
|
*
|
|
275
283
|
* Or with options:
|
|
284
|
+
* ```ts
|
|
276
285
|
* @SetCollate({ collate: CollateEnum.UTF8MB4_BIN, unique: true })
|
|
277
286
|
* @Column
|
|
278
287
|
* email: string;
|
|
288
|
+
* ```
|
|
279
289
|
*/
|
|
280
290
|
export declare function SetCollate(collation: string | CollateOptions): ClassDecorator & PropertyDecorator;
|
|
281
291
|
/**
|
|
282
292
|
* Decorator to set database-level options
|
|
283
293
|
*
|
|
284
294
|
* Usage:
|
|
295
|
+
* ```ts
|
|
285
296
|
* @Database({
|
|
286
297
|
* name: 'miapp',
|
|
287
298
|
* encoding: 'UTF8',
|
|
@@ -290,22 +301,27 @@ export declare function SetCollate(collation: string | CollateOptions): ClassDec
|
|
|
290
301
|
* connectionLimit: 25,
|
|
291
302
|
* })
|
|
292
303
|
* class Config extends Model {}
|
|
304
|
+
* ```
|
|
293
305
|
*/
|
|
294
306
|
export declare function Database(options: DatabaseOptions): ClassDecorator;
|
|
295
307
|
/**
|
|
296
308
|
* Decorator to set table-level collation and options
|
|
297
309
|
*
|
|
298
310
|
* Usage:
|
|
311
|
+
* ```ts
|
|
299
312
|
* @TableCollate({ collate: 'utf8mb4_spanish_ci', engine: 'InnoDB' })
|
|
300
313
|
* class User extends Model {}
|
|
314
|
+
* ```
|
|
301
315
|
*/
|
|
302
316
|
export declare function TableCollate(options: TableCollateOptions): ClassDecorator;
|
|
303
317
|
/**
|
|
304
318
|
* Decorator to specify order by with collation
|
|
305
319
|
*
|
|
306
320
|
* Usage:
|
|
321
|
+
* ```ts
|
|
307
322
|
* @OrderBy('name', 'ASC', Collate.UTF8MB4_SPANISH_CI)
|
|
308
323
|
* class User extends Model {}
|
|
324
|
+
* ```
|
|
309
325
|
*/
|
|
310
326
|
export declare function OrderBy(column: string, direction?: 'ASC' | 'DESC', collate?: string): ClassDecorator;
|
|
311
327
|
/**
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* // Column-level collation
|
|
11
12
|
* class User extends Model {
|
|
12
13
|
* @SetCollate(CollateEnum.UTF8MB4_UNICODE_CI)
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
* lcCtype: 'es_ES.UTF-8',
|
|
40
41
|
* template: 'template0',
|
|
41
42
|
* });
|
|
43
|
+
* ```
|
|
42
44
|
*/
|
|
43
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
46
|
exports.Locale = exports.LocaleEnum = exports.Collate = exports.CollateEnum = void 0;
|
|
@@ -158,27 +160,35 @@ const orderByMetadata = new Map();
|
|
|
158
160
|
* Decorator to set column-level collation
|
|
159
161
|
*
|
|
160
162
|
* Usage:
|
|
163
|
+
* ```ts
|
|
161
164
|
* @Collate(Collate.UTF8MB4_UNICODE_CI)
|
|
162
165
|
* @Column
|
|
163
166
|
* name: string;
|
|
167
|
+
* ```
|
|
164
168
|
*
|
|
165
169
|
* Or with options:
|
|
170
|
+
* ```ts
|
|
166
171
|
* @Collate({ collate: Collate.UTF8MB4_BIN, unique: true })
|
|
167
172
|
* @Column
|
|
168
173
|
* email: string;
|
|
174
|
+
* ```
|
|
169
175
|
*/
|
|
170
176
|
/**
|
|
171
177
|
* Decorator to set column-level collation
|
|
172
178
|
*
|
|
173
179
|
* Usage:
|
|
180
|
+
* ```ts
|
|
174
181
|
* @SetCollate(CollateEnum.UTF8MB4_UNICODE_CI)
|
|
175
182
|
* @Column
|
|
176
183
|
* name: string;
|
|
184
|
+
* ```
|
|
177
185
|
*
|
|
178
186
|
* Or with options:
|
|
187
|
+
* ```ts
|
|
179
188
|
* @SetCollate({ collate: CollateEnum.UTF8MB4_BIN, unique: true })
|
|
180
189
|
* @Column
|
|
181
190
|
* email: string;
|
|
191
|
+
* ```
|
|
182
192
|
*/
|
|
183
193
|
function SetCollate(collation) {
|
|
184
194
|
return function (target, propertyKey) {
|
|
@@ -202,6 +212,7 @@ function SetCollate(collation) {
|
|
|
202
212
|
* Decorator to set database-level options
|
|
203
213
|
*
|
|
204
214
|
* Usage:
|
|
215
|
+
* ```ts
|
|
205
216
|
* @Database({
|
|
206
217
|
* name: 'miapp',
|
|
207
218
|
* encoding: 'UTF8',
|
|
@@ -210,6 +221,7 @@ function SetCollate(collation) {
|
|
|
210
221
|
* connectionLimit: 25,
|
|
211
222
|
* })
|
|
212
223
|
* class Config extends Model {}
|
|
224
|
+
* ```
|
|
213
225
|
*/
|
|
214
226
|
function Database(options) {
|
|
215
227
|
return function (target) {
|
|
@@ -220,8 +232,10 @@ function Database(options) {
|
|
|
220
232
|
* Decorator to set table-level collation and options
|
|
221
233
|
*
|
|
222
234
|
* Usage:
|
|
235
|
+
* ```ts
|
|
223
236
|
* @TableCollate({ collate: 'utf8mb4_spanish_ci', engine: 'InnoDB' })
|
|
224
237
|
* class User extends Model {}
|
|
238
|
+
* ```
|
|
225
239
|
*/
|
|
226
240
|
function TableCollate(options) {
|
|
227
241
|
return function (target) {
|
|
@@ -232,8 +246,10 @@ function TableCollate(options) {
|
|
|
232
246
|
* Decorator to specify order by with collation
|
|
233
247
|
*
|
|
234
248
|
* Usage:
|
|
249
|
+
* ```ts
|
|
235
250
|
* @OrderBy('name', 'ASC', Collate.UTF8MB4_SPANISH_CI)
|
|
236
251
|
* class User extends Model {}
|
|
252
|
+
* ```
|
|
237
253
|
*/
|
|
238
254
|
function OrderBy(column, direction = 'ASC', collate) {
|
|
239
255
|
return function (target) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* `@Comment` decorator for database schema annotations
|
|
3
3
|
*
|
|
4
4
|
* Provides the ability to add comments to various database objects:
|
|
5
5
|
* - Table-level comments (on model classes)
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Usage:
|
|
11
11
|
*
|
|
12
|
+
* ```ts
|
|
12
13
|
* @Comment('This table stores user information')
|
|
13
14
|
* class User extends Model { ... }
|
|
14
15
|
*
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
* @Column
|
|
20
21
|
* @Comment('User email address')
|
|
21
22
|
* email: string;
|
|
23
|
+
* ```
|
|
22
24
|
*/
|
|
23
25
|
export interface CommentOptions {
|
|
24
26
|
value: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* `@Comment` decorator for database schema annotations
|
|
4
4
|
*
|
|
5
5
|
* Provides the ability to add comments to various database objects:
|
|
6
6
|
* - Table-level comments (on model classes)
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
12
|
*
|
|
13
|
+
* ```ts
|
|
13
14
|
* @Comment('This table stores user information')
|
|
14
15
|
* class User extends Model { ... }
|
|
15
16
|
*
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
* @Column
|
|
21
22
|
* @Comment('User email address')
|
|
22
23
|
* email: string;
|
|
24
|
+
* ```
|
|
23
25
|
*/
|
|
24
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
27
|
exports.CommentRegistry = void 0;
|