@snowtop/ent 0.1.0-alpha8 → 0.1.0-alpha80

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 (112) hide show
  1. package/action/action.d.ts +27 -25
  2. package/action/executor.d.ts +3 -3
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +29 -22
  5. package/action/experimental_action.js +29 -6
  6. package/action/orchestrator.d.ts +37 -16
  7. package/action/orchestrator.js +184 -54
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +38 -22
  10. package/core/clause.d.ts +65 -7
  11. package/core/clause.js +261 -54
  12. package/core/config.d.ts +8 -0
  13. package/core/context.d.ts +5 -3
  14. package/core/context.js +7 -2
  15. package/core/convert.d.ts +1 -1
  16. package/core/db.d.ts +1 -2
  17. package/core/db.js +1 -1
  18. package/core/ent.d.ts +76 -24
  19. package/core/ent.js +459 -143
  20. package/core/loaders/assoc_count_loader.d.ts +2 -2
  21. package/core/loaders/assoc_count_loader.js +6 -1
  22. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  23. package/core/loaders/loader.js +5 -5
  24. package/core/loaders/object_loader.d.ts +4 -3
  25. package/core/loaders/object_loader.js +22 -5
  26. package/core/loaders/query_loader.d.ts +2 -2
  27. package/core/loaders/raw_count_loader.d.ts +2 -2
  28. package/core/logger.d.ts +1 -1
  29. package/core/logger.js +1 -0
  30. package/core/privacy.d.ts +26 -25
  31. package/core/privacy.js +21 -25
  32. package/core/query/assoc_query.d.ts +6 -6
  33. package/core/query/custom_query.d.ts +5 -5
  34. package/core/query/query.d.ts +1 -1
  35. package/core/query/shared_assoc_test.d.ts +1 -1
  36. package/core/query/shared_assoc_test.js +17 -5
  37. package/core/query/shared_test.d.ts +3 -0
  38. package/core/query/shared_test.js +95 -17
  39. package/core/viewer.d.ts +3 -3
  40. package/core/viewer.js +1 -1
  41. package/graphql/builtins/connection.js +3 -3
  42. package/graphql/builtins/edge.js +2 -2
  43. package/graphql/builtins/node.js +1 -1
  44. package/graphql/graphql.js +8 -2
  45. package/graphql/query/connection_type.js +6 -6
  46. package/graphql/query/edge_connection.d.ts +9 -9
  47. package/graphql/query/page_info.d.ts +1 -1
  48. package/graphql/query/page_info.js +4 -4
  49. package/graphql/query/shared_assoc_test.js +2 -2
  50. package/graphql/scalars/time.d.ts +1 -1
  51. package/index.d.ts +10 -5
  52. package/index.js +13 -6
  53. package/package.json +2 -2
  54. package/parse_schema/parse.d.ts +14 -2
  55. package/parse_schema/parse.js +40 -2
  56. package/schema/base_schema.d.ts +1 -1
  57. package/schema/base_schema.js +3 -0
  58. package/schema/field.d.ts +36 -7
  59. package/schema/field.js +70 -2
  60. package/schema/index.d.ts +2 -2
  61. package/schema/json_field.d.ts +13 -1
  62. package/schema/json_field.js +28 -1
  63. package/schema/schema.d.ts +61 -10
  64. package/schema/schema.js +18 -4
  65. package/schema/struct_field.d.ts +11 -1
  66. package/schema/struct_field.js +43 -4
  67. package/scripts/custom_graphql.js +5 -1
  68. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  69. package/scripts/migrate_v0.1.js +36 -0
  70. package/scripts/read_schema.js +25 -2
  71. package/testutils/builder.d.ts +31 -21
  72. package/testutils/builder.js +82 -29
  73. package/testutils/db/fixture.d.ts +10 -0
  74. package/testutils/db/fixture.js +26 -0
  75. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
  76. package/testutils/db/{test_db.js → temp_db.js} +63 -15
  77. package/testutils/db/value.d.ts +6 -0
  78. package/testutils/db/value.js +251 -0
  79. package/testutils/db_time_zone.d.ts +4 -0
  80. package/testutils/db_time_zone.js +41 -0
  81. package/testutils/ent-graphql-tests/index.js +19 -12
  82. package/testutils/fake_data/fake_contact.d.ts +3 -3
  83. package/testutils/fake_data/fake_contact.js +9 -6
  84. package/testutils/fake_data/fake_event.d.ts +3 -3
  85. package/testutils/fake_data/fake_event.js +8 -5
  86. package/testutils/fake_data/fake_user.d.ts +4 -4
  87. package/testutils/fake_data/fake_user.js +16 -13
  88. package/testutils/fake_data/test_helpers.d.ts +2 -2
  89. package/testutils/fake_data/test_helpers.js +5 -5
  90. package/testutils/fake_data/user_query.d.ts +2 -2
  91. package/testutils/fake_log.d.ts +3 -3
  92. package/testutils/parse_sql.d.ts +6 -0
  93. package/testutils/parse_sql.js +16 -2
  94. package/testutils/test_edge_global_schema.d.ts +15 -0
  95. package/testutils/test_edge_global_schema.js +58 -0
  96. package/testutils/write.d.ts +2 -2
  97. package/testutils/write.js +29 -7
  98. package/tsc/ast.d.ts +44 -0
  99. package/tsc/ast.js +267 -0
  100. package/tsc/compilerOptions.d.ts +6 -0
  101. package/tsc/compilerOptions.js +40 -1
  102. package/tsc/move_generated.d.ts +1 -0
  103. package/tsc/move_generated.js +160 -0
  104. package/tsc/transform.d.ts +21 -0
  105. package/tsc/transform.js +167 -0
  106. package/tsc/transform_action.d.ts +22 -0
  107. package/tsc/transform_action.js +179 -0
  108. package/tsc/transform_ent.d.ts +17 -0
  109. package/tsc/transform_ent.js +59 -0
  110. package/tsc/transform_schema.d.ts +27 -0
  111. package/tsc/transform_schema.js +379 -0
  112. package/scripts/transform_schema.js +0 -437
