@snowtop/ent 0.1.0-alpha3 → 0.1.0-alpha34

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 (102) hide show
  1. package/action/action.d.ts +28 -24
  2. package/action/executor.d.ts +4 -4
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +21 -20
  5. package/action/experimental_action.js +11 -5
  6. package/action/orchestrator.d.ts +31 -16
  7. package/action/orchestrator.js +164 -43
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +25 -21
  10. package/core/base.js +16 -0
  11. package/core/clause.d.ts +24 -3
  12. package/core/clause.js +246 -5
  13. package/core/config.d.ts +23 -0
  14. package/core/config.js +17 -0
  15. package/core/context.d.ts +2 -2
  16. package/core/convert.d.ts +1 -1
  17. package/core/db.d.ts +3 -3
  18. package/core/db.js +2 -0
  19. package/core/ent.d.ts +19 -21
  20. package/core/ent.js +76 -25
  21. package/core/loaders/assoc_count_loader.d.ts +2 -2
  22. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  23. package/core/loaders/assoc_edge_loader.js +5 -4
  24. package/core/loaders/index_loader.js +1 -0
  25. package/core/loaders/object_loader.d.ts +10 -5
  26. package/core/loaders/object_loader.js +59 -4
  27. package/core/loaders/query_loader.d.ts +2 -2
  28. package/core/loaders/raw_count_loader.d.ts +2 -2
  29. package/core/privacy.d.ts +25 -25
  30. package/core/privacy.js +3 -0
  31. package/core/query/assoc_query.d.ts +6 -6
  32. package/core/query/custom_query.d.ts +5 -5
  33. package/core/query/query.d.ts +1 -1
  34. package/core/viewer.d.ts +4 -3
  35. package/core/viewer.js +4 -0
  36. package/graphql/builtins/connection.js +3 -3
  37. package/graphql/builtins/edge.js +2 -2
  38. package/graphql/builtins/node.js +1 -1
  39. package/graphql/graphql.d.ts +3 -2
  40. package/graphql/graphql.js +24 -23
  41. package/graphql/index.d.ts +1 -0
  42. package/graphql/index.js +3 -1
  43. package/graphql/mutations/union.d.ts +2 -0
  44. package/graphql/mutations/union.js +35 -0
  45. package/graphql/node_resolver.d.ts +0 -1
  46. package/graphql/query/connection_type.js +6 -6
  47. package/graphql/query/edge_connection.d.ts +9 -9
  48. package/graphql/query/page_info.d.ts +1 -1
  49. package/graphql/query/page_info.js +4 -4
  50. package/graphql/query/shared_assoc_test.js +2 -2
  51. package/graphql/scalars/time.d.ts +1 -1
  52. package/index.d.ts +16 -1
  53. package/index.js +18 -5
  54. package/package.json +3 -3
  55. package/parse_schema/parse.d.ts +18 -5
  56. package/parse_schema/parse.js +55 -6
  57. package/schema/base_schema.d.ts +36 -1
  58. package/schema/base_schema.js +51 -2
  59. package/schema/field.d.ts +1 -1
  60. package/schema/field.js +1 -1
  61. package/schema/index.d.ts +2 -2
  62. package/schema/index.js +8 -1
  63. package/schema/schema.d.ts +61 -1
  64. package/schema/schema.js +126 -5
  65. package/schema/union_field.d.ts +2 -1
  66. package/schema/union_field.js +32 -14
  67. package/scripts/custom_graphql.js +122 -15
  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 +15 -1
  71. package/testutils/builder.d.ts +31 -21
  72. package/testutils/builder.js +98 -13
  73. package/testutils/context/test_context.d.ts +2 -2
  74. package/testutils/context/test_context.js +7 -1
  75. package/testutils/db/test_db.d.ts +2 -1
  76. package/testutils/db/test_db.js +13 -4
  77. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  78. package/testutils/ent-graphql-tests/index.js +26 -17
  79. package/testutils/fake_data/fake_contact.d.ts +4 -8
  80. package/testutils/fake_data/fake_contact.js +15 -19
  81. package/testutils/fake_data/fake_event.d.ts +4 -8
  82. package/testutils/fake_data/fake_event.js +21 -25
  83. package/testutils/fake_data/fake_user.d.ts +5 -9
  84. package/testutils/fake_data/fake_user.js +23 -27
  85. package/testutils/fake_data/test_helpers.js +1 -1
  86. package/testutils/fake_data/user_query.d.ts +2 -2
  87. package/testutils/fake_log.d.ts +3 -3
  88. package/tsc/ast.d.ts +43 -0
  89. package/tsc/ast.js +264 -0
  90. package/tsc/compilerOptions.d.ts +6 -0
  91. package/tsc/compilerOptions.js +40 -1
  92. package/tsc/move_generated.d.ts +1 -0
  93. package/tsc/move_generated.js +160 -0
  94. package/tsc/transform.d.ts +21 -0
  95. package/tsc/transform.js +167 -0
  96. package/tsc/transform_action.d.ts +20 -0
  97. package/tsc/transform_action.js +169 -0
  98. package/tsc/transform_ent.d.ts +17 -0
  99. package/tsc/transform_ent.js +59 -0
  100. package/tsc/transform_schema.d.ts +27 -0
  101. package/tsc/transform_schema.js +354 -0
  102. package/scripts/transform_schema.js +0 -288
