@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha151

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 (171) 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 +52 -21
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +95 -40
  21. package/core/clause.js +395 -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 +538 -587
  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.d.ts +1 -0
  50. package/core/loaders/raw_count_loader.js +7 -2
  51. package/core/logger.d.ts +1 -1
  52. package/core/logger.js +1 -0
  53. package/core/privacy.d.ts +7 -6
  54. package/core/privacy.js +21 -25
  55. package/core/query/assoc_query.d.ts +3 -2
  56. package/core/query/assoc_query.js +9 -1
  57. package/core/query/custom_clause_query.d.ts +27 -0
  58. package/core/query/custom_clause_query.js +88 -0
  59. package/core/query/custom_query.d.ts +17 -2
  60. package/core/query/custom_query.js +88 -13
  61. package/core/query/index.d.ts +1 -0
  62. package/core/query/index.js +3 -1
  63. package/core/query/query.d.ts +15 -3
  64. package/core/query/query.js +128 -53
  65. package/core/query/shared_assoc_test.d.ts +2 -1
  66. package/core/query/shared_assoc_test.js +44 -54
  67. package/core/query/shared_test.d.ts +8 -1
  68. package/core/query/shared_test.js +532 -236
  69. package/core/viewer.d.ts +2 -0
  70. package/core/viewer.js +3 -1
  71. package/graphql/graphql.d.ts +52 -19
  72. package/graphql/graphql.js +174 -136
  73. package/graphql/graphql_field_helpers.d.ts +7 -1
  74. package/graphql/graphql_field_helpers.js +21 -1
  75. package/graphql/index.d.ts +2 -2
  76. package/graphql/index.js +3 -5
  77. package/graphql/query/connection_type.d.ts +9 -9
  78. package/graphql/query/shared_assoc_test.js +1 -1
  79. package/graphql/query/shared_edge_connection.js +1 -19
  80. package/graphql/scalars/orderby_direction.d.ts +2 -0
  81. package/graphql/scalars/orderby_direction.js +15 -0
  82. package/imports/dataz/example1/_auth.js +128 -47
  83. package/imports/dataz/example1/_viewer.js +87 -39
  84. package/imports/index.d.ts +7 -2
  85. package/imports/index.js +20 -5
  86. package/index.d.ts +18 -5
  87. package/index.js +30 -10
  88. package/package.json +18 -17
  89. package/parse_schema/parse.d.ts +31 -9
  90. package/parse_schema/parse.js +179 -32
  91. package/schema/base_schema.d.ts +13 -3
  92. package/schema/base_schema.js +13 -0
  93. package/schema/field.d.ts +78 -21
  94. package/schema/field.js +231 -71
  95. package/schema/index.d.ts +2 -2
  96. package/schema/index.js +7 -2
  97. package/schema/json_field.d.ts +16 -4
  98. package/schema/json_field.js +32 -2
  99. package/schema/schema.d.ts +109 -20
  100. package/schema/schema.js +42 -53
  101. package/schema/struct_field.d.ts +15 -3
  102. package/schema/struct_field.js +117 -22
  103. package/schema/union_field.d.ts +1 -1
  104. package/scripts/custom_compiler.js +12 -8
  105. package/scripts/custom_graphql.js +145 -34
  106. package/scripts/migrate_v0.1.js +36 -0
  107. package/scripts/move_types.js +120 -0
  108. package/scripts/read_schema.js +22 -7
  109. package/testutils/action/complex_schemas.d.ts +69 -0
  110. package/testutils/action/complex_schemas.js +405 -0
  111. package/testutils/builder.d.ts +39 -43
  112. package/testutils/builder.js +75 -49
  113. package/testutils/db/fixture.d.ts +10 -0
  114. package/testutils/db/fixture.js +26 -0
  115. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  116. package/testutils/db/{test_db.js → temp_db.js} +244 -48
  117. package/testutils/db/value.d.ts +7 -0
  118. package/testutils/db/value.js +251 -0
  119. package/testutils/db_mock.d.ts +16 -4
  120. package/testutils/db_mock.js +52 -9
  121. package/testutils/db_time_zone.d.ts +4 -0
  122. package/testutils/db_time_zone.js +41 -0
  123. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  124. package/testutils/ent-graphql-tests/index.js +56 -26
  125. package/testutils/fake_comms.js +1 -1
  126. package/testutils/fake_data/const.d.ts +2 -1
  127. package/testutils/fake_data/const.js +3 -0
  128. package/testutils/fake_data/fake_contact.d.ts +7 -3
  129. package/testutils/fake_data/fake_contact.js +13 -7
  130. package/testutils/fake_data/fake_event.d.ts +4 -1
  131. package/testutils/fake_data/fake_event.js +7 -6
  132. package/testutils/fake_data/fake_tag.d.ts +36 -0
  133. package/testutils/fake_data/fake_tag.js +89 -0
  134. package/testutils/fake_data/fake_user.d.ts +8 -5
  135. package/testutils/fake_data/fake_user.js +16 -15
  136. package/testutils/fake_data/index.js +5 -1
  137. package/testutils/fake_data/internal.d.ts +2 -0
  138. package/testutils/fake_data/internal.js +7 -1
  139. package/testutils/fake_data/tag_query.d.ts +13 -0
  140. package/testutils/fake_data/tag_query.js +43 -0
  141. package/testutils/fake_data/test_helpers.d.ts +11 -4
  142. package/testutils/fake_data/test_helpers.js +29 -13
  143. package/testutils/fake_data/user_query.d.ts +11 -4
  144. package/testutils/fake_data/user_query.js +54 -22
  145. package/testutils/fake_log.js +1 -1
  146. package/testutils/parse_sql.d.ts +6 -0
  147. package/testutils/parse_sql.js +16 -2
  148. package/testutils/test_edge_global_schema.d.ts +15 -0
  149. package/testutils/test_edge_global_schema.js +62 -0
  150. package/testutils/write.d.ts +2 -2
  151. package/testutils/write.js +33 -7
  152. package/tsc/ast.d.ts +25 -2
  153. package/tsc/ast.js +141 -17
  154. package/tsc/compilerOptions.js +5 -1
  155. package/tsc/move_generated.d.ts +1 -0
  156. package/tsc/move_generated.js +164 -0
  157. package/tsc/transform.d.ts +22 -0
  158. package/tsc/transform.js +182 -0
  159. package/tsc/transform_action.d.ts +22 -0
  160. package/tsc/transform_action.js +183 -0
  161. package/tsc/transform_ent.d.ts +17 -0
  162. package/tsc/transform_ent.js +60 -0
  163. package/tsc/transform_schema.d.ts +27 -0
  164. package/{scripts → tsc}/transform_schema.js +146 -117
  165. package/graphql/enums.d.ts +0 -3
  166. package/graphql/enums.js +0 -25
  167. package/scripts/move_generated.js +0 -142
  168. package/scripts/transform_code.js +0 -113
  169. package/scripts/transform_schema.d.ts +0 -1
  170. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  171. /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];