@@ -6,9 +6,12 @@ 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");
12
15
  class TestQueryFilter {
13
16
  constructor(filter, newQuery, ents, defaultViewer) {
14
17
  this.filter = filter;
@@ -37,19 +40,19 @@ class TestQueryFilter {
37
40
  expect(ids).toEqual(this.filteredContacts.map((contact) => contact.id));
38
41
  }
39
42
  // rawCount isn't affected by filters...
40
- async testRawCount() {
43
+ async testRawCount(expectedCount) {
41
44
  const count = await this.getQuery().queryRawCount();
42
- this.verifyRawCount(count);
45
+ this.verifyRawCount(count, expectedCount);
43
46
  }
44
- verifyRawCount(count) {
45
- expect(count).toBe(test_helpers_1.inputs.length);
47
+ verifyRawCount(count, expectedCount) {
48
+ expect(count).toBe(expectedCount ?? test_helpers_1.inputs.length);
46
49
  }
47
- async testCount() {
50
+ async testCount(expectedCount) {
48
51
  const count = await this.getQuery().queryCount();
49
- this.verifyCount(count);
52
+ this.verifyCount(count, expectedCount);
50
53
  }
51
- verifyCount(count) {
52
- expect(count).toBe(this.filteredContacts.length);
54
+ verifyCount(count, expectedCount) {
55
+ expect(count).toBe(expectedCount ?? this.filteredContacts.length);
53
56
  }
54
57
  async testEdges() {
55
58
  const edges = await this.getQuery().queryEdges();
@@ -72,7 +75,7 @@ class TestQueryFilter {
72
75
  verifyEnts(ents) {
73
76
  (0, test_helpers_1.verifyUserToContacts)(this.user, ents, this.filteredContacts);
74
77
  }
75
- async testAll() {
78
+ async testAll(expectedCount) {
76
79
  const query = this.getQuery(new viewer_1.IDViewer(this.user.id));
77
80
  const [edges, count, ids, rawCount, ents] = await Promise.all([
78
81
  query.queryEdges(),
@@ -81,10 +84,10 @@ class TestQueryFilter {
81
84
  query.queryRawCount(),
82
85
  query.queryEnts(),
83
86
  ]);
84
- this.verifyCount(count);
87
+ this.verifyCount(count, expectedCount);
85
88
  this.verifyEdges(edges);
86
89
  this.verifyIDs(ids);
87
- this.verifyRawCount(rawCount);
90
+ this.verifyRawCount(rawCount, expectedCount);
88
91
  this.verifyEnts(ents);
89
92
  }
90
93
  }
@@ -125,7 +128,19 @@ const commonTests = (opts) => {
125
128
  expect(queries.length).toBe(length);
126
129
  const query = queries[0];
127
130
  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`);
131
+ let parts = opts.where.split(" AND ");
132
+ if (parts[parts.length - 1] === "deleted_at IS NULL") {
133
+ parts = parts
134
+ .slice(0, parts.length - 1)
135
+ .concat([
136
+ `${opts.sortCol} < $${result.length + 1}`,
137
+ "deleted_at IS NULL",
138
+ ]);
139
+ }
140
+ else {
141
+ parts.push(`${opts.sortCol} < $${result.length + 1}`);
142
+ }
143
+ expect(query.qs?.whereClause).toBe(`${parts.join(" AND ")} ORDER BY ${opts.sortCol} DESC LIMIT 4`);
129
144
  }
130
145
  function verifyLastBeforeCursorQuery(length = 1) {
131
146
  if (opts.livePostgresDB || opts.sqlite) {
@@ -135,9 +150,21 @@ const commonTests = (opts) => {
135
150
  expect(queries.length).toBe(length);
136
151
  const query = queries[0];
137
152
  const result = [...opts.where.matchAll(preparedVar)];
153
+ let parts = opts.where.split(" AND ");
154
+ if (parts[parts.length - 1] === "deleted_at IS NULL") {
155
+ parts = parts
156
+ .slice(0, parts.length - 1)
157
+ .concat([
158
+ `${opts.sortCol} > $${result.length + 1}`,
159
+ "deleted_at IS NULL",
160
+ ]);
161
+ }
162
+ else {
163
+ parts.push(`${opts.sortCol} > $${result.length + 1}`);
164
+ }
138
165
  expect(query.qs?.whereClause).toBe(
139
166
  // extra fetched for pagination
140
- `${opts.where} AND ${opts.sortCol} > $${result.length + 1} ORDER BY ${opts.sortCol} ASC LIMIT 4`);
167
+ `${parts.join(" AND ")} ORDER BY ${opts.sortCol} ASC LIMIT 4`);
141
168
  }
142
169
  function getViewer() {
143
170
  // live db, let's do context because we're testing complicated paths
@@ -171,10 +198,12 @@ const commonTests = (opts) => {
171
198
  cursorKey: opts.sortCol,
172
199
  });
173
200
  }
201
+ if (opts.globalSchema) {
202
+ (0, ent_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
203
+ }
174
204
  let tdb;
175
205
  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);
206
+ (0, temp_db_1.setupSqlite)(`sqlite:///shared_test+${opts.uniqKey}.db`, () => (0, test_helpers_1.tempDBTables)(opts.globalSchema));
178
207
  }
179
208
  beforeAll(async () => {
180
209
  // want error on by default in tests?
@@ -196,7 +225,7 @@ const commonTests = (opts) => {
196
225
  });
197
226
  describe("simple queries", () => {
198
227
  const filter = new TestQueryFilter((q) => {
199
- // no filterzs
228
+ // no filters
200
229
  return q;
201
230
  }, opts.newQuery, (contacts) => {
202
231
  // nothing to do here
@@ -230,6 +259,55 @@ const commonTests = (opts) => {
230
259
  await filter.testAll();
231
260
  });
232
261
  });
262
+ describe("after delete", () => {
263
+ const filter = new TestQueryFilter((q) => {
264
+ // no filters
265
+ return q;
266
+ }, opts.newQuery, (contacts) => {
267
+ // nothing expected since deleted
268
+ return [];
269
+ }, getViewer());
270
+ beforeEach(async () => {
271
+ await filter.beforeEach();
272
+ const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
273
+ await Promise.all(filter.allContacts.map(async (contact) => {
274
+ action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
275
+ const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
276
+ await action2.save();
277
+ }));
278
+ await action.save();
279
+ db_mock_1.QueryRecorder.clearQueries();
280
+ });
281
+ test("ids", async () => {
282
+ await filter.testIDs();
283
+ verifyQuery({});
284
+ });
285
+ test("rawCount", async () => {
286
+ await filter.testRawCount(0);
287
+ verifyCountQuery({});
288
+ });
289
+ test("count", async () => {
290
+ await filter.testCount(0);
291
+ verifyQuery({});
292
+ });
293
+ test("edges", async () => {
294
+ await filter.testEdges();
295
+ verifyQuery({});
296
+ });
297
+ test("ents", async () => {
298
+ await filter.testEnts();
299
+ // no ents so no subsequent query. just the edge query
300
+ verifyQuery({ length: 1 });
301
+ });
302
+ test("all", async () => {
303
+ await filter.testAll(0);
304
+ });
305
+ test("raw_data", async () => {
306
+ if (opts.rawDataVerify) {
307
+ await opts.rawDataVerify(filter.user);
308
+ }
309
+ });
310
+ });
233
311
  describe("first. no cursor", () => {
234
312
  const N = 2;
235
313
  const filter = new TestQueryFilter((q) => {
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;
@@ -11,13 +11,13 @@ exports.GraphQLConnectionInterface = new graphql_1.GraphQLInterfaceType({
11
11
  description: "connection interface",
12
12
  fields: () => ({
13
13
  edges: {
14
- type: (0, graphql_1.GraphQLNonNull)((0, graphql_1.GraphQLList)((0, graphql_1.GraphQLNonNull)(edge_1.GraphQLEdgeInterface))),
14
+ type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edge_1.GraphQLEdgeInterface))),
15
15
  },
16
16
  nodes: {
17
- type: (0, graphql_1.GraphQLNonNull)((0, graphql_1.GraphQLList)((0, graphql_1.GraphQLNonNull)(node_1.GraphQLNodeInterface))),
17
+ type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface))),
18
18
  },
19
19
  pageInfo: {
20
- type: (0, graphql_1.GraphQLNonNull)(page_info_1.GraphQLPageInfo),
20
+ type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
21
21
  },
22
22
  }),
23
23
  });
@@ -9,10 +9,10 @@ exports.GraphQLEdgeInterface = new graphql_1.GraphQLInterfaceType({
9
9
  description: "edge interface",
10
10
  fields: () => ({
11
11
  node: {
12
- type: (0, graphql_1.GraphQLNonNull)(node_1.GraphQLNodeInterface),
12
+ type: new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface),
13
13
  },
14
14
  cursor: {
15
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLString),
15
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
16
16
  },
17
17
  }),
18
18
  });
@@ -8,7 +8,7 @@ exports.GraphQLNodeInterface = new graphql_1.GraphQLInterfaceType({
8
8
  description: "node interface",
9
9
  fields: () => ({
10
10
  id: {
11
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLID),
11
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
12
12
  },
13
13
  }),
14
14
  });
@@ -79,12 +79,18 @@ const addCustomType = (type) => {
79
79
  description: ct.description,
80
80
  name: ct.name,
81
81
  };
82
- if (ct.specifiedByUrl) {
83
- type.scalarInfo.specifiedByUrl = ct.specifiedByUrl;
82
+ if (ct.specifiedByURL) {
83
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
84
84
  }
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);
@@ -15,10 +15,10 @@ class GraphQLEdgeType extends graphql_1.GraphQLObjectType {
15
15
  name: `${name}Edge`,
16
16
  fields: () => ({
17
17
  node: {
18
- type: (0, graphql_1.GraphQLNonNull)(nodeType),
18
+ type: new graphql_1.GraphQLNonNull(nodeType),
19
19
  },
20
20
  cursor: {
21
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLString),
21
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
22
22
  },
23
23
  ...optional,
24
24
  }),
@@ -34,25 +34,25 @@ class GraphQLConnectionType extends graphql_1.GraphQLObjectType {
34
34
  name: `${name}Connection`,
35
35
  fields: () => ({
36
36
  edges: {
37
- type: (0, graphql_1.GraphQLNonNull)((0, graphql_1.GraphQLList)((0, graphql_1.GraphQLNonNull)(edgeType))),
37
+ type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edgeType))),
38
38
  resolve: (source) => {
39
39
  return source.queryEdges();
40
40
  },
41
41
  },
42
42
  nodes: {
43
- type: (0, graphql_1.GraphQLNonNull)((0, graphql_1.GraphQLList)((0, graphql_1.GraphQLNonNull)(nodeType))),
43
+ type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(nodeType))),
44
44
  resolve: (source) => {
45
45
  return source.queryNodes();
46
46
  },
47
47
  },
48
48
  pageInfo: {
49
- type: (0, graphql_1.GraphQLNonNull)(page_info_1.GraphQLPageInfo),
49
+ type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
50
50
  resolve: (source) => {
51
51
  return source.queryPageInfo();
52
52
  },
53
53
  },
54
54
  rawCount: {
55
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLInt),
55
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
56
56
  resolve: (source) => {
57
57
  return source.queryTotalCount();
58
58
  },
@@ -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>>>;
@@ -7,22 +7,22 @@ exports.GraphQLPageInfo = new graphql_1.GraphQLObjectType({
7
7
  name: "PageInfo",
8
8
  fields: () => ({
9
9
  hasNextPage: {
10
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLBoolean),
10
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
11
11
  resolve: (source) => {
12
12
  return source.hasNextPage || false;
13
13
  },
14
14
  },
15
15
  hasPreviousPage: {
16
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLBoolean),
16
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
17
17
  resolve: (source) => {
18
18
  return source.hasPreviousPage || false;
19
19
  },
20
20
  },
21
21
  startCursor: {
22
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLString),
22
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
23
23
  },
24
24
  endCursor: {
25
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLString),
25
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
26
26
  },
27
27
  }),
28
28
  });
