@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha91

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.
Files changed (135) hide show
  1. package/action/action.d.ts +36 -31
  2. package/action/action.js +2 -6
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +2 -2
  5. package/action/experimental_action.d.ts +29 -22
  6. package/action/experimental_action.js +29 -6
  7. package/action/orchestrator.d.ts +38 -16
  8. package/action/orchestrator.js +223 -61
  9. package/action/privacy.d.ts +2 -2
  10. package/core/base.d.ts +45 -24
  11. package/core/base.js +7 -1
  12. package/core/clause.d.ts +83 -7
  13. package/core/clause.js +334 -63
  14. package/core/config.d.ts +8 -0
  15. package/core/config.js +5 -1
  16. package/core/context.d.ts +5 -3
  17. package/core/context.js +20 -2
  18. package/core/convert.d.ts +1 -1
  19. package/core/db.d.ts +2 -2
  20. package/core/db.js +6 -2
  21. package/core/ent.d.ts +79 -24
  22. package/core/ent.js +527 -176
  23. package/core/loaders/assoc_count_loader.d.ts +3 -2
  24. package/core/loaders/assoc_count_loader.js +14 -2
  25. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  26. package/core/loaders/assoc_edge_loader.js +5 -1
  27. package/core/loaders/index.d.ts +1 -1
  28. package/core/loaders/index.js +1 -3
  29. package/core/loaders/index_loader.d.ts +2 -2
  30. package/core/loaders/loader.js +5 -5
  31. package/core/loaders/object_loader.d.ts +6 -5
  32. package/core/loaders/object_loader.js +67 -59
  33. package/core/loaders/query_loader.d.ts +6 -12
  34. package/core/loaders/query_loader.js +52 -11
  35. package/core/loaders/raw_count_loader.d.ts +2 -2
  36. package/core/loaders/raw_count_loader.js +5 -1
  37. package/core/logger.d.ts +1 -1
  38. package/core/logger.js +1 -0
  39. package/core/privacy.d.ts +26 -25
  40. package/core/privacy.js +21 -25
  41. package/core/query/assoc_query.d.ts +7 -6
  42. package/core/query/assoc_query.js +9 -1
  43. package/core/query/custom_clause_query.d.ts +26 -0
  44. package/core/query/custom_clause_query.js +78 -0
  45. package/core/query/custom_query.d.ts +20 -5
  46. package/core/query/custom_query.js +87 -12
  47. package/core/query/index.d.ts +1 -0
  48. package/core/query/index.js +3 -1
  49. package/core/query/query.d.ts +8 -4
  50. package/core/query/query.js +101 -53
  51. package/core/query/shared_assoc_test.d.ts +2 -1
  52. package/core/query/shared_assoc_test.js +34 -43
  53. package/core/query/shared_test.d.ts +8 -1
  54. package/core/query/shared_test.js +470 -236
  55. package/core/viewer.d.ts +3 -3
  56. package/core/viewer.js +1 -1
  57. package/graphql/graphql.js +16 -6
  58. package/graphql/query/edge_connection.d.ts +9 -9
  59. package/graphql/query/page_info.d.ts +1 -1
  60. package/graphql/query/shared_edge_connection.js +1 -15
  61. package/imports/index.js +5 -1
  62. package/index.d.ts +11 -5
  63. package/index.js +20 -7
  64. package/package.json +1 -1
  65. package/parse_schema/parse.d.ts +12 -3
  66. package/parse_schema/parse.js +70 -11
  67. package/schema/base_schema.js +3 -0
  68. package/schema/field.d.ts +44 -8
  69. package/schema/field.js +136 -10
  70. package/schema/index.d.ts +2 -2
  71. package/schema/index.js +5 -1
  72. package/schema/json_field.d.ts +13 -1
  73. package/schema/json_field.js +28 -1
  74. package/schema/schema.d.ts +66 -11
  75. package/schema/schema.js +18 -4
  76. package/schema/struct_field.d.ts +11 -1
  77. package/schema/struct_field.js +44 -5
  78. package/scripts/custom_compiler.js +10 -6
  79. package/scripts/custom_graphql.js +13 -4
  80. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  81. package/scripts/migrate_v0.1.js +36 -0
  82. package/scripts/read_schema.js +20 -5
  83. package/testutils/builder.d.ts +31 -21
  84. package/testutils/builder.js +83 -29
  85. package/testutils/db/fixture.d.ts +10 -0
  86. package/testutils/db/fixture.js +26 -0
  87. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +20 -7
  88. package/testutils/db/{test_db.js → temp_db.js} +102 -36
  89. package/testutils/db/value.d.ts +6 -0
  90. package/testutils/db/value.js +251 -0
  91. package/testutils/db_mock.js +3 -1
  92. package/testutils/db_time_zone.d.ts +4 -0
  93. package/testutils/db_time_zone.js +41 -0
  94. package/testutils/ent-graphql-tests/index.js +8 -1
  95. package/testutils/fake_data/const.d.ts +2 -1
  96. package/testutils/fake_data/const.js +3 -0
  97. package/testutils/fake_data/fake_contact.d.ts +7 -4
  98. package/testutils/fake_data/fake_contact.js +14 -6
  99. package/testutils/fake_data/fake_event.d.ts +5 -3
  100. package/testutils/fake_data/fake_event.js +8 -5
  101. package/testutils/fake_data/fake_tag.d.ts +35 -0
  102. package/testutils/fake_data/fake_tag.js +88 -0
  103. package/testutils/fake_data/fake_user.d.ts +6 -4
  104. package/testutils/fake_data/fake_user.js +16 -13
  105. package/testutils/fake_data/index.js +5 -1
  106. package/testutils/fake_data/internal.d.ts +2 -0
  107. package/testutils/fake_data/internal.js +7 -1
  108. package/testutils/fake_data/tag_query.d.ts +13 -0
  109. package/testutils/fake_data/tag_query.js +43 -0
  110. package/testutils/fake_data/test_helpers.d.ts +11 -4
  111. package/testutils/fake_data/test_helpers.js +28 -12
  112. package/testutils/fake_data/user_query.d.ts +13 -6
  113. package/testutils/fake_data/user_query.js +54 -22
  114. package/testutils/fake_log.d.ts +3 -3
  115. package/testutils/parse_sql.d.ts +6 -0
  116. package/testutils/parse_sql.js +16 -2
  117. package/testutils/test_edge_global_schema.d.ts +15 -0
  118. package/testutils/test_edge_global_schema.js +62 -0
  119. package/testutils/write.d.ts +2 -2
  120. package/testutils/write.js +33 -7
  121. package/tsc/ast.d.ts +44 -0
  122. package/tsc/ast.js +271 -0
  123. package/tsc/compilerOptions.d.ts +6 -0
  124. package/tsc/compilerOptions.js +45 -2
  125. package/tsc/move_generated.d.ts +1 -0
  126. package/tsc/move_generated.js +164 -0
  127. package/tsc/transform.d.ts +21 -0
  128. package/tsc/transform.js +171 -0
  129. package/tsc/transform_action.d.ts +22 -0
  130. package/tsc/transform_action.js +183 -0
  131. package/tsc/transform_ent.d.ts +17 -0
  132. package/tsc/transform_ent.js +59 -0
  133. package/tsc/transform_schema.d.ts +27 -0
  134. package/tsc/transform_schema.js +383 -0
  135. package/scripts/transform_schema.js +0 -445
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -27,6 +31,8 @@ const ent_1 = require("../ent");
27
31
  const clause = __importStar(require("../clause"));