@@ -22,13 +26,66 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ObjectLoaderFactory = exports.ObjectLoader = void 0;
29
+ exports.ObjectLoaderFactory = exports.ObjectCountLoader = exports.ObjectLoader = void 0;
26
30
  const dataloader_1 = __importDefault(require("dataloader"));
27
31
  const ent_1 = require("../ent");
28
32
  const clause = __importStar(require("../clause"));
29
33
  const logger_1 = require("../logger");
34
+ const clause_1 = require("../clause");
30
35
  const loader_1 = require("./loader");
31
36
  const memoizee_1 = __importDefault(require("memoizee"));
37
+ async function loadRowsForIDLoader(options, ids, context) {
38
+ let col = options.key;
39
+ const cls = (0, clause_1.getCombinedClause)(options, clause.DBTypeIn(col, ids, options.keyType || "uuid"));
40
+ const rowOptions = {
41
+ ...options,
42
+ clause: cls,
43
+ context,
44
+ };
45
+ let m = new Map();
46
+ let result = [];
47
+ for (let i = 0; i < ids.length; i++) {
48
+ result.push(null);
49
+ // store the index....
50
+ m.set(ids[i], i);
51
+ }
52
+ const rows = (await (0, ent_1.loadRows)(rowOptions));
53
+ for (const row of rows) {
54
+ const id = row[col];
55
+ if (id === undefined) {
56
+ throw new Error(`need to query for column ${col} when using an object loader because the query may not be sorted and we need the id to maintain sort order`);
57
+ }
58
+ const idx = m.get(id);
59
+ if (idx === undefined) {
60
+ throw new Error(`malformed query. got ${id} back but didn't query for it`);
61
+ }
62
+ result[idx] = row;
63
+ }
64
+ return result;
65
+ }
66
+ async function loadRowsForClauseLoader(options, clause) {
67
+ const rowOptions = {
68
+ ...options,
69
+ // @ts-expect-error clause in LoadRowOptions doesn't take templatized version of Clause
70
+ clause: (0, clause_1.getCombinedClause)(options, clause),
71
+ };
72
+ return (await (0, ent_1.loadRows)(rowOptions));
73
+ }
74
+ async function loadCountForClauseLoader(options, clause) {
75
+ const rowOptions = {
76
+ ...options,
77
+ // @ts-expect-error clause in LoadRowOptions doesn't take templatized version of Clause
78
+ clause: (0, clause_1.getCombinedClause)(options, clause),
79
+ };
80
+ const row = await (0, ent_1.loadRow)({
81
+ ...rowOptions,
82
+ fields: ["count(*) as count"],
83
+ });
84
+ if (!row) {
85
+ return 0;
86
+ }
87
+ return parseInt(row.count, 10);
88
+ }
32
89
  // optional clause...