@@ -110,7 +110,7 @@ function sharedAssocTests() {
110
110
  name: "User",
111
111
  fields: {
112
112
  id: {
113
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLID),
113
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
114
114
  },
115
115
  firstName: {
116
116
  type: graphql_1.GraphQLString,
@@ -128,7 +128,7 @@ function sharedAssocTests() {
128
128
  name: "Event",
129
129
  fields: {
130
130
  id: {
131
- type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLID),
131
+ type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
132
132
  },
133
133
  },
134
134
  interfaces: [node_1.GraphQLNodeInterface],
@@ -1,2 +1,2 @@
1
1
  import { GraphQLScalarType } from "graphql";
2
- export declare const GraphQLTime: GraphQLScalarType;
2
+ export declare const GraphQLTime: GraphQLScalarType<Date, string>;
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, 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 };
@@ -20,10 +20,15 @@ declare const query: {
20
20
  LessEq: typeof q.LessEq;
21
21
  ArrayEq: typeof q.ArrayEq;
22
22
  ArrayNotEq: typeof q.ArrayNotEq;
23
- ArrayGreater: typeof q.ArrayGreater;
24
- ArrayLess: typeof q.ArrayLess;
25
- ArrayGreaterEq: typeof q.ArrayGreaterEq;
26
- ArrayLessEq: typeof q.ArrayLessEq;
23
+ PostgresArrayContainsValue: typeof q.PostgresArrayContainsValue;
24
+ PostgresArrayContains: typeof q.PostgresArrayContains;
25
+ PostgresArrayNotContainsValue: typeof q.PostgresArrayNotContainsValue;
26
+ PostgresArrayNotContains: typeof q.PostgresArrayNotContains;
27
+ PostgresArrayOverlaps: typeof q.PostgresArrayOverlaps;
28
+ PostgresArrayNotOverlaps: typeof q.PostgresArrayNotOverlaps;
29
+ JSONPathValuePredicate: typeof q.JSONPathValuePredicate;
30
+ JSONObjectFieldKeyASJSON: typeof q.JSONObjectFieldKeyASJSON;
31
+ JSONObjectFieldKeyAsText: typeof q.JSONObjectFieldKeyAsText;
27
32
  TsQuery: typeof q.TsQuery;
28
33
  PlainToTsQuery: typeof q.PlainToTsQuery;
29
34
  PhraseToTsQuery: typeof q.PhraseToTsQuery;
package/index.js CHANGED
@@ -25,8 +25,8 @@ 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.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.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.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 = 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; } });
@@ -44,6 +44,7 @@ Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function ()
44
44
  Object.defineProperty(exports, "loadRow", { enumerable: true, get: function () { return ent_1.loadRow; } });
