@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha150

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 (170) hide show
  1. package/action/action.d.ts +27 -16
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +90 -23
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +3 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +125 -0
  10. package/action/operations.js +684 -0
  11. package/action/orchestrator.d.ts +38 -12
  12. package/action/orchestrator.js +427 -102
  13. package/action/relative_value.d.ts +47 -0
  14. package/action/relative_value.js +125 -0
  15. package/action/transaction.d.ts +10 -0
  16. package/action/transaction.js +23 -0
  17. package/auth/auth.d.ts +1 -1
  18. package/core/base.d.ts +51 -21
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +85 -40
  21. package/core/clause.js +375 -64
  22. package/core/config.d.ts +15 -1
  23. package/core/config.js +10 -1
  24. package/core/const.d.ts +3 -0
  25. package/core/const.js +6 -0
  26. package/core/context.d.ts +4 -2
  27. package/core/context.js +20 -2
  28. package/core/convert.d.ts +1 -1
  29. package/core/date.js +1 -5
  30. package/core/db.d.ts +12 -8
  31. package/core/db.js +18 -8
  32. package/core/ent.d.ts +68 -94
  33. package/core/ent.js +535 -586
  34. package/core/global_schema.d.ts +7 -0
  35. package/core/global_schema.js +51 -0
  36. package/core/loaders/assoc_count_loader.d.ts +1 -0
  37. package/core/loaders/assoc_count_loader.js +10 -2
  38. package/core/loaders/assoc_edge_loader.d.ts +1 -1
  39. package/core/loaders/assoc_edge_loader.js +10 -13
  40. package/core/loaders/index.d.ts +1 -1
  41. package/core/loaders/index.js +1 -3
  42. package/core/loaders/index_loader.d.ts +3 -3
  43. package/core/loaders/loader.d.ts +2 -2
  44. package/core/loaders/loader.js +5 -5
  45. package/core/loaders/object_loader.d.ts +30 -9
  46. package/core/loaders/object_loader.js +225 -78
  47. package/core/loaders/query_loader.d.ts +6 -12
  48. package/core/loaders/query_loader.js +54 -13
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +7 -6
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +3 -2
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +88 -0
  58. package/core/query/custom_query.d.ts +17 -2
  59. package/core/query/custom_query.js +88 -13
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +15 -3
  63. package/core/query/query.js +128 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +44 -54
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +532 -236
  68. package/core/viewer.d.ts +2 -0
  69. package/core/viewer.js +3 -1
  70. package/graphql/graphql.d.ts +52 -19
  71. package/graphql/graphql.js +174 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/shared_assoc_test.js +1 -1
  78. package/graphql/query/shared_edge_connection.js +1 -19
  79. package/graphql/scalars/orderby_direction.d.ts +2 -0
  80. package/graphql/scalars/orderby_direction.js +15 -0
  81. package/imports/dataz/example1/_auth.js +128 -47
  82. package/imports/dataz/example1/_viewer.js +87 -39
  83. package/imports/index.d.ts +7 -2
  84. package/imports/index.js +20 -5
  85. package/index.d.ts +14 -5
  86. package/index.js +26 -10
  87. package/package.json +18 -17
  88. package/parse_schema/parse.d.ts +31 -9
  89. package/parse_schema/parse.js +179 -32
  90. package/schema/base_schema.d.ts +13 -3
  91. package/schema/base_schema.js +13 -0
  92. package/schema/field.d.ts +78 -21
  93. package/schema/field.js +231 -71
  94. package/schema/index.d.ts +2 -2
  95. package/schema/index.js +7 -2
  96. package/schema/json_field.d.ts +16 -4
  97. package/schema/json_field.js +32 -2
  98. package/schema/schema.d.ts +109 -20
  99. package/schema/schema.js +42 -53
  100. package/schema/struct_field.d.ts +15 -3
  101. package/schema/struct_field.js +117 -22
  102. package/schema/union_field.d.ts +1 -1
  103. package/scripts/custom_compiler.js +12 -8
  104. package/scripts/custom_graphql.js +145 -34
  105. package/scripts/migrate_v0.1.js +36 -0
  106. package/scripts/move_types.js +120 -0
  107. package/scripts/read_schema.js +22 -7
  108. package/testutils/action/complex_schemas.d.ts +69 -0
  109. package/testutils/action/complex_schemas.js +405 -0
  110. package/testutils/builder.d.ts +39 -43
  111. package/testutils/builder.js +75 -49
  112. package/testutils/db/fixture.d.ts +10 -0
  113. package/testutils/db/fixture.js +26 -0
  114. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  115. package/testutils/db/{test_db.js → temp_db.js} +244 -48
  116. package/testutils/db/value.d.ts +7 -0
  117. package/testutils/db/value.js +251 -0
  118. package/testutils/db_mock.d.ts +16 -4
  119. package/testutils/db_mock.js +52 -9
  120. package/testutils/db_time_zone.d.ts +4 -0
  121. package/testutils/db_time_zone.js +41 -0
  122. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  123. package/testutils/ent-graphql-tests/index.js +56 -26
  124. package/testutils/fake_comms.js +1 -1
  125. package/testutils/fake_data/const.d.ts +2 -1
  126. package/testutils/fake_data/const.js +3 -0
  127. package/testutils/fake_data/fake_contact.d.ts +7 -3
  128. package/testutils/fake_data/fake_contact.js +13 -7
  129. package/testutils/fake_data/fake_event.d.ts +4 -1
  130. package/testutils/fake_data/fake_event.js +7 -6
  131. package/testutils/fake_data/fake_tag.d.ts +36 -0
  132. package/testutils/fake_data/fake_tag.js +89 -0
  133. package/testutils/fake_data/fake_user.d.ts +8 -5
  134. package/testutils/fake_data/fake_user.js +16 -15
  135. package/testutils/fake_data/index.js +5 -1
  136. package/testutils/fake_data/internal.d.ts +2 -0
  137. package/testutils/fake_data/internal.js +7 -1
  138. package/testutils/fake_data/tag_query.d.ts +13 -0
  139. package/testutils/fake_data/tag_query.js +43 -0
  140. package/testutils/fake_data/test_helpers.d.ts +11 -4
  141. package/testutils/fake_data/test_helpers.js +29 -13
  142. package/testutils/fake_data/user_query.d.ts +11 -4
  143. package/testutils/fake_data/user_query.js +54 -22
  144. package/testutils/fake_log.js +1 -1
  145. package/testutils/parse_sql.d.ts +6 -0
  146. package/testutils/parse_sql.js +16 -2
  147. package/testutils/test_edge_global_schema.d.ts +15 -0
  148. package/testutils/test_edge_global_schema.js +62 -0
  149. package/testutils/write.d.ts +2 -2
  150. package/testutils/write.js +33 -7
  151. package/tsc/ast.d.ts +25 -2
  152. package/tsc/ast.js +141 -17
  153. package/tsc/compilerOptions.js +5 -1
  154. package/tsc/move_generated.d.ts +1 -0
  155. package/tsc/move_generated.js +164 -0
  156. package/tsc/transform.d.ts +22 -0
  157. package/tsc/transform.js +182 -0
  158. package/tsc/transform_action.d.ts +22 -0
  159. package/tsc/transform_action.js +183 -0
  160. package/tsc/transform_ent.d.ts +17 -0
  161. package/tsc/transform_ent.js +60 -0
  162. package/tsc/transform_schema.d.ts +27 -0
  163. package/{scripts → tsc}/transform_schema.js +146 -117
  164. package/graphql/enums.d.ts +0 -3
  165. package/graphql/enums.js +0 -25
  166. package/scripts/move_generated.js +0 -142
  167. package/scripts/transform_code.js +0 -113
  168. package/scripts/transform_schema.d.ts +0 -1
  169. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  170. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.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,42 @@ 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
