@snowtop/ent 0.2.4 → 0.2.6
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.js +5 -5
- package/action/executor.d.ts +1 -1
- package/action/executor.js +4 -4
- package/action/experimental_action.d.ts +7 -4
- package/action/experimental_action.js +18 -8
- package/action/operations.js +17 -7
- package/action/orchestrator.d.ts +10 -2
- package/action/orchestrator.js +29 -31
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.js +3 -3
- package/auth/auth.d.ts +0 -1
- package/auth/auth.js +4 -5
- package/core/base.js +5 -5
- package/core/clause.js +76 -67
- package/core/config.d.ts +1 -1
- package/core/config.js +22 -9
- package/core/context.d.ts +0 -1
- package/core/convert.d.ts +0 -1
- package/core/convert.js +16 -17
- package/core/date.js +1 -2
- package/core/db.js +17 -7
- package/core/ent.d.ts +2 -0
- package/core/ent.js +127 -92
- package/core/global_schema.js +6 -7
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +17 -7
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +44 -20
- package/core/loaders/cache_utils.d.ts +1 -0
- package/core/loaders/cache_utils.js +28 -0
- package/core/loaders/index.d.ts +1 -0
- package/core/loaders/index.js +4 -1
- package/core/loaders/loader.d.ts +2 -0
- package/core/loaders/loader.js +20 -3
- package/core/loaders/object_loader.d.ts +6 -4
- package/core/loaders/object_loader.js +86 -48
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/query_loader.js +25 -9
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +22 -10
- package/core/logger.js +6 -7
- package/core/privacy.d.ts +2 -2
- package/core/privacy.js +4 -5
- package/core/query/assoc_query.js +17 -7
- package/core/query/query.js +17 -7
- package/core/query/shared_assoc_test.js +1 -2
- package/core/query_impl.js +4 -5
- package/core/viewer.d.ts +2 -2
- package/graphql/graphql_field_helpers.js +22 -22
- package/graphql/mutations/union.js +1 -2
- package/graphql/node_resolver.js +7 -7
- package/graphql/query/shared_assoc_test.js +1 -2
- package/graphql/scalars/date.js +8 -3
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/dataz/example1/_auth.js +14 -10
- package/imports/index.js +18 -9
- package/index.js +17 -7
- package/names/names.js +61 -18
- package/package.json +14 -17
- package/parse_schema/parse.js +2 -3
- package/schema/binary_field.js +3 -3
- package/schema/field.js +45 -35
- package/schema/json_field.js +7 -7
- package/schema/schema.js +12 -12
- package/schema/struct_field.js +4 -4
- package/schema/union_field.js +3 -3
- package/scripts/custom_compiler.js +17 -7
- package/scripts/custom_graphql.js +17 -7
- package/scripts/fix_action_exports.js +17 -7
- package/scripts/move_types.js +17 -7
- package/scripts/read_schema.js +17 -7
- package/testutils/action/complex_schemas.js +28 -18
- package/testutils/builder.d.ts +1 -1
- package/testutils/builder.js +7 -7
- package/testutils/db/fixture.js +1 -2
- package/testutils/db/temp_db.js +54 -44
- package/testutils/db/value.js +3 -4
- package/testutils/db_mock.js +12 -0
- package/testutils/ent-graphql-tests/index.d.ts +3 -3
- package/testutils/ent-graphql-tests/index.js +27 -18
- package/testutils/fake_data/const.js +2 -2
- package/testutils/fake_data/fake_contact.js +20 -10
- package/testutils/fake_data/fake_event.js +20 -10
- package/testutils/fake_data/fake_tag.js +21 -11
- package/testutils/fake_data/fake_user.js +21 -11
- package/testutils/fake_data/test_helpers.js +17 -17
- package/testutils/fake_data/user_query.js +19 -9
- package/testutils/parse_sql.js +151 -43
- package/testutils/query.js +2 -3
- package/testutils/soft_delete.js +17 -7
- package/testutils/test_edge_global_schema.js +17 -7
- package/testutils/write.js +20 -11
- package/tsc/ast.js +27 -18
- package/tsc/compilerOptions.js +22 -13
- package/tsc/move_generated.js +18 -9
- package/tsc/transform.js +18 -9
- package/tsc/transform_action.js +17 -7
- package/tsc/transform_schema.js +17 -7
package/core/db.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.PostgresClient = exports.Postgres = exports.Sqlite = exports.defaultTimestampParser = exports.Dialect = void 0;
|
|
27
37
|
const fs = __importStar(require("fs"));
|
package/core/ent.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ declare class ErrorWrapper {
|
|
|
19
19
|
constructor(error: Error);
|
|
20
20
|
}
|
|
21
21
|
export declare function rowIsError(row: any): row is Error;
|
|
22
|
+
export declare function setEntLoaderPrivacyConcurrencyLimit(limit: number): void;
|
|
23
|
+
export declare function getEntLoaderPrivacyConcurrencyLimit(): number;
|
|
22
24
|
declare class EntLoader<TViewer extends Viewer, TEnt extends Ent<TViewer>> implements LoaderWithLoadMany<ID, TEnt | ErrorWrapper | Error> {
|
|
23
25
|
private viewer;
|
|
24
26
|
private options;
|
package/core/ent.js
CHANGED
|
@@ -15,19 +15,79 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
39
|
+
exports.assocEdgeLoader = exports.AssocEdgeData = exports.AssocEdge = void 0;
|
|
40
|
+
exports.rowIsError = rowIsError;
|
|
41
|
+
exports.setEntLoaderPrivacyConcurrencyLimit = setEntLoaderPrivacyConcurrencyLimit;
|
|
42
|
+
exports.getEntLoaderPrivacyConcurrencyLimit = getEntLoaderPrivacyConcurrencyLimit;
|
|
43
|
+
exports.getEntLoader = getEntLoader;
|
|
44
|
+
exports.getEntKey = getEntKey;
|
|
45
|
+
exports.loadEnt = loadEnt;
|
|
46
|
+
exports.loadEntViaKey = loadEntViaKey;
|
|
47
|
+
exports.loadEntX = loadEntX;
|
|
48
|
+
exports.loadEntXViaKey = loadEntXViaKey;
|
|
49
|
+
exports.loadEntFromClause = loadEntFromClause;
|
|
50
|
+
exports.loadEntXFromClause = loadEntXFromClause;
|
|
51
|
+
exports.loadEnts = loadEnts;
|
|
52
|
+
exports.loadEntsList = loadEntsList;
|
|
53
|
+
exports.loadEntsFromClause = loadEntsFromClause;
|
|
54
|
+
exports.loadCustomEnts = loadCustomEnts;
|
|
55
|
+
exports.loadCustomData = loadCustomData;
|
|
56
|
+
exports.loadCustomCount = loadCustomCount;
|
|
57
|
+
exports.loadDerivedEnt = loadDerivedEnt;
|
|
58
|
+
exports.loadDerivedEntX = loadDerivedEntX;
|
|
59
|
+
exports.logQuery = logQuery;
|
|
60
|
+
exports.loadRowX = loadRowX;
|
|
61
|
+
exports.loadRow = loadRow;
|
|
62
|
+
exports.___setLogQueryErrorWithError = ___setLogQueryErrorWithError;
|
|
63
|
+
exports.performRawQuery = performRawQuery;
|
|
64
|
+
exports.loadRows = loadRows;
|
|
65
|
+
exports.buildGroupQuery = buildGroupQuery;
|
|
66
|
+
exports.buildInsertQuery = buildInsertQuery;
|
|
67
|
+
exports.createRow = createRow;
|
|
68
|
+
exports.createRowSync = createRowSync;
|
|
69
|
+
exports.buildUpdateQuery = buildUpdateQuery;
|
|
70
|
+
exports.editRow = editRow;
|
|
71
|
+
exports.editRowSync = editRowSync;
|
|
72
|
+
exports.deleteRows = deleteRows;
|
|
73
|
+
exports.deleteRowsSync = deleteRowsSync;
|
|
74
|
+
exports.getCursor = getCursor;
|
|
75
|
+
exports.loadEdgeData = loadEdgeData;
|
|
76
|
+
exports.loadEdgeDatas = loadEdgeDatas;
|
|
77
|
+
exports.setDefaultLimit = setDefaultLimit;
|
|
78
|
+
exports.getDefaultLimit = getDefaultLimit;
|
|
79
|
+
exports.loadEdges = loadEdges;
|
|
80
|
+
exports.getEdgeClauseAndFields = getEdgeClauseAndFields;
|
|
81
|
+
exports.loadCustomEdges = loadCustomEdges;
|
|
82
|
+
exports.loadUniqueEdge = loadUniqueEdge;
|
|
83
|
+
exports.loadUniqueNode = loadUniqueNode;
|
|
84
|
+
exports.loadRawEdgeCountX = loadRawEdgeCountX;
|
|
85
|
+
exports.loadEdgeForID2 = loadEdgeForID2;
|
|
86
|
+
exports.loadTwoWayEdges = loadTwoWayEdges;
|
|
87
|
+
exports.loadNodesByEdge = loadNodesByEdge;
|
|
88
|
+
exports.applyPrivacyPolicyForRow = applyPrivacyPolicyForRow;
|
|
89
|
+
exports.applyPrivacyPolicyForRows = applyPrivacyPolicyForRows;
|
|
90
|
+
exports.getEdgeTypeInGroup = getEdgeTypeInGroup;
|
|
31
91
|
const db_1 = __importStar(require("./db"));
|
|
32
92
|
const privacy_1 = require("./privacy");
|
|
33
93
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
@@ -65,7 +125,9 @@ class entCacheMap {
|
|
|
65
125
|
}
|
|
66
126
|
}
|
|
67
127
|
function createAssocEdgeConfigLoader(options) {
|
|
68
|
-
const loaderOptions = {
|
|
128
|
+
const loaderOptions = {
|
|
129
|
+
maxBatchSize: (0, loader_1.getLoaderMaxBatchSize)(),
|
|
130
|
+
};
|
|
69
131
|
// if query logging is enabled, we should log what's happening with loader
|
|
70
132
|
if ((0, logger_1.logEnabled)("query")) {
|
|
71
133
|
loaderOptions.cacheMap = new loader_1.CacheMap(options);
|
|
@@ -85,15 +147,14 @@ function createAssocEdgeConfigLoader(options) {
|
|
|
85
147
|
// TODO is there a better way of doing this?
|
|
86
148
|
// context not needed because we're creating a loader which has its own cache which is being used here
|
|
87
149
|
const nodes = await loadRows(rowOptions);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
150
|
+
const rowMap = new Map();
|
|
151
|
+
for (const node of nodes) {
|
|
152
|
+
const key = node[col];
|
|
153
|
+
if (!rowMap.has(key)) {
|
|
154
|
+
rowMap.set(key, node);
|
|
93
155
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return result;
|
|
156
|
+
}
|
|
157
|
+
return ids.map((id) => rowMap.get(id) ?? null);
|
|
97
158
|
}, loaderOptions);
|
|
98
159
|
}
|
|
99
160
|
// used to wrap errors that would eventually be thrown in ents
|
|
@@ -109,53 +170,75 @@ function rowIsError(row) {
|
|
|
109
170
|
// so we need to check the name as well for native error SqliteError
|
|
110
171
|
return row instanceof Error || row?.constructor?.name === "SqliteError";
|
|
111
172
|
}
|
|
112
|
-
|
|
173
|
+
let entLoaderPrivacyConcurrencyLimit = 20;
|
|
174
|
+
function setEntLoaderPrivacyConcurrencyLimit(limit) {
|
|
175
|
+
entLoaderPrivacyConcurrencyLimit = limit;
|
|
176
|
+
}
|
|
177
|
+
function getEntLoaderPrivacyConcurrencyLimit() {
|
|
178
|
+
return entLoaderPrivacyConcurrencyLimit;
|
|
179
|
+
}
|
|
180
|
+
async function mapWithConcurrency(items, limit, mapper) {
|
|
181
|
+
if (!items.length) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
const results = new Array(items.length);
|
|
185
|
+
const concurrency = limit === Infinity
|
|
186
|
+
? items.length
|
|
187
|
+
: Number.isFinite(limit) && limit > 0
|
|
188
|
+
? Math.floor(limit)
|
|
189
|
+
: 1;
|
|
190
|
+
let nextIndex = 0;
|
|
191
|
+
const workers = new Array(Math.min(concurrency, items.length))
|
|
192
|
+
.fill(null)
|
|
193
|
+
.map(async () => {
|
|
194
|
+
while (true) {
|
|
195
|
+
const currentIndex = nextIndex;
|
|
196
|
+
if (currentIndex >= items.length) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
nextIndex += 1;
|
|
200
|
+
results[currentIndex] = await mapper(items[currentIndex], currentIndex);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
await Promise.all(workers);
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
113
206
|
function createEntLoader(viewer, options, map) {
|
|
114
207
|
// share the cache across loaders even if we create a new instance
|
|
115
|
-
const loaderOptions = {
|
|
208
|
+
const loaderOptions = {
|
|
209
|
+
maxBatchSize: (0, loader_1.getLoaderMaxBatchSize)(),
|
|
210
|
+
};
|
|
116
211
|
loaderOptions.cacheMap = map;
|
|
117
212
|
return new dataloader_1.default(async (ids) => {
|
|
118
213
|
if (!ids.length) {
|
|
119
214
|
return [];
|
|
120
215
|
}
|
|
121
|
-
let result = [];
|
|
122
216
|
const tableName = options.loaderFactory.options?.tableName;
|
|
123
217
|
const loader = options.loaderFactory.createLoader(viewer.context);
|
|
124
218
|
const rows = await loader.loadMany(ids);
|
|
125
219
|
// this is a loader which should return the same order based on passed-in ids
|
|
126
220
|
// so let's depend on that...
|
|
127
|
-
|
|
128
|
-
const row = rows[idx];
|
|
221
|
+
return mapWithConcurrency(rows, getEntLoaderPrivacyConcurrencyLimit(), async (row, idx) => {
|
|
129
222
|
// db error
|
|
130
223
|
if (rowIsError(row)) {
|
|
131
224
|
if (row instanceof Error) {
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
// @ts-ignore SqliteError
|
|
136
|
-
result[idx] = new Error(row.message);
|
|
225
|
+
return row;
|
|
137
226
|
}
|
|
138
|
-
|
|
227
|
+
// @ts-ignore SqliteError
|
|
228
|
+
return new Error(row.message);
|
|
139
229
|
}
|
|
140
|
-
|
|
230
|
+
if (!row) {
|
|
141
231
|
if (tableName) {
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
result[idx] = new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]}`));
|
|
232
|
+
return new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]} in table ${tableName}`));
|
|
146
233
|
}
|
|
234
|
+
return new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]}`));
|
|
147
235
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
result[idx] = new ErrorWrapper(r);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
result[idx] = r;
|
|
155
|
-
}
|
|
236
|
+
const r = await applyPrivacyPolicyForRowImpl(viewer, options, row);
|
|
237
|
+
if (rowIsError(r)) {
|
|
238
|
+
return new ErrorWrapper(r);
|
|
156
239
|
}
|
|
157
|
-
|
|
158
|
-
|
|
240
|
+
return r;
|
|
241
|
+
});
|
|
159
242
|
}, loaderOptions);
|
|
160
243
|
}
|
|
161
244
|
class EntLoader {
|
|
@@ -191,11 +274,9 @@ function getEntLoader(viewer, options) {
|
|
|
191
274
|
const name = `ent-loader:${viewer.instanceKey()}:${options.loaderFactory.name}`;
|
|
192
275
|
return viewer.context.cache.getLoaderWithLoadMany(name, () => new EntLoader(viewer, options));
|
|
193
276
|
}
|
|
194
|
-
exports.getEntLoader = getEntLoader;
|
|
195
277
|
function getEntKey(viewer, id, options) {
|
|
196
278
|
return `${viewer.instanceKey()}:${options.loaderFactory.name}:${id}`;
|
|
197
279
|
}
|
|
198
|
-
exports.getEntKey = getEntKey;
|
|
199
280
|
async function loadEnt(viewer, id, options) {
|
|
200
281
|
if (typeof id !== "string" &&
|
|
201
282
|
typeof id !== "number" &&
|
|
@@ -205,7 +286,6 @@ async function loadEnt(viewer, id, options) {
|
|
|
205
286
|
const r = await getEntLoader(viewer, options).load(id);
|
|
206
287
|
return r instanceof ErrorWrapper ? null : r;
|
|
207
288
|
}
|
|
208
|
-
exports.loadEnt = loadEnt;
|
|
209
289
|
async function applyPrivacyPolicyForRowAndStoreInEntLoader(viewer, row, options,
|
|
210
290
|
// can pass in loader when calling this for multi-id cases...
|
|
211
291
|
loader) {
|
|
@@ -243,7 +323,6 @@ async function loadEntViaKey(viewer, key, options) {
|
|
|
243
323
|
const r = await applyPrivacyPolicyForRowAndStoreInEntLoader(viewer, row, options);
|
|
244
324
|
return r instanceof ErrorWrapper ? null : r;
|
|
245
325
|
}
|
|
246
|
-
exports.loadEntViaKey = loadEntViaKey;
|
|
247
326
|
async function loadEntX(viewer, id, options) {
|
|
248
327
|
if (typeof id !== "string" &&
|
|
249
328
|
typeof id !== "number" &&
|
|
@@ -256,7 +335,6 @@ async function loadEntX(viewer, id, options) {
|
|
|
256
335
|
}
|
|
257
336
|
return r;
|
|
258
337
|
}
|
|
259
|
-
exports.loadEntX = loadEntX;
|
|
260
338
|
async function loadEntXViaKey(viewer, key, options) {
|
|
261
339
|
const row = await options.loaderFactory
|
|
262
340
|
.createLoader(viewer.context)
|
|
@@ -271,7 +349,6 @@ async function loadEntXViaKey(viewer, key, options) {
|
|
|
271
349
|
}
|
|
272
350
|
return r;
|
|
273
351
|
}
|
|
274
|
-
exports.loadEntXViaKey = loadEntXViaKey;
|
|
275
352
|
/**
|
|
276
353
|
* @deprecated use loadCustomEnts
|
|
277
354
|
*/
|
|
@@ -287,7 +364,6 @@ async function loadEntFromClause(viewer, options, clause) {
|
|
|
287
364
|
}
|
|
288
365
|
return applyPrivacyPolicyForRow(viewer, options, row);
|
|
289
366
|
}
|
|
290
|
-
exports.loadEntFromClause = loadEntFromClause;
|
|
291
367
|
// same as loadEntFromClause
|
|
292
368
|
// only works for ents where primary key is "id"
|
|
293
369
|
// use loadEnt with a loaderFactory if different
|
|
@@ -303,7 +379,6 @@ async function loadEntXFromClause(viewer, options, clause) {
|
|
|
303
379
|
const row = await loadRowX(rowOptions);
|
|
304
380
|
return applyPrivacyPolicyForRowX(viewer, options, row);
|
|
305
381
|
}
|
|
306
|
-
exports.loadEntXFromClause = loadEntXFromClause;
|
|
307
382
|
async function loadEnts(viewer, options, ...ids) {
|
|
308
383
|
if (!ids.length) {
|
|
309
384
|
return new Map();
|
|
@@ -322,7 +397,6 @@ async function loadEnts(viewer, options, ...ids) {
|
|
|
322
397
|
}
|
|
323
398
|
return m;
|
|
324
399
|
}
|
|
325
|
-
exports.loadEnts = loadEnts;
|
|
326
400
|
// calls loadEnts and returns the results sorted in the order they were passed in
|
|
327
401
|
// useful for EntQuery and other paths where the order matters
|
|
328
402
|
async function loadEntsList(viewer, options, ...ids) {
|
|
@@ -336,7 +410,6 @@ async function loadEntsList(viewer, options, ...ids) {
|
|
|
336
410
|
});
|
|
337
411
|
return result;
|
|
338
412
|
}
|
|
339
|
-
exports.loadEntsList = loadEntsList;
|
|
340
413
|
// we return a map here so that any sorting for queries that exist
|
|
341
414
|
// can be done in O(N) time
|
|
342
415
|
/**
|
|
@@ -351,12 +424,10 @@ async function loadEntsFromClause(viewer, clause, options) {
|
|
|
351
424
|
const rows = await loadRows(rowOptions);
|
|
352
425
|
return applyPrivacyPolicyForRowsDeprecated(viewer, rows, options);
|
|
353
426
|
}
|
|
354
|
-
exports.loadEntsFromClause = loadEntsFromClause;
|
|
355
427
|
async function loadCustomEnts(viewer, options, query) {
|
|
356
428
|
const rows = await loadCustomData(options, query, viewer.context);
|
|
357
429
|
return applyPrivacyPolicyForRows(viewer, rows, options);
|
|
358
430
|
}
|
|
359
|
-
exports.loadCustomEnts = loadCustomEnts;
|
|
360
431
|
function isClause(opts) {
|
|
361
432
|
const cls = opts;
|
|
362
433
|
return cls.clause !== undefined && cls.values !== undefined;
|
|
@@ -410,7 +481,6 @@ async function loadCustomData(options, query, context) {
|
|
|
410
481
|
}
|
|
411
482
|
return rows;
|
|
412
483
|
}
|
|
413
|
-
exports.loadCustomData = loadCustomData;
|
|
414
484
|
// NOTE: if you use a raw query or paramterized query with this,
|
|
415
485
|
// you should use `SELECT count(*) as count...`
|
|
416
486
|
async function loadCustomCount(options, query, context) {
|
|
@@ -428,7 +498,6 @@ async function loadCustomCount(options, query, context) {
|
|
|
428
498
|
}
|
|
429
499
|
return 0;
|
|
430
500
|
}
|
|
431
|
-
exports.loadCustomCount = loadCustomCount;
|
|
432
501
|
function isPrimableLoader(loader) {
|
|
433
502
|
return loader != undefined;
|
|
434
503
|
}
|
|
@@ -484,13 +553,11 @@ async function loadDerivedEnt(viewer, data, loader) {
|
|
|
484
553
|
}
|
|
485
554
|
return r;
|
|
486
555
|
}
|
|
487
|
-
exports.loadDerivedEnt = loadDerivedEnt;
|
|
488
556
|
// won't have caching yet either
|
|
489
557
|
async function loadDerivedEntX(viewer, data, loader) {
|
|
490
558
|
const ent = new loader(viewer, data);
|
|
491
559
|
return applyPrivacyPolicyForEntX(viewer, ent, data, { ent: loader });
|
|
492
560
|
}
|
|
493
|
-
exports.loadDerivedEntX = loadDerivedEntX;
|
|
494
561
|
// everything calls into this two so should be fine
|
|
495
562
|
// TODO is there a smarter way to not instantiate two objects here?
|
|
496
563
|
async function applyPrivacyPolicyForEnt(viewer, ent, data, fieldPrivacyOptions) {
|
|
@@ -551,7 +618,6 @@ function logQuery(query, logValues) {
|
|
|
551
618
|
});
|
|
552
619
|
(0, logger_1.logTrace)();
|
|
553
620
|
}
|
|
554
|
-
exports.logQuery = logQuery;
|
|
555
621
|
// TODO long term figure out if this API should be exposed
|
|
556
622
|
async function loadRowX(options) {
|
|
557
623
|
const result = await loadRow(options);
|
|
@@ -562,7 +628,6 @@ async function loadRowX(options) {
|
|
|
562
628
|
}
|
|
563
629
|
return result;
|
|
564
630
|
}
|
|
565
|
-
exports.loadRowX = loadRowX;
|
|
566
631
|
// primitive data fetching. called by loaders
|
|
567
632
|
async function loadRow(options) {
|
|
568
633
|
let cache = options.context?.cache;
|
|
@@ -588,12 +653,10 @@ async function loadRow(options) {
|
|
|
588
653
|
}
|
|
589
654
|
return res.rows[0];
|
|
590
655
|
}
|
|
591
|
-
exports.loadRow = loadRow;
|
|
592
656
|
var _logQueryWithError = false;
|
|
593
657
|
function ___setLogQueryErrorWithError(val) {
|
|
594
658
|
_logQueryWithError = val || false;
|
|
595
659
|
}
|
|
596
|
-
exports.___setLogQueryErrorWithError = ___setLogQueryErrorWithError;
|
|
597
660
|
// this always goes to the db, no cache, nothing
|
|
598
661
|
async function performRawQuery(query, values, logValues) {
|
|
599
662
|
const pool = db_1.default.getInstance().getPool();
|
|
@@ -610,7 +673,6 @@ async function performRawQuery(query, values, logValues) {
|
|
|
610
673
|
throw e;
|
|
611
674
|
}
|
|
612
675
|
}
|
|
613
|
-
exports.performRawQuery = performRawQuery;
|
|
614
676
|
// TODO this should throw, we can't be hiding errors here
|
|
615
677
|
async function loadRows(options) {
|
|
616
678
|
let cache = options.context?.cache;
|
|
@@ -628,7 +690,6 @@ async function loadRows(options) {
|
|
|
628
690
|
}
|
|
629
691
|
return r;
|
|
630
692
|
}
|
|
631
|
-
exports.loadRows = loadRows;
|
|
632
693
|
// this is used for queries when we select multiple ids at once
|
|
633
694
|
function buildGroupQuery(options) {
|
|
634
695
|
const fields = [...options.fields, "row_number()"];
|
|
@@ -658,7 +719,6 @@ function buildGroupQuery(options) {
|
|
|
658
719
|
cls,
|
|
659
720
|
];
|
|
660
721
|
}
|
|
661
|
-
exports.buildGroupQuery = buildGroupQuery;
|
|
662
722
|
function isSyncQueryer(queryer) {
|
|
663
723
|
return queryer.execSync !== undefined;
|
|
664
724
|
}
|
|
@@ -751,7 +811,6 @@ function buildInsertQuery(options, suffix) {
|
|
|
751
811
|
}
|
|
752
812
|
return [query, values, logValues];
|
|
753
813
|
}
|
|
754
|
-
exports.buildInsertQuery = buildInsertQuery;
|
|
755
814
|
// TODO: these three are not to be exported out of this package
|
|
756
815
|
// only from this file
|
|
757
816
|
async function createRow(queryer, options, suffix) {
|
|
@@ -762,7 +821,6 @@ async function createRow(queryer, options, suffix) {
|
|
|
762
821
|
}
|
|
763
822
|
return null;
|
|
764
823
|
}
|
|
765
|
-
exports.createRow = createRow;
|
|
766
824
|
function createRowSync(queryer, options, suffix) {
|
|
767
825
|
const [query, values, logValues] = buildInsertQuery(options, suffix);
|
|
768
826
|
const res = mutateRowSync(queryer, query, values, logValues, options);
|
|
@@ -771,7 +829,6 @@ function createRowSync(queryer, options, suffix) {
|
|
|
771
829
|
}
|
|
772
830
|
return null;
|
|
773
831
|
}
|
|
774
|
-
exports.createRowSync = createRowSync;
|
|
775
832
|
function buildUpdateQuery(options, suffix) {
|
|
776
833
|
let valsString = [];
|
|
777
834
|
let values = [];
|
|
@@ -819,7 +876,6 @@ function buildUpdateQuery(options, suffix) {
|
|
|
819
876
|
}
|
|
820
877
|
return [query, values, logValues];
|
|
821
878
|
}
|
|
822
|
-
exports.buildUpdateQuery = buildUpdateQuery;
|
|
823
879
|
async function editRow(queryer, options, suffix) {
|
|
824
880
|
const [query, values, logValues] = buildUpdateQuery(options, suffix);
|
|
825
881
|
const res = await mutateRow(queryer, query, values, logValues, options);
|
|
@@ -831,7 +887,6 @@ async function editRow(queryer, options, suffix) {
|
|
|
831
887
|
}
|
|
832
888
|
return null;
|
|
833
889
|
}
|
|
834
|
-
exports.editRow = editRow;
|
|
835
890
|
function editRowSync(queryer, options, suffix) {
|
|
836
891
|
const [query, values, logValues] = buildUpdateQuery(options, suffix);
|
|
837
892
|
const res = mutateRowSync(queryer, query, values, logValues, options);
|
|
@@ -843,17 +898,14 @@ function editRowSync(queryer, options, suffix) {
|
|
|
843
898
|
}
|
|
844
899
|
return null;
|
|
845
900
|
}
|
|
846
|
-
exports.editRowSync = editRowSync;
|
|
847
901
|
async function deleteRows(queryer, options, cls) {
|
|
848
902
|
const query = `DELETE FROM ${options.tableName} WHERE ${cls.clause(1)}`;
|
|
849
903
|
await mutateRow(queryer, query, cls.values(), cls.logValues(), options);
|
|
850
904
|
}
|
|
851
|
-
exports.deleteRows = deleteRows;
|
|
852
905
|
function deleteRowsSync(queryer, options, cls) {
|
|
853
906
|
const query = `DELETE FROM ${options.tableName} WHERE ${cls.clause(1)}`;
|
|
854
907
|
mutateRowSync(queryer, query, cls.values(), cls.logValues(), options);
|
|
855
908
|
}
|
|
856
|
-
exports.deleteRowsSync = deleteRowsSync;
|
|
857
909
|
class AssocEdge {
|
|
858
910
|
constructor(data) {
|
|
859
911
|
this.id1 = data.id1;
|
|
@@ -897,7 +949,6 @@ function getCursor(opts) {
|
|
|
897
949
|
}
|
|
898
950
|
return btoa(JSON.stringify(parts));
|
|
899
951
|
}
|
|
900
|
-
exports.getCursor = getCursor;
|
|
901
952
|
class AssocEdgeData {
|
|
902
953
|
constructor(data) {
|
|
903
954
|
this.edgeType = data.edge_type;
|
|
@@ -930,7 +981,6 @@ async function loadEdgeData(edgeType) {
|
|
|
930
981
|
}
|
|
931
982
|
return new AssocEdgeData(row);
|
|
932
983
|
}
|
|
933
|
-
exports.loadEdgeData = loadEdgeData;
|
|
934
984
|
async function loadEdgeDatas(...edgeTypes) {
|
|
935
985
|
if (!edgeTypes.length) {
|
|
936
986
|
return new Map();
|
|
@@ -948,7 +998,6 @@ async function loadEdgeDatas(...edgeTypes) {
|
|
|
948
998
|
});
|
|
949
999
|
return m;
|
|
950
1000
|
}
|
|
951
|
-
exports.loadEdgeDatas = loadEdgeDatas;
|
|
952
1001
|
const edgeFields = [
|
|
953
1002
|
"id1",
|
|
954
1003
|
"id1_type",
|
|
@@ -962,11 +1011,9 @@ let defaultLimit = 1000;
|
|
|
962
1011
|
function setDefaultLimit(limit) {
|
|
963
1012
|
defaultLimit = limit;
|
|
964
1013
|
}
|
|
965
|
-
exports.setDefaultLimit = setDefaultLimit;
|
|
966
1014
|
function getDefaultLimit() {
|
|
967
1015
|
return defaultLimit;
|
|
968
1016
|
}
|
|
969
|
-
exports.getDefaultLimit = getDefaultLimit;
|
|
970
1017
|
function defaultEdgeQueryOptions(id1, edgeType, id2) {
|
|
971
1018
|
let cls = clause.And(clause.Eq("id1", id1), clause.Eq("edge_type", edgeType));
|
|
972
1019
|
if (id2) {
|
|
@@ -986,7 +1033,6 @@ function defaultEdgeQueryOptions(id1, edgeType, id2) {
|
|
|
986
1033
|
async function loadEdges(options) {
|
|
987
1034
|
return loadCustomEdges({ ...options, ctr: AssocEdge });
|
|
988
1035
|
}
|
|
989
|
-
exports.loadEdges = loadEdges;
|
|
990
1036
|
function getEdgeClauseAndFields(cls, options) {
|
|
991
1037
|
let fields = edgeFields;
|
|
992
1038
|
const transformEdgeRead = (0, global_schema_1.__getGlobalSchema)()?.transformEdgeRead;
|
|
@@ -1002,7 +1048,6 @@ function getEdgeClauseAndFields(cls, options) {
|
|
|
1002
1048
|
fields,
|
|
1003
1049
|
};
|
|
1004
1050
|
}
|
|
1005
|
-
exports.getEdgeClauseAndFields = getEdgeClauseAndFields;
|
|
1006
1051
|
async function loadCustomEdges(options) {
|
|
1007
1052
|
const { cls: actualClause, fields, defaultOptions, tableName, } = await loadEdgesInfo(options);
|
|
1008
1053
|
const rows = await loadRows({
|
|
@@ -1017,7 +1062,6 @@ async function loadCustomEdges(options) {
|
|
|
1017
1062
|
return new options.ctr(row);
|
|
1018
1063
|
});
|
|
1019
1064
|
}
|
|
1020
|
-
exports.loadCustomEdges = loadCustomEdges;
|
|
1021
1065
|
async function loadEdgesInfo(options, id2) {
|
|
1022
1066
|
const { id1, edgeType } = options;
|
|
1023
1067
|
const edgeData = await loadEdgeData(edgeType);
|
|
@@ -1053,7 +1097,6 @@ async function loadUniqueEdge(options) {
|
|
|
1053
1097
|
}
|
|
1054
1098
|
return new AssocEdge(row);
|
|
1055
1099
|
}
|
|
1056
|
-
exports.loadUniqueEdge = loadUniqueEdge;
|
|
1057
1100
|
async function loadUniqueNode(viewer, id1, edgeType, options) {
|
|
1058
1101
|
const edge = await loadUniqueEdge({
|
|
1059
1102
|
id1,
|
|
@@ -1065,7 +1108,6 @@ async function loadUniqueNode(viewer, id1, edgeType, options) {
|
|
|
1065
1108
|
}
|
|
1066
1109
|
return loadEnt(viewer, edge.id2, options);
|
|
1067
1110
|
}
|
|
1068
|
-
exports.loadUniqueNode = loadUniqueNode;
|
|
1069
1111
|
async function loadRawEdgeCountX(options) {
|
|
1070
1112
|
const { id1, edgeType, context } = options;
|
|
1071
1113
|
const edgeData = await loadEdgeData(edgeType);
|
|
@@ -1082,7 +1124,6 @@ async function loadRawEdgeCountX(options) {
|
|
|
1082
1124
|
});
|
|
1083
1125
|
return parseInt(row["count"], 10) || 0;
|
|
1084
1126
|
}
|
|
1085
|
-
exports.loadRawEdgeCountX = loadRawEdgeCountX;
|
|
1086
1127
|
async function loadEdgeForID2(options) {
|
|
1087
1128
|
const { cls: actualClause, fields, tableName, } = await loadEdgesInfo(options, options.id2);
|
|
1088
1129
|
const row = await loadRow({
|
|
@@ -1095,7 +1136,6 @@ async function loadEdgeForID2(options) {
|
|
|
1095
1136
|
return new options.ctr(row);
|
|
1096
1137
|
}
|
|
1097
1138
|
}
|
|
1098
|
-
exports.loadEdgeForID2 = loadEdgeForID2;
|
|
1099
1139
|
async function loadTwoWayEdges(opts) {
|
|
1100
1140
|
const { cls: actualClause, fields, tableName } = await loadEdgesInfo(opts);
|
|
1101
1141
|
const rows = await loadRows({
|
|
@@ -1116,7 +1156,6 @@ async function loadTwoWayEdges(opts) {
|
|
|
1116
1156
|
});
|
|
1117
1157
|
return rows;
|
|
1118
1158
|
}
|
|
1119
|
-
exports.loadTwoWayEdges = loadTwoWayEdges;
|
|
1120
1159
|
async function loadNodesByEdge(viewer, id1, edgeType, options) {
|
|
1121
1160
|
// load edges
|
|
1122
1161
|
const rows = await loadEdges({
|
|
@@ -1128,12 +1167,10 @@ async function loadNodesByEdge(viewer, id1, edgeType, options) {
|
|
|
1128
1167
|
const ids = rows.map((row) => row.id2);
|
|
1129
1168
|
return loadEntsList(viewer, options, ...ids);
|
|
1130
1169
|
}
|
|
1131
|
-
exports.loadNodesByEdge = loadNodesByEdge;
|
|
1132
1170
|
async function applyPrivacyPolicyForRow(viewer, options, row) {
|
|
1133
1171
|
const r = await applyPrivacyPolicyForRowImpl(viewer, options, row);
|
|
1134
1172
|
return rowIsError(r) ? null : r;
|
|
1135
1173
|
}
|
|
1136
|
-
exports.applyPrivacyPolicyForRow = applyPrivacyPolicyForRow;
|
|
1137
1174
|
async function applyPrivacyPolicyForRowImpl(viewer, options, row) {
|
|
1138
1175
|
const ent = new options.ent(viewer, row);
|
|
1139
1176
|
return applyPrivacyPolicyForEnt(viewer, ent, row, options);
|
|
@@ -1170,7 +1207,6 @@ async function applyPrivacyPolicyForRows(viewer, rows, options) {
|
|
|
1170
1207
|
// filter ents that aren't visible because of privacy
|
|
1171
1208
|
return result.filter((r) => r !== undefined);
|
|
1172
1209
|
}
|
|
1173
|
-
exports.applyPrivacyPolicyForRows = applyPrivacyPolicyForRows;
|
|
1174
1210
|
// given a viewer, an id pair, and a map of edgeEnum to EdgeType
|
|
1175
1211
|
// return the edgeEnum that's set in the group
|
|
1176
1212
|
async function getEdgeTypeInGroup(viewer, id1, id2, m) {
|
|
@@ -1214,4 +1250,3 @@ async function getEdgeTypeInGroup(viewer, id1, id2, m) {
|
|
|
1214
1250
|
}
|
|
1215
1251
|
}
|
|
1216
1252
|
}
|
|
1217
|
-
exports.getEdgeTypeInGroup = getEdgeTypeInGroup;
|
package/core/global_schema.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.setGlobalSchema = setGlobalSchema;
|
|
4
|
+
exports.clearGlobalSchema = clearGlobalSchema;
|
|
5
|
+
exports.__hasGlobalSchema = __hasGlobalSchema;
|
|
6
|
+
exports.__getGlobalSchema = __getGlobalSchema;
|
|
7
|
+
exports.__getGlobalSchemaFields = __getGlobalSchemaFields;
|
|
8
|
+
exports.__getGlobalSchemaField = __getGlobalSchemaField;
|
|
4
9
|
const schema_1 = require("../schema/schema");
|
|
5
10
|
let globalSchema;
|
|
6
11
|
let globalSchemaFields = new Map();
|
|
@@ -25,27 +30,21 @@ function setGlobalSchema(val) {
|
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
|
-
exports.setGlobalSchema = setGlobalSchema;
|
|
29
33
|
function clearGlobalSchema() {
|
|
30
34
|
globalSchema = undefined;
|
|
31
35
|
globalSchemaFields.clear();
|
|
32
36
|
}
|
|
33
|
-
exports.clearGlobalSchema = clearGlobalSchema;
|
|
34
37
|
// used by tests. no guarantee will always exist
|
|
35
38
|
function __hasGlobalSchema() {
|
|
36
39
|
return globalSchema !== undefined;
|
|
37
40
|
}
|
|
38
|
-
exports.__hasGlobalSchema = __hasGlobalSchema;
|
|
39
41
|
// used by tests. no guarantee will always exist
|
|
40
42
|
function __getGlobalSchema() {
|
|
41
43
|
return globalSchema;
|
|
42
44
|
}
|
|
43
|
-
exports.__getGlobalSchema = __getGlobalSchema;
|
|
44
45
|
function __getGlobalSchemaFields() {
|
|
45
46
|
return globalSchemaFields;
|
|
46
47
|
}
|
|
47
|
-
exports.__getGlobalSchemaFields = __getGlobalSchemaFields;
|
|
48
48
|
function __getGlobalSchemaField(type) {
|
|
49
49
|
return globalSchemaFields.get(type);
|
|
50
50
|
}
|
|
51
|
-
exports.__getGlobalSchemaField = __getGlobalSchemaField;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ID, Context, Loader, LoaderFactory, EdgeQueryableDataOptionsConfigureLoader } from "../base";
|
|
2
2
|
export declare class AssocEdgeCountLoader implements Loader<ID, number> {
|
|
3
3
|
private edgeType;
|
|
4
|
-
context?: Context
|
|
4
|
+
context?: Context | undefined;
|
|
5
5
|
private options?;
|
|
6
6
|
private loaderFn;
|
|
7
7
|
private loader;
|
|
8
|
-
constructor(edgeType: string, context?: Context
|
|
8
|
+
constructor(edgeType: string, context?: Context | undefined, options?: EdgeQueryableDataOptionsConfigureLoader | undefined);
|
|
9
9
|
private getLoader;
|
|
10
10
|
load(id: ID): Promise<number>;
|
|
11
11
|
clearAll(): void;
|