@snowtop/ent 0.1.0-alpha142 → 0.1.0-alpha143
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/core/config.d.ts +4 -1
- package/core/config.js +3 -0
- package/core/ent.d.ts +2 -1
- package/core/ent.js +11 -4
- package/core/loaders/assoc_edge_loader.js +2 -2
- package/core/loaders/query_loader.js +2 -2
- package/core/query/custom_clause_query.js +2 -2
- package/core/query/custom_query.js +1 -1
- package/core/query/query.js +1 -1
- package/core/query/shared_assoc_test.js +9 -9
- package/core/query/shared_test.js +63 -1
- package/package.json +1 -1
package/core/config.d.ts
CHANGED
|
@@ -18,8 +18,11 @@ export interface Config {
|
|
|
18
18
|
dbFile?: string;
|
|
19
19
|
db?: Database | DBDict;
|
|
20
20
|
log?: logType | logType[];
|
|
21
|
-
codegen?: CodegenConfig;
|
|
22
21
|
logQueryWithError?: boolean;
|
|
22
|
+
defaultConnectionLimit?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ConfigWithCodegen extends Config {
|
|
25
|
+
codegen?: CodegenConfig;
|
|
23
26
|
customGraphQLJSONPath?: string;
|
|
24
27
|
dynamicScriptCustomGraphQLJSONPath?: string;
|
|
25
28
|
globalSchemaPath?: string;
|
package/core/config.js
CHANGED
|
@@ -62,6 +62,9 @@ function setConfig(cfg) {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
(0, ent_1.___setLogQueryErrorWithError)(cfg.logQueryWithError);
|
|
65
|
+
if (cfg.defaultConnectionLimit) {
|
|
66
|
+
(0, ent_1.setDefaultLimit)(cfg.defaultConnectionLimit);
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
69
|
function isBuffer(b) {
|
|
67
70
|
return b.write !== undefined;
|
package/core/ent.d.ts
CHANGED
|
@@ -131,7 +131,8 @@ interface loadEdgesOptions {
|
|
|
131
131
|
interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
|
|
132
132
|
ctr: AssocEdgeConstructor<T>;
|
|
133
133
|
}
|
|
134
|
-
export declare
|
|
134
|
+
export declare function setDefaultLimit(limit: number): void;
|
|
135
|
+
export declare function getDefaultLimit(): number;
|
|
135
136
|
export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
|
|
136
137
|
export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
|
|
137
138
|
cls: clause.Clause<Data, string | number>;
|
package/core/ent.js
CHANGED
|
@@ -26,7 +26,7 @@ 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.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.
|
|
29
|
+
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.getDefaultLimit = exports.setDefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.___setLogQueryErrorWithError = exports.loadRow = exports.loadRowX = exports.logQuery = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
|
|
30
30
|
const db_1 = __importStar(require("./db"));
|
|
31
31
|
const privacy_1 = require("./privacy");
|
|
32
32
|
const clause = __importStar(require("./clause"));
|
|
@@ -955,8 +955,15 @@ const edgeFields = [
|
|
|
955
955
|
"time",
|
|
956
956
|
"data",
|
|
957
957
|
];
|
|
958
|
-
|
|
959
|
-
|
|
958
|
+
let defaultLimit = 1000;
|
|
959
|
+
function setDefaultLimit(limit) {
|
|
960
|
+
defaultLimit = limit;
|
|
961
|
+
}
|
|
962
|
+
exports.setDefaultLimit = setDefaultLimit;
|
|
963
|
+
function getDefaultLimit() {
|
|
964
|
+
return defaultLimit;
|
|
965
|
+
}
|
|
966
|
+
exports.getDefaultLimit = getDefaultLimit;
|
|
960
967
|
function defaultEdgeQueryOptions(id1, edgeType, id2) {
|
|
961
968
|
let cls = clause.And(clause.Eq("id1", id1), clause.Eq("edge_type", edgeType));
|
|
962
969
|
if (id2) {
|
|
@@ -965,7 +972,7 @@ function defaultEdgeQueryOptions(id1, edgeType, id2) {
|
|
|
965
972
|
return {
|
|
966
973
|
clause: cls,
|
|
967
974
|
orderby: "time DESC",
|
|
968
|
-
limit:
|
|
975
|
+
limit: defaultLimit,
|
|
969
976
|
};
|
|
970
977
|
}
|
|
971
978
|
async function loadEdges(options) {
|
|
@@ -61,7 +61,7 @@ function createLoader(options, edgeType, edgeCtr, edgeData) {
|
|
|
61
61
|
}
|
|
62
62
|
options.orderby = options.orderby || "time DESC";
|
|
63
63
|
// TODO defaultEdgeQueryOptions
|
|
64
|
-
options.limit = options.limit || ent_1.
|
|
64
|
+
options.limit = options.limit || (0, ent_1.getDefaultLimit)();
|
|
65
65
|
const tableName = edgeData.edgeTable;
|
|
66
66
|
const { cls: cls1, fields } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", edgeType), {});
|
|
67
67
|
const [query, cls] = (0, ent_1.buildGroupQuery)({
|
|
@@ -69,7 +69,7 @@ function createLoader(options, edgeType, edgeCtr, edgeData) {
|
|
|
69
69
|
fields,
|
|
70
70
|
values: keys,
|
|
71
71
|
orderby: options.orderby,
|
|
72
|
-
limit: options.limit || ent_1.
|
|
72
|
+
limit: options.limit || (0, ent_1.getDefaultLimit)(),
|
|
73
73
|
groupColumn: "id1",
|
|
74
74
|
clause: cls1,
|
|
75
75
|
});
|
|
@@ -67,7 +67,7 @@ async function simpleCase(options, id, queryOptions) {
|
|
|
67
67
|
...options,
|
|
68
68
|
clause: cls,
|
|
69
69
|
orderby: getOrderBy(sortCol, queryOptions?.orderby),
|
|
70
|
-
limit: queryOptions?.limit || ent_1.
|
|
70
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
function createLoader(options, queryOptions) {
|
|
@@ -110,7 +110,7 @@ function createLoader(options, queryOptions) {
|
|
|
110
110
|
fields: options.fields,
|
|
111
111
|
values: keys,
|
|
112
112
|
orderby: getOrderBy(sortCol, queryOptions?.orderby),
|
|
113
|
-
limit: queryOptions?.limit || ent_1.
|
|
113
|
+
limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
|
|
114
114
|
groupColumn: col,
|
|
115
115
|
clause: extraClause,
|
|
116
116
|
});
|
|
@@ -62,14 +62,14 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
62
62
|
options.orderby = `${this.options.sortColumn} ${direction}`;
|
|
63
63
|
}
|
|
64
64
|
if (!options.limit) {
|
|
65
|
-
options.limit = ent_1.
|
|
65
|
+
options.limit = (0, ent_1.getDefaultLimit)();
|
|
66
66
|
}
|
|
67
67
|
const rows = await (0, ent_1.loadRows)({
|
|
68
68
|
tableName: this.options.loadEntOptions.tableName,
|
|
69
69
|
fields: this.options.loadEntOptions.fields,
|
|
70
70
|
clause: (0, clause_1.AndOptional)(this.clause, options.clause),
|
|
71
71
|
orderby: (0, query_loader_1.getOrderBy)(this.getSortCol(), options?.orderby),
|
|
72
|
-
limit: options?.limit || ent_1.
|
|
72
|
+
limit: options?.limit || (0, ent_1.getDefaultLimit)(),
|
|
73
73
|
context: this.viewer.context,
|
|
74
74
|
});
|
|
75
75
|
this.edges.set(1, rows);
|
|
@@ -127,7 +127,7 @@ class CustomEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
|
127
127
|
options.orderby = `${this.getSortCol()} DESC`;
|
|
128
128
|
}
|
|
129
129
|
if (!options.limit) {
|
|
130
|
-
options.limit = ent_1.
|
|
130
|
+
options.limit = (0, ent_1.getDefaultLimit)();
|
|
131
131
|
}
|
|
132
132
|
const loader = this.getQueryLoader(options);
|
|
133
133
|
const info = infos[0];
|
package/core/query/query.js
CHANGED
|
@@ -351,7 +351,7 @@ class BaseEdgeQuery {
|
|
|
351
351
|
const idsInfo = await this.genIDInfosToFetch();
|
|
352
352
|
if (!this.filters.length) {
|
|
353
353
|
// if no filter, we add the firstN filter to ensure we get pagination info
|
|
354
|
-
this.first(ent_1.
|
|
354
|
+
this.first((0, ent_1.getDefaultLimit)());
|
|
355
355
|
}
|
|
356
356
|
let options = {};
|
|
357
357
|
// TODO once we add a lot of complex filters, this needs to be more complicated
|
|
@@ -52,7 +52,7 @@ function assocTests(ml, global = false) {
|
|
|
52
52
|
let execArray = /^SELECT (.+) FROM (.+) WHERE (.+)?/.exec(query.query);
|
|
53
53
|
return execArray?.[3];
|
|
54
54
|
}
|
|
55
|
-
function verifyQuery({ length = 1, numQueries = 1, limit = ent_1.
|
|
55
|
+
function verifyQuery({ length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, }) {
|
|
56
56
|
expect(ml.logs.length).toBe(length);
|
|
57
57
|
for (let i = 0; i < numQueries; i++) {
|
|
58
58
|
const whereClause = getWhereClause(ml.logs[i]);
|
|
@@ -118,7 +118,7 @@ function assocTests(ml, global = false) {
|
|
|
118
118
|
verifyQuery({
|
|
119
119
|
length: this.dataz.length,
|
|
120
120
|
numQueries: this.dataz.length,
|
|
121
|
-
limit: this.limit || ent_1.
|
|
121
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
// rawCount isn't affected by filters...
|
|
@@ -141,7 +141,7 @@ function assocTests(ml, global = false) {
|
|
|
141
141
|
verifyQuery({
|
|
142
142
|
length: this.dataz.length,
|
|
143
143
|
numQueries: this.dataz.length,
|
|
144
|
-
limit: this.limit || ent_1.
|
|
144
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
async testEdges() {
|
|
@@ -154,7 +154,7 @@ function assocTests(ml, global = false) {
|
|
|
154
154
|
verifyQuery({
|
|
155
155
|
length: this.dataz.length,
|
|
156
156
|
numQueries: this.dataz.length,
|
|
157
|
-
limit: this.limit || ent_1.
|
|
157
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
async testEnts() {
|
|
@@ -178,7 +178,7 @@ function assocTests(ml, global = false) {
|
|
|
178
178
|
// and then twice to fetch all the nodes for the contacts
|
|
179
179
|
length: this.dataz.length + this.dataz.length + this.dataz.length * 2,
|
|
180
180
|
numQueries: this.dataz.length,
|
|
181
|
-
limit: this.limit || ent_1.
|
|
181
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -464,7 +464,7 @@ function assocTests(ml, global = false) {
|
|
|
464
464
|
verifyQuery({
|
|
465
465
|
length: 1,
|
|
466
466
|
numQueries: 1,
|
|
467
|
-
limit: this.limit || ent_1.
|
|
467
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
470
|
// rawCount isn't affected by filters...
|
|
@@ -479,7 +479,7 @@ function assocTests(ml, global = false) {
|
|
|
479
479
|
verifyQuery({
|
|
480
480
|
length: 1,
|
|
481
481
|
numQueries: 1,
|
|
482
|
-
limit: this.limit || ent_1.
|
|
482
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
483
483
|
});
|
|
484
484
|
}
|
|
485
485
|
async testEdges() {
|
|
@@ -500,7 +500,7 @@ function assocTests(ml, global = false) {
|
|
|
500
500
|
verifyQuery({
|
|
501
501
|
length: 1,
|
|
502
502
|
numQueries: 1,
|
|
503
|
-
limit: this.limit || ent_1.
|
|
503
|
+
limit: this.limit || (0, ent_1.getDefaultLimit)(),
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
async testEnts() {
|
|
@@ -524,7 +524,7 @@ function assocTests(ml, global = false) {
|
|
|
524
524
|
// // 1 for edges, 1 for users, 1 for events
|
|
525
525
|
// length: 3,
|
|
526
526
|
// numQueries: 3,
|
|
527
|
-
// limit: this.limit ||
|
|
527
|
+
// limit: this.limit || getDefaultLimit(),
|
|
528
528
|
// });
|
|
529
529
|
}
|
|
530
530
|
}
|
|
@@ -147,7 +147,7 @@ const commonTests = (opts) => {
|
|
|
147
147
|
this.verifyEnts(ents);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
function verifyQuery(filter, { length = 1, numQueries = 1, limit = ent_1.
|
|
150
|
+
function verifyQuery(filter, { length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, orderby = opts.orderby, }) {
|
|
151
151
|
const uniqCol = isCustomQuery(filter) ? "id" : "id2";
|
|
152
152
|
expect(ml.logs.length).toBe(length);
|
|
153
153
|
for (let i = 0; i < numQueries; i++) {
|
|
@@ -355,6 +355,68 @@ const commonTests = (opts) => {
|
|
|
355
355
|
await filter.testDataCache();
|
|
356
356
|
});
|
|
357
357
|
});
|
|
358
|
+
describe("override default limit", () => {
|
|
359
|
+
const filter = new TestQueryFilter((q) => {
|
|
360
|
+
// no filters
|
|
361
|
+
return q;
|
|
362
|
+
}, opts.newQuery, (contacts) => {
|
|
363
|
+
// nothing to do here
|
|
364
|
+
// reverse because edges are most recent first
|
|
365
|
+
if (opts.orderby === "DESC") {
|
|
366
|
+
return contacts.reverse();
|
|
367
|
+
}
|
|
368
|
+
return contacts;
|
|
369
|
+
}, getViewer());
|
|
370
|
+
const OUR_DEFAULT_LIMIT = 10;
|
|
371
|
+
beforeAll(async () => {
|
|
372
|
+
(0, ent_1.setDefaultLimit)(OUR_DEFAULT_LIMIT);
|
|
373
|
+
});
|
|
374
|
+
afterAll(async () => {
|
|
375
|
+
//set it back to real default
|
|
376
|
+
(0, ent_1.setDefaultLimit)(1000);
|
|
377
|
+
});
|
|
378
|
+
beforeEach(async () => {
|
|
379
|
+
await filter.createData();
|
|
380
|
+
});
|
|
381
|
+
test("ids", async () => {
|
|
382
|
+
await filter.testIDs();
|
|
383
|
+
verifyQuery(filter, {
|
|
384
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
test("rawCount", async () => {
|
|
388
|
+
await filter.testRawCount();
|
|
389
|
+
verifyCountQuery({});
|
|
390
|
+
});
|
|
391
|
+
test("count", async () => {
|
|
392
|
+
await filter.testCount();
|
|
393
|
+
verifyQuery(filter, {
|
|
394
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
test("edges", async () => {
|
|
398
|
+
await filter.testEdges();
|
|
399
|
+
verifyQuery(filter, {
|
|
400
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
test("ents", async () => {
|
|
404
|
+
await filter.testEnts();
|
|
405
|
+
verifyQuery(filter, {
|
|
406
|
+
length: opts.entsLength,
|
|
407
|
+
limit: OUR_DEFAULT_LIMIT,
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
test("all", async () => {
|
|
411
|
+
await filter.testAll();
|
|
412
|
+
});
|
|
413
|
+
test("ents cache", async () => {
|
|
414
|
+
await filter.testEntsCache();
|
|
415
|
+
});
|
|
416
|
+
test("data cache", async () => {
|
|
417
|
+
await filter.testDataCache();
|
|
418
|
+
});
|
|
419
|
+
});
|
|
358
420
|
describe("after delete", () => {
|
|
359
421
|
const filter = new TestQueryFilter((q) => {
|
|
360
422
|
// no filters
|