@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90

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 (116) 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 +219 -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 +68 -7
  13. package/core/clause.js +291 -62
  14. package/core/config.d.ts +8 -0
  15. package/core/context.d.ts +5 -3
  16. package/core/context.js +20 -2
  17. package/core/convert.d.ts +1 -1
  18. package/core/db.d.ts +2 -2
  19. package/core/db.js +1 -1
  20. package/core/ent.d.ts +79 -24
  21. package/core/ent.js +520 -168
  22. package/core/loaders/assoc_count_loader.d.ts +2 -2
  23. package/core/loaders/assoc_count_loader.js +6 -1
  24. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  25. package/core/loaders/index.d.ts +1 -1
  26. package/core/loaders/index.js +1 -3
  27. package/core/loaders/index_loader.d.ts +2 -2
  28. package/core/loaders/loader.js +5 -5
  29. package/core/loaders/object_loader.d.ts +6 -5
  30. package/core/loaders/object_loader.js +62 -58
  31. package/core/loaders/query_loader.d.ts +6 -12
  32. package/core/loaders/query_loader.js +47 -10
  33. package/core/loaders/raw_count_loader.d.ts +2 -2
  34. package/core/logger.d.ts +1 -1
  35. package/core/logger.js +1 -0
  36. package/core/privacy.d.ts +26 -25
  37. package/core/privacy.js +21 -25
  38. package/core/query/assoc_query.d.ts +6 -6
  39. package/core/query/custom_clause_query.d.ts +24 -0
  40. package/core/query/custom_clause_query.js +72 -0
  41. package/core/query/custom_query.d.ts +20 -5
  42. package/core/query/custom_query.js +77 -10
  43. package/core/query/index.d.ts +1 -0
  44. package/core/query/index.js +3 -1
  45. package/core/query/query.d.ts +1 -1
  46. package/core/query/query.js +8 -1
  47. package/core/query/shared_assoc_test.d.ts +1 -1
  48. package/core/query/shared_assoc_test.js +17 -5
  49. package/core/query/shared_test.d.ts +3 -0
  50. package/core/query/shared_test.js +211 -30
  51. package/core/viewer.d.ts +3 -3
  52. package/core/viewer.js +1 -1
  53. package/graphql/graphql.js +6 -0
  54. package/graphql/query/edge_connection.d.ts +9 -9
  55. package/graphql/query/page_info.d.ts +1 -1
  56. package/index.d.ts +11 -5
  57. package/index.js +15 -6
  58. package/package.json +1 -1
  59. package/parse_schema/parse.d.ts +12 -3
  60. package/parse_schema/parse.js +70 -11
  61. package/schema/base_schema.js +3 -0
  62. package/schema/field.d.ts +44 -8
  63. package/schema/field.js +125 -9
  64. package/schema/index.d.ts +2 -2
  65. package/schema/json_field.d.ts +13 -1
  66. package/schema/json_field.js +28 -1
  67. package/schema/schema.d.ts +65 -11
  68. package/schema/schema.js +18 -4
  69. package/schema/struct_field.d.ts +11 -1
  70. package/schema/struct_field.js +44 -5
  71. package/scripts/custom_graphql.js +8 -3
  72. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  73. package/scripts/migrate_v0.1.js +36 -0
  74. package/scripts/read_schema.js +15 -4
  75. package/testutils/builder.d.ts +31 -21
  76. package/testutils/builder.js +83 -29
  77. package/testutils/db/fixture.d.ts +10 -0
  78. package/testutils/db/fixture.js +26 -0
  79. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
  80. package/testutils/db/{test_db.js → temp_db.js} +70 -16
  81. package/testutils/db/value.d.ts +6 -0
  82. package/testutils/db/value.js +251 -0
  83. package/testutils/db_time_zone.d.ts +4 -0
  84. package/testutils/db_time_zone.js +41 -0
  85. package/testutils/fake_data/fake_contact.d.ts +5 -4
  86. package/testutils/fake_data/fake_contact.js +14 -6
  87. package/testutils/fake_data/fake_event.d.ts +5 -3
  88. package/testutils/fake_data/fake_event.js +8 -5
  89. package/testutils/fake_data/fake_user.d.ts +4 -4
  90. package/testutils/fake_data/fake_user.js +16 -13
  91. package/testutils/fake_data/test_helpers.d.ts +3 -2
  92. package/testutils/fake_data/test_helpers.js +8 -6
  93. package/testutils/fake_data/user_query.d.ts +8 -6
  94. package/testutils/fake_data/user_query.js +28 -21
  95. package/testutils/fake_log.d.ts +3 -3
  96. package/testutils/parse_sql.d.ts +6 -0
  97. package/testutils/parse_sql.js +16 -2
  98. package/testutils/test_edge_global_schema.d.ts +15 -0
  99. package/testutils/test_edge_global_schema.js +58 -0
  100. package/testutils/write.d.ts +2 -2
  101. package/testutils/write.js +29 -7
  102. package/tsc/ast.d.ts +44 -0
  103. package/tsc/ast.js +267 -0
  104. package/tsc/compilerOptions.d.ts +6 -0
  105. package/tsc/compilerOptions.js +40 -1
  106. package/tsc/move_generated.d.ts +1 -0
  107. package/tsc/move_generated.js +160 -0
  108. package/tsc/transform.d.ts +21 -0
  109. package/tsc/transform.js +167 -0
  110. package/tsc/transform_action.d.ts +22 -0
  111. package/tsc/transform_action.js +179 -0
  112. package/tsc/transform_ent.d.ts +17 -0
  113. package/tsc/transform_ent.js +59 -0
  114. package/tsc/transform_schema.d.ts +27 -0
  115. package/tsc/transform_schema.js +379 -0
  116. package/scripts/transform_schema.js +0 -445
