@snowtop/ent 0.1.0-alpha99 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/action.d.ts +8 -1
- package/action/executor.d.ts +16 -3
- package/action/executor.js +83 -27
- package/action/index.d.ts +2 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +22 -8
- package/action/orchestrator.js +278 -67
- package/core/base.d.ts +34 -24
- package/core/clause.d.ts +62 -79
- package/core/clause.js +77 -5
- package/core/config.d.ts +5 -1
- package/core/config.js +3 -0
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +4 -3
- package/core/context.js +2 -1
- package/core/db.d.ts +1 -0
- package/core/db.js +7 -7
- package/core/ent.d.ts +53 -105
- package/core/ent.js +104 -599
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +4 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +16 -7
- package/core/loaders/index.d.ts +0 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +3 -20
- package/core/loaders/object_loader.d.ts +30 -10
- package/core/loaders/object_loader.js +179 -40
- package/core/loaders/query_loader.d.ts +4 -4
- package/core/loaders/query_loader.js +14 -19
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +3 -2
- package/core/privacy.d.ts +19 -10
- package/core/privacy.js +47 -26
- package/core/query/assoc_query.js +1 -1
- package/core/query/custom_clause_query.d.ts +6 -3
- package/core/query/custom_clause_query.js +36 -9
- package/core/query/custom_query.d.ts +3 -1
- package/core/query/custom_query.js +29 -6
- package/core/query/query.d.ts +12 -2
- package/core/query/query.js +67 -38
- package/core/query/shared_assoc_test.js +151 -10
- package/core/query/shared_test.d.ts +2 -2
- package/core/query/shared_test.js +90 -30
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +2 -0
- package/graphql/graphql.d.ts +103 -19
- package/graphql/graphql.js +169 -134
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -1
- package/graphql/index.js +5 -2
- 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 +1 -1
- package/imports/index.js +2 -2
- package/index.d.ts +12 -1
- package/index.js +18 -6
- package/package.json +20 -17
- package/parse_schema/parse.d.ts +10 -4
- package/parse_schema/parse.js +70 -24
- package/schema/base_schema.d.ts +8 -0
- package/schema/base_schema.js +11 -0
- package/schema/field.d.ts +6 -3
- package/schema/field.js +72 -17
- package/schema/index.d.ts +1 -1
- package/schema/index.js +2 -1
- package/schema/json_field.d.ts +3 -3
- package/schema/json_field.js +4 -1
- package/schema/schema.d.ts +42 -5
- package/schema/schema.js +35 -41
- package/schema/struct_field.d.ts +8 -6
- package/schema/struct_field.js +67 -8
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +4 -4
- package/scripts/custom_graphql.js +105 -75
- package/scripts/move_types.js +4 -1
- package/scripts/read_schema.js +2 -2
- package/testutils/action/complex_schemas.d.ts +1 -1
- package/testutils/action/complex_schemas.js +10 -3
- package/testutils/builder.d.ts +3 -0
- package/testutils/builder.js +6 -0
- package/testutils/db/temp_db.d.ts +9 -1
- package/testutils/db/temp_db.js +82 -14
- package/testutils/db_mock.js +1 -3
- package/testutils/ent-graphql-tests/index.d.ts +1 -1
- package/testutils/ent-graphql-tests/index.js +30 -19
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_tag.d.ts +1 -1
- package/testutils/fake_data/fake_user.d.ts +3 -3
- package/testutils/fake_data/fake_user.js +15 -4
- package/testutils/fake_data/tag_query.js +8 -3
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +4 -4
- package/testutils/fake_data/user_query.d.ts +5 -2
- package/testutils/fake_data/user_query.js +19 -2
- package/testutils/fake_log.js +1 -1
- package/tsc/ast.js +2 -1
- package/tsc/move_generated.js +2 -2
- package/tsc/transform.d.ts +2 -2
- package/tsc/transform.js +4 -3
- package/tsc/transform_ent.js +2 -1
- package/tsc/transform_schema.js +4 -3
- package/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
|
@@ -26,28 +26,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ObjectLoaderFactory = exports.ObjectLoader = void 0;
|
|
29
|
+
exports.ObjectLoaderFactory = exports.ObjectCountLoader = exports.ObjectLoader = void 0;
|
|
30
30
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
31
31
|
const ent_1 = require("../ent");
|
|
32
32
|
const clause = __importStar(require("../clause"));
|
|
33
33
|
const logger_1 = require("../logger");
|
|
34
|
+
const clause_1 = require("../clause");
|
|
34
35
|
const loader_1 = require("./loader");
|
|
35
36
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
36
|
-
async function
|
|
37
|
+
async function loadRowsForIDLoader(options, ids, context) {
|
|
37
38
|
let col = options.key;
|
|
38
|
-
|
|
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
|
-
}
|
|
39
|
+
const cls = (0, clause_1.getCombinedClause)(options, clause.DBTypeIn(col, ids, options.keyType || "uuid"));
|
|
51
40
|
const rowOptions = {
|
|
52
41
|
...options,
|
|
53
42
|
clause: cls,
|
|
@@ -60,7 +49,7 @@ async function loadRowsForLoader(options, ids, context) {
|
|
|
60
49
|
// store the index....
|
|
61
50
|
m.set(ids[i], i);
|
|
62
51
|
}
|
|
63
|
-
const rows = await (0, ent_1.loadRows)(rowOptions);
|
|
52
|
+
const rows = (await (0, ent_1.loadRows)(rowOptions));
|
|
64
53
|
for (const row of rows) {
|
|
65
54
|
const id = row[col];
|
|
66
55
|
if (id === undefined) {
|
|
@@ -74,6 +63,29 @@ async function loadRowsForLoader(options, ids, context) {
|
|
|
74
63
|
}
|
|
75
64
|
return result;
|
|
76
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
|
+
}
|
|
77
89
|
// optional clause...
|
|
78
90
|
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
79
91
|
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
@@ -81,16 +93,73 @@ function createDataLoader(options) {
|
|
|
81
93
|
const loaderOptions = {};
|
|
82
94
|
// if query logging is enabled, we should log what's happening with loader
|
|
83
95
|
if ((0, logger_1.logEnabled)("query")) {
|
|
84
|
-
loaderOptions.cacheMap = new loader_1.
|
|
96
|
+
loaderOptions.cacheMap = new loader_1.CacheMap(options);
|
|
85
97
|
}
|
|
86
98
|
return new dataloader_1.default(async (ids) => {
|
|
87
99
|
if (!ids.length) {
|
|
88
100
|
return [];
|
|
89
101
|
}
|
|
90
102
|
// context not needed because we're creating a loader which has its own cache which is being used here
|
|
91
|
-
return
|
|
103
|
+
return loadRowsForIDLoader(options, ids);
|
|
92
104
|
}, loaderOptions);
|
|
93
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
|
+
});
|
|
120
|
+
}
|
|
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 [];
|
|
137
|
+
}
|
|
138
|
+
const ret = [];
|
|
139
|
+
for await (const clause of clauses) {
|
|
140
|
+
const data = await loadRowsForClauseLoader(options, clause);
|
|
141
|
+
ret.push(data);
|
|
142
|
+
}
|
|
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
|
+
});
|
|
162
|
+
}
|
|
94
163
|
class ObjectLoader {
|
|
95
164
|
constructor(options, context, toPrime) {
|
|
96
165
|
this.options = options;
|
|
@@ -100,7 +169,8 @@ class ObjectLoader {
|
|
|
100
169
|
console.trace();
|
|
101
170
|
}
|
|
102
171
|
if (context) {
|
|
103
|
-
this.
|
|
172
|
+
this.idLoader = createDataLoader(options);
|
|
173
|
+
this.clauseLoader = createClauseDataLoder(options);
|
|
104
174
|
}
|
|
105
175
|
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
106
176
|
}
|
|
@@ -122,11 +192,17 @@ class ObjectLoader {
|
|
|
122
192
|
this.primedLoaders = primedLoaders;
|
|
123
193
|
}
|
|
124
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) {
|
|
125
201
|
// simple case. we get parallelization etc
|
|
126
|
-
if (this.
|
|
202
|
+
if (this.idLoader) {
|
|
127
203
|
this.memoizedInitPrime();
|
|
128
204
|
// prime the result if we got primable loaders
|
|
129
|
-
const result = await this.
|
|
205
|
+
const result = await this.idLoader.load(key);
|
|
130
206
|
if (result && this.primedLoaders) {
|
|
131
207
|
for (const [key, loader] of this.primedLoaders) {
|
|
132
208
|
const value = result[key];
|
|
@@ -137,19 +213,7 @@ class ObjectLoader {
|
|
|
137
213
|
}
|
|
138
214
|
return result;
|
|
139
215
|
}
|
|
140
|
-
|
|
141
|
-
if (this.options.clause) {
|
|
142
|
-
let optionClause;
|
|
143
|
-
if (typeof this.options.clause === "function") {
|
|
144
|
-
optionClause = this.options.clause();
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
optionClause = this.options.clause;
|
|
148
|
-
}
|
|
149
|
-
if (optionClause) {
|
|
150
|
-
cls = clause.And(cls, optionClause);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
216
|
+
const cls = (0, clause_1.getCombinedClause)(this.options, clause.Eq(this.options.key, key));
|
|
153
217
|
const rowOptions = {
|
|
154
218
|
...this.options,
|
|
155
219
|
clause: cls,
|
|
@@ -157,21 +221,50 @@ class ObjectLoader {
|
|
|
157
221
|
};
|
|
158
222
|
return (0, ent_1.loadRow)(rowOptions);
|
|
159
223
|
}
|
|
224
|
+
async loadClause(key) {
|
|
225
|
+
if (this.clauseLoader) {
|
|
226
|
+
return this.clauseLoader.load(key);
|
|
227
|
+
}
|
|
228
|
+
return loadRowsForClauseLoader(this.options, key);
|
|
229
|
+
}
|
|
160
230
|
clearAll() {
|
|
161
|
-
this.
|
|
231
|
+
this.idLoader && this.idLoader.clearAll();
|
|
232
|
+
this.clauseLoader && this.clauseLoader.clearAll();
|
|
162
233
|
}
|
|
163
234
|
async loadMany(keys) {
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
235
|
+
if (!keys.length) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
if (typeof keys[0] === "string" || typeof keys[0] === "number") {
|
|
239
|
+
return this.loadIDMany(keys);
|
|
240
|
+
}
|
|
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);
|
|
166
259
|
}
|
|
167
|
-
return
|
|
260
|
+
return res;
|
|
168
261
|
}
|
|
169
262
|
prime(data) {
|
|
170
263
|
// we have this data from somewhere else, prime it in the c
|
|
171
|
-
if (this.
|
|
264
|
+
if (this.idLoader) {
|
|
172
265
|
const col = this.options.key;
|
|
173
266
|
const key = data[col];
|
|
174
|
-
this.
|
|
267
|
+
this.idLoader.prime(key, data);
|
|
175
268
|
}
|
|
176
269
|
}
|
|
177
270
|
// prime this loader and any other loaders it's aware of
|
|
@@ -188,6 +281,43 @@ class ObjectLoader {
|
|
|
188
281
|
}
|
|
189
282
|
}
|
|
190
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;
|
|
191
321
|
// NOTE: if not querying for all columns
|
|
192
322
|
// have to query for the id field as one of the fields
|
|
193
323
|
// because it's used to maintain sort order of the queried ids
|
|
@@ -211,6 +341,15 @@ class ObjectLoaderFactory {
|
|
|
211
341
|
return new ObjectLoader(this.options, context, this.toPrime);
|
|
212
342
|
}, context);
|
|
213
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
|
+
}
|
|
214
353
|
// keep track of loaders to prime. needs to be done not in the constructor
|
|
215
354
|
// because there's usually self references here
|
|
216
355
|
addToPrime(factory) {
|
|
@@ -1,14 +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
|
-
|
|
4
|
+
import { OrderBy } from "../query_impl";
|
|
5
5
|
declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
|
|
6
6
|
private options;
|
|
7
7
|
private queryOptions?;
|
|
8
8
|
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
9
9
|
private memoizedInitPrime;
|
|
10
10
|
private primedLoaders;
|
|
11
|
-
constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "
|
|
11
|
+
constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "clause" | "limit" | "orderby" | "disableTransformations">> | undefined, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
12
12
|
private initPrime;
|
|
13
13
|
load(id: K): Promise<Data[]>;
|
|
14
14
|
clearAll(): void;
|
|
@@ -18,8 +18,8 @@ interface QueryOptions {
|
|
|
18
18
|
tableName: string;
|
|
19
19
|
groupCol?: string;
|
|
20
20
|
clause?: clause.Clause;
|
|
21
|
-
|
|
22
|
-
toPrime?: ObjectLoaderFactory<
|
|
21
|
+
orderby?: OrderBy;
|
|
22
|
+
toPrime?: ObjectLoaderFactory<Data>[];
|
|
23
23
|
}
|
|
24
24
|
export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<K, Data[]> {
|
|
25
25
|
private options;
|
|
@@ -26,25 +26,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.QueryLoaderFactory =
|
|
29
|
+
exports.QueryLoaderFactory = void 0;
|
|
30
30
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
31
31
|
const ent_1 = require("../ent");
|
|
32
32
|
const clause = __importStar(require("../clause"));
|
|
33
33
|
const logger_1 = require("../logger");
|
|
34
34
|
const loader_1 = require("./loader");
|
|
35
35
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
return `${sortCol}${orderbyDirection}`;
|
|
36
|
+
function getOrderByLocal(options, queryOptions) {
|
|
37
|
+
return (options.orderby ??
|
|
38
|
+
queryOptions?.orderby ?? [
|
|
39
|
+
{
|
|
40
|
+
column: "created_at",
|
|
41
|
+
direction: "DESC",
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
46
44
|
}
|
|
47
|
-
exports.getOrderBy = getOrderBy;
|
|
48
45
|
async function simpleCase(options, id, queryOptions) {
|
|
49
46
|
let cls;
|
|
50
47
|
if (options.groupCol) {
|
|
@@ -62,20 +59,18 @@ async function simpleCase(options, id, queryOptions) {
|
|
|
62
59
|
if (queryOptions?.clause) {
|
|
63
60
|
cls = clause.And(cls, queryOptions.clause);
|
|
64
61
|
}
|
|
65
|
-
let sortCol = options.sortColumn || "created_at";
|
|
66
62
|
return await (0, ent_1.loadRows)({
|
|
67
63
|
...options,
|
|
68
64
|
clause: cls,
|
|
69
|
-
orderby:
|
|
70
|
-
limit: queryOptions?.limit || ent_1.
|
|
65
|
+
orderby: getOrderByLocal(options, queryOptions),
|
|
66
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
71
67
|
});
|
|
72
68
|
}
|
|
73
69
|
function createLoader(options, queryOptions) {
|
|
74
|
-
let sortCol = options.sortColumn || "created_at";
|
|
75
70
|
const loaderOptions = {};
|
|
76
71
|
// if query logging is enabled, we should log what's happening with loader
|
|
77
72
|
if ((0, logger_1.logEnabled)("query")) {
|
|
78
|
-
loaderOptions.cacheMap = new loader_1.
|
|
73
|
+
loaderOptions.cacheMap = new loader_1.CacheMap(options);
|
|
79
74
|
}
|
|
80
75
|
return new dataloader_1.default(async (keys) => {
|
|
81
76
|
if (!keys.length) {
|
|
@@ -109,8 +104,8 @@ function createLoader(options, queryOptions) {
|
|
|
109
104
|
tableName: options.tableName,
|
|
110
105
|
fields: options.fields,
|
|
111
106
|
values: keys,
|
|
112
|
-
orderby:
|
|
113
|
-
limit: queryOptions?.limit || ent_1.
|
|
107
|
+
orderby: getOrderByLocal(options, queryOptions),
|
|
108
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
114
109
|
groupColumn: col,
|
|
115
110
|
clause: extraClause,
|
|
116
111
|
});
|
|
@@ -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>;
|
|
@@ -59,7 +59,7 @@ function createCountDataLoader(options) {
|
|
|
59
59
|
const loaderOptions = {};
|
|
60
60
|
// if query logging is enabled, we should log what's happening with loader
|
|
61
61
|
if ((0, logger_1.logEnabled)("query")) {
|
|
62
|
-
loaderOptions.cacheMap = new loader_1.
|
|
62
|
+
loaderOptions.cacheMap = new loader_1.CacheMap(options);
|
|
63
63
|
}
|
|
64
64
|
return new dataloader_1.default(async (keys) => {
|
|
65
65
|
if (!keys.length) {
|
|
@@ -69,7 +69,8 @@ function createCountDataLoader(options) {
|
|
|
69
69
|
if (keys.length == 1 || !options.groupCol) {
|
|
70
70
|
return simpleCase(options, keys[0]);
|
|
71
71
|
}
|
|
72
|
-
let
|
|
72
|
+
let typ = options.groupColType || "uuid";
|
|
73
|
+
let cls = clause.DBTypeIn(options.groupCol, keys, typ);
|
|
73
74
|
if (options.clause) {
|
|
74
75
|
cls = clause.And(cls, options.clause);
|
|
75
76
|
}
|
package/core/privacy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ent, ID, LoadEntOptions, PrivacyError, PrivacyPolicy, PrivacyPolicyRule, PrivacyResult, Viewer } from "./base";
|
|
1
|
+
import { Ent, ID, LoadEntOptions, PrivacyError, PrivacyPolicy, PrivacyPolicyRule, PrivacyResult, Viewer, EdgeQueryableDataOptionsConfigureLoader } from "./base";
|
|
2
2
|
export declare class EntPrivacyError extends Error implements PrivacyError {
|
|
3
3
|
privacyPolicy: PrivacyPolicy;
|
|
4
4
|
privacyRule: PrivacyPolicyRule;
|
|
@@ -115,51 +115,60 @@ export declare class AllowIfEdgeExistsRule implements PrivacyPolicyRule {
|
|
|
115
115
|
private id1;
|
|
116
116
|
private id2;
|
|
117
117
|
private edgeType;
|
|
118
|
-
|
|
118
|
+
private options?;
|
|
119
|
+
constructor(id1: ID, id2: ID, edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
119
120
|
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
120
121
|
}
|
|
121
122
|
export declare class AllowIfViewerInboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
122
123
|
private edgeType;
|
|
123
|
-
|
|
124
|
+
private options?;
|
|
125
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
124
126
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
125
127
|
}
|
|
126
128
|
export declare class AllowIfViewerOutboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
127
129
|
private edgeType;
|
|
128
|
-
|
|
130
|
+
private options?;
|
|
131
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
129
132
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
130
133
|
}
|
|
131
134
|
export declare class DenyIfEdgeExistsRule implements PrivacyPolicyRule {
|
|
132
135
|
private id1;
|
|
133
136
|
private id2;
|
|
134
137
|
private edgeType;
|
|
135
|
-
|
|
138
|
+
private options?;
|
|
139
|
+
constructor(id1: ID, id2: ID, edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
136
140
|
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
137
141
|
}
|
|
138
142
|
export declare class DenyIfViewerInboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
139
143
|
private edgeType;
|
|
140
|
-
|
|
144
|
+
private options?;
|
|
145
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
141
146
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
142
147
|
}
|
|
143
148
|
export declare class DenyIfViewerOutboundEdgeExistsRule implements PrivacyPolicyRule {
|
|
144
149
|
private edgeType;
|
|
145
|
-
|
|
150
|
+
private options?;
|
|
151
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
146
152
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
147
153
|
}
|
|
148
154
|
export declare class DenyIfEdgeDoesNotExistRule implements PrivacyPolicyRule {
|
|
149
155
|
private id1;
|
|
150
156
|
private id2;
|
|
151
157
|
private edgeType;
|
|
152
|
-
|
|
158
|
+
private options?;
|
|
159
|
+
constructor(id1: ID, id2: ID, edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
153
160
|
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
154
161
|
}
|
|
155
162
|
export declare class DenyIfViewerInboundEdgeDoesNotExistRule implements PrivacyPolicyRule {
|
|
156
163
|
private edgeType;
|
|
157
|
-
|
|
164
|
+
private options?;
|
|
165
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
158
166
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
159
167
|
}
|
|
160
168
|
export declare class DenyIfViewerOutboundEdgeDoesNotExistRule implements PrivacyPolicyRule {
|
|
161
169
|
private edgeType;
|
|
162
|
-
|
|
170
|
+
private options?;
|
|
171
|
+
constructor(edgeType: string, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
163
172
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
164
173
|
}
|
|
165
174
|
export declare class AllowIfConditionAppliesRule implements PrivacyPolicyRule {
|