@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha91
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 +36 -31
- package/action/action.js +2 -6
- package/action/executor.d.ts +3 -3
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +38 -16
- package/action/orchestrator.js +223 -61
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +45 -24
- package/core/base.js +7 -1
- package/core/clause.d.ts +83 -7
- package/core/clause.js +334 -63
- package/core/config.d.ts +8 -0
- package/core/config.js +5 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +2 -2
- package/core/db.js +6 -2
- package/core/ent.d.ts +79 -24
- package/core/ent.js +527 -176
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +14 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +5 -1
- 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/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +67 -59
- 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 +21 -25
- 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 +34 -43
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +470 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +16 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_edge_connection.js +1 -15
- package/imports/index.js +5 -1
- package/index.d.ts +11 -5
- package/index.js +20 -7
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +12 -3
- package/parse_schema/parse.js +70 -11
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +44 -8
- package/schema/field.js +136 -10
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +66 -11
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +44 -5
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +13 -4
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +83 -29
- 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} +20 -7
- package/testutils/db/{test_db.js → temp_db.js} +102 -36
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.js +3 -1
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.js +8 -1
- 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 +7 -4
- package/testutils/fake_data/fake_contact.js +14 -6
- package/testutils/fake_data/fake_event.d.ts +5 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_tag.d.ts +35 -0
- package/testutils/fake_data/fake_tag.js +88 -0
- package/testutils/fake_data/fake_user.d.ts +6 -4
- package/testutils/fake_data/fake_user.js +16 -13
- 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 +28 -12
- 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 +271 -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 +21 -0
- package/tsc/transform.js +171 -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/scripts/transform_schema.js +0 -445
|
@@ -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,15 @@ 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), {
|
|
49
|
+
// don't need this..
|
|
50
|
+
id1: "1",
|
|
51
|
+
edgeType: this.edgeType,
|
|
52
|
+
});
|
|
44
53
|
this.loader = (0, raw_count_loader_1.createCountDataLoader)({
|
|
45
54
|
tableName: edgeData.edgeTable,
|
|
46
55
|
groupCol: "id1",
|
|
47
|
-
clause:
|
|
56
|
+
clause: cls,
|
|
48
57
|
});
|
|
49
58
|
return this.loader;
|
|
50
59
|
}
|
|
@@ -68,6 +77,9 @@ class AssocEdgeCountLoaderFactory {
|
|
|
68
77
|
this.edgeType = edgeType;
|
|
69
78
|
this.name = `assocEdgeLoader:count:${edgeType}`;
|
|
70
79
|
}
|
|
80
|
+
getEdgeType() {
|
|
81
|
+
return this.edgeType;
|
|
82
|
+
}
|
|
71
83
|
createLoader(context) {
|
|
72
84
|
return (0, loader_1.getLoader)(this, () => new AssocEdgeCountLoader(this.edgeType, context), context);
|
|
73
85
|
}
|
|
@@ -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;
|
|
@@ -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/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
|
}
|
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,18 +1,19 @@
|
|
|
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
10
|
getOptions(): SelectDataOptions;
|
|
11
11
|
private initPrime;
|
|
12
12
|
load(key: T): Promise<Data | null>;
|
|
13
13
|
clearAll(): void;
|
|
14
|
-
loadMany(keys: T[]): Promise<Data
|
|
14
|
+
loadMany(keys: T[]): Promise<Array<Data | null>>;
|
|
15
15
|
prime(data: Data): void;
|
|
16
|
+
primeAll(data: Data): void;
|
|
16
17
|
}
|
|
17
18
|
interface ObjectLoaderOptions extends SelectDataOptions {
|
|
18
19
|
instanceKey?: string;
|
|
@@ -23,6 +24,6 @@ export declare class ObjectLoaderFactory<T> implements LoaderFactory<T, Data | n
|
|
|
23
24
|
private toPrime;
|
|
24
25
|
constructor(options: ObjectLoaderOptions);
|
|
25
26
|
createLoader(context?: Context): ObjectLoader<T>;
|
|
26
|
-
addToPrime(factory: ObjectLoaderFactory<T>):
|
|
27
|
+
addToPrime(factory: ObjectLoaderFactory<T>): this;
|
|
27
28
|
}
|
|
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,47 @@ 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
|
+
}
|
|
32
77
|
// optional clause...
|
|
33
78
|
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
34
79
|
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
@@ -42,42 +87,8 @@ function createDataLoader(options) {
|
|
|
42
87
|
if (!ids.length) {
|
|
43
88
|
return [];
|
|
44
89
|
}
|
|
45
|
-
let col = options.key;
|
|
46
|
-
let cls = clause.In(col, ...ids);
|
|
47
|
-
if (options.clause) {
|
|
48
|
-
let optionClause;
|
|
49
|
-
if (typeof options.clause === "function") {
|
|
50
|
-
optionClause = options.clause();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
optionClause = options.clause;
|
|
54
|
-
}
|
|
55
|
-
if (optionClause) {
|
|
56
|
-
cls = clause.And(optionClause, cls);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const rowOptions = {
|
|
60
|
-
...options,
|
|
61
|
-
clause: cls,
|
|
62
|
-
};
|
|
63
|
-
let m = new Map();
|
|
64
|
-
let result = [];
|
|
65
|
-
for (let i = 0; i < ids.length; i++) {
|
|
66
|
-
result.push(null);
|
|
67
|
-
// store the index....
|
|
68
|
-
m.set(ids[i], i);
|
|
69
|
-
}
|
|
70
90
|
// context not needed because we're creating a loader which has its own cache which is being used here
|
|
71
|
-
|
|
72
|
-
for (const row of rows) {
|
|
73
|
-
const id = row[col];
|
|
74
|
-
const idx = m.get(id);
|
|
75
|
-
if (idx === undefined) {
|
|
76
|
-
throw new Error(`malformed query. got ${id} back but didn't query for it`);
|
|
77
|
-
}
|
|
78
|
-
result[idx] = row;
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
91
|
+
return loadRowsForLoader(options, ids);
|
|
81
92
|
}, loaderOptions);
|
|
82
93
|
}
|
|
83
94
|
class ObjectLoader {
|
|
@@ -136,7 +147,7 @@ class ObjectLoader {
|
|
|
136
147
|
optionClause = this.options.clause;
|
|
137
148
|
}
|
|
138
149
|
if (optionClause) {
|
|
139
|
-
cls = clause.And(
|
|
150
|
+
cls = clause.And(cls, optionClause);
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
const rowOptions = {
|
|
@@ -144,7 +155,7 @@ class ObjectLoader {
|
|
|
144
155
|
clause: cls,
|
|
145
156
|
context: this.context,
|
|
146
157
|
};
|
|
147
|
-
return
|
|
158
|
+
return (0, ent_1.loadRow)(rowOptions);
|
|
148
159
|
}
|
|
149
160
|
clearAll() {
|
|
150
161
|
this.loader && this.loader.clearAll();
|
|
@@ -153,25 +164,7 @@ class ObjectLoader {
|
|
|
153
164
|
if (this.loader) {
|
|
154
165
|
return await this.loader.loadMany(keys);
|
|
155
166
|
}
|
|
156
|
-
|
|
157
|
-
if (this.options.clause) {
|
|
158
|
-
let optionClause;
|
|
159
|
-
if (typeof this.options.clause === "function") {
|
|
160
|
-
optionClause = this.options.clause();
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
optionClause = this.options.clause;
|
|
164
|
-
}
|
|
165
|
-
if (optionClause) {
|
|
166
|
-
cls = clause.And(optionClause, cls);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const rowOptions = {
|
|
170
|
-
...this.options,
|
|
171
|
-
clause: cls,
|
|
172
|
-
context: this.context,
|
|
173
|
-
};
|
|
174
|
-
return await (0, ent_1.loadRows)(rowOptions);
|
|
167
|
+
return loadRowsForLoader(this.options, keys, this.context);
|
|
175
168
|
}
|
|
176
169
|
prime(data) {
|
|
177
170
|
// we have this data from somewhere else, prime it in the c
|
|
@@ -181,14 +174,28 @@ class ObjectLoader {
|
|
|
181
174
|
this.loader.prime(key, data);
|
|
182
175
|
}
|
|
183
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
|
+
}
|
|
184
189
|
}
|
|
185
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
|
|
186
194
|
class ObjectLoaderFactory {
|
|
187
195
|
constructor(options) {
|
|
188
196
|
this.options = options;
|
|
189
197
|
this.toPrime = [];
|
|
190
|
-
|
|
191
|
-
let instanceKey = "";
|
|
198
|
+
let instanceKey = options.instanceKey || "";
|
|
192
199
|
if (typeof this.options.clause === "function") {
|
|
193
200
|
if (!options.instanceKey) {
|
|
194
201
|
throw new Error(`need to pass an instanceKey to ObjectLoader if clause is a function`);
|
|
@@ -208,6 +215,7 @@ class ObjectLoaderFactory {
|
|
|
208
215
|
// because there's usually self references here
|
|
209
216
|
addToPrime(factory) {
|
|
210
217
|
this.toPrime.push(factory);
|
|
218
|
+
return this;
|
|
211
219
|
}
|
|
212
220
|
}
|
|
213
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
|
-
declare type logType = "query" | "warn" | "info" | "error" | "debug";
|
|
1
|
+
declare 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;
|