joist-orm 0.1.536 → 1.0.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/build/{BaseEntity.d.ts → src/BaseEntity.d.ts} +2 -1
- package/build/{BaseEntity.js → src/BaseEntity.js} +13 -9
- package/build/src/BaseEntity.js.map +1 -0
- package/build/{EntityManager.d.ts → src/EntityManager.d.ts} +139 -110
- package/build/{EntityManager.js → src/EntityManager.js} +281 -262
- package/build/src/EntityManager.js.map +1 -0
- package/build/{QueryBuilder.d.ts → src/QueryBuilder.d.ts} +53 -3
- package/build/src/QueryBuilder.js +341 -0
- package/build/src/QueryBuilder.js.map +1 -0
- package/build/src/Todo.d.ts +25 -0
- package/build/src/Todo.js +52 -0
- package/build/src/Todo.js.map +1 -0
- package/build/src/changes.d.ts +34 -0
- package/build/src/changes.js +37 -0
- package/build/src/changes.js.map +1 -0
- package/build/src/config.d.ts +43 -0
- package/build/src/config.js +114 -0
- package/build/src/config.js.map +1 -0
- package/build/{createOrUpdatePartial.d.ts → src/createOrUpdatePartial.d.ts} +2 -1
- package/build/{createOrUpdatePartial.js → src/createOrUpdatePartial.js} +42 -10
- package/build/src/createOrUpdatePartial.js.map +1 -0
- package/build/src/dataloaders/findDataLoader.d.ts +5 -0
- package/build/src/dataloaders/findDataLoader.js +28 -0
- package/build/src/dataloaders/findDataLoader.js.map +1 -0
- package/build/src/dataloaders/loadDataLoader.d.ts +3 -0
- package/build/src/dataloaders/loadDataLoader.js +37 -0
- package/build/src/dataloaders/loadDataLoader.js.map +1 -0
- package/build/src/dataloaders/manyToManyDataLoader.d.ts +5 -0
- package/build/src/dataloaders/manyToManyDataLoader.js +78 -0
- package/build/src/dataloaders/manyToManyDataLoader.js.map +1 -0
- package/build/src/dataloaders/manyToManyFindDataLoader.d.ts +5 -0
- package/build/src/dataloaders/manyToManyFindDataLoader.js +33 -0
- package/build/src/dataloaders/manyToManyFindDataLoader.js.map +1 -0
- package/build/src/dataloaders/oneToManyDataLoader.d.ts +4 -0
- package/build/src/dataloaders/oneToManyDataLoader.js +40 -0
- package/build/src/dataloaders/oneToManyDataLoader.js.map +1 -0
- package/build/src/dataloaders/oneToManyFindDataLoader.d.ts +5 -0
- package/build/src/dataloaders/oneToManyFindDataLoader.js +32 -0
- package/build/src/dataloaders/oneToManyFindDataLoader.js.map +1 -0
- package/build/src/dataloaders/oneToOneDataLoader.d.ts +4 -0
- package/build/src/dataloaders/oneToOneDataLoader.js +40 -0
- package/build/src/dataloaders/oneToOneDataLoader.js.map +1 -0
- package/build/src/drivers/IdAssigner.d.ts +33 -0
- package/build/src/drivers/IdAssigner.js +106 -0
- package/build/src/drivers/IdAssigner.js.map +1 -0
- package/build/src/drivers/InMemoryDriver.d.ts +29 -0
- package/build/src/drivers/InMemoryDriver.js +306 -0
- package/build/src/drivers/InMemoryDriver.js.map +1 -0
- package/build/src/drivers/PostgresDriver.d.ts +40 -0
- package/build/src/drivers/PostgresDriver.js +376 -0
- package/build/src/drivers/PostgresDriver.js.map +1 -0
- package/build/src/drivers/driver.d.ts +23 -0
- package/build/src/drivers/driver.js +3 -0
- package/build/src/drivers/driver.js.map +1 -0
- package/build/src/drivers/index.d.ts +4 -0
- package/build/src/drivers/index.js +17 -0
- package/build/src/drivers/index.js.map +1 -0
- package/build/{getProperties.d.ts → src/getProperties.d.ts} +0 -0
- package/build/{getProperties.js → src/getProperties.js} +1 -1
- package/build/src/getProperties.js.map +1 -0
- package/build/src/index.d.ts +62 -0
- package/build/src/index.js +263 -0
- package/build/src/index.js.map +1 -0
- package/build/src/keys.d.ts +30 -0
- package/build/{keys.js → src/keys.js} +48 -16
- package/build/src/keys.js.map +1 -0
- package/build/{loadLens.d.ts → src/loadLens.d.ts} +2 -2
- package/build/{loadLens.js → src/loadLens.js} +1 -1
- package/build/src/loadLens.js.map +1 -0
- package/build/src/loaded.d.ts +49 -0
- package/build/src/loaded.js +9 -0
- package/build/src/loaded.js.map +1 -0
- package/build/{newTestInstance.d.ts → src/newTestInstance.d.ts} +37 -3
- package/build/src/newTestInstance.js +342 -0
- package/build/src/newTestInstance.js.map +1 -0
- package/build/{collections → src/relations}/AbstractRelationImpl.d.ts +6 -5
- package/build/{collections → src/relations}/AbstractRelationImpl.js +0 -0
- package/build/src/relations/AbstractRelationImpl.js.map +1 -0
- package/build/src/relations/Collection.d.ts +26 -0
- package/build/src/relations/Collection.js +19 -0
- package/build/src/relations/Collection.js.map +1 -0
- package/build/{collections → src/relations}/CustomCollection.d.ts +6 -2
- package/build/{collections → src/relations}/CustomCollection.js +17 -9
- package/build/src/relations/CustomCollection.js.map +1 -0
- package/build/{collections → src/relations}/CustomReference.d.ts +7 -2
- package/build/{collections → src/relations}/CustomReference.js +16 -9
- package/build/src/relations/CustomReference.js.map +1 -0
- package/build/src/relations/LargeCollection.d.ts +17 -0
- package/build/src/relations/LargeCollection.js +3 -0
- package/build/src/relations/LargeCollection.js.map +1 -0
- package/build/{collections → src/relations}/ManyToManyCollection.d.ts +9 -2
- package/build/src/relations/ManyToManyCollection.js +249 -0
- package/build/src/relations/ManyToManyCollection.js.map +1 -0
- package/build/src/relations/ManyToManyLargeCollection.d.ts +25 -0
- package/build/src/relations/ManyToManyLargeCollection.js +97 -0
- package/build/src/relations/ManyToManyLargeCollection.js.map +1 -0
- package/build/src/relations/ManyToOneReference.d.ts +77 -0
- package/build/{collections → src/relations}/ManyToOneReference.js +101 -48
- package/build/src/relations/ManyToOneReference.js.map +1 -0
- package/build/{collections → src/relations}/OneToManyCollection.d.ts +10 -2
- package/build/{collections → src/relations}/OneToManyCollection.js +54 -59
- package/build/src/relations/OneToManyCollection.js.map +1 -0
- package/build/src/relations/OneToManyLargeCollection.d.ts +25 -0
- package/build/src/relations/OneToManyLargeCollection.js +83 -0
- package/build/src/relations/OneToManyLargeCollection.js.map +1 -0
- package/build/src/relations/OneToOneReference.d.ts +82 -0
- package/build/src/relations/OneToOneReference.js +168 -0
- package/build/src/relations/OneToOneReference.js.map +1 -0
- package/build/src/relations/PolymorphicReference.d.ts +69 -0
- package/build/src/relations/PolymorphicReference.js +210 -0
- package/build/src/relations/PolymorphicReference.js.map +1 -0
- package/build/src/relations/Reference.d.ts +29 -0
- package/build/src/relations/Reference.js +23 -0
- package/build/src/relations/Reference.js.map +1 -0
- package/build/src/relations/Relation.d.ts +10 -0
- package/build/src/relations/Relation.js +13 -0
- package/build/src/relations/Relation.js.map +1 -0
- package/build/src/relations/hasAsyncProperty.d.ts +36 -0
- package/build/src/relations/hasAsyncProperty.js +55 -0
- package/build/src/relations/hasAsyncProperty.js.map +1 -0
- package/build/{collections → src/relations}/hasManyDerived.d.ts +2 -1
- package/build/{collections → src/relations}/hasManyDerived.js +1 -1
- package/build/src/relations/hasManyDerived.js.map +1 -0
- package/build/{collections → src/relations}/hasManyThrough.d.ts +0 -0
- package/build/{collections → src/relations}/hasManyThrough.js +2 -2
- package/build/src/relations/hasManyThrough.js.map +1 -0
- package/build/{collections → src/relations}/hasOneDerived.d.ts +3 -2
- package/build/{collections → src/relations}/hasOneDerived.js +1 -1
- package/build/src/relations/hasOneDerived.js.map +1 -0
- package/build/{collections → src/relations}/hasOneThrough.d.ts +0 -0
- package/build/{collections → src/relations}/hasOneThrough.js +2 -2
- package/build/src/relations/hasOneThrough.js.map +1 -0
- package/build/src/relations/index.d.ts +18 -0
- package/build/src/relations/index.js +53 -0
- package/build/src/relations/index.js.map +1 -0
- package/build/{reverseHint.d.ts → src/reverseHint.d.ts} +2 -1
- package/build/{reverseHint.js → src/reverseHint.js} +13 -9
- package/build/src/reverseHint.js.map +1 -0
- package/build/src/rules.d.ts +23 -0
- package/build/src/rules.js +23 -0
- package/build/src/rules.js.map +1 -0
- package/build/src/serde.d.ts +121 -0
- package/build/src/serde.js +190 -0
- package/build/src/serde.js.map +1 -0
- package/build/{utils.d.ts → src/utils.d.ts} +2 -0
- package/build/{utils.js → src/utils.js} +10 -1
- package/build/src/utils.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +30 -15
- package/build/BaseEntity.js.map +0 -1
- package/build/EntityManager.js.map +0 -1
- package/build/EntityPersister.d.ts +0 -30
- package/build/EntityPersister.js +0 -197
- package/build/EntityPersister.js.map +0 -1
- package/build/QueryBuilder.js +0 -195
- package/build/QueryBuilder.js.map +0 -1
- package/build/changes.d.ts +0 -23
- package/build/changes.js +0 -14
- package/build/changes.js.map +0 -1
- package/build/collections/AbstractRelationImpl.js.map +0 -1
- package/build/collections/CustomCollection.js.map +0 -1
- package/build/collections/CustomReference.js.map +0 -1
- package/build/collections/ManyToManyCollection.js +0 -288
- package/build/collections/ManyToManyCollection.js.map +0 -1
- package/build/collections/ManyToOneReference.d.ts +0 -50
- package/build/collections/ManyToOneReference.js.map +0 -1
- package/build/collections/OneToManyCollection.js.map +0 -1
- package/build/collections/OneToOneReference.d.ts +0 -51
- package/build/collections/OneToOneReference.js +0 -132
- package/build/collections/OneToOneReference.js.map +0 -1
- package/build/collections/hasManyDerived.js.map +0 -1
- package/build/collections/hasManyThrough.js.map +0 -1
- package/build/collections/hasOneDerived.js.map +0 -1
- package/build/collections/hasOneThrough.js.map +0 -1
- package/build/collections/index.d.ts +0 -19
- package/build/collections/index.js +0 -49
- package/build/collections/index.js.map +0 -1
- package/build/createOrUpdatePartial.js.map +0 -1
- package/build/getProperties.js.map +0 -1
- package/build/index.d.ts +0 -140
- package/build/index.js +0 -278
- package/build/index.js.map +0 -1
- package/build/keys.d.ts +0 -21
- package/build/keys.js.map +0 -1
- package/build/loadLens.js.map +0 -1
- package/build/newTestInstance.js +0 -153
- package/build/newTestInstance.js.map +0 -1
- package/build/reverseHint.js.map +0 -1
- package/build/serde.d.ts +0 -47
- package/build/serde.js +0 -93
- package/build/serde.js.map +0 -1
- package/build/utils.js.map +0 -1
- package/package.json.bak +0 -27
- package/src/BaseEntity.ts +0 -104
- package/src/EntityManager.ts +0 -1263
- package/src/EntityPersister.ts +0 -240
- package/src/QueryBuilder.ts +0 -289
- package/src/changes.ts +0 -40
- package/src/collections/AbstractRelationImpl.ts +0 -28
- package/src/collections/CustomCollection.ts +0 -152
- package/src/collections/CustomReference.ts +0 -138
- package/src/collections/ManyToManyCollection.ts +0 -346
- package/src/collections/ManyToOneReference.ts +0 -215
- package/src/collections/OneToManyCollection.ts +0 -254
- package/src/collections/OneToOneReference.ts +0 -153
- package/src/collections/hasManyDerived.ts +0 -29
- package/src/collections/hasManyThrough.ts +0 -20
- package/src/collections/hasOneDerived.ts +0 -26
- package/src/collections/hasOneThrough.ts +0 -20
- package/src/collections/index.ts +0 -74
- package/src/createOrUpdatePartial.ts +0 -144
- package/src/getProperties.ts +0 -27
- package/src/index.ts +0 -400
- package/src/keys.ts +0 -75
- package/src/loadLens.ts +0 -126
- package/src/newTestInstance.ts +0 -205
- package/src/reverseHint.ts +0 -43
- package/src/serde.ts +0 -97
- package/src/utils.ts +0 -63
- package/tsconfig.json +0 -21
- package/tsconfig.tsbuildinfo +0 -2646
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTestIndex = exports.maybeNew = exports.defaultValue = exports.testIndex = exports.newTestInstance = exports.testDate = exports.jan1 = void 0;
|
|
7
|
+
const is_plain_object_1 = __importDefault(require("is-plain-object"));
|
|
8
|
+
const EntityManager_1 = require("./EntityManager");
|
|
9
|
+
const index_1 = require("./index");
|
|
10
|
+
const keys_1 = require("./keys");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
// Chosen b/c it's a monday https://www.timeanddate.com/calendar/monthly.html?year=2018&month=1&country=1
|
|
13
|
+
exports.jan1 = new Date(2018, 0, 1);
|
|
14
|
+
exports.testDate = exports.jan1;
|
|
15
|
+
/** Creates a test instance of `T`. */
|
|
16
|
+
function newTestInstance(em, cstr, opts = {}) {
|
|
17
|
+
const meta = (0, EntityManager_1.getMetadata)(cstr);
|
|
18
|
+
// We share a single `use` map for a given `newEntity` factory call
|
|
19
|
+
const use = useMap(opts);
|
|
20
|
+
// Create just the primitive and m2o fields 1st, so we can create a minimal/valid
|
|
21
|
+
// instance of the entity. We'll do the o2m/other fields as a second pass.
|
|
22
|
+
const initialOpts = Object.values(meta.fields).map((field) => {
|
|
23
|
+
const { fieldName } = field;
|
|
24
|
+
// Use the opts value if they passed one in
|
|
25
|
+
if (fieldName in opts && opts[fieldName] !== defaultValueMarker) {
|
|
26
|
+
const optValue = opts[fieldName];
|
|
27
|
+
// We don't explicitly support null (callers should pass undefined), but we accept it
|
|
28
|
+
// for good measure.
|
|
29
|
+
if (optValue === null || (optValue === undefined && !field.required)) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
switch (field.kind) {
|
|
33
|
+
case "m2o":
|
|
34
|
+
return [fieldName, resolveFactoryOpt(em, opts, field, optValue, undefined)];
|
|
35
|
+
case "o2o":
|
|
36
|
+
case "o2m":
|
|
37
|
+
case "m2m":
|
|
38
|
+
// We do these in the 2nd pass after `entity` exists (see additionalOpts)
|
|
39
|
+
return [];
|
|
40
|
+
case "lo2m":
|
|
41
|
+
// If a child is passing themselves into a parent that is a large collection, just ignore it
|
|
42
|
+
return [];
|
|
43
|
+
case "primitive":
|
|
44
|
+
case "enum":
|
|
45
|
+
case "poly":
|
|
46
|
+
case "primaryKey":
|
|
47
|
+
// Look for strings that want to use the test index
|
|
48
|
+
if (typeof optValue === "string" && optValue.includes(exports.testIndex)) {
|
|
49
|
+
const actualIndex = getTestIndex(em, meta.cstr);
|
|
50
|
+
return [fieldName, optValue.replace(exports.testIndex, String(actualIndex))];
|
|
51
|
+
}
|
|
52
|
+
// Otherwise just use the user's opt value as-is
|
|
53
|
+
return [fieldName, optValue];
|
|
54
|
+
default:
|
|
55
|
+
return (0, utils_1.assertNever)(field);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (field.kind === "primitive" &&
|
|
59
|
+
(field.required || opts[fieldName] === defaultValueMarker) &&
|
|
60
|
+
!field.derived &&
|
|
61
|
+
!field.protected) {
|
|
62
|
+
const codegenDefault = cstr.defaultValues[field.fieldName];
|
|
63
|
+
return [fieldName, codegenDefault ?? defaultValueForField(field)];
|
|
64
|
+
}
|
|
65
|
+
else if (field.kind === "m2o") {
|
|
66
|
+
// If neither the user nor the factory (i.e. for an explicit "fan out" case) set this field,
|
|
67
|
+
// then look in `use` and for an "obvious" there-is-only-one default (even for optional fields)
|
|
68
|
+
const existing = getObviousDefault(em, field.otherMetadata(), opts);
|
|
69
|
+
if (existing) {
|
|
70
|
+
return [fieldName, existing];
|
|
71
|
+
}
|
|
72
|
+
// Otherwise, only make a new entity only if the field is required
|
|
73
|
+
if (field.required) {
|
|
74
|
+
return [fieldName, resolveFactoryOpt(em, opts, field, undefined, undefined)];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (field.kind === "enum" && field.required) {
|
|
78
|
+
const codegenDefault = cstr.defaultValues[field.fieldName];
|
|
79
|
+
return [fieldName, codegenDefault ?? field.enumDetailType.getValues()[0]];
|
|
80
|
+
}
|
|
81
|
+
return [];
|
|
82
|
+
});
|
|
83
|
+
const entity = em.create(meta.cstr, Object.fromEntries(initialOpts.filter((t) => t.length > 0)));
|
|
84
|
+
// If the type we just made doesn't exist in `use` yet, remember it. This works better than
|
|
85
|
+
// looking at the values in `fullOpts`, because instead of waiting until the end of the
|
|
86
|
+
// `build fullOpts` loop, we're also invoking `newTestInstance` as we go through the loop itself,
|
|
87
|
+
// creating each test instance within nested/recursive `newTestInstance` calls.
|
|
88
|
+
if (!use.has(entity.constructor)) {
|
|
89
|
+
use.set(entity.constructor, [entity, false]);
|
|
90
|
+
}
|
|
91
|
+
// Now that we've got the entity, do a 2nd pass for o2m/m2m where we pass
|
|
92
|
+
// `{ parent: entity }` down to children (i.e. to replace our original
|
|
93
|
+
// null marker approach).
|
|
94
|
+
const additionalOpts = Object.entries(opts).map(([fieldName, optValue]) => {
|
|
95
|
+
const field = meta.fields[fieldName];
|
|
96
|
+
// Check `!field` b/c `use` won't have a field
|
|
97
|
+
if (optValue === null || optValue === undefined || !field) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
if (field.kind === "o2m") {
|
|
101
|
+
// If this is a list of children, i.e. book.authors, handle partials to newTestInstance'd
|
|
102
|
+
return [fieldName, optValue.map((opt) => resolveFactoryOpt(em, opts, field, opt, entity))];
|
|
103
|
+
}
|
|
104
|
+
else if (field.kind == "m2m") {
|
|
105
|
+
return [fieldName, optValue.map((opt) => resolveFactoryOpt(em, opts, field, opt, [entity]))];
|
|
106
|
+
}
|
|
107
|
+
else if (field.kind === "o2o") {
|
|
108
|
+
// If this is an o2o, i.e. author.image, just pass the optValue (i.e. it won't be a list)
|
|
109
|
+
return [fieldName, resolveFactoryOpt(em, opts, field, optValue, entity)];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
entity.set(Object.fromEntries(additionalOpts.filter((t) => t.length > 0)));
|
|
116
|
+
return entity;
|
|
117
|
+
}
|
|
118
|
+
exports.newTestInstance = newTestInstance;
|
|
119
|
+
/**
|
|
120
|
+
* Resolves a `FactoryEntityOpt` (i.e. maybe an existing entity, maybe an id, maybe a hash of opts) to an entity.
|
|
121
|
+
*
|
|
122
|
+
* If `opt` is `undefined`, then the usual factory semantics of "check use", "look for only one instance" are
|
|
123
|
+
* checked before finally creating a brand new entity.
|
|
124
|
+
*
|
|
125
|
+
* We also accept an optional `otherFieldName` so that, if we do create a new entity, we pass along the null
|
|
126
|
+
* marker for them to know not to create their own version of us.
|
|
127
|
+
*
|
|
128
|
+
* (This was originally intended to be a public API, but the use case ended up being handled
|
|
129
|
+
* by the more-ergonomic `maybeNew` feature; we could explore making this public if another
|
|
130
|
+
* similar use case comes up in the future.)
|
|
131
|
+
*/
|
|
132
|
+
function resolveFactoryOpt(em, opts, field, opt, maybeEntity) {
|
|
133
|
+
const meta = field.otherMetadata();
|
|
134
|
+
if ((0, EntityManager_1.isEntity)(opt)) {
|
|
135
|
+
return opt;
|
|
136
|
+
}
|
|
137
|
+
else if ((0, EntityManager_1.isId)(opt)) {
|
|
138
|
+
return (em.entities.find((e) => e.id === opt || getTestId(em, e) === opt) || (0, utils_1.fail)(`Did not find tagged id ${opt}`));
|
|
139
|
+
}
|
|
140
|
+
else if (opt && !(0, is_plain_object_1.default)(opt) && !(opt instanceof MaybeNew)) {
|
|
141
|
+
// If opt isn't a POJO, assume this is a completely-custom factory
|
|
142
|
+
return meta.factory(em, opt);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// Look for an obvious default
|
|
146
|
+
if (opt === undefined || opt instanceof MaybeNew) {
|
|
147
|
+
const existing = getObviousDefault(em, meta, opts);
|
|
148
|
+
if (existing) {
|
|
149
|
+
return existing;
|
|
150
|
+
}
|
|
151
|
+
// Otherwise fall though to making a new entity via the factory
|
|
152
|
+
}
|
|
153
|
+
// If this is image.author (m2o) but the other-side is a o2o, pass null instead of []
|
|
154
|
+
maybeEntity ?? (maybeEntity = (field.otherMetadata().fields[field.otherFieldName].kind === "o2o" ? null : []));
|
|
155
|
+
return meta.factory(em, {
|
|
156
|
+
// Because of the `!isPlainObject` above, opt will either be undefined or an object here
|
|
157
|
+
...applyUse(opt || {}, useMap(opts), meta),
|
|
158
|
+
...(opt instanceof MaybeNew && opt.opts),
|
|
159
|
+
[field.otherFieldName]: maybeEntity,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** We look for `use`-cached and "if-only-one" defaults. */
|
|
164
|
+
function getObviousDefault(em, metadata, opts) {
|
|
165
|
+
// If neither the user nor the factory (i.e. for an explicit "fan out" case) set this field then look in use
|
|
166
|
+
const use = useMap(opts);
|
|
167
|
+
// ...we used to check "explicit use" vs. "implicit use" here and only use implicit values
|
|
168
|
+
// if the field was required; but in theory our "use if-only-one" heuristic was already looser
|
|
169
|
+
// that this, so it seems fine to just always check use, regardless of field required/optional.
|
|
170
|
+
//
|
|
171
|
+
// Note that we still use explicit/implicit use to know whether the user's `newAuthor` factory
|
|
172
|
+
// should have a use param passed to it, or if we should apply it here after-the-fact. (This gives
|
|
173
|
+
// `newAuthor` the opportunity to apply defaults.)
|
|
174
|
+
if (use.has(metadata.cstr)) {
|
|
175
|
+
return use.get(metadata.cstr)[0];
|
|
176
|
+
}
|
|
177
|
+
// If there is a single existing instance of this type, assume the caller is fine with that
|
|
178
|
+
const existing = em.entities.filter((e) => e instanceof metadata.cstr);
|
|
179
|
+
if (existing.length === 1) {
|
|
180
|
+
return existing[0];
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
// When a factory is called, i.e. `newAuthor`, opts will:
|
|
185
|
+
//
|
|
186
|
+
// - Have values explicitly passed by the user/other factories
|
|
187
|
+
// - Have values from the user's explicit `use` parameter
|
|
188
|
+
// - NOT have guessed (i.e. "only existing entity") or an implicitly-created `use` parameter
|
|
189
|
+
//
|
|
190
|
+
// This allows the factory to "fan out" by default, i.e. newInternalUser creating its own User
|
|
191
|
+
// and Market creating its own ProductAttribute, which originally we couldn't do when
|
|
192
|
+
// guessed/implicit opts were passed directly to `newAuthor`.
|
|
193
|
+
//
|
|
194
|
+
// Now, if the `newAuthor` factory doesn't explicitly "fan out" (by passing `user: {}` to
|
|
195
|
+
// `newTestInstance`), we still "fan in" by having `newTestInstance` sneak in the guessed/implicit
|
|
196
|
+
// opts of only-one-existing or factory-created instances.
|
|
197
|
+
/** Given we're going to call a factory, make sure any `use`s are put into `opts`. */
|
|
198
|
+
function applyUse(opts, use, metadata) {
|
|
199
|
+
// Find any unset fields
|
|
200
|
+
Object.values(metadata.fields)
|
|
201
|
+
.filter((f) => !(f.fieldName in opts))
|
|
202
|
+
.forEach((f) => {
|
|
203
|
+
// And set them to the current `use` entity for their type, if it exists
|
|
204
|
+
if (((0, index_1.isManyToOneField)(f) || (0, index_1.isOneToOneField)(f)) && use.has(f.otherMetadata().cstr)) {
|
|
205
|
+
const def = use.get(f.otherMetadata().cstr);
|
|
206
|
+
// Only pass explicit/user-defined `use` entities, so that factories can "fan out" if they want,
|
|
207
|
+
// and not see other factory-created entities look like user-specific values.
|
|
208
|
+
if (def[1]) {
|
|
209
|
+
opts[f.fieldName] = def[0];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
// Make a copy so we don't leak `use` onto opts that tests might later use in assertions.
|
|
214
|
+
return { ...opts, use };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A marker value for later replacement with the test instance's "unique-ish" index.
|
|
218
|
+
*
|
|
219
|
+
* This is meant to just be a helpful identifier in fields like entity names/descriptions for
|
|
220
|
+
* debugging purposes.
|
|
221
|
+
*/
|
|
222
|
+
exports.testIndex = "TEST_INDEX";
|
|
223
|
+
const defaultValueMarker = {};
|
|
224
|
+
/**
|
|
225
|
+
* A marker value for the default `newTestInstance` behavior.
|
|
226
|
+
*
|
|
227
|
+
* Useful for passing arguments to `newTestInstance` where you sometimes want to
|
|
228
|
+
* provide a specific value, and other times ask for the "pick a default" behavior
|
|
229
|
+
* (i.e. you don't want to pass `undefined` b/c that means explicitly "leave this
|
|
230
|
+
* key unset").
|
|
231
|
+
*
|
|
232
|
+
* Note that this is a function so that we can infer the return type as basically
|
|
233
|
+
* `any` without really using `any` (which would disable type-checking in the rest
|
|
234
|
+
* of the expression).
|
|
235
|
+
*/
|
|
236
|
+
function defaultValue() {
|
|
237
|
+
return defaultValueMarker;
|
|
238
|
+
}
|
|
239
|
+
exports.defaultValue = defaultValue;
|
|
240
|
+
/**
|
|
241
|
+
* Allows a factory to provide a default, i.e. for a field that would otherwise
|
|
242
|
+
* be optional, but still have that field be override by opts & use, without
|
|
243
|
+
* accidentally creating an extra entity as a side-effect.
|
|
244
|
+
*
|
|
245
|
+
* I.e.:
|
|
246
|
+
*
|
|
247
|
+
* ```typescript
|
|
248
|
+
* export function newAuthor(em: Entity, opts: FactoryOpts<Author>) {
|
|
249
|
+
* return newTestInstance(em, Author, {
|
|
250
|
+
* // publisher is not technically required, but make one
|
|
251
|
+
* publisher: maybeNew<Publisher>({}),
|
|
252
|
+
* ...opts,
|
|
253
|
+
* });
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
function maybeNew(opts) {
|
|
258
|
+
// Return a marker that resolveFactoryOpt will look for
|
|
259
|
+
return new MaybeNew((opts || {}));
|
|
260
|
+
}
|
|
261
|
+
exports.maybeNew = maybeNew;
|
|
262
|
+
class MaybeNew {
|
|
263
|
+
constructor(opts) {
|
|
264
|
+
this.opts = opts;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Returns a unique-ish test index for putting in `name` fields.
|
|
269
|
+
*
|
|
270
|
+
* Note that `testIndex` is easier to just include in a string, because it doesn't require passing
|
|
271
|
+
* the `EntityManger` and `type`. But if a factory really wants the test index as a number, they can
|
|
272
|
+
* call this method.
|
|
273
|
+
*
|
|
274
|
+
* Despite the name, these are 1-based, i.e. the first `Author` is `a1`.
|
|
275
|
+
*/
|
|
276
|
+
function getTestIndex(em, type) {
|
|
277
|
+
const existing = em.entities.filter((e) => e instanceof type);
|
|
278
|
+
return existing.length + 1;
|
|
279
|
+
}
|
|
280
|
+
exports.getTestIndex = getTestIndex;
|
|
281
|
+
/** Fakes a probably-right id for un-persisted entities. Solely used for quick lookups in tests/factories. */
|
|
282
|
+
function getTestId(em, entity) {
|
|
283
|
+
const meta = (0, EntityManager_1.getMetadata)(entity);
|
|
284
|
+
const sameType = em.entities.filter((e) => e instanceof meta.cstr);
|
|
285
|
+
return (0, keys_1.tagId)(meta, String(sameType.indexOf(entity) + 1));
|
|
286
|
+
}
|
|
287
|
+
function defaultValueForField(field) {
|
|
288
|
+
switch (field.type) {
|
|
289
|
+
case "string":
|
|
290
|
+
return field.fieldName;
|
|
291
|
+
case "number":
|
|
292
|
+
return 0;
|
|
293
|
+
case "Date":
|
|
294
|
+
return exports.testDate;
|
|
295
|
+
case "boolean":
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
// Do a one-time conversion of the user's `use` array into a map for internal use
|
|
301
|
+
function useMap(opts) {
|
|
302
|
+
const use = opts.use;
|
|
303
|
+
let map;
|
|
304
|
+
if (use instanceof Map) {
|
|
305
|
+
// it's already a map
|
|
306
|
+
map = use;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
map = new Map();
|
|
310
|
+
if (use instanceof Array) {
|
|
311
|
+
// it's a top-level `newAuthor` with a user-passed `use: array`
|
|
312
|
+
use.forEach((e) => map.set(e.constructor, [e, true]));
|
|
313
|
+
}
|
|
314
|
+
else if (use) {
|
|
315
|
+
// it's a top-level `newAuthor` w/o a `use: entity` param
|
|
316
|
+
map.set(use.constructor, [use, true]);
|
|
317
|
+
}
|
|
318
|
+
// Scan opts for entities to implicitly add to the map, i.e. if the user
|
|
319
|
+
// calls `newAuthor(em, { book: b1 })`, we'll use `b1` for any other books we
|
|
320
|
+
// might happen to create.
|
|
321
|
+
const todo = [opts];
|
|
322
|
+
while (todo.length > 0) {
|
|
323
|
+
const opts = todo.pop();
|
|
324
|
+
Object.values(opts || {}).forEach((opt) => {
|
|
325
|
+
if ((0, EntityManager_1.isEntity)(opt) && !map.has(opt.constructor)) {
|
|
326
|
+
map.set(opt.constructor, [opt, false]);
|
|
327
|
+
}
|
|
328
|
+
else if (opt instanceof Array) {
|
|
329
|
+
todo.push(...opt);
|
|
330
|
+
}
|
|
331
|
+
else if ((0, is_plain_object_1.default)(opt)) {
|
|
332
|
+
todo.push(opt);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// Store our potentially-massaged map back into opts i.e. in case resolveFactoryOpt needs it.
|
|
338
|
+
// Use as any b/c UseMap is our internal impl detail and not public.
|
|
339
|
+
opts.use = map;
|
|
340
|
+
return map;
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=newTestInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newTestInstance.js","sourceRoot":"","sources":["../../src/newTestInstance.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA4C;AAC5C,mDAgByB;AACzB,mCAAiE;AACjE,iCAA+B;AAC/B,mCAA4C;AAe5C,yGAAyG;AAC5F,QAAA,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,YAAI,CAAC;AAE3B,sCAAsC;AACtC,SAAgB,eAAe,CAC7B,EAAiB,EACjB,IAA0B,EAC1B,OAAuB,EAAE;IAEzB,MAAM,IAAI,GAAG,IAAA,2BAAW,EAAC,IAAI,CAAC,CAAC;IAC/B,mEAAmE;IACnE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAEzB,iFAAiF;IACjF,0EAA0E;IAC1E,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;QAE5B,2CAA2C;QAC3C,IAAI,SAAS,IAAI,IAAI,IAAK,IAAY,CAAC,SAAS,CAAC,KAAK,kBAAkB,EAAE;YACxE,MAAM,QAAQ,GAAI,IAAY,CAAC,SAAS,CAAC,CAAC;YAC1C,qFAAqF;YACrF,oBAAoB;YACpB,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBACpE,OAAO,EAAE,CAAC;aACX;YACD,QAAQ,KAAK,CAAC,IAAI,EAAE;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;
|
|
13
13
|
/**
|
|
14
14
|
* Called when our entity has been `EntityManager.delete`'d _and_ `EntityManager.flush` is being called,
|
|
15
|
-
* so we can unset any foreign keys to the being-deleted entity.
|
|
15
|
+
* so we can unset any foreign keys to the being-deleted entity and clear out any pointers to it.
|
|
16
16
|
*/
|
|
17
|
-
abstract
|
|
17
|
+
abstract cleanupOnEntityDeleted(): Promise<void>;
|
|
18
18
|
/**
|
|
19
|
-
* Called
|
|
20
|
-
*
|
|
19
|
+
* Called to cascade deletes into the relation if it has cascade behavior enabled. This function is called twice,
|
|
20
|
+
* once on the initial `EntityManager.delete` call in a potentially unloaded state, then again from a `beforeDelete`
|
|
21
|
+
* hook after the relation is fully loaded.
|
|
21
22
|
*/
|
|
22
|
-
abstract
|
|
23
|
+
abstract maybeCascadeDelete(): void;
|
|
23
24
|
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractRelationImpl.js","sourceRoot":"","sources":["../../../src/relations/AbstractRelationImpl.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAsB,oBAAoB;CAyBzC;AAzBD,oDAyBC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Entity, IdOf } from "../EntityManager";
|
|
2
|
+
import { Relation } from "./Relation";
|
|
3
|
+
/** A collection of `U` within `T`, either one-to-many or many-to-many. */
|
|
4
|
+
export interface Collection<T extends Entity, U extends Entity> extends Relation<T, U> {
|
|
5
|
+
load(opts?: {
|
|
6
|
+
withDeleted: boolean;
|
|
7
|
+
}): Promise<ReadonlyArray<U>>;
|
|
8
|
+
/** Looks up the specific `id` without fully loading the collection. */
|
|
9
|
+
find(id: IdOf<U>): Promise<U | undefined>;
|
|
10
|
+
/** Looks up the specific `other` without fully loading the collection. */
|
|
11
|
+
includes(other: U): Promise<boolean>;
|
|
12
|
+
add(other: U): void;
|
|
13
|
+
remove(other: U): void;
|
|
14
|
+
readonly isLoaded: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Adds a known-safe `get` accessor. */
|
|
17
|
+
export interface LoadedCollection<T extends Entity, U extends Entity> extends Collection<T, U> {
|
|
18
|
+
get: ReadonlyArray<U>;
|
|
19
|
+
getWithDeleted: ReadonlyArray<U>;
|
|
20
|
+
set(values: U[]): void;
|
|
21
|
+
removeAll(): void;
|
|
22
|
+
}
|
|
23
|
+
/** Type guard utility for determining if an entity field is a Collection. */
|
|
24
|
+
export declare function isCollection(maybeCollection: any): maybeCollection is Collection<any, any>;
|
|
25
|
+
/** Type guard utility for determining if an entity field is a loaded Collection. */
|
|
26
|
+
export declare function isLoadedCollection(maybeCollection: any): maybeCollection is Collection<any, any> & LoadedCollection<any, any>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoadedCollection = exports.isCollection = void 0;
|
|
4
|
+
const CustomCollection_1 = require("./CustomCollection");
|
|
5
|
+
const ManyToManyCollection_1 = require("./ManyToManyCollection");
|
|
6
|
+
const OneToManyCollection_1 = require("./OneToManyCollection");
|
|
7
|
+
/** Type guard utility for determining if an entity field is a Collection. */
|
|
8
|
+
function isCollection(maybeCollection) {
|
|
9
|
+
return (maybeCollection instanceof OneToManyCollection_1.OneToManyCollection ||
|
|
10
|
+
maybeCollection instanceof ManyToManyCollection_1.ManyToManyCollection ||
|
|
11
|
+
maybeCollection instanceof CustomCollection_1.CustomCollection);
|
|
12
|
+
}
|
|
13
|
+
exports.isCollection = isCollection;
|
|
14
|
+
/** Type guard utility for determining if an entity field is a loaded Collection. */
|
|
15
|
+
function isLoadedCollection(maybeCollection) {
|
|
16
|
+
return isCollection(maybeCollection) && maybeCollection.isLoaded;
|
|
17
|
+
}
|
|
18
|
+
exports.isLoadedCollection = isLoadedCollection;
|
|
19
|
+
//# sourceMappingURL=Collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Collection.js","sourceRoot":"","sources":["../../../src/relations/Collection.ts"],"names":[],"mappings":";;;AACA,yDAAsD;AACtD,iEAA8D;AAC9D,+DAA4D;AA+B5D,6EAA6E;AAC7E,SAAgB,YAAY,CAAC,eAAoB;IAC/C,OAAO,CACL,eAAe,YAAY,yCAAmB;QAC9C,eAAe,YAAY,2CAAoB;QAC/C,eAAe,YAAY,mCAAgB,CAC5C,CAAC;AACJ,CAAC;AAND,oCAMC;AAED,oFAAoF;AACpF,SAAgB,kBAAkB,CAChC,eAAoB;IAEpB,OAAO,YAAY,CAAC,eAAe,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAC;AACnE,CAAC;AAJD,gDAIC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Entity, IdOf } from "../EntityManager";
|
|
2
2
|
import { Collection } from "../index";
|
|
3
3
|
import { AbstractRelationImpl } from "./AbstractRelationImpl";
|
|
4
|
+
import { RelationT, RelationU } from "./Relation";
|
|
4
5
|
export declare type CustomCollectionOpts<T extends Entity, U extends Entity> = {
|
|
5
6
|
load: (entity: T) => Promise<any>;
|
|
6
7
|
get: (entity: T) => readonly U[];
|
|
@@ -36,14 +37,17 @@ export declare class CustomCollection<T extends Entity, U extends Entity> extend
|
|
|
36
37
|
set(values: U[]): void;
|
|
37
38
|
setFromOpts(values: U[]): void;
|
|
38
39
|
find(id: IdOf<U>): Promise<U | undefined>;
|
|
40
|
+
includes(other: U): Promise<boolean>;
|
|
39
41
|
add(other: U): void;
|
|
40
42
|
remove(other: U): void;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
cleanupOnEntityDeleted(): Promise<void>;
|
|
44
|
+
maybeCascadeDelete(): void;
|
|
43
45
|
refreshIfLoaded(): Promise<void>;
|
|
44
46
|
/** Finds this CustomCollections field name by looking in the entity for the key that we're assigned to. */
|
|
45
47
|
get fieldName(): string;
|
|
46
48
|
toString(): string;
|
|
47
49
|
private doGet;
|
|
48
50
|
private filterDeleted;
|
|
51
|
+
[RelationT]: T;
|
|
52
|
+
[RelationU]: U;
|
|
49
53
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a, _b;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.CustomCollection = void 0;
|
|
4
5
|
const index_1 = require("../index");
|
|
5
6
|
const AbstractRelationImpl_1 = require("./AbstractRelationImpl");
|
|
7
|
+
const Relation_1 = require("./Relation");
|
|
6
8
|
/**
|
|
7
9
|
* Allows user-defined collections that will work in `populate` / preload hints.
|
|
8
10
|
*
|
|
@@ -20,6 +22,8 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
20
22
|
this.entity = entity;
|
|
21
23
|
this.opts = opts;
|
|
22
24
|
this._isLoaded = false;
|
|
25
|
+
this[_a] = null;
|
|
26
|
+
this[_b] = null;
|
|
23
27
|
}
|
|
24
28
|
get get() {
|
|
25
29
|
return this.doGet({ withDeleted: false });
|
|
@@ -31,7 +35,7 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
31
35
|
return this._isLoaded;
|
|
32
36
|
}
|
|
33
37
|
async load(opts) {
|
|
34
|
-
index_1.ensureNotDeleted(this.entity, { ignore: "pending" });
|
|
38
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
35
39
|
if (!this.isLoaded) {
|
|
36
40
|
if (this.loadPromise === undefined) {
|
|
37
41
|
this.loadPromise = this.opts.load(this.entity);
|
|
@@ -64,7 +68,7 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
64
68
|
values.filter((value) => !current.includes(value)).forEach((value) => this.add(value));
|
|
65
69
|
}
|
|
66
70
|
else {
|
|
67
|
-
index_1.fail(`'set' not implemented and not inferrable from 'add'/'remove' on ${this}`);
|
|
71
|
+
(0, index_1.fail)(`'set' not implemented and not inferrable from 'add'/'remove' on ${this}`);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
setFromOpts(values) {
|
|
@@ -82,11 +86,14 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
82
86
|
return find(this.entity, id);
|
|
83
87
|
}
|
|
84
88
|
}
|
|
89
|
+
async includes(other) {
|
|
90
|
+
throw new Error("Not implemented");
|
|
91
|
+
}
|
|
85
92
|
add(other) {
|
|
86
93
|
ensureNewOrLoaded(this);
|
|
87
94
|
const { add } = this.opts;
|
|
88
95
|
if (add === undefined) {
|
|
89
|
-
index_1.fail(`'add' not implemented on ${this}`);
|
|
96
|
+
(0, index_1.fail)(`'add' not implemented on ${this}`);
|
|
90
97
|
}
|
|
91
98
|
add(this.entity, other);
|
|
92
99
|
}
|
|
@@ -94,13 +101,13 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
94
101
|
ensureNewOrLoaded(this);
|
|
95
102
|
const { remove } = this.opts;
|
|
96
103
|
if (remove === undefined) {
|
|
97
|
-
index_1.fail(`'add' not implemented on ${this}`);
|
|
104
|
+
(0, index_1.fail)(`'add' not implemented on ${this}`);
|
|
98
105
|
}
|
|
99
106
|
remove(this.entity, other);
|
|
100
107
|
}
|
|
101
108
|
// these callbacks should be no-ops as they ought to be handled by the underlying relations
|
|
102
|
-
async
|
|
103
|
-
|
|
109
|
+
async cleanupOnEntityDeleted() { }
|
|
110
|
+
maybeCascadeDelete() { }
|
|
104
111
|
async refreshIfLoaded() { }
|
|
105
112
|
/** Finds this CustomCollections field name by looking in the entity for the key that we're assigned to. */
|
|
106
113
|
get fieldName() {
|
|
@@ -110,19 +117,20 @@ class CustomCollection extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
|
110
117
|
return `CustomCollection(entity: ${this.entity}, fieldName: ${this.fieldName})`;
|
|
111
118
|
}
|
|
112
119
|
doGet(opts) {
|
|
113
|
-
index_1.ensureNotDeleted(this.entity, { ignore: "pending" });
|
|
120
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
114
121
|
ensureNewOrLoaded(this);
|
|
115
122
|
return this.filterDeleted(this.opts.get(this.entity), opts);
|
|
116
123
|
}
|
|
117
124
|
filterDeleted(entities, opts) {
|
|
118
|
-
return entities.filter((entity) =>
|
|
125
|
+
return entities.filter((entity) => opts?.withDeleted === true || !entity.isDeletedEntity);
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
128
|
exports.CustomCollection = CustomCollection;
|
|
129
|
+
_a = Relation_1.RelationT, _b = Relation_1.RelationU;
|
|
122
130
|
function ensureNewOrLoaded(reference) {
|
|
123
131
|
if (!(reference.isLoaded || reference.entity.isNewEntity)) {
|
|
124
132
|
// This should only be callable in the type system if we've already resolved this to an instance
|
|
125
|
-
index_1.fail(`${reference.entity}.${reference.fieldName} was not loaded`);
|
|
133
|
+
(0, index_1.fail)(`${reference.entity}.${reference.fieldName} was not loaded`);
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
//# sourceMappingURL=CustomCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomCollection.js","sourceRoot":"","sources":["../../../src/relations/CustomCollection.ts"],"names":[],"mappings":";;;;AACA,oCAA8D;AAC9D,iEAA8D;AAC9D,yCAAkD;AAalD;;;;;;;;;;GAUG;AACH,MAAa,gBACX,SAAQ,2CAAyB;IAQjC,YAAmB,MAAS,EAAU,IAAgC;QACpE,KAAK,EAAE,CAAC;QADS,WAAM,GAAN,MAAM,CAAG;QAAU,SAAI,GAAJ,IAAI,CAA4B;QAF9D,cAAS,GAAG,KAAK,CAAC;QAsH1B,QAAW,GAAM,IAAK,CAAC;QACvB,QAAW,GAAM,IAAK,CAAC;IAnHvB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,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AE,WAAW,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAC5F,CAAC;CAIF;AA/HD,4CA+HC;KAFE,oBAAS,OACT,oBAAS;AAGZ,SAAS,iBAAiB,CAAC,SAAqC;IAC9D,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;QACzD,gGAAgG;QAChG,IAAA,YAAI,EAAC,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,SAAS,iBAAiB,CAAC,CAAC;KACnE;AACH,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Entity, IdOf } from "../EntityManager";
|
|
2
2
|
import { Reference } from "../index";
|
|
3
3
|
import { AbstractRelationImpl } from "./AbstractRelationImpl";
|
|
4
|
+
import { ReferenceN } from "./Reference";
|
|
5
|
+
import { RelationT, RelationU } from "./Relation";
|
|
4
6
|
export declare type CustomReferenceOpts<T extends Entity, U extends Entity, N extends never | undefined> = {
|
|
5
7
|
load: (entity: T) => Promise<void>;
|
|
6
8
|
get: (entity: T) => U | N;
|
|
@@ -37,12 +39,15 @@ export declare class CustomReference<T extends Entity, U extends Entity, N exten
|
|
|
37
39
|
get isSet(): boolean;
|
|
38
40
|
set(value: U): void;
|
|
39
41
|
setFromOpts(value: U): void;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
cleanupOnEntityDeleted(): Promise<void>;
|
|
43
|
+
maybeCascadeDelete(): void;
|
|
42
44
|
refreshIfLoaded(): Promise<void>;
|
|
43
45
|
/** Finds this CustomReferences field name by looking in the entity for the key that we're assigned to. */
|
|
44
46
|
get fieldName(): string;
|
|
45
47
|
toString(): string;
|
|
46
48
|
private doGet;
|
|
47
49
|
private filterDeleted;
|
|
50
|
+
[RelationT]: T;
|
|
51
|
+
[RelationU]: U;
|
|
52
|
+
[ReferenceN]: N;
|
|
48
53
|
}
|