@@ -6,9 +6,13 @@ const ent_1 = require("../ent");
6
6
  const viewer_1 = require("../viewer");
7
7
  const index_1 = require("../../testutils/fake_data/index");
8
8
  const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
9
- const test_db_1 = require("../../testutils/db/test_db");
9
+ const temp_db_1 = require("../../testutils/db/temp_db");
10
10
  const test_context_1 = require("../../testutils/context/test_context");
11
11
  const logger_1 = require("../logger");
12
+ const test_edge_global_schema_1 = require("../../testutils/test_edge_global_schema");
13
+ const builder_1 = require("../../testutils/builder");
14
+ const action_1 = require("../../action");
15
+ const mock_log_1 = require("../../testutils/mock_log");
12
16
  class TestQueryFilter {
13
17
  constructor(filter, newQuery, ents, defaultViewer) {
14
18
  this.filter = filter;
@@ -17,11 +21,15 @@ class TestQueryFilter {
17
21
  this.defaultViewer = defaultViewer;
18
22
  this.allContacts = [];
19
23
  this.filteredContacts = [];
24
+ // @ts-ignore
25
+ const q = this.newQuery(this.defaultViewer);
26
+ // TODO sad not generic enough
27
+ this.customQuery =
28
+ q instanceof index_1.UserToContactsFkeyQuery ||
29
+ q instanceof index_1.UserToContactsFkeyQueryDeprecated;
20
30
  }
21
- async beforeEach() {
22
- // console.log("sss");
31
+ async createData() {
23
32
  [this.user, this.allContacts] = await (0, test_helpers_1.createAllContacts)();
24
- // console.log(this.user, this.contacts);
25
33
  // this.allContacts = this.allContacts.reverse();
26
34
  this.filteredContacts = this.ents(this.allContacts);
27
35
  db_mock_1.QueryRecorder.clearQueries();
@@ -37,19 +45,19 @@ class TestQueryFilter {
37
45
  expect(ids).toEqual(this.filteredContacts.map((contact) => contact.id));
38
46
  }
39
47
  // rawCount isn't affected by filters...
40
- async testRawCount() {
48
+ async testRawCount(expectedCount) {
41
49
  const count = await this.getQuery().queryRawCount();
42
- this.verifyRawCount(count);
50
+ this.verifyRawCount(count, expectedCount);
43
51
  }
44
- verifyRawCount(count) {
45
- expect(count).toBe(test_helpers_1.inputs.length);
52
+ verifyRawCount(count, expectedCount) {
53
+ expect(count).toBe(expectedCount ?? test_helpers_1.inputs.length);
46
54
  }
47
- async testCount() {
55
+ async testCount(expectedCount) {
48
56
  const count = await this.getQuery().queryCount();
49
- this.verifyCount(count);
57
+ this.verifyCount(count, expectedCount);
50
58
  }
51
- verifyCount(count) {
52
- expect(count).toBe(this.filteredContacts.length);
59
+ verifyCount(count, expectedCount) {
60
+ expect(count).toBe(expectedCount ?? this.filteredContacts.length);
53
61
  }
54
62
  async testEdges() {
55
63
  const edges = await this.getQuery().queryEdges();
@@ -58,21 +66,60 @@ class TestQueryFilter {
58
66
  verifyEdges(edges) {
59
67
  const q = this.getQuery();
60
68
  // TODO sad not generic enough
61
- if (q instanceof index_1.UserToContactsFkeyQuery) {
69
+ if (this.customQuery) {
62
70
  (0, test_helpers_1.verifyUserToContactRawData)(this.user, edges, this.filteredContacts);
63
71
  }
64
72
  else {
65
73
  (0, test_helpers_1.verifyUserToContactEdges)(this.user, edges, this.filteredContacts);
66
74
  }
67
75
  }
68
- async testEnts() {
69
- const entsMap = await this.getQuery(new viewer_1.IDViewer(this.user.id)).queryEnts();
70
- this.verifyEnts(entsMap);
76
+ async testEnts(v) {
77
+ const ents = await this.getQuery(v || new viewer_1.IDViewer(this.user.id)).queryEnts();
78
+ this.verifyEnts(ents);
79
+ return ents;
80
+ }
81
+ async testEntsCache() {
82
+ if (!this.customQuery) {
83
+ return;
84
+ }
85
+ (0, logger_1.setLogLevels)(["query", "cache"]);
86
+ const ml = new mock_log_1.MockLogs();
87
+ ml.mock();
88
+ const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
89
+ const ents = await this.testEnts(v);
90
+ expect(ml.logs.length).toBe(1);
91
+ expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
92
+ await Promise.all(ents.map((ent) => index_1.FakeContact.loadX(v, ent.id)));
93
+ expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
94
+ for (const log of ml.logs.slice(1)) {
95
+ expect(log["ent-cache-hit"]).toBeDefined();
96
+ }
97
+ ml.restore();
98
+ (0, logger_1.clearLogLevels)();
99
+ }
100
+ async testDataCache() {
101
+ if (!this.customQuery) {
102
+ return;
103
+ }
104
+ (0, logger_1.setLogLevels)(["query", "cache"]);
105
+ const ml = new mock_log_1.MockLogs();
106
+ ml.mock();
107
+ const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
108
+ const ents = await this.testEnts(v);
109
+ expect(ml.logs.length).toBe(1);
110
+ expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
111
+ await Promise.all(ents.map((ent) => index_1.FakeContact.loadRawData(ent.id, v.context)));
112
+ expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
113
+ for (const log of ml.logs.slice(1)) {
114
+ expect(log["dataloader-cache-hit"]).toBeDefined();
115
+ }
116
+ ml.restore();
117
+ (0, logger_1.clearLogLevels)();
71
118
  }
72
119
  verifyEnts(ents) {
73
120
  (0, test_helpers_1.verifyUserToContacts)(this.user, ents, this.filteredContacts);
74
121
  }
75
- async testAll() {
122
+ async testAll(expectedCount) {
76
123
  const query = this.getQuery(new viewer_1.IDViewer(this.user.id));
77
124
  const [edges, count, ids, rawCount, ents] = await Promise.all([
78
125
  query.queryEdges(),
@@ -81,10 +128,10 @@ class TestQueryFilter {
81
128
  query.queryRawCount(),
82
129
  query.queryEnts(),
83
130
  ]);
84
- this.verifyCount(count);
131
+ this.verifyCount(count, expectedCount);
85
132
  this.verifyEdges(edges);
86
133
  this.verifyIDs(ids);
87
- this.verifyRawCount(rawCount);
134
+ this.verifyRawCount(rawCount, expectedCount);
88
135
  this.verifyEnts(ents);
89
136
  }
90
137
  }
@@ -125,7 +172,19 @@ const commonTests = (opts) => {
125
172
  expect(queries.length).toBe(length);
126
173
  const query = queries[0];
127
174
  const result = [...opts.where.matchAll(preparedVar)];
128
- expect(query.qs?.whereClause).toBe(`${opts.where} AND ${opts.sortCol} < $${result.length + 1} ORDER BY ${opts.sortCol} DESC LIMIT 4`);
175
+ let parts = opts.where.split(" AND ");
176
+ if (parts[parts.length - 1] === "deleted_at IS NULL") {
177
+ parts = parts
178
+ .slice(0, parts.length - 1)
179
+ .concat([
180
+ `${opts.sortCol} < $${result.length + 1}`,
181
+ "deleted_at IS NULL",
182
+ ]);
183
+ }
184
+ else {
185
+ parts.push(`${opts.sortCol} < $${result.length + 1}`);
186
+ }
187
+ expect(query.qs?.whereClause).toBe(`${parts.join(" AND ")} ORDER BY ${opts.sortCol} DESC LIMIT 4`);
129
188
  }
130
189
  function verifyLastBeforeCursorQuery(length = 1) {
131
190
  if (opts.livePostgresDB || opts.sqlite) {
@@ -135,9 +194,21 @@ const commonTests = (opts) => {
135
194
  expect(queries.length).toBe(length);
136
195
  const query = queries[0];
137
196
  const result = [...opts.where.matchAll(preparedVar)];
197
+ let parts = opts.where.split(" AND ");
198
+ if (parts[parts.length - 1] === "deleted_at IS NULL") {
199
+ parts = parts
200
+ .slice(0, parts.length - 1)
201
+ .concat([
202
+ `${opts.sortCol} > $${result.length + 1}`,
203
+ "deleted_at IS NULL",
204
+ ]);
205
+ }
206
+ else {
207
+ parts.push(`${opts.sortCol} > $${result.length + 1}`);
208
+ }
138
209
  expect(query.qs?.whereClause).toBe(
139
210
  // extra fetched for pagination
140
- `${opts.where} AND ${opts.sortCol} > $${result.length + 1} ORDER BY ${opts.sortCol} ASC LIMIT 4`);
211
+ `${parts.join(" AND ")} ORDER BY ${opts.sortCol} ASC LIMIT 4`);
141
212
  }
142
213
  function getViewer() {
143
214
  // live db, let's do context because we're testing complicated paths
@@ -171,20 +242,26 @@ const commonTests = (opts) => {
171
242
  cursorKey: opts.sortCol,
172
243
  });
173
244
  }
245
+ if (opts.globalSchema) {
246
+ (0, ent_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
247
+ }
174
248
  let tdb;
175
249
  if (opts.sqlite) {
176
- // tableName just to make it unique
177
- (0, test_db_1.setupSqlite)(`sqlite:///shared_test+${opts.tableName}.db`, test_helpers_1.tempDBTables);
250
+ (0, temp_db_1.setupSqlite)(`sqlite:///shared_test+${opts.uniqKey}.db`, () => (0, test_helpers_1.tempDBTables)(opts.globalSchema), {
251
+ disableDeleteAfterEachTest: true,
252
+ });
178
253
  }
179
254
  beforeAll(async () => {
180
255
  // want error on by default in tests?
181
256
  (0, logger_1.setLogLevels)(["error", "warn", "info"]);
182
257
  if (opts.livePostgresDB) {
183
258
  tdb = await (0, test_helpers_1.setupTempDB)();
259
+ return;
184
260
  }
261
+ await (0, test_helpers_1.createEdges)();
185
262
  });
186
263
  beforeEach(async () => {
187
- if (opts.livePostgresDB) {
264
+ if (opts.livePostgresDB || opts.sqlite) {
188
265
  return;
189
266
  }
190
267
  await (0, test_helpers_1.createEdges)();
@@ -196,7 +273,7 @@ const commonTests = (opts) => {
196
273
  });
197
274
  describe("simple queries", () => {
198
275
  const filter = new TestQueryFilter((q) => {
199
- // no filterzs
276
+ // no filters
200
277
  return q;
201
278
  }, opts.newQuery, (contacts) => {
202
279
  // nothing to do here
@@ -204,7 +281,7 @@ const commonTests = (opts) => {
204
281
  return contacts.reverse();
205
282
  }, getViewer());
206
283
  beforeEach(async () => {
207
- await filter.beforeEach();
284
+ await filter.createData();
208
285
  });
209
286
  test("ids", async () => {
210
287
  await filter.testIDs();
@@ -229,6 +306,67 @@ const commonTests = (opts) => {
229
306
  test("all", async () => {
230
307
  await filter.testAll();
231
308
  });
309
+ test("ents cache", async () => {
310
+ await filter.testEntsCache();
311
+ });
312
+ test("data cache", async () => {
313
+ await filter.testDataCache();
314
+ });
315
+ });
316
+ describe("after delete", () => {
317
+ const filter = new TestQueryFilter((q) => {
318
+ // no filters
319
+ return q;
320
+ }, opts.newQuery, (contacts) => {
321
+ // nothing expected since deleted
322
+ return [];
323
+ }, getViewer());
324
+ beforeEach(async () => {
325
+ await filter.createData();
326
+ const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
327
+ await Promise.all(filter.allContacts.map(async (contact) => {
328
+ action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
329
+ const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
330
+ await action2.save();
331
+ }));
332
+ await action.save();
333
+ db_mock_1.QueryRecorder.clearQueries();
334
+ });
335
+ test("ids", async () => {
336
+ await filter.testIDs();
337
+ verifyQuery({});
338
+ });
339
+ test("rawCount", async () => {
340
+ await filter.testRawCount(0);
341
+ verifyCountQuery({});
342
+ });
343
+ test("count", async () => {
344
+ await filter.testCount(0);
345
+ verifyQuery({});
346
+ });
347
+ test("edges", async () => {
348
+ await filter.testEdges();
349
+ verifyQuery({});
350
+ });
351
+ test("ents", async () => {
352
+ await filter.testEnts();
353
+ // no ents so no subsequent query. just the edge query
354
+ verifyQuery({ length: 1 });
355
+ });
356
+ test("all", async () => {
357
+ await filter.testAll(0);
358
+ });
359
+ test("raw_data", async () => {
360
+ if (opts.rawDataVerify) {
361
+ await opts.rawDataVerify(filter.user);
362
+ }
363
+ });
364
+ test("ents cache", async () => {
365
+ await filter.testEntsCache();
366
+ });
367
+ test("data cache", async () => {
368
+ await filter.testDataCache();
369
+ });
232
370
  });
233
371
  describe("first. no cursor", () => {
234
372
  const N = 2;
@@ -239,7 +377,7 @@ const commonTests = (opts) => {
239
377
  return contacts.reverse().slice(0, N);
240
378
  }, getViewer());
241
379
  beforeEach(async () => {
242
- await filter.beforeEach();
380
+ await filter.createData();
243
381
  });
244
382
  test("ids", async () => {
245
383
  await filter.testIDs();
@@ -264,6 +402,12 @@ const commonTests = (opts) => {
264
402
  test("all", async () => {
265
403
  await filter.testAll();
266
404
  });
405
+ test("ents cache", async () => {
406
+ await filter.testEntsCache();
407
+ });
408
+ test("data cache", async () => {
409
+ await filter.testDataCache();
410
+ });
267
411
  });
268
412
  describe("last", () => {
269
413
  const N = 2;
@@ -275,7 +419,7 @@ const commonTests = (opts) => {
275
419
  return contacts.slice(0, N).reverse();
276
420
  }, getViewer());
277
421
  beforeEach(async () => {
278
- await filter.beforeEach();
422
+ await filter.createData();
279
423
  });
280
424
  test("ids", async () => {
281
425
  await filter.testIDs();
@@ -300,6 +444,12 @@ const commonTests = (opts) => {
300
444
  test("all", async () => {
301
445
  await filter.testAll();
302
446
  });
447
+ test("ents cache", async () => {
448
+ await filter.testEntsCache();
449
+ });
450
+ test("data cache", async () => {
451
+ await filter.testDataCache();
452
+ });
303
453
  });
304
454
  describe("first after cursor", () => {
305
455
  const idx = 2;
@@ -310,8 +460,18 @@ const commonTests = (opts) => {
310
460
  // < check so we shouldn't get that index
311
461
  return contacts.reverse().slice(idx + 1, idx + N);
312
462
  }, getViewer());
463
+ beforeAll(async () => {
464
+ if (opts.livePostgresDB || opts.sqlite) {
465
+ await filter.createData();
466
+ }
467
+ });
468
+ // TODO do we still need QueryRecorder?
469
+ // should just delete this...
313
470
  beforeEach(async () => {
314
- await filter.beforeEach();
471
+ if (opts.livePostgresDB || opts.sqlite) {
472
+ return;
473
+ }
474
+ await filter.createData();
315
475
  });
316
476
  test("ids", async () => {
317
477
  await filter.testIDs();
@@ -336,6 +496,12 @@ const commonTests = (opts) => {
336
496
  test("all", async () => {
337
497
  await filter.testAll();
338
498
  });
499
+ test("ents cache", async () => {
500
+ await filter.testEntsCache();
501
+ });
502
+ test("data cache", async () => {
503
+ await filter.testDataCache();
504
+ });
339
505
  });
340
506
  test("first. after each cursor", async () => {
341
507
  let [user, contacts] = await (0, test_helpers_1.createAllContacts)();
@@ -378,8 +544,17 @@ const commonTests = (opts) => {
378
544
  // > check so we don't want that index
379
545
  return contacts.reverse().slice(0, idx).reverse(); // because of order returned
380
546
  }, getViewer());
547
+ beforeAll(async () => {
548
+ if (opts.livePostgresDB || opts.sqlite) {
549
+ await filter.createData();
550
+ }
551
+ });
552
+ // same TODO above
381
553
  beforeEach(async () => {
382
- await filter.beforeEach();
554
+ if (opts.livePostgresDB || opts.sqlite) {
555
+ return;
556
+ }
557
+ await filter.createData();
383
558
  });
384
559
  test("ids", async () => {
385
560
  await filter.testIDs();
@@ -404,6 +579,12 @@ const commonTests = (opts) => {
404
579
  test("all", async () => {
405
580
  await filter.testAll();
406
581
  });
582
+ test("ents cache", async () => {
583
+ await filter.testEntsCache();
584
+ });
585
+ test("data cache", async () => {
586
+ await filter.testDataCache();
587
+ });
407
588
  });
408
589
  test("last. before each cursor", async () => {
409
590
  let [user, contacts] = await (0, test_helpers_1.createAllContacts)();
package/core/viewer.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ID, Ent, Viewer, Context } from "./base";
2
2
  export declare class LoggedOutViewer implements Viewer {
3
- context?: Context | undefined;
4
- constructor(context?: Context | undefined);
3
+ context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined;
4
+ constructor(context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined);
5
5
  viewerID: null;
6
6
  viewer(): Promise<null>;
7
7
  instanceKey(): string;
@@ -18,6 +18,6 @@ export declare class IDViewer implements Viewer {
18
18
  constructor(viewerID: ID, opts?: Partial<IDViewerOptions>);
19
19
  constructor(opts: IDViewerOptions);
20
20
  setContext(ctx: Context): this;
21
- viewer(): Promise<Ent | null>;
21
+ viewer(): Promise<Ent<Viewer<Ent<any> | null, ID | null>> | null>;
22
22
  instanceKey(): string;
23
23
  }
package/core/viewer.js CHANGED
@@ -35,7 +35,7 @@ class IDViewer {
35
35
  return this.ent;
36
36
  }
37
37
  instanceKey() {
38
- return `idViewer: ${this.viewerID}`;
38
+ return `idViewer:${this.viewerID}`;
39
39
  }
40
40
  }
41
41
  exports.IDViewer = IDViewer;
@@ -85,6 +85,12 @@ const addCustomType = (type) => {
85
85
  }
86
86
  }
87
87
  catch (e) {
88
+ if (type.secondaryImportPath) {
89
+ (0, exports.addCustomType)({
90
+ ...type,
91
+ importPath: type.secondaryImportPath,
92
+ });
93
+ }
88
94
  return;
89
95
  }
90
96
  GQLCapture.getCustomTypes().set(type.type, type);
@@ -1,30 +1,30 @@
1
1
  import { EdgeQuery, PaginationInfo } from "../../core/query/query";
2
- import { Data, Ent, Viewer } from "../../core/base";
2
+ import { Data, Ent, ID, Viewer } from "../../core/base";
3
3
  export interface GraphQLEdge<T extends Data> {
4
4
  edge: T;
5
5
  node: Ent;
6
6
  cursor: string;
7
7
  }
8
- interface edgeQueryCtr<T extends Ent, TEdge extends Data> {
9
- (v: Viewer, src: T): EdgeQuery<T, Ent, TEdge>;
8
+ interface edgeQueryCtr<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
9
+ (v: TViewer, src: T): EdgeQuery<T, Ent, TEdge>;
10
10
  }
11
- interface edgeQueryCtr2<T extends Ent, TEdge extends Data> {
12
- (v: Viewer): EdgeQuery<T, Ent, TEdge>;
11
+ interface edgeQueryCtr2<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
12
+ (v: TViewer): EdgeQuery<T, Ent, TEdge>;
13
13
  }
14
- export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data> {
14
+ export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data, TViewer extends Viewer = Viewer> {
15
15
  query: EdgeQuery<TSource, Ent, TEdge>;
16
16
  private results;
17
17
  private viewer;
18
18
  private source?;
19
19
  private args?;
20
- constructor(viewer: Viewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge>, args?: Data);
21
- constructor(viewer: Viewer, getQuery: edgeQueryCtr2<TSource, TEdge>, args?: Data);
20
+ constructor(viewer: TViewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge, TViewer>, args?: Data);
21
+ constructor(viewer: TViewer, getQuery: edgeQueryCtr2<TSource, TEdge, TViewer>, args?: Data);
22
22
  first(limit: number, cursor?: string): void;
23
23
  last(limit: number, cursor?: string): void;
24
24
  modifyQuery(fn: (query: EdgeQuery<TSource, Ent, TEdge>) => EdgeQuery<TSource, Ent, TEdge>): void;
25
25
  queryTotalCount(): Promise<number>;
26
26
  queryEdges(): Promise<GraphQLEdge<TEdge>[]>;
27
- queryNodes(): Promise<Ent[]>;
27
+ queryNodes(): Promise<Ent<Viewer<Ent<any> | null, ID | null>>[]>;
28
28
  private defaultPageInfo;
29
29
  queryPageInfo(): Promise<PaginationInfo>;
30
30
  private queryData;
@@ -1,4 +1,4 @@
1
1
  import { GraphQLObjectType } from "graphql";
2
2
  import { RequestContext } from "../../core/context";
3
3
  import { PaginationInfo } from "../../core/query/query";
4
- export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext>;
4
+ export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext<import("../..").Viewer<import("../..").Ent<any> | null, import("../..").ID | null>>>;
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./core/base";
2
- export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, } from "./core/ent";
2
+ export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
3
3
  import DB from "./core/db";
4
4
  export * from "./core/loaders";
5
5
  export { DB };
@@ -13,6 +13,7 @@ declare const query: {
13
13
  And: typeof q.And;
14
14
  AndOptional: typeof q.AndOptional;
15
15
  Or: typeof q.Or;
16
+ OrOptional: typeof q.OrOptional;
16
17
  In: typeof q.In;
17
18
  Greater: typeof q.Greater;
18
19
  Less: typeof q.Less;
@@ -20,10 +21,15 @@ declare const query: {
20
21
  LessEq: typeof q.LessEq;
21
22
  ArrayEq: typeof q.ArrayEq;
22
23
  ArrayNotEq: typeof q.ArrayNotEq;
23
- ArrayGreater: typeof q.ArrayGreater;
24
- ArrayLess: typeof q.ArrayLess;
25
- ArrayGreaterEq: typeof q.ArrayGreaterEq;
26
- ArrayLessEq: typeof q.ArrayLessEq;
24
+ PostgresArrayContainsValue: typeof q.PostgresArrayContainsValue;
25
+ PostgresArrayContains: typeof q.PostgresArrayContains;
26
+ PostgresArrayNotContainsValue: typeof q.PostgresArrayNotContainsValue;
27
+ PostgresArrayNotContains: typeof q.PostgresArrayNotContains;
28
+ PostgresArrayOverlaps: typeof q.PostgresArrayOverlaps;
29
+ PostgresArrayNotOverlaps: typeof q.PostgresArrayNotOverlaps;
30
+ JSONPathValuePredicate: typeof q.JSONPathValuePredicate;
31
+ JSONObjectFieldKeyASJSON: typeof q.JSONObjectFieldKeyASJSON;
32
+ JSONObjectFieldKeyAsText: typeof q.JSONObjectFieldKeyAsText;
27
33
  TsQuery: typeof q.TsQuery;
28
34
  PlainToTsQuery: typeof q.PlainToTsQuery;
29
35
  PhraseToTsQuery: typeof q.PhraseToTsQuery;
package/index.js CHANGED
@@ -25,13 +25,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
29
- exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = void 0;
28
+ exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.setGlobalSchema = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.RawQueryOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomCount = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
29
+ exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = void 0;
30
30
  __exportStar(require("./core/base"), exports);
31
31
  var ent_1 = require("./core/ent");
32
32
  Object.defineProperty(exports, "loadEnt", { enumerable: true, get: function () { return ent_1.loadEnt; } });
33
33
  Object.defineProperty(exports, "loadCustomData", { enumerable: true, get: function () { return ent_1.loadCustomData; } });
34
34
  Object.defineProperty(exports, "loadCustomEnts", { enumerable: true, get: function () { return ent_1.loadCustomEnts; } });
35
+ Object.defineProperty(exports, "loadCustomCount", { enumerable: true, get: function () { return ent_1.loadCustomCount; } });
35
36
  Object.defineProperty(exports, "loadEntX", { enumerable: true, get: function () { return ent_1.loadEntX; } });
36
37
  Object.defineProperty(exports, "loadEnts", { enumerable: true, get: function () { return ent_1.loadEnts; } });
37
38
  Object.defineProperty(exports, "loadDerivedEnt", { enumerable: true, get: function () { return ent_1.loadDerivedEnt; } });
@@ -44,6 +45,7 @@ Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function ()
44
45
  Object.defineProperty(exports, "loadRow", { enumerable: true, get: function () { return ent_1.loadRow; } });
45
46
  Object.defineProperty(exports, "loadRows", { enumerable: true, get: function () { return ent_1.loadRows; } });
46
47
  Object.defineProperty(exports, "EditNodeOperation", { enumerable: true, get: function () { return ent_1.EditNodeOperation; } });
48
+ Object.defineProperty(exports, "RawQueryOperation", { enumerable: true, get: function () { return ent_1.RawQueryOperation; } });
47
49
  Object.defineProperty(exports, "EdgeOperation", { enumerable: true, get: function () { return ent_1.EdgeOperation; } });
48
50
  Object.defineProperty(exports, "DeleteNodeOperation", { enumerable: true, get: function () { return ent_1.DeleteNodeOperation; } });
49
51
  Object.defineProperty(exports, "AssocEdge", { enumerable: true, get: function () { return ent_1.AssocEdge; } });
@@ -57,6 +59,7 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
57
59
  Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
58
60
  Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
59
61
  Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
62
+ Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
60
63
  const db_1 = __importDefault(require("./core/db"));
61
64
  exports.DB = db_1.default;
62
65
  __exportStar(require("./core/loaders"), exports);
@@ -109,6 +112,7 @@ const query = {
109
112
  And: q.And,
110
113
  AndOptional: q.AndOptional,
111
114
  Or: q.Or,
115
+ OrOptional: q.OrOptional,
112
116
  In: q.In,
113
117
  Greater: q.Greater,
114
118
  Less: q.Less,
@@ -116,10 +120,15 @@ const query = {
116
120
  LessEq: q.LessEq,
117
121
  ArrayEq: q.ArrayEq,
118
122
  ArrayNotEq: q.ArrayNotEq,
119
- ArrayGreater: q.ArrayGreater,
120
- ArrayLess: q.ArrayLess,
121
- ArrayGreaterEq: q.ArrayGreaterEq,
122
- ArrayLessEq: q.ArrayLessEq,
123
+ PostgresArrayContainsValue: q.PostgresArrayContainsValue,
124
+ PostgresArrayContains: q.PostgresArrayContains,
125
+ PostgresArrayNotContainsValue: q.PostgresArrayNotContainsValue,
126
+ PostgresArrayNotContains: q.PostgresArrayNotContains,
127
+ PostgresArrayOverlaps: q.PostgresArrayOverlaps,
128
+ PostgresArrayNotOverlaps: q.PostgresArrayNotOverlaps,
129
+ JSONPathValuePredicate: q.JSONPathValuePredicate,
130
+ JSONObjectFieldKeyASJSON: q.JSONObjectFieldKeyASJSON,
131
+ JSONObjectFieldKeyAsText: q.JSONObjectFieldKeyAsText,
123
132
  TsQuery: q.TsQuery,
124
133
  PlainToTsQuery: q.PlainToTsQuery,
125
134
  PhraseToTsQuery: q.PhraseToTsQuery,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha9",
3
+ "version": "0.1.0-alpha90",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type } from "../schema/schema";
2
+ import { ActionField, Type, GlobalSchema } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
@@ -24,6 +24,7 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
24
24
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
25
25
  fields: ProcessedField[];
26
26
  schemaPath?: string;
27
+ patternNames?: string[];
27
28
  };
28
29
  declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
29
30
  edgeAction?: OutputAction;
@@ -38,13 +39,14 @@ interface ProcessedPattern {
38
39
  name: string;
39
40
  assocEdges: ProcessedAssocEdge[];
40
41
  fields: ProcessedField[];
42
+ disableMixin?: boolean;
41
43
  }
42
44
  declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
43
45
  subFields?: ProcessedField[];
44
46
  listElemType?: ProcessedType;
45
47
  unionFields?: ProcessedField[];
46
48
  };
47
- declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
49
+ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
48
50
  name: string;
49
51
  hasDefaultValueOnCreate?: boolean;
50
52
  hasDefaultValueOnEdit?: boolean;
@@ -52,6 +54,7 @@ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOn
52
54
  hasFieldPrivacy?: boolean;
53
55
  derivedFields?: ProcessedField[];
54
56
  type: ProcessedType;
57
+ serverDefault?: string;
55
58
  };
56
59
  interface patternsDict {
57
60
  [key: string]: ProcessedPattern;
@@ -59,9 +62,15 @@ interface patternsDict {
59
62
  interface Result {
60
63
  schemas: schemasDict;
61
64
  patterns: patternsDict;
65
+ globalSchema?: ProcessedGlobalSchema;
62
66
  }
63
67
  declare type PotentialSchemas = {
64
68
  [key: string]: any;
65
69
  };
66
- export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
70
+ export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
71
+ interface ProcessedGlobalSchema {
72
+ globalEdges: ProcessedAssocEdge[];
73
+ extraEdgeFields: ProcessedField[];
74
+ initForEdges?: boolean;
75
+ }
67
76
  export {};