package/core/viewer.js CHANGED
@@ -27,6 +27,10 @@ class IDViewer {
27
27
  this.ent = opts?.ent || null;
28
28
  this.context = opts?.context;
29
29
  }
30
+ setContext(ctx) {
31
+ this.context = ctx;
32
+ return this;
33
+ }
30
34
  async viewer() {
31
35
  return this.ent;
32
36
  }
@@ -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
  });
@@ -82,6 +82,9 @@ declare enum NullableResult {
82
82
  CONTENTS_AND_LIST = "contentsAndList",
83
83
  ITEM = "true"
84
84
  }
85
+ export declare const knownAllowedNames: Map<string, string>;
86
+ export declare const knownDisAllowedNames: Map<string, boolean>;
87
+ export declare const isCustomType: (type: Type) => type is CustomType;
85
88
  export declare const addCustomType: (type: CustomType) => void;
86
89
  export declare class GQLCapture {
87
90
  private static enabled;
@@ -107,8 +110,6 @@ export declare class GQLCapture {
107
110
  static getProcessedCustomMutations(): ProcessedCustomField[];
108
111
  static getProcessedCustomQueries(): ProcessedCustomField[];
109
112
  private static getProcessedCustomFieldsImpl;
110
- private static knownAllowedNames;
111
- private static knownDisAllowedNames;
112
113
  private static getResultFromMetadata;
113
114
  static gqlField(options?: gqlFieldOptions): any;
114
115
  private static getCustomField;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.CustomFieldType = void 0;
3
+ exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
4
4
  require("reflect-metadata");
5
5
  // export interface gqlTopLevelOptions
6
6
  // name?: string;
@@ -20,6 +20,22 @@ var NullableResult;
20
20
  NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
21
21
  NullableResult["ITEM"] = "true";
22
22
  })(NullableResult || (NullableResult = {}));