33
90
  // so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
34
91
  // and we need a disableTransform which skips loader completely and uses loadRow...
@@ -42,43 +99,66 @@ function createDataLoader(options) {
42
99
  if (!ids.length) {
43
100
  return [];
44
101
  }
45
- let col = options.key;
46
- let cls = clause.In(col, ...ids);
47
- if (options.clause) {
48
- let optionClause;
49
- if (typeof options.clause === "function") {
50
- optionClause = options.clause();
51
- }
52
- else {
53
- optionClause = options.clause;
54
- }
55
- if (optionClause) {
56
- cls = clause.And(optionClause, cls);
57
- }
102
+ // context not needed because we're creating a loader which has its own cache which is being used here
103
+ return loadRowsForIDLoader(options, ids);
104
+ }, loaderOptions);
105
+ }
106
+ class clauseCacheMap {
107
+ constructor(options, count) {
108
+ this.options = options;
109
+ this.count = count;
110
+ this.m = new Map();
111
+ }
112
+ get(key) {
113
+ const key2 = key.instanceKey();
114
+ const ret = this.m.get(key2);
115
+ if (ret) {
116
+ (0, logger_1.log)("cache", {
117
+ "dataloader-cache-hit": key2 + (this.count ? ":count" : ""),
118
+ "tableName": this.options.tableName,
119
+ });
58
120
  }
59
- const rowOptions = {
60
- ...options,
61
- clause: cls,
62
- };
63
- let m = new Map();
64
- let result = [];
65
- for (let i = 0; i < ids.length; i++) {
66
- result.push(null);
67
- // store the index....
68
- m.set(ids[i], i);
121
+ return ret;
122
+ }
123
+ set(key, value) {
124
+ return this.m.set(key.instanceKey(), value);
125
+ }
126
+ delete(key) {
127
+ return this.m.delete(key.instanceKey());
128
+ }
129
+ clear() {
130
+ return this.m.clear();
131
+ }
132
+ }
133
+ function createClauseDataLoder(options) {
134
+ return new dataloader_1.default(async (clauses) => {
135
+ if (!clauses.length) {
136
+ return [];
69
137
  }
70
- // context not needed because we're creating a loader which has its own cache which is being used here
71
- const rows = await (0, ent_1.loadRows)(rowOptions);
72
- for (const row of rows) {
73
- const id = row[col];
74
- const idx = m.get(id);
75
- if (idx === undefined) {
76
- throw new Error(`malformed query. got ${id} back but didn't query for it`);
77
- }
78
- result[idx] = row;
138
+ const ret = [];
139
+ for await (const clause of clauses) {
140
+ const data = await loadRowsForClauseLoader(options, clause);
141
+ ret.push(data);
79
142
  }
80
- return result;
81
- }, loaderOptions);
143
+ return ret;
144
+ }, {
145
+ cacheMap: new clauseCacheMap(options),
146
+ });
147
+ }
148
+ function createClauseCountDataLoader(options) {
149
+ return new dataloader_1.default(async (clauses) => {
150
+ if (!clauses.length) {
151
+ return [];
152
+ }
153
+ const ret = [];
154
+ for await (const clause of clauses) {
155
+ const data = await loadCountForClauseLoader(options, clause);
156
+ ret.push(data);
157
+ }
158
+ return ret;
159
+ }, {
160
+ cacheMap: new clauseCacheMap(options, true),
161
+ });
82
162
  }