28
32
  const memoizee_1 = __importDefault(require("memoizee"));
29
33
  const privacy_1 = require("../privacy");
34
+ const uuid_1 = require("uuid");
35
+ const util_1 = require("util");
30
36
  // TODO can we generalize EdgeQuery to support any clause
31
37
  function assertPositive(n) {
32
38
  if (n < 0) {
@@ -36,31 +42,32 @@ function assertPositive(n) {
36
42
  function assertValidCursor(cursor, col) {
37
43
  let decoded = Buffer.from(cursor, "base64").toString("ascii");
38
44
  let parts = decoded.split(":");
45
+ // uuid, don't parse int since it tries to validate just first part
46
+ if ((0, uuid_1.validate)(parts[1])) {
47
+ return parts[1];
48
+ }
39
49
  // invalid or unknown cursor. nothing to do here.
40
50
  if (parts.length !== 2 || parts[0] !== col) {
41
51
  throw new Error(`invalid cursor ${cursor} passed`);
42
52
  }
43
- // TODO check if numeric or not but for now we're only doing numbers
53
+ // TODO handle both cases... (time vs not) better
54
+ // TODO change this to only do the parseInt part if time...
55
+ // pass flag indicating if time?
44
56
  const time = parseInt(parts[1], 10);
45
57
  if (isNaN(time)) {
46
- throw new Error(`invalid cursor ${cursor} passed`);
58
+ return parts[1];
47
59
  }
48
60
  return time;
49
61
  }
62
+ const orderbyRegex = new RegExp(/([0-9a-z_]+)[ ]?([0-9a-z_]+)?/i);
50
63
  class FirstFilter {
51
64
  constructor(options) {
52
65
  this.options = options;
53
66
  this.pageMap = new Map();
54
67
  assertPositive(options.limit);
55
- if (options.before) {
56
- throw new Error(`cannot specify before with a first filter`);
57
- }
58
- this.sortCol = options.sortCol || "time";
68
+ this.sortCol = options.sortCol;
59
69
  if (options.after) {
60
- this.offset = assertValidCursor(options.after, this.sortCol);
61
- }
62
- if (this.options.sortColNotTime && !this.options.sortCol) {
63
- throw new Error(`cannot specify sortColNotTime without specifying a sortCol`);
70
+ this.offset = assertValidCursor(options.after, options.cursorCol);
64
71
  }
65
72
  this.edgeQuery = options.query;
66
73
  }
@@ -69,6 +76,8 @@ class FirstFilter {
69
76
  const ret = edges.slice(0, this.options.limit);
70
77
  this.pageMap.set(id, {
71
78
  hasNextPage: true,
79
+ // hasPreviousPage always false even if there's a previous page because
80
+ // we shouldn't be querying in both directions at the same
72
81
  hasPreviousPage: false,
73
82
  startCursor: this.edgeQuery.getCursor(ret[0]),
74
83
  endCursor: this.edgeQuery.getCursor(ret[ret.length - 1]),
@@ -82,22 +91,32 @@ class FirstFilter {
82
91
  // so we'd need a way to indicate whether this is done in sql or not
83
92
  return edges;
84
93
  }
85
- query(options) {
94
+ async query(options) {
86
95
  // we fetch an extra one to see if we're at the end
87
96
  const limit = this.options.limit + 1;
88
97
  options.limit = limit;
89
- // todo may not be desc
90
- // and if asc
91
- // clause below should switch to greater...
92
- options.orderby = `${this.sortCol} DESC`;
98
+ let orderby = this.options.defaultDirection || "DESC";
93
99
  // we sort by most recent first
94
100
  // so when paging, we fetch afterCursor X
95
- if (this.offset) {
96
- if (this.options.sortColNotTime) {
97
- options.clause = clause.Less(this.sortCol, this.offset);
101
+ const less = orderby === "DESC";
102
+ if (this.options.cursorCol !== this.sortCol) {
103
+ // we also sort unique col in same direction since it doesn't matter...
104
+ options.orderby = `${this.sortCol} ${orderby}, ${this.options.cursorCol} ${orderby}`;
105
+ if (this.offset) {
106
+ const res = this.edgeQuery.getTableName();
107
+ const tableName = util_1.types.isPromise(res) ? await res : res;
108
+ // inner col time
109
+ options.clause = clause.PaginationMultipleColsSubQuery(this.sortCol, less ? "<" : ">", tableName, this.options.cursorCol, this.offset);
98
110
  }
99
- else {
100
- options.clause = clause.Less(this.sortCol, new Date(this.offset).toISOString());
111
+ }
112
+ else {
113
+ options.orderby = `${this.sortCol} ${orderby}`;
114
+ if (this.offset) {
115
+ let clauseFn = less ? clause.Less : clause.Greater;
116
+ let val = this.options.sortColTime
117
+ ? new Date(this.offset).toISOString()
118
+ : this.offset;
119
+ options.clause = clauseFn(this.sortCol, val);
101
120
  }
102
121
  }
103
122
  return options;
@@ -112,15 +131,9 @@ class LastFilter {
112
131
  this.options = options;
113
132
  this.pageMap = new Map();
114
133
  assertPositive(options.limit);
115
- if (options.after) {
116
- throw new Error(`cannot specify after with a last filter`);
117
- }
118
- this.sortCol = options.sortCol || "time";
134
+ this.sortCol = options.sortCol;
119
135
  if (options.before) {
120
- this.offset = assertValidCursor(options.before, this.sortCol);
121
- }
122
- if (this.options.sortColNotTime && !this.options.sortCol) {
123
- throw new Error(`cannot specify sortColNotTime without specifying a sortCol`);
136
+ this.offset = assertValidCursor(options.before, options.cursorCol);
124
137
  }
125
138
  this.edgeQuery = options.query;
126
139
  }
@@ -137,11 +150,13 @@ class LastFilter {
137
150
  }
138
151
  }
139
152
  else {
140
- ret = edges.slice(edges.length - this.options.limit, edges.length);
153
+ ret = edges.slice(0, this.options.limit);
141
154
  }
142
155
  if (edges.length > this.options.limit) {
143
156
  this.pageMap.set(id, {
144
157
  hasPreviousPage: true,
158
+ // hasNextPage always false even if there's a next page because
159
+ // we shouldn't be querying in both directions at the same
145
160
  hasNextPage: false,
146
161
  startCursor: this.edgeQuery.getCursor(ret[0]),
147
162
  endCursor: this.edgeQuery.getCursor(ret[ret.length - 1]),
@@ -149,17 +164,39 @@ class LastFilter {
149
164
  }
150
165
  return ret;
151
166
  }
152
- query(options) {
153
- if (!this.offset) {
154
- return options;
167
+ async query(options) {
168
+ // assume desc by default
169
+ // so last is reverse
170
+ let orderby = "ASC";
171
+ if (this.options.defaultDirection) {
172
+ // reverse sort col shown...
173
+ if (this.options.defaultDirection === "DESC") {
174
+ orderby = "ASC";
175
+ }
176
+ else {
177
+ orderby = "DESC";
178
+ }
155
179
  }
156
- options.orderby = `${this.sortCol} ASC`;
180
+ const greater = orderby === "ASC";
157
181
  options.limit = this.options.limit + 1; // fetch an extra so we know if previous pag
158
- if (this.options.sortColNotTime) {
159
- options.clause = clause.Greater(this.sortCol, this.offset);
182
+ if (this.options.cursorCol !== this.sortCol) {
183
+ const res = this.edgeQuery.getTableName();
184
+ const tableName = util_1.types.isPromise(res) ? await res : res;
185
+ if (this.offset) {
186
+ // inner col time
187
+ options.clause = clause.PaginationMultipleColsSubQuery(this.sortCol, greater ? ">" : "<", tableName, this.options.cursorCol, this.offset);
188
+ }
189
+ options.orderby = `${this.sortCol} ${orderby}, ${this.options.cursorCol} ${orderby}`;
160
190
  }
161
191
  else {
162
- options.clause = clause.Greater(this.sortCol, new Date(this.offset).toISOString());
192
+ options.orderby = `${this.sortCol} ${orderby}`;
193
+ if (this.offset) {
194
+ let clauseFn = greater ? clause.Greater : clause.Less;
195
+ let val = this.options.sortColTime
196
+ ? new Date(this.offset).toISOString()
197
+ : this.offset;
198
+ options.clause = clauseFn(this.sortCol, val);
199
+ }
163
200
  }
164
201
  return options;
165
202
  }
@@ -168,9 +205,8 @@ class LastFilter {
168
205
  }
169
206
  }
170
207
  class BaseEdgeQuery {
171
- constructor(viewer, sortCol) {
208
+ constructor(viewer, sortCol, cursorCol) {
172
209
  this.viewer = viewer;
173
- this.sortCol = sortCol;
174
210
  this.filters = [];
175
211
  this.edges = new Map();
176
212
  this.pagination = new Map();
@@ -226,9 +262,26 @@ class BaseEdgeQuery {
226
262
  await Promise.all(promises);
227
263
  return results;
228
264
  };
265
+ let m = orderbyRegex.exec(sortCol);
266
+ if (!m) {
267
+ throw new Error(`invalid sort column ${sortCol}`);
268
+ }
269
+ this.sortCol = m[1];
270
+ if (m[2]) {
271
+ // @ts-ignore
272
+ this.defaultDirection = m[2].toUpperCase();
273
+ }
274
+ let m2 = orderbyRegex.exec(cursorCol);
275
+ if (!m2) {
276
+ throw new Error(`invalid sort column ${cursorCol}`);
277
+ }
278
+ this.cursorCol = m2[1];
229
279
  this.memoizedloadEdges = (0, memoizee_1.default)(this.loadEdges.bind(this));
230
280
  this.genIDInfosToFetch = (0, memoizee_1.default)(this.genIDInfosToFetchImpl.bind(this));
231
281
  }
282
+ getSortCol() {
283
+ return this.sortCol;
284
+ }
232
285
  getPrivacyPolicy() {
233
286
  // default PrivacyPolicy is always allow. nothing to do here
234
287
  return privacy_1.AlwaysAllowPrivacyPolicy;
@@ -239,6 +292,8 @@ class BaseEdgeQuery {
239
292
  limit: n,
240
293
  after,
241
294
  sortCol: this.sortCol,
295
+ cursorCol: this.cursorCol,
296
+ defaultDirection: this.defaultDirection,
242
297
  query: this,
243
298
  }));
244
299
  return this;
@@ -249,6 +304,8 @@ class BaseEdgeQuery {
249
304
  limit: n,
250
305
  before,
251
306
  sortCol: this.sortCol,
307
+ cursorCol: this.cursorCol,
308
+ defaultDirection: this.defaultDirection,
252
309
  query: this,
253
310
  }));
254
311
  return this;
@@ -300,11 +357,12 @@ class BaseEdgeQuery {
300
357
  // TODO once we add a lot of complex filters, this needs to be more complicated
301
358
  // e.g. commutative filters. what can be done in sql or combined together etc
302
359
  // may need to bring sql mode or something back
303
- this.filters.forEach((filter) => {
360
+ for (const filter of this.filters) {
304
361
  if (filter.query) {
305
- options = filter.query(options);
362
+ let res = filter.query(options);
363
+ options = util_1.types.isPromise(res) ? await res : res;
306
364
  }
307
- });
365
+ }
308
366
  await this.loadRawData(idsInfo, options);
309
367
  // no filters. nothing to do here.
310
368
  if (!this.filters.length) {
@@ -331,17 +389,7 @@ class BaseEdgeQuery {
331
389
  getCursor(row) {
332
390
  return (0, ent_1.getCursor)({
333
391
  row,
334
- col: this.sortCol,
335
- conv: (datum) => {
336
- if (datum instanceof Date) {
337
- return datum.getTime();
338
- }
339
- // sqlite stores it as string and doesn't convert back
340
- if (typeof datum === "string") {
341
- return Date.parse(datum);
342
- }
343
- return datum;
344
- },
392
+ col: this.cursorCol,
345
393
  });
346
394
  }
347
395
  }
@@ -1 +1,2 @@
1
- export declare function assocTests(): void;
1
+ import { MockLogs } from "../../testutils/mock_log";
2
+ export declare function assocTests(ml: MockLogs, global?: boolean): void;
@@ -1,33 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.assocTests = void 0;
23
- const db_mock_1 = require("../../testutils/db_mock");
24
4
  const ent_1 = require("../ent");
25
5
  const viewer_1 = require("../viewer");
26
6
  const jest_date_mock_1 = require("jest-date-mock");
27
7
  const index_1 = require("../../testutils/fake_data/index");
28
8
  const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
29
- const db_1 = __importStar(require("../db"));
30
- function assocTests() {
9
+ const clause_1 = require("../clause");
10
+ function assocTests(ml, global = false) {
11
+ ml.mock();
31
12
  describe("custom edge", () => {
32
13
  let user1, user2;
33
14
  beforeEach(async () => {
@@ -67,29 +48,37 @@ function assocTests() {
67
48
  function firstNEntsFilter(contacts) {
68
49
  return contacts.reverse().slice(0, N);
69
50
  }
51
+ function getWhereClause(query) {
52
+ let execArray = /^SELECT (.+) FROM (.+) WHERE (.+)?/.exec(query.query);
53
+ return execArray?.[3];
54
+ }
70
55
  function verifyQuery({ length = 1, numQueries = 1, limit = ent_1.DefaultLimit, disablePaginationBump = false, }) {
71
- if (db_1.default.getDialect() === db_1.Dialect.SQLite) {
72
- return;
73
- }
74
- const queries = db_mock_1.QueryRecorder.getCurrentQueries();
75
- expect(queries.length).toBe(length);
56
+ expect(ml.logs.length).toBe(length);
76
57
  for (let i = 0; i < numQueries; i++) {
77
- const query = queries[i];
58
+ const whereClause = getWhereClause(ml.logs[i]);
78
59
  let expLimit = disablePaginationBump ? limit : limit + 1;
79
- expect(query.qs?.whereClause, `${i}`).toBe(
80
- // default limit
81
- `id1 = $1 AND edge_type = $2 ORDER BY time DESC LIMIT ${expLimit}`);
60
+ if (global) {
61
+ expect(whereClause, `${i}`).toBe(
62
+ // default limit
63
+ `${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", ""), (0, clause_1.Eq)("deleted_at", null)).clause(1)} ORDER BY time DESC, id2 DESC LIMIT ${expLimit}`);
64
+ }
65
+ else {
66
+ expect(whereClause, `${i}`).toBe(
67
+ // default limit
68
+ `${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", "")).clause(1)} ORDER BY time DESC, id2 DESC LIMIT ${expLimit}`);
69
+ }
82
70
  }
83
71
  }
84
72
  function verifyCountQuery({ length = 1, numQueries = 1 }) {
85
- if (db_1.default.getDialect() === db_1.Dialect.SQLite) {
86
- return;
87
- }
88
- const queries = db_mock_1.QueryRecorder.getCurrentQueries();
89
- expect(queries.length).toBe(length);
73
+ expect(ml.logs.length).toBe(length);
90
74
  for (let i = 0; i < numQueries; i++) {
91
- const query = queries[i];
92
- expect(query.qs?.whereClause).toBe(`id1 = $1 AND edge_type = $2`);
75
+ const whereClause = getWhereClause(ml.logs[i]);
76
+ if (global) {
77
+ expect(whereClause).toBe(`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", ""), (0, clause_1.Eq)("deleted_at", null)).clause(1)}`);
78
+ }
79
+ else {
80
+ expect(whereClause).toBe(`${(0, clause_1.And)((0, clause_1.Eq)("id1", ""), (0, clause_1.Eq)("edge_type", "")).clause(1)}`);
81
+ }
93
82
  }
94
83
  }
95
84
  // TODO need to test multi-ids with id1s that aren't visible...
@@ -103,16 +92,18 @@ function assocTests() {
103
92
  }
104
93
  async beforeEach() {
105
94
  let [user1, user2, user3] = await Promise.all([
106
- (0, test_helpers_1.createAllContacts)({ firstName: "Jon", lastName: "Snow" }),
107
- (0, test_helpers_1.createAllContacts)({ firstName: "Aegon", lastName: "Targaryen" }),
108
- (0, test_helpers_1.createAllContacts)({ firstName: "Ned", lastName: "Stark" }),
95
+ (0, test_helpers_1.createAllContacts)({ input: { firstName: "Jon", lastName: "Snow" } }),
96
+ (0, test_helpers_1.createAllContacts)({
97
+ input: { firstName: "Aegon", lastName: "Targaryen" },
98
+ }),
99
+ (0, test_helpers_1.createAllContacts)({ input: { firstName: "Ned", lastName: "Stark" } }),
109
100
  ]);
110
101
  // modify contacts as needed
111
102
  user1[1] = this.ents(user1[1]);
112
103
  user2[1] = this.ents(user2[1]);
113
104
  user3[1] = this.ents(user3[1]);
114
105
  this.dataz = [user1, user2, user3];
115
- db_mock_1.QueryRecorder.clearQueries();
106
+ ml.clear();
116
107
  }
117
108
  getQuery(viewer) {
118
109
  return this.filter(index_1.UserToContactsQuery.query(viewer || new viewer_1.LoggedOutViewer(), this.dataz.map((data) => data[0])));
@@ -457,7 +448,7 @@ function assocTests() {
457
448
  }
458
449
  //order is users, then events
459
450
  this.expCount = this.ents([...this.users, ...this.events]).length;
460
- db_mock_1.QueryRecorder.clearQueries();
451
+ ml.clear();
461
452
  }
462
453
  getQuery(viewer) {
463
454
  return this.filter(index_1.UserToFollowingQuery.query(viewer || new viewer_1.IDViewer(this.user.id), this.user));
@@ -1,14 +1,21 @@
1
1
  import { Data, Viewer } from "../base";
2
2
  import { FakeUser, FakeContact } from "../../testutils/fake_data/index";
3
3
  import { EdgeQuery } from "./query";
4
+ import { MockLogs } from "../../testutils/mock_log";
5
+ import { Clause } from "../clause";
4
6
  interface options<TData extends Data> {
5
7
  newQuery: (v: Viewer, user: FakeUser) => EdgeQuery<FakeUser, FakeContact, TData>;
6
8
  tableName: string;
9
+ uniqKey: string;
10
+ ml: MockLogs;
7
11
  entsLength?: number;
8
- where: string;
12
+ clause: Clause;
9
13
  sortCol: string;
10
14
  livePostgresDB?: boolean;
11
15
  sqlite?: boolean;
16
+ globalSchema?: boolean;
17
+ orderby: "DESC" | "ASC";
18
+ rawDataVerify?(user: FakeUser): Promise<void>;
12
19
  }
13
20
  export declare const commonTests: <TData extends Data>(opts: options<TData>) => void;
14
21
  export {};