45
45
  Object.defineProperty(exports, "loadRows", { enumerable: true, get: function () { return ent_1.loadRows; } });
46
46
  Object.defineProperty(exports, "EditNodeOperation", { enumerable: true, get: function () { return ent_1.EditNodeOperation; } });
47
+ Object.defineProperty(exports, "RawQueryOperation", { enumerable: true, get: function () { return ent_1.RawQueryOperation; } });
47
48
  Object.defineProperty(exports, "EdgeOperation", { enumerable: true, get: function () { return ent_1.EdgeOperation; } });
48
49
  Object.defineProperty(exports, "DeleteNodeOperation", { enumerable: true, get: function () { return ent_1.DeleteNodeOperation; } });
49
50
  Object.defineProperty(exports, "AssocEdge", { enumerable: true, get: function () { return ent_1.AssocEdge; } });
@@ -57,6 +58,7 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
57
58
  Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
58
59
  Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
59
60
  Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
61
+ Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
60
62
  const db_1 = __importDefault(require("./core/db"));
61
63
  exports.DB = db_1.default;
62
64
  __exportStar(require("./core/loaders"), exports);
@@ -116,10 +118,15 @@ const query = {
116
118
  LessEq: q.LessEq,
117
119
  ArrayEq: q.ArrayEq,
118
120
  ArrayNotEq: q.ArrayNotEq,
119
- ArrayGreater: q.ArrayGreater,
120
- ArrayLess: q.ArrayLess,
121
- ArrayGreaterEq: q.ArrayGreaterEq,
122
- ArrayLessEq: q.ArrayLessEq,
121
+ PostgresArrayContainsValue: q.PostgresArrayContainsValue,
122
+ PostgresArrayContains: q.PostgresArrayContains,
123
+ PostgresArrayNotContainsValue: q.PostgresArrayNotContainsValue,
124
+ PostgresArrayNotContains: q.PostgresArrayNotContains,
125
+ PostgresArrayOverlaps: q.PostgresArrayOverlaps,
126
+ PostgresArrayNotOverlaps: q.PostgresArrayNotOverlaps,
127
+ JSONPathValuePredicate: q.JSONPathValuePredicate,
128
+ JSONObjectFieldKeyASJSON: q.JSONObjectFieldKeyASJSON,
129
+ JSONObjectFieldKeyAsText: q.JSONObjectFieldKeyAsText,
123
130
  TsQuery: q.TsQuery,
124
131
  PlainToTsQuery: q.PlainToTsQuery,
125
132
  PhraseToTsQuery: q.PhraseToTsQuery,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha8",
3
+ "version": "0.1.0-alpha80",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "better-sqlite3": "^7.4.1",
34
- "graphql": "^15.5"
34
+ "graphql": "^16.5.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "better-sqlite3": {
@@ -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",
@@ -23,6 +23,8 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
23
23
  assocEdges: ProcessedAssocEdge[];
24
24
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
25
25
  fields: ProcessedField[];
26
+ schemaPath?: string;
27
+ patternNames?: string[];
26
28
  };
