@snowtop/ent 0.1.0-alpha2 → 0.1.0-alpha20
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 +21 -20
- package/action/experimental_action.js +11 -5
- package/action/orchestrator.d.ts +31 -16
- package/action/orchestrator.js +156 -43
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +25 -21
- package/core/base.js +16 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +246 -5
- package/core/config.d.ts +23 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/db.d.ts +3 -3
- package/core/db.js +2 -0
- package/core/ent.d.ts +19 -21
- package/core/ent.js +76 -25
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- 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/object_loader.d.ts +10 -5
- package/core/loaders/object_loader.js +59 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/privacy.d.ts +25 -25
- package/core/privacy.js +3 -0
- 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/viewer.d.ts +4 -3
- package/core/viewer.js +4 -0
- 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 +24 -23
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -1
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- 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 +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +23 -4
- package/parse_schema/parse.js +68 -6
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +1 -1
- package/schema/field.js +11 -3
- package/schema/index.d.ts +4 -2
- package/schema/index.js +10 -1
- package/schema/schema.d.ts +64 -2
- package/schema/schema.js +125 -5
- package/schema/struct_field.d.ts +17 -0
- package/schema/struct_field.js +102 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_graphql.js +122 -15
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +43 -0
- package/scripts/read_schema.js +15 -1
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +98 -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 +2 -1
- package/testutils/db/test_db.js +13 -4
- 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 +4 -8
- package/testutils/fake_data/fake_contact.js +15 -19
- package/testutils/fake_data/fake_event.d.ts +4 -8
- package/testutils/fake_data/fake_event.js +21 -25
- package/testutils/fake_data/fake_user.d.ts +5 -9
- package/testutils/fake_data/fake_user.js +23 -27
- package/testutils/fake_data/test_helpers.js +1 -1
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/tsc/ast.d.ts +33 -0
- package/tsc/ast.js +191 -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 +175 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +144 -0
- package/tsc/transform_action.d.ts +27 -0
- package/tsc/transform_action.js +204 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +21 -0
- package/tsc/transform_schema.js +341 -0
- package/scripts/transform_schema.js +0 -288
package/tsc/transform.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
51
|
+
const ret = transform.traverseChild(sourceFile, contents, file, node);
|
|
52
|
+
if (!ret) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (ret.node || ret.rawString) {
|
|
56
|
+
nodes.push(ret);
|
|
57
|
+
}
|
|
58
|
+
if (ret.imports) {
|
|
59
|
+
for (const [k, v] of ret.imports) {
|
|
60
|
+
imports.set(k, v);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (ret.traversed) {
|
|
64
|
+
traversed = ret.traversed;
|
|
65
|
+
}
|
|
66
|
+
if (ret.removeImports?.length) {
|
|
67
|
+
removeImports.push(...ret.removeImports);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (!traversed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let newContents = "";
|
|
74
|
+
let afterProcessed = false;
|
|
75
|
+
let seen = new Map();
|
|
76
|
+
const processAfterImport = () => {
|
|
77
|
+
// do this for the first non-import node we see
|
|
78
|
+
// we want to add new imports to end of imports and there's an assumption that imports are ordered
|
|
79
|
+
// at top of file
|
|
80
|
+
if (!afterProcessed) {
|
|
81
|
+
for (const [imp, list] of imports) {
|
|
82
|
+
if (seen.has(imp)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
newContents += `\nimport { ${list.join(", ")} } from "${imp}"`;
|
|
86
|
+
}
|
|
87
|
+
afterProcessed = true;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
for (const node of nodes) {
|
|
91
|
+
if (node.node) {
|
|
92
|
+
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
93
|
+
const impInfo = (0, ast_1.getImportInfo)(node.node, sourceFile);
|
|
94
|
+
if (impInfo) {
|
|
95
|
+
const impPath = normalizePath(impInfo.importPath);
|
|
96
|
+
const list = imports.get(impPath);
|
|
97
|
+
if (list) {
|
|
98
|
+
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
99
|
+
// if we've done this path before, don't try and add
|
|
100
|
+
// but still try and do any removals since we don't know which of the imports
|
|
101
|
+
// has it
|
|
102
|
+
newImports: seen.has(impPath) ? undefined : list,
|
|
103
|
+
removeImports,
|
|
104
|
+
// don't use normalized path here, we wanna use the path that's in code...
|
|
105
|
+
transformPath: impInfo.importPath,
|
|
106
|
+
});
|
|
107
|
+
if (transformed) {
|
|
108
|
+
newContents += transformed;
|
|
109
|
+
seen.set(impPath, true);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (!typescript_1.default.isExportDeclaration(node.node)) {
|
|
117
|
+
processAfterImport();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
newContents += node.node.getFullText(sourceFile);
|
|
121
|
+
}
|
|
122
|
+
else if (node.rawString) {
|
|
123
|
+
processAfterImport();
|
|
124
|
+
newContents += node.rawString;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error(`malformed node with no node or rawString`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let writeFile = file;
|
|
131
|
+
if (transform.fileToWrite) {
|
|
132
|
+
writeFile = transform.fileToWrite(file);
|
|
133
|
+
}
|
|
134
|
+
// TODO new file
|
|
135
|
+
fs.writeFileSync(writeFile, newContents);
|
|
136
|
+
if (transform.postProcess) {
|
|
137
|
+
transform.postProcess(file);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (transform.prettierGlob) {
|
|
141
|
+
(0, child_process_1.execSync)(`prettier ${transform.prettierGlob} --write`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.transform = transform;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
interface customInfo {
|
|
4
|
+
viewerInfo: {
|
|
5
|
+
path: string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
relativeImports?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class TransformAction implements TransformFile {
|
|
11
|
+
glob: string;
|
|
12
|
+
customInfo: customInfo;
|
|
13
|
+
prettierGlob: string;
|
|
14
|
+
constructor();
|
|
15
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
16
|
+
node: ts.Node;
|
|
17
|
+
rawString?: undefined;
|
|
18
|
+
traversed?: undefined;
|
|
19
|
+
imports?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
rawString: string;
|
|
22
|
+
traversed: boolean;
|
|
23
|
+
imports: Map<string, string[]>;
|
|
24
|
+
node?: undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
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 fs = __importStar(require("fs"));
|
|
29
|
+
const action_1 = require("../action");
|
|
30
|
+
const viewer_1 = require("../core/viewer");
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const js_yaml_1 = require("js-yaml");
|
|
33
|
+
function getCustomInfo() {
|
|
34
|
+
let yaml = {};
|
|
35
|
+
let relativeImports = false;
|
|
36
|
+
try {
|
|
37
|
+
yaml = (0, js_yaml_1.load)(fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
|
|
38
|
+
encoding: "utf8",
|
|
39
|
+
}));
|
|
40
|
+
relativeImports = yaml?.codegen?.relativeImports || false;
|
|
41
|
+
if (yaml?.codegen?.templatizedViewer) {
|
|
42
|
+
return {
|
|
43
|
+
viewerInfo: yaml.codegen.templatizedViewer,
|
|
44
|
+
relativeImports,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e) { }
|
|
49
|
+
return {
|
|
50
|
+
viewerInfo: {
|
|
51
|
+
path: "@snowtop/ent",
|
|
52
|
+
name: "Viewer",
|
|
53
|
+
},
|
|
54
|
+
relativeImports,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function findInput(file, classInfo, sourceFile) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
60
|
+
for (const imp of importStatements) {
|
|
61
|
+
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
62
|
+
if ((0, ast_1.isSrcGeneratedImport)(imp, sourceFile) ||
|
|
63
|
+
(0, ast_1.isRelativeGeneratedImport)(imp, sourceFile)) {
|
|
64
|
+
// base file and we're importing from it
|
|
65
|
+
// e.g. in create_user_action, we're importing from create_user_action_base
|
|
66
|
+
if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
70
|
+
if (!impInfo) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let inputs = impInfo.imports
|
|
74
|
+
.filter((imp) => imp.trim() && imp.endsWith("Input"))
|
|
75
|
+
.map((v) => v.trim());
|
|
76
|
+
if (inputs.length === 1) {
|
|
77
|
+
return inputs[0];
|
|
78
|
+
}
|
|
79
|
+
if (inputs.length && classInfo.name.endsWith("Action")) {
|
|
80
|
+
const prefix = classInfo.name.slice(0, classInfo.name.length - 6);
|
|
81
|
+
inputs = inputs.filter((imp) => imp.slice(0, imp.length - 5) === prefix);
|
|
82
|
+
if (inputs.length === 1) {
|
|
83
|
+
return inputs[0];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
let m = {
|
|
91
|
+
triggers: {
|
|
92
|
+
m: "getTriggers",
|
|
93
|
+
i: "Trigger",
|
|
94
|
+
},
|
|
95
|
+
observers: {
|
|
96
|
+
m: "getObservers",
|
|
97
|
+
i: "Observer",
|
|
98
|
+
},
|
|
99
|
+
validators: {
|
|
100
|
+
m: "getValidators",
|
|
101
|
+
i: "Validator",
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
function getConversionInfo(mm) {
|
|
105
|
+
if (mm.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const text = mm.name.escapedText;
|
|
109
|
+
const v = m[text];
|
|
110
|
+
if (v === undefined) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
text,
|
|
115
|
+
method: v.m,
|
|
116
|
+
interface: v.i,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function transformRelative(file, importPath, relative) {
|
|
120
|
+
if (!relative || !importPath.startsWith("src")) {
|
|
121
|
+
return importPath;
|
|
122
|
+
}
|
|
123
|
+
const fileFullPath = path.join(process.cwd(), file);
|
|
124
|
+
const impFullPath = path.join(process.cwd(), importPath);
|
|
125
|
+
// relative path is from directory
|
|
126
|
+
return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
|
|
127
|
+
}
|
|
128
|
+
function normalizePath(p) {
|
|
129
|
+
if (p.endsWith("..")) {
|
|
130
|
+
return p + "/";
|
|
131
|
+
}
|
|
132
|
+
return p;
|
|
133
|
+
}
|
|
134
|
+
class TransformAction {
|
|
135
|
+
constructor() {
|
|
136
|
+
this.glob = "src/ent/**/actions/**/*_action.ts";
|
|
137
|
+
this.prettierGlob = "src/ent/**/actions/**.ts";
|
|
138
|
+
this.customInfo = getCustomInfo();
|
|
139
|
+
}
|
|
140
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
141
|
+
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
142
|
+
return { node };
|
|
143
|
+
}
|
|
144
|
+
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
145
|
+
// only do classes
|
|
146
|
+
if (!classInfo || !classInfo.default) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// require action
|
|
150
|
+
const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
|
|
151
|
+
const action = new p.default(new viewer_1.LoggedOutViewer(), {});
|
|
152
|
+
const builder = action.builder.constructor.name;
|
|
153
|
+
const nodeName = action.builder.ent.name;
|
|
154
|
+
const existingEnt = action.builder.operation === action_1.WriteOperation.Insert
|
|
155
|
+
? `${nodeName} | null`
|
|
156
|
+
: nodeName;
|
|
157
|
+
const viewer = this.customInfo.viewerInfo.name;
|
|
158
|
+
const input = findInput(file, classInfo, sourceFile);
|
|
159
|
+
if (!input) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
let klassContents = "";
|
|
163
|
+
let traversed = false;
|
|
164
|
+
let newImports = [];
|
|
165
|
+
for (const mm of node.members) {
|
|
166
|
+
const conv = getConversionInfo(mm);
|
|
167
|
+
if (conv !== null) {
|
|
168
|
+
const property = mm;
|
|
169
|
+
// if invalid, bounce
|
|
170
|
+
if (!property.initializer) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
traversed = true;
|
|
174
|
+
const pp = property.initializer.getFullText(sourceFile).trim();
|
|
175
|
+
const code = `${conv.method}(): ${conv.interface}<${nodeName}, ${builder}<${input}, ${existingEnt}>, ${viewer}, ${input}, ${existingEnt}>[] {
|
|
176
|
+
return ${pp}
|
|
177
|
+
}`;
|
|
178
|
+
newImports.push(conv.interface);
|
|
179
|
+
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
klassContents += mm.getFullText(sourceFile);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
let imports = new Map([
|
|
186
|
+
[
|
|
187
|
+
transformRelative(file, this.customInfo.viewerInfo.path, this.customInfo.relativeImports),
|
|
188
|
+
[viewer],
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
transformRelative(file, "src/ent", this.customInfo.relativeImports),
|
|
192
|
+
[nodeName],
|
|
193
|
+
],
|
|
194
|
+
["@snowtop/ent/action", newImports],
|
|
195
|
+
]);
|
|
196
|
+
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
197
|
+
return {
|
|
198
|
+
rawString: classInfo.wrapClassContents(klassContents),
|
|
199
|
+
traversed,
|
|
200
|
+
imports,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
export declare class TransformSchema implements TransformFile {
|
|
4
|
+
glob: string;
|
|
5
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
6
|
+
node: ts.Node;
|
|
7
|
+
traversed?: undefined;
|
|
8
|
+
rawString?: undefined;
|
|
9
|
+
removeImports?: undefined;
|
|
10
|
+
imports?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
traversed: boolean;
|
|
13
|
+
rawString: string;
|
|
14
|
+
removeImports: string[];
|
|
15
|
+
imports: Map<string, string[]>;
|
|
16
|
+
node?: undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
fileToWrite(file: string): string;
|
|
19
|
+
postProcess(file: string): void;
|
|
20
|
+
prettierGlob: string;
|
|
21
|
+
}
|