23
+ exports.knownAllowedNames = new Map([
24
+ ["Date", "Date"],
25
+ ["Boolean", "boolean"],
26
+ ["Number", "number"],
27
+ ["String", "string"],
28
+ // TODO not right to have this and Number
29
+ ["Int", "number"],
30
+ ["Float", "number"],
31
+ ["ID", "ID"],
32
+ ]);
33
+ exports.knownDisAllowedNames = new Map([
34
+ ["Function", true],
35
+ ["Object", true],
36
+ ["Array", true],
37
+ ["Promise", true],
38
+ ]);
23
39
  const isArray = (type) => {
24
40
  if (typeof type === "function") {
25
41
  return false;
@@ -41,6 +57,7 @@ const isString = (type) => {
41
57
  const isCustomType = (type) => {
42
58
  return type.importPath !== undefined;
43
59
  };
60
+ exports.isCustomType = isCustomType;
44
61
  const isGraphQLScalarType = (type) => {
45
62
  return type.serialize !== undefined;
46
63
  };
@@ -62,8 +79,8 @@ const addCustomType = (type) => {
62
79
  description: ct.description,
63
80
  name: ct.name,
64
81
  };
65
- if (ct.specifiedByUrl) {
66
- type.scalarInfo.specifiedByUrl = ct.specifiedByUrl;
82
+ if (ct.specifiedByURL) {
83
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
67
84
  }
68
85
  }
69
86
  }
@@ -92,7 +109,7 @@ const getType = (typ, result) => {
92
109
  }
93
110
  return;
94
111
  }
95
- if (isCustomType(typ)) {
112
+ if ((0, exports.isCustomType)(typ)) {
96
113
  result.type = typ.type;
97
114
  (0, exports.addCustomType)(typ);
98
115
  return;
@@ -197,20 +214,20 @@ class GQLCapture {
197
214
  connection = r.connection;
198
215
  type = r.type;
199
216
  }
200
- if (GQLCapture.knownDisAllowedNames.has(type)) {
217
+ if (exports.knownDisAllowedNames.has(type)) {
201
218
  throw new Error(`${type} isn't a valid type for accessor/function/property`);
202
219
  }
203
220
  let result = {
204
221
  name: metadata.paramName || "",
205
222
  type,
206
- tsType: this.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
223
+ tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
207
224
  nullable: options?.nullable,
208
225
  list: list,
209
226
  connection: connection,
210
227
  isContextArg: metadata.isContextArg,
211
228
  };
212
229
  // unknown type. we need to flag that this field needs to eventually be resolved
213
- if (!GQLCapture.knownAllowedNames.has(type)) {
230
+ if (!exports.knownAllowedNames.has(type)) {
214
231
  if (scalarType) {
215
232
  throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
216
233
  }
@@ -461,22 +478,6 @@ GQLCapture.customArgs = new Map();
461
478
  GQLCapture.customInputObjects = new Map();
462
479
  GQLCapture.customObjects = new Map();
463
480
  GQLCapture.customTypes = new Map();
464
- GQLCapture.knownAllowedNames = new Map([
465
- ["Date", "Date"],
466
- ["Boolean", "boolean"],
467
- ["Number", "number"],
468
- ["String", "string"],
469
- // TODO not right to have this and Number
470
- ["Int", "number"],
471
- ["Float", "number"],
472
- ["ID", "ID"],
473
- ]);
474
- GQLCapture.knownDisAllowedNames = new Map([
475
- ["Function", true],
476
- ["Object", true],
477
- ["Array", true],
478
- ["Promise", true],
479
- ]);
480
481
  // User -> add -> [{name, options}, {}, {}]
481
482
  GQLCapture.argMap = new Map();
482
483
  // why is this a static class lol?
@@ -8,3 +8,4 @@ export { GraphQLConnectionInterface } from "./builtins/connection";
8
8
  export { GraphQLEdgeInterface } from "./builtins/edge";
9
9
  export { NodeResolver, EntNodeResolver, registerResolver, clearResolvers, resolveID, nodeIDEncoder, mustDecodeIDFromGQLID, mustDecodeNullableIDFromGQLID, encodeGQLID, } from "./node_resolver";
10
10
  export { convertFromGQLEnum, convertToGQLEnum } from "./enums";
11
+ export { transformUnionTypes } from "./mutations/union";
package/graphql/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToGQLEnum = exports.convertFromGQLEnum = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLTime = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = void 0;
3
+ exports.transformUnionTypes = exports.convertToGQLEnum = exports.convertFromGQLEnum = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLTime = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = void 0;
4
4
  var graphql_1 = require("./graphql");
5
5
  Object.defineProperty(exports, "gqlField", { enumerable: true, get: function () { return graphql_1.gqlField; } });
6
6
  Object.defineProperty(exports, "gqlArg", { enumerable: true, get: function () { return graphql_1.gqlArg; } });
@@ -40,3 +40,5 @@ Object.defineProperty(exports, "encodeGQLID", { enumerable: true, get: function
40
40
  var enums_1 = require("./enums");
41
41
  Object.defineProperty(exports, "convertFromGQLEnum", { enumerable: true, get: function () { return enums_1.convertFromGQLEnum; } });
42
42
  Object.defineProperty(exports, "convertToGQLEnum", { enumerable: true, get: function () { return enums_1.convertToGQLEnum; } });
43
+ var union_1 = require("./mutations/union");
44
+ Object.defineProperty(exports, "transformUnionTypes", { enumerable: true, get: function () { return union_1.transformUnionTypes; } });
@@ -0,0 +1,2 @@
1
+ import { Data } from "../../core/base";
2
+ export declare function transformUnionTypes<T extends Data>(input: T, pathsList: string[][]): T;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformUnionTypes = void 0;
4
+ // this transforms an input for union types from graphql format to TS format
5
+ // in graphql, we represent it as UnionType = {foo: FooType, bar: BarType, baz: BazType}
6
+ // in TS, we repseent it as UnionType = FooType | BarType | BazType
7
+ // this takes an input, paths to unions and transforms them as needed
8
+ // only works on fields that are defined. depends on graphql to handle nullable/missing fields
9
+ function transformUnionTypes(input, pathsList) {
10
+ for (const paths of pathsList) {
11
+ const lastPath = paths[paths.length - 1];
12
+ let last = input;
13
+ for (const path of paths) {
14
+ let curr = last[path];
15
+ if (curr === undefined) {
16
+ break;
17
+ }
18
+ if (path === lastPath) {
19
+ let count = 0;
20
+ let lastKey = undefined;
21
+ for (const k in curr) {
22
+ count++;
23
+ lastKey = k;
24
+ }
25
+ if (count != 1) {
26
+ throw new Error(`can only only pass one key of union. passed ${count}`);
27
+ }
28
+ last[path] = curr[lastKey];
29
+ }
30
+ last = curr;
31
+ }
32
+ }
33
+ return input;
34
+ }
35
+ exports.transformUnionTypes = transformUnionTypes;
@@ -5,7 +5,6 @@ interface Node {
5
5
  id: ID;
6
6
  }
7
7
  export interface NodeResolver {
8
- encode(node: Node): string;
9
8
  decodeObj(viewer: Viewer, id: string): Promise<Node | null>;
10
9
  }
11
10
  interface loadEnt {
@@ -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, applyPrivacyPolicyForEnt, applyPrivacyPolicyForEntX, 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, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, } from "./core/ent";
3
3
  import DB from "./core/db";
4
4
  export * from "./core/loaders";
5
5
  export { DB };
@@ -11,12 +11,27 @@ declare const query: {
11
11
  Eq: typeof q.Eq;
12
12
  NotEq: typeof q.NotEq;
13
13
  And: typeof q.And;
14
+ AndOptional: typeof q.AndOptional;
14
15
  Or: typeof q.Or;
15
16
  In: typeof q.In;
16
17
  Greater: typeof q.Greater;
17
18
  Less: typeof q.Less;
18
19
  GreaterEq: typeof q.GreaterEq;
19
20
  LessEq: typeof q.LessEq;
21
+ ArrayEq: typeof q.ArrayEq;
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;
27
+ TsQuery: typeof q.TsQuery;
28
+ PlainToTsQuery: typeof q.PlainToTsQuery;
29
+ PhraseToTsQuery: typeof q.PhraseToTsQuery;
30
+ WebsearchToTsQuery: typeof q.WebsearchToTsQuery;
31
+ TsVectorColTsQuery: typeof q.TsVectorColTsQuery;
32
+ TsVectorPlainToTsQuery: typeof q.TsVectorPlainToTsQuery;
33
+ TsVectorPhraseToTsQuery: typeof q.TsVectorPhraseToTsQuery;
34
+ TsVectorWebsearchToTsQuery: typeof q.TsVectorWebsearchToTsQuery;
20
35
  };
21
36
  export { query };
22
37
  export { RequestContext, ContextCache } from "./core/context";
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.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.applyPrivacyPolicyForEntX = exports.applyPrivacyPolicyForEnt = 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;
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;
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; } });
@@ -38,8 +38,6 @@ Object.defineProperty(exports, "loadDerivedEnt", { enumerable: true, get: functi
38
38
  Object.defineProperty(exports, "loadDerivedEntX", { enumerable: true, get: function () { return ent_1.loadDerivedEntX; } });
39
39
  Object.defineProperty(exports, "loadEntViaKey", { enumerable: true, get: function () { return ent_1.loadEntViaKey; } });
40
40
  Object.defineProperty(exports, "loadEntXViaKey", { enumerable: true, get: function () { return ent_1.loadEntXViaKey; } });
41
- Object.defineProperty(exports, "applyPrivacyPolicyForEnt", { enumerable: true, get: function () { return ent_1.applyPrivacyPolicyForEnt; } });
42
- Object.defineProperty(exports, "applyPrivacyPolicyForEntX", { enumerable: true, get: function () { return ent_1.applyPrivacyPolicyForEntX; } });
43
41
  Object.defineProperty(exports, "performRawQuery", { enumerable: true, get: function () { return ent_1.performRawQuery; } });
44
42
  // even these 3 need to change...
45
43
  Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function () { return ent_1.loadRowX; } });
@@ -62,7 +60,7 @@ Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: fu
62
60
  const db_1 = __importDefault(require("./core/db"));
63
61
  exports.DB = db_1.default;
64
62
  __exportStar(require("./core/loaders"), exports);
65
- // TODO figure out if this should be its own
63
+ // TODO figure out if this should be its own import path e.g. @snowtop/ent/privacy
66
64
  var privacy_1 = require("./core/privacy");
67
65
  Object.defineProperty(exports, "EntPrivacyError", { enumerable: true, get: function () { return privacy_1.EntPrivacyError; } });
68
66
  Object.defineProperty(exports, "AlwaysAllowRule", { enumerable: true, get: function () { return privacy_1.AlwaysAllowRule; } });
@@ -109,12 +107,27 @@ const query = {
109
107
  Eq: q.Eq,
110
108
  NotEq: q.NotEq,
111
109
  And: q.And,
110
+ AndOptional: q.AndOptional,
112
111
  Or: q.Or,
113
112
  In: q.In,
114
113
  Greater: q.Greater,
115
114
  Less: q.Less,
116
115
  GreaterEq: q.GreaterEq,
117
116
  LessEq: q.LessEq,
117
+ ArrayEq: q.ArrayEq,
118
+ ArrayNotEq: q.ArrayNotEq,
119
+ ArrayGreater: q.ArrayGreater,
120
+ ArrayLess: q.ArrayLess,
121
+ ArrayGreaterEq: q.ArrayGreaterEq,
122
+ ArrayLessEq: q.ArrayLessEq,
123
+ TsQuery: q.TsQuery,
124
+ PlainToTsQuery: q.PlainToTsQuery,
125
+ PhraseToTsQuery: q.PhraseToTsQuery,
126
+ WebsearchToTsQuery: q.WebsearchToTsQuery,
127
+ TsVectorColTsQuery: q.TsVectorColTsQuery,
128
+ TsVectorPlainToTsQuery: q.TsVectorPlainToTsQuery,
129
+ TsVectorPhraseToTsQuery: q.TsVectorPhraseToTsQuery,
130
+ TsVectorWebsearchToTsQuery: q.TsVectorWebsearchToTsQuery,
118
131
  };
119
132
  exports.query = query;
120
133
  var context_1 = require("./core/context");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha3",
3
+ "version": "0.1.0-alpha34",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "json5": "^2.1.3",
18
18
  "luxon": "^1.25.0",
19
19
  "memoizee": "^0.4.15",
20
- "minimist": "^1.2.5",
20
+ "minimist": "^1.2.6",
21
21
  "pascal-case": "^3.1.2",
22
22
  "pg": "^8.0.3",
23
23
  "prettier": "^2.3.2",
@@ -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
- import { Schema, Field, AssocEdge, AssocEdgeGroup, Action, Type } from "../schema";
2
- import { ActionField } from "../schema/schema";
1
+ import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
+ import { ActionField, Type } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
@@ -12,11 +12,19 @@ declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActi
12
12
  patternName?: string;
13
13
  edgeActions?: OutputAction[];
14
14
  };
15
- declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & {
15
+ interface TransformFlags {
16
+ transformsSelect?: boolean;
17
+ transformsDelete?: boolean;
18
+ transformsInsert?: boolean;
19
+ transformsUpdate?: boolean;
20
+ }
21
+ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
16
22
  actions: OutputAction[];
17
23
  assocEdges: ProcessedAssocEdge[];
18
24
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
19
25
  fields: ProcessedField[];
26
+ schemaPath?: string;
27
+ patternNames?: string[];
20
28
  };
21
29
  declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
22
30
  edgeAction?: OutputAction;
@@ -31,17 +39,19 @@ interface ProcessedPattern {
31
39
  name: string;
32
40
  assocEdges: ProcessedAssocEdge[];
33
41
  fields: ProcessedField[];
42
+ disableMixin?: boolean;
34
43
  }
35
44
  declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
36
45
  subFields?: ProcessedField[];
37
46
  listElemType?: ProcessedType;
38
47
  unionFields?: ProcessedField[];
39
48
  };
40
- declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "type"> & {
49
+ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
41
50
  name: string;
42
51
  hasDefaultValueOnCreate?: boolean;
43
52
  hasDefaultValueOnEdit?: boolean;
44
53
  patternName?: string;
54
+ hasFieldPrivacy?: boolean;
45
55
  derivedFields?: ProcessedField[];
46
56
  type: ProcessedType;
47
57
  };
@@ -52,5 +62,8 @@ interface Result {
52
62
  schemas: schemasDict;
53
63
  patterns: patternsDict;
54
64
  }
55
- export declare function parseSchema(potentialSchemas: {}): Result;
65
+ declare type PotentialSchemas = {
66
+ [key: string]: any;
67
+ };
68
+ export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
56
69
  export {};