@decaf-ts/core 0.6.0 → 0.7.1
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/README.md +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/lib/esm/identity/decorators.js +6 -5
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/identity/utils.d.ts +3 -2
- package/lib/esm/identity/utils.js +7 -7
- package/lib/esm/identity/utils.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/model/construction.d.ts +2 -11
- package/lib/esm/model/construction.js +21 -33
- package/lib/esm/model/construction.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +11 -2
- package/lib/esm/model/decorators.js +91 -69
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/model/types.d.ts +6 -2
- package/lib/esm/overrides/Metadata.d.ts +14 -2
- package/lib/esm/overrides/overrides.js +31 -0
- package/lib/esm/overrides/overrides.js.map +1 -1
- package/lib/esm/persistence/Adapter.d.ts +3 -9
- package/lib/esm/persistence/Adapter.js +27 -46
- package/lib/esm/persistence/Adapter.js.map +1 -1
- package/lib/esm/persistence/Sequence.d.ts +2 -1
- package/lib/esm/persistence/Sequence.js.map +1 -1
- package/lib/esm/persistence/index.d.ts +0 -1
- package/lib/esm/persistence/index.js +0 -1
- package/lib/esm/persistence/index.js.map +1 -1
- package/lib/esm/persistence/migrations.js +1 -2
- package/lib/esm/persistence/migrations.js.map +1 -1
- package/lib/esm/query/Paginator.d.ts +4 -2
- package/lib/esm/query/Paginator.js +3 -1
- package/lib/esm/query/Paginator.js.map +1 -1
- package/lib/esm/query/Statement.d.ts +2 -1
- package/lib/esm/query/Statement.js +2 -2
- package/lib/esm/query/Statement.js.map +1 -1
- package/lib/esm/query/options.d.ts +2 -1
- package/lib/esm/query/selectors.d.ts +2 -1
- package/lib/esm/ram/RamAdapter.d.ts +2 -1
- package/lib/esm/ram/RamAdapter.js +7 -5
- package/lib/esm/ram/RamAdapter.js.map +1 -1
- package/lib/esm/ram/RamPaginator.d.ts +2 -1
- package/lib/esm/ram/RamPaginator.js +1 -1
- package/lib/esm/ram/RamPaginator.js.map +1 -1
- package/lib/esm/ram/RamStatement.js +3 -3
- package/lib/esm/ram/RamStatement.js.map +1 -1
- package/lib/esm/ram/types.d.ts +2 -1
- package/lib/esm/repository/Repository.d.ts +2 -1
- package/lib/esm/repository/Repository.js +30 -40
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/decorators.d.ts +2 -1
- package/lib/esm/repository/decorators.js +7 -8
- package/lib/esm/repository/decorators.js.map +1 -1
- package/lib/esm/repository/injectables.d.ts +1 -2
- package/lib/esm/repository/injectables.js +6 -6
- package/lib/esm/repository/injectables.js.map +1 -1
- package/lib/esm/repository/utils.d.ts +2 -2
- package/lib/esm/repository/utils.js +4 -5
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/identity/decorators.cjs +6 -5
- package/lib/identity/decorators.js.map +1 -1
- package/lib/identity/utils.cjs +5 -5
- package/lib/identity/utils.d.ts +3 -2
- package/lib/identity/utils.js.map +1 -1
- package/lib/index.cjs +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js.map +1 -1
- package/lib/model/construction.cjs +19 -31
- package/lib/model/construction.d.ts +2 -11
- package/lib/model/construction.js.map +1 -1
- package/lib/model/decorators.cjs +99 -76
- package/lib/model/decorators.d.ts +11 -2
- package/lib/model/decorators.js.map +1 -1
- package/lib/model/types.d.ts +6 -2
- package/lib/overrides/Metadata.d.ts +14 -2
- package/lib/overrides/overrides.cjs +31 -0
- package/lib/overrides/overrides.js.map +1 -1
- package/lib/persistence/Adapter.cjs +25 -44
- package/lib/persistence/Adapter.d.ts +3 -9
- package/lib/persistence/Adapter.js.map +1 -1
- package/lib/persistence/Sequence.d.ts +2 -1
- package/lib/persistence/Sequence.js.map +1 -1
- package/lib/persistence/index.cjs +0 -1
- package/lib/persistence/index.d.ts +0 -1
- package/lib/persistence/index.js.map +1 -1
- package/lib/persistence/migrations.cjs +1 -2
- package/lib/persistence/migrations.js.map +1 -1
- package/lib/query/Paginator.cjs +3 -1
- package/lib/query/Paginator.d.ts +4 -2
- package/lib/query/Paginator.js.map +1 -1
- package/lib/query/Statement.cjs +1 -1
- package/lib/query/Statement.d.ts +2 -1
- package/lib/query/Statement.js.map +1 -1
- package/lib/query/options.d.ts +2 -1
- package/lib/query/selectors.d.ts +2 -1
- package/lib/ram/RamAdapter.cjs +9 -7
- package/lib/ram/RamAdapter.d.ts +2 -1
- package/lib/ram/RamAdapter.js.map +1 -1
- package/lib/ram/RamPaginator.cjs +1 -1
- package/lib/ram/RamPaginator.d.ts +2 -1
- package/lib/ram/RamPaginator.js.map +1 -1
- package/lib/ram/RamStatement.cjs +3 -3
- package/lib/ram/RamStatement.js.map +1 -1
- package/lib/ram/types.d.ts +2 -1
- package/lib/repository/Repository.cjs +29 -39
- package/lib/repository/Repository.d.ts +2 -1
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/decorators.cjs +5 -6
- package/lib/repository/decorators.d.ts +2 -1
- package/lib/repository/decorators.js.map +1 -1
- package/lib/repository/injectables.cjs +5 -5
- package/lib/repository/injectables.d.ts +1 -2
- package/lib/repository/injectables.js.map +1 -1
- package/lib/repository/utils.cjs +4 -5
- package/lib/repository/utils.d.ts +2 -2
- package/lib/repository/utils.js.map +1 -1
- package/package.json +2 -4
- package/lib/esm/persistence/decorators.d.ts +0 -11
- package/lib/esm/persistence/decorators.js +0 -19
- package/lib/esm/persistence/decorators.js.map +0 -1
- package/lib/persistence/decorators.cjs +0 -22
- package/lib/persistence/decorators.d.ts +0 -11
- package/lib/persistence/decorators.js.map +0 -1
package/lib/model/decorators.cjs
CHANGED
|
@@ -18,14 +18,12 @@ exports.noValidateOn = noValidateOn;
|
|
|
18
18
|
exports.noValidateOnCreate = noValidateOnCreate;
|
|
19
19
|
exports.noValidateOnUpdate = noValidateOnUpdate;
|
|
20
20
|
exports.noValidateOnCreateUpdate = noValidateOnCreateUpdate;
|
|
21
|
+
exports.relation = relation;
|
|
21
22
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
22
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
23
23
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
24
24
|
const constants_1 = require("./../persistence/constants.cjs");
|
|
25
25
|
const constants_2 = require("./../repository/constants.cjs");
|
|
26
26
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
27
|
-
const persistence_1 = require("./../persistence/index.cjs");
|
|
28
|
-
const Repository_1 = require("./../repository/Repository.cjs");
|
|
29
27
|
const Condition_1 = require("./../query/Condition.cjs");
|
|
30
28
|
const construction_1 = require("./construction.cjs");
|
|
31
29
|
const utils_1 = require("./../utils/index.cjs");
|
|
@@ -38,15 +36,16 @@ const utils_1 = require("./../utils/index.cjs");
|
|
|
38
36
|
* @category Class Decorators
|
|
39
37
|
*/
|
|
40
38
|
function table(opts) {
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}
|
|
39
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.TABLE)
|
|
40
|
+
.define({
|
|
41
|
+
decorator: function table(opts) {
|
|
42
|
+
return function table(target) {
|
|
43
|
+
return (0, decoration_1.metadata)(constants_1.PersistenceKeys.TABLE, opts || target.name.toLowerCase())(target);
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
args: [opts],
|
|
47
|
+
})
|
|
48
|
+
.apply();
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
52
51
|
* @description Specifies the database column name for a model property
|
|
@@ -57,42 +56,43 @@ function table(opts) {
|
|
|
57
56
|
* @category Property Decorators
|
|
58
57
|
*/
|
|
59
58
|
function column(columnName) {
|
|
60
|
-
|
|
61
|
-
return decorator_validation_1.Decoration.for(key)
|
|
59
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.COLUMN)
|
|
62
60
|
.define({
|
|
63
|
-
decorator: function column(
|
|
61
|
+
decorator: function column(c) {
|
|
64
62
|
return function column(obj, attr) {
|
|
65
|
-
return (0,
|
|
63
|
+
return (0, decoration_1.propMetadata)(decoration_1.Metadata.key(constants_1.PersistenceKeys.COLUMN, attr), c || attr)(obj, attr);
|
|
66
64
|
};
|
|
67
65
|
},
|
|
68
|
-
args: [
|
|
66
|
+
args: [columnName],
|
|
69
67
|
})
|
|
70
68
|
.apply();
|
|
71
69
|
}
|
|
72
70
|
function index(directions, compositions, name) {
|
|
73
71
|
function index(directions, compositions, name) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
compositions = undefined;
|
|
78
|
-
}
|
|
79
|
-
if (typeof compositions === "string") {
|
|
80
|
-
name = compositions;
|
|
81
|
-
compositions = undefined;
|
|
82
|
-
}
|
|
83
|
-
if (!compositions && directions) {
|
|
84
|
-
if (directions.find((d) => ![constants_2.OrderDirection.ASC, constants_2.OrderDirection.DSC].includes(d))) {
|
|
85
|
-
compositions = directions;
|
|
72
|
+
return function index(obj, attr) {
|
|
73
|
+
if (typeof directions === "string") {
|
|
74
|
+
name = directions;
|
|
86
75
|
directions = undefined;
|
|
76
|
+
compositions = undefined;
|
|
77
|
+
}
|
|
78
|
+
if (typeof compositions === "string") {
|
|
79
|
+
name = compositions;
|
|
80
|
+
compositions = undefined;
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
if (!compositions && directions) {
|
|
83
|
+
if (directions.find((d) => ![constants_2.OrderDirection.ASC, constants_2.OrderDirection.DSC].includes(d))) {
|
|
84
|
+
compositions = directions;
|
|
85
|
+
directions = undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return (0, decoration_1.propMetadata)(decoration_1.Metadata.key(`${constants_1.PersistenceKeys.INDEX}${compositions && compositions?.length ? `.${compositions.join(".")}` : ""}`, attr), {
|
|
89
|
+
directions: directions,
|
|
90
|
+
compositions: compositions,
|
|
91
|
+
name: name,
|
|
92
|
+
})(obj, attr);
|
|
93
|
+
};
|
|
94
94
|
}
|
|
95
|
-
return
|
|
95
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.INDEX)
|
|
96
96
|
.define({
|
|
97
97
|
decorator: index,
|
|
98
98
|
args: [directions, compositions, name],
|
|
@@ -141,9 +141,9 @@ async function uniqueOnCreateUpdate(context, data, key, model) {
|
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
143
|
function unique() {
|
|
144
|
-
const key =
|
|
145
|
-
return
|
|
146
|
-
.define((0, db_decorators_1.onCreateUpdate)(uniqueOnCreateUpdate), (0,
|
|
144
|
+
const key = constants_1.PersistenceKeys.UNIQUE;
|
|
145
|
+
return decoration_1.Decoration.for(key)
|
|
146
|
+
.define((0, db_decorators_1.onCreateUpdate)(uniqueOnCreateUpdate), (0, decoration_1.propMetadata)(key, {}))
|
|
147
147
|
.apply();
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
@@ -189,9 +189,15 @@ model) {
|
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
191
|
function createdBy() {
|
|
192
|
-
const key =
|
|
193
|
-
|
|
194
|
-
.
|
|
192
|
+
const key = constants_1.PersistenceKeys.CREATED_BY;
|
|
193
|
+
function createdBy() {
|
|
194
|
+
return (0, decoration_1.apply)((0, db_decorators_1.onCreate)(createdByOnCreateUpdate), (0, decoration_1.propMetadata)(key, {}));
|
|
195
|
+
}
|
|
196
|
+
return decoration_1.Decoration.for(key)
|
|
197
|
+
.define({
|
|
198
|
+
decorator: createdBy,
|
|
199
|
+
args: [],
|
|
200
|
+
})
|
|
195
201
|
.apply();
|
|
196
202
|
}
|
|
197
203
|
/**
|
|
@@ -209,9 +215,15 @@ function createdBy() {
|
|
|
209
215
|
* ```
|
|
210
216
|
*/
|
|
211
217
|
function updatedBy() {
|
|
212
|
-
const key =
|
|
213
|
-
|
|
214
|
-
.
|
|
218
|
+
const key = constants_1.PersistenceKeys.UPDATED_BY;
|
|
219
|
+
function updatedBy() {
|
|
220
|
+
return (0, decoration_1.apply)((0, db_decorators_1.onUpdate)(createdByOnCreateUpdate), (0, decoration_1.propMetadata)(key, {}));
|
|
221
|
+
}
|
|
222
|
+
return decoration_1.Decoration.for(key)
|
|
223
|
+
.define({
|
|
224
|
+
decorator: updatedBy,
|
|
225
|
+
args: [],
|
|
226
|
+
})
|
|
215
227
|
.apply();
|
|
216
228
|
}
|
|
217
229
|
function createdAt() {
|
|
@@ -246,11 +258,10 @@ function updatedAt() {
|
|
|
246
258
|
* @see manyToOne
|
|
247
259
|
*/
|
|
248
260
|
function oneToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate = true, joinColumnOpts, fk) {
|
|
249
|
-
const key =
|
|
250
|
-
// Model.register(clazz as Constructor<M>);
|
|
261
|
+
const key = constants_1.PersistenceKeys.ONE_TO_ONE;
|
|
251
262
|
function oneToOneDec(clazz, cascade, populate, joinColumnOpts, fk) {
|
|
252
263
|
const meta = {
|
|
253
|
-
class: clazz
|
|
264
|
+
class: clazz,
|
|
254
265
|
cascade: cascade,
|
|
255
266
|
populate: populate,
|
|
256
267
|
};
|
|
@@ -258,14 +269,9 @@ function oneToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate =
|
|
|
258
269
|
meta.joinTable = joinColumnOpts;
|
|
259
270
|
if (fk)
|
|
260
271
|
meta.name = fk;
|
|
261
|
-
return (0,
|
|
262
|
-
clazz.name ? clazz.name : clazz,
|
|
263
|
-
String.name,
|
|
264
|
-
Number.name,
|
|
265
|
-
BigInt.name,
|
|
266
|
-
]), (0, db_decorators_1.onCreate)(construction_1.oneToOneOnCreate, meta), (0, db_decorators_1.onUpdate)(construction_1.oneToOneOnUpdate, meta), (0, db_decorators_1.onDelete)(construction_1.oneToOneOnDelete, meta), (0, db_decorators_1.afterAny)(construction_1.populate, meta), (0, decorator_validation_1.propMetadata)(key, meta));
|
|
272
|
+
return (0, decoration_1.apply)((0, decoration_1.prop)(), relation(key, meta), (0, decorator_validation_1.type)([clazz, String, Number, BigInt]), (0, db_decorators_1.onCreate)(construction_1.oneToOneOnCreate, meta), (0, db_decorators_1.onUpdate)(construction_1.oneToOneOnUpdate, meta), (0, db_decorators_1.onDelete)(construction_1.oneToOneOnDelete, meta), (0, db_decorators_1.afterAny)(construction_1.populate, meta));
|
|
267
273
|
}
|
|
268
|
-
return
|
|
274
|
+
return decoration_1.Decoration.for(key)
|
|
269
275
|
.define({
|
|
270
276
|
decorator: oneToOneDec,
|
|
271
277
|
args: [clazz, cascadeOptions, populate, joinColumnOpts, fk],
|
|
@@ -301,10 +307,10 @@ function oneToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate =
|
|
|
301
307
|
* @see manyToOne
|
|
302
308
|
*/
|
|
303
309
|
function oneToMany(clazz, cascadeOptions = constants_2.DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
304
|
-
const key =
|
|
310
|
+
const key = constants_1.PersistenceKeys.ONE_TO_MANY;
|
|
305
311
|
function oneToManyDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
306
312
|
const metadata = {
|
|
307
|
-
class: clazz
|
|
313
|
+
class: clazz,
|
|
308
314
|
cascade: cascade,
|
|
309
315
|
populate: populate,
|
|
310
316
|
};
|
|
@@ -312,15 +318,15 @@ function oneToMany(clazz, cascadeOptions = constants_2.DefaultCascade, populate
|
|
|
312
318
|
metadata.joinTable = joinTableOpts;
|
|
313
319
|
if (fk)
|
|
314
320
|
metadata.name = fk;
|
|
315
|
-
return (0,
|
|
321
|
+
return (0, decoration_1.apply)((0, decoration_1.prop)(), relation(key, metadata), (0, decorator_validation_1.list)([
|
|
316
322
|
clazz,
|
|
317
323
|
String,
|
|
318
324
|
Number,
|
|
319
325
|
// @ts-expect-error Bigint is not a constructor
|
|
320
326
|
BigInt,
|
|
321
|
-
]), (0, db_decorators_1.onCreate)(construction_1.oneToManyOnCreate, metadata), (0, db_decorators_1.onUpdate)(construction_1.oneToManyOnUpdate, metadata), (0, db_decorators_1.onDelete)(construction_1.oneToManyOnDelete, metadata), (0, db_decorators_1.afterAny)(construction_1.populate, metadata)
|
|
327
|
+
]), (0, db_decorators_1.onCreate)(construction_1.oneToManyOnCreate, metadata), (0, db_decorators_1.onUpdate)(construction_1.oneToManyOnUpdate, metadata), (0, db_decorators_1.onDelete)(construction_1.oneToManyOnDelete, metadata), (0, db_decorators_1.afterAny)(construction_1.populate, metadata));
|
|
322
328
|
}
|
|
323
|
-
return
|
|
329
|
+
return decoration_1.Decoration.for(key)
|
|
324
330
|
.define({
|
|
325
331
|
decorator: oneToManyDec,
|
|
326
332
|
args: [clazz, cascadeOptions, populate, joinTableOpts, fk],
|
|
@@ -357,11 +363,10 @@ function oneToMany(clazz, cascadeOptions = constants_2.DefaultCascade, populate
|
|
|
357
363
|
*/
|
|
358
364
|
function manyToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
359
365
|
// Model.register(clazz as Constructor<M>);
|
|
360
|
-
const key =
|
|
366
|
+
const key = constants_1.PersistenceKeys.MANY_TO_ONE;
|
|
361
367
|
function manyToOneDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
362
|
-
const clazzName = () => (clazz?.name ? clazz : clazz()).name;
|
|
363
368
|
const metadata = {
|
|
364
|
-
class: clazz
|
|
369
|
+
class: clazz,
|
|
365
370
|
cascade: cascade,
|
|
366
371
|
populate: populate,
|
|
367
372
|
};
|
|
@@ -369,14 +374,14 @@ function manyToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate
|
|
|
369
374
|
metadata.joinTable = joinTableOpts;
|
|
370
375
|
if (fk)
|
|
371
376
|
metadata.name = fk;
|
|
372
|
-
return (0,
|
|
377
|
+
return (0, decoration_1.apply)((0, decoration_1.prop)(), relation(key, metadata), (0, decorator_validation_1.type)([clazz, String, Number, BigInt])
|
|
373
378
|
// onCreate(oneToManyOnCreate, metadata),
|
|
374
379
|
// onUpdate(oneToManyOnUpdate, metadata),
|
|
375
380
|
// onDelete(oneToManyOnDelete, metadata),
|
|
376
381
|
// afterAny(pop, metadata),
|
|
377
|
-
|
|
382
|
+
);
|
|
378
383
|
}
|
|
379
|
-
return
|
|
384
|
+
return decoration_1.Decoration.for(key)
|
|
380
385
|
.define({
|
|
381
386
|
decorator: manyToOneDec,
|
|
382
387
|
args: [clazz, cascadeOptions, populate, joinTableOpts, fk],
|
|
@@ -413,10 +418,10 @@ function manyToOne(clazz, cascadeOptions = constants_2.DefaultCascade, populate
|
|
|
413
418
|
*/
|
|
414
419
|
function manyToMany(clazz, cascadeOptions = constants_2.DefaultCascade, populate = true, joinTableOpts, fk) {
|
|
415
420
|
// Model.register(clazz as Constructor<M>);
|
|
416
|
-
const key =
|
|
421
|
+
const key = constants_1.PersistenceKeys.MANY_TO_MANY;
|
|
417
422
|
function manyToManyDec(clazz, cascade, populate, joinTableOpts, fk) {
|
|
418
423
|
const metadata = {
|
|
419
|
-
class: clazz
|
|
424
|
+
class: clazz,
|
|
420
425
|
cascade: cascade,
|
|
421
426
|
populate: populate,
|
|
422
427
|
};
|
|
@@ -424,19 +429,14 @@ function manyToMany(clazz, cascadeOptions = constants_2.DefaultCascade, populate
|
|
|
424
429
|
metadata.joinTable = joinTableOpts;
|
|
425
430
|
if (fk)
|
|
426
431
|
metadata.name = fk;
|
|
427
|
-
return (0,
|
|
428
|
-
clazz.name ? clazz.name : clazz,
|
|
429
|
-
String.name,
|
|
430
|
-
Number.name,
|
|
431
|
-
BigInt.name,
|
|
432
|
-
]),
|
|
432
|
+
return (0, decoration_1.apply)((0, decoration_1.prop)(), relation(key, metadata), (0, decorator_validation_1.list)([clazz, String, Number, BigInt])
|
|
433
433
|
// onCreate(oneToManyOnCreate, metadata),
|
|
434
434
|
// onUpdate(oneToManyOnUpdate, metadata),
|
|
435
435
|
// onDelete(oneToManyOnDelete, metadata),
|
|
436
436
|
// afterAll(populate, metadata),
|
|
437
|
-
|
|
437
|
+
);
|
|
438
438
|
}
|
|
439
|
-
return
|
|
439
|
+
return decoration_1.Decoration.for(key)
|
|
440
440
|
.define({
|
|
441
441
|
decorator: manyToManyDec,
|
|
442
442
|
args: [clazz, cascadeOptions, populate, joinTableOpts, fk],
|
|
@@ -459,4 +459,27 @@ function noValidateOnUpdate() {
|
|
|
459
459
|
function noValidateOnCreateUpdate() {
|
|
460
460
|
return noValidateOn(db_decorators_1.OperationKeys.UPDATE, db_decorators_1.OperationKeys.CREATE);
|
|
461
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* @description Specifies the model property as a relation
|
|
464
|
+
* @summary Decorator that specifies the model property as a relation in the database
|
|
465
|
+
* @return {Function} A decorator function that can be applied to a class property
|
|
466
|
+
* @function relation
|
|
467
|
+
* @category Property Decorators
|
|
468
|
+
*/
|
|
469
|
+
function relation(relationKey, meta) {
|
|
470
|
+
function relation(relationKey, meta) {
|
|
471
|
+
return function relation(obj, attr) {
|
|
472
|
+
(0, decoration_1.propMetadata)(relationKey, meta)(obj, attr);
|
|
473
|
+
return (0, decoration_1.propMetadata)(decoration_1.Metadata.key(constants_1.PersistenceKeys.RELATIONS, attr), Object.assign({}, meta, {
|
|
474
|
+
key: relationKey,
|
|
475
|
+
}))(obj, attr);
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return decoration_1.Decoration.for(constants_1.PersistenceKeys.RELATIONS)
|
|
479
|
+
.define({
|
|
480
|
+
decorator: relation,
|
|
481
|
+
args: [relationKey, meta],
|
|
482
|
+
})
|
|
483
|
+
.apply();
|
|
484
|
+
}
|
|
462
485
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Context, OperationKeys, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
2
|
+
import { propMetadata, Constructor } from "@decaf-ts/decoration";
|
|
2
3
|
import { CascadeMetadata } from "../repository/types";
|
|
3
4
|
import { OrderDirection } from "../repository/constants";
|
|
4
|
-
import {
|
|
5
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
6
|
import { Repo } from "../repository/Repository";
|
|
6
7
|
import { JoinColumnOptions, JoinTableMultipleColumnsOptions, JoinTableOptions, RelationsMetadata } from "./types";
|
|
7
8
|
/**
|
|
@@ -12,7 +13,7 @@ import { JoinColumnOptions, JoinTableMultipleColumnsOptions, JoinTableOptions, R
|
|
|
12
13
|
* @function table
|
|
13
14
|
* @category Class Decorators
|
|
14
15
|
*/
|
|
15
|
-
export declare function table<OPTS = string>(opts?: OPTS): (target: any) => any;
|
|
16
|
+
export declare function table<OPTS = string>(opts?: OPTS): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
16
17
|
/**
|
|
17
18
|
* @description Specifies the database column name for a model property
|
|
18
19
|
* @summary Decorator that maps a model property to a specific column name in the database
|
|
@@ -238,3 +239,11 @@ export declare function noValidateOn(...ops: OperationKeys[]): (target: any, pro
|
|
|
238
239
|
export declare function noValidateOnCreate(): (target: any, propertyKey?: any) => void;
|
|
239
240
|
export declare function noValidateOnUpdate(): (target: any, propertyKey?: any) => void;
|
|
240
241
|
export declare function noValidateOnCreateUpdate(): (target: any, propertyKey?: any) => void;
|
|
242
|
+
/**
|
|
243
|
+
* @description Specifies the model property as a relation
|
|
244
|
+
* @summary Decorator that specifies the model property as a relation in the database
|
|
245
|
+
* @return {Function} A decorator function that can be applied to a class property
|
|
246
|
+
* @function relation
|
|
247
|
+
* @category Property Decorators
|
|
248
|
+
*/
|
|
249
|
+
export declare function relation(relationKey: string, meta: RelationsMetadata): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/model/decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/model/decorators.ts"],"names":[],"mappings":";;AAuDA,sBAcC;AAUD,wBAcC;AAyBD,sBAmDC;AAmBD,oDAqBC;AAiBD,wBAKC;AAmBD,0DAoBC;AAgBD,8BAaC;AAgBD,8BAWC;AAED,8BAEC;AAED,8BAEC;AA2BD,4BAuCC;AA8BD,8BA8CC;AA8BD,8BAyCC;AA8BD,gCAwCC;AAED,oCAeC;AAED,gDAEC;AAED,gDAEC;AAED,4DAEC;AASD,4BAmBC;AAlqBD,2DAWiC;AACjC,qDAU8B;AAC9B,8DAA2D;AAE3D,6DAAyE;AACzE,yEAAmE;AAGnE,wDAA+C;AAO/C,qDAQwB;AACxB,gDAA8C;AAE9C;;;;;;;GAOG;AACH,SAAgB,KAAK,CAAgB,IAAW;IAC9C,OAAO,uBAAU,CAAC,GAAG,CAAC,2BAAe,CAAC,KAAK,CAAC;SACzC,MAAM,CAAC;QACN,SAAS,EAAE,SAAS,KAAK,CAAC,IAAU;YAClC,OAAO,SAAS,KAAK,CAAC,MAAW;gBAC/B,OAAO,IAAA,qBAAQ,EACb,2BAAe,CAAC,KAAK,EACrB,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAClC,CAAC,MAAM,CAAC,CAAC;YACZ,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,EAAE,CAAC,IAAI,CAAC;KACb,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,MAAM,CAAgB,UAAiB;IACrD,OAAO,uBAAU,CAAC,GAAG,CAAC,2BAAe,CAAC,MAAM,CAAC;SAC1C,MAAM,CAAC;QACN,SAAS,EAAE,SAAS,MAAM,CAAC,CAAC;YAC1B,OAAO,SAAS,MAAM,CAAC,GAAQ,EAAE,IAAS;gBACxC,OAAO,IAAA,yBAAY,EACjB,qBAAQ,CAAC,GAAG,CAAC,2BAAe,CA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AM,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,YAAY,CAAC,6BAAa,CAAC,MAAM,EAAE,6BAAa,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,WAAmB,EAAE,IAAuB;IACnE,SAAS,QAAQ,CAAC,WAAmB,EAAE,IAAuB;QAC5D,OAAO,SAAS,QAAQ,CAAC,GAAQ,EAAE,IAAS;YAC1C,IAAA,yBAAY,EAAC,WAAW,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3C,OAAO,IAAA,yBAAY,EACjB,qBAAQ,CAAC,GAAG,CAAC,2BAAe,CAAC,SAAS,EAAE,IAAI,CAAC,EAC7C,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE;gBACtB,GAAG,EAAE,WAAW;aACjB,CAAC,CACH,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,uBAAU,CAAC,GAAG,CAAC,2BAAe,CAAC,SAAS,CAAC;SAC7C,MAAM,CAAC;QACN,SAAS,EAAE,QAAQ;QACnB,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC;KAC1B,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC"}
|
package/lib/model/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
1
2
|
import { CascadeMetadata } from "../repository";
|
|
2
|
-
import {
|
|
3
|
+
import { PersistenceKeys } from "../persistence/index";
|
|
3
4
|
/**
|
|
4
5
|
* Describes join column options.
|
|
5
6
|
*/
|
|
@@ -48,9 +49,12 @@ export type JoinTableMultipleColumnsOptions = {
|
|
|
48
49
|
inverseJoinColumns?: JoinColumnOptions[];
|
|
49
50
|
};
|
|
50
51
|
export type RelationsMetadata = {
|
|
51
|
-
class:
|
|
52
|
+
class: Constructor<any> | (() => Constructor<any>);
|
|
52
53
|
cascade: CascadeMetadata;
|
|
53
54
|
populate: boolean;
|
|
54
55
|
name?: string;
|
|
55
56
|
joinTable?: JoinTableOptions;
|
|
56
57
|
};
|
|
58
|
+
export type ExtendedRelationsMetadata = RelationsMetadata & {
|
|
59
|
+
key: PersistenceKeys.ONE_TO_ONE | PersistenceKeys.ONE_TO_MANY | PersistenceKeys.MANY_TO_ONE | PersistenceKeys.MANY_TO_MANY;
|
|
60
|
+
};
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import "@decaf-ts/decoration";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { Context, OperationKeys, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
4
|
-
import type { Adapter, Migration } from "../persistence
|
|
4
|
+
import type { Adapter, Migration } from "../persistence";
|
|
5
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
6
|
+
import type { ExtendedRelationsMetadata } from "../model";
|
|
5
7
|
declare module "@decaf-ts/decoration" {
|
|
6
8
|
namespace Metadata {
|
|
7
9
|
function validationExceptions<M extends Model>(model: Constructor<M>, op: OperationKeys): string[];
|
|
8
10
|
function migrationsFor<A extends Adapter<CONF, CONN, QUERY, FLAGS, CONTEXT>, CONF, CONN, QUERY, FLAGS extends RepositoryFlags = RepositoryFlags, CONTEXT extends Context<FLAGS> = Context<FLAGS>>(adapter?: A): Constructor<Migration<any, A, CONF, CONN, QUERY, FLAGS, CONTEXT>>[];
|
|
11
|
+
function relations<M extends Model>(m: Constructor<M>): string[] | undefined;
|
|
12
|
+
function relations<M extends Model>(m: Constructor<M>, prop: keyof M): ExtendedRelationsMetadata;
|
|
13
|
+
function relations<M extends Model>(m: Constructor<M>, prop?: keyof M): string[] | ExtendedRelationsMetadata | undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
17
|
+
namespace Model {
|
|
18
|
+
function relations<M extends Model>(m: Constructor<M>): string[];
|
|
19
|
+
function relations<M extends Model>(m: Constructor<M>, prop: keyof M): ExtendedRelationsMetadata;
|
|
20
|
+
function relations<M extends Model>(m: Constructor<M>, prop?: keyof M): string[] | ExtendedRelationsMetadata;
|
|
9
21
|
}
|
|
10
22
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
4
|
+
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
4
5
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
5
6
|
const index_1 = require("./../persistence/index.cjs");
|
|
6
7
|
decoration_1.Metadata.validationExceptions = function (model, op) {
|
|
@@ -11,6 +12,23 @@ decoration_1.Metadata.validationExceptions = function (model, op) {
|
|
|
11
12
|
.filter(([, val]) => val.includes(op))
|
|
12
13
|
.map(([key]) => key);
|
|
13
14
|
}.bind(decoration_1.Metadata);
|
|
15
|
+
decorator_validation_1.Model.shouldValidateNestedHandler = function (model, property) {
|
|
16
|
+
const metadata = decoration_1.Metadata.get(model.constructor);
|
|
17
|
+
if (!metadata)
|
|
18
|
+
return false;
|
|
19
|
+
const relations = metadata[index_1.PersistenceKeys.RELATIONS];
|
|
20
|
+
const relation = metadata[index_1.PersistenceKeys.RELATION];
|
|
21
|
+
if (Array.isArray(relations) && relations?.includes(property)) {
|
|
22
|
+
const relationName = Object.keys(relation)[0];
|
|
23
|
+
const relationClassName = decorator_validation_1.Model.isPropertyModel(model, property);
|
|
24
|
+
return (relation[relationName]?.class !== relationClassName
|
|
25
|
+
// TODO: Revisit this
|
|
26
|
+
// ||
|
|
27
|
+
// relation[relationName]?.populate !== false
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}.bind(decorator_validation_1.Model);
|
|
14
32
|
decoration_1.Metadata.migrationsFor = function (adapter) {
|
|
15
33
|
adapter = adapter ?? index_1.Adapter.current;
|
|
16
34
|
if (!adapter)
|
|
@@ -18,4 +36,17 @@ decoration_1.Metadata.migrationsFor = function (adapter) {
|
|
|
18
36
|
const migrations = decoration_1.Metadata["innerGet"](Symbol.for(index_1.PersistenceKeys.MIGRATION), adapter.alias);
|
|
19
37
|
return migrations.map((m) => m.class);
|
|
20
38
|
}.bind(decoration_1.Metadata);
|
|
39
|
+
decoration_1.Metadata.relations = function (m, prop) {
|
|
40
|
+
const meta = decoration_1.Metadata.get(m, index_1.PersistenceKeys.RELATIONS);
|
|
41
|
+
if (!meta)
|
|
42
|
+
return undefined;
|
|
43
|
+
if (!prop)
|
|
44
|
+
return Object.keys(meta);
|
|
45
|
+
if (!meta[prop])
|
|
46
|
+
throw new db_decorators_1.InternalError(`No relations metadata found for property ${prop}`);
|
|
47
|
+
return meta[prop];
|
|
48
|
+
}.bind(decoration_1.Metadata);
|
|
49
|
+
decorator_validation_1.Model.relations = function (m, prop) {
|
|
50
|
+
return decoration_1.Metadata.relations(m, prop) || [];
|
|
51
|
+
};
|
|
21
52
|
//# sourceMappingURL=overrides.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../src/overrides/overrides.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../src/overrides/overrides.ts"],"names":[],"mappings":";;AAAA,qDAA6D;AAC7D,yEAAuD;AACvD,2DAKiC;AACjC,sDAAgF;AAG/E,qBAAgB,CAAC,oBAAoB,GAAG,UAEvC,KAAqB,EACrB,EAAiB;IAEjB,MAAM,YAAY,GAChB,qBAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,uBAAe,CAAC,WAAW,CAAC,CAAC;IACnD,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAE7B,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;SAChC,M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,MAAM,UAAU,GAAG,qBAAQ,CAAC,UAAU,CAAC,CACrC,MAAM,CAAC,GAAG,CAAC,uBAAe,CAAC,SAAS,CAAC,EACrC,OAAO,CAAC,KAAK,CACd,CAAC;IACF,OAAO,UAAU,CAAC,GAAG,CACnB,CAAC,CAEA,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CACd,CAAC;AACJ,CAAC,CAAC,IAAI,CAAC,qBAAQ,CAAC,CAAC;AAEhB,qBAAgB,CAAC,SAAS,GAAG,UAC5B,CAAiB,EACjB,IAAc;IAEd,MAAM,IAAI,GAAG,qBAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,uBAAe,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,IAAI,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,IAAI,CAAC,IAAc,CAAC;QACvB,MAAM,IAAI,6BAAa,CACrB,4CAA4C,IAAc,EAAE,CAC7D,CAAC;IACJ,OAAO,IAAI,CAAC,IAAc,CAAC,CAAC;AAC9B,CAAC,CAAC,IAAI,CAAC,qBAAQ,CAAC,CAAC;AAEhB,4BAAa,CAAC,SAAS,GAAG,UACzB,CAAiB,EACjB,IAAc;IAEd,OAAO,qBAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;AAC3C,CAAC,CAAC"}
|
|
@@ -17,27 +17,35 @@ const utils_1 = require("./../utils/index.cjs");
|
|
|
17
17
|
const ObserverHandler_1 = require("./ObserverHandler.cjs");
|
|
18
18
|
const logging_1 = require("@decaf-ts/logging");
|
|
19
19
|
const utils_2 = require("./../identity/utils.cjs");
|
|
20
|
-
const db_decorators_2 = require("@decaf-ts/db-decorators");
|
|
21
20
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
22
21
|
const errors_1 = require("./errors.cjs");
|
|
23
|
-
|
|
22
|
+
const flavourResolver = decoration_1.Decoration["flavourResolver"].bind(decoration_1.Decoration);
|
|
23
|
+
decoration_1.Decoration["flavourResolver"] = (obj) => {
|
|
24
24
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
const result = flavourResolver(obj);
|
|
26
|
+
if (result && result !== decoration_1.DefaultFlavour)
|
|
27
|
+
return result;
|
|
28
|
+
const targetCtor = typeof obj === "function"
|
|
29
|
+
? obj
|
|
30
|
+
: obj?.constructor;
|
|
31
|
+
const registeredFlavour = targetCtor && typeof decoration_1.Metadata["registeredFlavour"] === "function"
|
|
32
|
+
? decoration_1.Metadata.registeredFlavour(targetCtor)
|
|
33
|
+
: undefined;
|
|
34
|
+
if (registeredFlavour && registeredFlavour !== decoration_1.DefaultFlavour)
|
|
35
|
+
return registeredFlavour;
|
|
36
|
+
const currentFlavour = Adapter["_currentFlavour"];
|
|
37
|
+
if (currentFlavour) {
|
|
38
|
+
const cachedAdapter = Adapter["_cache"]?.[currentFlavour];
|
|
39
|
+
if (cachedAdapter?.flavour)
|
|
40
|
+
return cachedAdapter.flavour;
|
|
41
|
+
return currentFlavour;
|
|
42
|
+
}
|
|
35
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
44
|
}
|
|
37
45
|
catch (e) {
|
|
38
|
-
return
|
|
46
|
+
return decoration_1.DefaultFlavour;
|
|
39
47
|
}
|
|
40
|
-
}
|
|
48
|
+
};
|
|
41
49
|
/**
|
|
42
50
|
* @description Abstract Facade class for persistence adapters
|
|
43
51
|
* @summary Provides the foundation for all database adapters in the persistence layer. This class
|
|
@@ -304,7 +312,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
304
312
|
*/
|
|
305
313
|
prepare(model, pk) {
|
|
306
314
|
const log = this.log.for(this.prepare);
|
|
307
|
-
const split =
|
|
315
|
+
const split = model.segregate();
|
|
308
316
|
const result = Object.entries(split.model).reduce((accum, [key, val]) => {
|
|
309
317
|
if (typeof val === "undefined")
|
|
310
318
|
return accum;
|
|
@@ -518,8 +526,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
518
526
|
* @return {string} The adapter flavor name
|
|
519
527
|
*/
|
|
520
528
|
static flavourOf(model) {
|
|
521
|
-
return
|
|
522
|
-
this.current?.flavour);
|
|
529
|
+
return decoration_1.Metadata.flavourOf(model);
|
|
523
530
|
}
|
|
524
531
|
static get currentFlavour() {
|
|
525
532
|
if (!Adapter._currentFlavour)
|
|
@@ -561,15 +568,6 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
561
568
|
static setCurrent(flavour) {
|
|
562
569
|
this._currentFlavour = flavour;
|
|
563
570
|
}
|
|
564
|
-
/**
|
|
565
|
-
* @description Creates a metadata key
|
|
566
|
-
* @summary Generates a standardized metadata key for persistence-related metadata
|
|
567
|
-
* @param {string} key - The base key name
|
|
568
|
-
* @return {string} The formatted metadata key
|
|
569
|
-
*/
|
|
570
|
-
static key(key) {
|
|
571
|
-
return db_decorators_2.Repository.key(key);
|
|
572
|
-
}
|
|
573
571
|
/**
|
|
574
572
|
* @description Gets all models associated with an adapter flavor
|
|
575
573
|
* @summary Retrieves all model constructors that are configured to use a specific adapter flavor
|
|
@@ -579,24 +577,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
579
577
|
*/
|
|
580
578
|
static models(flavour) {
|
|
581
579
|
try {
|
|
582
|
-
|
|
583
|
-
const cache = registry.cache;
|
|
584
|
-
const managedModels = Object.values(cache)
|
|
585
|
-
.map((m) => {
|
|
586
|
-
let f = Reflect.getMetadata(Adapter.key(constants_1.PersistenceKeys.ADAPTER), m);
|
|
587
|
-
if (f && f === flavour)
|
|
588
|
-
return m;
|
|
589
|
-
if (!f) {
|
|
590
|
-
const repo = Reflect.getMetadata(db_decorators_2.Repository.key(db_decorators_1.DBKeys.REPOSITORY), m);
|
|
591
|
-
if (!repo)
|
|
592
|
-
return;
|
|
593
|
-
const repository = this._baseRepository.forModel(m);
|
|
594
|
-
f = Reflect.getMetadata(Adapter.key(constants_1.PersistenceKeys.ADAPTER), repository);
|
|
595
|
-
return f;
|
|
596
|
-
}
|
|
597
|
-
})
|
|
598
|
-
.filter((m) => !!m);
|
|
599
|
-
return managedModels;
|
|
580
|
+
return decoration_1.Metadata.flavouredAs(flavour);
|
|
600
581
|
}
|
|
601
582
|
catch (e) {
|
|
602
583
|
throw new db_decorators_1.InternalError(e);
|