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
|
@@ -4,7 +4,7 @@ import { Entity, EntityManager, EntityOrmField, IdOf, OptsOf, PartialOrNull } fr
|
|
|
4
4
|
*
|
|
5
5
|
* Currently this just adds the `.load(lensFn)` method for declarative reference traversal.
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class BaseEntity implements Entity {
|
|
7
|
+
export declare abstract class BaseEntity<EM extends EntityManager = EntityManager> implements Entity {
|
|
8
8
|
abstract id: string | undefined;
|
|
9
9
|
readonly __orm: EntityOrmField;
|
|
10
10
|
protected constructor(em: EntityManager, metadata: any, defaultValues: object, opts: any);
|
|
@@ -23,6 +23,7 @@ export declare abstract class BaseEntity implements Entity {
|
|
|
23
23
|
get isPendingFlush(): boolean;
|
|
24
24
|
get isPendingDelete(): boolean;
|
|
25
25
|
toString(): string;
|
|
26
|
+
get em(): EM;
|
|
26
27
|
/**
|
|
27
28
|
* A very simple toJSON.
|
|
28
29
|
*
|
|
@@ -9,28 +9,29 @@ const index_1 = require("./index");
|
|
|
9
9
|
*/
|
|
10
10
|
class BaseEntity {
|
|
11
11
|
constructor(em, metadata, defaultValues, opts) {
|
|
12
|
-
this.__orm = { em, metadata, data: { ...defaultValues }, originalData: {} };
|
|
12
|
+
this.__orm = { em, metadata, data: { ...defaultValues }, originalData: {}, isNew: true, isTouched: false };
|
|
13
13
|
// Ensure we have at least id set so the `EntityManager.register` works
|
|
14
14
|
if (typeof opts === "string") {
|
|
15
15
|
this.__orm.data["id"] = opts;
|
|
16
|
+
this.__orm.isNew = false;
|
|
16
17
|
}
|
|
17
18
|
em.register(metadata, this);
|
|
18
19
|
}
|
|
19
20
|
get idUntagged() {
|
|
20
21
|
if (this.id) {
|
|
21
|
-
return index_1.deTagIds(index_1.getMetadata(this), [this.id])[0];
|
|
22
|
+
return (0, index_1.deTagIds)((0, index_1.getMetadata)(this), [this.id])[0];
|
|
22
23
|
}
|
|
23
24
|
return undefined;
|
|
24
25
|
}
|
|
25
26
|
get idUntaggedOrFail() {
|
|
26
|
-
return this.idUntagged || index_1.fail("Entity has no id yet");
|
|
27
|
+
return this.idUntagged || (0, index_1.fail)("Entity has no id yet");
|
|
27
28
|
}
|
|
28
29
|
/** @returns the current entity id or a runtime error if it's unassigned, i.e. it's not been assigned from the db yet. */
|
|
29
30
|
get idOrFail() {
|
|
30
|
-
return this.__orm.data["id"] || index_1.fail("Entity has no id yet");
|
|
31
|
+
return this.__orm.data["id"] || (0, index_1.fail)("Entity has no id yet");
|
|
31
32
|
}
|
|
32
33
|
get isNewEntity() {
|
|
33
|
-
return this.
|
|
34
|
+
return this.__orm.isNew;
|
|
34
35
|
}
|
|
35
36
|
get isDeletedEntity() {
|
|
36
37
|
return this.__orm.deleted !== undefined;
|
|
@@ -39,18 +40,21 @@ class BaseEntity {
|
|
|
39
40
|
return Object.keys(this.__orm.originalData).length > 0;
|
|
40
41
|
}
|
|
41
42
|
get isPendingFlush() {
|
|
42
|
-
return this.isNewEntity || this.isDirtyEntity || this.isPendingDelete;
|
|
43
|
+
return this.isNewEntity || this.isDirtyEntity || this.isPendingDelete || this.__orm.isTouched;
|
|
43
44
|
}
|
|
44
45
|
get isPendingDelete() {
|
|
45
46
|
return this.__orm.deleted === "pending";
|
|
46
47
|
}
|
|
47
48
|
toString() {
|
|
48
|
-
const meta = index_1.getMetadata(this);
|
|
49
|
+
const meta = (0, index_1.getMetadata)(this);
|
|
49
50
|
// Strip the tag because we add back the entity prefix
|
|
50
|
-
const id = index_1.keyToNumber(meta, this.id) || "new";
|
|
51
|
+
const id = (0, index_1.keyToNumber)(meta, this.id) || "new";
|
|
51
52
|
// Returns `Author:1` instead of `author:1` to differentiate the instance's toString from the tagged id itself
|
|
52
53
|
return `${meta.type}:${id}`;
|
|
53
54
|
}
|
|
55
|
+
get em() {
|
|
56
|
+
return this.__orm.em;
|
|
57
|
+
}
|
|
54
58
|
/**
|
|
55
59
|
* A very simple toJSON.
|
|
56
60
|
*
|
|
@@ -62,7 +66,7 @@ class BaseEntity {
|
|
|
62
66
|
toJSON() {
|
|
63
67
|
return Object.fromEntries(Object.entries(this.__orm.data).map(([key, value]) => {
|
|
64
68
|
// Don't recurse into new entities b/c the point is to stay shallow
|
|
65
|
-
return [key, index_1.isEntity(value) ? value.toString() : value];
|
|
69
|
+
return [key, (0, index_1.isEntity)(value) ? value.toString() : value];
|
|
66
70
|
}));
|
|
67
71
|
}
|
|
68
72
|
[Symbol.toStringTag]() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseEntity.js","sourceRoot":"","sources":["../../src/BaseEntity.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
import DataLoader from "dataloader";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { Knex } from "knex";
|
|
5
|
+
import { Driver } from "./drivers/driver";
|
|
6
|
+
import { ConfigApi, DeepPartialOrNull, FieldSerde, PartialOrNull, PolymorphicKeySerde } from "./index";
|
|
7
|
+
import { Loaded, LoadHint, New } from "./loaded";
|
|
8
|
+
import { JoinRow } from "./relations/ManyToManyCollection";
|
|
8
9
|
export interface EntityConstructor<T> {
|
|
9
|
-
new (em: EntityManager
|
|
10
|
+
new (em: EntityManager<any>, opts: any): T;
|
|
10
11
|
}
|
|
11
12
|
/** Return the `FooOpts` type a given `Foo` entity constructor. */
|
|
12
13
|
export declare type OptsOf<T> = T extends {
|
|
13
|
-
|
|
14
|
+
__orm: {
|
|
14
15
|
optsType: infer O;
|
|
15
16
|
};
|
|
16
17
|
} ? O : never;
|
|
17
18
|
export declare type OptIdsOf<T> = T extends {
|
|
18
|
-
|
|
19
|
+
__orm: {
|
|
19
20
|
optIdsType: infer O;
|
|
20
21
|
};
|
|
21
22
|
} ? O : never;
|
|
@@ -23,19 +24,19 @@ export declare type OptIdsOf<T> = T extends {
|
|
|
23
24
|
export declare type EntityOf<C> = C extends new (em: EntityManager, opts: any) => infer T ? T : never;
|
|
24
25
|
/** Pulls the entity query type out of a given entity type T. */
|
|
25
26
|
export declare type FilterOf<T> = T extends {
|
|
26
|
-
|
|
27
|
+
__orm: {
|
|
27
28
|
filterType: infer Q;
|
|
28
29
|
};
|
|
29
30
|
} ? Q : never;
|
|
30
31
|
/** Pulls the entity GraphQL query type out of a given entity type T. */
|
|
31
32
|
export declare type GraphQLFilterOf<T> = T extends {
|
|
32
|
-
|
|
33
|
+
__orm: {
|
|
33
34
|
gqlFilterType: infer Q;
|
|
34
35
|
};
|
|
35
36
|
} ? Q : never;
|
|
36
37
|
/** Pulls the entity order type out of a given entity type T. */
|
|
37
38
|
export declare type OrderOf<T> = T extends {
|
|
38
|
-
|
|
39
|
+
__orm: {
|
|
39
40
|
orderType: infer Q;
|
|
40
41
|
};
|
|
41
42
|
} ? Q : never;
|
|
@@ -45,7 +46,7 @@ export declare type OrderOf<T> = T extends {
|
|
|
45
46
|
* This is because `FactoryOpts` is a set of defaults, but the user can customize it if they want.
|
|
46
47
|
*/
|
|
47
48
|
export declare type ActualFactoryOpts<T> = T extends {
|
|
48
|
-
|
|
49
|
+
__orm: {
|
|
49
50
|
factoryOptsType: infer Q;
|
|
50
51
|
};
|
|
51
52
|
} ? Q : never;
|
|
@@ -53,6 +54,7 @@ export declare type ActualFactoryOpts<T> = T extends {
|
|
|
53
54
|
export declare type IdOf<T> = T extends {
|
|
54
55
|
id: infer I | undefined;
|
|
55
56
|
} ? I : never;
|
|
57
|
+
export declare function isId(value: any): value is IdOf<unknown>;
|
|
56
58
|
/** The `__orm` metadata field we track on each instance. */
|
|
57
59
|
export interface EntityOrmField {
|
|
58
60
|
/** A point to our entity type's metadata. */
|
|
@@ -65,6 +67,10 @@ export interface EntityOrmField {
|
|
|
65
67
|
deleted?: "pending" | "deleted";
|
|
66
68
|
/** All entities must be associated to an `EntityManager` to handle lazy loading/etc. */
|
|
67
69
|
em: EntityManager;
|
|
70
|
+
/** Whether our entity is new or not. */
|
|
71
|
+
isNew: boolean;
|
|
72
|
+
/** Whether our entity should flush regardless of any other changes. */
|
|
73
|
+
isTouched: boolean;
|
|
68
74
|
}
|
|
69
75
|
export declare let currentlyInstantiatingEntity: Entity | undefined;
|
|
70
76
|
/** A marker/base interface for all of our entity types. */
|
|
@@ -72,6 +78,7 @@ export interface Entity {
|
|
|
72
78
|
id: string | undefined;
|
|
73
79
|
idOrFail: string;
|
|
74
80
|
__orm: EntityOrmField;
|
|
81
|
+
readonly em: EntityManager<any>;
|
|
75
82
|
readonly isNewEntity: boolean;
|
|
76
83
|
readonly isDeletedEntity: boolean;
|
|
77
84
|
readonly isDirtyEntity: boolean;
|
|
@@ -80,78 +87,54 @@ export interface Entity {
|
|
|
80
87
|
set(opts: Partial<OptsOf<this>>): void;
|
|
81
88
|
setPartial(values: PartialOrNull<OptsOf<this>>): void;
|
|
82
89
|
}
|
|
83
|
-
|
|
84
|
-
declare type
|
|
90
|
+
declare type MaybePromise<T> = T | PromiseLike<T>;
|
|
91
|
+
export declare type EntityManagerHook = "beforeTransaction" | "afterTransaction";
|
|
92
|
+
declare type HookFn = (em: EntityManager, knex: Knex.Transaction) => MaybePromise<any>;
|
|
85
93
|
/**
|
|
86
|
-
* A
|
|
87
|
-
*
|
|
88
|
-
* We also look in opts `O` for the "`U`" type, i.e. the next level up/down in the graph,
|
|
89
|
-
* because the call site's opts may be using an also-marked loaded parent/child as an opt,
|
|
90
|
-
* so this will infer the type of that parent/child and use that for the `U` type.
|
|
94
|
+
* A marker to prevent setter calls during `flush` calls.
|
|
91
95
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
96
|
+
* The `flush` process does a dirty check + SQL flush and generally doesn't want
|
|
97
|
+
* entities to re-dirtied after it's done the initial dirty check. So we'd like
|
|
98
|
+
* to prevent all setter calls while `flush` is running.
|
|
94
99
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
98
|
-
declare type MaybeUseOptsType<T extends Entity, O, K extends keyof T & keyof O> = O[K] extends NullOrDefinedOr<infer OK> ? OK extends Entity ? T[K] extends Reference<T, infer U, infer N> ? LoadedReference<T, OK, N> : never : OK extends Array<infer OU> ? OU extends Entity ? T[K] extends Collection<T, infer U> ? LoadedCollection<T, OU> : never : never : T[K] : never;
|
|
99
|
-
/**
|
|
100
|
-
* Marks all references/collections of `T` as loaded, i.e. for newly instantiated entities where
|
|
101
|
-
* we know there are no already-existing rows with fk's to this new entity in the database.
|
|
100
|
+
* That said, lifecycle code like hooks actually can make setter calls b/c `flush`
|
|
101
|
+
* invokes them at a specific point in its process.
|
|
102
102
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* We solve this by using node's `AsyncLocalStorage` to mark certain callbacks (promise
|
|
104
|
+
* handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,
|
|
105
|
+
* but any external callers (i.e. application code) will be rejected.
|
|
105
106
|
*/
|
|
106
|
-
export declare type New<T extends Entity, O extends OptsOf<T> = OptsOf<T>> = T & {
|
|
107
|
-
[K in keyof T]: K extends keyof O ? MaybeUseOptsType<T, O, K> : MarkLoaded<T, T[K]>;
|
|
108
|
-
};
|
|
109
|
-
/** Given an entity `T` that is being populated with hints `H`, marks the `H` attributes as populated. */
|
|
110
|
-
export declare type Loaded<T extends Entity, H extends LoadHint<T>> = T & {
|
|
111
|
-
[K in keyof T]: H extends NestedLoadHint<T> ? LoadedIfInNestedHint<T, K, H> : H extends ReadonlyArray<infer U> ? LoadedIfInKeyHint<T, K, U> : LoadedIfInKeyHint<T, K, H>;
|
|
112
|
-
};
|
|
113
|
-
declare type LoadedIfInNestedHint<T extends Entity, K extends keyof T, H> = K extends keyof H ? MarkLoaded<T, T[K], H[K]> : unknown;
|
|
114
|
-
declare type LoadedIfInKeyHint<T extends Entity, K extends keyof T, H> = K extends H ? MarkLoaded<T, T[K]> : unknown;
|
|
115
|
-
/** From any non-`Relations` field in `T`, i.e. for loader hints. */
|
|
116
|
-
export declare type RelationsIn<T extends Entity> = SubType<T, Relation<any, any>>;
|
|
117
|
-
declare type SubType<T, C> = Pick<T, {
|
|
118
|
-
[K in keyof T]: T[K] extends C ? K : never;
|
|
119
|
-
}[keyof T]>;
|
|
120
|
-
export declare type LoadHint<T extends Entity> = keyof RelationsIn<T> | ReadonlyArray<keyof RelationsIn<T>> | NestedLoadHint<T>;
|
|
121
|
-
declare type NestedLoadHint<T extends Entity> = {
|
|
122
|
-
[K in keyof RelationsIn<T>]?: T[K] extends Relation<T, infer U> ? LoadHint<U> : never;
|
|
123
|
-
};
|
|
124
|
-
export declare type LoaderCache = Record<string, DataLoader<any, any>>;
|
|
125
|
-
declare type MaybePromise<T> = T | PromiseLike<T>;
|
|
126
|
-
export declare type EntityManagerHook = "beforeTransaction";
|
|
127
|
-
declare type HookFn = (em: EntityManager, knex: Knex.Transaction) => MaybePromise<any>;
|
|
128
|
-
export declare type HasKnex = {
|
|
129
|
-
knex: Knex;
|
|
130
|
-
};
|
|
131
107
|
export declare const currentFlushSecret: AsyncLocalStorage<{
|
|
132
108
|
flushSecret: number;
|
|
133
109
|
}>;
|
|
134
|
-
export declare
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
110
|
+
export declare type LoaderCache = Record<string, DataLoader<any, any>>;
|
|
111
|
+
export interface FlushOptions {
|
|
112
|
+
/** Skip all validations, including reactive validations, when flushing */
|
|
113
|
+
skipValidation?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export declare class EntityManager<C = {}> {
|
|
116
|
+
readonly ctx: C;
|
|
117
|
+
driver: Driver;
|
|
118
|
+
currentTxnKnex: Knex | undefined;
|
|
139
119
|
private _entities;
|
|
140
120
|
private _entityIndex;
|
|
141
|
-
private findLoaders;
|
|
142
121
|
private flushSecret;
|
|
143
122
|
private _isFlushing;
|
|
123
|
+
loadLoaders: LoaderCache;
|
|
124
|
+
findLoaders: LoaderCache;
|
|
144
125
|
__data: {
|
|
145
|
-
loaders: Record<string, DataLoader<any, any, any>>;
|
|
146
126
|
joinRows: Record<string, JoinRow[]>;
|
|
147
127
|
};
|
|
148
128
|
private hooks;
|
|
129
|
+
constructor(em: EntityManager<C>);
|
|
130
|
+
constructor(ctx: C, driver: Driver);
|
|
131
|
+
/** Returns a read-only shallow copy of the currently-loaded entities. */
|
|
149
132
|
get entities(): ReadonlyArray<Entity>;
|
|
133
|
+
/** Looks up `id` in the list of already-loaded entities. */
|
|
134
|
+
getEntity<T extends Entity>(id: IdOf<T>): T | undefined;
|
|
150
135
|
find<T extends Entity>(type: EntityConstructor<T>, where: FilterOf<T>): Promise<T[]>;
|
|
151
|
-
find<T extends Entity, H extends LoadHint<T
|
|
152
|
-
|
|
153
|
-
} | N | N[]), N extends Narrowable>(type: EntityConstructor<T>, where: FilterOf<T>, options?: {
|
|
154
|
-
populate?: H;
|
|
136
|
+
find<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, where: FilterOf<T>, options?: {
|
|
137
|
+
populate?: Const<H>;
|
|
155
138
|
orderBy?: OrderOf<T>;
|
|
156
139
|
limit?: number;
|
|
157
140
|
offset?: number;
|
|
@@ -162,26 +145,20 @@ export declare class EntityManager<C extends HasKnex = HasKnex> {
|
|
|
162
145
|
* I.e. filtering by `null` on fields that are non-`nullable`.
|
|
163
146
|
*/
|
|
164
147
|
findGql<T extends Entity>(type: EntityConstructor<T>, where: GraphQLFilterOf<T>): Promise<T[]>;
|
|
165
|
-
findGql<T extends Entity, H extends LoadHint<T
|
|
166
|
-
|
|
167
|
-
} | N | N[]), N extends Narrowable>(type: EntityConstructor<T>, where: GraphQLFilterOf<T>, options?: {
|
|
168
|
-
populate?: H;
|
|
148
|
+
findGql<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, where: GraphQLFilterOf<T>, options?: {
|
|
149
|
+
populate?: Const<H>;
|
|
169
150
|
orderBy?: OrderOf<T>;
|
|
170
151
|
limit?: number;
|
|
171
152
|
offset?: number;
|
|
172
153
|
}): Promise<Loaded<T, H>[]>;
|
|
173
154
|
findOne<T extends Entity>(type: EntityConstructor<T>, where: FilterOf<T>): Promise<T | undefined>;
|
|
174
|
-
findOne<T extends Entity, H extends LoadHint<T
|
|
175
|
-
|
|
176
|
-
} | N | N[]), N extends Narrowable>(type: EntityConstructor<T>, where: FilterOf<T>, options?: {
|
|
177
|
-
populate: H;
|
|
155
|
+
findOne<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, where: FilterOf<T>, options?: {
|
|
156
|
+
populate: Const<H>;
|
|
178
157
|
}): Promise<Loaded<T, H> | undefined>;
|
|
179
158
|
/** Executes a given query filter and returns exactly one result, otherwise throws `NotFoundError` or `TooManyError`. */
|
|
180
159
|
findOneOrFail<T extends Entity>(type: EntityConstructor<T>, where: FilterOf<T>): Promise<T>;
|
|
181
|
-
findOneOrFail<T extends Entity, H extends LoadHint<T
|
|
182
|
-
|
|
183
|
-
} | N | N[]), N extends Narrowable>(type: EntityConstructor<T>, where: FilterOf<T>, options: {
|
|
184
|
-
populate: H;
|
|
160
|
+
findOneOrFail<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, where: FilterOf<T>, options: {
|
|
161
|
+
populate: Const<H>;
|
|
185
162
|
}): Promise<Loaded<T, H>>;
|
|
186
163
|
/**
|
|
187
164
|
* Conditionally finds or creates an Entity.
|
|
@@ -196,36 +173,53 @@ export declare class EntityManager<C extends HasKnex = HasKnex> {
|
|
|
196
173
|
* @param upsert the fields to update if the entity is either existing or new
|
|
197
174
|
*/
|
|
198
175
|
findOrCreate<T extends Entity, F extends Partial<OptsOf<T>>, U extends Partial<OptsOf<T>> | {}, O extends Omit<OptsOf<T>, keyof F | keyof U>>(type: EntityConstructor<T>, where: F, ifNew: O, upsert?: U): Promise<T>;
|
|
199
|
-
findOrCreate<T extends Entity, F extends Partial<OptsOf<T>>, U extends Partial<OptsOf<T>> | {}, O extends Omit<OptsOf<T>, keyof F | keyof U>, H extends LoadHint<T>
|
|
200
|
-
[k: string]: N | H | [];
|
|
201
|
-
} | N | N[]), N extends Narrowable>(type: EntityConstructor<T>, where: F, ifNew: O, upsert?: U, populate?: H): Promise<Loaded<T, H>>;
|
|
176
|
+
findOrCreate<T extends Entity, F extends Partial<OptsOf<T>>, U extends Partial<OptsOf<T>> | {}, O extends Omit<OptsOf<T>, keyof F | keyof U>, H extends LoadHint<T>>(type: EntityConstructor<T>, where: F, ifNew: O, upsert?: U, populate?: Const<H>): Promise<Loaded<T, H>>;
|
|
202
177
|
/** Creates a new `type` and marks it as loaded, i.e. we know its collections are all safe to access in memory. */
|
|
203
178
|
create<T extends Entity, O extends OptsOf<T>>(type: EntityConstructor<T>, opts: O): New<T, O>;
|
|
204
179
|
/** Creates a new `type` but with `opts` that are nullable, to accept partial-update-style input. */
|
|
205
180
|
createPartial<T extends Entity>(type: EntityConstructor<T>, opts: PartialOrNull<OptsOf<T>>): T;
|
|
206
181
|
/** Creates a new `type` but with `opts` that are nullable, to accept partial-update-style input. */
|
|
207
182
|
createOrUpdatePartial<T extends Entity>(type: EntityConstructor<T>, opts: DeepPartialOrNull<T>): Promise<T>;
|
|
183
|
+
/**
|
|
184
|
+
* Utility to clone an entity and its nested relations, as determined by a populate hint
|
|
185
|
+
*
|
|
186
|
+
* @param entity - Any entity
|
|
187
|
+
* @param hint - A populate hint
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* // This will duplicate the author
|
|
191
|
+
* const duplicatedAuthor = await em.clone(author)
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* // This will duplicate the author and all their related book entities
|
|
195
|
+
* const duplicatedAuthorAndBooks = await em.clone(author, "books")
|
|
196
|
+
*
|
|
197
|
+
* @exmaple
|
|
198
|
+
* // This will duplicate the author, all their books, and the images for those books
|
|
199
|
+
* const duplicatedAuthorAndBooksAndImages = await em.clone(author, {books: "image"})
|
|
200
|
+
*/
|
|
201
|
+
clone<T extends Entity, H extends LoadHint<T>>(entity: T, hint?: H): Promise<Loaded<T, H>>;
|
|
208
202
|
/** Returns an instance of `type` for the given `id`, resolving to an existing instance if in our Unit of Work. */
|
|
203
|
+
load<T>(id: IdOf<T>): Promise<T>;
|
|
204
|
+
load(id: string): Promise<Entity>;
|
|
209
205
|
load<T extends Entity>(type: EntityConstructor<T>, id: string): Promise<T>;
|
|
210
|
-
load<T extends Entity, H extends LoadHint<T>
|
|
211
|
-
|
|
212
|
-
}, N extends Narrowable>(type: EntityConstructor<T>, id: string, populate: H): Promise<Loaded<T, H>>;
|
|
213
|
-
load<T extends Entity, H extends LoadHint<T> & (N | N[]), N extends Narrowable>(type: EntityConstructor<T>, id: string, populate: H): Promise<Loaded<T, H>>;
|
|
206
|
+
load<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, id: string, populate: Const<H>): Promise<Loaded<T, H>>;
|
|
207
|
+
load<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, id: string, populate: Const<H>): Promise<Loaded<T, H>>;
|
|
214
208
|
/** Returns instances of `type` for the given `ids`, resolving to an existing instance if in our Unit of Work. */
|
|
215
209
|
loadAll<T extends Entity>(type: EntityConstructor<T>, ids: string[]): Promise<T[]>;
|
|
216
|
-
loadAll<T extends Entity, H extends LoadHint<T>
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
loadAll<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, ids: string[], populate: Const<H>): Promise<Loaded<T, H>[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Returns instances of `type` for the given `ids`, resolving to an existing instance if in our Unit of Work. Ignores
|
|
213
|
+
* IDs that are not found.
|
|
214
|
+
*/
|
|
215
|
+
loadAllIfExists<T extends Entity>(type: EntityConstructor<T>, ids: string[]): Promise<T[]>;
|
|
216
|
+
loadAllIfExists<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, ids: string[], populate: Const<H>): Promise<Loaded<T, H>[]>;
|
|
219
217
|
/** Loads entities from a knex QueryBuilder. */
|
|
220
|
-
loadFromQuery<T extends Entity>(type: EntityConstructor<T>, query: QueryBuilder): Promise<T[]>;
|
|
221
|
-
loadFromQuery<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, query: QueryBuilder, populate: H): Promise<Loaded<T, H>[]>;
|
|
218
|
+
loadFromQuery<T extends Entity>(type: EntityConstructor<T>, query: Knex.QueryBuilder): Promise<T[]>;
|
|
219
|
+
loadFromQuery<T extends Entity, H extends LoadHint<T>>(type: EntityConstructor<T>, query: Knex.QueryBuilder, populate: H): Promise<Loaded<T, H>[]>;
|
|
222
220
|
/** Given a hint `H` (a field, array of fields, or nested hash), pre-load that data into `entity` for sync access. */
|
|
223
|
-
populate<T extends Entity, H extends LoadHint<T>
|
|
224
|
-
|
|
225
|
-
} | N | N[]), N extends Narrowable>(entity: T, hint: H): Promise<Loaded<T, H>>;
|
|
226
|
-
populate<T extends Entity, H extends LoadHint<T> & ({
|
|
227
|
-
[k: string]: N | H | [];
|
|
228
|
-
} | N | N[]), N extends Narrowable>(entities: ReadonlyArray<T>, hint: H): Promise<Loaded<T, H>[]>;
|
|
221
|
+
populate<T extends Entity, H extends LoadHint<T>>(entity: T, hint: Const<H>): Promise<Loaded<T, H>>;
|
|
222
|
+
populate<T extends Entity, H extends LoadHint<T>>(entities: ReadonlyArray<T>, hint: Const<H>): Promise<Loaded<T, H>[]>;
|
|
229
223
|
/**
|
|
230
224
|
* Executes `fn` with a transaction, and automatically calls `flush`/`commit` at the end.
|
|
231
225
|
*
|
|
@@ -258,8 +252,10 @@ export declare class EntityManager<C extends HasKnex = HasKnex> {
|
|
|
258
252
|
* If this is run within an existing transaction, i.e. `EntityManager.transaction`,
|
|
259
253
|
* then it will only issue `INSERT`s/etc. and defer to the caller to `COMMIT`
|
|
260
254
|
* the transaction.
|
|
255
|
+
*
|
|
256
|
+
* It returns entities that have changed (an entity is considered changed if it has been deleted, inserted, or updated)
|
|
261
257
|
*/
|
|
262
|
-
flush(): Promise<
|
|
258
|
+
flush(flushOptions?: FlushOptions): Promise<Entity[]>;
|
|
263
259
|
get isFlushing(): boolean;
|
|
264
260
|
/**
|
|
265
261
|
* A very simple toJSON.
|
|
@@ -284,9 +280,7 @@ export declare class EntityManager<C extends HasKnex = HasKnex> {
|
|
|
284
280
|
refresh(entity: Entity): Promise<void>;
|
|
285
281
|
refresh(entities: ReadonlyArray<Entity>): Promise<void>;
|
|
286
282
|
get numberOfEntities(): number;
|
|
287
|
-
|
|
288
|
-
private loaderForEntity;
|
|
289
|
-
private findExistingInstance;
|
|
283
|
+
findExistingInstance<T>(id: string): T | undefined;
|
|
290
284
|
/**
|
|
291
285
|
* Takes a result `row` from a custom query and maps the db values into a new-or-existing domain object for that row.
|
|
292
286
|
*
|
|
@@ -299,7 +293,12 @@ export declare class EntityManager<C extends HasKnex = HasKnex> {
|
|
|
299
293
|
hydrate<T extends Entity>(type: EntityConstructor<T>, row: any, options?: {
|
|
300
294
|
overwriteExisting?: boolean;
|
|
301
295
|
}): T;
|
|
296
|
+
/**
|
|
297
|
+
* Mark an entity as needing to be flushed regardless of its state
|
|
298
|
+
*/
|
|
299
|
+
touch(entity: Entity): void;
|
|
302
300
|
beforeTransaction(fn: HookFn): void;
|
|
301
|
+
afterTransaction(fn: HookFn): void;
|
|
303
302
|
toString(): string;
|
|
304
303
|
}
|
|
305
304
|
export declare let entityLimit: number;
|
|
@@ -308,25 +307,21 @@ export declare function setDefaultEntityLimit(): void;
|
|
|
308
307
|
export interface EntityMetadata<T extends Entity> {
|
|
309
308
|
cstr: EntityConstructor<T>;
|
|
310
309
|
type: string;
|
|
310
|
+
idType: "int" | "uuid";
|
|
311
311
|
tableName: string;
|
|
312
312
|
tagName: string;
|
|
313
|
-
|
|
314
|
-
fields: Array<Field>;
|
|
313
|
+
fields: Record<string, Field>;
|
|
315
314
|
config: ConfigApi<T, any>;
|
|
316
315
|
factory: (em: EntityManager, opts?: any) => New<T>;
|
|
317
316
|
}
|
|
318
|
-
export declare type
|
|
319
|
-
|
|
320
|
-
columnName: string;
|
|
321
|
-
dbType: string;
|
|
322
|
-
serde: ColumnSerde;
|
|
323
|
-
};
|
|
324
|
-
export declare type Field = PrimaryKeyField | PrimitiveField | EnumField | OneToManyField | ManyToOneField | ManyToManyField | OneToOneField;
|
|
317
|
+
export declare type Field = PrimaryKeyField | PrimitiveField | EnumField | OneToManyField | LargeOneToManyField | ManyToOneField | ManyToManyField | OneToOneField | PolymorphicField;
|
|
318
|
+
export declare type SerdeField = PrimaryKeyField | PrimitiveField | EnumField | ManyToOneField | PolymorphicField;
|
|
325
319
|
export declare type PrimaryKeyField = {
|
|
326
320
|
kind: "primaryKey";
|
|
327
321
|
fieldName: string;
|
|
328
322
|
fieldIdName: undefined;
|
|
329
323
|
required: true;
|
|
324
|
+
serde: FieldSerde;
|
|
330
325
|
};
|
|
331
326
|
export declare type PrimitiveField = {
|
|
332
327
|
kind: "primitive";
|
|
@@ -336,6 +331,7 @@ export declare type PrimitiveField = {
|
|
|
336
331
|
derived: "orm" | "sync" | "async" | false;
|
|
337
332
|
protected: boolean;
|
|
338
333
|
type: string | Function;
|
|
334
|
+
serde: FieldSerde;
|
|
339
335
|
};
|
|
340
336
|
export declare type EnumField = {
|
|
341
337
|
kind: "enum";
|
|
@@ -345,6 +341,7 @@ export declare type EnumField = {
|
|
|
345
341
|
enumDetailType: {
|
|
346
342
|
getValues(): ReadonlyArray<unknown>;
|
|
347
343
|
};
|
|
344
|
+
serde: FieldSerde;
|
|
348
345
|
};
|
|
349
346
|
export declare type OneToManyField = {
|
|
350
347
|
kind: "o2m";
|
|
@@ -353,6 +350,16 @@ export declare type OneToManyField = {
|
|
|
353
350
|
required: boolean;
|
|
354
351
|
otherMetadata: () => EntityMetadata<any>;
|
|
355
352
|
otherFieldName: string;
|
|
353
|
+
serde: undefined;
|
|
354
|
+
};
|
|
355
|
+
export declare type LargeOneToManyField = {
|
|
356
|
+
kind: "lo2m";
|
|
357
|
+
fieldName: string;
|
|
358
|
+
fieldIdName: string;
|
|
359
|
+
required: boolean;
|
|
360
|
+
otherMetadata: () => EntityMetadata<any>;
|
|
361
|
+
otherFieldName: string;
|
|
362
|
+
serde: undefined;
|
|
356
363
|
};
|
|
357
364
|
export declare type ManyToOneField = {
|
|
358
365
|
kind: "m2o";
|
|
@@ -361,6 +368,7 @@ export declare type ManyToOneField = {
|
|
|
361
368
|
required: boolean;
|
|
362
369
|
otherMetadata: () => EntityMetadata<any>;
|
|
363
370
|
otherFieldName: string;
|
|
371
|
+
serde: FieldSerde;
|
|
364
372
|
};
|
|
365
373
|
export declare type ManyToManyField = {
|
|
366
374
|
kind: "m2m";
|
|
@@ -369,6 +377,7 @@ export declare type ManyToManyField = {
|
|
|
369
377
|
required: boolean;
|
|
370
378
|
otherMetadata: () => EntityMetadata<any>;
|
|
371
379
|
otherFieldName: string;
|
|
380
|
+
serde: undefined;
|
|
372
381
|
};
|
|
373
382
|
export declare type OneToOneField = {
|
|
374
383
|
kind: "o2o";
|
|
@@ -377,18 +386,38 @@ export declare type OneToOneField = {
|
|
|
377
386
|
required: boolean;
|
|
378
387
|
otherMetadata: () => EntityMetadata<any>;
|
|
379
388
|
otherFieldName: string;
|
|
389
|
+
serde: undefined;
|
|
390
|
+
};
|
|
391
|
+
export declare type PolymorphicField = {
|
|
392
|
+
kind: "poly";
|
|
393
|
+
fieldName: string;
|
|
394
|
+
fieldIdName: string;
|
|
395
|
+
required: boolean;
|
|
396
|
+
components: PolymorphicFieldComponent[];
|
|
397
|
+
serde: PolymorphicKeySerde;
|
|
398
|
+
};
|
|
399
|
+
export declare type PolymorphicFieldComponent = {
|
|
400
|
+
otherMetadata: () => EntityMetadata<any>;
|
|
401
|
+
otherFieldName: string;
|
|
402
|
+
columnName: string;
|
|
380
403
|
};
|
|
381
404
|
export declare function isEntity(maybeEntity: any): maybeEntity is Entity;
|
|
382
405
|
export declare function isKey(k: any): k is string;
|
|
383
406
|
/** Compares `a` to `b`, where `b` might be an id. B/c ids can overlap, we need to know `b`'s metadata type. */
|
|
384
|
-
export declare function sameEntity(a: Entity,
|
|
407
|
+
export declare function sameEntity(a: Entity | undefined, meta: EntityMetadata<any>, b: Entity | string | undefined): boolean;
|
|
385
408
|
export declare function getMetadata<T extends Entity>(entity: T): EntityMetadata<T>;
|
|
386
409
|
export declare function getMetadata<T extends Entity>(type: EntityConstructor<T>): EntityMetadata<T>;
|
|
410
|
+
export declare function getMetadata<T extends Entity>(meta: EntityMetadata<T>): EntityMetadata<T>;
|
|
387
411
|
/** Thrown by `findOneOrFail` if an entity is not found. */
|
|
388
412
|
export declare class NotFoundError extends Error {
|
|
389
413
|
}
|
|
390
414
|
/** Thrown by `findOne` and `findOneOrFail` if more than one entity is found. */
|
|
391
415
|
export declare class TooManyError extends Error {
|
|
392
416
|
}
|
|
393
|
-
declare
|
|
417
|
+
export declare function beforeTransaction(em: EntityManager, knex: Knex.Transaction): Promise<unknown>;
|
|
418
|
+
export declare function afterTransaction(em: EntityManager, knex: Knex.Transaction): Promise<unknown>;
|
|
419
|
+
declare type Narrowable = string | number | boolean | symbol | object | undefined | void | null | {} | [];
|
|
420
|
+
declare type Const<N> = N | {
|
|
421
|
+
[K in keyof N]: N[K] extends Narrowable ? N[K] | Const<N[K]> : never;
|
|
422
|
+
};
|
|
394
423
|
export {};
|