@snowtop/ent 0.0.40-alpha6 → 0.1.0-alpha10

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 (65) hide show
  1. package/action/action.d.ts +14 -14
  2. package/action/executor.d.ts +1 -1
  3. package/action/experimental_action.d.ts +20 -20
  4. package/action/experimental_action.js +1 -1
  5. package/action/orchestrator.d.ts +10 -10
  6. package/action/orchestrator.js +14 -14
  7. package/core/base.d.ts +6 -6
  8. package/core/ent.d.ts +2 -1
  9. package/core/ent.js +14 -10
  10. package/core/privacy.d.ts +1 -1
  11. package/core/query/assoc_query.js +2 -2
  12. package/core/query/query.d.ts +1 -1
  13. package/graphql/builtins/connection.js +3 -3
  14. package/graphql/builtins/edge.js +2 -2
  15. package/graphql/builtins/node.js +1 -1
  16. package/graphql/graphql.js +2 -2
  17. package/graphql/index.d.ts +1 -0
  18. package/graphql/index.js +3 -1
  19. package/graphql/mutations/union.d.ts +2 -0
  20. package/graphql/mutations/union.js +35 -0
  21. package/graphql/query/connection_type.js +6 -6
  22. package/graphql/query/page_info.js +4 -4
  23. package/graphql/query/shared_assoc_test.js +2 -2
  24. package/graphql/scalars/time.d.ts +1 -1
  25. package/imports/index.d.ts +0 -1
  26. package/imports/index.js +3 -36
  27. package/package.json +2 -2
  28. package/parse_schema/parse.d.ts +15 -3
  29. package/parse_schema/parse.js +42 -7
  30. package/schema/base_schema.d.ts +36 -1
  31. package/schema/base_schema.js +63 -17
  32. package/schema/field.d.ts +25 -25
  33. package/schema/field.js +42 -33
  34. package/schema/index.d.ts +4 -2
  35. package/schema/index.js +5 -1
  36. package/schema/json_field.d.ts +6 -6
  37. package/schema/json_field.js +2 -2
  38. package/schema/schema.d.ts +11 -6
  39. package/schema/schema.js +46 -12
  40. package/schema/struct_field.d.ts +17 -0
  41. package/schema/struct_field.js +102 -0
  42. package/schema/union_field.d.ts +23 -0
  43. package/schema/union_field.js +79 -0
  44. package/scripts/custom_compiler.js +2 -19
  45. package/scripts/read_schema.js +15 -1
  46. package/scripts/transform_code.d.ts +1 -0
  47. package/scripts/transform_code.js +114 -0
  48. package/scripts/transform_schema.d.ts +1 -0
  49. package/scripts/transform_schema.js +357 -0
  50. package/testutils/builder.d.ts +19 -15
  51. package/testutils/builder.js +41 -7
  52. package/testutils/db/test_db.js +9 -9
  53. package/testutils/ent-graphql-tests/index.js +19 -12
  54. package/testutils/fake_data/fake_contact.d.ts +3 -7
  55. package/testutils/fake_data/fake_contact.js +14 -26
  56. package/testutils/fake_data/fake_event.d.ts +3 -7
  57. package/testutils/fake_data/fake_event.js +20 -33
  58. package/testutils/fake_data/fake_user.d.ts +3 -7
  59. package/testutils/fake_data/fake_user.js +22 -36
  60. package/testutils/fake_data/test_helpers.js +1 -1
  61. package/testutils/fake_data/user_query.d.ts +2 -2
  62. package/tsc/ast.d.ts +20 -0
  63. package/tsc/ast.js +131 -0
  64. package/tsc/compilerOptions.d.ts +7 -0
  65. package/tsc/compilerOptions.js +95 -0
