@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha100

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 (172) hide show
  1. package/action/action.d.ts +38 -30
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +4 -4
  4. package/action/executor.js +8 -3
  5. package/action/experimental_action.d.ts +32 -22
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +2 -0
  8. package/action/index.js +7 -1
  9. package/action/orchestrator.d.ts +48 -16
  10. package/action/orchestrator.js +343 -81
  11. package/action/privacy.d.ts +2 -2
  12. package/action/relative_value.d.ts +47 -0
  13. package/action/relative_value.js +125 -0
  14. package/action/transaction.d.ts +10 -0
  15. package/action/transaction.js +23 -0
  16. package/auth/auth.d.ts +1 -1
  17. package/core/base.d.ts +54 -27
  18. package/core/base.js +23 -1
  19. package/core/clause.d.ts +105 -3
  20. package/core/clause.js +563 -30
  21. package/core/config.d.ts +30 -1
  22. package/core/config.js +24 -1
  23. package/core/context.d.ts +5 -3
  24. package/core/context.js +20 -2
  25. package/core/convert.d.ts +1 -1
  26. package/core/date.js +1 -5
  27. package/core/db.d.ts +14 -11
  28. package/core/db.js +22 -8
  29. package/core/ent.d.ts +82 -28
  30. package/core/ent.js +692 -202
  31. package/core/loaders/assoc_count_loader.d.ts +3 -2
  32. package/core/loaders/assoc_count_loader.js +10 -2
  33. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  34. package/core/loaders/assoc_edge_loader.js +13 -15
  35. package/core/loaders/index.d.ts +1 -1
  36. package/core/loaders/index.js +1 -3
  37. package/core/loaders/index_loader.d.ts +2 -2
  38. package/core/loaders/index_loader.js +1 -0
  39. package/core/loaders/loader.js +5 -5
  40. package/core/loaders/object_loader.d.ts +13 -7
  41. package/core/loaders/object_loader.js +95 -32
  42. package/core/loaders/query_loader.d.ts +6 -12
  43. package/core/loaders/query_loader.js +52 -11
  44. package/core/loaders/raw_count_loader.d.ts +2 -2
  45. package/core/loaders/raw_count_loader.js +5 -1
  46. package/core/logger.d.ts +1 -1
  47. package/core/logger.js +1 -0
  48. package/core/privacy.d.ts +26 -25
  49. package/core/privacy.js +23 -24
  50. package/core/query/assoc_query.d.ts +7 -6
  51. package/core/query/assoc_query.js +9 -1
  52. package/core/query/custom_clause_query.d.ts +26 -0
  53. package/core/query/custom_clause_query.js +78 -0
  54. package/core/query/custom_query.d.ts +20 -5
  55. package/core/query/custom_query.js +87 -12
  56. package/core/query/index.d.ts +1 -0
  57. package/core/query/index.js +3 -1
  58. package/core/query/query.d.ts +8 -4
  59. package/core/query/query.js +101 -53
  60. package/core/query/shared_assoc_test.d.ts +2 -1
  61. package/core/query/shared_assoc_test.js +35 -45
  62. package/core/query/shared_test.d.ts +8 -1
  63. package/core/query/shared_test.js +469 -236
  64. package/core/viewer.d.ts +4 -3
  65. package/core/viewer.js +5 -1
  66. package/graphql/builtins/connection.js +3 -3
  67. package/graphql/builtins/edge.js +2 -2
  68. package/graphql/builtins/node.js +1 -1
  69. package/graphql/graphql.d.ts +17 -9
  70. package/graphql/graphql.js +47 -30
  71. package/graphql/index.d.ts +1 -1
  72. package/graphql/index.js +3 -4
  73. package/graphql/mutations/union.d.ts +2 -0
  74. package/graphql/mutations/union.js +35 -0
  75. package/graphql/node_resolver.d.ts +0 -1
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/connection_type.js +6 -6
  78. package/graphql/query/edge_connection.d.ts +9 -9
  79. package/graphql/query/page_info.d.ts +1 -1
  80. package/graphql/query/page_info.js +4 -4
  81. package/graphql/query/shared_assoc_test.js +3 -3
  82. package/graphql/query/shared_edge_connection.js +1 -19
  83. package/graphql/scalars/time.d.ts +1 -1
  84. package/imports/index.d.ts +6 -1
  85. package/imports/index.js +19 -4
  86. package/index.d.ts +23 -1
  87. package/index.js +32 -6
  88. package/package.json +18 -17
  89. package/parse_schema/parse.d.ts +45 -8
  90. package/parse_schema/parse.js +193 -15
  91. package/schema/base_schema.d.ts +38 -1
  92. package/schema/base_schema.js +53 -2
  93. package/schema/field.d.ts +75 -21
  94. package/schema/field.js +185 -72
  95. package/schema/index.d.ts +4 -2
  96. package/schema/index.js +15 -2
  97. package/schema/json_field.d.ts +13 -1
  98. package/schema/json_field.js +28 -1
  99. package/schema/schema.d.ts +125 -10
  100. package/schema/schema.js +133 -5
  101. package/schema/struct_field.d.ts +27 -0
  102. package/schema/struct_field.js +138 -0
  103. package/schema/union_field.d.ts +23 -0
  104. package/schema/union_field.js +79 -0
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +224 -36
  107. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  108. package/scripts/migrate_v0.1.js +36 -0
  109. package/scripts/move_types.d.ts +1 -0
  110. package/scripts/move_types.js +117 -0
  111. package/scripts/read_schema.js +35 -6
  112. package/testutils/action/complex_schemas.d.ts +69 -0
  113. package/testutils/action/complex_schemas.js +398 -0
  114. package/testutils/builder.d.ts +52 -49
  115. package/testutils/builder.js +143 -44
  116. package/testutils/context/test_context.d.ts +2 -2
  117. package/testutils/context/test_context.js +7 -1
  118. package/testutils/db/fixture.d.ts +10 -0
  119. package/testutils/db/fixture.js +26 -0
  120. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +26 -9
  121. package/testutils/db/{test_db.js → temp_db.js} +190 -46
  122. package/testutils/db/value.d.ts +7 -0
  123. package/testutils/db/value.js +251 -0
  124. package/testutils/db_mock.d.ts +16 -4
  125. package/testutils/db_mock.js +51 -6
  126. package/testutils/db_time_zone.d.ts +4 -0
  127. package/testutils/db_time_zone.js +41 -0
  128. package/testutils/ent-graphql-tests/index.d.ts +9 -1
  129. package/testutils/ent-graphql-tests/index.js +53 -25
  130. package/testutils/fake_data/const.d.ts +2 -1
  131. package/testutils/fake_data/const.js +3 -0
  132. package/testutils/fake_data/fake_contact.d.ts +10 -10
  133. package/testutils/fake_data/fake_contact.js +23 -21
  134. package/testutils/fake_data/fake_event.d.ts +8 -9
  135. package/testutils/fake_data/fake_event.js +25 -28
  136. package/testutils/fake_data/fake_tag.d.ts +36 -0
  137. package/testutils/fake_data/fake_tag.js +89 -0
  138. package/testutils/fake_data/fake_user.d.ts +10 -11
  139. package/testutils/fake_data/fake_user.js +20 -23
  140. package/testutils/fake_data/index.js +5 -1
  141. package/testutils/fake_data/internal.d.ts +2 -0
  142. package/testutils/fake_data/internal.js +7 -1
  143. package/testutils/fake_data/tag_query.d.ts +13 -0
  144. package/testutils/fake_data/tag_query.js +43 -0
  145. package/testutils/fake_data/test_helpers.d.ts +11 -4
  146. package/testutils/fake_data/test_helpers.js +29 -13
  147. package/testutils/fake_data/user_query.d.ts +13 -6
  148. package/testutils/fake_data/user_query.js +54 -22
  149. package/testutils/fake_log.d.ts +3 -3
  150. package/testutils/parse_sql.d.ts +6 -0
  151. package/testutils/parse_sql.js +16 -2
  152. package/testutils/test_edge_global_schema.d.ts +15 -0
  153. package/testutils/test_edge_global_schema.js +62 -0
  154. package/testutils/write.d.ts +2 -2
  155. package/testutils/write.js +33 -7
  156. package/tsc/ast.d.ts +44 -0
  157. package/tsc/ast.js +277 -0
  158. package/tsc/compilerOptions.d.ts +6 -0
  159. package/tsc/compilerOptions.js +45 -2
  160. package/tsc/move_generated.d.ts +1 -0
  161. package/tsc/move_generated.js +164 -0
  162. package/tsc/transform.d.ts +22 -0
  163. package/tsc/transform.js +181 -0
  164. package/tsc/transform_action.d.ts +22 -0
  165. package/tsc/transform_action.js +183 -0
  166. package/tsc/transform_ent.d.ts +17 -0
  167. package/tsc/transform_ent.js +59 -0
  168. package/tsc/transform_schema.d.ts +27 -0
  169. package/tsc/transform_schema.js +383 -0
  170. package/graphql/enums.d.ts +0 -3
  171. package/graphql/enums.js +0 -25
  172. package/scripts/transform_schema.js +0 -288
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;
@@ -17,6 +17,7 @@ export declare class IDViewer implements Viewer {
17
17
  context?: Context;
18
18
  constructor(viewerID: ID, opts?: Partial<IDViewerOptions>);
19
19
  constructor(opts: IDViewerOptions);
20
- viewer(): Promise<Ent | null>;
20
+ setContext(ctx: Context): this;
21
+ viewer(): Promise<Ent<Viewer<Ent<any> | null, ID | null>> | null>;
21
22
  instanceKey(): string;
22
23
  }
