@snowtop/ent 0.1.0-alpha3 → 0.1.0-alpha34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/action/action.d.ts +28 -24
  2. package/action/executor.d.ts +4 -4
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +21 -20
  5. package/action/experimental_action.js +11 -5
  6. package/action/orchestrator.d.ts +31 -16
  7. package/action/orchestrator.js +164 -43
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +25 -21
  10. package/core/base.js +16 -0
  11. package/core/clause.d.ts +24 -3
  12. package/core/clause.js +246 -5
  13. package/core/config.d.ts +23 -0
  14. package/core/config.js +17 -0
  15. package/core/context.d.ts +2 -2
  16. package/core/convert.d.ts +1 -1
  17. package/core/db.d.ts +3 -3
  18. package/core/db.js +2 -0
  19. package/core/ent.d.ts +19 -21
  20. package/core/ent.js +76 -25
  21. package/core/loaders/assoc_count_loader.d.ts +2 -2
  22. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  23. package/core/loaders/assoc_edge_loader.js +5 -4
  24. package/core/loaders/index_loader.js +1 -0
  25. package/core/loaders/object_loader.d.ts +10 -5
  26. package/core/loaders/object_loader.js +59 -4
  27. package/core/loaders/query_loader.d.ts +2 -2
  28. package/core/loaders/raw_count_loader.d.ts +2 -2
  29. package/core/privacy.d.ts +25 -25
  30. package/core/privacy.js +3 -0
  31. package/core/query/assoc_query.d.ts +6 -6
  32. package/core/query/custom_query.d.ts +5 -5
  33. package/core/query/query.d.ts +1 -1
  34. package/core/viewer.d.ts +4 -3
  35. package/core/viewer.js +4 -0
  36. package/graphql/builtins/connection.js +3 -3
  37. package/graphql/builtins/edge.js +2 -2
  38. package/graphql/builtins/node.js +1 -1
  39. package/graphql/graphql.d.ts +3 -2
  40. package/graphql/graphql.js +24 -23
  41. package/graphql/index.d.ts +1 -0
  42. package/graphql/index.js +3 -1
  43. package/graphql/mutations/union.d.ts +2 -0
  44. package/graphql/mutations/union.js +35 -0
  45. package/graphql/node_resolver.d.ts +0 -1
  46. package/graphql/query/connection_type.js +6 -6
  47. package/graphql/query/edge_connection.d.ts +9 -9
  48. package/graphql/query/page_info.d.ts +1 -1
  49. package/graphql/query/page_info.js +4 -4
  50. package/graphql/query/shared_assoc_test.js +2 -2
  51. package/graphql/scalars/time.d.ts +1 -1
  52. package/index.d.ts +16 -1
  53. package/index.js +18 -5
  54. package/package.json +3 -3
  55. package/parse_schema/parse.d.ts +18 -5
  56. package/parse_schema/parse.js +55 -6
  57. package/schema/base_schema.d.ts +36 -1
  58. package/schema/base_schema.js +51 -2
  59. package/schema/field.d.ts +1 -1
  60. package/schema/field.js +1 -1
  61. package/schema/index.d.ts +2 -2
  62. package/schema/index.js +8 -1
  63. package/schema/schema.d.ts +61 -1
  64. package/schema/schema.js +126 -5
  65. package/schema/union_field.d.ts +2 -1
  66. package/schema/union_field.js +32 -14
  67. package/scripts/custom_graphql.js +122 -15
  68. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  69. package/scripts/migrate_v0.1.js +36 -0
  70. package/scripts/read_schema.js +15 -1
  71. package/testutils/builder.d.ts +31 -21
  72. package/testutils/builder.js +98 -13
  73. package/testutils/context/test_context.d.ts +2 -2
  74. package/testutils/context/test_context.js +7 -1
  75. package/testutils/db/test_db.d.ts +2 -1
  76. package/testutils/db/test_db.js +13 -4
  77. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  78. package/testutils/ent-graphql-tests/index.js +26 -17
  79. package/testutils/fake_data/fake_contact.d.ts +4 -8
  80. package/testutils/fake_data/fake_contact.js +15 -19
  81. package/testutils/fake_data/fake_event.d.ts +4 -8
  82. package/testutils/fake_data/fake_event.js +21 -25
  83. package/testutils/fake_data/fake_user.d.ts +5 -9
  84. package/testutils/fake_data/fake_user.js +23 -27
  85. package/testutils/fake_data/test_helpers.js +1 -1
  86. package/testutils/fake_data/user_query.d.ts +2 -2
  87. package/testutils/fake_log.d.ts +3 -3
  88. package/tsc/ast.d.ts +43 -0
  89. package/tsc/ast.js +264 -0
  90. package/tsc/compilerOptions.d.ts +6 -0
  91. package/tsc/compilerOptions.js +40 -1
  92. package/tsc/move_generated.d.ts +1 -0
  93. package/tsc/move_generated.js +160 -0
  94. package/tsc/transform.d.ts +21 -0
  95. package/tsc/transform.js +167 -0
  96. package/tsc/transform_action.d.ts +20 -0
  97. package/tsc/transform_action.js +169 -0
  98. package/tsc/transform_ent.d.ts +17 -0
  99. package/tsc/transform_ent.js +59 -0
  100. package/tsc/transform_schema.d.ts +27 -0
  101. package/tsc/transform_schema.js +354 -0
  102. package/scripts/transform_schema.js +0 -288
