joist-orm 0.1.538 → 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,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OneToManyLargeCollection = exports.hasLargeMany = void 0;
|
|
5
|
+
const oneToManyFindDataLoader_1 = require("../dataloaders/oneToManyFindDataLoader");
|
|
6
|
+
const EntityManager_1 = require("../EntityManager");
|
|
7
|
+
const index_1 = require("../index");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const Relation_1 = require("./Relation");
|
|
10
|
+
/** An alias for creating `OneToManyLargeCollection`s. */
|
|
11
|
+
function hasLargeMany(otherMeta, fieldName, otherFieldName, otherColumnName) {
|
|
12
|
+
const entity = EntityManager_1.currentlyInstantiatingEntity;
|
|
13
|
+
return new OneToManyLargeCollection(entity, otherMeta, fieldName, otherFieldName, otherColumnName);
|
|
14
|
+
}
|
|
15
|
+
exports.hasLargeMany = hasLargeMany;
|
|
16
|
+
class OneToManyLargeCollection {
|
|
17
|
+
constructor(
|
|
18
|
+
// These are public to our internal implementation but not exposed in the Collection API
|
|
19
|
+
entity, otherMeta, fieldName, otherFieldName, otherColumnName) {
|
|
20
|
+
this.entity = entity;
|
|
21
|
+
this.otherMeta = otherMeta;
|
|
22
|
+
this.fieldName = fieldName;
|
|
23
|
+
this.otherFieldName = otherFieldName;
|
|
24
|
+
this.otherColumnName = otherColumnName;
|
|
25
|
+
// Even though a large collection can never be loaded, we do track local
|
|
26
|
+
// mutations so that `find` can be accurate.
|
|
27
|
+
this.locallyAdded = [];
|
|
28
|
+
this.locallyRemoved = [];
|
|
29
|
+
this[_a] = null;
|
|
30
|
+
this[_b] = null;
|
|
31
|
+
}
|
|
32
|
+
async find(id) {
|
|
33
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
34
|
+
// locallyAdded is never authoritative b/c we never become fully loaded (unlike OneToManyCollection),
|
|
35
|
+
// so we can probe our local collection, but if we don't find anything, we still have to query
|
|
36
|
+
const localAdd = this.locallyAdded.find((u) => u.id === id);
|
|
37
|
+
if (localAdd) {
|
|
38
|
+
return localAdd;
|
|
39
|
+
}
|
|
40
|
+
const localRemove = this.locallyRemoved.find((u) => u.id === id);
|
|
41
|
+
if (localRemove) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (this.entity.isNewEntity) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
// Make a cacheable tuple to look up this specific o2m row
|
|
48
|
+
const key = `id=${id},${this.otherColumnName}=${this.entity.idOrFail}`;
|
|
49
|
+
return (0, oneToManyFindDataLoader_1.oneToManyFindDataLoader)(this.entity.em, this).load(key);
|
|
50
|
+
}
|
|
51
|
+
async includes(other) {
|
|
52
|
+
return (0, EntityManager_1.sameEntity)(this.entity, this.meta, this.getOtherRelation(other).current());
|
|
53
|
+
}
|
|
54
|
+
add(other) {
|
|
55
|
+
(0, utils_1.remove)(this.locallyRemoved, other);
|
|
56
|
+
if (!this.locallyAdded.includes(other)) {
|
|
57
|
+
this.locallyAdded.push(other);
|
|
58
|
+
}
|
|
59
|
+
// This will no-op and mark other dirty if necessary
|
|
60
|
+
this.getOtherRelation(other).set(this.entity);
|
|
61
|
+
}
|
|
62
|
+
remove(other) {
|
|
63
|
+
(0, utils_1.remove)(this.locallyAdded, other);
|
|
64
|
+
if (!this.locallyRemoved.includes(other)) {
|
|
65
|
+
this.locallyRemoved.push(other);
|
|
66
|
+
}
|
|
67
|
+
// This will no-op and mark other dirty if necessary
|
|
68
|
+
this.getOtherRelation(other).set(undefined);
|
|
69
|
+
}
|
|
70
|
+
get meta() {
|
|
71
|
+
return (0, index_1.getMetadata)(this.entity);
|
|
72
|
+
}
|
|
73
|
+
toString() {
|
|
74
|
+
return `OneToManyLargeCollection(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;
|
|
75
|
+
}
|
|
76
|
+
/** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */
|
|
77
|
+
getOtherRelation(other) {
|
|
78
|
+
return other[this.otherFieldName];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.OneToManyLargeCollection = OneToManyLargeCollection;
|
|
82
|
+
_a = Relation_1.RelationT, _b = Relation_1.RelationU;
|
|
83
|
+
//# sourceMappingURL=OneToManyLargeCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneToManyLargeCollection.js","sourceRoot":"","sources":["../../../src/relations/OneToManyLargeCollection.ts"],"names":[],"mappings":";;;;AAAA,oFAAiF;AACjF,oDAA0G;AAC1G,oCAAiF;AACjF,oCAAkC;AAElC,yCAAkD;AAElD,yDAAyD;AACzD,SAAgB,YAAY,CAC1B,SAA4B,EAC5B,SAAkB,EAClB,cAAuB,EACvB,eAAuB;IAEvB,MAAM,MAAM,GAAG,4CAAiC,CAAC;IACjD,OAAO,IAAI,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE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I,CAAC,cAAc,GAAG,CAAC;IACrK,CAAC;IAED,kHAAkH;IAC1G,gBAAgB,CAAC,KAAQ;QAC/B,OAAQ,KAAW,CAAC,IAAI,CAAC,cAAc,CAAQ,CAAC;IAClD,CAAC;CAIF;AA5ED,4DA4EC;KAFE,oBAAS,OACT,oBAAS"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { IdOf, LoadedReference } from "../";
|
|
2
|
+
import { Entity, EntityMetadata } from "../EntityManager";
|
|
3
|
+
import { AbstractRelationImpl } from "./AbstractRelationImpl";
|
|
4
|
+
import { Reference, ReferenceN } from "./Reference";
|
|
5
|
+
import { RelationT, RelationU } from "./Relation";
|
|
6
|
+
declare const OneToOne: unique symbol;
|
|
7
|
+
/** The lazy-loaded/lookup side of a one-to-one, i.e. the side w/o the unique foreign key column. */
|
|
8
|
+
export interface OneToOneReference<T extends Entity, U extends Entity> extends Reference<T, U, undefined> {
|
|
9
|
+
[OneToOne]: T;
|
|
10
|
+
}
|
|
11
|
+
/** Adds a known-safe `get` accessor. */
|
|
12
|
+
export interface LoadedOneToOneReference<T extends Entity, U extends Entity> extends LoadedReference<T, U, undefined> {
|
|
13
|
+
get: U | undefined;
|
|
14
|
+
getWithDeleted: U | undefined;
|
|
15
|
+
/** Returns the id of the current assigned entity or a runtime error if it's either a) unset or b) set to a new entity that doesn't have an `id` yet. */
|
|
16
|
+
idOrFail: IdOf<U>;
|
|
17
|
+
idUntagged: string | undefined;
|
|
18
|
+
idUntaggedOrFail: string;
|
|
19
|
+
/** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */
|
|
20
|
+
readonly isSet: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Type guard utility for determining if an entity field is a Reference. */
|
|
23
|
+
export declare function isOneToOneReference(maybeReference: any): maybeReference is OneToOneReference<any, any>;
|
|
24
|
+
/** Type guard utility for determining if an entity field is a loaded Reference. */
|
|
25
|
+
export declare function isLoadedOneToOneReference(maybeReference: any): maybeReference is Reference<any, any, any> & LoadedOneToOneReference<any, any>;
|
|
26
|
+
/** An alias for creating `OneToOneReference`s. */
|
|
27
|
+
export declare function hasOneToOne<T extends Entity, U extends Entity>(otherMeta: EntityMetadata<U>, fieldName: keyof T, otherFieldName: keyof U, otherColumnName: string): OneToOneReference<T, U>;
|
|
28
|
+
/**
|
|
29
|
+
* Represents the "many" side of a one-to-one relationship.
|
|
30
|
+
*
|
|
31
|
+
* I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.
|
|
32
|
+
*
|
|
33
|
+
* This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and
|
|
34
|
+
* so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.
|
|
35
|
+
*
|
|
36
|
+
* This class implements `Reference` because it is essentially like "one entity pointing/refereing to another",
|
|
37
|
+
* however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference
|
|
38
|
+
* which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness
|
|
39
|
+
* around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this
|
|
40
|
+
* class can actually only be called post `load`/`populate`.
|
|
41
|
+
*
|
|
42
|
+
* Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing
|
|
43
|
+
* `Reference` seemed worth the downside of a un-type-safe `.id` property.
|
|
44
|
+
*/
|
|
45
|
+
export declare class OneToOneReferenceImpl<T extends Entity, U extends Entity> extends AbstractRelationImpl<U> implements OneToOneReference<T, U> {
|
|
46
|
+
entity: T;
|
|
47
|
+
otherMeta: EntityMetadata<U>;
|
|
48
|
+
fieldName: keyof T;
|
|
49
|
+
otherFieldName: keyof U;
|
|
50
|
+
otherColumnName: string;
|
|
51
|
+
private loaded;
|
|
52
|
+
private _isLoaded;
|
|
53
|
+
private isCascadeDelete;
|
|
54
|
+
constructor(entity: T, otherMeta: EntityMetadata<U>, fieldName: keyof T, otherFieldName: keyof U, otherColumnName: string);
|
|
55
|
+
get id(): IdOf<U> | undefined;
|
|
56
|
+
get idOrFail(): IdOf<U>;
|
|
57
|
+
get idUntagged(): string | undefined;
|
|
58
|
+
get idUntaggedOrFail(): string;
|
|
59
|
+
get isSet(): boolean;
|
|
60
|
+
load(opts?: {
|
|
61
|
+
withDeleted?: boolean;
|
|
62
|
+
}): Promise<U | undefined>;
|
|
63
|
+
set(other: U): void;
|
|
64
|
+
get isLoaded(): boolean;
|
|
65
|
+
get getWithDeleted(): U | undefined;
|
|
66
|
+
get get(): U | undefined;
|
|
67
|
+
private doGet;
|
|
68
|
+
setFromOpts(other: U): void;
|
|
69
|
+
initializeForNewEntity(): void;
|
|
70
|
+
refreshIfLoaded(): Promise<void>;
|
|
71
|
+
maybeCascadeDelete(): void;
|
|
72
|
+
cleanupOnEntityDeleted(): Promise<void>;
|
|
73
|
+
toString(): string;
|
|
74
|
+
private filterDeleted;
|
|
75
|
+
/** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */
|
|
76
|
+
private getOtherRelation;
|
|
77
|
+
[RelationT]: never;
|
|
78
|
+
[RelationU]: never;
|
|
79
|
+
[ReferenceN]: never;
|
|
80
|
+
[OneToOne]: never;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OneToOneReferenceImpl = exports.hasOneToOne = exports.isLoadedOneToOneReference = exports.isOneToOneReference = void 0;
|
|
5
|
+
const __1 = require("../");
|
|
6
|
+
const oneToOneDataLoader_1 = require("../dataloaders/oneToOneDataLoader");
|
|
7
|
+
const EntityManager_1 = require("../EntityManager");
|
|
8
|
+
const AbstractRelationImpl_1 = require("./AbstractRelationImpl");
|
|
9
|
+
const Reference_1 = require("./Reference");
|
|
10
|
+
const Relation_1 = require("./Relation");
|
|
11
|
+
const OneToOne = Symbol();
|
|
12
|
+
/** Type guard utility for determining if an entity field is a Reference. */
|
|
13
|
+
function isOneToOneReference(maybeReference) {
|
|
14
|
+
return maybeReference instanceof OneToOneReferenceImpl;
|
|
15
|
+
}
|
|
16
|
+
exports.isOneToOneReference = isOneToOneReference;
|
|
17
|
+
/** Type guard utility for determining if an entity field is a loaded Reference. */
|
|
18
|
+
function isLoadedOneToOneReference(maybeReference) {
|
|
19
|
+
return isOneToOneReference(maybeReference) && maybeReference.isLoaded;
|
|
20
|
+
}
|
|
21
|
+
exports.isLoadedOneToOneReference = isLoadedOneToOneReference;
|
|
22
|
+
/** An alias for creating `OneToOneReference`s. */
|
|
23
|
+
function hasOneToOne(otherMeta, fieldName, otherFieldName, otherColumnName) {
|
|
24
|
+
const entity = __1.currentlyInstantiatingEntity;
|
|
25
|
+
return new OneToOneReferenceImpl(entity, otherMeta, fieldName, otherFieldName, otherColumnName);
|
|
26
|
+
}
|
|
27
|
+
exports.hasOneToOne = hasOneToOne;
|
|
28
|
+
/**
|
|
29
|
+
* Represents the "many" side of a one-to-one relationship.
|
|
30
|
+
*
|
|
31
|
+
* I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.
|
|
32
|
+
*
|
|
33
|
+
* This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and
|
|
34
|
+
* so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.
|
|
35
|
+
*
|
|
36
|
+
* This class implements `Reference` because it is essentially like "one entity pointing/refereing to another",
|
|
37
|
+
* however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference
|
|
38
|
+
* which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness
|
|
39
|
+
* around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this
|
|
40
|
+
* class can actually only be called post `load`/`populate`.
|
|
41
|
+
*
|
|
42
|
+
* Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing
|
|
43
|
+
* `Reference` seemed worth the downside of a un-type-safe `.id` property.
|
|
44
|
+
*/
|
|
45
|
+
class OneToOneReferenceImpl extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
46
|
+
constructor(
|
|
47
|
+
// These are public to our internal implementation but not exposed in the Collection API
|
|
48
|
+
entity, otherMeta, fieldName, otherFieldName, otherColumnName) {
|
|
49
|
+
super();
|
|
50
|
+
this.entity = entity;
|
|
51
|
+
this.otherMeta = otherMeta;
|
|
52
|
+
this.fieldName = fieldName;
|
|
53
|
+
this.otherFieldName = otherFieldName;
|
|
54
|
+
this.otherColumnName = otherColumnName;
|
|
55
|
+
this._isLoaded = false;
|
|
56
|
+
this[_a] = null;
|
|
57
|
+
this[_b] = null;
|
|
58
|
+
this[_c] = null;
|
|
59
|
+
this[_d] = null;
|
|
60
|
+
this.isCascadeDelete = (0, EntityManager_1.getMetadata)(entity).config.__data.cascadeDeleteFields.includes(fieldName);
|
|
61
|
+
}
|
|
62
|
+
get id() {
|
|
63
|
+
if (this._isLoaded) {
|
|
64
|
+
return this.loaded?.id;
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`${this.entity}.${this.fieldName} was not loaded`);
|
|
67
|
+
}
|
|
68
|
+
get idOrFail() {
|
|
69
|
+
return this.id || (0, __1.fail)(`${this.entity}.${this.fieldName} has no id yet`);
|
|
70
|
+
}
|
|
71
|
+
get idUntagged() {
|
|
72
|
+
return this.id && (0, __1.deTagIds)(this.otherMeta, [this.id])[0];
|
|
73
|
+
}
|
|
74
|
+
get idUntaggedOrFail() {
|
|
75
|
+
return this.idUntagged || (0, __1.fail)("Reference is unset or assigned to a new entity");
|
|
76
|
+
}
|
|
77
|
+
get isSet() {
|
|
78
|
+
if (this._isLoaded) {
|
|
79
|
+
return this.loaded !== undefined;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`${this.entity}.${this.fieldName} was not loaded`);
|
|
82
|
+
}
|
|
83
|
+
// opts is an internal parameter
|
|
84
|
+
async load(opts) {
|
|
85
|
+
(0, __1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
86
|
+
if (!this._isLoaded) {
|
|
87
|
+
if (!this.entity.isNewEntity) {
|
|
88
|
+
this.loaded = await (0, oneToOneDataLoader_1.oneToOneDataLoader)(this.entity.em, this).load(this.entity.idOrFail);
|
|
89
|
+
}
|
|
90
|
+
this._isLoaded = true;
|
|
91
|
+
}
|
|
92
|
+
return this.filterDeleted(this.loaded, opts);
|
|
93
|
+
}
|
|
94
|
+
set(other) {
|
|
95
|
+
(0, __1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
96
|
+
if (other === this.loaded) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this._isLoaded) {
|
|
100
|
+
if (this.loaded) {
|
|
101
|
+
this.getOtherRelation(this.loaded).set(undefined);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.loaded = other;
|
|
105
|
+
this._isLoaded = true;
|
|
106
|
+
// This will no-op and mark other dirty if necessary
|
|
107
|
+
if (other) {
|
|
108
|
+
this.getOtherRelation(other).set(this.entity);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
get isLoaded() {
|
|
112
|
+
return this._isLoaded;
|
|
113
|
+
}
|
|
114
|
+
get getWithDeleted() {
|
|
115
|
+
return this.filterDeleted(this.doGet(), { withDeleted: true });
|
|
116
|
+
}
|
|
117
|
+
get get() {
|
|
118
|
+
return this.filterDeleted(this.doGet(), { withDeleted: false });
|
|
119
|
+
}
|
|
120
|
+
doGet() {
|
|
121
|
+
(0, __1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
122
|
+
if (!this._isLoaded) {
|
|
123
|
+
// This should only be callable in the type system if we've already resolved this to an instance
|
|
124
|
+
throw new Error("get was called when not preloaded");
|
|
125
|
+
}
|
|
126
|
+
return this.loaded;
|
|
127
|
+
}
|
|
128
|
+
// internal impl
|
|
129
|
+
setFromOpts(other) {
|
|
130
|
+
this.set(other);
|
|
131
|
+
}
|
|
132
|
+
initializeForNewEntity() {
|
|
133
|
+
this._isLoaded = true;
|
|
134
|
+
}
|
|
135
|
+
async refreshIfLoaded() {
|
|
136
|
+
if (this._isLoaded) {
|
|
137
|
+
this._isLoaded = false;
|
|
138
|
+
await this.load();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
maybeCascadeDelete() {
|
|
142
|
+
if (this.isCascadeDelete && this.loaded) {
|
|
143
|
+
this.entity.em.delete(this.loaded);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async cleanupOnEntityDeleted() {
|
|
147
|
+
const current = await this.load({ withDeleted: true });
|
|
148
|
+
if (current !== undefined) {
|
|
149
|
+
this.getOtherRelation(current).set(undefined);
|
|
150
|
+
(0, __1.setField)(current, this.otherFieldName, undefined);
|
|
151
|
+
}
|
|
152
|
+
this.loaded = undefined;
|
|
153
|
+
this._isLoaded = true;
|
|
154
|
+
}
|
|
155
|
+
toString() {
|
|
156
|
+
return `OneToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;
|
|
157
|
+
}
|
|
158
|
+
filterDeleted(entity, opts) {
|
|
159
|
+
return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;
|
|
160
|
+
}
|
|
161
|
+
/** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */
|
|
162
|
+
getOtherRelation(other) {
|
|
163
|
+
return other[this.otherFieldName];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.OneToOneReferenceImpl = OneToOneReferenceImpl;
|
|
167
|
+
_a = Relation_1.RelationT, _b = Relation_1.RelationU, _c = Reference_1.ReferenceN, _d = OneToOne;
|
|
168
|
+
//# sourceMappingURL=OneToOneReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneToOneReference.js","sourceRoot":"","sources":["../../../src/relations/OneToOneReference.ts"],"names":[],"mappings":";;;;AAAA,2BAAsH;AACtH,0EAAuE;AACvE,oDAAuE;AACvE,iEAA8D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,MAAqB,EAAE,IAAgC;QAC3E,OAAO,IAAI,EAAE,WAAW,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5G,CAAC;IAED,kHAAkH;IAC1G,gBAAgB,CAAC,KAAQ;QAC/B,OAAQ,KAAW,CAAC,IAAI,CAAC,cAAc,CAAQ,CAAC;IAClD,CAAC;CAMF;AAnJD,sDAmJC;KAJE,oBAAS,OACT,oBAAS,OACT,sBAAU,OACV,QAAQ"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Entity, IdOf } from "../EntityManager";
|
|
2
|
+
import { Reference } from "../index";
|
|
3
|
+
import { AbstractRelationImpl } from "./AbstractRelationImpl";
|
|
4
|
+
import { ReferenceN } from "./Reference";
|
|
5
|
+
import { RelationT, RelationU } from "./Relation";
|
|
6
|
+
export declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(fieldName: keyof T): PolymorphicReference<T, U, N>;
|
|
7
|
+
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
8
|
+
export declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
|
|
9
|
+
export interface PolymorphicReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
|
|
10
|
+
/** Returns the id of the current assigned entity (or `undefined` if its new and has no id yet), or `undefined` if this column is nullable and currently unset. */
|
|
11
|
+
id: IdOf<U> | undefined;
|
|
12
|
+
/** Returns the id of the current assigned entity or a runtime error if it's either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */
|
|
13
|
+
idOrFail: IdOf<U>;
|
|
14
|
+
idUntagged: string | undefined;
|
|
15
|
+
idUntaggedOrFail: string;
|
|
16
|
+
/** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */
|
|
17
|
+
readonly isSet: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.
|
|
21
|
+
*
|
|
22
|
+
* We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the
|
|
23
|
+
* current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)
|
|
24
|
+
* from the database, or an entity `Book` / `BookReview` that the user has set.
|
|
25
|
+
*
|
|
26
|
+
* Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will
|
|
27
|
+
* essentially be half of a one-to-one relationship, but we'll keep using this reference on the "owning" side; the other
|
|
28
|
+
* side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.
|
|
29
|
+
*/
|
|
30
|
+
export declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<U> implements PolymorphicReference<T, U, N> {
|
|
31
|
+
private entity;
|
|
32
|
+
private fieldName;
|
|
33
|
+
private loaded;
|
|
34
|
+
private _isLoaded;
|
|
35
|
+
private field;
|
|
36
|
+
constructor(entity: T, fieldName: keyof T);
|
|
37
|
+
private get currentComponent();
|
|
38
|
+
private get isCascadeDelete();
|
|
39
|
+
load(opts?: {
|
|
40
|
+
withDeleted?: boolean;
|
|
41
|
+
}): Promise<U | N>;
|
|
42
|
+
set(other: U | N): void;
|
|
43
|
+
get isSet(): boolean;
|
|
44
|
+
get isLoaded(): boolean;
|
|
45
|
+
private doGet;
|
|
46
|
+
get getWithDeleted(): U | N;
|
|
47
|
+
get get(): U | N;
|
|
48
|
+
get id(): IdOf<U> | undefined;
|
|
49
|
+
get idOrFail(): IdOf<U>;
|
|
50
|
+
get idUntagged(): string | undefined;
|
|
51
|
+
get idUntaggedOrFail(): string;
|
|
52
|
+
setFromOpts(other: U): void;
|
|
53
|
+
initializeForNewEntity(): void;
|
|
54
|
+
refreshIfLoaded(): Promise<void>;
|
|
55
|
+
maybeCascadeDelete(): void;
|
|
56
|
+
cleanupOnEntityDeleted(): Promise<void>;
|
|
57
|
+
setImpl(other: U | N): void;
|
|
58
|
+
current(opts?: {
|
|
59
|
+
withDeleted?: boolean;
|
|
60
|
+
}): U | string | N;
|
|
61
|
+
toString(): string;
|
|
62
|
+
private filterDeleted;
|
|
63
|
+
/** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */
|
|
64
|
+
private getOtherRelation;
|
|
65
|
+
private maybeFindExisting;
|
|
66
|
+
[RelationT]: T;
|
|
67
|
+
[RelationU]: U;
|
|
68
|
+
[ReferenceN]: N;
|
|
69
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PolymorphicReferenceImpl = exports.isPolymorphicReference = exports.hasOnePolymorphic = void 0;
|
|
5
|
+
const EntityManager_1 = require("../EntityManager");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const AbstractRelationImpl_1 = require("./AbstractRelationImpl");
|
|
8
|
+
const OneToManyCollection_1 = require("./OneToManyCollection");
|
|
9
|
+
const Reference_1 = require("./Reference");
|
|
10
|
+
const Relation_1 = require("./Relation");
|
|
11
|
+
function hasOnePolymorphic(fieldName) {
|
|
12
|
+
const entity = EntityManager_1.currentlyInstantiatingEntity;
|
|
13
|
+
return new PolymorphicReferenceImpl(entity, fieldName);
|
|
14
|
+
}
|
|
15
|
+
exports.hasOnePolymorphic = hasOnePolymorphic;
|
|
16
|
+
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
17
|
+
function isPolymorphicReference(maybeReference) {
|
|
18
|
+
return maybeReference instanceof PolymorphicReferenceImpl;
|
|
19
|
+
}
|
|
20
|
+
exports.isPolymorphicReference = isPolymorphicReference;
|
|
21
|
+
/**
|
|
22
|
+
* Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.
|
|
23
|
+
*
|
|
24
|
+
* We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the
|
|
25
|
+
* current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)
|
|
26
|
+
* from the database, or an entity `Book` / `BookReview` that the user has set.
|
|
27
|
+
*
|
|
28
|
+
* Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will
|
|
29
|
+
* essentially be half of a one-to-one relationship, but we'll keep using this reference on the "owning" side; the other
|
|
30
|
+
* side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.
|
|
31
|
+
*/
|
|
32
|
+
class PolymorphicReferenceImpl extends AbstractRelationImpl_1.AbstractRelationImpl {
|
|
33
|
+
constructor(entity, fieldName) {
|
|
34
|
+
super();
|
|
35
|
+
this.entity = entity;
|
|
36
|
+
this.fieldName = fieldName;
|
|
37
|
+
// We need a separate boolean to b/c loaded == undefined can still mean "_isLoaded" for nullable fks.
|
|
38
|
+
this._isLoaded = false;
|
|
39
|
+
this[_a] = null;
|
|
40
|
+
this[_b] = null;
|
|
41
|
+
this[_c] = null;
|
|
42
|
+
this.field = (0, EntityManager_1.getMetadata)(entity).fields[this.fieldName];
|
|
43
|
+
}
|
|
44
|
+
get currentComponent() {
|
|
45
|
+
const cstr = (0, index_1.maybeGetConstructorFromReference)(this.current());
|
|
46
|
+
return this.field.components.find((c) => c.otherMetadata().cstr === cstr);
|
|
47
|
+
}
|
|
48
|
+
get isCascadeDelete() {
|
|
49
|
+
return (this.currentComponent?.otherMetadata().config.__data.cascadeDeleteFields.includes(this.fieldName) ?? false);
|
|
50
|
+
}
|
|
51
|
+
async load(opts) {
|
|
52
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
53
|
+
const current = this.current();
|
|
54
|
+
// Resolve the id to an entity
|
|
55
|
+
if (!(0, EntityManager_1.isEntity)(current) && current !== undefined) {
|
|
56
|
+
this.loaded = (await this.entity.em.load((0, index_1.getConstructorFromTaggedId)(current), current));
|
|
57
|
+
}
|
|
58
|
+
this._isLoaded = true;
|
|
59
|
+
return this.filterDeleted(this.loaded, opts);
|
|
60
|
+
}
|
|
61
|
+
set(other) {
|
|
62
|
+
this.setImpl(other);
|
|
63
|
+
}
|
|
64
|
+
get isSet() {
|
|
65
|
+
return this.current() !== undefined;
|
|
66
|
+
}
|
|
67
|
+
get isLoaded() {
|
|
68
|
+
return this._isLoaded;
|
|
69
|
+
}
|
|
70
|
+
doGet(opts) {
|
|
71
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
72
|
+
// This should only be callable in the type system if we've already resolved this to an instance,
|
|
73
|
+
// but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW
|
|
74
|
+
if (!this._isLoaded) {
|
|
75
|
+
const existing = this.maybeFindExisting();
|
|
76
|
+
if (existing === undefined) {
|
|
77
|
+
throw new Error(`${this.entity}.${this.fieldName} was not loaded`);
|
|
78
|
+
}
|
|
79
|
+
this.loaded = existing;
|
|
80
|
+
this._isLoaded = true;
|
|
81
|
+
}
|
|
82
|
+
return this.filterDeleted(this.loaded, opts);
|
|
83
|
+
}
|
|
84
|
+
get getWithDeleted() {
|
|
85
|
+
return this.doGet({ withDeleted: true });
|
|
86
|
+
}
|
|
87
|
+
get get() {
|
|
88
|
+
return this.doGet({ withDeleted: false });
|
|
89
|
+
}
|
|
90
|
+
get id() {
|
|
91
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
92
|
+
return (0, index_1.maybeResolveReferenceToId)(this.current());
|
|
93
|
+
}
|
|
94
|
+
get idOrFail() {
|
|
95
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
96
|
+
return this.id || (0, index_1.fail)("Reference is unset or assigned to a new entity");
|
|
97
|
+
}
|
|
98
|
+
get idUntagged() {
|
|
99
|
+
return this.id && (0, index_1.deTagId)((0, EntityManager_1.getMetadata)((0, index_1.getConstructorFromTaggedId)(this.id)), this.id);
|
|
100
|
+
}
|
|
101
|
+
get idUntaggedOrFail() {
|
|
102
|
+
return this.idUntagged || (0, index_1.fail)("Reference is unset or assigned to a new entity");
|
|
103
|
+
}
|
|
104
|
+
// private impl
|
|
105
|
+
setFromOpts(other) {
|
|
106
|
+
this.setImpl(other);
|
|
107
|
+
}
|
|
108
|
+
initializeForNewEntity() {
|
|
109
|
+
// Our codegened Opts type will ensure our field is initialized if necessary/notNull
|
|
110
|
+
this._isLoaded = true;
|
|
111
|
+
}
|
|
112
|
+
async refreshIfLoaded() {
|
|
113
|
+
// TODO We should remember what load hints have been applied to this collection and re-apply them.
|
|
114
|
+
if (this._isLoaded) {
|
|
115
|
+
const current = this.current();
|
|
116
|
+
if (typeof current === "string") {
|
|
117
|
+
this.loaded = (await this.entity.em.load((0, index_1.getConstructorFromTaggedId)(current), current));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.loaded = current;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
maybeCascadeDelete() {
|
|
125
|
+
if (this.isCascadeDelete) {
|
|
126
|
+
const current = this.current({ withDeleted: true });
|
|
127
|
+
if (current !== undefined && typeof current !== "string") {
|
|
128
|
+
this.entity.em.delete(current);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async cleanupOnEntityDeleted() {
|
|
133
|
+
const current = await this.load({ withDeleted: true });
|
|
134
|
+
if (current !== undefined) {
|
|
135
|
+
const o2m = this.getOtherRelation(current);
|
|
136
|
+
if (o2m instanceof OneToManyCollection_1.OneToManyCollection) {
|
|
137
|
+
o2m.remove(this.entity, { requireLoaded: false });
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
o2m.set(undefined);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
(0, index_1.setField)(this.entity, this.fieldName, undefined);
|
|
144
|
+
this.loaded = undefined;
|
|
145
|
+
this._isLoaded = true;
|
|
146
|
+
}
|
|
147
|
+
// Internal method used by PolymorphicReference
|
|
148
|
+
setImpl(other) {
|
|
149
|
+
if (other?.isNewEntity ? other === this.loaded : this.id === other?.id) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (other !== undefined && !this.field.components.some((c) => other instanceof c.otherMetadata().cstr)) {
|
|
153
|
+
(0, index_1.fail)(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);
|
|
154
|
+
}
|
|
155
|
+
// we may not be loaded yet, but our previous entity might already be in the UoW
|
|
156
|
+
const previousLoaded = this.loaded ?? this.maybeFindExisting();
|
|
157
|
+
(0, index_1.ensureNotDeleted)(this.entity, { ignore: "pending" });
|
|
158
|
+
// Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself
|
|
159
|
+
const changed = (0, index_1.setField)(this.entity, this.fieldName, other?.id ?? other);
|
|
160
|
+
if (!changed) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.loaded = other;
|
|
164
|
+
this._isLoaded = true;
|
|
165
|
+
// If had an existing value, remove us from its collection
|
|
166
|
+
if (previousLoaded) {
|
|
167
|
+
const prevRelation = this.getOtherRelation(previousLoaded);
|
|
168
|
+
if (prevRelation instanceof OneToManyCollection_1.OneToManyCollection) {
|
|
169
|
+
prevRelation.removeIfLoaded(this.entity);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
prevRelation.set(undefined);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (other !== undefined) {
|
|
176
|
+
const newRelation = this.getOtherRelation(other);
|
|
177
|
+
if (newRelation instanceof OneToManyCollection_1.OneToManyCollection) {
|
|
178
|
+
newRelation.add(this.entity);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
newRelation.set(this.entity);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// We need to keep U in data[fieldName] to handle entities without an id assigned yet.
|
|
186
|
+
current(opts) {
|
|
187
|
+
const current = this.entity.__orm.data[this.fieldName ?? ""];
|
|
188
|
+
if (current !== undefined && (0, EntityManager_1.isEntity)(current)) {
|
|
189
|
+
return this.filterDeleted(current, opts);
|
|
190
|
+
}
|
|
191
|
+
return current;
|
|
192
|
+
}
|
|
193
|
+
toString() {
|
|
194
|
+
return `PolymorphicReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${this.currentComponent?.otherFieldName}, id: ${this.id})`;
|
|
195
|
+
}
|
|
196
|
+
filterDeleted(entity, opts) {
|
|
197
|
+
return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;
|
|
198
|
+
}
|
|
199
|
+
/** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */
|
|
200
|
+
getOtherRelation(other) {
|
|
201
|
+
const component = this.field.components.find((c) => c.otherMetadata().cstr === other.constructor);
|
|
202
|
+
return other[component?.otherFieldName];
|
|
203
|
+
}
|
|
204
|
+
maybeFindExisting() {
|
|
205
|
+
return this.id !== undefined ? this.entity.em.getEntity(this.id) : undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.PolymorphicReferenceImpl = PolymorphicReferenceImpl;
|
|
209
|
+
_a = Relation_1.RelationT, _b = Relation_1.RelationU, _c = Reference_1.ReferenceN;
|
|
210
|
+
//# sourceMappingURL=PolymorphicReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.js","sourceRoot":"","sources":["../../../src/relations/PolymorphicReference.ts"],"names":[],"mappings":";;;;AAAA,oDAO0B;AAC1B,oCAWkB;AAClB,iEAA8D;AAC9D,+DAA4D;AAC5D,2CAAyC;AACzC,yCAAkD;AAElD,SAAgB,iBAAiB,CAC/B,SAAkB;IAElB,MAAM,MAAM,GAAG,4CAAiC,CAAC;IACjD,OAAO,IAAI,wBAAwB,CAAU,MAAM,EAAE,SAAS,CAAC,CAAC;AAClE,CAAC;AALD,8CAKC;A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