@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
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnionListType = exports.UnionType = exports.UnionField = void 0;
4
+ const schema_1 = require("./schema");
5
+ const field_1 = require("./field");
6
+ // used to know which key in the union is valid.
7
+ // maybe there's a better way of doing this eventually
8
+ const KEY = "___valid___key___";
9
+ class UnionField extends field_1.BaseField {
10
+ constructor(options) {
11
+ super();
12
+ this.options = options;
13
+ this.type = {
14
+ dbType: schema_1.DBType.JSONB,
15
+ };
16
+ this.m = new Map();
17
+ this.type.unionFields = options.fields;
18
+ this.type.type = options.tsType;
19
+ this.type.graphQLType = options.graphQLType || options.tsType;
20
+ // TODO should throw if not nested?
21
+ if (options.jsonNotJSONB) {
22
+ this.type.dbType = schema_1.DBType.JSON;
23
+ }
24
+ }
25
+ format(obj) {
26
+ if (!(obj instanceof Object)) {
27
+ throw new Error("valid was not called");
28
+ }
29
+ const k = obj[KEY];
30
+ if (k === undefined) {
31
+ throw new Error(`need to call valid first`);
32
+ }
33
+ // now delete it since we don't need it anymore
34
+ delete obj[KEY];
35
+ const field = this.options.fields[k];
36
+ // always nested for now so pass through
37
+ return field.format(obj, true);
38
+ }
39
+ async validField(k, f, obj) {
40
+ const valid = await f.valid(obj);
41
+ return {
42
+ valid,
43
+ key: k,
44
+ };
45
+ }
46
+ async valid(obj) {
47
+ if (!(obj instanceof Object)) {
48
+ return false;
49
+ }
50
+ let promises = [];
51
+ for (const k in this.options.fields) {
52
+ const field = this.options.fields[k];
53
+ promises.push(this.validField(k, field, obj));
54
+ }
55
+ let lastKey;
56
+ let validCt = 0;
57
+ const ret = await Promise.all(promises);
58
+ for (const v of ret) {
59
+ if (v.valid) {
60
+ validCt++;
61
+ lastKey = v.key;
62
+ }
63
+ }
64
+ if (lastKey !== undefined) {
65
+ obj[KEY] = lastKey;
66
+ }
67
+ return validCt == 1;
68
+ }
69
+ }
70
+ exports.UnionField = UnionField;
71
+ function UnionType(options) {
72
+ let result = new UnionField(options);
73
+ return Object.assign(result, options);
74
+ }
75
+ exports.UnionType = UnionType;
76
+ function UnionListType(options) {
77
+ return new field_1.ListField(UnionType(options), options);
78
+ }
79
+ exports.UnionListType = UnionListType;
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -193,7 +197,7 @@ class Compiler {
193
197
  }
194
198
  relPath = path.relative(
195
199
  // just because of how imports work. it's relative from directory not current path
196
- path.dirname(fullPath), path.join(text.substr(0, idx).replace(r, str.substr(0, strIdx)), text.substr(idx)));
200
+ path.dirname(fullPath), path.join(text.substring(0, idx).replace(r, str.substring(0, strIdx)), text.substring(idx)));
197
201
  // if file ends with "..", we've reached a case where we're trying to
198
202
  // import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
199
203
  // and we're confused about it so we need to detect that case and handle it
@@ -204,7 +208,7 @@ class Compiler {
204
208
  let text2 = text + ".ts";
205
209
  relPath = path.relative(
206
210
  // just because of how imports work. it's relative from directory not current path
207
- path.dirname(fullPath), path.join(text2.substr(0, idx).replace(r, str.substr(0, strIdx)), text2.substr(idx)));
211
+ path.dirname(fullPath), path.join(text2.substring(0, idx).replace(r, str.substring(0, strIdx)), text2.substring(idx)));
208
212
  }
209
213
  }
