@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha100
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/action/action.d.ts +38 -30
- package/action/action.js +22 -7
- package/action/executor.d.ts +4 -4
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +48 -16
- package/action/orchestrator.js +343 -81
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +54 -27
- package/core/base.js +23 -1
- package/core/clause.d.ts +105 -3
- package/core/clause.js +563 -30
- package/core/config.d.ts +30 -1
- package/core/config.js +24 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +14 -11
- package/core/db.js +22 -8
- package/core/ent.d.ts +82 -28
- package/core/ent.js +692 -202
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +13 -15
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +13 -7
- package/core/loaders/object_loader.js +95 -32
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +17 -9
- package/graphql/graphql.js +47 -30
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -4
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +3 -3
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +23 -1
- package/index.js +32 -6
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +45 -8
- package/parse_schema/parse.js +193 -15
- package/schema/base_schema.d.ts +38 -1
- package/schema/base_schema.js +53 -2
- package/schema/field.d.ts +75 -21
- package/schema/field.js +185 -72
- package/schema/index.d.ts +4 -2
- package/schema/index.js +15 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +125 -10
- package/schema/schema.js +133 -5
- package/schema/struct_field.d.ts +27 -0
- package/schema/struct_field.js +138 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +224 -36
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.d.ts +1 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +35 -6
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +52 -49
- package/testutils/builder.js +143 -44
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +26 -9
- package/testutils/db/{test_db.js → temp_db.js} +190 -46
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +9 -1
- package/testutils/ent-graphql-tests/index.js +53 -25
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +10 -10
- package/testutils/fake_data/fake_contact.js +23 -21
- package/testutils/fake_data/fake_event.d.ts +8 -9
- package/testutils/fake_data/fake_event.js +25 -28
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +10 -11
- package/testutils/fake_data/fake_user.js +20 -23
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +29 -13
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +277 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +45 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +383 -0
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_schema.js +0 -288
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ID, Context, Loader, LoaderFactory } from "../base";
|
|
2
2
|
export declare class AssocEdgeCountLoader implements Loader<ID, number> {
|
|
3
3
|
private edgeType;
|
|
4
|
-
context?: Context | undefined;
|
|
4
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
5
5
|
private loaderFn;
|
|
6
6
|
private loader;
|
|
7
|
-
constructor(edgeType: string, context?: Context | undefined);
|
|
7
|
+
constructor(edgeType: string, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
8
8
|
private getLoader;
|
|
9
9
|
load(id: ID): Promise<number>;
|
|
10
10
|
clearAll(): void;
|
|
@@ -13,5 +13,6 @@ export declare class AssocEdgeCountLoaderFactory implements LoaderFactory<ID, nu
|
|
|
13
13
|
private edgeType;
|
|
14
14
|
name: string;
|
|
15
15
|
constructor(edgeType: string);
|
|
16
|
+
getEdgeType(): string;
|
|
16
17
|
createLoader(context?: Context): AssocEdgeCountLoader;
|
|
17
18
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -41,10 +45,11 @@ class AssocEdgeCountLoader {
|
|
|
41
45
|
if (!edgeData) {
|
|
42
46
|
throw new Error(`error loading edge data for ${this.edgeType}`);
|
|
43
47
|
}
|
|
48
|
+
const { cls } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", this.edgeType), {});
|
|
44
49
|
this.loader = (0, raw_count_loader_1.createCountDataLoader)({
|
|
45
50
|
tableName: edgeData.edgeTable,
|
|
46
51
|
groupCol: "id1",
|
|
47
|
-
clause:
|
|
52
|
+
clause: cls,
|
|
48
53
|
});
|
|
49
54
|
return this.loader;
|
|
50
55
|
}
|
|
@@ -68,6 +73,9 @@ class AssocEdgeCountLoaderFactory {
|
|
|
68
73
|
this.edgeType = edgeType;
|
|
69
74
|
this.name = `assocEdgeLoader:count:${edgeType}`;
|
|
70
75
|
}
|
|
76
|
+
getEdgeType() {
|
|
77
|
+
return this.edgeType;
|
|
78
|
+
}
|
|
71
79
|
createLoader(context) {
|
|
72
80
|
return (0, loader_1.getLoader)(this, () => new AssocEdgeCountLoader(this.edgeType, context), context);
|
|
73
81
|
}
|
|
@@ -20,8 +20,8 @@ export declare class AssocDirectEdgeLoader<T extends AssocEdge> implements Loade
|
|
|
20
20
|
private edgeType;
|
|
21
21
|
private edgeCtr;
|
|
22
22
|
private options?;
|
|
23
|
-
context?: Context | undefined;
|
|
24
|
-
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T>, options?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined, context?: Context | undefined);
|
|
23
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
24
|
+
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T>, options?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
25
25
|
load(id: ID): Promise<T[]>;
|
|
26
26
|
loadEdgeForID2(id: ID, id2: ID): Promise<T | undefined>;
|
|
27
27
|
clearAll(): void;
|
|
@@ -32,7 +32,7 @@ export declare class AssocEdgeLoaderFactory<T extends AssocEdge> implements Load
|
|
|
32
32
|
name: string;
|
|
33
33
|
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T> | (() => AssocEdgeConstructor<T>));
|
|
34
34
|
createLoader(context?: Context): AssocLoader<T>;
|
|
35
|
-
private
|
|
35
|
+
private isConstructor;
|
|
36
36
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): AssocLoader<T>;
|
|
37
37
|
}
|
|
38
38
|
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -59,22 +63,15 @@ function createLoader(options, edgeType, edgeCtr, edgeData) {
|
|
|
59
63
|
// TODO defaultEdgeQueryOptions
|
|
60
64
|
options.limit = options.limit || ent_1.DefaultLimit;
|
|
61
65
|
const tableName = edgeData.edgeTable;
|
|
66
|
+
const { cls: cls1, fields } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", edgeType), {});
|
|
62
67
|
const [query, cls] = (0, ent_1.buildGroupQuery)({
|
|
63
68
|
tableName: tableName,
|
|
64
|
-
fields
|
|
65
|
-
"id1",
|
|
66
|
-
"id2",
|
|
67
|
-
"edge_type",
|
|
68
|
-
"id1_type",
|
|
69
|
-
"id2_type",
|
|
70
|
-
"data",
|
|
71
|
-
"time",
|
|
72
|
-
],
|
|
69
|
+
fields,
|
|
73
70
|
values: keys,
|
|
74
71
|
orderby: options.orderby,
|
|
75
72
|
limit: options.limit || ent_1.DefaultLimit,
|
|
76
73
|
groupColumn: "id1",
|
|
77
|
-
clause:
|
|
74
|
+
clause: cls1,
|
|
78
75
|
});
|
|
79
76
|
const rows = await (0, ent_1.performRawQuery)(query, cls.values(), cls.logValues());
|
|
80
77
|
for (const row of rows) {
|
|
@@ -161,16 +158,17 @@ class AssocEdgeLoaderFactory {
|
|
|
161
158
|
createLoader(context) {
|
|
162
159
|
return this.createConfigurableLoader({}, context);
|
|
163
160
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
isConstructor(edgeCtr) {
|
|
162
|
+
return (edgeCtr.prototype &&
|
|
163
|
+
edgeCtr.prototype.constructor &&
|
|
164
|
+
edgeCtr.prototype.constructor.name.length > 0);
|
|
167
165
|
}
|
|
168
166
|
createConfigurableLoader(options, context) {
|
|
169
167
|
let edgeCtr = this.edgeCtr;
|
|
170
168
|
// in generated code, the edge is not necessarily defined at the time of loading
|
|
171
169
|
// so we call this as follows:
|
|
172
170
|
// const loader = new AssocEdgeLoaderFactory(EdgeType.Foo, ()=>DerivedEdgeClass);
|
|
173
|
-
if (this.
|
|
171
|
+
if (!this.isConstructor(edgeCtr)) {
|
|
174
172
|
edgeCtr = edgeCtr();
|
|
175
173
|
}
|
|
176
174
|
// rename to make TS happy
|
package/core/loaders/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { RawCountLoader, RawCountLoaderFactory } from "./raw_count_loader";
|
|
|
3
3
|
export { AssocEdgeCountLoader, AssocEdgeCountLoaderFactory, } from "./assoc_count_loader";
|
|
4
4
|
export { AssocDirectEdgeLoader, AssocEdgeLoader, AssocEdgeLoaderFactory, } from "./assoc_edge_loader";
|
|
5
5
|
export { IndexLoaderFactory } from "./index_loader";
|
|
6
|
-
export {
|
|
6
|
+
export { QueryLoaderFactory } from "./query_loader";
|
package/core/loaders/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryLoaderFactory = exports.
|
|
3
|
+
exports.QueryLoaderFactory = exports.IndexLoaderFactory = exports.AssocEdgeLoaderFactory = exports.AssocEdgeLoader = exports.AssocDirectEdgeLoader = exports.AssocEdgeCountLoaderFactory = exports.AssocEdgeCountLoader = exports.RawCountLoaderFactory = exports.RawCountLoader = exports.ObjectLoaderFactory = exports.ObjectLoader = void 0;
|
|
4
4
|
var object_loader_1 = require("./object_loader");
|
|
5
5
|
Object.defineProperty(exports, "ObjectLoader", { enumerable: true, get: function () { return object_loader_1.ObjectLoader; } });
|
|
6
6
|
Object.defineProperty(exports, "ObjectLoaderFactory", { enumerable: true, get: function () { return object_loader_1.ObjectLoaderFactory; } });
|
|
@@ -17,6 +17,4 @@ Object.defineProperty(exports, "AssocEdgeLoaderFactory", { enumerable: true, get
|
|
|
17
17
|
var index_loader_1 = require("./index_loader");
|
|
18
18
|
Object.defineProperty(exports, "IndexLoaderFactory", { enumerable: true, get: function () { return index_loader_1.IndexLoaderFactory; } });
|
|
19
19
|
var query_loader_1 = require("./query_loader");
|
|
20
|
-
Object.defineProperty(exports, "QueryLoader", { enumerable: true, get: function () { return query_loader_1.QueryLoader; } });
|
|
21
|
-
Object.defineProperty(exports, "QueryDirectLoader", { enumerable: true, get: function () { return query_loader_1.QueryDirectLoader; } });
|
|
22
20
|
Object.defineProperty(exports, "QueryLoaderFactory", { enumerable: true, get: function () { return query_loader_1.QueryLoaderFactory; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ID, SelectBaseDataOptions, Context, Data, LoaderFactory, EdgeQueryableDataOptions } from "../base";
|
|
1
|
+
import { ID, SelectBaseDataOptions, Context, Data, LoaderFactory, EdgeQueryableDataOptions, Loader } from "../base";
|
|
2
2
|
import * as clause from "../clause";
|
|
3
3
|
import { ObjectLoaderFactory } from "./object_loader";
|
|
4
4
|
export declare class IndexLoaderFactory implements LoaderFactory<ID, Data[]> {
|
|
@@ -10,5 +10,5 @@ export declare class IndexLoaderFactory implements LoaderFactory<ID, Data[]> {
|
|
|
10
10
|
toPrime?: ObjectLoaderFactory<ID>[];
|
|
11
11
|
});
|
|
12
12
|
createLoader(context?: Context): any;
|
|
13
|
-
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context):
|
|
13
|
+
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<ID, Data[]>;
|
|
14
14
|
}
|
|
@@ -4,6 +4,7 @@ exports.IndexLoaderFactory = void 0;
|
|
|
4
4
|
const query_loader_1 = require("./query_loader");
|
|
5
5
|
// we're keeping this for legacy reasons so as to not break existing callers
|
|
6
6
|
// and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
|
|
7
|
+
// @deprecated use QueryLoaderFactory
|
|
7
8
|
class IndexLoaderFactory {
|
|
8
9
|
constructor(options, col, opts) {
|
|
9
10
|
this.factory = new query_loader_1.QueryLoaderFactory({
|
package/core/loaders/loader.js
CHANGED
|
@@ -37,12 +37,12 @@ class cacheMap {
|
|
|
37
37
|
// might be a lot?
|
|
38
38
|
// TODO this is not the best log format
|
|
39
39
|
// was designed for ObjectLoader time. Now we have different needs e.g. count, assoc etc
|
|
40
|
-
(0, logger_1.log)("
|
|
40
|
+
(0, logger_1.log)("cache", {
|
|
41
41
|
"dataloader-cache-hit": key,
|
|
42
42
|
"tableName": this.options.tableName,
|
|
43
43
|
});
|
|
44
44
|
// } else {
|
|
45
|
-
// log("
|
|
45
|
+
// log("cache", {
|
|
46
46
|
// "dataloader-cache-miss": key,
|
|
47
47
|
// "tableName": options.tableName,
|
|
48
48
|
// });
|
|
@@ -50,21 +50,21 @@ class cacheMap {
|
|
|
50
50
|
return ret;
|
|
51
51
|
}
|
|
52
52
|
set(key, value) {
|
|
53
|
-
// log("
|
|
53
|
+
// log("cache", {
|
|
54
54
|
// "dataloader-cache-set": key,
|
|
55
55
|
// "tableName": options.tableName,
|
|
56
56
|
// });
|
|
57
57
|
return this.m.set(key, value);
|
|
58
58
|
}
|
|
59
59
|
delete(key) {
|
|
60
|
-
// log("
|
|
60
|
+
// log("cache", {
|
|
61
61
|
// "dataloader-cache-delete": key,
|
|
62
62
|
// "tableName": options.tableName,
|
|
63
63
|
// });
|
|
64
64
|
return this.m.delete(key);
|
|
65
65
|
}
|
|
66
66
|
clear() {
|
|
67
|
-
// log("
|
|
67
|
+
// log("cache", {
|
|
68
68
|
// "dataloader-cache-clear": true,
|
|
69
69
|
// "tableName": options.tableName,
|
|
70
70
|
// });
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import { Data, SelectDataOptions, Context, Loader, LoaderFactory } from "../base";
|
|
1
|
+
import { ID, Data, SelectDataOptions, Context, Loader, LoaderFactory } from "../base";
|
|
2
2
|
export declare class ObjectLoader<T> implements Loader<T, Data | null> {
|
|
3
3
|
private options;
|
|
4
|
-
context?: Context | undefined;
|
|
4
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
5
5
|
private toPrime?;
|
|
6
6
|
private loader;
|
|
7
7
|
private primedLoaders;
|
|
8
8
|
private memoizedInitPrime;
|
|
9
|
-
constructor(options: SelectDataOptions, context?: Context | undefined, toPrime?: ObjectLoaderFactory<T>[] | undefined);
|
|
9
|
+
constructor(options: SelectDataOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined, toPrime?: ObjectLoaderFactory<T>[] | undefined);
|
|
10
|
+
getOptions(): SelectDataOptions;
|
|
10
11
|
private initPrime;
|
|
11
12
|
load(key: T): Promise<Data | null>;
|
|
12
13
|
clearAll(): void;
|
|
13
|
-
loadMany(keys: T[]): Promise<Data
|
|
14
|
+
loadMany(keys: T[]): Promise<Array<Data | null>>;
|
|
14
15
|
prime(data: Data): void;
|
|
16
|
+
primeAll(data: Data): void;
|
|
17
|
+
}
|
|
18
|
+
interface ObjectLoaderOptions extends SelectDataOptions {
|
|
19
|
+
instanceKey?: string;
|
|
15
20
|
}
|
|
16
21
|
export declare class ObjectLoaderFactory<T> implements LoaderFactory<T, Data | null> {
|
|
17
|
-
options:
|
|
22
|
+
options: ObjectLoaderOptions;
|
|
18
23
|
name: string;
|
|
19
24
|
private toPrime;
|
|
20
|
-
constructor(options:
|
|
25
|
+
constructor(options: ObjectLoaderOptions);
|
|
21
26
|
createLoader(context?: Context): ObjectLoader<T>;
|
|
22
|
-
addToPrime(factory: ObjectLoaderFactory<T>):
|
|
27
|
+
addToPrime(factory: ObjectLoaderFactory<T>): this;
|
|
23
28
|
}
|
|
29
|
+
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -29,6 +33,50 @@ const clause = __importStar(require("../clause"));
|
|
|
29
33
|
const logger_1 = require("../logger");
|
|
30
34
|
const loader_1 = require("./loader");
|
|
31
35
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
36
|
+
async function loadRowsForLoader(options, ids, context) {
|
|
37
|
+
let col = options.key;
|
|
38
|
+
let cls = clause.In(col, ...ids);
|
|
39
|
+
if (options.clause) {
|
|
40
|
+
let optionClause;
|
|
41
|
+
if (typeof options.clause === "function") {
|
|
42
|
+
optionClause = options.clause();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
optionClause = options.clause;
|
|
46
|
+
}
|
|
47
|
+
if (optionClause) {
|
|
48
|
+
cls = clause.And(cls, optionClause);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const rowOptions = {
|
|
52
|
+
...options,
|
|
53
|
+
clause: cls,
|
|
54
|
+
context,
|
|
55
|
+
};
|
|
56
|
+
let m = new Map();
|
|
57
|
+
let result = [];
|
|
58
|
+
for (let i = 0; i < ids.length; i++) {
|
|
59
|
+
result.push(null);
|
|
60
|
+
// store the index....
|
|
61
|
+
m.set(ids[i], i);
|
|
62
|
+
}
|
|
63
|
+
const rows = await (0, ent_1.loadRows)(rowOptions);
|
|
64
|
+
for (const row of rows) {
|
|
65
|
+
const id = row[col];
|
|
66
|
+
if (id === undefined) {
|
|
67
|
+
throw new Error(`need to query for column ${col} when using an object loader because the query may not be sorted and we need the id to maintain sort order`);
|
|
68
|
+
}
|
|
69
|
+
const idx = m.get(id);
|
|
70
|
+
if (idx === undefined) {
|
|
71
|
+
throw new Error(`malformed query. got ${id} back but didn't query for it`);
|
|
72
|
+
}
|
|
73
|
+
result[idx] = row;
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
// optional clause...
|
|
78
|
+
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
79
|
+
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
32
80
|
function createDataLoader(options) {
|
|
33
81
|
const loaderOptions = {};
|
|
34
82
|
// if query logging is enabled, we should log what's happening with loader
|
|
@@ -39,29 +87,8 @@ function createDataLoader(options) {
|
|
|
39
87
|
if (!ids.length) {
|
|
40
88
|
return [];
|
|
41
89
|
}
|
|
42
|
-
let col = options.key;
|
|
43
|
-
const rowOptions = {
|
|
44
|
-
...options,
|
|
45
|
-
clause: clause.In(col, ...ids),
|
|
46
|
-
};
|
|
47
|
-
let m = new Map();
|
|
48
|
-
let result = [];
|
|
49
|
-
for (let i = 0; i < ids.length; i++) {
|
|
50
|
-
result.push(null);
|
|
51
|
-
// store the index....
|
|
52
|
-
m.set(ids[i], i);
|
|
53
|
-
}
|
|
54
90
|
// context not needed because we're creating a loader which has its own cache which is being used here
|
|
55
|
-
|
|
56
|
-
for (const row of rows) {
|
|
57
|
-
const id = row[col];
|
|
58
|
-
const idx = m.get(id);
|
|
59
|
-
if (idx === undefined) {
|
|
60
|
-
throw new Error(`malformed query. got ${id} back but didn't query for it`);
|
|
61
|
-
}
|
|
62
|
-
result[idx] = row;
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
91
|
+
return loadRowsForLoader(options, ids);
|
|
65
92
|
}, loaderOptions);
|
|
66
93
|
}
|
|
67
94
|
class ObjectLoader {
|
|
@@ -77,6 +104,9 @@ class ObjectLoader {
|
|
|
77
104
|
}
|
|
78
105
|
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
79
106
|
}
|
|
107
|
+
getOptions() {
|
|
108
|
+
return this.options;
|
|
109
|
+
}
|
|
80
110
|
initPrime() {
|
|
81
111
|
if (!this.context || !this.toPrime) {
|
|
82
112
|
return;
|
|
@@ -107,12 +137,25 @@ class ObjectLoader {
|
|
|
107
137
|
}
|
|
108
138
|
return result;
|
|
109
139
|
}
|
|
140
|
+
let cls = clause.Eq(this.options.key, key);
|
|
141
|
+
if (this.options.clause) {
|
|
142
|
+
let optionClause;
|
|
143
|
+
if (typeof this.options.clause === "function") {
|
|
144
|
+
optionClause = this.options.clause();
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
optionClause = this.options.clause;
|
|
148
|
+
}
|
|
149
|
+
if (optionClause) {
|
|
150
|
+
cls = clause.And(cls, optionClause);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
110
153
|
const rowOptions = {
|
|
111
154
|
...this.options,
|
|
112
|
-
clause:
|
|
155
|
+
clause: cls,
|
|
113
156
|
context: this.context,
|
|
114
157
|
};
|
|
115
|
-
return
|
|
158
|
+
return (0, ent_1.loadRow)(rowOptions);
|
|
116
159
|
}
|
|
117
160
|
clearAll() {
|
|
118
161
|
this.loader && this.loader.clearAll();
|
|
@@ -121,12 +164,7 @@ class ObjectLoader {
|
|
|
121
164
|
if (this.loader) {
|
|
122
165
|
return await this.loader.loadMany(keys);
|
|
123
166
|
}
|
|
124
|
-
|
|
125
|
-
...this.options,
|
|
126
|
-
clause: clause.In(this.options.key, ...keys),
|
|
127
|
-
context: this.context,
|
|
128
|
-
};
|
|
129
|
-
return await (0, ent_1.loadRows)(rowOptions);
|
|
167
|
+
return loadRowsForLoader(this.options, keys, this.context);
|
|
130
168
|
}
|
|
131
169
|
prime(data) {
|
|
132
170
|
// we have this data from somewhere else, prime it in the c
|
|
@@ -136,13 +174,37 @@ class ObjectLoader {
|
|
|
136
174
|
this.loader.prime(key, data);
|
|
137
175
|
}
|
|
138
176
|
}
|
|
177
|
+
// prime this loader and any other loaders it's aware of
|
|
178
|
+
primeAll(data) {
|
|
179
|
+
this.prime(data);
|
|
180
|
+
if (this.primedLoaders) {
|
|
181
|
+
for (const [key, loader] of this.primedLoaders) {
|
|
182
|
+
const value = data[key];
|
|
183
|
+
if (value !== undefined) {
|
|
184
|
+
loader.prime(data);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
139
189
|
}
|
|
140
190
|
exports.ObjectLoader = ObjectLoader;
|
|
191
|
+
// NOTE: if not querying for all columns
|
|
192
|
+
// have to query for the id field as one of the fields
|
|
193
|
+
// because it's used to maintain sort order of the queried ids
|
|
141
194
|
class ObjectLoaderFactory {
|
|
142
195
|
constructor(options) {
|
|
143
196
|
this.options = options;
|
|
144
197
|
this.toPrime = [];
|
|
145
|
-
|
|
198
|
+
let instanceKey = options.instanceKey || "";
|
|
199
|
+
if (typeof this.options.clause === "function") {
|
|
200
|
+
if (!options.instanceKey) {
|
|
201
|
+
throw new Error(`need to pass an instanceKey to ObjectLoader if clause is a function`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (this.options.clause) {
|
|
205
|
+
instanceKey = this.options.clause.instanceKey();
|
|
206
|
+
}
|
|
207
|
+
this.name = `${options.tableName}:${options.key}:${instanceKey}`;
|
|
146
208
|
}
|
|
147
209
|
createLoader(context) {
|
|
148
210
|
return (0, loader_1.getLoader)(this, () => {
|
|
@@ -153,6 +215,7 @@ class ObjectLoaderFactory {
|
|
|
153
215
|
// because there's usually self references here
|
|
154
216
|
addToPrime(factory) {
|
|
155
217
|
this.toPrime.push(factory);
|
|
218
|
+
return this;
|
|
156
219
|
}
|
|
157
220
|
}
|
|
158
221
|
exports.ObjectLoaderFactory = ObjectLoaderFactory;
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { Context, ID, EdgeQueryableDataOptions, Loader, LoaderFactory, Data } from "../base";
|
|
2
2
|
import * as clause from "../clause";
|
|
3
3
|
import { ObjectLoaderFactory } from "./object_loader";
|
|
4
|
-
export declare
|
|
4
|
+
export declare function getOrderBy(sortCol: string, orderby?: string): string;
|
|
5
|
+
declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
|
|
5
6
|
private options;
|
|
6
7
|
private queryOptions?;
|
|
7
|
-
|
|
8
|
-
load(id: K): Promise<Data[]>;
|
|
9
|
-
clearAll(): void;
|
|
10
|
-
}
|
|
11
|
-
export declare class QueryLoader<K extends any> implements Loader<K, Data[]> {
|
|
12
|
-
private options;
|
|
13
|
-
context?: Context | undefined;
|
|
14
|
-
private queryOptions?;
|
|
15
|
-
private loader;
|
|
16
|
-
private primedLoaders;
|
|
8
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
17
9
|
private memoizedInitPrime;
|
|
18
|
-
|
|
10
|
+
private primedLoaders;
|
|
11
|
+
constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
19
12
|
private initPrime;
|
|
20
13
|
load(id: K): Promise<Data[]>;
|
|
21
14
|
clearAll(): void;
|
|
@@ -34,5 +27,6 @@ export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<
|
|
|
34
27
|
constructor(options: QueryOptions);
|
|
35
28
|
createLoader(context?: Context): any;
|
|
36
29
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<unknown, Data[]> | QueryDirectLoader<unknown>;
|
|
30
|
+
static createConfigurableLoader(name: string, queryOptions: QueryOptions, options: EdgeQueryableDataOptions, context?: Context): Loader<unknown, Data[]> | QueryDirectLoader<unknown>;
|
|
37
31
|
}
|
|
38
32
|
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.QueryLoaderFactory = exports.
|
|
29
|
+
exports.QueryLoaderFactory = exports.getOrderBy = void 0;
|
|
26
30
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
27
31
|
const ent_1 = require("../ent");
|
|
28
32
|
const clause = __importStar(require("../clause"));
|
|
@@ -30,13 +34,17 @@ const logger_1 = require("../logger");
|
|
|
30
34
|
const loader_1 = require("./loader");
|
|
31
35
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
32
36
|
function getOrderBy(sortCol, orderby) {
|
|
37
|
+
if (orderby) {
|
|
38
|
+
return orderby;
|
|
39
|
+
}
|
|
33
40
|
let sortColLower = sortCol.toLowerCase();
|
|
34
41
|
let orderbyDirection = " DESC";
|
|
35
42
|
if (sortColLower.endsWith("asc") || sortCol.endsWith("desc")) {
|
|
36
43
|
orderbyDirection = "";
|
|
37
44
|
}
|
|
38
|
-
return
|
|
45
|
+
return `${sortCol}${orderbyDirection}`;
|
|
39
46
|
}
|
|
47
|
+
exports.getOrderBy = getOrderBy;
|
|
40
48
|
async function simpleCase(options, id, queryOptions) {
|
|
41
49
|
let cls;
|
|
42
50
|
if (options.groupCol) {
|
|
@@ -120,16 +128,47 @@ function createLoader(options, queryOptions) {
|
|
|
120
128
|
}, loaderOptions);
|
|
121
129
|
}
|
|
122
130
|
class QueryDirectLoader {
|
|
123
|
-
constructor(options, queryOptions) {
|
|
131
|
+
constructor(options, queryOptions, context) {
|
|
124
132
|
this.options = options;
|
|
125
133
|
this.queryOptions = queryOptions;
|
|
134
|
+
this.context = context;
|
|
135
|
+
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
136
|
+
}
|
|
137
|
+
initPrime() {
|
|
138
|
+
if (!this.context || !this.options?.toPrime) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let primedLoaders = new Map();
|
|
142
|
+
this.options.toPrime.forEach((prime) => {
|
|
143
|
+
const l2 = prime.createLoader(this.context);
|
|
144
|
+
if (l2.prime === undefined) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
primedLoaders.set(prime.options.key, l2);
|
|
148
|
+
});
|
|
149
|
+
this.primedLoaders = primedLoaders;
|
|
126
150
|
}
|
|
127
151
|
async load(id) {
|
|
128
|
-
|
|
152
|
+
const rows = await simpleCase(this.options, id, this.queryOptions);
|
|
153
|
+
if (this.context) {
|
|
154
|
+
this.memoizedInitPrime();
|
|
155
|
+
if (this.primedLoaders) {
|
|
156
|
+
for (const row of rows) {
|
|
157
|
+
for (const [key, loader] of this.primedLoaders) {
|
|
158
|
+
const value = row[key];
|
|
159
|
+
if (value !== undefined) {
|
|
160
|
+
loader.prime(row);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return rows;
|
|
129
167
|
}
|
|
130
168
|
clearAll() { }
|
|
131
169
|
}
|
|
132
|
-
|
|
170
|
+
// note, you should never call this directly
|
|
171
|
+
// there's scenarios where QueryDirectLoader is needed instead of this...
|
|
133
172
|
class QueryLoader {
|
|
134
173
|
constructor(options, context, queryOptions) {
|
|
135
174
|
this.options = options;
|
|
@@ -176,7 +215,6 @@ class QueryLoader {
|
|
|
176
215
|
this.loader && this.loader.clearAll();
|
|
177
216
|
}
|
|
178
217
|
}
|
|
179
|
-
exports.QueryLoader = QueryLoader;
|
|
180
218
|
class QueryLoaderFactory {
|
|
181
219
|
constructor(options) {
|
|
182
220
|
this.options = options;
|
|
@@ -194,11 +232,14 @@ class QueryLoaderFactory {
|
|
|
194
232
|
return (0, loader_1.getLoader)(this, () => new QueryLoader(this.options, context), context);
|
|
195
233
|
}
|
|
196
234
|
createConfigurableLoader(options, context) {
|
|
197
|
-
|
|
198
|
-
|
|
235
|
+
return QueryLoaderFactory.createConfigurableLoader(this.name, this.options, options, context);
|
|
236
|
+
}
|
|
237
|
+
static createConfigurableLoader(name, queryOptions, options, context) {
|
|
238
|
+
if (options.clause || !context) {
|
|
239
|
+
return new QueryDirectLoader(queryOptions, options, context);
|
|
199
240
|
}
|
|
200
|
-
const key = `${
|
|
201
|
-
return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(
|
|
241
|
+
const key = `${name}:limit:${options.limit}:orderby:${options.orderby}`;
|
|
242
|
+
return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(queryOptions, context, options), context);
|
|
202
243
|
}
|
|
203
244
|
}
|
|
204
245
|
exports.QueryLoaderFactory = QueryLoaderFactory;
|
|
@@ -9,9 +9,9 @@ interface QueryCountOptions {
|
|
|
9
9
|
export declare function createCountDataLoader<K extends any>(options: QueryCountOptions): DataLoader<K, number, K>;
|
|
10
10
|
export declare class RawCountLoader<K extends any> implements Loader<K, number> {
|
|
11
11
|
private options;
|
|
12
|
-
context?: Context | undefined;
|
|
12
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
13
13
|
private loader;
|
|
14
|
-
constructor(options: QueryCountOptions, context?: Context | undefined);
|
|
14
|
+
constructor(options: QueryCountOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
15
15
|
load(id: K): Promise<number>;
|
|
16
16
|
clearAll(): void;
|
|
17
17
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/core/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type logType = "query" | "warn" | "info" | "error" | "debug" | "cache";
|
|
2
2
|
export declare function setLogLevels(levels: logType | logType[]): void;
|
|
3
3
|
export declare function clearLogLevels(): void;
|
|
4
4
|
export declare function log(level: logType, msg: any): void;
|