package/core/viewer.js CHANGED
@@ -27,11 +27,15 @@ 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
  }
33
37
  instanceKey() {
34
- return `idViewer: ${this.viewerID}`;
38
+ return `idViewer:${this.viewerID}`;
35
39
  }
36
40
  }
37
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
  });
@@ -3,15 +3,20 @@ import { GraphQLScalarType } from "graphql";
3
3
  interface ClassType<T = any> {
4
4
  new (...args: any[]): T;
5
5
  }
6
+ declare type StringToStringMap = {
7
+ [key: string]: string;
8
+ };
6
9
  export interface CustomType {
7
10
  type: string;
8
11
  importPath: string;
9
12
  tsType?: string;
10
13
  tsImportPath?: string;
14
+ enumMap?: StringToStringMap;
15
+ inputType?: boolean;
11
16
  [x: string]: any;
12
17
  }
13
- declare type Type = GraphQLScalarType | ClassType | string | CustomType;
14
- export declare type GraphQLConnection<T> = {
18
+ type Type = GraphQLScalarType | ClassType | string | CustomType;
19
+ export type GraphQLConnection<T> = {
15
20
  node: T;
16
21
  };
17
22
  export interface gqlFieldOptions {
@@ -24,7 +29,7 @@ export interface gqlObjectOptions {
24
29
  name?: string;
25
30
  description?: string;
26
31
  }
27
- declare type gqlTopLevelOptions = Exclude<gqlFieldOptions, "nullable">;
32
+ type gqlTopLevelOptions = Exclude<gqlFieldOptions, "nullable">;
28
33
  export declare enum CustomFieldType {
29
34
  Accessor = "ACCESSOR",
30
35
  Field = "FIELD",
@@ -42,6 +47,8 @@ interface CustomFieldImpl {
42
47
  export interface CustomField extends CustomFieldImpl {
43
48
  args: Field[];
44
49
  results: Field[];
50
+ extraImports?: any[];
51
+ functionContents?: string;
45
52
  }
46
53
  export interface CustomMutation extends CustomField {
47
54
  }
@@ -51,15 +58,15 @@ export interface ProcessedCustomField extends CustomFieldImpl {
51
58
  args: ProcessedField[];
52
59
  results: ProcessedField[];
53
60
  }
54
- export declare type ProcessCustomFieldMap = {
55
- [key: string]: ProcessedCustomField;
61
+ export type ProcessCustomFieldMap = {
62
+ [key: string]: ProcessedCustomField[];
56
63
  };
57
64
  export interface CustomObject {
58
65
  nodeName: string;
59
66
  className: string;
60
67
  description?: string;
61
68
  }
62
- declare type NullableListOptions = "contents" | "contentsAndList";
69
+ type NullableListOptions = "contents" | "contentsAndList";
63
70
  interface FieldImpl {
64
71
  type: string;
65
72
  tsType?: string;
@@ -82,7 +89,10 @@ declare enum NullableResult {
82
89
  CONTENTS_AND_LIST = "contentsAndList",
83
90
  ITEM = "true"
84
91
  }
85
- export declare const addCustomType: (type: CustomType) => void;
92
+ export declare const knownAllowedNames: Map<string, string>;
93
+ export declare const knownDisAllowedNames: Map<string, boolean>;
94
+ export declare const isCustomType: (type: Type) => type is CustomType;
95
+ export declare const addCustomType: (type: CustomType, gqlCapture: typeof GQLCapture) => void;
86
96
  export declare class GQLCapture {
87
97
  private static enabled;
88
98
  static enable(enabled: boolean): void;
@@ -107,8 +117,6 @@ export declare class GQLCapture {
107
117
  static getProcessedCustomMutations(): ProcessedCustomField[];
108
118
  static getProcessedCustomQueries(): ProcessedCustomField[];
109
119
  private static getProcessedCustomFieldsImpl;
110
- private static knownAllowedNames;
111
- private static knownDisAllowedNames;
112
120
  private static getResultFromMetadata;
113
121
  static gqlField(options?: gqlFieldOptions): any;
114
122
  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,16 +57,19 @@ 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
  };
47
- const addCustomType = (type) => {
64
+ const addCustomType = (type, gqlCapture) => {
48
65
  // TODO these should return ReadOnly objects...
49
- const customType = GQLCapture.getCustomTypes().get(type.type);
50
- if (customType && customType !== type) {
51
- throw new Error(`cannot add multiple custom types of name ${type.type}`);
66
+ const customTypes = gqlCapture.getCustomTypes();
67
+ const customType = customTypes.get(type.type);
68
+ if (customType && customType === type) {
69
+ return;
52
70
  }
53
- if (customType) {
71
+ if (type.enumMap) {
72
+ customTypes.set(type.type, type);
54
73
  return;
55
74
  }
56
75
  try {
@@ -62,15 +81,27 @@ const addCustomType = (type) => {
62
81
  description: ct.description,
63
82
  name: ct.name,
64
83
  };
65
- if (ct.specifiedByUrl) {
66
- type.scalarInfo.specifiedByUrl = ct.specifiedByUrl;
84
+ if (ct.specifiedByURL) {
85
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
67
86
  }
68
87
  }
69
88
  }
70
89
  catch (e) {
90
+ if (type.secondaryImportPath) {
91
+ (0, exports.addCustomType)({
92
+ ...type,
93
+ importPath: type.secondaryImportPath,
94
+ }, gqlCapture);
95
+ }
71
96
  return;
72
97
  }
73
- GQLCapture.getCustomTypes().set(type.type, type);
98
+ if (customType) {
99
+ if (JSON.stringify(customType) !== JSON.stringify(type)) {
100
+ throw new Error(`cannot add multiple custom types of name ${type.type}`);
101
+ }
102
+ return;
103
+ }
104
+ customTypes.set(type.type, type);
74
105
  };
75
106
  exports.addCustomType = addCustomType;
76
107
  const getType = (typ, result) => {
@@ -92,9 +123,10 @@ const getType = (typ, result) => {
92
123
  }
93
124
  return;
94
125
  }
95
- if (isCustomType(typ)) {
126
+ if ((0, exports.isCustomType)(typ)) {
96
127
  result.type = typ.type;
97
- (0, exports.addCustomType)(typ);
128
+ // TODO???
129
+ (0, exports.addCustomType)(typ, GQLCapture);
98
130
  return;
99
131
  }
100
132
  // GraphQLScalarType or ClassType
@@ -197,20 +229,20 @@ class GQLCapture {
197
229
  connection = r.connection;
198
230
  type = r.type;
199
231
  }
200
- if (GQLCapture.knownDisAllowedNames.has(type)) {
232
+ if (exports.knownDisAllowedNames.has(type)) {
201
233
  throw new Error(`${type} isn't a valid type for accessor/function/property`);
202
234
  }
203
235
  let result = {
204
236
  name: metadata.paramName || "",
205
237
  type,
206
- tsType: this.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
238
+ tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
207
239
  nullable: options?.nullable,
208
240
  list: list,
209
241
  connection: connection,
210
242
  isContextArg: metadata.isContextArg,
211
243
  };
212
244
  // unknown type. we need to flag that this field needs to eventually be resolved
213
- if (!GQLCapture.knownAllowedNames.has(type)) {
245
+ if (!exports.knownAllowedNames.has(type)) {
214
246
  if (scalarType) {
215
247
  throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
216
248
  }
@@ -416,6 +448,7 @@ class GQLCapture {
416
448
  this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
417
449
  baseArgs.set("Context", true);
418
450
  this.customTypes.forEach((_val, key) => baseArgs.set(key, true));
451
+ // TODO this should be aware of knownCustomTypes
419
452
  const resolveFields = (fields) => {
420
453
  fields.forEach((field) => {
421
454
  // we have a check earlier that *should* make this path impossible
@@ -461,22 +494,6 @@ GQLCapture.customArgs = new Map();
461
494
  GQLCapture.customInputObjects = new Map();
462
495
  GQLCapture.customObjects = new Map();
463
496
  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
497
  // User -> add -> [{name, options}, {}, {}]
481
498
  GQLCapture.argMap = new Map();
482
499
  // why is this a static class lol?
@@ -7,4 +7,4 @@ export { GraphQLNodeInterface } from "./builtins/node";
7
7
  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
- export { convertFromGQLEnum, convertToGQLEnum } from "./enums";
10
+ 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.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; } });
@@ -37,6 +37,5 @@ Object.defineProperty(exports, "nodeIDEncoder", { enumerable: true, get: functio
37
37
  Object.defineProperty(exports, "mustDecodeIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeIDFromGQLID; } });
38
38
  Object.defineProperty(exports, "mustDecodeNullableIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeNullableIDFromGQLID; } });
39
39
  Object.defineProperty(exports, "encodeGQLID", { enumerable: true, get: function () { return node_resolver_1.encodeGQLID; } });
40
- var enums_1 = require("./enums");
41
- Object.defineProperty(exports, "convertFromGQLEnum", { enumerable: true, get: function () { return enums_1.convertFromGQLEnum; } });
42
- Object.defineProperty(exports, "convertToGQLEnum", { enumerable: true, get: function () { return enums_1.convertToGQLEnum; } });
40
+ var union_1 = require("./mutations/union");
41
+ 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 {
@@ -1,16 +1,16 @@
1
1
  import { GraphQLFieldConfigMap, GraphQLObjectType, GraphQLInterfaceType } from "graphql";
2
2
  import { RequestContext } from "../../core/context";
3
3
  import { GraphQLEdge } from "./edge_connection";
4
- import { Data } from "../../core/base";
5
- declare type nodeType = GraphQLObjectType | GraphQLInterfaceType;
6
- export declare class GraphQLEdgeType<TNode extends nodeType, TEdge extends Data> extends GraphQLObjectType {
7
- constructor(name: string, nodeType: TNode, optionalFields?: () => GraphQLFieldConfigMap<GraphQLEdge<TEdge>, RequestContext>);
4
+ import { Data, Viewer } from "../../core/base";
5
+ type nodeType = GraphQLObjectType | GraphQLInterfaceType;
6
+ export declare class GraphQLEdgeType<TNode extends nodeType, TEdge extends Data, TViewer extends Viewer> extends GraphQLObjectType {
7
+ constructor(name: string, nodeType: TNode, optionalFields?: () => GraphQLFieldConfigMap<GraphQLEdge<TEdge>, RequestContext<TViewer>>);
8
8
  }
9
- interface connectionOptions<T extends Data> {
10
- fields?(): GraphQLFieldConfigMap<GraphQLEdge<T>, RequestContext>;
9
+ interface connectionOptions<T extends Data, TViewer extends Viewer> {
10
+ fields?(): GraphQLFieldConfigMap<GraphQLEdge<T>, RequestContext<TViewer>>;
11
11
  }
12
- export declare class GraphQLConnectionType<TNode extends nodeType, TEdge extends Data> extends GraphQLObjectType {
13
- edgeType: GraphQLEdgeType<TNode, TEdge>;
14
- constructor(name: string, nodeType: TNode, options?: connectionOptions<TEdge>);
12
+ export declare class GraphQLConnectionType<TNode extends nodeType, TEdge extends Data, TViewer extends Viewer> extends GraphQLObjectType {
13
+ edgeType: GraphQLEdgeType<TNode, TEdge, TViewer>;
14
+ constructor(name: string, nodeType: TNode, options?: connectionOptions<TEdge, TViewer>);
15
15
  }
16
16
  export {};
@@ -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],
@@ -139,7 +139,7 @@ function sharedAssocTests() {
139
139
  const conn = new connection_type_1.GraphQLConnectionType("CustomEdge", eventType);
140
140
  const length = (m) => {
141
141
  let count = 0;
142
- for (let k in m) {
142
+ for (let _ in m) {
143
143
  count++;
144
144
  }
145
145
  return count;
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commonTests = void 0;
4
- const pg_1 = require("pg");
5
4
  const viewer_1 = require("../../core/viewer");
6
5
  const ent_1 = require("../../core/ent");
7
- const db_mock_1 = require("../../testutils/db_mock");
8
6
  const edge_connection_1 = require("./edge_connection");
9
7
  const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
10
- jest.mock("pg");
11
- db_mock_1.QueryRecorder.mockPool(pg_1.Pool);
12
8
  class TestConnection {
13
9
  constructor(getQuery, ents, filter) {
14
10
  this.getQuery = getQuery;
@@ -48,23 +44,9 @@ class TestConnection {
48
44
  }
49
45
  const commonTests = (opts) => {
50
46
  function getCursorFrom(contacts, idx) {
51
- // we depend on the fact that the same time is used for the edge and created_at
52
- // based on getContactBuilder
53
- // so regardless of if we're doing assoc or custom queries, we can get the time
54
- // from the created_at field
55
47
  return (0, ent_1.getCursor)({
56
48
  row: contacts[idx],
57
- col: "createdAt",
58
- conv: (t) => {
59
- //sqlite
60
- if (typeof t === "string") {
61
- return Date.parse(t);
62
- }
63
- return t.getTime();
64
- },
65
- // we want the right column to be encoded in the cursor as opposed e.g. time for
66
- // assoc queries, created_at for index/custom queries
67
- cursorKey: opts.sortCol,
49
+ col: "id",
68
50
  });
69
51
  }
70
52
  describe("no filters", () => {
@@ -1,2 +1,2 @@
1
1
  import { GraphQLScalarType } from "graphql";
2
- export declare const GraphQLTime: GraphQLScalarType;
2
+ export declare const GraphQLTime: GraphQLScalarType<Date, string>;
@@ -1,5 +1,6 @@
1
1
  export interface Options {
2
2
  filter?: (file: string, index: number, array: string[]) => boolean;
3
+ justCurrentDir?: boolean;
3
4
  ignore?: string | Readonly<string[]> | undefined;
4
5
  }
5
6
  export interface PathResult {
@@ -10,7 +11,11 @@ interface classResult {
10
11
  class: classInfo;
11
12
  file: file;
12
13
  }
13
- export declare function parseCustomImports(filePath: string, opts?: Options): PathResult;
14
+ interface ParseInput {
15
+ root: string;
16
+ opts?: Options;
17
+ }
18
+ export declare function parseCustomImports(filePath: string, inputs: ParseInput[]): PathResult;
14
19
  export interface importInfo {
15
20
  name: string;
16
21
  importPath: string;