210
214
  if (!relPath.startsWith("..")) {
@@ -213,7 +217,7 @@ class Compiler {
213
217
  // tsc removes this by default so we need to also do it
214
218
  let tsIdx = relPath.indexOf(".ts");
215
219
  if (tsIdx !== -1) {
216
- relPath = relPath.substr(0, tsIdx);
220
+ relPath = relPath.substring(0, tsIdx);
217
221
  }
218
222
  return relPath;
219
223
  }
@@ -225,7 +229,7 @@ class Compiler {
225
229
  let relPath = checkPath(paths, text);
226
230
  if (relPath) {
227
231
  // update the node...
228
- return typescript_1.default.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.createLiteral(relPath));
232
+ return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
229
233
  }
230
234
  }
231
235
  if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
@@ -235,7 +239,7 @@ class Compiler {
235
239
  let relPath = checkPath(paths, text);
236
240
  if (relPath) {
237
241
  // update the node...
238
- return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.createLiteral(relPath), exportNode.isTypeOnly);
242
+ return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
239
243
  }
240
244
  }
241
245
  }
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -24,13 +28,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
28
  };
25
29
  Object.defineProperty(exports, "__esModule", { value: true });
26
30
  const glob_1 = __importDefault(require("glob"));
31
+ const json5_1 = __importDefault(require("json5"));
27
32
  const minimist_1 = __importDefault(require("minimist"));
28
- const graphql_1 = require("../graphql/graphql");
29
- const readline = __importStar(require("readline"));
30
33
  const path = __importStar(require("path"));
31
34
  const fs = __importStar(require("fs"));
35
+ const graphql_1 = require("../graphql/graphql");
36
+ const readline = __importStar(require("readline"));
32
37
  const imports_1 = require("../imports");
33
38
  const process_1 = require("process");
39
+ const child_process_1 = require("child_process");
34
40
  // need to use the GQLCapture from the package so that when we call GQLCapture.enable()
35
41
  // we're affecting the local paths as opposed to a different instance
36
42
  // life is hard
@@ -53,7 +59,150 @@ async function readInputs() {
53
59
  });
54
60
  });
55
61
  }