+ let nullsPlacement = "";
103
+ if (this.options.nullsPlacement) {
104
+ if (this.options.nullsPlacement === "first") {
105
+ nullsPlacement = " NULLS FIRST";
98
106
  }
99
107
  else {
100
- options.clause = clause.Less(this.sortCol, new Date(this.offset).toISOString());
108
+ nullsPlacement = " NULLS LAST";
109
+ }
110
+ }
111
+ if (this.options.cursorCol !== this.sortCol) {
112
+ // we also sort unique col in same direction since it doesn't matter...
113
+ // nulls placement only affects sortCol. assumption is cursorCol will not be null and no need for that
114
+ options.orderby = `${this.sortCol} ${orderby}${nullsPlacement}, ${this.options.cursorCol} ${orderby}`;
115
+ if (this.offset) {
116
+ const res = this.edgeQuery.getTableName();
117
+ const tableName = util_1.types.isPromise(res) ? await res : res;
118
+ // inner col time
119
+ options.clause = clause.PaginationMultipleColsSubQuery(this.sortCol, less ? "<" : ">", tableName, this.options.cursorCol, this.offset);
120
+ }
121
+ }
122
+ else {
123
+ options.orderby = `${this.sortCol}${nullsPlacement} ${orderby}`;
124
+ if (this.offset) {
125
+ let clauseFn = less ? clause.Less : clause.Greater;
126
+ let val = this.options.sortColTime
127
+ ? new Date(this.offset).toISOString()
128
+ : this.offset;
129
+ options.clause = clauseFn(this.sortCol, val);
101
130
  }
102
131
  }
