@snowtop/ent 0.1.0-alpha13 → 0.1.0-alpha131

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 (173) hide show
  1. package/action/action.d.ts +33 -29
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +3 -3
  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 +32 -15
  10. package/action/orchestrator.js +249 -53
  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 +61 -37
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +85 -40
  20. package/core/clause.js +375 -64
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -1
  23. package/core/const.d.ts +3 -0
  24. package/core/const.js +6 -0
  25. package/core/context.d.ts +6 -4
  26. package/core/context.js +20 -2
  27. package/core/convert.d.ts +1 -1
  28. package/core/date.js +1 -5
  29. package/core/db.d.ts +11 -8
  30. package/core/db.js +20 -8
  31. package/core/ent.d.ts +86 -30
  32. package/core/ent.js +626 -197
  33. package/core/global_schema.d.ts +7 -0
  34. package/core/global_schema.js +51 -0
  35. package/core/loaders/assoc_count_loader.d.ts +3 -2
  36. package/core/loaders/assoc_count_loader.js +10 -2
  37. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  38. package/core/loaders/assoc_edge_loader.js +8 -11
  39. package/core/loaders/index.d.ts +1 -1
  40. package/core/loaders/index.js +1 -3
  41. package/core/loaders/index_loader.d.ts +3 -3
  42. package/core/loaders/loader.d.ts +2 -2
  43. package/core/loaders/loader.js +5 -5
  44. package/core/loaders/object_loader.d.ts +32 -11
  45. package/core/loaders/object_loader.js +225 -78
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +52 -11
  48. package/core/loaders/raw_count_loader.d.ts +2 -2
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +25 -24
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +7 -6
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +84 -0
  58. package/core/query/custom_query.d.ts +20 -5
  59. package/core/query/custom_query.js +87 -12
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +8 -4
  63. package/core/query/query.js +101 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +35 -45
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +470 -236
  68. package/core/viewer.d.ts +3 -3
  69. package/core/viewer.js +1 -1
  70. package/graphql/graphql.d.ts +51 -19
  71. package/graphql/graphql.js +160 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/edge_connection.d.ts +9 -9
  78. package/graphql/query/page_info.d.ts +1 -1
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +6 -1
  86. package/imports/index.js +19 -4
  87. package/index.d.ts +13 -5
  88. package/index.js +21 -7
  89. package/package.json +17 -17
  90. package/parse_schema/parse.d.ts +31 -9
  91. package/parse_schema/parse.js +155 -13
  92. package/schema/base_schema.d.ts +7 -3
  93. package/schema/base_schema.js +10 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +231 -71
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +5 -1
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +89 -19
  101. package/schema/schema.js +11 -13
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +128 -31
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +20 -5
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +398 -0
  112. package/testutils/builder.d.ts +41 -47
  113. package/testutils/builder.js +76 -49
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +182 -45
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -7
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +52 -23
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +16 -15
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +43 -0
  142. package/testutils/fake_data/test_helpers.d.ts +11 -4
  143. package/testutils/fake_data/test_helpers.js +28 -12
  144. package/testutils/fake_data/user_query.d.ts +13 -6
  145. package/testutils/fake_data/user_query.js +54 -22
  146. package/testutils/fake_log.d.ts +3 -3
  147. package/testutils/fake_log.js +1 -1
  148. package/testutils/parse_sql.d.ts +6 -0
  149. package/testutils/parse_sql.js +16 -2
  150. package/testutils/test_edge_global_schema.d.ts +15 -0
  151. package/testutils/test_edge_global_schema.js +62 -0
  152. package/testutils/write.d.ts +2 -2
  153. package/testutils/write.js +33 -7
  154. package/tsc/ast.d.ts +25 -2
  155. package/tsc/ast.js +141 -17
  156. package/tsc/compilerOptions.js +5 -1
  157. package/tsc/move_generated.d.ts +1 -0
  158. package/tsc/move_generated.js +164 -0
  159. package/tsc/transform.d.ts +22 -0
  160. package/tsc/transform.js +181 -0
  161. package/tsc/transform_action.d.ts +22 -0
  162. package/tsc/transform_action.js +183 -0
  163. package/tsc/transform_ent.d.ts +17 -0
  164. package/tsc/transform_ent.js +60 -0
  165. package/tsc/transform_schema.d.ts +27 -0
  166. package/{scripts → tsc}/transform_schema.js +146 -117
  167. package/graphql/enums.d.ts +0 -3
  168. package/graphql/enums.js +0 -25
  169. package/scripts/move_generated.js +0 -142
  170. package/scripts/transform_code.js +0 -113
  171. package/scripts/transform_schema.d.ts +0 -1
  172. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  173. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