package/tsc/ast.js ADDED
@@ -0,0 +1,131 @@
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
+ exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ function getPreText(fileContents, node, sourceFile) {
9
+ return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
10
+ }
11
+ exports.getPreText = getPreText;
12
+ function getClassInfo(fileContents, sourceFile, node) {
13
+ let className = node.name?.text;
14
+ let classExtends;
15
+ let impl = [];
16
+ if (node.heritageClauses) {
17
+ for (const hc of node.heritageClauses) {
18
+ switch (hc.token) {
19
+ case typescript_1.default.SyntaxKind.ImplementsKeyword:
20
+ for (const type of hc.types) {
21
+ impl.push(type.expression.getText(sourceFile));
22
+ }
23
+ break;
24
+ case typescript_1.default.SyntaxKind.ExtendsKeyword:
25
+ // can only extend one class
26
+ for (const type of hc.types) {
27
+ const text = type.expression.getText(sourceFile);
28
+ classExtends = text;
29
+ }
30
+ break;
31
+ }
32
+ }
33
+ }
34
+ // we probably still don't need all of this...
35
+ if (!className || !node.heritageClauses || !classExtends) {
36
+ return undefined;
37
+ }
38
+ let hasExport = false;
39
+ let hasDefault = false;
40
+ let comment = getPreText(fileContents, node, sourceFile);
41
+ const wrapClassContents = (inner) => {
42
+ let ret = `${comment}`;
43
+ if (hasExport) {
44
+ ret += "export ";
45
+ }
46
+ if (hasDefault) {
47
+ ret += "default ";
48
+ }
49
+ ret += `class ${className} `;
50
+ if (classExtends) {
51
+ ret += `extends ${classExtends} `;
52
+ }
53
+ if (impl.length) {
54
+ ret += `implements ${impl.join(", ")}`;
55
+ }
56
+ return `${ret}{
57
+ ${inner}
58
+ }`;
59
+ };
60
+ if (node.modifiers) {
61
+ for (const mod of node.modifiers) {
62
+ const text = mod.getText(sourceFile);
63
+ if (text === "export") {
64
+ hasExport = true;
65
+ }
66
+ else if (text === "default") {
67
+ hasDefault = true;
68
+ }
69
+ }
70
+ }
71
+ return {
72
+ name: className,
73
+ extends: classExtends,
74
+ comment,
75
+ implements: impl,
76
+ wrapClassContents,
77
+ export: hasExport,
78
+ default: hasDefault,
79
+ };
80
+ }
81
+ exports.getClassInfo = getClassInfo;
82
+ function transformImport(fileContents, importNode, sourceFile, opts) {
83
+ // remove quotes too
84
+ const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
85
+ if (text !== "@snowtop/ent" &&
86
+ text !== "@snowtop/ent/schema" &&
87
+ text !== "@snowtop/ent/schema/") {
88
+ return;
89
+ }
90
+ const importText = importNode.importClause?.getText(sourceFile) || "";
91
+ const start = importText.indexOf("{");
92
+ const end = importText.lastIndexOf("}");
93
+ if (start === -1 || end === -1) {
94
+ return;
95
+ }
96
+ const imports = importText
97
+ .substring(start + 1, end)
98
+ // .trim()
99
+ .split(",");
100
+ let removeImportsMap = {};
101
+ if (opts?.removeImports) {
102
+ opts.removeImports.forEach((imp) => (removeImportsMap[imp] = true));
103
+ }
104
+ let finalImports = new Set();
105
+ for (let i = 0; i < imports.length; i++) {
106
+ let imp = imports[i].trim();
107
+ if (imp === "") {
108
+ continue;
109
+ }
110
+ if (opts?.transform) {
111
+ imp = opts.transform(imp);
112
+ }
113
+ if (removeImportsMap[imp]) {
114
+ continue;
115
+ }
116
+ finalImports.add(imp);
117
+ }
118
+ if (opts?.newImports) {
119
+ opts.newImports.forEach((imp) => finalImports.add(imp));
120
+ }
121
+ const comment = getPreText(fileContents, importNode, sourceFile);
122
+ return (comment +
123
+ "import " +
124
+ importText.substring(0, start + 1) +
125
+ Array.from(finalImports).join(", ") +
126
+ importText.substring(end) +
127
+ ' from "' +
128
+ text +
129
+ '";');
130
+ }
131
+ exports.transformImport = transformImport;
@@ -0,0 +1,7 @@
1
+ import ts from "typescript";
2
+ export declare function readCompilerOptions(filePath: string): ts.CompilerOptions;
3
+ export declare function getTarget(target?: string): ts.ScriptTarget.ES3 | ts.ScriptTarget.ES5 | ts.ScriptTarget.ES2015 | ts.ScriptTarget.ES2016 | ts.ScriptTarget.ES2017 | ts.ScriptTarget.ES2018 | ts.ScriptTarget.ES2019 | ts.ScriptTarget.ES2020 | ts.ScriptTarget.ES2021 | ts.ScriptTarget.ESNext;
4
+ export declare function createSourceFile(target: ts.ScriptTarget, file: string): {
5
+ contents: string;
6
+ sourceFile: ts.SourceFile;
7
+ };
@@ -0,0 +1,95 @@
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
+ exports.createSourceFile = exports.getTarget = exports.readCompilerOptions = void 0;
26
+ const fs = __importStar(require("fs"));
27
+ const json5_1 = __importDefault(require("json5"));
28
+ const typescript_1 = __importDefault(require("typescript"));
29
+ const path = __importStar(require("path"));
30
+ function findTSConfigFile(filePath) {
31
+ while (filePath != "/") {
32
+ let configPath = `${filePath}/tsconfig.json`;
33
+ if (fs.existsSync(configPath)) {
34
+ return configPath;
35
+ }
36
+ filePath = path.join(filePath, "..");
37
+ }
38
+ return null;
39
+ }
40
+ function readCompilerOptions(filePath) {
41
+ let configPath = findTSConfigFile(filePath);
42
+ if (!configPath) {
43
+ return {};
44
+ }
45
+ let json = {};
46
+ try {
47
+ json = json5_1.default.parse(fs.readFileSync(configPath, {
48
+ encoding: "utf8",
49
+ }));
50
+ }
51
+ catch (e) {
52
+ console.error("couldn't read tsconfig.json file");
53
+ }
54
+ let options = json["compilerOptions"] || {};
55
+ // @ts-ignore
56
+ if (options.moduleResolution === "node") {
57
+ options.moduleResolution = typescript_1.default.ModuleResolutionKind.NodeJs;
58
+ }
59
+ return options;
60
+ }
61
+ exports.readCompilerOptions = readCompilerOptions;
62
+ function getTarget(target) {
63
+ switch (target?.toLowerCase()) {
64
+ case "es2015":
65
+ return typescript_1.default.ScriptTarget.ES2015;
66
+ case "es2016":
67
+ return typescript_1.default.ScriptTarget.ES2016;
68
+ case "es2017":
69
+ return typescript_1.default.ScriptTarget.ES2017;
70
+ case "es2018":
71
+ return typescript_1.default.ScriptTarget.ES2018;
72
+ case "es2019":
73
+ return typescript_1.default.ScriptTarget.ES2019;
74
+ case "es2020":
75
+ return typescript_1.default.ScriptTarget.ES2020;
76
+ case "es2021":
77
+ return typescript_1.default.ScriptTarget.ES2021;
78
+ case "es3":
79
+ return typescript_1.default.ScriptTarget.ES3;
80
+ case "es5":
81
+ return typescript_1.default.ScriptTarget.ES5;
82
+ case "esnext":
83
+ return typescript_1.default.ScriptTarget.ESNext;
84
+ default:
85
+ return typescript_1.default.ScriptTarget.ESNext;
86
+ }
87
+ }
88
+ exports.getTarget = getTarget;
89
+ function createSourceFile(target, file) {
90
+ let contents = fs.readFileSync(file).toString();
91
+ // go through the file and print everything back if not starting immediately after other position
92
+ const sourceFile = typescript_1.default.createSourceFile(file, contents, target, false, typescript_1.default.ScriptKind.TS);
93
+ return { contents, sourceFile };
94
+ }
95
+ exports.createSourceFile = createSourceFile;