103
132
  return options;
@@ -112,15 +141,9 @@ class LastFilter {
112
141
  this.options = options;
113
142
  this.pageMap = new Map();
114
143
  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";
144
+ this.sortCol = options.sortCol;
119
145
  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`);
146
+ this.offset = assertValidCursor(options.before, options.cursorCol);
124
147
  }
125
148
  this.edgeQuery = options.query;
126
149
  }
@@ -137,11 +160,13 @@ class LastFilter {
137
160
  }
138
161
  }
139
162
  else {
140
- ret = edges.slice(edges.length - this.options.limit, edges.length);
163
+ ret = edges.slice(0, this.options.limit);
141
164
  }
142
165
  if (edges.length > this.options.limit) {
143
166
  this.pageMap.set(id, {
144
167
  hasPreviousPage: true,
168
+ // hasNextPage always false even if there's a next page because
169
+ // we shouldn't be querying in both directions at the same
145
170
  hasNextPage: false,
146
171
  startCursor: this.edgeQuery.getCursor(ret[0]),
147
172
  endCursor: this.edgeQuery.getCursor(ret[ret.length - 1]),
@@ -149,17 +174,39 @@ class LastFilter {
149
174
  }
150
175
  return ret;
151
176
  }
152
- query(options) {
153
- if (!this.offset) {
154
- return options;
177
+ async query(options) {
178
+ // assume desc by default
179
+ // so last is reverse
180
+ let orderby = "ASC";
181
+ if (this.options.defaultDirection) {
182
+ // reverse sort col shown...
183
+ if (this.options.defaultDirection === "DESC") {
184
+ orderby = "ASC";
185
+ }
186
+ else {
187
+ orderby = "DESC";
188
+ }
155
189
  }
156
- options.orderby = `${this.sortCol} ASC`;
190
+ const greater = orderby === "ASC";
157
191
  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);
192
+ if (this.options.cursorCol !== this.sortCol) {
193
+ const res = this.edgeQuery.getTableName();
194
+ const tableName = util_1.types.isPromise(res) ? await res : res;
195
+ if (this.offset) {
196
+ // inner col time
197
+ options.clause = clause.PaginationMultipleColsSubQuery(this.sortCol, greater ? ">" : "<", tableName, this.options.cursorCol, this.offset);
198
+ }
199
+ options.orderby = `${this.sortCol} ${orderby}, ${this.options.cursorCol} ${orderby}`;
160
200
  }
161
201
  else {
162
- options.clause = clause.Greater(this.sortCol, new Date(this.offset).toISOString());
202
+ options.orderby = `${this.sortCol} ${orderby}`;
203
+ if (this.offset) {
204
+ let clauseFn = greater ? clause.Greater : clause.Less;
205
+ let val = this.options.sortColTime
206
+ ? new Date(this.offset).toISOString()
207
+ : this.offset;
208
+ options.clause = clauseFn(this.sortCol, val);
209
+ }
163
210
  }
164
211
  return options;
165
212
  }
@@ -168,9 +215,8 @@ class LastFilter {
168
215
  }
169
216
  }
170
217
  class BaseEdgeQuery {
171
- constructor(viewer, sortCol) {
218
+ constructor(viewer, sortColOrOptions, cursorColMaybe) {
172
219
  this.viewer = viewer;
173
- this.sortCol = sortCol;
174
220
  this.filters = [];
175
221
  this.edges = new Map();
176
222
  this.pagination = new Map();
@@ -226,9 +272,41 @@ class BaseEdgeQuery {
226
272
  await Promise.all(promises);
227
273
  return results;
228
274
  };
275
+ let sortCol;
276
+ let cursorCol;
277
+ if (typeof sortColOrOptions === "string") {
278
+ sortCol = sortColOrOptions;
279
+ cursorCol = cursorColMaybe;
280
+ this.edgeQueryOptions = {
281
+ cursorCol,
282
+ sortCol,
283
+ };
284
+ }
285
+ else {
286
+ sortCol = sortColOrOptions.sortCol;
287
+ cursorCol = sortColOrOptions.cursorCol;
288
+ this.edgeQueryOptions = sortColOrOptions;
289
+ }
290
+ let m = orderbyRegex.exec(sortCol);
291
+ if (!m) {
292
+ throw new Error(`invalid sort column ${sortCol}`);
293
+ }
294
+ this.sortCol = m[1];
295
+ if (m[2]) {
296
+ // @ts-ignore
297
+ this.defaultDirection = m[2].toUpperCase();
298
+ }
299
+ let m2 = orderbyRegex.exec(cursorCol);
300
+ if (!m2) {
301
+ throw new Error(`invalid sort column ${cursorCol}`);
302
+ }
303
+ this.cursorCol = m2[1];
229
304
  this.memoizedloadEdges = (0, memoizee_1.default)(this.loadEdges.bind(this));
230
305
  this.genIDInfosToFetch = (0, memoizee_1.default)(this.genIDInfosToFetchImpl.bind(this));
231
306
  }
307
+ getSortCol() {
308
+ return this.sortCol;
309
+ }
232
310
  getPrivacyPolicy() {
233
311
  // default PrivacyPolicy is always allow. nothing to do here
234
312
  return privacy_1.AlwaysAllowPrivacyPolicy;
@@ -239,6 +317,9 @@ class BaseEdgeQuery {
239
317
  limit: n,
240
318
  after,
241
319
  sortCol: this.sortCol,
320
+ cursorCol: this.cursorCol,
321
+ defaultDirection: this.defaultDirection,
322
+ nullsPlacement: this.edgeQueryOptions.nullsPlacement,
242
323
  query: this,
243
324
  }));
244
325
  return this;
@@ -249,6 +330,9 @@ class BaseEdgeQuery {
249
330
  limit: n,
250
331
  before,
251
332
  sortCol: this.sortCol,
333
+ cursorCol: this.cursorCol,
334
+ defaultDirection: this.defaultDirection,
335
+ nullsPlacement: this.edgeQueryOptions.nullsPlacement,
252
336
  query: this,
253
337
  }));
254
338
  return this;
@@ -294,17 +378,18 @@ class BaseEdgeQuery {
294
378
  const idsInfo = await this.genIDInfosToFetch();
295
379
  if (!this.filters.length) {
296
380
  // if no filter, we add the firstN filter to ensure we get pagination info
297
- this.first(ent_1.DefaultLimit);
381
+ this.first((0, ent_1.getDefaultLimit)());
298
382
  }
299
383
  let options = {};
300
384
  // TODO once we add a lot of complex filters, this needs to be more complicated
301
385
  // e.g. commutative filters. what can be done in sql or combined together etc
302
386
  // may need to bring sql mode or something back
303
- this.filters.forEach((filter) => {
387
+ for (const filter of this.filters) {
304
388
  if (filter.query) {
305
- options = filter.query(options);
389
+ let res = filter.query(options);
390
+ options = util_1.types.isPromise(res) ? await res : res;
306
391
  }
307
- });
392
+ }
308
393
  await this.loadRawData(idsInfo, options);
309
394
  // no filters. nothing to do here.
310
395
  if (!this.filters.length) {
@@ -331,17 +416,7 @@ class BaseEdgeQuery {
331
416
  getCursor(row) {
332
417
  return (0, ent_1.getCursor)({
333
418
  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
- },
419
+ col: this.cursorCol,
345
420
  });
346
421
  }
347
422
  }
@@ -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
  }
70
- 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);
51
+ function getWhereClause(query) {
52
+ let execArray = /^SELECT (.+) FROM (.+) WHERE (.+)?/.exec(query.query);
53
+ return execArray?.[3];
54
+ }
55
+ function verifyQuery({ length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, }) {
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])));
@@ -127,7 +118,7 @@ function assocTests() {
127
118
  verifyQuery({
128
119
  length: this.dataz.length,
129
120
  numQueries: this.dataz.length,
130
- limit: this.limit || ent_1.DefaultLimit,
121
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
131
122
  });
132
123
  }
133
124
  // rawCount isn't affected by filters...
@@ -150,7 +141,7 @@ function assocTests() {
150
141
  verifyQuery({
151
142
  length: this.dataz.length,
152
143
  numQueries: this.dataz.length,
153
- limit: this.limit || ent_1.DefaultLimit,
144
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
154
145
  });
155
146
  }
156
147
  async testEdges() {
@@ -163,7 +154,7 @@ function assocTests() {
163
154
  verifyQuery({
164
155
  length: this.dataz.length,
165
156
  numQueries: this.dataz.length,
166
- limit: this.limit || ent_1.DefaultLimit,
157
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
167
158
  });
168
159
  }
169
160
  async testEnts() {
@@ -187,7 +178,7 @@ function assocTests() {
187
178
  // and then twice to fetch all the nodes for the contacts
188
179
  length: this.dataz.length + this.dataz.length + this.dataz.length * 2,
189
180
  numQueries: this.dataz.length,
190
- limit: this.limit || ent_1.DefaultLimit,
181
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
191
182
  });
192
183
  }
193
184
  }
@@ -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));
@@ -473,7 +464,7 @@ function assocTests() {
473
464
  verifyQuery({
474
465
  length: 1,
475
466
  numQueries: 1,
476
- limit: this.limit || ent_1.DefaultLimit,
467
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
477
468
  });
478
469
  }
479
470
  // rawCount isn't affected by filters...
@@ -488,7 +479,7 @@ function assocTests() {
488
479
  verifyQuery({
489
480
  length: 1,
490
481
  numQueries: 1,
491
- limit: this.limit || ent_1.DefaultLimit,
482
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
492
483
  });
493
484
  }
494
485
  async testEdges() {
@@ -509,7 +500,7 @@ function assocTests() {
509
500
  verifyQuery({
510
501
  length: 1,
511
502
  numQueries: 1,
512
- limit: this.limit || ent_1.DefaultLimit,
503
+ limit: this.limit || (0, ent_1.getDefaultLimit)(),
513
504
  });
514
505
  }
515
506
  async testEnts() {
@@ -533,7 +524,7 @@ function assocTests() {
533
524
  // // 1 for edges, 1 for users, 1 for events
534
525
  // length: 3,
535
526
  // numQueries: 3,
536
- // limit: this.limit || DefaultLimit,
527
+ // limit: this.limit || getDefaultLimit(),
537
528
  // });
538
529
  }
539
530
  }
@@ -619,10 +610,9 @@ function assocTests() {
619
610
  let user;
620
611
  let friendRequests;
621
612
  let user2;
622
- let friendRequests2;
623
613
  beforeEach(async () => {
624
614
  [user, friendRequests] = await (0, test_helpers_1.createUserPlusFriendRequests)();
625
- [user2, friendRequests2] = await (0, test_helpers_1.createUserPlusFriendRequests)();
615
+ [user2] = await (0, test_helpers_1.createUserPlusFriendRequests)();
626
616
  });
627
617
  function getQuery(viewer) {
628
618
  return index_1.UserToIncomingFriendRequestsQuery.query(viewer || user.viewer, [
@@ -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 {};