bigal 13.0.0-beta2 → 13.0.0-beta3
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 +4 -0
- package/dist/decorators/index.cjs +282 -0
- package/dist/decorators/index.d.cts +1 -0
- package/dist/decorators/index.d.mts +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.mjs +271 -0
- package/dist/index.cjs +18 -638
- package/dist/index.d.cts +4 -419
- package/dist/index.d.mts +4 -419
- package/dist/index.d.ts +4 -419
- package/dist/index.mjs +4 -623
- package/dist/metadata/index.cjs +369 -0
- package/dist/metadata/index.d.cts +1 -0
- package/dist/metadata/index.d.mts +1 -0
- package/dist/metadata/index.d.ts +1 -0
- package/dist/metadata/index.mjs +358 -0
- package/dist/shared/bigal.03669aef.d.cts +105 -0
- package/dist/shared/bigal.03669aef.d.mts +105 -0
- package/dist/shared/bigal.03669aef.d.ts +105 -0
- package/dist/shared/bigal.7bdb464e.d.cts +315 -0
- package/dist/shared/bigal.7bdb464e.d.mts +315 -0
- package/dist/shared/bigal.7bdb464e.d.ts +315 -0
- package/package.json +21 -1
package/dist/index.mjs
CHANGED
|
@@ -1,359 +1,7 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __publicField$7 = (obj, key, value) => {
|
|
6
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
return value;
|
|
8
|
-
};
|
|
9
|
-
class MetadataStorage {
|
|
10
|
-
constructor() {
|
|
11
|
-
__publicField$7(this, "models", []);
|
|
12
|
-
// All columns for all models. This data only represents @column specifics, not additional column modifiers
|
|
13
|
-
__publicField$7(this, "columns", []);
|
|
14
|
-
// This represents additional column behavior separate from the main @column decorator. For example, @primaryColumn, @versionColumn, etc
|
|
15
|
-
// This behavior will be merged over defaults from @column()
|
|
16
|
-
__publicField$7(this, "columnModifiers", []);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var __defProp$6 = Object.defineProperty;
|
|
21
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
22
|
-
var __publicField$6 = (obj, key, value) => {
|
|
23
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
|
-
class ColumnBaseMetadata {
|
|
27
|
-
constructor({
|
|
28
|
-
target,
|
|
29
|
-
name,
|
|
30
|
-
propertyName,
|
|
31
|
-
required = false,
|
|
32
|
-
insert = true,
|
|
33
|
-
update = true,
|
|
34
|
-
primary = false,
|
|
35
|
-
createDate = false,
|
|
36
|
-
updateDate = false,
|
|
37
|
-
version = false
|
|
38
|
-
}) {
|
|
39
|
-
/**
|
|
40
|
-
* Name of class with @table decorator
|
|
41
|
-
*/
|
|
42
|
-
__publicField$6(this, "target");
|
|
43
|
-
/**
|
|
44
|
-
* Column name in the database
|
|
45
|
-
*/
|
|
46
|
-
__publicField$6(this, "name");
|
|
47
|
-
/**
|
|
48
|
-
* Class property to which the column is applied
|
|
49
|
-
*/
|
|
50
|
-
__publicField$6(this, "propertyName");
|
|
51
|
-
/**
|
|
52
|
-
* Indicates if a value is required for creates.
|
|
53
|
-
*/
|
|
54
|
-
__publicField$6(this, "required");
|
|
55
|
-
/**
|
|
56
|
-
* Indicates if column is inserted by default. Default is true
|
|
57
|
-
*/
|
|
58
|
-
__publicField$6(this, "insert");
|
|
59
|
-
/**
|
|
60
|
-
* Indicates if column value is updated by "save" operation. Default is true
|
|
61
|
-
*/
|
|
62
|
-
__publicField$6(this, "update");
|
|
63
|
-
/**
|
|
64
|
-
* Indicates if this column is a primary key.
|
|
65
|
-
* Same can be achieved when @primaryColumn decorator is used
|
|
66
|
-
*/
|
|
67
|
-
__publicField$6(this, "primary");
|
|
68
|
-
/**
|
|
69
|
-
* Value will be equal to `new Date()` when the row is inserted into the table
|
|
70
|
-
* Same can be achieved when @createDateColumn decorator is used
|
|
71
|
-
*/
|
|
72
|
-
__publicField$6(this, "createDate");
|
|
73
|
-
/**
|
|
74
|
-
* Value will be equal to `new Date()` when the row is updated
|
|
75
|
-
* Same can be achieved when @updateDateColumn decorator is used
|
|
76
|
-
*/
|
|
77
|
-
__publicField$6(this, "updateDate");
|
|
78
|
-
/**
|
|
79
|
-
* Value will be set to 1 when the row is inserted. Value will be incremented by one when the row is updated
|
|
80
|
-
* Same can be achieved when @versionColumn decorator is used
|
|
81
|
-
*/
|
|
82
|
-
__publicField$6(this, "version");
|
|
83
|
-
this.target = target;
|
|
84
|
-
this.name = name;
|
|
85
|
-
this.propertyName = propertyName;
|
|
86
|
-
this.required = required;
|
|
87
|
-
this.insert = insert;
|
|
88
|
-
this.update = update;
|
|
89
|
-
this.primary = primary;
|
|
90
|
-
this.createDate = createDate;
|
|
91
|
-
this.updateDate = updateDate;
|
|
92
|
-
this.version = version;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var __defProp$5 = Object.defineProperty;
|
|
97
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
98
|
-
var __publicField$5 = (obj, key, value) => {
|
|
99
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
100
|
-
return value;
|
|
101
|
-
};
|
|
102
|
-
class ColumnCollectionMetadata extends ColumnBaseMetadata {
|
|
103
|
-
constructor({
|
|
104
|
-
target,
|
|
105
|
-
//
|
|
106
|
-
name,
|
|
107
|
-
propertyName,
|
|
108
|
-
required,
|
|
109
|
-
insert,
|
|
110
|
-
update,
|
|
111
|
-
primary,
|
|
112
|
-
createDate,
|
|
113
|
-
updateDate,
|
|
114
|
-
version,
|
|
115
|
-
collection,
|
|
116
|
-
via,
|
|
117
|
-
through
|
|
118
|
-
}) {
|
|
119
|
-
super({
|
|
120
|
-
target,
|
|
121
|
-
name,
|
|
122
|
-
propertyName,
|
|
123
|
-
required,
|
|
124
|
-
insert,
|
|
125
|
-
update,
|
|
126
|
-
primary,
|
|
127
|
-
createDate,
|
|
128
|
-
updateDate,
|
|
129
|
-
version
|
|
130
|
-
});
|
|
131
|
-
__publicField$5(this, "_collectionString");
|
|
132
|
-
__publicField$5(this, "_collectionFn");
|
|
133
|
-
__publicField$5(this, "_throughString");
|
|
134
|
-
__publicField$5(this, "_throughFn");
|
|
135
|
-
/**
|
|
136
|
-
* Property name of the on the collection item type
|
|
137
|
-
*/
|
|
138
|
-
__publicField$5(this, "via");
|
|
139
|
-
this.via = via;
|
|
140
|
-
if (typeof collection === "string") {
|
|
141
|
-
this._collectionString = collection;
|
|
142
|
-
} else {
|
|
143
|
-
this._collectionFn = collection;
|
|
144
|
-
}
|
|
145
|
-
if (typeof through === "string") {
|
|
146
|
-
this._throughString = through;
|
|
147
|
-
} else if (through) {
|
|
148
|
-
this._throughFn = through;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Type of the items in the collection
|
|
153
|
-
*/
|
|
154
|
-
get collection() {
|
|
155
|
-
if (this._collectionString) {
|
|
156
|
-
return this._collectionString;
|
|
157
|
-
}
|
|
158
|
-
if (!this._collectionFn) {
|
|
159
|
-
throw new Error(`Unable to determine collection type for ${this.target}#${this.propertyName}`);
|
|
160
|
-
}
|
|
161
|
-
this._collectionString = this._collectionFn();
|
|
162
|
-
return this._collectionString;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Name of the junction table for multi-multi associations
|
|
166
|
-
*/
|
|
167
|
-
get through() {
|
|
168
|
-
if (this._throughString) {
|
|
169
|
-
return this._throughString;
|
|
170
|
-
}
|
|
171
|
-
if (this._throughFn) {
|
|
172
|
-
this._throughString = this._throughFn();
|
|
173
|
-
return this._throughString;
|
|
174
|
-
}
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var __defProp$4 = Object.defineProperty;
|
|
180
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
181
|
-
var __publicField$4 = (obj, key, value) => {
|
|
182
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
183
|
-
return value;
|
|
184
|
-
};
|
|
185
|
-
class ColumnModelMetadata extends ColumnBaseMetadata {
|
|
186
|
-
constructor({
|
|
187
|
-
target,
|
|
188
|
-
//
|
|
189
|
-
name,
|
|
190
|
-
propertyName,
|
|
191
|
-
required,
|
|
192
|
-
insert,
|
|
193
|
-
update,
|
|
194
|
-
primary,
|
|
195
|
-
createDate,
|
|
196
|
-
updateDate,
|
|
197
|
-
version,
|
|
198
|
-
model
|
|
199
|
-
}) {
|
|
200
|
-
super({
|
|
201
|
-
target,
|
|
202
|
-
name,
|
|
203
|
-
propertyName,
|
|
204
|
-
required,
|
|
205
|
-
insert,
|
|
206
|
-
update,
|
|
207
|
-
primary,
|
|
208
|
-
createDate,
|
|
209
|
-
updateDate,
|
|
210
|
-
version
|
|
211
|
-
});
|
|
212
|
-
__publicField$4(this, "_modelString");
|
|
213
|
-
__publicField$4(this, "_modelFn");
|
|
214
|
-
if (typeof model === "string") {
|
|
215
|
-
this._modelString = model;
|
|
216
|
-
} else {
|
|
217
|
-
this._modelFn = model;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Name of the model represented by this column id
|
|
222
|
-
*/
|
|
223
|
-
get model() {
|
|
224
|
-
if (this._modelString) {
|
|
225
|
-
return this._modelString;
|
|
226
|
-
}
|
|
227
|
-
if (!this._modelFn) {
|
|
228
|
-
throw new Error(`Unable to determine model type for ${this.target}#${this.propertyName}`);
|
|
229
|
-
}
|
|
230
|
-
this._modelString = this._modelFn();
|
|
231
|
-
return this._modelString;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
var __defProp$3 = Object.defineProperty;
|
|
236
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
237
|
-
var __publicField$3 = (obj, key, value) => {
|
|
238
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
239
|
-
return value;
|
|
240
|
-
};
|
|
241
|
-
class ColumnTypeMetadata extends ColumnBaseMetadata {
|
|
242
|
-
constructor(options) {
|
|
243
|
-
super({
|
|
244
|
-
target: options.target,
|
|
245
|
-
name: options.name,
|
|
246
|
-
propertyName: options.propertyName,
|
|
247
|
-
required: options.required,
|
|
248
|
-
insert: options.insert,
|
|
249
|
-
update: options.update,
|
|
250
|
-
primary: options.primary,
|
|
251
|
-
createDate: options.createDate,
|
|
252
|
-
updateDate: options.updateDate,
|
|
253
|
-
version: options.version
|
|
254
|
-
});
|
|
255
|
-
/**
|
|
256
|
-
* Type of the column
|
|
257
|
-
*/
|
|
258
|
-
__publicField$3(this, "type");
|
|
259
|
-
/**
|
|
260
|
-
* Default database value
|
|
261
|
-
*/
|
|
262
|
-
__publicField$3(this, "defaultsTo");
|
|
263
|
-
/**
|
|
264
|
-
* Array of possible enumerated values
|
|
265
|
-
*/
|
|
266
|
-
__publicField$3(this, "enum");
|
|
267
|
-
/**
|
|
268
|
-
* If set, enforces a maximum length check on the column
|
|
269
|
-
*
|
|
270
|
-
* Applies to types: string | string[]
|
|
271
|
-
*/
|
|
272
|
-
__publicField$3(this, "maxLength");
|
|
273
|
-
this.type = options.type;
|
|
274
|
-
this.defaultsTo = options.defaultsTo;
|
|
275
|
-
this.enum = options.enum;
|
|
276
|
-
this.maxLength = options.maxLength;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
var __defProp$2 = Object.defineProperty;
|
|
281
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
282
|
-
var __publicField$2 = (obj, key, value) => {
|
|
283
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
284
|
-
return value;
|
|
285
|
-
};
|
|
286
|
-
class ModelMetadata {
|
|
287
|
-
constructor({
|
|
288
|
-
name,
|
|
289
|
-
//
|
|
290
|
-
type,
|
|
291
|
-
connection,
|
|
292
|
-
tableName,
|
|
293
|
-
readonly = false
|
|
294
|
-
}) {
|
|
295
|
-
__publicField$2(this, "_columns", []);
|
|
296
|
-
__publicField$2(this, "_primaryKeyColumn");
|
|
297
|
-
__publicField$2(this, "_createDateColumns", []);
|
|
298
|
-
__publicField$2(this, "_updateDateColumns", []);
|
|
299
|
-
__publicField$2(this, "_versionDateColumns", []);
|
|
300
|
-
__publicField$2(this, "name");
|
|
301
|
-
__publicField$2(this, "type");
|
|
302
|
-
__publicField$2(this, "connection");
|
|
303
|
-
__publicField$2(this, "tableName");
|
|
304
|
-
__publicField$2(this, "readonly");
|
|
305
|
-
__publicField$2(this, "columnsByColumnName", {});
|
|
306
|
-
__publicField$2(this, "columnsByPropertyName", {});
|
|
307
|
-
this.name = name;
|
|
308
|
-
this.type = type;
|
|
309
|
-
this.connection = connection;
|
|
310
|
-
this.tableName = tableName ?? _.snakeCase(name);
|
|
311
|
-
this.readonly = readonly;
|
|
312
|
-
}
|
|
313
|
-
set columns(columns) {
|
|
314
|
-
this._columns = columns;
|
|
315
|
-
this.columnsByColumnName = {};
|
|
316
|
-
this.columnsByPropertyName = {};
|
|
317
|
-
for (const column of columns) {
|
|
318
|
-
this.columnsByColumnName[column.name] = column;
|
|
319
|
-
this.columnsByPropertyName[column.propertyName] = column;
|
|
320
|
-
if (column.primary) {
|
|
321
|
-
this._primaryKeyColumn = column;
|
|
322
|
-
}
|
|
323
|
-
if (column.createDate) {
|
|
324
|
-
this._createDateColumns.push(column);
|
|
325
|
-
}
|
|
326
|
-
if (column.updateDate) {
|
|
327
|
-
this._updateDateColumns.push(column);
|
|
328
|
-
}
|
|
329
|
-
if (column.version) {
|
|
330
|
-
this._versionDateColumns.push(column);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
get columns() {
|
|
335
|
-
return this._columns;
|
|
336
|
-
}
|
|
337
|
-
get primaryKeyColumn() {
|
|
338
|
-
return this._primaryKeyColumn;
|
|
339
|
-
}
|
|
340
|
-
get createDateColumns() {
|
|
341
|
-
return this._createDateColumns;
|
|
342
|
-
}
|
|
343
|
-
get updateDateColumns() {
|
|
344
|
-
return this._updateDateColumns;
|
|
345
|
-
}
|
|
346
|
-
get versionColumns() {
|
|
347
|
-
return this._versionDateColumns;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function getMetadataStorage() {
|
|
352
|
-
if (!global.bigAlMetadataArgsStorage) {
|
|
353
|
-
global.bigAlMetadataArgsStorage = new MetadataStorage();
|
|
354
|
-
}
|
|
355
|
-
return global.bigAlMetadataArgsStorage;
|
|
356
|
-
}
|
|
2
|
+
import { getMetadataStorage, ModelMetadata, ColumnModelMetadata, ColumnTypeMetadata } from './metadata/index.mjs';
|
|
3
|
+
export { ColumnBaseMetadata, ColumnCollectionMetadata } from './metadata/index.mjs';
|
|
4
|
+
export { column, createDateColumn, primaryColumn, table, updateDateColumn, versionColumn } from './decorators/index.mjs';
|
|
357
5
|
|
|
358
6
|
var __defProp$1 = Object.defineProperty;
|
|
359
7
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -2162,273 +1810,6 @@ ${stack}`;
|
|
|
2162
1810
|
}
|
|
2163
1811
|
}
|
|
2164
1812
|
|
|
2165
|
-
function column(dbColumnNameOrOptions, options) {
|
|
2166
|
-
return function columnDecorator(object, propertyName) {
|
|
2167
|
-
if (!dbColumnNameOrOptions) {
|
|
2168
|
-
dbColumnNameOrOptions = _.snakeCase(propertyName);
|
|
2169
|
-
}
|
|
2170
|
-
let dbColumnName;
|
|
2171
|
-
if (typeof dbColumnNameOrOptions === "string") {
|
|
2172
|
-
dbColumnName = dbColumnNameOrOptions;
|
|
2173
|
-
} else {
|
|
2174
|
-
options = dbColumnNameOrOptions;
|
|
2175
|
-
}
|
|
2176
|
-
if (!options) {
|
|
2177
|
-
options = {};
|
|
2178
|
-
}
|
|
2179
|
-
if (!dbColumnName) {
|
|
2180
|
-
dbColumnName = options.name ?? _.snakeCase(propertyName);
|
|
2181
|
-
}
|
|
2182
|
-
const metadataStorage = getMetadataStorage();
|
|
2183
|
-
const columnCollectionOptions = options;
|
|
2184
|
-
if (columnCollectionOptions.collection || columnCollectionOptions.via) {
|
|
2185
|
-
if (!columnCollectionOptions.collection) {
|
|
2186
|
-
throw new Error("Unable to determine collection value. Please try specifying values as a strings to avoid circular dependency issues.");
|
|
2187
|
-
}
|
|
2188
|
-
metadataStorage.columns.push(
|
|
2189
|
-
new ColumnCollectionMetadata({
|
|
2190
|
-
target: object.constructor.name,
|
|
2191
|
-
name: dbColumnName,
|
|
2192
|
-
propertyName,
|
|
2193
|
-
required: columnCollectionOptions.required,
|
|
2194
|
-
collection: columnCollectionOptions.collection,
|
|
2195
|
-
through: columnCollectionOptions.through,
|
|
2196
|
-
via: columnCollectionOptions.via
|
|
2197
|
-
})
|
|
2198
|
-
);
|
|
2199
|
-
return;
|
|
2200
|
-
}
|
|
2201
|
-
const columnModelOptions = options;
|
|
2202
|
-
if (columnModelOptions.model) {
|
|
2203
|
-
metadataStorage.columns.push(
|
|
2204
|
-
new ColumnModelMetadata({
|
|
2205
|
-
target: object.constructor.name,
|
|
2206
|
-
name: dbColumnName,
|
|
2207
|
-
propertyName,
|
|
2208
|
-
required: columnModelOptions.required,
|
|
2209
|
-
model: columnModelOptions.model
|
|
2210
|
-
})
|
|
2211
|
-
);
|
|
2212
|
-
return;
|
|
2213
|
-
}
|
|
2214
|
-
const columnTypeOptions = options;
|
|
2215
|
-
metadataStorage.columns.push(
|
|
2216
|
-
new ColumnTypeMetadata({
|
|
2217
|
-
target: object.constructor.name,
|
|
2218
|
-
name: dbColumnName,
|
|
2219
|
-
propertyName,
|
|
2220
|
-
required: columnTypeOptions.required,
|
|
2221
|
-
type: columnTypeOptions.type,
|
|
2222
|
-
defaultsTo: columnTypeOptions.defaultsTo,
|
|
2223
|
-
enum: columnTypeOptions.enum,
|
|
2224
|
-
maxLength: columnTypeOptions.maxLength
|
|
2225
|
-
})
|
|
2226
|
-
);
|
|
2227
|
-
};
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
function createDateColumn(dbColumnNameOrOptions, options) {
|
|
2231
|
-
return function createDateColumnDecorator(object, propertyName) {
|
|
2232
|
-
const metadataStorage = getMetadataStorage();
|
|
2233
|
-
let dbColumnName;
|
|
2234
|
-
if (typeof dbColumnNameOrOptions === "string") {
|
|
2235
|
-
dbColumnName = dbColumnNameOrOptions;
|
|
2236
|
-
} else {
|
|
2237
|
-
options = dbColumnNameOrOptions;
|
|
2238
|
-
}
|
|
2239
|
-
if (dbColumnNameOrOptions) {
|
|
2240
|
-
if (!options) {
|
|
2241
|
-
options = {};
|
|
2242
|
-
}
|
|
2243
|
-
if (!dbColumnName) {
|
|
2244
|
-
dbColumnName = options.name ?? _.snakeCase(propertyName);
|
|
2245
|
-
}
|
|
2246
|
-
metadataStorage.columns.push(
|
|
2247
|
-
new ColumnTypeMetadata({
|
|
2248
|
-
target: object.constructor.name,
|
|
2249
|
-
name: dbColumnName,
|
|
2250
|
-
propertyName,
|
|
2251
|
-
createDate: true,
|
|
2252
|
-
required: options.required,
|
|
2253
|
-
type: options.type
|
|
2254
|
-
})
|
|
2255
|
-
);
|
|
2256
|
-
} else {
|
|
2257
|
-
metadataStorage.columnModifiers.push({
|
|
2258
|
-
target: object.constructor.name,
|
|
2259
|
-
name: dbColumnName ?? _.snakeCase(propertyName),
|
|
2260
|
-
propertyName,
|
|
2261
|
-
createDate: true,
|
|
2262
|
-
required: options ? options.required : void 0,
|
|
2263
|
-
type: options ? options.type : "datetime"
|
|
2264
|
-
});
|
|
2265
|
-
}
|
|
2266
|
-
};
|
|
2267
|
-
}
|
|
2268
|
-
|
|
2269
|
-
function primaryColumn(dbColumnNameOrOptions, options) {
|
|
2270
|
-
return function primaryColumnDecorator(object, propertyName) {
|
|
2271
|
-
let dbColumnName;
|
|
2272
|
-
if (typeof dbColumnNameOrOptions === "string") {
|
|
2273
|
-
dbColumnName = dbColumnNameOrOptions;
|
|
2274
|
-
} else {
|
|
2275
|
-
options = dbColumnNameOrOptions;
|
|
2276
|
-
}
|
|
2277
|
-
if (dbColumnNameOrOptions) {
|
|
2278
|
-
if (!options) {
|
|
2279
|
-
options = {};
|
|
2280
|
-
}
|
|
2281
|
-
if (!dbColumnName) {
|
|
2282
|
-
dbColumnName = options.name ?? _.snakeCase(propertyName);
|
|
2283
|
-
}
|
|
2284
|
-
const { type } = options;
|
|
2285
|
-
const { model } = options;
|
|
2286
|
-
const metadataStorage = getMetadataStorage();
|
|
2287
|
-
if (model) {
|
|
2288
|
-
metadataStorage.columns.push(
|
|
2289
|
-
new ColumnModelMetadata({
|
|
2290
|
-
target: object.constructor.name,
|
|
2291
|
-
name: dbColumnName,
|
|
2292
|
-
propertyName,
|
|
2293
|
-
primary: true,
|
|
2294
|
-
required: options.required,
|
|
2295
|
-
model
|
|
2296
|
-
})
|
|
2297
|
-
);
|
|
2298
|
-
} else {
|
|
2299
|
-
metadataStorage.columns.push(
|
|
2300
|
-
new ColumnTypeMetadata({
|
|
2301
|
-
target: object.constructor.name,
|
|
2302
|
-
name: dbColumnName,
|
|
2303
|
-
propertyName,
|
|
2304
|
-
primary: true,
|
|
2305
|
-
required: options.required,
|
|
2306
|
-
type
|
|
2307
|
-
})
|
|
2308
|
-
);
|
|
2309
|
-
}
|
|
2310
|
-
} else {
|
|
2311
|
-
const metadataStorage = getMetadataStorage();
|
|
2312
|
-
metadataStorage.columnModifiers.push({
|
|
2313
|
-
target: object.constructor.name,
|
|
2314
|
-
name: dbColumnName ?? _.snakeCase(propertyName),
|
|
2315
|
-
propertyName,
|
|
2316
|
-
primary: true,
|
|
2317
|
-
required: options ? options.required : void 0,
|
|
2318
|
-
type: options ? options.type : void 0,
|
|
2319
|
-
model: options ? options.model : void 0
|
|
2320
|
-
});
|
|
2321
|
-
}
|
|
2322
|
-
};
|
|
2323
|
-
}
|
|
2324
|
-
|
|
2325
|
-
function table(dbNameOrTableOptions, options) {
|
|
2326
|
-
return function tableDecorator(classObject) {
|
|
2327
|
-
const className = classObject.name;
|
|
2328
|
-
let dbTableName;
|
|
2329
|
-
if (typeof dbNameOrTableOptions === "string") {
|
|
2330
|
-
dbTableName = dbNameOrTableOptions;
|
|
2331
|
-
} else {
|
|
2332
|
-
options = dbNameOrTableOptions;
|
|
2333
|
-
}
|
|
2334
|
-
if (!options) {
|
|
2335
|
-
options = {};
|
|
2336
|
-
}
|
|
2337
|
-
if (!options.name) {
|
|
2338
|
-
options.name = dbTableName ?? _.snakeCase(className);
|
|
2339
|
-
}
|
|
2340
|
-
const metadataStorage = getMetadataStorage();
|
|
2341
|
-
const modelMetadata = new ModelMetadata({
|
|
2342
|
-
name: className,
|
|
2343
|
-
type: classObject,
|
|
2344
|
-
tableName: options.name,
|
|
2345
|
-
readonly: options.readonly ?? false,
|
|
2346
|
-
connection: options.connection
|
|
2347
|
-
});
|
|
2348
|
-
metadataStorage.models.push(modelMetadata);
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
|
-
function updateDateColumn(dbColumnNameOrOptions, options) {
|
|
2353
|
-
return function updateDateColumnDecorator(object, propertyName) {
|
|
2354
|
-
let dbColumnName;
|
|
2355
|
-
if (typeof dbColumnNameOrOptions === "string") {
|
|
2356
|
-
dbColumnName = dbColumnNameOrOptions;
|
|
2357
|
-
} else {
|
|
2358
|
-
options = dbColumnNameOrOptions;
|
|
2359
|
-
}
|
|
2360
|
-
if (dbColumnNameOrOptions) {
|
|
2361
|
-
if (!options) {
|
|
2362
|
-
options = {};
|
|
2363
|
-
}
|
|
2364
|
-
if (!dbColumnName) {
|
|
2365
|
-
dbColumnName = options.name ?? _.snakeCase(propertyName);
|
|
2366
|
-
}
|
|
2367
|
-
const metadataStorage = getMetadataStorage();
|
|
2368
|
-
metadataStorage.columns.push(
|
|
2369
|
-
new ColumnTypeMetadata({
|
|
2370
|
-
target: object.constructor.name,
|
|
2371
|
-
name: dbColumnName,
|
|
2372
|
-
propertyName,
|
|
2373
|
-
updateDate: true,
|
|
2374
|
-
required: options.required,
|
|
2375
|
-
type: options.type
|
|
2376
|
-
})
|
|
2377
|
-
);
|
|
2378
|
-
} else {
|
|
2379
|
-
const metadataStorage = getMetadataStorage();
|
|
2380
|
-
metadataStorage.columnModifiers.push({
|
|
2381
|
-
target: object.constructor.name,
|
|
2382
|
-
name: dbColumnName ?? _.snakeCase(propertyName),
|
|
2383
|
-
propertyName,
|
|
2384
|
-
updateDate: true,
|
|
2385
|
-
required: options ? options.required : void 0,
|
|
2386
|
-
type: options ? options.type : "datetime"
|
|
2387
|
-
});
|
|
2388
|
-
}
|
|
2389
|
-
};
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
function versionColumn(dbColumnNameOrOptions, options) {
|
|
2393
|
-
return function versionColumnDecorator(object, propertyName) {
|
|
2394
|
-
let dbColumnName;
|
|
2395
|
-
if (typeof dbColumnNameOrOptions === "string") {
|
|
2396
|
-
dbColumnName = dbColumnNameOrOptions;
|
|
2397
|
-
} else {
|
|
2398
|
-
options = dbColumnNameOrOptions;
|
|
2399
|
-
}
|
|
2400
|
-
if (dbColumnNameOrOptions) {
|
|
2401
|
-
if (!options) {
|
|
2402
|
-
options = {};
|
|
2403
|
-
}
|
|
2404
|
-
if (!dbColumnName) {
|
|
2405
|
-
dbColumnName = options.name ?? _.snakeCase(propertyName);
|
|
2406
|
-
}
|
|
2407
|
-
const metadataStorage = getMetadataStorage();
|
|
2408
|
-
metadataStorage.columns.push(
|
|
2409
|
-
new ColumnTypeMetadata({
|
|
2410
|
-
target: object.constructor.name,
|
|
2411
|
-
name: dbColumnName,
|
|
2412
|
-
propertyName,
|
|
2413
|
-
version: true,
|
|
2414
|
-
required: options.required,
|
|
2415
|
-
type: options.type
|
|
2416
|
-
})
|
|
2417
|
-
);
|
|
2418
|
-
} else {
|
|
2419
|
-
const metadataStorage = getMetadataStorage();
|
|
2420
|
-
metadataStorage.columnModifiers.push({
|
|
2421
|
-
target: object.constructor.name,
|
|
2422
|
-
name: dbColumnName ?? _.snakeCase(propertyName),
|
|
2423
|
-
propertyName,
|
|
2424
|
-
version: true,
|
|
2425
|
-
required: options ? options.required : void 0,
|
|
2426
|
-
type: options ? options.type : void 0
|
|
2427
|
-
});
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
}
|
|
2431
|
-
|
|
2432
1813
|
class Entity {
|
|
2433
1814
|
static beforeCreate(values) {
|
|
2434
1815
|
return values;
|
|
@@ -2602,4 +1983,4 @@ function initialize({ models, pool, readonlyPool = pool, connections = {}, expos
|
|
|
2602
1983
|
return repositoriesByModelName;
|
|
2603
1984
|
}
|
|
2604
1985
|
|
|
2605
|
-
export {
|
|
1986
|
+
export { ColumnModelMetadata, ColumnTypeMetadata, Entity, ModelMetadata, ReadonlyRepository, Repository, getMetadataStorage, initialize };
|