56
- async function captureCustom(filePath, filesCsv) {
62
+ function processCustomObjects(l, gqlCapture, input) {
63
+ let m;
64
+ if (input) {
65
+ m = gqlCapture.getCustomInputObjects();
66
+ }
67
+ else {
68
+ m = gqlCapture.getCustomObjects();
69
+ }
70
+ for (const input of l) {
71
+ m.set(input.name, {
72
+ nodeName: input.graphQLName || input.name,
73
+ className: input.name,
74
+ });
75
+ if (input.fields) {
76
+ processCustomFields(input.fields, gqlCapture, input.name);
77
+ }
78
+ }
79
+ }
80
+ function transformArgs(f, gqlCapture) {
81
+ return (f.args || []).map((v) => {
82
+ const ret = {
83
+ ...v,
84
+ };
85
+ // duplicated from getType in graphql.ts
86
+ if ((0, graphql_1.isCustomType)(ret.type)) {
87
+ ret.type = v.type.type;
88
+ (0, graphql_1.addCustomType)(v.type, gqlCapture);
89
+ }
90
+ // scalar types not supported for now
91
+ ret.tsType = graphql_1.knownAllowedNames.get(v.type);
92
+ return ret;
93
+ });
94
+ }
95
+ function transformResultType(f) {
96
+ return f.resultType
97
+ ? [
98
+ {
99
+ name: "",
100
+ type: f.resultType,
101
+ tsType: graphql_1.knownAllowedNames.get(f.resultType),
102
+ list: f.list,
103
+ connection: f.connection,
104
+ nullable: f.nullable,
105
+ },
106
+ ]
107
+ : [];
108
+ }
109
+ function processTopLevel(l, l2, gqlCapture) {
110
+ for (const custom of l) {
111
+ l2.push({
112
+ nodeName: custom.class,
113
+ functionName: custom.functionName || custom.name,
114
+ gqlName: custom.graphQLName || custom.name,
115
+ fieldType: custom.fieldType,
116
+ args: transformArgs(custom, gqlCapture),
117
+ results: transformResultType(custom),
118
+ description: custom.description,
119
+ extraImports: custom.extraImports,
120
+ functionContents: custom.functionContents,
121
+ });
122
+ }
123
+ }
124
+ function processCustomFields(fields, gqlCapture, nodeName) {
125
+ const m = gqlCapture.getCustomFields();
126
+ let results = [];
127
+ for (const f of fields) {
128
+ results.push({
129
+ nodeName: nodeName,
130
+ gqlName: f.graphQLName || f.name,
131
+ functionName: f.functionName || f.name,
132
+ fieldType: f.fieldType,
133
+ args: transformArgs(f, gqlCapture),
134
+ results: transformResultType(f),
135
+ description: f.description,
136
+ });
137
+ }
138
+ m.set(nodeName, results);
139
+ }
140
+ async function captureDynamic(filePath, gqlCapture) {
141
+ if (!filePath) {
142
+ return;
143
+ }
144
+ return await new Promise((resolve, reject) => {
145
+ // do we eventually need tsconfig-paths here or do we get it by default because child process?
146
+ const r = (0, child_process_1.spawn)("ts-node", [filePath]);
147
+ const datas = [];
148
+ r.stdout.on("data", (data) => {
149
+ datas.push(data.toString());
150
+ });
151
+ r.stderr.on("data", (data) => {
152
+ reject(new Error(data.toString()));
153
+ });
154
+ r.on("close", (code) => {
155
+ if (code !== 0) {
156
+ reject(new Error(`error code ${code} on dynamic path`));
157
+ return;
158
+ }
159
+ let json = json5_1.default.parse(datas.join(""));
160
+ for (const k in json) {
161
+ const v = json[k];
162
+ switch (k) {
163
+ case "queries":
164
+ processTopLevel(v, gqlCapture.getCustomQueries(), gqlCapture);
165
+ break;
166
+ case "mutations":
167
+ processTopLevel(v, gqlCapture.getCustomMutations(), gqlCapture);
168
+ break;
169
+ default:
170
+ reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
171
+ }
172
+ }
173
+ resolve(undefined);
174
+ });
175
+ });
176
+ }
177
+ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
178
+ if (jsonPath !== undefined) {
179
+ let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
180
+ encoding: "utf8",
181
+ }));
182
+ if (json.fields) {
183
+ for (const k in json.fields) {
184
+ processCustomFields(json.fields[k], gqlCapture, k);
185
+ }
186
+ }
187
+ if (json.inputs) {
188
+ processCustomObjects(json.inputs, gqlCapture, true);
189
+ }
190
+ if (json.objects) {
191
+ processCustomObjects(json.objects, gqlCapture);
192
+ }
193
+ if (json.queries) {
194
+ processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
195
+ }
196
+ if (json.mutations) {
197
+ processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
198
+ }
199
+ if (json.customTypes) {
200
+ for (const k in json.customTypes) {
201
+ (0, graphql_1.addCustomType)(json.customTypes[k], gqlCapture);
202
+ }
203
+ }
204
+ return;
205
+ }
57
206
  if (filesCsv !== undefined) {
58
207
  let files = filesCsv.split(",");
59
208
  for (let i = 0; i < files.length; i++) {
@@ -111,11 +260,27 @@ async function requireFiles(files) {
111
260
  throw new Error(err);
112
261
  });
113
262
  }