83
163
  class ObjectLoader {
84
164
  constructor(options, context, toPrime) {
@@ -89,7 +169,8 @@ class ObjectLoader {
89
169
  console.trace();
90
170
  }
91
171
  if (context) {
92
- this.loader = createDataLoader(options);
172
+ this.idLoader = createDataLoader(options);
173
+ this.clauseLoader = createClauseDataLoder(options);
93
174
  }
94
175
  this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
95
176
  }
@@ -111,11 +192,17 @@ class ObjectLoader {
111
192
  this.primedLoaders = primedLoaders;
112
193
  }
113
194
  async load(key) {
195
+ if (typeof key === "string" || typeof key === "number") {
196
+ return this.loadID(key);
197
+ }
198
+ return this.loadClause(key);
199
+ }
200
+ async loadID(key) {
114
201
  // simple case. we get parallelization etc
115
- if (this.loader) {
202
+ if (this.idLoader) {
116
203
  this.memoizedInitPrime();
117
204
  // prime the result if we got primable loaders
118
- const result = await this.loader.load(key);
205
+ const result = await this.idLoader.load(key);
119
206
  if (result && this.primedLoaders) {
120
207
  for (const [key, loader] of this.primedLoaders) {
121
208
  const value = result[key];
@@ -126,69 +213,119 @@ class ObjectLoader {
126
213
  }
127
214
  return result;
128
215
  }
129
- let cls = clause.Eq(this.options.key, key);
130
- if (this.options.clause) {
131
- let optionClause;
132
- if (typeof this.options.clause === "function") {
133
- optionClause = this.options.clause();
134
- }
135
- else {
136
- optionClause = this.options.clause;
137
- }
138
- if (optionClause) {
139
- cls = clause.And(optionClause, cls);
140
- }
141
- }
216
+ const cls = (0, clause_1.getCombinedClause)(this.options, clause.Eq(this.options.key, key));
142
217
  const rowOptions = {
143
218
  ...this.options,
144
219
  clause: cls,
145
220
  context: this.context,
146
221
  };
147
- return await (0, ent_1.loadRow)(rowOptions);
222
+ return (0, ent_1.loadRow)(rowOptions);
223
+ }
224
+ async loadClause(key) {
225
+ if (this.clauseLoader) {
226
+ return this.clauseLoader.load(key);
227
+ }
228
+ return loadRowsForClauseLoader(this.options, key);
148
229
  }
149
230
  clearAll() {
150
- this.loader && this.loader.clearAll();
231
+ this.idLoader && this.idLoader.clearAll();
232
+ this.clauseLoader && this.clauseLoader.clearAll();
151
233
  }
152
234
  async loadMany(keys) {
153
- if (this.loader) {
154
- return await this.loader.loadMany(keys);
235
+ if (!keys.length) {
236
+ return [];
155
237
  }
156
- let cls = clause.In(this.options.key, ...keys);
157
- if (this.options.clause) {
158
- let optionClause;
159
- if (typeof this.options.clause === "function") {
160
- optionClause = this.options.clause();
161
- }
162
- else {
163
- optionClause = this.options.clause;
164
- }
165
- if (optionClause) {
166
- cls = clause.And(optionClause, cls);
167
- }
238
+ if (typeof keys[0] === "string" || typeof keys[0] === "number") {
239
+ return this.loadIDMany(keys);
168
240
  }
169
- const rowOptions = {
170
- ...this.options,
171
- clause: cls,
172
- context: this.context,
173
- };
174
- return await (0, ent_1.loadRows)(rowOptions);
241
+ return this.loadClauseMany(keys);
242
+ }
243
+ loadIDMany(keys) {
244
+ if (this.idLoader) {
245
+ // @ts-expect-error TODO?
246
+ return this.idLoader.loadMany(keys);
247
+ }
248
+ return loadRowsForIDLoader(this.options, keys, this.context);
249
+ }
250
+ async loadClauseMany(keys) {
251
+ if (this.clauseLoader) {
252
+ // @ts-expect-error TODO?
253
+ return this.clauseLoader.loadMany(keys);
254
+ }
255
+ const res = [];
256
+ for await (const key of keys) {
257
+ const rows = await loadRowsForClauseLoader(this.options, key);
258
+ res.push(rows);
259
+ }
260
+ return res;
175
261
  }
176
262
  prime(data) {
177
263
  // we have this data from somewhere else, prime it in the c
178
- if (this.loader) {
264
+ if (this.idLoader) {
179
265
  const col = this.options.key;
180
266
  const key = data[col];
181
- this.loader.prime(key, data);
267
+ this.idLoader.prime(key, data);
268
+ }
269
+ }
270
+ // prime this loader and any other loaders it's aware of
271
+ primeAll(data) {
272
+ this.prime(data);
273
+ if (this.primedLoaders) {
274
+ for (const [key, loader] of this.primedLoaders) {
275
+ const value = data[key];
276
+ if (value !== undefined) {
277
+ loader.prime(data);
278
+ }
279
+ }
182
280
  }
183
281
  }
184
282
  }
185
283
  exports.ObjectLoader = ObjectLoader;
284
+ class ObjectCountLoader {
285
+ constructor(options, context) {
286
+ this.options = options;
287
+ this.context = context;
288
+ if (context) {
289
+ this.loader = createClauseCountDataLoader(options);
290
+ }
291
+ }
292
+ getOptions() {
293
+ return this.options;
294
+ }
295
+ async load(key) {
296
+ if (this.loader) {
297
+ return this.loader.load(key);
298
+ }
299
+ return loadCountForClauseLoader(this.options, key);
300
+ }
301
+ clearAll() {
302
+ this.loader && this.loader.clearAll();
303
+ }
304
+ async loadMany(keys) {
305
+ if (!keys.length) {
306
+ return [];
307
+ }
308
+ if (this.loader) {
309
+ // @ts-expect-error
310
+ return this.loader.loadMany(keys);
311
+ }
312
+ const res = [];
313
+ for await (const key of keys) {
314
+ const r = await loadCountForClauseLoader(this.options, key);
315
+ res.push(r);
316
+ }
317
+ return res;
318
+ }
319
+ }
320
+ exports.ObjectCountLoader = ObjectCountLoader;
321
+ // NOTE: if not querying for all columns
322
+ // have to query for the id field as one of the fields
323
+ // because it's used to maintain sort order of the queried ids
186
324
  class ObjectLoaderFactory {
187
325
  constructor(options) {
188
326
  this.options = options;
189
327
  this.toPrime = [];
190
- // we don't wanna do it here because we want it to be delayed
191
- let instanceKey = "";
328
+ let instanceKey = options.instanceKey || "";
192
329
  if (typeof this.options.clause === "function") {
193
330
  if (!options.instanceKey) {
194
331
  throw new Error(`need to pass an instanceKey to ObjectLoader if clause is a function`);
@@ -204,10 +341,20 @@ class ObjectLoaderFactory {
204
341
  return new ObjectLoader(this.options, context, this.toPrime);
205
342
  }, context);
206
343
  }
344
+ createTypedLoader(context) {
345
+ const loader = this.createLoader(context);
346
+ return loader;
347
+ }
348
+ createCountLoader(context) {
349
+ return (0, loader_1.getCustomLoader)(`${this.name}:count_loader`, () => {
350
+ return new ObjectCountLoader(this.options, context);
351
+ }, context);
352
+ }
207
353
  // keep track of loaders to prime. needs to be done not in the constructor
208
354
  // because there's usually self references here
209
355
  addToPrime(factory) {
210
356
  this.toPrime.push(factory);
357
+ return this;
211
358
  }
212
359
  }
213
360
  exports.ObjectLoaderFactory = ObjectLoaderFactory;
@@ -1,21 +1,14 @@
1
1
  import { Context, ID, EdgeQueryableDataOptions, Loader, LoaderFactory, Data } from "../base";
2
2
  import * as clause from "../clause";
3
3
  import { ObjectLoaderFactory } from "./object_loader";
4
- export declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
4
+ export declare function getOrderBy(sortCol: string, orderby?: string): string;
5
+ declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
5
6
  private options;
6
7
  private queryOptions?;
7
- constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined);
8
- load(id: K): Promise<Data[]>;
9
- clearAll(): void;
10
- }
11
- export declare class QueryLoader<K extends any> implements Loader<K, Data[]> {
12
- private options;
13
8
  context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
14
- private queryOptions?;
15
- private loader;
16
- private primedLoaders;
17
9
  private memoizedInitPrime;
18
- constructor(options: QueryOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "limit" | "orderby" | "clause">> | undefined);
10
+ private primedLoaders;
11
+ constructor(options: QueryOptions, queryOptions?: Partial<Pick<import("../base").QueryableDataOptions, "clause" | "limit" | "orderby">> | undefined, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
19
12
  private initPrime;
20
13
  load(id: K): Promise<Data[]>;
21
14
  clearAll(): void;
@@ -26,7 +19,7 @@ interface QueryOptions {
26
19
  groupCol?: string;
27
20
  clause?: clause.Clause;
28
21
  sortColumn?: string;
29
- toPrime?: ObjectLoaderFactory<ID>[];
22
+ toPrime?: ObjectLoaderFactory<Data>[];
30
23
  }
31
24
  export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<K, Data[]> {
32
25
  private options;
@@ -34,5 +27,6 @@ export declare class QueryLoaderFactory<K extends any> implements LoaderFactory<
34
27
  constructor(options: QueryOptions);
35
28
  createLoader(context?: Context): any;
36
29
  createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<unknown, Data[]> | QueryDirectLoader<unknown>;
30
+ static createConfigurableLoader(name: string, queryOptions: QueryOptions, options: EdgeQueryableDataOptions, context?: Context): Loader<unknown, Data[]> | QueryDirectLoader<unknown>;
37
31
  }
38
32
  export {};
@@ -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];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.QueryLoaderFactory = exports.QueryLoader = exports.QueryDirectLoader = void 0;
29
+ exports.QueryLoaderFactory = exports.getOrderBy = void 0;
26
30
  const dataloader_1 = __importDefault(require("dataloader"));
27
31
  const ent_1 = require("../ent");
28
32
  const clause = __importStar(require("../clause"));
@@ -30,13 +34,17 @@ const logger_1 = require("../logger");
30
34
  const loader_1 = require("./loader");
31
35
  const memoizee_1 = __importDefault(require("memoizee"));
32
36
  function getOrderBy(sortCol, orderby) {
37
+ if (orderby) {
38
+ return orderby;
39
+ }
33
40
  let sortColLower = sortCol.toLowerCase();
34
41
  let orderbyDirection = " DESC";
35
42
  if (sortColLower.endsWith("asc") || sortCol.endsWith("desc")) {
36
43
  orderbyDirection = "";
37
44
  }
38
- return orderby || `${sortCol}${orderbyDirection}`;
45
+ return `${sortCol}${orderbyDirection}`;
39
46
  }
47
+ exports.getOrderBy = getOrderBy;
40
48
  async function simpleCase(options, id, queryOptions) {
41
49
  let cls;
42
50
  if (options.groupCol) {
@@ -59,7 +67,7 @@ async function simpleCase(options, id, queryOptions) {
59
67
  ...options,
60
68
  clause: cls,
61
69
  orderby: getOrderBy(sortCol, queryOptions?.orderby),
62
- limit: queryOptions?.limit || ent_1.DefaultLimit,
70
+ limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
63
71
  });
64
72
  }
65
73
  function createLoader(options, queryOptions) {
@@ -102,7 +110,7 @@ function createLoader(options, queryOptions) {
102
110
  fields: options.fields,
103
111
  values: keys,
104
112
  orderby: getOrderBy(sortCol, queryOptions?.orderby),
105
- limit: queryOptions?.limit || ent_1.DefaultLimit,
113
+ limit: queryOptions?.limit || (0, ent_1.getDefaultLimit)(),
106
114
  groupColumn: col,
107
115
  clause: extraClause,
108
116
  });
@@ -120,16 +128,47 @@ function createLoader(options, queryOptions) {
120
128
  }, loaderOptions);
121
129
  }
122
130
  class QueryDirectLoader {
123
- constructor(options, queryOptions) {
131
+ constructor(options, queryOptions, context) {
124
132
  this.options = options;
125
133
  this.queryOptions = queryOptions;
134
+ this.context = context;
135
+ this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
136
+ }
137
+ initPrime() {
138
+ if (!this.context || !this.options?.toPrime) {
139
+ return;
140
+ }
141
+ let primedLoaders = new Map();
142
+ this.options.toPrime.forEach((prime) => {
143
+ const l2 = prime.createLoader(this.context);
144
+ if (l2.prime === undefined) {
145
+ return;
146
+ }
147
+ primedLoaders.set(prime.options.key, l2);
148
+ });
149
+ this.primedLoaders = primedLoaders;
126
150
  }
127
151
  async load(id) {
128
- return simpleCase(this.options, id, this.queryOptions);
152
+ const rows = await simpleCase(this.options, id, this.queryOptions);
153
+ if (this.context) {
154
+ this.memoizedInitPrime();
155
+ if (this.primedLoaders) {
156
+ for (const row of rows) {
157
+ for (const [key, loader] of this.primedLoaders) {
158
+ const value = row[key];
159
+ if (value !== undefined) {
160
+ loader.prime(row);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ }
166
+ return rows;
129
167
  }
130
168
  clearAll() { }
131
169
  }
132
- exports.QueryDirectLoader = QueryDirectLoader;
170
+ // note, you should never call this directly
171
+ // there's scenarios where QueryDirectLoader is needed instead of this...
133
172
  class QueryLoader {
134
173
  constructor(options, context, queryOptions) {
135
174
  this.options = options;
@@ -176,7 +215,6 @@ class QueryLoader {
176
215
  this.loader && this.loader.clearAll();
177
216
  }
178
217
  }
179
- exports.QueryLoader = QueryLoader;
180
218
  class QueryLoaderFactory {
181
219
  constructor(options) {
182
220
  this.options = options;
@@ -194,11 +232,14 @@ class QueryLoaderFactory {
194
232
  return (0, loader_1.getLoader)(this, () => new QueryLoader(this.options, context), context);
195
233
  }
196
234
  createConfigurableLoader(options, context) {
197
- if (options?.clause || !context) {
198
- return new QueryDirectLoader(this.options, options);
235
+ return QueryLoaderFactory.createConfigurableLoader(this.name, this.options, options, context);
236
+ }
237
+ static createConfigurableLoader(name, queryOptions, options, context) {
238
+ if (options.clause || !context) {
239
+ return new QueryDirectLoader(queryOptions, options, context);
199
240
  }
200
- const key = `${this.name}:limit:${options.limit}:orderby:${options.orderby}`;
201
- return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(this.options, context, options), context);
241
+ const key = `${name}:limit:${options.limit}:orderby:${options.orderby}`;
242
+ return (0, loader_1.getCustomLoader)(key, () => new QueryLoader(queryOptions, context, options), context);
202
243
  }
203
244
  }
204
245
  exports.QueryLoaderFactory = QueryLoaderFactory;
@@ -4,6 +4,7 @@ import * as clause from "../clause";
4
4
  interface QueryCountOptions {
5
5
  tableName: string;
6
6
  groupCol?: string;
7
+ groupColType?: string;
7
8
  clause?: clause.Clause;
8
9
  }
9
10
  export declare function createCountDataLoader<K extends any>(options: QueryCountOptions): DataLoader<K, number, K>;
@@ -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];
@@ -65,7 +69,8 @@ function createCountDataLoader(options) {
65
69
  if (keys.length == 1 || !options.groupCol) {
66
70
  return simpleCase(options, keys[0]);
67
71
  }
68
- let cls = clause.In(options.groupCol, ...keys);
72
+ let typ = options.groupColType || "uuid";
73
+ let cls = clause.DBTypeIn(options.groupCol, keys, typ);
69
74
  if (options.clause) {
70
75
  cls = clause.And(cls, options.clause);
71
76
  }
package/core/logger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare type logType = "query" | "warn" | "info" | "error" | "debug";
1
+ type logType = "query" | "warn" | "info" | "error" | "debug" | "cache";
2
2
  export declare function setLogLevels(levels: logType | logType[]): void;
3
3
  export declare function clearLogLevels(): void;
4
4
  export declare function log(level: logType, msg: any): void;
package/core/logger.js CHANGED
@@ -7,6 +7,7 @@ var m = {
7
7
  info: "log",
8
8
  error: "error",
9
9
  debug: "debug",
10
+ cache: "log",
10
11
  };
11
12
  var logLevels = new Map();
12
13
  function setLogLevels(levels) {
package/core/privacy.d.ts CHANGED
@@ -6,22 +6,22 @@ export declare class EntPrivacyError extends Error implements PrivacyError {
6
6
  constructor(privacyPolicy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent);
7
7
  }
8
8
  export declare const AlwaysAllowRule: {
9
- apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
9
+ apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
10
10
  };
11
11
  export declare const AlwaysDenyRule: {
12
- apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
12
+ apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
13
13
  };
14
14
  export declare const DenyIfLoggedOutRule: {
15
- apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
15
+ apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
16
16
  };
17
17
  export declare const DenyIfLoggedInRule: {
18
- apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
18
+ apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
19
19
  };
20
20
  export declare const AllowIfHasIdentity: {
21
- apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
21
+ apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
22
22
  };
23
23
  export declare const AllowIfViewerRule: {
24
- apply(v: Viewer, ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
24
+ apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
25
25
  };
26
26
  export declare class AllowIfViewerEqualsRule {
27
27
  private id;
@@ -183,6 +183,7 @@ export declare class AllowIfSubPolicyAllowsRule implements PrivacyPolicyRule {
183
183
  }
184
184
  export declare function applyPrivacyPolicy(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined): Promise<boolean>;
185
185
  export declare function applyPrivacyPolicyX(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined, throwErr?: () => Error): Promise<boolean>;
186
+ export declare function applyPrivacyPolicyImpl(v: Viewer, policy: PrivacyPolicy, ent: Ent | undefined, throwErr?: () => Error): Promise<Error | null>;
186
187
  export declare const AlwaysAllowPrivacyPolicy: PrivacyPolicy;
187
188
  export declare const AlwaysDenyPrivacyPolicy: PrivacyPolicy;
188
189
  export declare const AllowIfViewerPrivacyPolicy: PrivacyPolicy;