@@ -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];
@@ -26,16 +30,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
30
  const glob_1 = __importDefault(require("glob"));
27
31
  const json5_1 = __importDefault(require("json5"));
28
32
  const minimist_1 = __importDefault(require("minimist"));
29
- const graphql_1 = require("../graphql/graphql");
30
- const readline = __importStar(require("readline"));
31
33
  const path = __importStar(require("path"));
32
34
  const fs = __importStar(require("fs"));
35
+ const graphql_1 = require("../graphql/graphql");
36
+ const readline = __importStar(require("readline"));
33
37
  const imports_1 = require("../imports");
34
38
  const process_1 = require("process");
39
+ const child_process_1 = require("child_process");
40
+ const const_1 = require("../core/const");
35
41
  // need to use the GQLCapture from the package so that when we call GQLCapture.enable()
36
42
  // we're affecting the local paths as opposed to a different instance
37
43
  // life is hard
38
- const MODULE_PATH = "@snowtop/ent/graphql";
44
+ const MODULE_PATH = const_1.GRAPHQL_PATH;
39
45
  async function readInputs() {
40
46
  return await new Promise((resolve) => {
41
47
  const rl = readline.createInterface({
@@ -72,7 +78,7 @@ function processCustomObjects(l, gqlCapture, input) {
72
78
  }
73
79
  }
74
80
  }
75
- function transformArgs(f) {
81
+ function transformArgs(f, gqlCapture) {
76
82
  return (f.args || []).map((v) => {
77
83
  const ret = {
78
84
  ...v,
@@ -80,7 +86,7 @@ function transformArgs(f) {
80
86
  // duplicated from getType in graphql.ts
81
87
  if ((0, graphql_1.isCustomType)(ret.type)) {
82
88
  ret.type = v.type.type;
83
- (0, graphql_1.addCustomType)(v.type);
89
+ (0, graphql_1.addCustomType)(v.type, gqlCapture);
84
90
  }
85
91
  // scalar types not supported for now
86
92
  ret.tsType = graphql_1.knownAllowedNames.get(v.type);
@@ -95,23 +101,33 @@ function transformResultType(f) {
95
101
  type: f.resultType,
96
102
  tsType: graphql_1.knownAllowedNames.get(f.resultType),
97
103
  list: f.list,
104
+ connection: f.connection,
98
105
  nullable: f.nullable,
99
106
  },
100
107
  ]
101
108
  : [];
102
109
  }
103
- function processTopLevel(l, l2) {
110
+ function processTopLevel(l, l2, gqlCapture) {
104
111
  for (const custom of l) {
105
112
  l2.push({
106
113
  nodeName: custom.class,
107
114
  functionName: custom.functionName || custom.name,
108
115
  gqlName: custom.graphQLName || custom.name,
116
+ edgeName: custom.edgeName,
109
117
  fieldType: custom.fieldType,
110
- args: transformArgs(custom),
118
+ args: transformArgs(custom, gqlCapture),
111
119
  results: transformResultType(custom),
120
+ description: custom.description,
121
+ extraImports: custom.extraImports,
122
+ functionContents: custom.functionContents,
112
123
  });
113
124
  }
114
125
  }
126
+ function processCustomTypes(m, gqlCapture) {
127
+ for (const k in m) {
128
+ (0, graphql_1.addCustomType)(m[k], gqlCapture);
129
+ }
130
+ }
115
131
  function processCustomFields(fields, gqlCapture, nodeName) {
116
132
  const m = gqlCapture.getCustomFields();
117
133
  let results = [];
@@ -121,12 +137,57 @@ function processCustomFields(fields, gqlCapture, nodeName) {
121
137
  gqlName: f.graphQLName || f.name,
122
138
  functionName: f.functionName || f.name,
123
139
  fieldType: f.fieldType,
124
- args: transformArgs(f),
140
+ args: transformArgs(f, gqlCapture),
125
141
  results: transformResultType(f),
142
+ description: f.description,
126
143
  });
127
144
  }
128
145
  m.set(nodeName, results);
129
146
  }
147
+ async function captureDynamic(filePath, gqlCapture) {
148
+ if (!filePath) {
149
+ return;
150
+ }
151
+ return await new Promise((resolve, reject) => {
152
+ // do we eventually need tsconfig-paths here or do we get it by default because child process?
153
+ const args = ["--swc", filePath];
154
+ if (process.env.DISABLE_SWC) {
155
+ args.shift();
156
+ }
157
+ const r = (0, child_process_1.spawn)("ts-node", args);
158
+ const datas = [];
159
+ r.stdout.on("data", (data) => {
160
+ datas.push(data.toString());
161
+ });
162
+ r.stderr.on("data", (data) => {
163
+ reject(new Error(data.toString()));
164
+ });
165
+ r.on("close", (code) => {
166
+ if (code !== 0) {
167
+ reject(new Error(`error code ${code} on dynamic path`));
168
+ return;
169
+ }
170
+ let json = json5_1.default.parse(datas.join(""));
171
+ for (const k in json) {
172
+ const v = json[k];
173
+ switch (k) {
174
+ case "queries":
175
+ processTopLevel(v, gqlCapture.getCustomQueries(), gqlCapture);
176
+ break;
177
+ case "mutations":
178
+ processTopLevel(v, gqlCapture.getCustomMutations(), gqlCapture);
179
+ break;
180
+ case "customTypes":
181
+ processCustomTypes(v, gqlCapture);
182
+ break;
183
+ default:
184
+ reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
185
+ }
186
+ }
187
+ resolve(undefined);
188
+ });
189
+ });
190
+ }
130
191
  async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
131
192
  if (jsonPath !== undefined) {
132
193
  let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
@@ -144,10 +205,13 @@ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
144
205
  processCustomObjects(json.objects, gqlCapture);
145
206
  }
146
207
  if (json.queries) {
147
- processTopLevel(json.queries, gqlCapture.getCustomQueries());
208
+ processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
148
209
  }
149
210
  if (json.mutations) {
150
- processTopLevel(json.mutations, gqlCapture.getCustomMutations());
211
+ processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
212
+ }
213
+ if (json.customTypes) {
214
+ processCustomTypes(json.customTypes, gqlCapture);
151
215
  }
152
216
  return;
153
217
  }
@@ -208,11 +272,27 @@ async function requireFiles(files) {
208
272
  throw new Error(err);
209
273
  });
210
274
  }
275
+ // filePath is path-to-src
211
276
  async function parseImports(filePath) {
212
- // only do graphql files...
213
- return (0, imports_1.parseCustomImports)(path.join(filePath, "graphql"), {
214
- ignore: ["**/generated/**", "**/tests/**"],
215
- });
277
+ return (0, imports_1.parseCustomImports)(filePath, [
278
+ {
279
+ // graphql files
280
+ root: path.join(filePath, "graphql"),
281
+ opts: {
282
+ ignore: ["**/generated/**", "**/tests/**"],
283
+ },
284
+ },
285
+ {
286
+ // can't just use top level ent files but have to check for all (non-generated) files
287
+ // in src/ent/* because custom edges (or other things) could have @gqlField etc
288
+ // and then have to look for these imports etc
289
+ root: path.join(filePath, "ent"),
290
+ opts: {
291
+ // not in action files since we can't customize payloads (yet?)
292
+ ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
293
+ },
294
+ },
295
+ ]);
216
296
  }
217
297
  function findGraphQLPath(filePath) {
218
298
  while (filePath !== "/") {
@@ -227,21 +307,11 @@ function findGraphQLPath(filePath) {
227
307
  }
228
308
  return undefined;
229
309
  }
310
+ // test as follows:
311
+ // there should be an easier way to do this...
312
+ // also, there should be a way to get the list of objects here that's not manual
313
+ //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/
230
314
  async function main() {
231
- // known custom types that are not required
232
- // if not in the schema, will be ignored
233
- // something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
234
- // these 2 need this because they're added by the schema
235
- // if this list grows too long, need to build this into golang types and passed here
236
- // TODO foreign non-scalars eventually
237
- (0, graphql_1.addCustomType)({
238
- importPath: "../graphql/scalars/time",
239
- type: "GraphQLTime",
240
- });
241
- (0, graphql_1.addCustomType)({
242
- importPath: "graphql-type-json",
243
- type: "GraphQLJSON",
244
- });
245
315
  const options = (0, minimist_1.default)(process.argv.slice(2));
246
316
  if (!options.path) {
247
317
  throw new Error("path required");
@@ -266,9 +336,28 @@ async function main() {
266
336
  gqlCapture = r.GQLCapture;
267
337
  gqlCapture.enable(true);
268
338
  }
269
- const [inputsRead, _, imports] = await Promise.all([
339
+ // known custom types that are not required
340
+ // if not in the schema, will be ignored
341
+ // something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
342
+ // these 2 need this because they're added by the schema
343
+ // if this list grows too long, need to build this into golang types and passed here
344
+ // TODO foreign non-scalars eventually
345
+ (0, graphql_1.addCustomType)({
346
+ importPath: MODULE_PATH,
347
+ // for go tests...
348
+ // TODO need a flag that only does this for go tests
349
+ // breaks when running locally sometimes...
350
+ secondaryImportPath: "../graphql/scalars/time",
351
+ type: "GraphQLTime",
352
+ }, gqlCapture);
353
+ (0, graphql_1.addCustomType)({
354
+ importPath: "graphql-type-json",
355
+ type: "GraphQLJSON",
356
+ }, gqlCapture);
357
+ const [inputsRead, _, __, imports] = await Promise.all([
270
358
  readInputs(),
271
359
  captureCustom(options.path, options.files, options.json_path, gqlCapture),
360
+ captureDynamic(options.dynamic_path, gqlCapture),
272
361
  parseImports(options.path),
273
362
  ]);
274
363
  const { nodes, nodesMap } = inputsRead;
@@ -286,6 +375,8 @@ async function main() {
286
375
  let queries = gqlCapture.getProcessedCustomQueries();
287
376
  let mutations = gqlCapture.getProcessedCustomMutations();
288
377
  let objects = fromMap(gqlCapture.getCustomObjects());
378
+ let interfaces = fromMap(gqlCapture.getCustomInterfaces());
379
+ let unions = fromMap(gqlCapture.getCustomUnions());
289
380
  let customTypes = fromMap(gqlCapture.getCustomTypes());
290
381
  let classes = {};
291
382
  let allFiles = {};
@@ -325,7 +416,7 @@ async function main() {
325
416
  };
326
417
  const buildClasses = (fields) => {
327
418
  fields.forEach((field) => {
328
- if (!nodesMap.has(field.nodeName)) {
419
+ if (field.nodeName && !nodesMap.has(field.nodeName)) {
329
420
  let info = imports.getInfoForClass(field.nodeName);
330
421
  classes[field.nodeName] = { ...info.class, path: info.file.path };
331
422
  buildFiles(info.file);
@@ -336,6 +427,10 @@ async function main() {
336
427
  };
337
428
  buildClasses(mutations);
338
429
  buildClasses(queries);
430
+ // call for every field in a node
431
+ for (const k in fields) {
432
+ buildClasses(fields[k]);
433
+ }
339
434
  console.log(JSON.stringify({
340
435
  args,
341
436
  inputs,
@@ -344,6 +439,8 @@ async function main() {
344
439
  mutations,
345
440
  classes,
346
441
  objects,
442
+ interfaces,
443
+ unions,
347
444
  files: allFiles,
348
445
  customTypes,
349
446
  }));
@@ -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,120 @@
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 modifiers = typescript_1.default.canHaveModifiers(node)
40
+ ? typescript_1.default.getModifiers(node)
41
+ : undefined;
42
+ const exported = modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
43
+ if (exported?.length) {
44
+ if (typescript_1.default.isEnumDeclaration(node) ||
45
+ typescript_1.default.isInterfaceDeclaration(node) ||
46
+ typescript_1.default.isTypeAliasDeclaration(node)) {
47
+ this.names.push(node.name.text);
48
+ }
49
+ if (typescript_1.default.isFunctionDeclaration(node) && node.name?.text) {
50
+ this.names.push(node.name.text);
51
+ }
52
+ }
53
+ return { node };
54
+ }
55
+ }
56
+ class TransformImports {
57
+ constructor() {
58
+ this.glob = "src/**/*.ts";
59
+ this.prettierGlob = "src/**/*.ts";
60
+ this.impsToMove = new Map();
61
+ this.cwd = "";
62
+ this.relative = false;
63
+ this.cwd = process.cwd();
64
+ const gt = new GatherExportsInGeneratedTypes();
65
+ (0, transform_1.transform)(gt);
66
+ gt.names.forEach((v) => this.impsToMove.set(v, true));
67
+ this.relative = (0, ast_1.getCustomInfo)().relativeImports ?? this.relative;
68
+ }
69
+ getSrcPath(file, text) {
70
+ if (text.startsWith("src")) {
71
+ return text;
72
+ }
73
+ const dir = path_1.default.dirname(path_1.default.join(this.cwd, file));
74
+ const fullPath = path_1.default.join(dir, text);
75
+ return path_1.default.relative(this.cwd, fullPath);
76
+ }
77
+ traverseChild(sourceFile, contents, file, node) {
78
+ if (!(0, typescript_1.isImportDeclaration)(node)) {
79
+ return { node };
80
+ }
81
+ const impInfo = (0, ast_1.getImportInfo)(node, sourceFile);
82
+ if (!impInfo) {
83
+ return { node };
84
+ }
85
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
86
+ const pathToWrite = (0, ast_1.transformRelative)(file, "src/ent/generated/types", this.relative);
87
+ const current = (0, ast_1.transformRelative)(file, text, this.relative);
88
+ const srcPath = this.getSrcPath(file, text);
89
+ // nothing to do here
90
+ if (!srcPath.startsWith("src/ent") || pathToWrite === current) {
91
+ return { node };
92
+ }
93
+ // let's see if we can simplify
94
+ let seenImports = [];
95
+ for (let imp of impInfo.imports) {
96
+ imp = imp.trim();
97
+ if (this.impsToMove.has(imp)) {
98
+ seenImports.push(imp);
99
+ }
100
+ }
101
+ if (!seenImports.length) {
102
+ return { node };
103
+ }
104
+ let imports = new Map([[pathToWrite, seenImports]]);
105
+ return {
106
+ rawString: (0, ast_1.transformImport)(contents, node, sourceFile, {
107
+ removeImports: seenImports,
108
+ transformPath: text,
109
+ }),
110
+ traversed: true,
111
+ imports,
112
+ allowSeenImportsAdded: true,
113
+ };
114
+ }
115
+ }
116
+ // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/move_types.ts
117
+ function main() {
118
+ (0, transform_1.transform)(new TransformImports());
119
+ }
120
+ main();
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -26,20 +30,28 @@ const glob_1 = __importDefault(require("glob"));
26
30
  const path = __importStar(require("path"));
27
31
  const pascal_case_1 = require("pascal-case");
28
32
  const minimist_1 = __importDefault(require("minimist"));
29
- const process_1 = require("process");
30
33
  const parse_1 = require("../parse_schema/parse");
34
+ const ast_1 = require("../tsc/ast");
31
35
  function main() {
32
36
  const options = (0, minimist_1.default)(process.argv.slice(2));
33
37
  if (!options.path) {
34
38
  throw new Error("path required");
35
39
  }
40
+ const customInfo = (0, ast_1.getCustomInfo)();
41
+ const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
42
+ let globalSchema;
36
43
  const r = /(\w+).ts/;
44
+ // do we still even need this...
37
45
  const paths = glob_1.default.sync(path.join(options.path, "*.ts"), {
38
46
  ignore: [`\d+_read_schema.ts`],
39
47
  });
40
48
  let potentialSchemas = {};
41
49
  for (const p of paths) {
42
50
  const basename = path.basename(p);
51
+ if (basename === globalSchemaPath) {
52
+ globalSchema = require(p).default;
53
+ continue;
54
+ }
43
55
  const match = r.exec(basename);
44
56
  if (!match) {
45
57
  throw new Error(`non-typescript file ${p} returned by glob`);
@@ -61,13 +73,16 @@ function main() {
61
73
  potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
62
74
  }
63
75
  // console.log(potentialSchemas);
64
- const result = (0, parse_1.parseSchema)(potentialSchemas);
65
- console.log(JSON.stringify(result));
76
+ // NB: do not change this to async/await
77
+ // doing so runs it buffer limit on linux (65536 bytes) and we lose data reading in go
78
+ (0, parse_1.parseSchema)(potentialSchemas, globalSchema).then((result) => {
79
+ console.log(JSON.stringify(result));
80
+ });
66
81
  }
67
82
  try {
68
83
  main();
69
84
  }
70
85
  catch (err) {
71
86
  console.error(err);
72
- (0, process_1.exit)(1);
87
+ process.exit(1);
73
88
  }
@@ -0,0 +1,69 @@
1
+ import { Ent, ID, Viewer, Data } from "../../core/base";
2
+ import { DataOperation } from "../../core/ent";
3
+ import { Action, Builder, Executor, WriteOperation, Trigger, Observer, TriggerReturn } from "../../action/action";
4
+ import { EdgeInputData } from "../../action/orchestrator";
5
+ import { User, Group, Message, Contact, SimpleBuilder, BuilderSchema, SimpleAction, BaseEnt } from "../../testutils/builder";
6
+ import { MockLogs } from "../../testutils/mock_log";
7
+ import { Table } from "../db/temp_db";
8
+ export declare function setupTest(): void;
9
+ export declare function getML(): MockLogs;
10
+ export declare function getOperations(): DataOperation<Ent<Viewer<Ent<any> | null, ID | null>>>[];
11
+ export declare const UserSchema: BuilderSchema<User>;
12
+ export declare class UserWithBalance extends User {
13
+ }
14
+ export declare const UserBalanceSchema: BuilderSchema<UserWithBalance>;
15
+ export declare class UserWithBalanceWithCheck extends UserWithBalance {
16
+ }
17
+ export declare const UserBalanceWithCheckSchema: BuilderSchema<UserWithBalanceWithCheck>;
18
+ export declare class Account extends BaseEnt {
19
+ accountID: string;
20
+ nodeType: string;
21
+ }
22
+ export declare const AccountSchema: BuilderSchema<Account>;
23
+ export declare const ContactSchema: BuilderSchema<Contact>;
24
+ export declare const GroupSchema: BuilderSchema<Group>;
25
+ export declare class GroupMembership extends BaseEnt {
26
+ nodeType: string;
27
+ }
28
+ export declare const GroupMembershipSchema: BuilderSchema<GroupMembership>;
29
+ export declare class Changelog extends BaseEnt {
30
+ nodeType: string;
31
+ }
32
+ export declare const ChangelogSchema: BuilderSchema<Changelog>;
33
+ export declare const MessageSchema: BuilderSchema<Message>;
34
+ export declare function executeAction<T extends Ent, E = any>(action: Action<T, Builder<T>>, name?: E): Promise<Executor>;
35
+ export declare function createGroup(): Promise<Group>;
36
+ export declare function createUser(): Promise<User>;
37
+ export declare class MessageAction extends SimpleAction<Message> {
38
+ constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: Message | null);
39
+ getTriggers(): Trigger<Message, SimpleBuilder<Message, Message | null>>[];
40
+ getObservers(): Observer<Message, SimpleBuilder<Message>>[];
41
+ }
42
+ export declare class UserAction extends SimpleAction<User> {
43
+ contactAction: SimpleAction<Contact> | undefined;
44
+ constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: User | null);
45
+ getTriggers(): Trigger<User, SimpleBuilder<User>>[];
46
+ getObservers(): Observer<User, SimpleBuilder<User>>[];
47
+ }
48
+ type getMembershipFunction = (viewer: Viewer, edge: EdgeInputData) => SimpleAction<Ent>;
49
+ export declare class GroupMembershipTrigger implements Trigger<Group, SimpleBuilder<Group>> {
50
+ private getter;
51
+ constructor(getter: getMembershipFunction);
52
+ changeset(builder: SimpleBuilder<Group>, input: Data): TriggerReturn;
53
+ }
54
+ export declare class EditGroupAction extends SimpleAction<Group> {
55
+ viewer: Viewer;
56
+ private getter;
57
+ constructor(viewer: Viewer, schema: BuilderSchema<Group>, fields: Map<string, any>, existingEnt: Group, getter: getMembershipFunction);
58
+ getTriggers: () => GroupMembershipTrigger[];
59
+ }
60
+ export declare function verifyGroupMembers(group: Group, members: User[]): Promise<ID[]>;
61
+ export declare function loadMemberships(viewer: Viewer, membershipids: ID[]): Promise<GroupMembership[]>;
62
+ export declare function loadChangelogs(viewer: Viewer, clids: ID[]): Promise<Changelog[]>;
63
+ export declare function verifyChangelogFromMeberships(user: User, memberships: GroupMembership[]): Promise<void>;
64
+ export declare class GroupMemberOf extends BaseEnt {
65
+ nodeType: string;
66
+ }
67
+ export declare const GroupMemberOfSchema: BuilderSchema<GroupMemberOf>;
68
+ export declare const getTables: () => Table[];
69
+ export {};