@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
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.
- package/action/action.d.ts +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
package/tsc/compilerOptions.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.readCompilerOptions = void 0;
|
|
25
|
+
exports.createSourceFile = exports.getTargetFromCurrentDir = exports.getTarget = exports.readCompilerOptions = void 0;
|
|
26
26
|
const fs = __importStar(require("fs"));
|
|
27
27
|
const json5_1 = __importDefault(require("json5"));
|
|
28
28
|
const typescript_1 = __importDefault(require("typescript"));
|
|
@@ -59,3 +59,42 @@ function readCompilerOptions(filePath) {
|
|
|
59
59
|
return options;
|
|
60
60
|
}
|
|
61
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 getTargetFromCurrentDir() {
|
|
90
|
+
const options = readCompilerOptions(".");
|
|
91
|
+
return getTarget(options.target?.toString());
|
|
92
|
+
}
|
|
93
|
+
exports.getTargetFromCurrentDir = getTargetFromCurrentDir;
|
|
94
|
+
function createSourceFile(target, file) {
|
|
95
|
+
let contents = fs.readFileSync(file).toString();
|
|
96
|
+
// go through the file and print everything back if not starting immediately after other position
|
|
97
|
+
const sourceFile = typescript_1.default.createSourceFile(file, contents, target, false, typescript_1.default.ScriptKind.TS);
|
|
98
|
+
return { contents, sourceFile };
|
|
99
|
+
}
|
|
100
|
+
exports.createSourceFile = createSourceFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function moveGenerated(relativeImports: boolean): void;
|
|
@@ -0,0 +1,160 @@
|
|
|
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.moveGenerated = void 0;
|
|
26
|
+
const glob_1 = require("glob");
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
30
|
+
const ast_1 = require("./ast");
|
|
31
|
+
const transform_1 = require("./transform");
|
|
32
|
+
class MoveFiles {
|
|
33
|
+
constructor(globPath) {
|
|
34
|
+
this.globPath = globPath;
|
|
35
|
+
}
|
|
36
|
+
move() {
|
|
37
|
+
const files = glob_1.glob.sync(this.globPath);
|
|
38
|
+
moveFiles(files);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class TransformImports {
|
|
42
|
+
constructor(glob, prettierGlob, relativeImports, checkRelativeImportsValid) {
|
|
43
|
+
this.glob = glob;
|
|
44
|
+
this.prettierGlob = prettierGlob;
|
|
45
|
+
this.relativeImports = relativeImports;
|
|
46
|
+
this.checkRelativeImportsValid = checkRelativeImportsValid;
|
|
47
|
+
this.globOptions = {
|
|
48
|
+
ignore: ["node_modules/**"],
|
|
49
|
+
};
|
|
50
|
+
this.cwd = process.cwd();
|
|
51
|
+
}
|
|
52
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
53
|
+
if (!typescript_1.default.isImportDeclaration(node)) {
|
|
54
|
+
return { node };
|
|
55
|
+
}
|
|
56
|
+
let dirPath = path.join(this.cwd, file, "..");
|
|
57
|
+
const newImportPath = this.getNewImportPath(node, file, sourceFile, dirPath);
|
|
58
|
+
if (!newImportPath) {
|
|
59
|
+
return { node };
|
|
60
|
+
}
|
|
61
|
+
const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
|
|
62
|
+
return {
|
|
63
|
+
traversed: true,
|
|
64
|
+
rawString: v,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
getNewImportPath(node, file, sourceFile, dirPath) {
|
|
68
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
69
|
+
// it's relative and has generated in there, continue
|
|
70
|
+
// do relative imports path regardless of if relative imports is on or not
|
|
71
|
+
if ((0, ast_1.isRelativeGeneratedImport)(node, sourceFile)) {
|
|
72
|
+
const oldPath = path.join(dirPath, text);
|
|
73
|
+
const relFromRoot = path.relative(".", oldPath);
|
|
74
|
+
const conv = transformPath(relFromRoot);
|
|
75
|
+
if (!conv || conv.newFile === relFromRoot) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return path.relative(dirPath, conv.newFile);
|
|
79
|
+
}
|
|
80
|
+
if (this.checkRelativeImportsValid && (0, ast_1.isRelativeImport)(node, sourceFile)) {
|
|
81
|
+
const parts = file.split(path.sep);
|
|
82
|
+
if (parts.length === 5 &&
|
|
83
|
+
parts.slice(0, 3).join(path.sep) ===
|
|
84
|
+
["src", "graphql", "generated"].join(path.sep)) {
|
|
85
|
+
// we have custom graphql import paths
|
|
86
|
+
// src/graphql/generated/mutations|resolvers/foo_type.ts
|
|
87
|
+
// which used to be
|
|
88
|
+
// src/graphql/mutations|resolvers/generated/foo_type.ts
|
|
89
|
+
// we probably have a broken import.
|
|
90
|
+
// try and fix it...
|
|
91
|
+
let temp = parts[2];
|
|
92
|
+
parts[2] = parts[3];
|
|
93
|
+
parts[3] = temp;
|
|
94
|
+
const oldPath = parts.join(path.sep);
|
|
95
|
+
let oldDir = path.join(this.cwd, oldPath, "..");
|
|
96
|
+
let importPath = path.join(oldDir, text);
|
|
97
|
+
let exists = fs.statSync(importPath + ".ts", { throwIfNoEntry: false });
|
|
98
|
+
if (!exists) {
|
|
99
|
+
// doesn't exist. sadly has to be fixed manually. could theoretically also be a directory but we shouldn't have that
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
return path.relative(dirPath, importPath);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// if relative imports, we done.
|
|
106
|
+
if (this.relativeImports) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// non relative, only transform src paths with generated
|
|
110
|
+
if ((0, ast_1.isSrcGeneratedImport)(node, sourceFile)) {
|
|
111
|
+
const conv = transformPath(text);
|
|
112
|
+
if (!conv || conv.newFile === text) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
return conv.newFile;
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function transformPath(old) {
|
|
121
|
+
const parts = old.split(path.sep);
|
|
122
|
+
if (parts.length < 3) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const changedParts = parts
|
|
126
|
+
.slice(0, 2)
|
|
127
|
+
.concat("generated")
|
|
128
|
+
.concat(parts.slice(2).filter((v) => v !== "generated"));
|
|
129
|
+
const newFile = changedParts.join(path.sep);
|
|
130
|
+
return { changedParts, newFile };
|
|
131
|
+
}
|
|
132
|
+
function moveFiles(files) {
|
|
133
|
+
files.forEach((file) => {
|
|
134
|
+
const conv = transformPath(file);
|
|
135
|
+
if (!conv) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const { changedParts, newFile } = conv;
|
|
139
|
+
if (file === newFile) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// check if directory exists, if not, create recursive dir
|
|
143
|
+
const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
|
|
144
|
+
const statInfo = fs.statSync(p, { throwIfNoEntry: false });
|
|
145
|
+
if (!statInfo) {
|
|
146
|
+
fs.mkdirSync(p, {
|
|
147
|
+
recursive: true,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// move file to new location
|
|
151
|
+
fs.renameSync(file, newFile);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function moveGenerated(relativeImports) {
|
|
155
|
+
new MoveFiles("src/ent/**/generated/**/**.ts").move();
|
|
156
|
+
new MoveFiles("src/graphql/**/generated/**/**.ts").move();
|
|
157
|
+
(0, transform_1.transform)(new TransformImports("src/ent/**/*.ts", "src/ent/**/*.ts", relativeImports));
|
|
158
|
+
(0, transform_1.transform)(new TransformImports("src/graphql/**/*.ts", "src/graphql/**/*.ts", relativeImports, true));
|
|
159
|
+
}
|
|
160
|
+
exports.moveGenerated = moveGenerated;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IOptions } from "glob";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
interface TraverseChildResponse {
|
|
4
|
+
node?: ts.Node;
|
|
5
|
+
rawString?: string;
|
|
6
|
+
traversed?: boolean;
|
|
7
|
+
imports?: Map<string, string[]>;
|
|
8
|
+
removeImports?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface TransformFile {
|
|
11
|
+
glob: string;
|
|
12
|
+
globOptions?: IOptions;
|
|
13
|
+
preprocessFile?: (contents: string, file: string, sourceFile: ts.SourceFile) => boolean;
|
|
14
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): TraverseChildResponse | undefined;
|
|
15
|
+
filter?(files: string[]): string[];
|
|
16
|
+
fileToWrite?(file: string): string;
|
|
17
|
+
postProcess?(file: string): void;
|
|
18
|
+
prettierGlob?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function transform(transform: TransformFile): void;
|
|
21
|
+
export {};
|
package/tsc/transform.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
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.transform = void 0;
|
|
26
|
+
const glob_1 = require("glob");
|
|
27
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
28
|
+
const child_process_1 = require("child_process");
|
|
29
|
+
const fs = __importStar(require("fs"));
|
|
30
|
+
const ast_1 = require("./ast");
|
|
31
|
+
const compilerOptions_1 = require("./compilerOptions");
|
|
32
|
+
function normalizePath(p) {
|
|
33
|
+
if (p.endsWith("..")) {
|
|
34
|
+
return p + "/";
|
|
35
|
+
}
|
|
36
|
+
return p;
|
|
37
|
+
}
|
|
38
|
+
function transform(transform) {
|
|
39
|
+
let files = glob_1.glob.sync(transform.glob, transform.globOptions);
|
|
40
|
+
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
41
|
+
if (transform.filter) {
|
|
42
|
+
files = transform.filter(files);
|
|
43
|
+
}
|
|
44
|
+
files.forEach((file) => {
|
|
45
|
+
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
46
|
+
let nodes = [];
|
|
47
|
+
let imports = new Map();
|
|
48
|
+
let removeImports = [];
|
|
49
|
+
let traversed = false;
|
|
50
|
+
let seenImports = new Map();
|
|
51
|
+
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
52
|
+
if (typescript_1.default.isImportDeclaration(node)) {
|
|
53
|
+
const imp = (0, ast_1.getImportInfo)(node, sourceFile);
|
|
54
|
+
if (imp) {
|
|
55
|
+
imp.imports.forEach((v) => {
|
|
56
|
+
v = v.trim();
|
|
57
|
+
v && seenImports.set(v, true);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const ret = transform.traverseChild(sourceFile, contents, file, node);
|
|
62
|
+
if (!ret) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ret.node || ret.rawString) {
|
|
66
|
+
nodes.push(ret);
|
|
67
|
+
}
|
|
68
|
+
if (ret.imports) {
|
|
69
|
+
for (const [k, v] of ret.imports) {
|
|
70
|
+
imports.set(k, v);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (ret.traversed) {
|
|
74
|
+
traversed = ret.traversed;
|
|
75
|
+
}
|
|
76
|
+
if (ret.removeImports?.length) {
|
|
77
|
+
removeImports.push(...ret.removeImports);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!traversed) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let newContents = "";
|
|
84
|
+
let afterProcessed = false;
|
|
85
|
+
let seen = new Map();
|
|
86
|
+
const processAfterImport = () => {
|
|
87
|
+
// do this for the first non-import node we see
|
|
88
|
+
// we want to add new imports to end of imports and there's an assumption that imports are ordered
|
|
89
|
+
// at top of file
|
|
90
|
+
if (!afterProcessed) {
|
|
91
|
+
for (const [imp, list] of imports) {
|
|
92
|
+
if (seen.has(imp)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const final = list.filter((v) => !seenImports.has(v));
|
|
96
|
+
if (final.length) {
|
|
97
|
+
newContents += `\nimport { ${final.join(", ")} } from "${imp}"`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
afterProcessed = true;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
for (const node of nodes) {
|
|
104
|
+
if (node.node) {
|
|
105
|
+
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
106
|
+
const impInfo = (0, ast_1.getImportInfo)(node.node, sourceFile);
|
|
107
|
+
// console.debug(impInfo);
|
|
108
|
+
if (impInfo) {
|
|
109
|
+
const impPath = normalizePath(impInfo.importPath);
|
|
110
|
+
const list = imports.get(impPath);
|
|
111
|
+
// path exists, we care about it
|
|
112
|
+
if (list !== undefined) {
|
|
113
|
+
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
114
|
+
// if we've done this path before, don't try and add
|
|
115
|
+
// but still try and do any removals since we don't know which of the imports
|
|
116
|
+
// has it
|
|
117
|
+
newImports: seen.has(impPath) ? undefined : list,
|
|
118
|
+
removeImports,
|
|
119
|
+
// don't use normalized path here, we wanna use the path that's in code...
|
|
120
|
+
transformPath: impInfo.importPath,
|
|
121
|
+
});
|
|
122
|
+
if (transformed) {
|
|
123
|
+
newContents += transformed;
|
|
124
|
+
seen.set(impPath, true);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (!typescript_1.default.isExportDeclaration(node.node) &&
|
|
132
|
+
!isRequireStatement(node.node, sourceFile)) {
|
|
133
|
+
processAfterImport();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
newContents += node.node.getFullText(sourceFile);
|
|
137
|
+
}
|
|
138
|
+
else if (node.rawString) {
|
|
139
|
+
processAfterImport();
|
|
140
|
+
newContents += node.rawString;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
throw new Error(`malformed node with no node or rawString`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
let writeFile = file;
|
|
147
|
+
if (transform.fileToWrite) {
|
|
148
|
+
writeFile = transform.fileToWrite(file);
|
|
149
|
+
}
|
|
150
|
+
fs.writeFileSync(writeFile, newContents);
|
|
151
|
+
if (transform.postProcess) {
|
|
152
|
+
transform.postProcess(file);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
if (transform.prettierGlob) {
|
|
156
|
+
(0, child_process_1.execSync)(`prettier ${transform.prettierGlob} --write`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.transform = transform;
|
|
160
|
+
function isRequireStatement(node, sourceFile) {
|
|
161
|
+
if (node.kind !== typescript_1.default.SyntaxKind.VariableStatement) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const v = node;
|
|
165
|
+
const text = v.declarationList.declarations[0].getFullText(sourceFile);
|
|
166
|
+
return text.includes("require(");
|
|
167
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { customInfo } from "../tsc/ast";
|
|
3
|
+
import { TransformFile } from "./transform";
|
|
4
|
+
export declare class TransformAction implements TransformFile {
|
|
5
|
+
private customInfo;
|
|
6
|
+
glob: string;
|
|
7
|
+
prettierGlob: string;
|
|
8
|
+
constructor(customInfo: customInfo);
|
|
9
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
10
|
+
node: ts.Node;
|
|
11
|
+
rawString?: undefined;
|
|
12
|
+
traversed?: undefined;
|
|
13
|
+
imports?: undefined;
|
|
14
|
+
removeImports?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
rawString: string;
|
|
17
|
+
traversed: boolean;
|
|
18
|
+
imports: Map<string, string[]>;
|
|
19
|
+
removeImports: string[];
|
|
20
|
+
node?: undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
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.TransformAction = void 0;
|
|
26
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
27
|
+
const ast_1 = require("../tsc/ast");
|
|
28
|
+
const viewer_1 = require("../core/viewer");
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const snake_case_1 = require("snake-case");
|
|
31
|
+
// returns input and importPath
|
|
32
|
+
function getBaseFileInfo(file, classInfo, sourceFile) {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
35
|
+
for (const imp of importStatements) {
|
|
36
|
+
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
37
|
+
if ((0, ast_1.isSrcGeneratedImport)(imp, sourceFile) ||
|
|
38
|
+
(0, ast_1.isRelativeGeneratedImport)(imp, sourceFile)) {
|
|
39
|
+
// base file and we're importing from it
|
|
40
|
+
// e.g. in create_user_action, we're importing from create_user_action_base
|
|
41
|
+
if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
45
|
+
if (!impInfo) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
let inputs = impInfo.imports
|
|
49
|
+
.filter((imp) => imp.trim() && imp.endsWith("Input"))
|
|
50
|
+
.map((v) => v.trim());
|
|
51
|
+
if (inputs.length === 1) {
|
|
52
|
+
return {
|
|
53
|
+
input: inputs[0],
|
|
54
|
+
importPath: impInfo.importPath,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (inputs.length && classInfo.name.endsWith("Action")) {
|
|
58
|
+
const prefix = classInfo.name.slice(0, classInfo.name.length - 6);
|
|
59
|
+
inputs = inputs.filter((imp) => imp.slice(0, imp.length - 5) === prefix);
|
|
60
|
+
if (inputs.length === 1) {
|
|
61
|
+
return {
|
|
62
|
+
input: inputs[0],
|
|
63
|
+
importPath: impInfo.importPath,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let m = {
|
|
72
|
+
triggers: {
|
|
73
|
+
m: "getTriggers",
|
|
74
|
+
i: "Trigger",
|
|
75
|
+
suffix: "Triggers",
|
|
76
|
+
},
|
|
77
|
+
observers: {
|
|
78
|
+
m: "getObservers",
|
|
79
|
+
i: "Observer",
|
|
80
|
+
suffix: "Observers",
|
|
81
|
+
},
|
|
82
|
+
validators: {
|
|
83
|
+
m: "getValidators",
|
|
84
|
+
i: "Validator",
|
|
85
|
+
suffix: "Validators",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
function getConversionInfo(mm, actionName) {
|
|
89
|
+
if (mm.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const text = mm.name.escapedText;
|
|
93
|
+
const v = m[text];
|
|
94
|
+
if (v === undefined) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
text,
|
|
99
|
+
method: v.m,
|
|
100
|
+
interface: v.i,
|
|
101
|
+
// CreateFooActionTriggers etc
|
|
102
|
+
methodType: actionName + v.suffix,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
class TransformAction {
|
|
106
|
+
constructor(customInfo) {
|
|
107
|
+
this.customInfo = customInfo;
|
|
108
|
+
this.glob = "src/ent/**/actions/**/*_action.ts";
|
|
109
|
+
this.prettierGlob = "src/ent/**/actions/**.ts";
|
|
110
|
+
}
|
|
111
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
112
|
+
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
113
|
+
return { node };
|
|
114
|
+
}
|
|
115
|
+
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
116
|
+
// only do classes
|
|
117
|
+
if (!classInfo || !classInfo.default) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// require action
|
|
121
|
+
const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
|
|
122
|
+
const action = new p.default(new viewer_1.LoggedOutViewer(), {});
|
|
123
|
+
const actionName = action.constructor.name;
|
|
124
|
+
const builder = action.builder.constructor.name;
|
|
125
|
+
const nodeName = action.builder.ent.name;
|
|
126
|
+
const viewer = this.customInfo.viewerInfo.name;
|
|
127
|
+
const baseInfo = getBaseFileInfo(file, classInfo, sourceFile);
|
|
128
|
+
if (!baseInfo) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let klassContents = "";
|
|
132
|
+
let traversed = false;
|
|
133
|
+
let newImports = [];
|
|
134
|
+
for (const mm of node.members) {
|
|
135
|
+
const conv = getConversionInfo(mm, actionName);
|
|
136
|
+
if (conv !== null) {
|
|
137
|
+
const property = mm;
|
|
138
|
+
// if invalid, bounce
|
|
139
|
+
if (!property.initializer) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
traversed = true;
|
|
143
|
+
const pp = property.initializer.getFullText(sourceFile).trim();
|
|
144
|
+
const code = `${conv.method}(): ${conv.methodType} {
|
|
145
|
+
return ${pp}
|
|
146
|
+
}`;
|
|
147
|
+
newImports.push(conv.methodType);
|
|
148
|
+
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
klassContents += mm.getFullText(sourceFile);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const builderPath = `src/ent/generated/${(0, snake_case_1.snakeCase)(nodeName)}/actions/${(0, snake_case_1.snakeCase)(builder)}`;
|
|
155
|
+
let imports = new Map([
|
|
156
|
+
[
|
|
157
|
+
(0, ast_1.transformRelative)(file, this.customInfo.viewerInfo.path, this.customInfo.relativeImports),
|
|
158
|
+
[viewer],
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
(0, ast_1.transformRelative)(file, baseInfo.importPath, this.customInfo.relativeImports),
|
|
162
|
+
newImports,
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
(0, ast_1.transformRelative)(file, builderPath, this.customInfo.relativeImports),
|
|
166
|
+
[builder],
|
|
167
|
+
],
|
|
168
|
+
]);
|
|
169
|
+
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
170
|
+
return {
|
|
171
|
+
rawString: classInfo.wrapClassContents(klassContents),
|
|
172
|
+
traversed,
|
|
173
|
+
imports,
|
|
174
|
+
removeImports: ["Trigger", "Observer", "Validator"],
|
|
175
|
+
// not removing FooBuilder incase it's still somehow used in type of inline builders
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.TransformAction = TransformAction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
export declare class TransformEnt implements TransformFile {
|
|
4
|
+
glob: string;
|
|
5
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
6
|
+
node: ts.Node;
|
|
7
|
+
rawString?: undefined;
|
|
8
|
+
traversed?: undefined;
|
|
9
|
+
imports?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
rawString: string;
|
|
12
|
+
traversed: boolean;
|
|
13
|
+
imports: Map<string, string[]>;
|
|
14
|
+
node?: undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
prettierGlob: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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.TransformEnt = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const ast_1 = require("./ast");
|
|
9
|
+
function isPrivacyPolicy(mm) {
|
|
10
|
+
return (mm.kind === typescript_1.default.SyntaxKind.PropertyDeclaration &&
|
|
11
|
+
mm.name.escapedText === "privacyPolicy");
|
|
12
|
+
}
|
|
13
|
+
class TransformEnt {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.glob = "src/ent/*.ts";
|
|
16
|
+
this.prettierGlob = "src/ent/*.ts";
|
|
17
|
+
}
|
|
18
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
19
|
+
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
20
|
+
return { node };
|
|
21
|
+
}
|
|
22
|
+
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
23
|
+
if (!classInfo) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// different class. ignore
|
|
27
|
+
// only do classes which extend a base class e.g. User extends UserBase
|
|
28
|
+
// if different class (e.g. privacy rule), just return it
|
|
29
|
+
if (classInfo.extends !== classInfo.name + "Base") {
|
|
30
|
+
return { node };
|
|
31
|
+
}
|
|
32
|
+
let klassContents = "";
|
|
33
|
+
let traversed = false;
|
|
34
|
+
for (const mm of node.members) {
|
|
35
|
+
if (isPrivacyPolicy(mm)) {
|
|
36
|
+
const property = mm;
|
|
37
|
+
// if invalid privacy policy, bounce
|
|
38
|
+
if (!property.initializer) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const pp = property.initializer.getFullText(sourceFile);
|
|
42
|
+
const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
43
|
+
return ${pp}
|
|
44
|
+
}`;
|
|
45
|
+
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
46
|
+
traversed = true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
klassContents += mm.getFullText(sourceFile);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
rawString: classInfo.wrapClassContents(klassContents),
|
|
54
|
+
traversed,
|
|
55
|
+
imports: new Map([["@snowtop/ent", ["PrivacyPolicy"]]]),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.TransformEnt = TransformEnt;
|