@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90
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 +219 -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 +68 -7
- package/core/clause.js +291 -62
- package/core/config.d.ts +8 -0
- 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 +1 -1
- package/core/ent.d.ts +79 -24
- package/core/ent.js +520 -168
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- 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 +62 -58
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +47 -10
- package/core/loaders/raw_count_loader.d.ts +2 -2
- 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 +6 -6
- package/core/query/custom_clause_query.d.ts +24 -0
- package/core/query/custom_clause_query.js +72 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +77 -10
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +1 -1
- package/core/query/query.js +8 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +211 -30
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +6 -0
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/index.d.ts +11 -5
- package/index.js +15 -6
- 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 +125 -9
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +65 -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_graphql.js +8 -3
- 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 +15 -4
- 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} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +70 -16
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/fake_data/fake_contact.d.ts +5 -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_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +8 -6
- package/testutils/fake_data/user_query.d.ts +8 -6
- package/testutils/fake_data/user_query.js +28 -21
- 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 +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +29 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -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 +379 -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;
|
|
@@ -41,10 +41,15 @@ class AssocEdgeCountLoader {
|
|
|
41
41
|
if (!edgeData) {
|
|
42
42
|
throw new Error(`error loading edge data for ${this.edgeType}`);
|
|
43
43
|
}
|
|
44
|
+
const { cls } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", this.edgeType), {
|
|
45
|
+
// don't need this..
|
|
46
|
+
id1: "1",
|
|
47
|
+
edgeType: this.edgeType,
|
|
48
|
+
});
|
|
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
|
}
|
|
@@ -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;
|
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 {};
|
|
@@ -29,6 +29,47 @@ const clause = __importStar(require("../clause"));
|
|
|
29
29
|
const logger_1 = require("../logger");
|
|
30
30
|
const loader_1 = require("./loader");
|
|
31
31
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
32
|
+
async function loadRowsForLoader(options, ids, context) {
|
|
33
|
+
let col = options.key;
|
|
34
|
+
let cls = clause.In(col, ...ids);
|
|
35
|
+
if (options.clause) {
|
|
36
|
+
let optionClause;
|
|
37
|
+
if (typeof options.clause === "function") {
|
|
38
|
+
optionClause = options.clause();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
optionClause = options.clause;
|
|
42
|
+
}
|
|
43
|
+
if (optionClause) {
|
|
44
|
+
cls = clause.And(cls, optionClause);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const rowOptions = {
|
|
48
|
+
...options,
|
|
49
|
+
clause: cls,
|
|
50
|
+
context,
|
|
51
|
+
};
|
|
52
|
+
let m = new Map();
|
|
53
|
+
let result = [];
|
|
54
|
+
for (let i = 0; i < ids.length; i++) {
|
|
55
|
+
result.push(null);
|
|
56
|
+
// store the index....
|
|
57
|
+
m.set(ids[i], i);
|
|
58
|
+
}
|
|
59
|
+
const rows = await (0, ent_1.loadRows)(rowOptions);
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
const id = row[col];
|
|
62
|
+
if (id === undefined) {
|
|
63
|
+
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`);
|
|
64
|
+
}
|
|
65
|
+
const idx = m.get(id);
|
|
66
|
+
if (idx === undefined) {
|
|
67
|
+
throw new Error(`malformed query. got ${id} back but didn't query for it`);
|
|
68
|
+
}
|
|
69
|
+
result[idx] = row;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
32
73
|
// optional clause...
|
|
33
74
|
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
34
75
|
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
@@ -42,42 +83,8 @@ function createDataLoader(options) {
|
|
|
42
83
|
if (!ids.length) {
|
|
43
84
|
return [];
|
|
44
85
|
}
|
|
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
86
|
// 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;
|
|
87
|
+
return loadRowsForLoader(options, ids);
|
|
81
88
|
}, loaderOptions);
|
|
82
89
|
}
|
|
83
90
|
class ObjectLoader {
|
|
@@ -136,7 +143,7 @@ class ObjectLoader {
|
|
|
136
143
|
optionClause = this.options.clause;
|
|
137
144
|
}
|
|
138
145
|
if (optionClause) {
|
|
139
|
-
cls = clause.And(
|
|
146
|
+
cls = clause.And(cls, optionClause);
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
const rowOptions = {
|
|
@@ -144,7 +151,7 @@ class ObjectLoader {
|
|
|
144
151
|
clause: cls,
|
|
145
152
|
context: this.context,
|
|
146
153
|
};
|
|
147
|
-
return
|
|
154
|
+
return (0, ent_1.loadRow)(rowOptions);
|
|
148
155
|
}
|
|
149
156
|
clearAll() {
|
|
150
157
|
this.loader && this.loader.clearAll();
|
|
@@ -153,25 +160,7 @@ class ObjectLoader {
|
|
|
153
160
|
if (this.loader) {
|
|
154
161
|
return await this.loader.loadMany(keys);
|
|
155
162
|
}
|
|
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);
|
|
163
|
+
return loadRowsForLoader(this.options, keys, this.context);
|
|
175
164
|
}
|
|
176
165
|
prime(data) {
|
|
177
166
|
// we have this data from somewhere else, prime it in the c
|
|
@@ -181,14 +170,28 @@ class ObjectLoader {
|
|
|
181
170
|
this.loader.prime(key, data);
|
|
182
171
|
}
|
|
183
172
|
}
|
|
173
|
+
// prime this loader and any other loaders it's aware of
|
|
174
|
+
primeAll(data) {
|
|
175
|
+
this.prime(data);
|
|
176
|
+
if (this.primedLoaders) {
|
|
177
|
+
for (const [key, loader] of this.primedLoaders) {
|
|
178
|
+
const value = data[key];
|
|
179
|
+
if (value !== undefined) {
|
|
180
|
+
loader.prime(data);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
184
185
|
}
|
|
185
186
|
exports.ObjectLoader = ObjectLoader;
|
|
187
|
+
// NOTE: if not querying for all columns
|
|
188
|
+
// have to query for the id field as one of the fields
|
|
189
|
+
// because it's used to maintain sort order of the queried ids
|
|
186
190
|
class ObjectLoaderFactory {
|
|
187
191
|
constructor(options) {
|
|
188
192
|
this.options = options;
|
|
189
193
|
this.toPrime = [];
|
|
190
|
-
|
|
191
|
-
let instanceKey = "";
|
|
194
|
+
let instanceKey = options.instanceKey || "";
|
|
192
195
|
if (typeof this.options.clause === "function") {
|
|
193
196
|
if (!options.instanceKey) {
|
|
194
197
|
throw new Error(`need to pass an instanceKey to ObjectLoader if clause is a function`);
|
|
@@ -208,6 +211,7 @@ class ObjectLoaderFactory {
|
|
|
208
211
|
// because there's usually self references here
|
|
209
212
|
addToPrime(factory) {
|
|
210
213
|
this.toPrime.push(factory);
|
|
214
|
+
return this;
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
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 {};
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.QueryLoaderFactory = exports.
|
|
25
|
+
exports.QueryLoaderFactory = exports.getOrderBy = void 0;
|
|
26
26
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
27
27
|
const ent_1 = require("../ent");
|
|
28
28
|
const clause = __importStar(require("../clause"));
|
|
@@ -30,13 +30,17 @@ const logger_1 = require("../logger");
|
|
|
30
30
|
const loader_1 = require("./loader");
|
|
31
31
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
32
32
|
function getOrderBy(sortCol, orderby) {
|
|
33
|
+
if (orderby) {
|
|
34
|
+
return orderby;
|
|
35
|
+
}
|
|
33
36
|
let sortColLower = sortCol.toLowerCase();
|
|
34
37
|
let orderbyDirection = " DESC";
|
|
35
38
|
if (sortColLower.endsWith("asc") || sortCol.endsWith("desc")) {
|
|
36
39
|
orderbyDirection = "";
|
|
37
40
|
}
|
|
38
|
-
return
|
|
41
|
+
return `${sortCol}${orderbyDirection}`;
|
|
39
42
|
}
|
|
43
|
+
exports.getOrderBy = getOrderBy;
|
|
40
44
|
async function simpleCase(options, id, queryOptions) {
|
|
41
45
|
let cls;
|
|
42
46
|
if (options.groupCol) {
|
|
@@ -120,16 +124,47 @@ function createLoader(options, queryOptions) {
|
|
|
120
124
|
}, loaderOptions);
|
|
121
125
|
}
|
|
122
126
|
class QueryDirectLoader {
|
|
123
|
-
constructor(options, queryOptions) {
|
|
127
|
+
constructor(options, queryOptions, context) {
|
|
124
128
|
this.options = options;
|
|
125
129
|
this.queryOptions = queryOptions;
|
|
130
|
+
this.context = context;
|
|
131
|
+
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
132
|
+
}
|
|
133
|
+
initPrime() {
|
|
134
|
+
if (!this.context || !this.options?.toPrime) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let primedLoaders = new Map();
|
|
138
|
+
this.options.toPrime.forEach((prime) => {
|
|
139
|
+
const l2 = prime.createLoader(this.context);
|
|
140
|
+
if (l2.prime === undefined) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
primedLoaders.set(prime.options.key, l2);
|
|
144
|
+
});
|
|
145
|
+
this.primedLoaders = primedLoaders;
|
|
126
146
|
}
|
|
127
147
|
async load(id) {
|
|
128
|
-
|
|
148
|
+
const rows = await simpleCase(this.options, id, this.queryOptions);
|
|
149
|
+
if (this.context) {
|
|
150
|
+
this.memoizedInitPrime();
|
|
151
|
+
if (this.primedLoaders) {
|
|
152
|
+
for (const row of rows) {
|
|
153
|
+
for (const [key, loader] of this.primedLoaders) {
|
|
154
|
+
const value = row[key];
|
|
155
|
+
if (value !== undefined) {
|
|
156
|
+
loader.prime(row);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return rows;
|
|
129
163
|
}
|
|
130
164
|
clearAll() { }
|
|
131
165
|
}
|
|
132
|
-
|
|
166
|
+
// note, you should never call this directly
|
|
167
|
+
// there's scenarios where QueryDirectLoader is needed instead of this...
|
|
133
168
|
class QueryLoader {
|
|
134
169
|
constructor(options, context, queryOptions) {
|
|
135
170
|
this.options = options;
|
|
@@ -176,7 +211,6 @@ class QueryLoader {
|
|
|
176
211
|
this.loader && this.loader.clearAll();
|
|
177
212
|
}
|
|
178
213
|
}
|
|
179
|
-
exports.QueryLoader = QueryLoader;
|
|
180
214
|
class QueryLoaderFactory {
|
|
181
215
|
constructor(options) {
|
|
182
216
|
this.options = options;
|
|
@@ -194,11 +228,14 @@ class QueryLoaderFactory {
|
|
|
194
228
|
return (0, loader_1.getLoader)(this, () => new QueryLoader(this.options, context), context);
|
|
195
229
|
}
|
|
196
230
|
createConfigurableLoader(options, context) {
|
|
197
|
-
|
|
198
|
-
|
|
231
|
+
return QueryLoaderFactory.createConfigurableLoader(this.name, this.options, options, context);
|
|
232
|
+
}
|
|
233
|
+
static createConfigurableLoader(name, queryOptions, options, context) {
|
|
234
|
+
if (options.clause || !context) {
|
|
235
|
+
return new QueryDirectLoader(queryOptions, options, context);
|
|
199
236
|
}
|
|
200
|
-
const key = `${
|
|
201
|
-
return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(
|
|
237
|
+
const key = `${name}:limit:${options.limit}:orderby:${options.orderby}`;
|
|
238
|
+
return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(queryOptions, context, options), context);
|
|
202
239
|
}
|
|
203
240
|
}
|
|
204
241
|
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
|
}
|
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;
|
package/core/logger.js
CHANGED
package/core/privacy.d.ts
CHANGED
|
@@ -6,22 +6,22 @@ export declare class EntPrivacyError extends Error implements PrivacyError {
|
|
|
6
6
|
constructor(privacyPolicy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent);
|
|
7
7
|
}
|
|
8
8
|
export declare const AlwaysAllowRule: {
|
|
9
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
9
|
+
apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare const AlwaysDenyRule: {
|
|
12
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
12
|
+
apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
13
13
|
};
|
|
14
14
|
export declare const DenyIfLoggedOutRule: {
|
|
15
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
15
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
16
16
|
};
|
|
17
17
|
export declare const DenyIfLoggedInRule: {
|
|
18
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
18
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
19
19
|
};
|
|
20
20
|
export declare const AllowIfHasIdentity: {
|
|
21
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
21
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
22
22
|
};
|
|
23
23
|
export declare const AllowIfViewerRule: {
|
|
24
|
-
apply(v: Viewer, ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
24
|
+
apply(v: Viewer, ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
25
25
|
};
|
|
26
26
|
export declare class AllowIfViewerEqualsRule {
|
|
27
27
|
private id;
|
|
@@ -71,45 +71,45 @@ export declare class DenyIfEntPropertyIsRule<T extends Ent> implements PrivacyPo
|
|
|
71
71
|
constructor(property: keyof T, val: any);
|
|
72
72
|
apply(v: Viewer, ent?: T): Promise<PrivacyResult>;
|
|
73
73
|
}
|
|
74
|
-
export declare class AllowIfEntIsVisibleRule<
|
|
74
|
+
export declare class AllowIfEntIsVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
75
75
|
private id;
|
|
76
76
|
private options;
|
|
77
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
78
|
-
apply(v:
|
|
77
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
78
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
79
79
|
}
|
|
80
|
-
export declare class AllowIfEntIsNotVisibleRule<
|
|
80
|
+
export declare class AllowIfEntIsNotVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
81
81
|
private id;
|
|
82
82
|
private options;
|
|
83
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
84
|
-
apply(v:
|
|
83
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
84
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
85
85
|
}
|
|
86
|
-
export declare class AllowIfEntIsVisiblePolicy<
|
|
86
|
+
export declare class AllowIfEntIsVisiblePolicy<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicy<TEnt, TViewer> {
|
|
87
87
|
private id;
|
|
88
88
|
private options;
|
|
89
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
89
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
90
90
|
rules: {
|
|
91
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
91
|
+
apply(_v: Viewer<Ent<any> | null, ID | null>, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
92
92
|
}[];
|
|
93
93
|
}
|
|
94
|
-
export declare class DenyIfEntIsVisiblePolicy<
|
|
94
|
+
export declare class DenyIfEntIsVisiblePolicy<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicy<TEnt, TViewer> {
|
|
95
95
|
private id;
|
|
96
96
|
private options;
|
|
97
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
97
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
98
98
|
rules: {
|
|
99
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
99
|
+
apply(_v: Viewer<Ent<any> | null, ID | null>, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
100
100
|
}[];
|
|
101
101
|
}
|
|
102
|
-
export declare class DenyIfEntIsVisibleRule<
|
|
102
|
+
export declare class DenyIfEntIsVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule<TEnt, TViewer> {
|
|
103
103
|
private id;
|
|
104
104
|
private options;
|
|
105
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
106
|
-
apply(v:
|
|
105
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
106
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
107
107
|
}
|
|
108
|
-
export declare class DenyIfEntIsNotVisibleRule<
|
|
108
|
+
export declare class DenyIfEntIsNotVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
109
109
|
private id;
|
|
110
110
|
private options;
|
|
111
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
112
|
-
apply(v:
|
|
111
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
112
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
113
113
|
}
|
|
114
114
|
export declare class AllowIfEdgeExistsRule implements PrivacyPolicyRule {
|
|
115
115
|
private id1;
|
|
@@ -121,7 +121,7 @@ export declare class AllowIfEdgeExistsRule implements PrivacyPolicyRule {
|
|
|
121
121
|
export declare class AllowIfViewerInboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
122
122
|
private edgeType;
|
|
123
123
|
constructor(edgeType: string);
|
|
124
|
-
apply(v: Viewer, ent
|
|
124
|
+
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
125
125
|
}
|
|
126
126
|
export declare class AllowIfViewerOutboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
127
127
|
private edgeType;
|
|
@@ -183,6 +183,7 @@ export declare class AllowIfSubPolicyAllowsRule implements PrivacyPolicyRule {
|
|
|
183
183
|
}
|
|
184
184
|
export declare function applyPrivacyPolicy(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined): Promise<boolean>;
|
|
185
185
|
export declare function applyPrivacyPolicyX(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined, throwErr?: () => Error): Promise<boolean>;
|
|
186
|
+
export declare function applyPrivacyPolicyImpl(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined, throwErr?: () => Error): Promise<Error | null>;
|
|
186
187
|
export declare const AlwaysAllowPrivacyPolicy: PrivacyPolicy;
|
|
187
188
|
export declare const AlwaysDenyPrivacyPolicy: PrivacyPolicy;
|
|
188
189
|
export declare const AllowIfViewerPrivacyPolicy: PrivacyPolicy;
|