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,29 @@
|
|
|
1
|
+
import { Entity, IdOf } from "../EntityManager";
|
|
2
|
+
import { Relation } from "./Relation";
|
|
3
|
+
export declare const ReferenceN: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A many-to-one / foreign key from `T` to `U`, i.e. book to author.
|
|
6
|
+
*
|
|
7
|
+
* The `N` generic is for whether the field is optional (i.e. the foreign key column is
|
|
8
|
+
* nullable). If it is optional, `N` will be `undefined`, which makes the return types
|
|
9
|
+
* `U | undefined`. If it is not optional, `N` will be `never`, making the return types
|
|
10
|
+
* `U | never` which becomes just `U`.
|
|
11
|
+
*/
|
|
12
|
+
export interface Reference<T extends Entity, U extends Entity, N extends never | undefined> extends Relation<T, U> {
|
|
13
|
+
readonly isLoaded: boolean;
|
|
14
|
+
load(opts?: {
|
|
15
|
+
withDeleted: boolean;
|
|
16
|
+
}): Promise<U | N>;
|
|
17
|
+
set(other: U | N): void;
|
|
18
|
+
[ReferenceN]: N;
|
|
19
|
+
}
|
|
20
|
+
/** Adds a known-safe `get` accessor. */
|
|
21
|
+
export interface LoadedReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
|
|
22
|
+
id: IdOf<U> | N;
|
|
23
|
+
get: U | N;
|
|
24
|
+
getWithDeleted: U | N;
|
|
25
|
+
}
|
|
26
|
+
/** Type guard utility for determining if an entity field is a Reference. */
|
|
27
|
+
export declare function isReference(maybeReference: any): maybeReference is Reference<any, any, any>;
|
|
28
|
+
/** Type guard utility for determining if an entity field is a loaded Reference. */
|
|
29
|
+
export declare function isLoadedReference(maybeReference: any): maybeReference is Reference<any, any, any> & LoadedReference<any, any, any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoadedReference = exports.isReference = exports.ReferenceN = void 0;
|
|
4
|
+
const CustomReference_1 = require("./CustomReference");
|
|
5
|
+
const ManyToOneReference_1 = require("./ManyToOneReference");
|
|
6
|
+
const OneToOneReference_1 = require("./OneToOneReference");
|
|
7
|
+
const PolymorphicReference_1 = require("./PolymorphicReference");
|
|
8
|
+
// Exported and used in sub-interfaces/types per https://stackoverflow.com/a/70437874/355031
|
|
9
|
+
exports.ReferenceN = Symbol();
|
|
10
|
+
/** Type guard utility for determining if an entity field is a Reference. */
|
|
11
|
+
function isReference(maybeReference) {
|
|
12
|
+
return (maybeReference instanceof OneToOneReference_1.OneToOneReferenceImpl ||
|
|
13
|
+
maybeReference instanceof ManyToOneReference_1.ManyToOneReferenceImpl ||
|
|
14
|
+
maybeReference instanceof CustomReference_1.CustomReference ||
|
|
15
|
+
maybeReference instanceof PolymorphicReference_1.PolymorphicReferenceImpl);
|
|
16
|
+
}
|
|
17
|
+
exports.isReference = isReference;
|
|
18
|
+
/** Type guard utility for determining if an entity field is a loaded Reference. */
|
|
19
|
+
function isLoadedReference(maybeReference) {
|
|
20
|
+
return isReference(maybeReference) && maybeReference.isLoaded;
|
|
21
|
+
}
|
|
22
|
+
exports.isLoadedReference = isLoadedReference;
|
|
23
|
+
//# sourceMappingURL=Reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Reference.js","sourceRoot":"","sources":["../../../src/relations/Reference.ts"],"names":[],"mappings":";;;AACA,uDAAoD;AACpD,6DAA8D;AAC9D,2DAA4D;AAC5D,iEAAkE;AAGlE,4FAA4F;AAC/E,QAAA,UAAU,GAAG,MAAM,EAAE,CAAC;AAqCnC,4EAA4E;AAC5E,SAAgB,WAAW,CAAC,cAAmB;IAC7C,OAAO,CACL,cAAc,YAAY,yCAAqB;QAC/C,cAAc,YAAY,2CAAsB;QAChD,cAAc,YAAY,iCAAe;QACzC,cAAc,YAAY,+CAAwB,CACnD,CAAC;AACJ,CAAC;AAPD,kCAOC;AAED,mFAAmF;AACnF,SAAgB,iBAAiB,CAC/B,cAAmB;IAEnB,OAAO,WAAW,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC;AAChE,CAAC;AAJD,8CAIC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Entity } from "../EntityManager";
|
|
2
|
+
export declare const RelationT: unique symbol;
|
|
3
|
+
export declare const RelationU: unique symbol;
|
|
4
|
+
/** A relationship from `T` to `U`, could be any of many-to-one, one-to-many, or many-to-many. */
|
|
5
|
+
export interface Relation<T extends Entity, U extends Entity> {
|
|
6
|
+
[RelationT]: T;
|
|
7
|
+
[RelationU]: U;
|
|
8
|
+
}
|
|
9
|
+
/** Type guard utility for determining if an entity field is a Relation. */
|
|
10
|
+
export declare function isRelation(maybeRelation: any): maybeRelation is Relation<any, any>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRelation = exports.RelationU = exports.RelationT = void 0;
|
|
4
|
+
const Collection_1 = require("./Collection");
|
|
5
|
+
const Reference_1 = require("./Reference");
|
|
6
|
+
exports.RelationT = Symbol();
|
|
7
|
+
exports.RelationU = Symbol();
|
|
8
|
+
/** Type guard utility for determining if an entity field is a Relation. */
|
|
9
|
+
function isRelation(maybeRelation) {
|
|
10
|
+
return (0, Reference_1.isReference)(maybeRelation) || (0, Collection_1.isCollection)(maybeRelation);
|
|
11
|
+
}
|
|
12
|
+
exports.isRelation = isRelation;
|
|
13
|
+
//# sourceMappingURL=Relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Relation.js","sourceRoot":"","sources":["../../../src/relations/Relation.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAC5C,2CAA0C;AAE7B,QAAA,SAAS,GAAG,MAAM,EAAE,CAAC;AACrB,QAAA,SAAS,GAAG,MAAM,EAAE,CAAC;AAclC,2EAA2E;AAC3E,SAAgB,UAAU,CAAC,aAAkB;IAC3C,OAAO,IAAA,uBAAW,EAAC,aAAa,CAAC,IAAI,IAAA,yBAAY,EAAC,aAAa,CAAC,CAAC;AACnE,CAAC;AAFD,gCAEC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Entity } from "../EntityManager";
|
|
2
|
+
import { Loaded, LoadHint } from "../loaded";
|
|
3
|
+
declare const I: unique symbol;
|
|
4
|
+
export interface AsyncProperty<T extends Entity, V> {
|
|
5
|
+
isLoaded: boolean;
|
|
6
|
+
load(): Promise<V>;
|
|
7
|
+
[I]?: T;
|
|
8
|
+
}
|
|
9
|
+
export interface LoadedProperty<T extends Entity, V> {
|
|
10
|
+
get: V;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a calculated derived value from a load hint + lambda.
|
|
14
|
+
*
|
|
15
|
+
* The property can be accessed by default as a promise, with `someProperty.load()`.
|
|
16
|
+
*
|
|
17
|
+
* But if `someProperty` is used as a populate hint, then it can be accessed synchronously,
|
|
18
|
+
* with `someProperty.get`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasAsyncProperty<T extends Entity, H extends LoadHint<T>, V>(loadHint: H, fn: (entity: Loaded<T, H>) => V): AsyncProperty<T, V>;
|
|
21
|
+
export declare class AsyncPropertyImpl<T extends Entity, H extends LoadHint<T>, V> implements AsyncProperty<T, V> {
|
|
22
|
+
private entity;
|
|
23
|
+
private loadHint;
|
|
24
|
+
private fn;
|
|
25
|
+
private loaded;
|
|
26
|
+
private loadPromise;
|
|
27
|
+
constructor(entity: T, loadHint: H, fn: (entity: Loaded<T, H>) => V);
|
|
28
|
+
load(): Promise<V>;
|
|
29
|
+
get get(): V;
|
|
30
|
+
get isLoaded(): boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Type guard utility for determining if an entity field is an AsyncProperty. */
|
|
33
|
+
export declare function isAsyncProperty(maybeAsyncProperty: any): maybeAsyncProperty is AsyncProperty<any, any>;
|
|
34
|
+
/** Type guard utility for determining if an entity field is a loaded AsyncProperty. */
|
|
35
|
+
export declare function isLoadedAsyncProperty(maybeAsyncProperty: any): maybeAsyncProperty is AsyncProperty<any, any> & LoadedProperty<any, any>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoadedAsyncProperty = exports.isAsyncProperty = exports.AsyncPropertyImpl = exports.hasAsyncProperty = void 0;
|
|
4
|
+
const EntityManager_1 = require("../EntityManager");
|
|
5
|
+
const I = Symbol();
|
|
6
|
+
/**
|
|
7
|
+
* Creates a calculated derived value from a load hint + lambda.
|
|
8
|
+
*
|
|
9
|
+
* The property can be accessed by default as a promise, with `someProperty.load()`.
|
|
10
|
+
*
|
|
11
|
+
* But if `someProperty` is used as a populate hint, then it can be accessed synchronously,
|
|
12
|
+
* with `someProperty.get`.
|
|
13
|
+
*/
|
|
14
|
+
function hasAsyncProperty(loadHint, fn) {
|
|
15
|
+
const entity = EntityManager_1.currentlyInstantiatingEntity;
|
|
16
|
+
return new AsyncPropertyImpl(entity, loadHint, fn);
|
|
17
|
+
}
|
|
18
|
+
exports.hasAsyncProperty = hasAsyncProperty;
|
|
19
|
+
class AsyncPropertyImpl {
|
|
20
|
+
constructor(entity, loadHint, fn) {
|
|
21
|
+
this.entity = entity;
|
|
22
|
+
this.loadHint = loadHint;
|
|
23
|
+
this.fn = fn;
|
|
24
|
+
this.loaded = false;
|
|
25
|
+
}
|
|
26
|
+
load() {
|
|
27
|
+
const { entity, loadHint, fn } = this;
|
|
28
|
+
if (!this.loaded) {
|
|
29
|
+
return (this.loadPromise ?? (this.loadPromise = entity.em.populate(entity, loadHint).then((loaded) => {
|
|
30
|
+
this.loaded = true;
|
|
31
|
+
return fn(loaded);
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
return Promise.resolve(this.get);
|
|
35
|
+
}
|
|
36
|
+
get get() {
|
|
37
|
+
const { entity, fn } = this;
|
|
38
|
+
return fn(entity);
|
|
39
|
+
}
|
|
40
|
+
get isLoaded() {
|
|
41
|
+
return this.loaded;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.AsyncPropertyImpl = AsyncPropertyImpl;
|
|
45
|
+
/** Type guard utility for determining if an entity field is an AsyncProperty. */
|
|
46
|
+
function isAsyncProperty(maybeAsyncProperty) {
|
|
47
|
+
return maybeAsyncProperty instanceof AsyncPropertyImpl;
|
|
48
|
+
}
|
|
49
|
+
exports.isAsyncProperty = isAsyncProperty;
|
|
50
|
+
/** Type guard utility for determining if an entity field is a loaded AsyncProperty. */
|
|
51
|
+
function isLoadedAsyncProperty(maybeAsyncProperty) {
|
|
52
|
+
return isAsyncProperty(maybeAsyncProperty) && maybeAsyncProperty.isLoaded;
|
|
53
|
+
}
|
|
54
|
+
exports.isLoadedAsyncProperty = isLoadedAsyncProperty;
|
|
55
|
+
//# sourceMappingURL=hasAsyncProperty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasAsyncProperty.js","sourceRoot":"","sources":["../../../src/relations/hasAsyncProperty.ts"],"names":[],"mappings":";;;AAAA,oDAAwE;AAGxE,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC;AAYnB;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,QAAW,EACX,EAA+B;IAE/B,MAAM,MAAM,GAAG,4CAAiC,CAAC;IACjD,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAND,4CAMC;AAED,MAAa,iBAAiB;IAG5B,YAAoB,MAAS,EAAU,QAAW,EAAU,EAA+B;QAAvE,WAAM,GAAN,MAAM,CAAG;QAAU,aAAQ,GAAR,QAAQ,CAAG;QAAU,OAAE,GAAF,EAAE,CAA6B;QAFnF,WAAM,GAAG,KAAK,CAAC;IAEuE,CAAC;IAE/F,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,WAAW,KAAhB,IAAI,CAAC,WAAW,GAAK,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,EAAC,CAAC;SACL;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,GAAG;QACL,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;QAC5B,OAAO,EAAE,CAAC,MAAsB,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAxBD,8CAwBC;AAED,iFAAiF;AACjF,SAAgB,eAAe,CAAC,kBAAuB;IACrD,OAAO,kBAAkB,YAAY,iBAAiB,CAAC;AACzD,CAAC;AAFD,0CAEC;AAED,uFAAuF;AACvF,SAAgB,qBAAqB,CACnC,kBAAuB;IAEvB,OAAO,eAAe,CAAC,kBAAkB,CAAC,IAAI,kBAAkB,CAAC,QAAQ,CAAC;AAC5E,CAAC;AAJD,sDAIC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Collection } from "../";
|
|
2
|
-
import { Entity
|
|
2
|
+
import { Entity } from "../EntityManager";
|
|
3
|
+
import { Loaded, LoadHint } from "../loaded";
|
|
3
4
|
declare type HasManyDerivedOpts<T extends Entity, U extends Entity, H extends LoadHint<T>> = {
|
|
4
5
|
load?: (entity: T) => Promise<any>;
|
|
5
6
|
get: (entity: Loaded<T, H>) => readonly U[];
|
|
@@ -14,7 +14,7 @@ function hasManyDerived(loadHint, opts) {
|
|
|
14
14
|
const entity = __1.currentlyInstantiatingEntity;
|
|
15
15
|
const { load, ...rest } = opts;
|
|
16
16
|
return new CustomCollection_1.CustomCollection(entity, {
|
|
17
|
-
load: load
|
|
17
|
+
load: load ?? ((entity) => entity.em.populate(entity, loadHint)),
|
|
18
18
|
...rest,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasManyDerived.js","sourceRoot":"","sources":["../../../src/relations/hasManyDerived.ts"],"names":[],"mappings":";;;AAAA,2BAA+D;AAG/D,yDAAsD;AAUtD;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,QAAW,EACX,IAAiC;IAEjC,MAAM,MAAM,GAAM,gCAAiC,CAAC;IACpD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC/B,OAAO,IAAI,mCAAgB,CAAO,MAAM,EAAE;QACxC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChE,GAAI,IAAY;KACjB,CAAC,CAAC;AACL,CAAC;AAVD,wCAUC"}
|
|
File without changes
|
|
@@ -13,9 +13,9 @@ function hasManyThrough(lens) {
|
|
|
13
13
|
const entity = index_1.currentlyInstantiatingEntity;
|
|
14
14
|
return new index_1.CustomCollection(entity, {
|
|
15
15
|
load: async (entity) => {
|
|
16
|
-
await index_1.loadLens(entity, lens);
|
|
16
|
+
await (0, index_1.loadLens)(entity, lens);
|
|
17
17
|
},
|
|
18
|
-
get: () => index_1.getLens(entity, lens),
|
|
18
|
+
get: () => (0, index_1.getLens)(entity, lens),
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.hasManyThrough = hasManyThrough;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasManyThrough.js","sourceRoot":"","sources":["../../../src/relations/hasManyThrough.ts"],"names":[],"mappings":";;;AAAA,oCAAuH;AAEvH;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,IAAqC;IAErC,MAAM,MAAM,GAAM,oCAAiC,CAAC;IACpD,OAAO,IAAI,wBAAgB,CAAO,MAAM,EAAE;QACxC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,IAAA,gBAAQ,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAA,eAAO,EAAC,MAAM,EAAE,IAAI,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAVD,wCAUC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Entity } from "../EntityManager";
|
|
2
|
+
import { Loaded, LoadHint } from "../loaded";
|
|
3
|
+
import { Reference } from "./Reference";
|
|
3
4
|
/**
|
|
4
5
|
* Creates a CustomReference that can conditionally walk across references in the object graph.
|
|
5
6
|
*
|
|
@@ -14,7 +14,7 @@ function hasOneDerived(loadHint, get) {
|
|
|
14
14
|
const entity = __1.currentlyInstantiatingEntity;
|
|
15
15
|
return new CustomReference_1.CustomReference(entity, {
|
|
16
16
|
load: async (entity) => {
|
|
17
|
-
await
|
|
17
|
+
await entity.em.populate(entity, loadHint);
|
|
18
18
|
},
|
|
19
19
|
get: () => get(entity),
|
|
20
20
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOneDerived.js","sourceRoot":"","sources":["../../../src/relations/hasOneDerived.ts"],"names":[],"mappings":";;;AAAA,2BAAmD;AAGnD,uDAAoD;AAGpD;;;;;;GAMG;AACH,SAAgB,aAAa,CAM3B,QAAW,EAAE,GAAgC;IAC7C,MAAM,MAAM,GAAM,gCAAiC,CAAC;IACpD,OAAO,IAAI,iCAAe,CAAU,MAAM,EAAE;QAC1C,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAsB,CAAC;KACvC,CAAC,CAAC;AACL,CAAC;AAdD,sCAcC"}
|
|
File without changes
|
|
@@ -13,9 +13,9 @@ function hasOneThrough(lens) {
|
|
|
13
13
|
const entity = index_1.currentlyInstantiatingEntity;
|
|
14
14
|
return new index_1.CustomReference(entity, {
|
|
15
15
|
load: async (entity) => {
|
|
16
|
-
await index_1.loadLens(entity, lens);
|
|
16
|
+
await (0, index_1.loadLens)(entity, lens);
|
|
17
17
|
},
|
|
18
|
-
get: () => index_1.getLens(entity, lens),
|
|
18
|
+
get: () => (0, index_1.getLens)(entity, lens),
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.hasOneThrough = hasOneThrough;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasOneThrough.js","sourceRoot":"","sources":["../../../src/relations/hasOneThrough.ts"],"names":[],"mappings":";;;AAAA,oCAAqH;AAErH;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,IAAgC;IAEhC,MAAM,MAAM,GAAM,oCAAiC,CAAC;IACpD,OAAO,IAAI,uBAAe,CAAU,MAAM,EAAE;QAC1C,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,IAAA,gBAAQ,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CAAC,IAAA,eAAO,EAAC,MAAM,EAAE,IAAI,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAVD,sCAUC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { Collection, isCollection, isLoadedCollection, LoadedCollection } from "./Collection";
|
|
2
|
+
export { CustomCollection } from "./CustomCollection";
|
|
3
|
+
export { CustomReference } from "./CustomReference";
|
|
4
|
+
export { AsyncProperty, hasAsyncProperty, isAsyncProperty, isLoadedAsyncProperty, LoadedProperty, } from "./hasAsyncProperty";
|
|
5
|
+
export { hasManyDerived } from "./hasManyDerived";
|
|
6
|
+
export { hasManyThrough } from "./hasManyThrough";
|
|
7
|
+
export { hasOneDerived } from "./hasOneDerived";
|
|
8
|
+
export { hasOneThrough } from "./hasOneThrough";
|
|
9
|
+
export { LargeCollection } from "./LargeCollection";
|
|
10
|
+
export { hasManyToMany, ManyToManyCollection } from "./ManyToManyCollection";
|
|
11
|
+
export { hasLargeManyToMany, ManyToManyLargeCollection } from "./ManyToManyLargeCollection";
|
|
12
|
+
export { hasOne, isManyToOneReference, ManyToOneReference, ManyToOneReferenceImpl } from "./ManyToOneReference";
|
|
13
|
+
export { hasMany, OneToManyCollection } from "./OneToManyCollection";
|
|
14
|
+
export { hasLargeMany, OneToManyLargeCollection } from "./OneToManyLargeCollection";
|
|
15
|
+
export { hasOneToOne, isLoadedOneToOneReference, isOneToOneReference, OneToOneReference, OneToOneReferenceImpl, } from "./OneToOneReference";
|
|
16
|
+
export { hasOnePolymorphic, isPolymorphicReference, PolymorphicReference, PolymorphicReferenceImpl, } from "./PolymorphicReference";
|
|
17
|
+
export { isLoadedReference, isReference, LoadedReference, Reference } from "./Reference";
|
|
18
|
+
export { isRelation, Relation } from "./Relation";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRelation = exports.isReference = exports.isLoadedReference = exports.PolymorphicReferenceImpl = exports.isPolymorphicReference = exports.hasOnePolymorphic = exports.OneToOneReferenceImpl = exports.isOneToOneReference = exports.isLoadedOneToOneReference = exports.hasOneToOne = exports.OneToManyLargeCollection = exports.hasLargeMany = exports.OneToManyCollection = exports.hasMany = exports.ManyToOneReferenceImpl = exports.isManyToOneReference = exports.hasOne = exports.ManyToManyLargeCollection = exports.hasLargeManyToMany = exports.ManyToManyCollection = exports.hasManyToMany = exports.hasOneThrough = exports.hasOneDerived = exports.hasManyThrough = exports.hasManyDerived = exports.isLoadedAsyncProperty = exports.isAsyncProperty = exports.hasAsyncProperty = exports.CustomReference = exports.CustomCollection = exports.isLoadedCollection = exports.isCollection = void 0;
|
|
4
|
+
var Collection_1 = require("./Collection");
|
|
5
|
+
Object.defineProperty(exports, "isCollection", { enumerable: true, get: function () { return Collection_1.isCollection; } });
|
|
6
|
+
Object.defineProperty(exports, "isLoadedCollection", { enumerable: true, get: function () { return Collection_1.isLoadedCollection; } });
|
|
7
|
+
var CustomCollection_1 = require("./CustomCollection");
|
|
8
|
+
Object.defineProperty(exports, "CustomCollection", { enumerable: true, get: function () { return CustomCollection_1.CustomCollection; } });
|
|
9
|
+
var CustomReference_1 = require("./CustomReference");
|
|
10
|
+
Object.defineProperty(exports, "CustomReference", { enumerable: true, get: function () { return CustomReference_1.CustomReference; } });
|
|
11
|
+
var hasAsyncProperty_1 = require("./hasAsyncProperty");
|
|
12
|
+
Object.defineProperty(exports, "hasAsyncProperty", { enumerable: true, get: function () { return hasAsyncProperty_1.hasAsyncProperty; } });
|
|
13
|
+
Object.defineProperty(exports, "isAsyncProperty", { enumerable: true, get: function () { return hasAsyncProperty_1.isAsyncProperty; } });
|
|
14
|
+
Object.defineProperty(exports, "isLoadedAsyncProperty", { enumerable: true, get: function () { return hasAsyncProperty_1.isLoadedAsyncProperty; } });
|
|
15
|
+
var hasManyDerived_1 = require("./hasManyDerived");
|
|
16
|
+
Object.defineProperty(exports, "hasManyDerived", { enumerable: true, get: function () { return hasManyDerived_1.hasManyDerived; } });
|
|
17
|
+
var hasManyThrough_1 = require("./hasManyThrough");
|
|
18
|
+
Object.defineProperty(exports, "hasManyThrough", { enumerable: true, get: function () { return hasManyThrough_1.hasManyThrough; } });
|
|
19
|
+
var hasOneDerived_1 = require("./hasOneDerived");
|
|
20
|
+
Object.defineProperty(exports, "hasOneDerived", { enumerable: true, get: function () { return hasOneDerived_1.hasOneDerived; } });
|
|
21
|
+
var hasOneThrough_1 = require("./hasOneThrough");
|
|
22
|
+
Object.defineProperty(exports, "hasOneThrough", { enumerable: true, get: function () { return hasOneThrough_1.hasOneThrough; } });
|
|
23
|
+
var ManyToManyCollection_1 = require("./ManyToManyCollection");
|
|
24
|
+
Object.defineProperty(exports, "hasManyToMany", { enumerable: true, get: function () { return ManyToManyCollection_1.hasManyToMany; } });
|
|
25
|
+
Object.defineProperty(exports, "ManyToManyCollection", { enumerable: true, get: function () { return ManyToManyCollection_1.ManyToManyCollection; } });
|
|
26
|
+
var ManyToManyLargeCollection_1 = require("./ManyToManyLargeCollection");
|
|
27
|
+
Object.defineProperty(exports, "hasLargeManyToMany", { enumerable: true, get: function () { return ManyToManyLargeCollection_1.hasLargeManyToMany; } });
|
|
28
|
+
Object.defineProperty(exports, "ManyToManyLargeCollection", { enumerable: true, get: function () { return ManyToManyLargeCollection_1.ManyToManyLargeCollection; } });
|
|
29
|
+
var ManyToOneReference_1 = require("./ManyToOneReference");
|
|
30
|
+
Object.defineProperty(exports, "hasOne", { enumerable: true, get: function () { return ManyToOneReference_1.hasOne; } });
|
|
31
|
+
Object.defineProperty(exports, "isManyToOneReference", { enumerable: true, get: function () { return ManyToOneReference_1.isManyToOneReference; } });
|
|
32
|
+
Object.defineProperty(exports, "ManyToOneReferenceImpl", { enumerable: true, get: function () { return ManyToOneReference_1.ManyToOneReferenceImpl; } });
|
|
33
|
+
var OneToManyCollection_1 = require("./OneToManyCollection");
|
|
34
|
+
Object.defineProperty(exports, "hasMany", { enumerable: true, get: function () { return OneToManyCollection_1.hasMany; } });
|
|
35
|
+
Object.defineProperty(exports, "OneToManyCollection", { enumerable: true, get: function () { return OneToManyCollection_1.OneToManyCollection; } });
|
|
36
|
+
var OneToManyLargeCollection_1 = require("./OneToManyLargeCollection");
|
|
37
|
+
Object.defineProperty(exports, "hasLargeMany", { enumerable: true, get: function () { return OneToManyLargeCollection_1.hasLargeMany; } });
|
|
38
|
+
Object.defineProperty(exports, "OneToManyLargeCollection", { enumerable: true, get: function () { return OneToManyLargeCollection_1.OneToManyLargeCollection; } });
|
|
39
|
+
var OneToOneReference_1 = require("./OneToOneReference");
|
|
40
|
+
Object.defineProperty(exports, "hasOneToOne", { enumerable: true, get: function () { return OneToOneReference_1.hasOneToOne; } });
|
|
41
|
+
Object.defineProperty(exports, "isLoadedOneToOneReference", { enumerable: true, get: function () { return OneToOneReference_1.isLoadedOneToOneReference; } });
|
|
42
|
+
Object.defineProperty(exports, "isOneToOneReference", { enumerable: true, get: function () { return OneToOneReference_1.isOneToOneReference; } });
|
|
43
|
+
Object.defineProperty(exports, "OneToOneReferenceImpl", { enumerable: true, get: function () { return OneToOneReference_1.OneToOneReferenceImpl; } });
|
|
44
|
+
var PolymorphicReference_1 = require("./PolymorphicReference");
|
|
45
|
+
Object.defineProperty(exports, "hasOnePolymorphic", { enumerable: true, get: function () { return PolymorphicReference_1.hasOnePolymorphic; } });
|
|
46
|
+
Object.defineProperty(exports, "isPolymorphicReference", { enumerable: true, get: function () { return PolymorphicReference_1.isPolymorphicReference; } });
|
|
47
|
+
Object.defineProperty(exports, "PolymorphicReferenceImpl", { enumerable: true, get: function () { return PolymorphicReference_1.PolymorphicReferenceImpl; } });
|
|
48
|
+
var Reference_1 = require("./Reference");
|
|
49
|
+
Object.defineProperty(exports, "isLoadedReference", { enumerable: true, get: function () { return Reference_1.isLoadedReference; } });
|
|
50
|
+
Object.defineProperty(exports, "isReference", { enumerable: true, get: function () { return Reference_1.isReference; } });
|
|
51
|
+
var Relation_1 = require("./Relation");
|
|
52
|
+
Object.defineProperty(exports, "isRelation", { enumerable: true, get: function () { return Relation_1.isRelation; } });
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relations/index.ts"],"names":[],"mappings":";;;AAAA,2CAA8F;AAAzE,0GAAA,YAAY,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AACrD,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAM4B;AAJ1B,oHAAA,gBAAgB,OAAA;AAChB,mHAAA,eAAe,OAAA;AACf,yHAAA,qBAAqB,OAAA;AAGvB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,+DAA6E;AAApE,qHAAA,aAAa,OAAA;AAAE,4HAAA,oBAAoB,OAAA;AAC5C,yEAA4F;AAAnF,+HAAA,kBAAkB,OAAA;AAAE,sIAAA,yBAAyB,OAAA;AACtD,2DAAgH;AAAvG,4GAAA,MAAM,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAAsB,4HAAA,sBAAsB,OAAA;AACjF,6DAAqE;AAA5D,8GAAA,OAAO,OAAA;AAAE,0HAAA,mBAAmB,OAAA;AACrC,uEAAoF;AAA3E,wHAAA,YAAY,OAAA;AAAE,oIAAA,wBAAwB,OAAA;AAC/C,yDAM6B;AAL3B,gHAAA,WAAW,OAAA;AACX,8HAAA,yBAAyB,OAAA;AACzB,wHAAA,mBAAmB,OAAA;AAEnB,0HAAA,qBAAqB,OAAA;AAEvB,+DAKgC;AAJ9B,yHAAA,iBAAiB,OAAA;AACjB,8HAAA,sBAAsB,OAAA;AAEtB,gIAAA,wBAAwB,OAAA;AAE1B,yCAAyF;AAAhF,8GAAA,iBAAiB,OAAA;AAAE,wGAAA,WAAW,OAAA;AACvC,uCAAkD;AAAzC,sGAAA,UAAU,OAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Entity, EntityConstructor
|
|
1
|
+
import { Entity, EntityConstructor } from "./EntityManager";
|
|
2
|
+
import { LoadHint } from "./loaded";
|
|
2
3
|
/**
|
|
3
4
|
* Given a load hint of "given an entity, load these N things", return an array
|
|
4
5
|
* of what those N things are, and reversed load hints to "come back" to the
|
|
@@ -12,9 +12,9 @@ function reverseHint(entityType, hint) {
|
|
|
12
12
|
if (typeof hint === "string") {
|
|
13
13
|
// For a simple string hint, i.e. Book "author", find the Book.author field,
|
|
14
14
|
// and use the metdata to find the otherFieldName, i.e. Author "books"
|
|
15
|
-
const meta = EntityManager_1.getMetadata(entityType);
|
|
16
|
-
const field = meta.fields
|
|
17
|
-
if (field.kind !== "m2m" && field.kind !== "m2o" && field.kind !== "o2m") {
|
|
15
|
+
const meta = (0, EntityManager_1.getMetadata)(entityType);
|
|
16
|
+
const field = meta.fields[hint] || (0, utils_1.fail)(`Invalid hint ${entityType.name} ${JSON.stringify(hint)}`);
|
|
17
|
+
if (field.kind !== "m2m" && field.kind !== "m2o" && field.kind !== "o2m" && field.kind !== "o2o") {
|
|
18
18
|
throw new Error("Invalid hint");
|
|
19
19
|
}
|
|
20
20
|
const otherMeta = field.otherMetadata();
|
|
@@ -30,15 +30,19 @@ function reverseHint(entityType, hint) {
|
|
|
30
30
|
// For a hash of hints, i.e. Author { books: reviews }, recurse for each
|
|
31
31
|
// key in the hash, and then combine
|
|
32
32
|
return Object.entries(hint).flatMap(([key, hint]) => {
|
|
33
|
-
const meta = EntityManager_1.getMetadata(entityType);
|
|
34
|
-
const field = meta.fields
|
|
35
|
-
if (field.kind !== "m2m" && field.kind !== "m2o" && field.kind !== "o2m") {
|
|
33
|
+
const meta = (0, EntityManager_1.getMetadata)(entityType);
|
|
34
|
+
const field = meta.fields[key] || (0, utils_1.fail)(`Invalid hint ${entityType.name} ${JSON.stringify(hint)}`);
|
|
35
|
+
if (field.kind !== "m2m" && field.kind !== "m2o" && field.kind !== "o2m" && field.kind !== "o2o") {
|
|
36
36
|
throw new Error("Invalid hint");
|
|
37
37
|
}
|
|
38
38
|
const otherMeta = field.otherMetadata();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const me = [otherMeta.cstr, [field.otherFieldName]];
|
|
40
|
+
return [
|
|
41
|
+
me,
|
|
42
|
+
...reverseHint(otherMeta.cstr, hint).map(([e, hint]) => {
|
|
43
|
+
return [e, [...hint, field.otherFieldName]];
|
|
44
|
+
}),
|
|
45
|
+
];
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverseHint.js","sourceRoot":"","sources":["../../src/reverseHint.ts"],"names":[],"mappings":";;;AAAA,mDAAyE;AAEzE,mCAA+B;AAE/B;;;;GAIG;AACH,SAAgB,WAAW,CACzB,UAAgC,EAChC,IAAiB;IAEjB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,4EAA4E;QAC5E,sEAAsE;QACtE,MAAM,IAAI,GAAG,IAAA,2BAAW,EAAC,UAAU,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAA,YAAI,EAAC,gBAAgB,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnG,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;YAChG,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;SACjC;QACD,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;QACxC,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;KACnD;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9B,uEAAuE;QACvE,uEAAuE;QACvE,wBAAwB;QACxB,OAAQ,IAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,IAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;KACtF;SAAM;QACL,wEAAwE;QACxE,oCAAoC;QACpC,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;YAClD,MAAM,IAAI,GAAG,IAAA,2BAAW,EAAC,UAAU,CAAC,CAAC;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAA,YAAI,EAAC,gBAAgB,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClG,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;gBAChG,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;aACjC;YACD,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;YACxC,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAuC,CAAC;YAC1F,OAAO;gBACL,EAAE;gBACF,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;oBACrD,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAuC,CAAC;gBACpF,CAAC,CAAC;aACH,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAtCD,kCAsCC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Entity } from "./EntityManager";
|
|
2
|
+
/**
|
|
3
|
+
* Return type of a `ValidationRule`.
|
|
4
|
+
*
|
|
5
|
+
* Consumers can extend `GenericError` to add fields relevant for their application.
|
|
6
|
+
*/
|
|
7
|
+
export declare type ValidationRuleResult<E extends GenericError> = string | E | E[] | undefined;
|
|
8
|
+
/** Entity validation errors; if `entity` is invalid, throw a `ValidationError`. */
|
|
9
|
+
export declare type ValidationRule<T extends Entity> = (entity: T) => MaybePromise<ValidationRuleResult<any>>;
|
|
10
|
+
export declare type MaybePromise<T> = T | PromiseLike<T>;
|
|
11
|
+
/** A generic error which contains only a message field */
|
|
12
|
+
export declare type GenericError = {
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
/** An extension to GenericError which associates the error to a specific entity */
|
|
16
|
+
export declare type ValidationError = {
|
|
17
|
+
entity: Entity;
|
|
18
|
+
} & GenericError;
|
|
19
|
+
export declare class ValidationErrors extends Error {
|
|
20
|
+
errors: ValidationError[];
|
|
21
|
+
constructor(errors: ValidationError[]);
|
|
22
|
+
}
|
|
23
|
+
export declare function newRequiredRule<T extends Entity>(key: keyof T): ValidationRule<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newRequiredRule = exports.ValidationErrors = void 0;
|
|
4
|
+
class ValidationErrors extends Error {
|
|
5
|
+
constructor(errors) {
|
|
6
|
+
super(errorMessage(errors));
|
|
7
|
+
this.errors = errors;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ValidationErrors = ValidationErrors;
|
|
11
|
+
function newRequiredRule(key) {
|
|
12
|
+
return (entity) => (entity.__orm.data[key] === undefined ? `${key} is required` : undefined);
|
|
13
|
+
}
|
|
14
|
+
exports.newRequiredRule = newRequiredRule;
|
|
15
|
+
function errorMessage(errors) {
|
|
16
|
+
if (errors.length === 1) {
|
|
17
|
+
return `Validation error: ${errors[0].message}`;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return `Validation errors (${errors.length}): ${errors.map((e) => e.message).join(", ")}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/rules.ts"],"names":[],"mappings":";;;AAoBA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAmB,MAAyB;QAC1C,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;QADX,WAAM,GAAN,MAAM,CAAmB;IAE5C,CAAC;CACF;AAJD,4CAIC;AAED,SAAgB,eAAe,CAAmB,GAAY;IAC5D,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAC/F,CAAC;AAFD,0CAEC;AAED,SAAS,YAAY,CAAC,MAAyB;IAC7C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,qBAAqB,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;KACjD;SAAM;QACL,OAAO,sBAAsB,MAAM,CAAC,MAAM,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;KAC3F;AACH,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Field, SerdeField } from "./EntityManager";
|
|
2
|
+
import { EntityMetadata } from "./index";
|
|
3
|
+
export declare function hasSerde(field: Field): field is SerdeField;
|
|
4
|
+
/**
|
|
5
|
+
* The database/column serialization / deserialization details of a given field.
|
|
6
|
+
*
|
|
7
|
+
* Most implementations will have just a single column in `columns`, but some logical
|
|
8
|
+
* domain fields can be mapped to multiple physical database columns, i.e. polymorphic
|
|
9
|
+
* references.
|
|
10
|
+
*/
|
|
11
|
+
export interface FieldSerde {
|
|
12
|
+
/** A single field might persist to multiple columns, i.e. polymorphic references. */
|
|
13
|
+
columns: Column[];
|
|
14
|
+
/**
|
|
15
|
+
* Accepts a database `row` and sets the field's value(s) into the `__orm.data`.
|
|
16
|
+
*
|
|
17
|
+
* Used in EntityManager.hydrate to set row value on the entity
|
|
18
|
+
*/
|
|
19
|
+
setOnEntity(data: any, row: any): void;
|
|
20
|
+
}
|
|
21
|
+
/** A specific physical column of a logical field. */
|
|
22
|
+
export interface Column {
|
|
23
|
+
columnName: string;
|
|
24
|
+
dbType: string;
|
|
25
|
+
dbValue(data: any): any;
|
|
26
|
+
mapToDb(value: any): any;
|
|
27
|
+
isArray: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class PrimitiveSerde implements FieldSerde {
|
|
30
|
+
private fieldName;
|
|
31
|
+
columnName: string;
|
|
32
|
+
dbType: string;
|
|
33
|
+
isArray: boolean;
|
|
34
|
+
columns: this[];
|
|
35
|
+
constructor(fieldName: string, columnName: string, dbType: string);
|
|
36
|
+
setOnEntity(data: any, row: any): void;
|
|
37
|
+
dbValue(data: any): any;
|
|
38
|
+
mapToDb(value: any): any;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Maps `decimal(...)` database types to the JS `number`.
|
|
42
|
+
*
|
|
43
|
+
* Note that we assume the db values are within the range of the JS `number`;
|
|
44
|
+
* we should eventually sanity check that.
|
|
45
|
+
*
|
|
46
|
+
* Also note that knex/pg accept `number`s as input, so we only need
|
|
47
|
+
* to handle from-database -> to JS translation.
|
|
48
|
+
*/
|
|
49
|
+
export declare class DecimalToNumberSerde implements FieldSerde {
|
|
50
|
+
private fieldName;
|
|
51
|
+
columnName: string;
|
|
52
|
+
dbType: string;
|
|
53
|
+
isArray: boolean;
|
|
54
|
+
columns: this[];
|
|
55
|
+
constructor(fieldName: string, columnName: string);
|
|
56
|
+
setOnEntity(data: any, row: any): void;
|
|
57
|
+
dbValue(data: any): any;
|
|
58
|
+
mapToDb(value: any): any;
|
|
59
|
+
}
|
|
60
|
+
/** Maps physical integer keys to logical string IDs "because GraphQL". */
|
|
61
|
+
export declare class KeySerde implements FieldSerde {
|
|
62
|
+
private fieldName;
|
|
63
|
+
columnName: string;
|
|
64
|
+
dbType: "int" | "uuid";
|
|
65
|
+
isArray: boolean;
|
|
66
|
+
columns: this[];
|
|
67
|
+
private meta;
|
|
68
|
+
constructor(tagName: string, fieldName: string, columnName: string, dbType: "int" | "uuid");
|
|
69
|
+
setOnEntity(data: any, row: any): void;
|
|
70
|
+
dbValue(data: any): number | undefined;
|
|
71
|
+
mapToDb(value: any): number | undefined;
|
|
72
|
+
}
|
|
73
|
+
export declare class PolymorphicKeySerde implements FieldSerde {
|
|
74
|
+
private meta;
|
|
75
|
+
private fieldName;
|
|
76
|
+
constructor(meta: () => EntityMetadata<any>, fieldName: string);
|
|
77
|
+
setOnEntity(data: any, row: any): void;
|
|
78
|
+
get columns(): Array<Column & {
|
|
79
|
+
otherMetadata: () => EntityMetadata<any>;
|
|
80
|
+
}>;
|
|
81
|
+
get columnName(): string;
|
|
82
|
+
private get field();
|
|
83
|
+
}
|
|
84
|
+
export declare class EnumFieldSerde implements FieldSerde {
|
|
85
|
+
private fieldName;
|
|
86
|
+
columnName: string;
|
|
87
|
+
private enumObject;
|
|
88
|
+
dbType: string;
|
|
89
|
+
isArray: boolean;
|
|
90
|
+
columns: this[];
|
|
91
|
+
constructor(fieldName: string, columnName: string, enumObject: any);
|
|
92
|
+
setOnEntity(data: any, row: any): void;
|
|
93
|
+
dbValue(data: any): any;
|
|
94
|
+
mapToDb(value: any): any;
|
|
95
|
+
}
|
|
96
|
+
export declare class EnumArrayFieldSerde implements FieldSerde {
|
|
97
|
+
private fieldName;
|
|
98
|
+
columnName: string;
|
|
99
|
+
private enumObject;
|
|
100
|
+
dbType: string;
|
|
101
|
+
isArray: boolean;
|
|
102
|
+
columns: this[];
|
|
103
|
+
constructor(fieldName: string, columnName: string, enumObject: any);
|
|
104
|
+
setOnEntity(data: any, row: any): void;
|
|
105
|
+
dbValue(data: any): any;
|
|
106
|
+
mapToDb(value: any): any;
|
|
107
|
+
}
|
|
108
|
+
/** Similar to SimpleSerde, but applies the superstruct `assert` function when reading values from the db. */
|
|
109
|
+
export declare class SuperstructSerde implements FieldSerde {
|
|
110
|
+
private fieldName;
|
|
111
|
+
columnName: string;
|
|
112
|
+
private superstruct;
|
|
113
|
+
dbType: string;
|
|
114
|
+
isArray: boolean;
|
|
115
|
+
columns: this[];
|
|
116
|
+
private assert;
|
|
117
|
+
constructor(fieldName: string, columnName: string, superstruct: any);
|
|
118
|
+
setOnEntity(data: any, row: any): void;
|
|
119
|
+
dbValue(data: any): any;
|
|
120
|
+
mapToDb(value: any): any;
|
|
121
|
+
}
|