@@ -1,288 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const glob_1 = require("glob");
26
- const typescript_1 = __importDefault(require("typescript"));
27
- const fs = __importStar(require("fs"));
28
- const compilerOptions_1 = require("../tsc/compilerOptions");
29
- const child_process_1 = require("child_process");
30
- function getTarget(target) {
31
- switch (target.toLowerCase()) {
32
- case "es2015":
33
- return typescript_1.default.ScriptTarget.ES2015;
34
- case "es2016":
35
- return typescript_1.default.ScriptTarget.ES2016;
36
- case "es2017":
37
- return typescript_1.default.ScriptTarget.ES2017;
38
- case "es2018":
39
- return typescript_1.default.ScriptTarget.ES2018;
40
- case "es2019":
41
- return typescript_1.default.ScriptTarget.ES2019;
42
- case "es2020":
43
- return typescript_1.default.ScriptTarget.ES2020;
44
- case "es2021":
45
- return typescript_1.default.ScriptTarget.ES2021;
46
- case "es3":
47
- return typescript_1.default.ScriptTarget.ES3;
48
- case "es5":
49
- return typescript_1.default.ScriptTarget.ES5;
50
- case "esnext":
51
- return typescript_1.default.ScriptTarget.ESNext;
52
- default:
53
- return typescript_1.default.ScriptTarget.ESNext;
54
- }
55
- }
56
- async function main() {
57
- // this assumes this is being run from root of directory
58
- const options = (0, compilerOptions_1.readCompilerOptions)(".");
59
- let files = glob_1.glob.sync("src/schema/*.ts");
60
- const target = options.target
61
- ? // @ts-ignore
62
- getTarget(options.target)
63
- : typescript_1.default.ScriptTarget.ESNext;
64
- // filter to only event.ts e.g. for comments and whitespace...
65
- // files = files.filter((f) => f.endsWith("event.ts"));
66
- files.forEach((file) => {
67
- // assume valid file since we do glob above
68
- const idx = file.lastIndexOf(".ts");
69
- const writeFile = file.substring(0, idx) + "2" + ".ts";
70
- let contents = fs.readFileSync(file).toString();
71
- // go through the file and print everything back if not starting immediately after other position
72
- const sourceFile = typescript_1.default.createSourceFile(file, contents, target, false, typescript_1.default.ScriptKind.TS);
73
- const nodes = [];
74
- let updateImport = false;
75
- const f = {
76
- trackNode: function (tni) {
77
- nodes.push({
78
- node: tni.node,
79
- importNode: tni.node && typescript_1.default.isImportDeclaration(tni.node),
80
- rawString: tni.rawString,
81
- });
82
- },
83
- flagUpdateImport() {
84
- updateImport = true;
85
- },
86
- };
87
- if (!traverse(contents, sourceFile, f)) {
88
- return;
89
- }
90
- let newContents = "";
91
- for (const node of nodes) {
92
- if (updateImport && node.importNode) {
93
- const importNode = node.node;
94
- const transformedImport = transformImport(importNode, sourceFile);
95
- if (transformedImport) {
96
- newContents += transformedImport;
97
- continue;
98
- }
99
- }
100
- if (node.node) {
101
- newContents += node.node.getFullText(sourceFile);
102
- }
103
- else if (node.rawString) {
104
- newContents += node.rawString;
105
- }
106
- else {
107
- console.error("invalid node");
108
- }
109
- }
110
- // console.debug(newContents);
111
- // ideally there's a flag that indicates if we write
112
- fs.writeFileSync(writeFile, newContents);
113
- });
114
- (0, child_process_1.execSync)("prettier src/schema/*.ts --write");
115
- }
116
- function traverse(fileContents, sourceFile, f) {
117
- let traversed = false;
118
- typescript_1.default.forEachChild(sourceFile, function (node) {
119
- if (typescript_1.default.isClassDeclaration(node)) {
120
- traversed = true;
121
- // TODO address implicit schema doesn't work here...
122
- // console.debug(sourceFile.fileName, node.kind);
123
- if (traverseClass(fileContents, sourceFile, node, f)) {
124
- f.flagUpdateImport();
125
- return;
126
- }
127
- }
128
- f.trackNode({ node });
129
- });
130
- return traversed;
131
- }
132
- // TODO need to replace class field member, print that and see what happens
133
- function traverseClass(fileContents, sourceFile, node, f) {
134
- let updated = false;
135
- // beginning of class...
136
- // including comment
137
- let klassContents = fileContents.substring(node.getFullStart(), node.members[0].getFullStart());
138
- for (let member of node.members) {
139
- if (!isFieldElement(member, sourceFile)) {
140
- klassContents += member.getFullText(sourceFile);
141
- continue;
142
- }
143
- // intentionally doesn't parse decorators since we don't need it
144
- let fieldMap = "";
145
- // fieldMapComment...
146
- const comment = getPreText(fileContents, member, sourceFile);
147
- if (comment) {
148
- fieldMap += comment;
149
- }
150
- updated = true;
151
- // need to change to fields: FieldMap = {code: StringType()};
152
- const property = member;
153
- const initializer = property.initializer;
154
- fieldMap += "fields: FieldMap = {";
155
- for (const element of initializer.elements) {
156
- const parsed = parseFieldElement(element, sourceFile, fileContents);
157
- if (parsed === null) {
158
- return false;
159
- }
160
- const { callEx, name, nameComment, properties } = parsed;
161
- let property = "";
162
- const fieldComment = getPreText(fileContents, element, sourceFile).trim();
163
- if (fieldComment) {
164
- property += "\n" + fieldComment + "\n";
165
- }
166
- if (nameComment) {
167
- property += nameComment + "\n";
168
- }
169
- // e.g. UUIDType, StringType etc
170
- let call = callEx.expression.getText(sourceFile);
171
- let fnCall = "";
172
- if (properties.length) {
173
- fnCall = `{${properties.join(",")}}`;
174
- }
175
- property += `${name}:${call}(${fnCall}),`;
176
- fieldMap += property;
177
- }
178
- fieldMap += "}";
179
- klassContents += fieldMap;
180
- }
181
- klassContents += "\n}";
182
- // console.debug(klassContents);
183
- if (!updated) {
184
- return updated;
185
- }
186
- f.trackNode({ rawString: klassContents });
187
- return updated;
188
- }
189
- function isFieldElement(member, sourceFile) {
190
- if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
191
- return false;
192
- }
193
- const property = member;
194
- const token = property.name;
195
- if (token.escapedText !== "fields") {
196
- return false;
197
- }
198
- const propertytype = property.type?.getText(sourceFile);
199
- if (propertytype !== "Field[]") {
200
- return false;
201
- }
202
- if (property.initializer?.kind !== typescript_1.default.SyntaxKind.ArrayLiteralExpression) {
203
- console.error("invalid array type");
204
- return false;
205
- }
206
- return true;
207
- }
208
- function parseFieldElement(element, sourceFile, fileContents) {
209
- if (element.kind !== typescript_1.default.SyntaxKind.CallExpression) {
210
- console.error("skipped non-call expression");
211
- return null;
212
- }
213
- let callEx = element;
214
- if (callEx.arguments.length !== 1) {
215
- console.error("callExpression with arguments not of length 1");
216
- return null;
217
- }
218
- let arg = callEx.arguments[0];
219
- if (arg.kind !== typescript_1.default.SyntaxKind.ObjectLiteralExpression) {
220
- console.error("not objectLiteralExpression");
221
- return null;
222
- }
223
- let expr = arg;
224
- let name = "";
225
- let propertyComment;
226
- let properties = [];
227
- for (const p of expr.properties) {
228
- const p2 = p;
229
- // found name property
230
- if (p2.name.escapedText === "name") {
231
- name = p2.initializer.getText(sourceFile);
232
- // check for any comment associated with name: "fooo"
233
- propertyComment = getPreText(fileContents, p, sourceFile).trim();
234
- }
235
- else {
236
- properties.push(p.getFullText(sourceFile));
237
- }
238
- }
239
- if (!name) {
240
- console.error(`couldn't find name property`);
241
- return null;
242
- }
243
- // remove quotes
244
- name = name.slice(1, -1);
245
- return {
246
- callEx,
247
- name,
248
- properties,
249
- nameComment: propertyComment,
250
- };
251
- }
252
- function transformImport(importNode, sourceFile) {
253
- // remove quotes too
254
- const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
255
- if (text !== "@snowtop/ent" &&
256
- text !== "@snowtop/ent/schema" &&
257
- text !== "@snowtop/ent/schema/") {
258
- return;
259
- }
260
- const importText = importNode.importClause?.getText(sourceFile) || "";
261
- const start = importText.indexOf("{");
262
- const end = importText.lastIndexOf("}");
263
- if (start === -1 || end === -1) {
264
- return;
265
- }
266
- const imports = importText
267
- .substring(start + 1, end)
268
- // .trim()
269
- .split(",");
270
- for (let i = 0; i < imports.length; i++) {
271
- const imp = imports[i].trim();
272
- if (imp === "Field") {
273
- imports[i] = "FieldMap";
274
- }
275
- }
276
- // TODO better to update node instead of doing this but this works for now
277
- return ("import " +
278
- importText.substring(0, start + 1) +
279
- imports.join(", ") +
280
- importText.substring(end) +
281
- ' from "' +
282
- text +
283
- '"');
284
- }
285
- function getPreText(fileContents, node, sourceFile) {
286
- return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
287
- }
288
- Promise.resolve(main());