@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha151
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 +27 -16
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +90 -23
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +3 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +125 -0
- package/action/operations.js +684 -0
- package/action/orchestrator.d.ts +38 -12
- package/action/orchestrator.js +427 -102
- 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 +52 -21
- package/core/base.js +7 -1
- package/core/clause.d.ts +95 -40
- package/core/clause.js +395 -64
- package/core/config.d.ts +15 -1
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +4 -2
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +18 -8
- package/core/ent.d.ts +68 -94
- package/core/ent.js +538 -587
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +1 -0
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/assoc_edge_loader.js +10 -13
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +3 -3
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +225 -78
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +54 -13
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +7 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +7 -6
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +27 -0
- package/core/query/custom_clause_query.js +88 -0
- package/core/query/custom_query.d.ts +17 -2
- package/core/query/custom_query.js +88 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +15 -3
- package/core/query/query.js +128 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +44 -54
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +532 -236
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +52 -19
- package/graphql/graphql.js +174 -136
- package/graphql/graphql_field_helpers.d.ts +7 -1
- package/graphql/graphql_field_helpers.js +21 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +3 -5
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/orderby_direction.d.ts +2 -0
- package/graphql/scalars/orderby_direction.js +15 -0
- package/imports/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/imports/index.d.ts +7 -2
- package/imports/index.js +20 -5
- package/index.d.ts +18 -5
- package/index.js +30 -10
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +179 -32
- package/schema/base_schema.d.ts +13 -3
- package/schema/base_schema.js +13 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +231 -71
- package/schema/index.d.ts +2 -2
- package/schema/index.js +7 -2
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +109 -20
- package/schema/schema.js +42 -53
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +117 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +12 -8
- package/scripts/custom_graphql.js +145 -34
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +22 -7
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +405 -0
- package/testutils/builder.d.ts +39 -43
- package/testutils/builder.js +75 -49
- 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} +32 -8
- package/testutils/db/{test_db.js → temp_db.js} +244 -48
- 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 +52 -9
- 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 +7 -1
- package/testutils/ent-graphql-tests/index.js +56 -26
- package/testutils/fake_comms.js +1 -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 -3
- package/testutils/fake_data/fake_contact.js +13 -7
- package/testutils/fake_data/fake_event.d.ts +4 -1
- package/testutils/fake_data/fake_event.js +7 -6
- 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 +8 -5
- package/testutils/fake_data/fake_user.js +16 -15
- 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 +11 -4
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.js +1 -1
- 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 +25 -2
- package/tsc/ast.js +141 -17
- package/tsc/compilerOptions.js +5 -1
- 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 +182 -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 +60 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +146 -117
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -142
- package/scripts/transform_code.js +0 -113
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
|
@@ -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,13 +26,66 @@ 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.ObjectLoaderFactory = exports.ObjectLoader = void 0;
|
|
29
|
+
exports.ObjectLoaderFactory = exports.ObjectCountLoader = exports.ObjectLoader = void 0;
|
|
26
30
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
27
31
|
const ent_1 = require("../ent");
|
|
28
32
|
const clause = __importStar(require("../clause"));
|
|
29
33
|
const logger_1 = require("../logger");
|
|
34
|
+
const clause_1 = require("../clause");
|
|
30
35
|
const loader_1 = require("./loader");
|
|
31
36
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
37
|
+
async function loadRowsForIDLoader(options, ids, context) {
|
|
38
|
+
let col = options.key;
|
|
39
|
+
const cls = (0, clause_1.getCombinedClause)(options, clause.DBTypeIn(col, ids, options.keyType || "uuid"));
|
|
40
|
+
const rowOptions = {
|
|
41
|
+
...options,
|
|
42
|
+
clause: cls,
|
|
43
|
+
context,
|
|
44
|
+
};
|
|
45
|
+
let m = new Map();
|
|
46
|
+
let result = [];
|
|
47
|
+
for (let i = 0; i < ids.length; i++) {
|
|
48
|
+
result.push(null);
|
|
49
|
+
// store the index....
|
|
50
|
+
m.set(ids[i], i);
|
|
51
|
+
}
|
|
52
|
+
const rows = (await (0, ent_1.loadRows)(rowOptions));
|
|
53
|
+
for (const row of rows) {
|
|
54
|
+
const id = row[col];
|
|
55
|
+
if (id === undefined) {
|
|
56
|
+
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`);
|
|
57
|
+
}
|
|
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;
|
|
65
|
+
}
|
|
66
|
+
async function loadRowsForClauseLoader(options, clause) {
|
|
67
|
+
const rowOptions = {
|
|
68
|
+
...options,
|
|
69
|
+
// @ts-expect-error clause in LoadRowOptions doesn't take templatized version of Clause
|
|
70
|
+
clause: (0, clause_1.getCombinedClause)(options, clause),
|
|
71
|
+
};
|
|
72
|
+
return (await (0, ent_1.loadRows)(rowOptions));
|
|
73
|
+
}
|
|
74
|
+
async function loadCountForClauseLoader(options, clause) {
|
|
75
|
+
const rowOptions = {
|
|
76
|
+
...options,
|
|
77
|
+
// @ts-expect-error clause in LoadRowOptions doesn't take templatized version of Clause
|
|
78
|
+
clause: (0, clause_1.getCombinedClause)(options, clause),
|
|
79
|
+
};
|
|
80
|
+
const row = await (0, ent_1.loadRow)({
|
|
81
|
+
...rowOptions,
|
|
82
|
+
fields: ["count(*) as count"],
|
|
83
|
+
});
|
|
84
|
+
if (!row) {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
return parseInt(row.count, 10);
|
|
88
|
+
}
|
|
32
89
|
// optional clause...
|
|
33
90
|
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
34
91
|
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
@@ -42,43 +99,66 @@ function createDataLoader(options) {
|
|
|
42
99
|
if (!ids.length) {
|
|
43
100
|
return [];
|
|
44
101
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
102
|
+
// context not needed because we're creating a loader which has its own cache which is being used here
|
|
103
|
+
return loadRowsForIDLoader(options, ids);
|
|
104
|
+
}, loaderOptions);
|
|
105
|
+
}
|
|
106
|
+
class clauseCacheMap {
|
|
107
|
+
constructor(options, count) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
this.count = count;
|
|
110
|
+
this.m = new Map();
|
|
111
|
+
}
|
|
112
|
+
get(key) {
|
|
113
|
+
const key2 = key.instanceKey();
|
|
114
|
+
const ret = this.m.get(key2);
|
|
115
|
+
if (ret) {
|
|
116
|
+
(0, logger_1.log)("cache", {
|
|
117
|
+
"dataloader-cache-hit": key2 + (this.count ? ":count" : ""),
|
|
118
|
+
"tableName": this.options.tableName,
|
|
119
|
+
});
|
|
58
120
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
121
|
+
return ret;
|
|
122
|
+
}
|
|
123
|
+
set(key, value) {
|
|
124
|
+
return this.m.set(key.instanceKey(), value);
|
|
125
|
+
}
|
|
126
|
+
delete(key) {
|
|
127
|
+
return this.m.delete(key.instanceKey());
|
|
128
|
+
}
|
|
129
|
+
clear() {
|
|
130
|
+
return this.m.clear();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function createClauseDataLoder(options) {
|
|
134
|
+
return new dataloader_1.default(async (clauses) => {
|
|
135
|
+
if (!clauses.length) {
|
|
136
|
+
return [];
|
|
69
137
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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;
|
|
138
|
+
const ret = [];
|
|
139
|
+
for await (const clause of clauses) {
|
|
140
|
+
const data = await loadRowsForClauseLoader(options, clause);
|
|
141
|
+
ret.push(data);
|
|
79
142
|
}
|
|
80
|
-
return
|
|
81
|
-
},
|
|
143
|
+
return ret;
|
|
144
|
+
}, {
|
|
145
|
+
cacheMap: new clauseCacheMap(options),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function createClauseCountDataLoader(options) {
|
|
149
|
+
return new dataloader_1.default(async (clauses) => {
|
|
150
|
+
if (!clauses.length) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
const ret = [];
|
|
154
|
+
for await (const clause of clauses) {
|
|
155
|
+
const data = await loadCountForClauseLoader(options, clause);
|
|
156
|
+
ret.push(data);
|
|
157
|
+
}
|
|
158
|
+
return ret;
|
|
159
|
+
}, {
|
|
160
|
+
cacheMap: new clauseCacheMap(options, true),
|
|
161
|
+
});
|
|
82
162
|
}
|
|
83
163
|
class ObjectLoader {
|
|
84
164
|
constructor(options, context, toPrime) {
|
|
@@ -89,7 +169,8 @@ class ObjectLoader {
|
|
|
89
169
|
console.trace();
|
|
90
170
|
}
|
|
91
171
|
if (context) {
|
|
92
|
-
this.
|
|
172
|
+
this.idLoader = createDataLoader(options);
|
|
173
|
+
this.clauseLoader = createClauseDataLoder(options);
|
|
93
174
|
}
|
|
94
175
|
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
95
176
|
}
|
|
@@ -111,11 +192,17 @@ class ObjectLoader {
|
|
|
111
192
|
this.primedLoaders = primedLoaders;
|
|
112
193
|
}
|
|
113
194
|
async load(key) {
|
|
195
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
196
|
+
return this.loadID(key);
|
|
197
|
+
}
|
|
198
|
+
return this.loadClause(key);
|
|
199
|
+
}
|
|
200
|
+
async loadID(key) {
|
|
114
201
|
// simple case. we get parallelization etc
|
|
115
|
-
if (this.
|
|
202
|
+
if (this.idLoader) {
|
|
116
203
|
this.memoizedInitPrime();
|
|
117
204
|
// prime the result if we got primable loaders
|
|
118
|
-
const result = await this.
|
|
205
|
+
const result = await this.idLoader.load(key);
|
|
119
206
|
if (result && this.primedLoaders) {
|
|
120
207
|
for (const [key, loader] of this.primedLoaders) {
|
|
121
208
|
const value = result[key];
|
|
@@ -126,69 +213,119 @@ class ObjectLoader {
|
|
|
126
213
|
}
|
|
127
214
|
return result;
|
|
128
215
|
}
|
|
129
|
-
|
|
130
|
-
if (this.options.clause) {
|
|
131
|
-
let optionClause;
|
|
132
|
-
if (typeof this.options.clause === "function") {
|
|
133
|
-
optionClause = this.options.clause();
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
optionClause = this.options.clause;
|
|
137
|
-
}
|
|
138
|
-
if (optionClause) {
|
|
139
|
-
cls = clause.And(optionClause, cls);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
216
|
+
const cls = (0, clause_1.getCombinedClause)(this.options, clause.Eq(this.options.key, key));
|
|
142
217
|
const rowOptions = {
|
|
143
218
|
...this.options,
|
|
144
219
|
clause: cls,
|
|
145
220
|
context: this.context,
|
|
146
221
|
};
|
|
147
|
-
return
|
|
222
|
+
return (0, ent_1.loadRow)(rowOptions);
|
|
223
|
+
}
|
|
224
|
+
async loadClause(key) {
|
|
225
|
+
if (this.clauseLoader) {
|
|
226
|
+
return this.clauseLoader.load(key);
|
|
227
|
+
}
|
|
228
|
+
return loadRowsForClauseLoader(this.options, key);
|
|
148
229
|
}
|
|
149
230
|
clearAll() {
|
|
150
|
-
this.
|
|
231
|
+
this.idLoader && this.idLoader.clearAll();
|
|
232
|
+
this.clauseLoader && this.clauseLoader.clearAll();
|
|
151
233
|
}
|
|
152
234
|
async loadMany(keys) {
|
|
153
|
-
if (
|
|
154
|
-
return
|
|
235
|
+
if (!keys.length) {
|
|
236
|
+
return [];
|
|
155
237
|
}
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
}
|
|
238
|
+
if (typeof keys[0] === "string" || typeof keys[0] === "number") {
|
|
239
|
+
return this.loadIDMany(keys);
|
|
168
240
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
241
|
+
return this.loadClauseMany(keys);
|
|
242
|
+
}
|
|
243
|
+
loadIDMany(keys) {
|
|
244
|
+
if (this.idLoader) {
|
|
245
|
+
// @ts-expect-error TODO?
|
|
246
|
+
return this.idLoader.loadMany(keys);
|
|
247
|
+
}
|
|
248
|
+
return loadRowsForIDLoader(this.options, keys, this.context);
|
|
249
|
+
}
|
|
250
|
+
async loadClauseMany(keys) {
|
|
251
|
+
if (this.clauseLoader) {
|
|
252
|
+
// @ts-expect-error TODO?
|
|
253
|
+
return this.clauseLoader.loadMany(keys);
|
|
254
|
+
}
|
|
255
|
+
const res = [];
|
|
256
|
+
for await (const key of keys) {
|
|
257
|
+
const rows = await loadRowsForClauseLoader(this.options, key);
|
|
258
|
+
res.push(rows);
|
|
259
|
+
}
|
|
260
|
+
return res;
|
|
175
261
|
}
|
|
176
262
|
prime(data) {
|
|
177
263
|
// we have this data from somewhere else, prime it in the c
|
|
178
|
-
if (this.
|
|
264
|
+
if (this.idLoader) {
|
|
179
265
|
const col = this.options.key;
|
|
180
266
|
const key = data[col];
|
|
181
|
-
this.
|
|
267
|
+
this.idLoader.prime(key, data);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// prime this loader and any other loaders it's aware of
|
|
271
|
+
primeAll(data) {
|
|
272
|
+
this.prime(data);
|
|
273
|
+
if (this.primedLoaders) {
|
|
274
|
+
for (const [key, loader] of this.primedLoaders) {
|
|
275
|
+
const value = data[key];
|
|
276
|
+
if (value !== undefined) {
|
|
277
|
+
loader.prime(data);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
182
280
|
}
|
|
183
281
|
}
|
|
184
282
|
}
|
|
185
283
|
exports.ObjectLoader = ObjectLoader;
|
|
284
|
+
class ObjectCountLoader {
|
|
285
|
+
constructor(options, context) {
|
|
286
|
+
this.options = options;
|
|
287
|
+
this.context = context;
|
|
288
|
+
if (context) {
|
|
289
|
+
this.loader = createClauseCountDataLoader(options);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
getOptions() {
|
|
293
|
+
return this.options;
|
|
294
|
+
}
|
|
295
|
+
async load(key) {
|
|
296
|
+
if (this.loader) {
|
|
297
|
+
return this.loader.load(key);
|
|
298
|
+
}
|
|
299
|
+
return loadCountForClauseLoader(this.options, key);
|
|
300
|
+
}
|
|
301
|
+
clearAll() {
|
|
302
|
+
this.loader && this.loader.clearAll();
|
|
303
|
+
}
|
|
304
|
+
async loadMany(keys) {
|
|
305
|
+
if (!keys.length) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
if (this.loader) {
|
|
309
|
+
// @ts-expect-error
|
|
310
|
+
return this.loader.loadMany(keys);
|
|
311
|
+
}
|
|
312
|
+
const res = [];
|
|
313
|
+
for await (const key of keys) {
|
|
314
|
+
const r = await loadCountForClauseLoader(this.options, key);
|
|
315
|
+
res.push(r);
|
|
316
|
+
}
|
|
317
|
+
return res;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.ObjectCountLoader = ObjectCountLoader;
|
|
321
|
+
// NOTE: if not querying for all columns
|
|
322
|
+
// have to query for the id field as one of the fields
|
|
323
|
+
// because it's used to maintain sort order of the queried ids
|
|
186
324
|
class ObjectLoaderFactory {
|
|
187
325
|
constructor(options) {
|
|
188
326
|
this.options = options;
|
|
189
327
|
this.toPrime = [];
|
|
190
|
-
|
|
191
|
-
let instanceKey = "";
|
|
328
|
+
let instanceKey = options.instanceKey || "";
|
|
192
329
|
if (typeof this.options.clause === "function") {
|
|
193
330
|
if (!options.instanceKey) {
|
|
194
331
|
throw new Error(`need to pass an instanceKey to ObjectLoader if clause is a function`);
|
|
@@ -204,10 +341,20 @@ class ObjectLoaderFactory {
|
|
|
204
341
|
return new ObjectLoader(this.options, context, this.toPrime);
|
|
205
342
|
}, context);
|
|
206
343
|
}
|
|
344
|
+
createTypedLoader(context) {
|
|
345
|
+
const loader = this.createLoader(context);
|
|
346
|
+
return loader;
|
|
347
|
+
}
|
|
348
|
+
createCountLoader(context) {
|
|
349
|
+
return (0, loader_1.getCustomLoader)(`${this.name}:count_loader`, () => {
|
|
350
|
+
return new ObjectCountLoader(this.options, context);
|
|
351
|
+
}, context);
|
|
352
|
+
}
|
|
207
353
|
// keep track of loaders to prime. needs to be done not in the constructor
|
|
208
354
|
// because there's usually self references here
|
|
209
355
|
addToPrime(factory) {
|
|
210
356
|
this.toPrime.push(factory);
|
|
357
|
+
return this;
|
|
211
358
|
}
|
|
212
359
|
}
|
|
213
360
|
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
|
-
constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined);
|
|
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
8
|
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
14
|
-
private queryOptions?;
|
|
15
|
-
private loader;
|
|
16
|
-
private primedLoaders;
|
|
17
9
|
private memoizedInitPrime;
|
|
18
|
-
|
|
10
|
+
private primedLoaders;
|
|
11
|
+
constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "clause" | "limit" | "orderby">> | 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;
|
|
@@ -26,7 +19,7 @@ interface QueryOptions {
|
|
|
26
19
|
groupCol?: string;
|
|
27
20
|
clause?: clause.Clause;
|
|
28
21
|
sortColumn?: string;
|
|
29
|
-
toPrime?: ObjectLoaderFactory<
|
|
22
|
+
toPrime?: ObjectLoaderFactory<Data>[];
|
|
30
23
|
}
|
|
31
24
|
export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<K, Data[]> {
|
|
32
25
|
private options;
|
|
@@ -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) {
|
|
@@ -59,7 +67,7 @@ async function simpleCase(options, id, queryOptions) {
|
|
|
59
67
|
...options,
|
|
60
68
|
clause: cls,
|
|
61
69
|
orderby: getOrderBy(sortCol, queryOptions?.orderby),
|
|
62
|
-
limit: queryOptions?.limit || ent_1.
|
|
70
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
63
71
|
});
|
|
64
72
|
}
|
|
65
73
|
function createLoader(options, queryOptions) {
|
|
@@ -102,7 +110,7 @@ function createLoader(options, queryOptions) {
|
|
|
102
110
|
fields: options.fields,
|
|
103
111
|
values: keys,
|
|
104
112
|
orderby: getOrderBy(sortCol, queryOptions?.orderby),
|
|
105
|
-
limit: queryOptions?.limit || ent_1.
|
|
113
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
106
114
|
groupColumn: col,
|
|
107
115
|
clause: extraClause,
|
|
108
116
|
});
|
|
@@ -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;
|
|
@@ -4,6 +4,7 @@ import * as clause from "../clause";
|
|
|
4
4
|
interface QueryCountOptions {
|
|
5
5
|
tableName: string;
|
|
6
6
|
groupCol?: string;
|
|
7
|
+
groupColType?: string;
|
|
7
8
|
clause?: clause.Clause;
|
|
8
9
|
}
|
|
9
10
|
export declare function createCountDataLoader<K extends any>(options: QueryCountOptions): DataLoader<K, number, K>;
|
|
@@ -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];
|
|
@@ -65,7 +69,8 @@ function createCountDataLoader(options) {
|
|
|
65
69
|
if (keys.length == 1 || !options.groupCol) {
|
|
66
70
|
return simpleCase(options, keys[0]);
|
|
67
71
|
}
|
|
68
|
-
let
|
|
72
|
+
let typ = options.groupColType || "uuid";
|
|
73
|
+
let cls = clause.DBTypeIn(options.groupCol, keys, typ);
|
|
69
74
|
if (options.clause) {
|
|
70
75
|
cls = clause.And(cls, options.clause);
|
|
71
76
|
}
|
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;
|
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
|
|
9
|
+
apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare const AlwaysDenyRule: {
|
|
12
|
-
apply(_v: Viewer, _ent?: Ent
|
|
12
|
+
apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
13
13
|
};
|
|
14
14
|
export declare const DenyIfLoggedOutRule: {
|
|
15
|
-
apply(v: Viewer, _ent?: Ent
|
|
15
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
16
16
|
};
|
|
17
17
|
export declare const DenyIfLoggedInRule: {
|
|
18
|
-
apply(v: Viewer, _ent?: Ent
|
|
18
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
19
19
|
};
|
|
20
20
|
export declare const AllowIfHasIdentity: {
|
|
21
|
-
apply(v: Viewer, _ent?: Ent
|
|
21
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
22
22
|
};
|
|
23
23
|
export declare const AllowIfViewerRule: {
|
|
24
|
-
apply(v: Viewer, ent?: Ent
|
|
24
|
+
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
25
25
|
};
|
|
26
26
|
export declare class AllowIfViewerEqualsRule {
|
|
27
27
|
private id;
|
|
@@ -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;
|