@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90
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 +36 -31
- package/action/action.js +2 -6
- package/action/executor.d.ts +3 -3
- 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 +38 -16
- package/action/orchestrator.js +219 -61
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +45 -24
- package/core/base.js +7 -1
- package/core/clause.d.ts +68 -7
- package/core/clause.js +291 -62
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +2 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +79 -24
- package/core/ent.js +520 -168
- 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 +2 -2
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +62 -58
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +47 -10
- 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 +21 -25
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_clause_query.d.ts +24 -0
- package/core/query/custom_clause_query.js +72 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +77 -10
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +1 -1
- package/core/query/query.js +8 -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 +211 -30
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +6 -0
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/index.d.ts +11 -5
- package/index.js +15 -6
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +12 -3
- package/parse_schema/parse.js +70 -11
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +44 -8
- package/schema/field.js +125 -9
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +65 -11
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +44 -5
- package/scripts/custom_graphql.js +8 -3
- 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 +15 -4
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +83 -29
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +70 -16
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/fake_data/fake_contact.d.ts +5 -4
- package/testutils/fake_data/fake_contact.js +14 -6
- package/testutils/fake_data/fake_event.d.ts +5 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +8 -6
- package/testutils/fake_data/user_query.d.ts +8 -6
- package/testutils/fake_data/user_query.js +28 -21
- 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 +29 -7
- 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 -445
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const glob_1 = require("glob");
|
|
26
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
function getTarget(target) {
|
|
32
|
-
switch (target.toLowerCase()) {
|
|
33
|
-
case "es2015":
|
|
34
|
-
return typescript_1.default.ScriptTarget.ES2015;
|
|
35
|
-
case "es2016":
|
|
36
|
-
return typescript_1.default.ScriptTarget.ES2016;
|
|
37
|
-
case "es2017":
|
|
38
|
-
return typescript_1.default.ScriptTarget.ES2017;
|
|
39
|
-
case "es2018":
|
|
40
|
-
return typescript_1.default.ScriptTarget.ES2018;
|
|
41
|
-
case "es2019":
|
|
42
|
-
return typescript_1.default.ScriptTarget.ES2019;
|
|
43
|
-
case "es2020":
|
|
44
|
-
return typescript_1.default.ScriptTarget.ES2020;
|
|
45
|
-
case "es2021":
|
|
46
|
-
return typescript_1.default.ScriptTarget.ES2021;
|
|
47
|
-
case "es3":
|
|
48
|
-
return typescript_1.default.ScriptTarget.ES3;
|
|
49
|
-
case "es5":
|
|
50
|
-
return typescript_1.default.ScriptTarget.ES5;
|
|
51
|
-
case "esnext":
|
|
52
|
-
return typescript_1.default.ScriptTarget.ESNext;
|
|
53
|
-
default:
|
|
54
|
-
return typescript_1.default.ScriptTarget.ESNext;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function main() {
|
|
58
|
-
// this assumes this is being run from root of directory
|
|
59
|
-
const options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
60
|
-
let files = glob_1.glob.sync("src/schema/*.ts");
|
|
61
|
-
const target = options.target
|
|
62
|
-
? // @ts-ignore
|
|
63
|
-
getTarget(options.target)
|
|
64
|
-
: typescript_1.default.ScriptTarget.ESNext;
|
|
65
|
-
// filter to only event.ts e.g. for comments and whitespace...
|
|
66
|
-
// files = files.filter((f) => f.endsWith("event.ts"));
|
|
67
|
-
files.forEach((file) => {
|
|
68
|
-
// assume valid file since we do glob above
|
|
69
|
-
// const idx = file.lastIndexOf(".ts");
|
|
70
|
-
// const writeFile = file.substring(0, idx) + "2" + ".ts";
|
|
71
|
-
// console.debug(file);
|
|
72
|
-
const writeFile = "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
73
|
-
// const writeFile = file;
|
|
74
|
-
// console.debug(file, writeFile);
|
|
75
|
-
let contents = fs.readFileSync(file).toString();
|
|
76
|
-
// go through the file and print everything back if not starting immediately after other position
|
|
77
|
-
const sourceFile = typescript_1.default.createSourceFile(file, contents, target, false, typescript_1.default.ScriptKind.TS);
|
|
78
|
-
const nodes = [];
|
|
79
|
-
let updateImport = false;
|
|
80
|
-
let removeImports = [];
|
|
81
|
-
const f = {
|
|
82
|
-
trackNode: function (tni) {
|
|
83
|
-
nodes.push({
|
|
84
|
-
node: tni.node,
|
|
85
|
-
importNode: tni.node && typescript_1.default.isImportDeclaration(tni.node),
|
|
86
|
-
rawString: tni.rawString,
|
|
87
|
-
});
|
|
88
|
-
if (tni.removeImports) {
|
|
89
|
-
removeImports.push(...tni.removeImports);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
flagUpdateImport() {
|
|
93
|
-
updateImport = true;
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
if (!traverse(contents, sourceFile, f)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
let newContents = "";
|
|
100
|
-
for (const node of nodes) {
|
|
101
|
-
if (updateImport && node.importNode) {
|
|
102
|
-
const importNode = node.node;
|
|
103
|
-
const transformedImport = transformImport(importNode, sourceFile, removeImports);
|
|
104
|
-
if (transformedImport) {
|
|
105
|
-
newContents += transformedImport;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (node.node) {
|
|
110
|
-
newContents += node.node.getFullText(sourceFile);
|
|
111
|
-
}
|
|
112
|
-
else if (node.rawString) {
|
|
113
|
-
newContents += node.rawString;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
console.error("invalid node");
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// console.debug(newContents);
|
|
120
|
-
// ideally there's a flag that indicates if we write
|
|
121
|
-
fs.writeFileSync(writeFile, newContents);
|
|
122
|
-
fs.rmSync(file);
|
|
123
|
-
});
|
|
124
|
-
(0, child_process_1.execSync)("prettier src/schema/*.ts --write");
|
|
125
|
-
}
|
|
126
|
-
function traverse(fileContents, sourceFile, f) {
|
|
127
|
-
let traversed = false;
|
|
128
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
129
|
-
if (typescript_1.default.isClassDeclaration(node)) {
|
|
130
|
-
traversed = true;
|
|
131
|
-
// TODO address implicit schema doesn't work here...
|
|
132
|
-
// console.debug(sourceFile.fileName, node.kind);
|
|
133
|
-
if (traverseClass(fileContents, sourceFile, node, f)) {
|
|
134
|
-
f.flagUpdateImport();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
f.trackNode({ node });
|
|
139
|
-
});
|
|
140
|
-
return traversed;
|
|
141
|
-
}
|
|
142
|
-
function traverseClass(fileContents, sourceFile, node, f) {
|
|
143
|
-
const ci = getClassInfo(fileContents, sourceFile, node);
|
|
144
|
-
if (!ci) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
let klassContents = `${ci.comment}const ${ci.name} = new ${ci.class}({\n`;
|
|
148
|
-
let removeImports = [];
|
|
149
|
-
if (ci.implementsSchema) {
|
|
150
|
-
removeImports.push("Schema");
|
|
151
|
-
}
|
|
152
|
-
for (let member of node.members) {
|
|
153
|
-
const fInfo = getClassElementInfo(fileContents, member, sourceFile);
|
|
154
|
-
if (!fInfo) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
klassContents += `${fInfo.comment}${fInfo.key}:${fInfo.value},\n`;
|
|
158
|
-
if (fInfo.type) {
|
|
159
|
-
removeImports.push(fInfo.type);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
klassContents += "\n})";
|
|
163
|
-
if (ci.export && ci.default) {
|
|
164
|
-
klassContents += `\n export default ${ci.name};`;
|
|
165
|
-
}
|
|
166
|
-
else if (ci.export) {
|
|
167
|
-
klassContents = "export " + klassContents;
|
|
168
|
-
}
|
|
169
|
-
// console.debug(klassContents);
|
|
170
|
-
f.trackNode({ rawString: klassContents, removeImports: removeImports });
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
function transformSchema(str) {
|
|
174
|
-
// only do known class names
|
|
175
|
-
if (str === "BaseEntSchema" || str === "BaseEntSchemaWithTZ") {
|
|
176
|
-
return str.substring(4);
|
|
177
|
-
}
|
|
178
|
-
return str;
|
|
179
|
-
}
|
|
180
|
-
function getClassInfo(fileContents, sourceFile, node) {
|
|
181
|
-
let className = node.name?.text;
|
|
182
|
-
if (!className?.endsWith("Schema")) {
|
|
183
|
-
className += "Schema";
|
|
184
|
-
}
|
|
185
|
-
let classExtends;
|
|
186
|
-
let implementsSchema = false;
|
|
187
|
-
if (node.heritageClauses) {
|
|
188
|
-
for (const hc of node.heritageClauses) {
|
|
189
|
-
if (hc.token === typescript_1.default.SyntaxKind.ImplementsKeyword) {
|
|
190
|
-
for (const type of hc.types) {
|
|
191
|
-
if (type.expression.getText(sourceFile) === "Schema") {
|
|
192
|
-
implementsSchema = true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
// ts.SyntaxKind.ExtendsKeyword
|
|
198
|
-
// can only extend one class
|
|
199
|
-
for (const type of hc.types) {
|
|
200
|
-
const text = type.expression.getText(sourceFile);
|
|
201
|
-
const transformed = transformSchema(text);
|
|
202
|
-
if (transformed === text) {
|
|
203
|
-
return undefined;
|
|
204
|
-
}
|
|
205
|
-
classExtends = transformed;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (!className || !node.heritageClauses || !classExtends) {
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
let ci = {
|
|
213
|
-
name: className,
|
|
214
|
-
class: classExtends,
|
|
215
|
-
comment: getPreText(fileContents, node, sourceFile),
|
|
216
|
-
implementsSchema,
|
|
217
|
-
};
|
|
218
|
-
if (node.modifiers) {
|
|
219
|
-
for (const mod of node.modifiers) {
|
|
220
|
-
const text = mod.getText(sourceFile);
|
|
221
|
-
if (text === "export") {
|
|
222
|
-
ci.export = true;
|
|
223
|
-
}
|
|
224
|
-
else if (text === "default") {
|
|
225
|
-
ci.default = true;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return ci;
|
|
230
|
-
}
|
|
231
|
-
// intentionally doesn't parse decorators since we don't need it
|
|
232
|
-
function getClassElementInfo(fileContents, member, sourceFile) {
|
|
233
|
-
if (isFieldElement(member, sourceFile)) {
|
|
234
|
-
return getFieldElementInfo(fileContents, member, sourceFile);
|
|
235
|
-
}
|
|
236
|
-
if (member.kind === typescript_1.default.SyntaxKind.Constructor) {
|
|
237
|
-
return getConstructorElementInfo(fileContents, member, sourceFile);
|
|
238
|
-
}
|
|
239
|
-
if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
// other properties
|
|
243
|
-
const property = member;
|
|
244
|
-
if (!property.initializer) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const token = property.name;
|
|
248
|
-
return {
|
|
249
|
-
key: token.escapedText.toString(),
|
|
250
|
-
value: property.initializer?.getFullText(sourceFile),
|
|
251
|
-
comment: getPreText(fileContents, member, sourceFile),
|
|
252
|
-
type: getType(property, sourceFile),
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
function getType(property, sourceFile) {
|
|
256
|
-
let propertytype = property.type?.getText(sourceFile) || "";
|
|
257
|
-
let ends = ["| null", "[]"];
|
|
258
|
-
for (const end of ends) {
|
|
259
|
-
if (propertytype.endsWith(end)) {
|
|
260
|
-
propertytype = propertytype.slice(0, -1 * end.length);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return propertytype;
|
|
264
|
-
}
|
|
265
|
-
function getFieldElementInfo(fileContents, member, sourceFile) {
|
|
266
|
-
let fieldMap = "";
|
|
267
|
-
// need to change to fields: {code: StringType()};
|
|
268
|
-
const property = member;
|
|
269
|
-
const initializer = property.initializer;
|
|
270
|
-
fieldMap += "{";
|
|
271
|
-
for (const element of initializer.elements) {
|
|
272
|
-
const parsed = parseFieldElement(element, sourceFile, fileContents);
|
|
273
|
-
if (parsed === null) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const { callEx, name, nameComment, properties } = parsed;
|
|
277
|
-
let property = "";
|
|
278
|
-
const fieldComment = getPreText(fileContents, element, sourceFile).trim();
|
|
279
|
-
if (fieldComment) {
|
|
280
|
-
property += "\n" + fieldComment + "\n";
|
|
281
|
-
}
|
|
282
|
-
if (nameComment) {
|
|
283
|
-
property += nameComment + "\n";
|
|
284
|
-
}
|
|
285
|
-
// e.g. UUIDType, StringType etc
|
|
286
|
-
let call = callEx.expression.getText(sourceFile);
|
|
287
|
-
let fnCall = "";
|
|
288
|
-
if (properties.length) {
|
|
289
|
-
fnCall = `{${properties.join(",")}}`;
|
|
290
|
-
}
|
|
291
|
-
property += `${name}:${call}(${fnCall}),`;
|
|
292
|
-
fieldMap += property;
|
|
293
|
-
}
|
|
294
|
-
fieldMap += "}";
|
|
295
|
-
return {
|
|
296
|
-
key: "fields",
|
|
297
|
-
value: fieldMap,
|
|
298
|
-
comment: getPreText(fileContents, member, sourceFile),
|
|
299
|
-
type: getType(property, sourceFile),
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
function getConstructorElementInfo(fileContents, member, sourceFile) {
|
|
303
|
-
const c = member;
|
|
304
|
-
//remove {}
|
|
305
|
-
let fullText = c.body?.getFullText(sourceFile) || "";
|
|
306
|
-
fullText = fullText.trim().slice(1, -1).trim();
|
|
307
|
-
// convert something like
|
|
308
|
-
/*
|
|
309
|
-
constructor() {
|
|
310
|
-
super();
|
|
311
|
-
this.addPatterns(
|
|
312
|
-
new Feedback(),
|
|
313
|
-
new DayOfWeek(),
|
|
314
|
-
new Feedback(),
|
|
315
|
-
new DayOfWeek(),
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
*/
|
|
319
|
-
// into this.addPatterns(new Feedback(),new DayOfWeek(),new Feedback(),new DayOfWeek(),)
|
|
320
|
-
const lines = fullText
|
|
321
|
-
.split("\n")
|
|
322
|
-
.map((line) => line.trim())
|
|
323
|
-
.join("")
|
|
324
|
-
.split(";")
|
|
325
|
-
.filter((f) => f != "super()" && f != "");
|
|
326
|
-
// at this point there should be only line for what we handle
|
|
327
|
-
if (lines.length != 1) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
const line = lines[0];
|
|
331
|
-
const addPatterns = "this.addPatterns(";
|
|
332
|
-
if (!line.startsWith(addPatterns)) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
key: "patterns",
|
|
337
|
-
// remove this.addPatterns at the front, remove trailing ) at the end
|
|
338
|
-
// if there's a trailing comma, it'll be handled by prettier
|
|
339
|
-
value: `[${line.slice(addPatterns.length, -1)}]`,
|
|
340
|
-
comment: "",
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function isFieldElement(member, sourceFile) {
|
|
344
|
-
if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
const property = member;
|
|
348
|
-
const token = property.name;
|
|
349
|
-
if (token.escapedText !== "fields") {
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
|
-
const propertytype = property.type?.getText(sourceFile);
|
|
353
|
-
if (propertytype !== "Field[]") {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
if (property.initializer?.kind !== typescript_1.default.SyntaxKind.ArrayLiteralExpression) {
|
|
357
|
-
console.error("invalid array type");
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
function parseFieldElement(element, sourceFile, fileContents) {
|
|
363
|
-
if (element.kind !== typescript_1.default.SyntaxKind.CallExpression) {
|
|
364
|
-
console.error("skipped non-call expression");
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
let callEx = element;
|
|
368
|
-
if (callEx.arguments.length !== 1) {
|
|
369
|
-
console.error("callExpression with arguments not of length 1");
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
let arg = callEx.arguments[0];
|
|
373
|
-
if (arg.kind !== typescript_1.default.SyntaxKind.ObjectLiteralExpression) {
|
|
374
|
-
console.error("not objectLiteralExpression");
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
let expr = arg;
|
|
378
|
-
let name = "";
|
|
379
|
-
let propertyComment;
|
|
380
|
-
let properties = [];
|
|
381
|
-
for (const p of expr.properties) {
|
|
382
|
-
const p2 = p;
|
|
383
|
-
// found name property
|
|
384
|
-
if (p2.name.escapedText === "name") {
|
|
385
|
-
name = p2.initializer.getText(sourceFile);
|
|
386
|
-
// check for any comment associated with name: "fooo"
|
|
387
|
-
propertyComment = getPreText(fileContents, p, sourceFile).trim();
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
properties.push(p.getFullText(sourceFile));
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
if (!name) {
|
|
394
|
-
console.error(`couldn't find name property`);
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
// remove quotes
|
|
398
|
-
name = name.slice(1, -1);
|
|
399
|
-
return {
|
|
400
|
-
callEx,
|
|
401
|
-
name,
|
|
402
|
-
properties,
|
|
403
|
-
nameComment: propertyComment,
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
function transformImport(importNode, sourceFile, removeImports) {
|
|
407
|
-
// remove quotes too
|
|
408
|
-
const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
409
|
-
if (text !== "@snowtop/ent" &&
|
|
410
|
-
text !== "@snowtop/ent/schema" &&
|
|
411
|
-
text !== "@snowtop/ent/schema/") {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
const importText = importNode.importClause?.getText(sourceFile) || "";
|
|
415
|
-
const start = importText.indexOf("{");
|
|
416
|
-
const end = importText.lastIndexOf("}");
|
|
417
|
-
if (start === -1 || end === -1) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
const imports = importText
|
|
421
|
-
.substring(start + 1, end)
|
|
422
|
-
// .trim()
|
|
423
|
-
.split(",");
|
|
424
|
-
let removeImportsMap = {};
|
|
425
|
-
removeImports.forEach((imp) => (removeImportsMap[imp] = true));
|
|
426
|
-
let newImports = [];
|
|
427
|
-
for (let i = 0; i < imports.length; i++) {
|
|
428
|
-
let imp = transformSchema(imports[i].trim());
|
|
429
|
-
if (removeImportsMap[imp]) {
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
|
-
newImports.push(imp);
|
|
433
|
-
}
|
|
434
|
-
return ("import " +
|
|
435
|
-
importText.substring(0, start + 1) +
|
|
436
|
-
newImports.join(", ") +
|
|
437
|
-
importText.substring(end) +
|
|
438
|
-
' from "' +
|
|
439
|
-
text +
|
|
440
|
-
'";');
|
|
441
|
-
}
|
|
442
|
-
function getPreText(fileContents, node, sourceFile) {
|
|
443
|
-
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
444
|
-
}
|
|
445
|
-
Promise.resolve(main());
|