@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha73
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 +35 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +69 -3
- package/core/clause.js +420 -5
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/context.js +2 -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 +62 -27
- package/core/ent.js +272 -63
- 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 +10 -5
- package/core/loaders/object_loader.js +58 -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 +25 -25
- package/core/privacy.js +5 -5
- 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 +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 +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/schema.d.ts +100 -2
- package/schema/schema.js +127 -5
- 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/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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
export declare class TransformSchema implements TransformFile {
|
|
4
|
+
private relativeImports;
|
|
5
|
+
private oldBaseClass?;
|
|
6
|
+
private newSchemaClass?;
|
|
7
|
+
private transformPath?;
|
|
8
|
+
constructor(relativeImports: boolean, oldBaseClass?: string | undefined, newSchemaClass?: string | undefined, transformPath?: string | undefined);
|
|
9
|
+
glob: string;
|
|
10
|
+
private transformSchema;
|
|
11
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
12
|
+
node: ts.Node;
|
|
13
|
+
traversed?: undefined;
|
|
14
|
+
rawString?: undefined;
|
|
15
|
+
removeImports?: undefined;
|
|
16
|
+
imports?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
traversed: boolean;
|
|
19
|
+
rawString: string;
|
|
20
|
+
removeImports: string[];
|
|
21
|
+
imports: Map<string, string[]>;
|
|
22
|
+
node?: undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
fileToWrite(file: string): string;
|
|
25
|
+
postProcess(file: string): void;
|
|
26
|
+
prettierGlob: string;
|
|
27
|
+
}
|