263
+ // filePath is path-to-src
114
264
  async function parseImports(filePath) {
115
- // only do graphql files...
116
- return (0, imports_1.parseCustomImports)(path.join(filePath, "graphql"), {
117
- ignore: ["**/generated/**", "**/tests/**"],
118
- });
265
+ return (0, imports_1.parseCustomImports)(filePath, [
266
+ {
267
+ // graphql files
268
+ root: path.join(filePath, "graphql"),
269
+ opts: {
270
+ ignore: ["**/generated/**", "**/tests/**"],
271
+ },
272
+ },
273
+ {
274
+ // can't just use top level ent files but have to check for all (non-generated) files
275
+ // in src/ent/* because custom edges (or other things) could have @gqlField etc
276
+ // and then have to look for these imports etc
277
+ root: path.join(filePath, "ent"),
278
+ opts: {
279
+ // not in action files since we can't customize payloads (yet?)
280
+ ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
281
+ },
282
+ },
283
+ ]);
119
284
  }
120
285
  function findGraphQLPath(filePath) {
121
286
  while (filePath !== "/") {
@@ -130,7 +295,35 @@ function findGraphQLPath(filePath) {
130
295
  }
131
296
  return undefined;
132
297
  }
298
+ // test as follows:
299
+ // there should be an easier way to do this...
300
+ // also, there should be a way to get the list of objects here that's not manual
301
+ //echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
133
302
  async function main() {
303
+ const options = (0, minimist_1.default)(process.argv.slice(2));
304
+ if (!options.path) {
305
+ throw new Error("path required");
306
+ }
307
+ const gqlPath = process.env.GRAPHQL_PATH || findGraphQLPath(options.path);
308
+ if (!gqlPath) {
309
+ throw new Error("could not find graphql path");
310
+ }
311
+ // use different variable so that we use the correct GQLCapture as needed
312
+ // for local dev, get the one from the file system. otherwise, get the one
313
+ // from node_modules
314
+ let gqlCapture;
315
+ if (process.env.LOCAL_SCRIPT_PATH) {
316
+ const r = require("../graphql/graphql");
317
+ gqlCapture = r.GQLCapture;
318
+ }
319
+ else {
320
+ const r = require(gqlPath);
321
+ if (!r.GQLCapture) {
322
+ throw new Error("could not find GQLCapture in module");
323
+ }
324
+ gqlCapture = r.GQLCapture;
325
+ gqlCapture.enable(true);
326
+ }
134
327
  // known custom types that are not required
135
328
  // if not in the schema, will be ignored
136
329
  // something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
@@ -138,30 +331,21 @@ async function main() {
138
331
  // if this list grows too long, need to build this into golang types and passed here
139
332
  // TODO foreign non-scalars eventually
140
333
  (0, graphql_1.addCustomType)({
141
- importPath: "../graphql/scalars/time",
334
+ importPath: MODULE_PATH,
335
+ // for go tests...
336
+ // TODO need a flag that only does this for go tests
337
+ // breaks when running locally sometimes...
338
+ secondaryImportPath: "../graphql/scalars/time",
142
339
  type: "GraphQLTime",
143
- });
340
+ }, gqlCapture);
144
341
  (0, graphql_1.addCustomType)({
145
342
  importPath: "graphql-type-json",
146
343
  type: "GraphQLJSON",
147
- });
148
- const options = (0, minimist_1.default)(process.argv.slice(2));
149
- if (!options.path) {
150
- throw new Error("path required");
151
- }
152
- const gqlPath = process.env.GRAPHQL_PATH || findGraphQLPath(options.path);
153
- if (!gqlPath) {
154
- throw new Error("could not find graphql path");
155
- }
156
- const r = require(gqlPath);
157
- if (!r.GQLCapture) {
158
- throw new Error("could not find GQLCapture in module");
159
- }
160
- const GQLCapture = r.GQLCapture;
161
- GQLCapture.enable(true);
162
- const [inputsRead, _, imports] = await Promise.all([
344
+ }, gqlCapture);
345
+ const [inputsRead, _, __, imports] = await Promise.all([
163
346
  readInputs(),
164
- captureCustom(options.path, options.files),
347
+ captureCustom(options.path, options.files, options.json_path, gqlCapture),
348
+ captureDynamic(options.dynamic_path, gqlCapture),
165
349
  parseImports(options.path),
166
350
  ]);
167
351
  const { nodes, nodesMap } = inputsRead;
@@ -172,14 +356,14 @@ async function main() {
172
356
  }
173
357
  return result;
174
358
  }