27
29
  declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
28
30
  edgeAction?: OutputAction;
@@ -37,6 +39,7 @@ interface ProcessedPattern {
37
39
  name: string;
38
40
  assocEdges: ProcessedAssocEdge[];
39
41
  fields: ProcessedField[];
42
+ disableMixin?: boolean;
40
43
  }
41
44
  declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
42
45
  subFields?: ProcessedField[];
@@ -58,6 +61,15 @@ interface patternsDict {
58
61
  interface Result {
59
62
  schemas: schemasDict;
60
63
  patterns: patternsDict;
64
+ globalSchema?: ProcessedGlobalSchema;
65
+ }
66
+ declare type PotentialSchemas = {
67
+ [key: string]: any;
68
+ };
69
+ export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Result;
70
+ interface ProcessedGlobalSchema {
71
+ globalEdges: ProcessedAssocEdge[];
72
+ extraEdgeFields: ProcessedField[];
73
+ initForEdges?: boolean;
61
74
  }
62
- export declare function parseSchema(potentialSchemas: {}): Result;
63
75
  export {};
@@ -36,6 +36,19 @@ function processFields(src, patternName) {
36
36
  else {
37
37
  delete f.polymorphic;
38
38
  }
39
+ if (field.private) {
40
+ // convert boolean into object
41
+ // we keep boolean as an option to keep API simple
42
+ if (typeof field.private === "boolean") {
43
+ f.private = {};
44
+ }
45
+ else {
46
+ f.private = field.private;
47
+ }
48
+ }
49
+ else {
50
+ delete f.private;
51
+ }
39
52
  // convert string to object to make API consumed by go simple
40
53
  if (f.fieldEdge && f.fieldEdge.inverseEdge) {
41
54
  if (typeof f.fieldEdge.inverseEdge === "string") {
@@ -130,6 +143,7 @@ function processPattern(patterns, pattern, processedSchema) {
130
143
  name: pattern.name,
131
144
  assocEdges: edges,
132
145
  fields: fields,
146
+ disableMixin: pattern.disableMixin,
133
147
  };
134
148
  }
135
149
  else {
@@ -171,9 +185,13 @@ function processAction(action) {
171
185
  ret.actionOnlyFields = actionOnlyFields;
172
186
  return ret;
173
187
  }
174
- function parseSchema(potentialSchemas) {
188
+ function parseSchema(potentialSchemas, globalSchema) {
175
189
  let schemas = {};
176
190
  let patterns = {};
191
+ let parsedGlobalSchema;
192
+ if (globalSchema) {
193
+ parsedGlobalSchema = parseGlobalSchema(globalSchema);
194
+ }
177
195
  for (const key in potentialSchemas) {
178
196
  const value = potentialSchemas[key];
179
197
  let schema;
@@ -189,6 +207,7 @@ function parseSchema(potentialSchemas) {
189
207
  }
190
208
  let processedSchema = {
191
209
  fields: [],
210
+ schemaPath: schema.schemaPath,
192
211
  tableName: schema.tableName,
193
212
  enumTable: schema.enumTable,
194
213
  dbRows: schema.dbRows,
@@ -201,9 +220,11 @@ function parseSchema(potentialSchemas) {
201
220
  };
202
221
  // let's put patterns first just so we have id, created_at, updated_at first
203
222
  // ¯\_(ツ)_/¯
223
+ let patternNames = [];
204
224
  if (schema.patterns) {
205
225
  for (const pattern of schema.patterns) {
206
226
  const ret = processPattern(patterns, pattern, processedSchema);
227
+ patternNames.push(pattern.name);
207
228
  if (ret.transformsSelect) {
208
229
  if (processedSchema.transformsSelect) {
209
230
  throw new Error(`can only have one pattern which transforms default querying behavior`);
@@ -220,6 +241,7 @@ function parseSchema(potentialSchemas) {
220
241
  }
221
242
  const fields = processFields(schema.fields);
222
243
  processedSchema.fields.push(...fields);
244
+ processedSchema.patternNames = patternNames;
223
245
  if (schema.edges) {
224
246
  const edges = processEdges(schema.edges);
225
247
  processedSchema.assocEdges.push(...edges);
@@ -229,6 +251,22 @@ function parseSchema(potentialSchemas) {
229
251
  }
230
252
  schemas[key] = processedSchema;
231
253
  }
232
- return { schemas, patterns };
254
+ return { schemas, patterns, globalSchema: parsedGlobalSchema };
233
255
  }
234
256
  exports.parseSchema = parseSchema;
257
+ function parseGlobalSchema(s) {
258
+ const ret = {
259
+ globalEdges: [],
260
+ extraEdgeFields: [],
261
+ initForEdges: !!s.extraEdgeFields ||
262
+ s.transformEdgeRead !== undefined ||
263
+ s.transformEdgeWrite !== undefined,
264
+ };
265
+ if (s.extraEdgeFields) {
266
+ ret.extraEdgeFields = processFields(s.extraEdgeFields);
267
+ }
268
+ if (s.edges) {
269
+ ret.globalEdges = processEdges(s.edges);
270
+ }
271
+ return ret;
272
+ }