175
- GQLCapture.resolve(nodes);
176
- let args = fromMap(GQLCapture.getCustomArgs());
177
- let inputs = fromMap(GQLCapture.getCustomInputObjects());
178
- let fields = GQLCapture.getProcessedCustomFields();
179
- let queries = GQLCapture.getProcessedCustomQueries();
180
- let mutations = GQLCapture.getProcessedCustomMutations();
181
- let objects = fromMap(GQLCapture.getCustomObjects());
182
- let customTypes = fromMap(GQLCapture.getCustomTypes());
359
+ gqlCapture.resolve(nodes);
360
+ let args = fromMap(gqlCapture.getCustomArgs());
361
+ let inputs = fromMap(gqlCapture.getCustomInputObjects());
362
+ let fields = gqlCapture.getProcessedCustomFields();
363
+ let queries = gqlCapture.getProcessedCustomQueries();
364
+ let mutations = gqlCapture.getProcessedCustomMutations();
365
+ let objects = fromMap(gqlCapture.getCustomObjects());
366
+ let customTypes = fromMap(gqlCapture.getCustomTypes());
183
367
  let classes = {};
184
368
  let allFiles = {};
185
369
  const buildClasses2 = (args) => {
@@ -218,7 +402,7 @@ async function main() {
218
402
  };
219
403
  const buildClasses = (fields) => {
220
404
  fields.forEach((field) => {
221
- if (!nodesMap.has(field.nodeName)) {
405
+ if (field.nodeName && !nodesMap.has(field.nodeName)) {
222
406
  let info = imports.getInfoForClass(field.nodeName);
223
407
  classes[field.nodeName] = { ...info.class, path: info.file.path };
224
408
  buildFiles(info.file);
@@ -229,6 +413,10 @@ async function main() {
229
413
  };
230
414
  buildClasses(mutations);
231
415
  buildClasses(queries);
416
+ // call for every field in a node
417
+ for (const k in fields) {
418
+ buildClasses(fields[k]);
419
+ }
232
420
  console.log(JSON.stringify({
233
421
  args,
234
422
  inputs,
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const minimist_1 = __importDefault(require("minimist"));
7
+ const transform_1 = require("../tsc/transform");
8
+ const transform_schema_1 = require("../tsc/transform_schema");
9
+ const transform_ent_1 = require("../tsc/transform_ent");
10
+ const move_generated_1 = require("../tsc/move_generated");
11
+ const transform_action_1 = require("../tsc/transform_action");
12
+ const ast_1 = require("../tsc/ast");
13
+ // todo-sqlite
14
+ // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
15
+ function main() {
16
+ const customInfo = (0, ast_1.getCustomInfo)();
17
+ const options = (0, minimist_1.default)(process.argv.slice(2));
18
+ // install 0.1.x dependencies
19
+ // maybe provide options to make this easier if someone wants to do this in steps to see what's happening
20
+ if (options.move_generated) {
21
+ (0, move_generated_1.moveGenerated)(customInfo.relativeImports);
22
+ }
23
+ // codegen write-all --disable-custom-graphql
24
+ if (options.transform_schema) {
25
+ (0, transform_1.transform)(new transform_schema_1.TransformSchema(customInfo.relativeImports, options.old_base_class, options.new_schema_class, options.transform_path));
26
+ }
27
+ // codegen write-all --disable-custom-graphql
28
+ if (options.transform_ent) {
29
+ (0, transform_1.transform)(new transform_ent_1.TransformEnt());
30
+ }
31
+ if (options.transform_action) {
32
+ (0, transform_1.transform)(new transform_action_1.TransformAction(customInfo));
33
+ }
34
+ // codegen write-all
35
+ }
36
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const transform_1 = require("../tsc/transform");
30
+ const ast_1 = require("../tsc/ast");
31
+ const typescript_1 = __importStar(require("typescript"));
32
+ const path_1 = __importDefault(require("path"));
33
+ class GatherExportsInGeneratedTypes {
34
+ constructor() {
35
+ this.glob = "src/ent/generated/types.ts";
36
+ this.names = [];
37
+ }
38
+ traverseChild(sourceFile, contents, file, node) {
39
+ const exported = node.modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
40
+ if (exported?.length) {
41
+ if (typescript_1.default.isEnumDeclaration(node) ||
42
+ typescript_1.default.isInterfaceDeclaration(node) ||
43
+ typescript_1.default.isTypeAliasDeclaration(node)) {
44
+ this.names.push(node.name.text);
45
+ }
46
+ if (typescript_1.default.isFunctionDeclaration(node) && node.name?.text) {
47
+ this.names.push(node.name.text);
48
+ }
49
+ }
50
+ return { node };
51
+ }
52
+ }
53
+ class TransformImports {
54
+ constructor() {
55
+ this.glob = "src/**/*.ts";
56
+ this.prettierGlob = "src/**/*.ts";
57
+ this.impsToMove = new Map();
58
+ this.cwd = "";
59
+ this.relative = false;
60
+ this.cwd = process.cwd();
61
+ const gt = new GatherExportsInGeneratedTypes();
62
+ (0, transform_1.transform)(gt);
63
+ gt.names.forEach((v) => this.impsToMove.set(v, true));
64
+ this.relative = (0, ast_1.getCustomInfo)().relativeImports ?? this.relative;
65
+ }
66
+ getSrcPath(file, text) {
67
+ if (text.startsWith("src")) {
68
+ return text;
69
+ }
70
+ const dir = path_1.default.dirname(path_1.default.join(this.cwd, file));
71
+ const fullPath = path_1.default.join(dir, text);
72
+ return path_1.default.relative(this.cwd, fullPath);
73
+ }
74
+ traverseChild(sourceFile, contents, file, node) {
75
+ if (!(0, typescript_1.isImportDeclaration)(node)) {
76
+ return { node };
77
+ }
78
+ const impInfo = (0, ast_1.getImportInfo)(node, sourceFile);
79
+ if (!impInfo) {
80
+ return { node };
81
+ }
82
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
83
+ const pathToWrite = (0, ast_1.transformRelative)(file, "src/ent/generated/types", this.relative);
84
+ const current = (0, ast_1.transformRelative)(file, text, this.relative);
85
+ const srcPath = this.getSrcPath(file, text);
86
+ // nothing to do here
87
+ if (!srcPath.startsWith("src/ent") || pathToWrite === current) {
88
+ return { node };
89
+ }
90
+ // let's see if we can simplify
91
+ let seenImports = [];
92
+ for (let imp of impInfo.imports) {
93
+ imp = imp.trim();
94
+ if (this.impsToMove.has(imp)) {
95
+ seenImports.push(imp);
96
+ }
97
+ }
98
+ if (!seenImports.length) {
99
+ return { node };
100
+ }
101
+ let imports = new Map([[pathToWrite, seenImports]]);
102
+ return {
103
+ rawString: (0, ast_1.transformImport)(contents, node, sourceFile, {
104
+ removeImports: seenImports,
105
+ transformPath: text,
106
+ }),
107
+ traversed: true,
108
+ imports,
109
+ allowSeenImportsAdded: true,
110
+ };
111
+ }
112
+ }
113
+ // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/move_types.ts
114
+ function main() {
115
+ (0, transform_1.transform)(new TransformImports());
116
+ }
117
+ main();