@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101
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 +37 -31
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +40 -16
- package/action/orchestrator.js +230 -62
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +49 -26
- package/core/base.js +7 -1
- package/core/clause.d.ts +88 -7
- package/core/clause.js +355 -63
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +81 -25
- package/core/ent.js +636 -193
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- 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 +67 -59
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -24
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +14 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +1 -4
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +12 -5
- package/index.js +20 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +29 -9
- package/parse_schema/parse.js +118 -11
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +5 -0
- package/schema/field.d.ts +74 -20
- package/schema/field.js +174 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +81 -18
- package/schema/schema.js +24 -17
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +57 -21
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +117 -30
- package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +46 -47
- package/testutils/builder.js +108 -65
- 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} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +179 -44
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +27 -8
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +7 -3
- package/testutils/fake_data/fake_contact.js +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +7 -4
- package/testutils/fake_data/fake_user.js +18 -16
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +28 -12
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- 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 +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +26 -2
- package/tsc/ast.js +163 -17
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +11 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -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/{scripts → tsc}/transform_schema.js +145 -119
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_code.js +0 -114
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,111 +26,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
|
|
29
|
+
exports.TransformSchema = void 0;
|
|
26
30
|
const typescript_1 = __importDefault(require("typescript"));
|
|
27
31
|
const fs = __importStar(require("fs"));
|
|
28
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
32
|
const path_1 = __importDefault(require("path"));
|
|
31
33
|
const ast_1 = require("../tsc/ast");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
35
|
-
let files = glob_1.glob.sync("src/schema/*.ts");
|
|
36
|
-
const target = (0, compilerOptions_1.getTarget)(options.target?.toString());
|
|
37
|
-
// filter to only event.ts e.g. for comments and whitespace...
|
|
38
|
-
// files = files.filter((f) => f.endsWith("event.ts"));
|
|
39
|
-
files.forEach((file) => {
|
|
40
|
-
// assume valid file since we do glob above
|
|
41
|
-
// const idx = file.lastIndexOf(".ts");
|
|
42
|
-
// const writeFile = file.substring(0, idx) + "2" + ".ts";
|
|
43
|
-
// console.debug(file);
|
|
44
|
-
const writeFile = "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
45
|
-
// const writeFile = file;
|
|
46
|
-
// console.debug(file, writeFile);
|
|
47
|
-
// go through the file and print everything back if not starting immediately after other position
|
|
48
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
49
|
-
const nodes = [];
|
|
50
|
-
let updateImport = false;
|
|
51
|
-
let removeImports = [];
|
|
52
|
-
const f = {
|
|
53
|
-
trackNode: function (tni) {
|
|
54
|
-
nodes.push({
|
|
55
|
-
node: tni.node,
|
|
56
|
-
importNode: tni.node && typescript_1.default.isImportDeclaration(tni.node),
|
|
57
|
-
rawString: tni.rawString,
|
|
58
|
-
});
|
|
59
|
-
if (tni.removeImports) {
|
|
60
|
-
removeImports.push(...tni.removeImports);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
flagUpdateImport() {
|
|
64
|
-
updateImport = true;
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
if (!traverse(contents, sourceFile, f)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
let newContents = "";
|
|
71
|
-
for (const node of nodes) {
|
|
72
|
-
if (updateImport && node.importNode) {
|
|
73
|
-
const importNode = node.node;
|
|
74
|
-
const transformedImport = (0, ast_1.transformImport)(contents, importNode, sourceFile, {
|
|
75
|
-
removeImports,
|
|
76
|
-
transform: transformSchema,
|
|
77
|
-
});
|
|
78
|
-
if (transformedImport) {
|
|
79
|
-
newContents += transformedImport;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (node.node) {
|
|
84
|
-
newContents += node.node.getFullText(sourceFile);
|
|
85
|
-
}
|
|
86
|
-
else if (node.rawString) {
|
|
87
|
-
newContents += node.rawString;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
console.error("invalid node");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// console.debug(newContents);
|
|
94
|
-
// ideally there's a flag that indicates if we write
|
|
95
|
-
fs.writeFileSync(writeFile, newContents);
|
|
96
|
-
fs.rmSync(file);
|
|
97
|
-
});
|
|
98
|
-
(0, child_process_1.execSync)("prettier src/schema/*.ts --write");
|
|
99
|
-
}
|
|
100
|
-
function traverse(fileContents, sourceFile, f) {
|
|
101
|
-
let traversed = false;
|
|
102
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
103
|
-
if (typescript_1.default.isClassDeclaration(node)) {
|
|
104
|
-
traversed = true;
|
|
105
|
-
// TODO address implicit schema doesn't work here...
|
|
106
|
-
// console.debug(sourceFile.fileName, node.kind);
|
|
107
|
-
if (traverseClass(fileContents, sourceFile, node, f)) {
|
|
108
|
-
f.flagUpdateImport();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
f.trackNode({ node });
|
|
113
|
-
});
|
|
114
|
-
return traversed;
|
|
115
|
-
}
|
|
116
|
-
function traverseClass(fileContents, sourceFile, node, f) {
|
|
117
|
-
const ci = getTransformClassInfo(fileContents, sourceFile, node);
|
|
34
|
+
function traverseClass(fileContents, sourceFile, node, transformSchema) {
|
|
35
|
+
const ci = getTransformClassInfo(fileContents, sourceFile, node, transformSchema);
|
|
118
36
|
if (!ci) {
|
|
119
|
-
return
|
|
37
|
+
return;
|
|
120
38
|
}
|
|
121
|
-
let klassContents = `${ci.comment}const ${ci.name} = new ${ci.class}({\n`;
|
|
39
|
+
let klassContents = `${ci.comment}const ${ci.name} = new ${transformSchema(ci.class)}({\n`;
|
|
122
40
|
let removeImports = [];
|
|
123
41
|
if (ci.implementsSchema) {
|
|
124
42
|
removeImports.push("Schema");
|
|
125
43
|
}
|
|
44
|
+
removeImports.push(ci.class);
|
|
45
|
+
let newImports = [transformSchema(ci.class)];
|
|
126
46
|
for (let member of node.members) {
|
|
127
47
|
const fInfo = getClassElementInfo(fileContents, member, sourceFile);
|
|
128
48
|
if (!fInfo) {
|
|
129
|
-
return
|
|
49
|
+
return;
|
|
130
50
|
}
|
|
131
51
|
klassContents += `${fInfo.comment}${fInfo.key}:${fInfo.value},\n`;
|
|
132
52
|
if (fInfo.type) {
|
|
@@ -141,20 +61,13 @@ function traverseClass(fileContents, sourceFile, node, f) {
|
|
|
141
61
|
klassContents = "export " + klassContents;
|
|
142
62
|
}
|
|
143
63
|
// console.debug(klassContents);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (str === "BaseEntSchema" || str === "BaseEntSchemaWithTZ") {
|
|
150
|
-
return str.substring(4);
|
|
151
|
-
}
|
|
152
|
-
return str;
|
|
64
|
+
return {
|
|
65
|
+
rawString: klassContents,
|
|
66
|
+
removeImports: removeImports,
|
|
67
|
+
newImports,
|
|
68
|
+
};
|
|
153
69
|
}
|
|
154
|
-
|
|
155
|
-
// and then have a schema specific version
|
|
156
|
-
// may make sense to just duplicate this logic...
|
|
157
|
-
function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
70
|
+
function getTransformClassInfo(fileContents, sourceFile, node, transformSchema) {
|
|
158
71
|
const generic = (0, ast_1.getClassInfo)(fileContents, sourceFile, node);
|
|
159
72
|
if (!generic) {
|
|
160
73
|
return;
|
|
@@ -165,6 +78,7 @@ function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
|
165
78
|
}
|
|
166
79
|
let implementsSchema = generic.implements?.some((v) => v == "Schema");
|
|
167
80
|
let classExtends = generic.extends;
|
|
81
|
+
// nothing transformed here, so nothing to do here
|
|
168
82
|
if (classExtends && classExtends === transformSchema(classExtends)) {
|
|
169
83
|
return undefined;
|
|
170
84
|
}
|
|
@@ -181,7 +95,7 @@ function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
|
181
95
|
}
|
|
182
96
|
// intentionally doesn't parse decorators since we don't need it
|
|
183
97
|
function getClassElementInfo(fileContents, member, sourceFile) {
|
|
184
|
-
if (isFieldElement(member, sourceFile)) {
|
|
98
|
+
if (isFieldElement(fileContents, member, sourceFile)) {
|
|
185
99
|
return getFieldElementInfo(fileContents, member, sourceFile);
|
|
186
100
|
}
|
|
187
101
|
if (member.kind === typescript_1.default.SyntaxKind.Constructor) {
|
|
@@ -224,7 +138,7 @@ function getFieldElementInfo(fileContents, member, sourceFile) {
|
|
|
224
138
|
if (parsed === null) {
|
|
225
139
|
return;
|
|
226
140
|
}
|
|
227
|
-
const { callEx, name, nameComment, properties } = parsed;
|
|
141
|
+
const { callEx, name, nameComment, properties, suffix } = parsed;
|
|
228
142
|
let property = "";
|
|
229
143
|
const fieldComment = (0, ast_1.getPreText)(fileContents, element, sourceFile).trim();
|
|
230
144
|
if (fieldComment) {
|
|
@@ -239,7 +153,7 @@ function getFieldElementInfo(fileContents, member, sourceFile) {
|
|
|
239
153
|
if (properties.length) {
|
|
240
154
|
fnCall = `{${properties.join(",")}}`;
|
|
241
155
|
}
|
|
242
|
-
property += `${name}:${call}(${fnCall}),`;
|
|
156
|
+
property += `${name}:${call}(${fnCall})${suffix || ""},`;
|
|
243
157
|
fieldMap += property;
|
|
244
158
|
}
|
|
245
159
|
fieldMap += "}";
|
|
@@ -291,7 +205,7 @@ function getConstructorElementInfo(fileContents, member, sourceFile) {
|
|
|
291
205
|
comment: "",
|
|
292
206
|
};
|
|
293
207
|
}
|
|
294
|
-
function isFieldElement(member, sourceFile) {
|
|
208
|
+
function isFieldElement(fileContents, member, sourceFile) {
|
|
295
209
|
if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
296
210
|
return false;
|
|
297
211
|
}
|
|
@@ -305,24 +219,60 @@ function isFieldElement(member, sourceFile) {
|
|
|
305
219
|
return false;
|
|
306
220
|
}
|
|
307
221
|
if (property.initializer?.kind !== typescript_1.default.SyntaxKind.ArrayLiteralExpression) {
|
|
308
|
-
|
|
222
|
+
throwErr(fileContents, member, "invalid array type");
|
|
309
223
|
return false;
|
|
310
224
|
}
|
|
311
225
|
return true;
|
|
312
226
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
227
|
+
// if there's an error transforming any of the schemas, we should stop...
|
|
228
|
+
function throwErr(fileContents, node, error) {
|
|
229
|
+
console.error(error);
|
|
230
|
+
throw new Error(`error transforming this field ${fileContents.substring(node.getFullStart(), node.getEnd())}`);
|
|
231
|
+
}
|
|
232
|
+
function parseFieldElement(element, sourceFile, fileContents, nested) {
|
|
233
|
+
if (element.kind !== typescript_1.default.SyntaxKind.CallExpression &&
|
|
234
|
+
element.kind !== typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
235
|
+
throwErr(fileContents, element, `skipped unknown (non-call|non-property) expression ${element.kind}`);
|
|
316
236
|
return null;
|
|
317
237
|
}
|
|
238
|
+
if (element.kind === typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
239
|
+
const ret = parseFieldElement(element.expression, sourceFile, fileContents, true);
|
|
240
|
+
if (ret !== null) {
|
|
241
|
+
if (!nested) {
|
|
242
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), element.getEnd());
|
|
243
|
+
}
|
|
244
|
+
return ret;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
318
247
|
let callEx = element;
|
|
319
248
|
if (callEx.arguments.length !== 1) {
|
|
320
|
-
|
|
321
|
-
|
|
249
|
+
// have a situation like: StringType({ name: "canonicalName" }).trim().toLowerCase(),
|
|
250
|
+
// need to keep calling this until we find what we want and then get the suffix we should just add to the end of the transformed code
|
|
251
|
+
if (callEx.expression.kind === typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
252
|
+
const ret = parseFieldElement(callEx.expression.expression, sourceFile, fileContents, true);
|
|
253
|
+
if (ret !== null) {
|
|
254
|
+
if (!nested) {
|
|
255
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), callEx.getEnd());
|
|
256
|
+
}
|
|
257
|
+
return ret;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
throwErr(fileContents, element, "callExpression with arguments not of length 1");
|
|
322
261
|
}
|
|
323
262
|
let arg = callEx.arguments[0];
|
|
324
263
|
if (arg.kind !== typescript_1.default.SyntaxKind.ObjectLiteralExpression) {
|
|
325
|
-
|
|
264
|
+
// this and the check above for PropertyAccessExpression are to handle things like
|
|
265
|
+
// FooType({
|
|
266
|
+
/// ...
|
|
267
|
+
// }).function(blah)
|
|
268
|
+
const ret = parseFieldElement(callEx.expression, sourceFile, fileContents, true);
|
|
269
|
+
if (ret !== null) {
|
|
270
|
+
if (!nested) {
|
|
271
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), callEx.getEnd());
|
|
272
|
+
}
|
|
273
|
+
return ret;
|
|
274
|
+
}
|
|
275
|
+
throwErr(fileContents, element, `not objectLiteralExpression. kind ${arg.kind}`);
|
|
326
276
|
return null;
|
|
327
277
|
}
|
|
328
278
|
let expr = arg;
|
|
@@ -342,7 +292,7 @@ function parseFieldElement(element, sourceFile, fileContents) {
|
|
|
342
292
|
}
|
|
343
293
|
}
|
|
344
294
|
if (!name) {
|
|
345
|
-
|
|
295
|
+
throwErr(fileContents, element, `couldn't find name property`);
|
|
346
296
|
return null;
|
|
347
297
|
}
|
|
348
298
|
// remove quotes
|
|
@@ -354,4 +304,80 @@ function parseFieldElement(element, sourceFile, fileContents) {
|
|
|
354
304
|
nameComment: propertyComment,
|
|
355
305
|
};
|
|
356
306
|
}
|
|
357
|
-
|
|
307
|
+
// find which of these importPaths is being used and use that to replace
|
|
308
|
+
function findSchemaImportPath(sourceFile) {
|
|
309
|
+
const paths = {
|
|
310
|
+
"@snowtop/ent": true,
|
|
311
|
+
"@snowtop/ent/schema": true,
|
|
312
|
+
"@snowtop/ent/schema/": true,
|
|
313
|
+
};
|
|
314
|
+
// @ts-ignore
|
|
315
|
+
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
316
|
+
for (const imp of importStatements) {
|
|
317
|
+
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
318
|
+
if (!impInfo) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (paths[impInfo.importPath] !== undefined) {
|
|
322
|
+
return impInfo.importPath;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class TransformSchema {
|
|
327
|
+
// we only end up doing this once because we change the schema representation
|
|
328
|
+
// so safe to run this multiple times
|
|
329
|
+
constructor(relativeImports, oldBaseClass, newSchemaClass, transformPath) {
|
|
330
|
+
this.relativeImports = relativeImports;
|
|
331
|
+
this.oldBaseClass = oldBaseClass;
|
|
332
|
+
this.newSchemaClass = newSchemaClass;
|
|
333
|
+
this.transformPath = transformPath;
|
|
334
|
+
this.glob = "src/schema/*.ts";
|
|
335
|
+
this.prettierGlob = "src/schema/*.ts";
|
|
336
|
+
}
|
|
337
|
+
transformSchema(className) {
|
|
338
|
+
if (className === "BaseEntSchema" || className === "BaseEntSchemaWithTZ") {
|
|
339
|
+
return className.substring(4);
|
|
340
|
+
}
|
|
341
|
+
if (className === this.oldBaseClass && this.newSchemaClass) {
|
|
342
|
+
return this.newSchemaClass;
|
|
343
|
+
}
|
|
344
|
+
return className;
|
|
345
|
+
}
|
|
346
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
347
|
+
if (!typescript_1.default.isClassDeclaration(node)) {
|
|
348
|
+
return { node };
|
|
349
|
+
}
|
|
350
|
+
// TODO address implicit schema doesn't work here...
|
|
351
|
+
const ret = traverseClass(contents, sourceFile, node, this.transformSchema.bind(this));
|
|
352
|
+
if (ret === undefined) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
let imports = new Map();
|
|
356
|
+
const imp = findSchemaImportPath(sourceFile);
|
|
357
|
+
if (imp) {
|
|
358
|
+
if (this.transformPath) {
|
|
359
|
+
imports.set(imp, []);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
imports.set(imp, ret.newImports);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (this.transformPath) {
|
|
366
|
+
// add new imports to this path
|
|
367
|
+
imports.set((0, ast_1.transformRelative)(file, this.transformPath, this.relativeImports), ret.newImports);
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
traversed: true,
|
|
371
|
+
rawString: ret.rawString,
|
|
372
|
+
removeImports: ret.removeImports,
|
|
373
|
+
imports: imports,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
fileToWrite(file) {
|
|
377
|
+
return "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
378
|
+
}
|
|
379
|
+
postProcess(file) {
|
|
380
|
+
fs.rmSync(file);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.TransformSchema = TransformSchema;
|
package/graphql/enums.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { GraphQLEnumValue } from "graphql";
|
|
2
|
-
export declare function convertToGQLEnum(val: string | null, tsValues: string[], gqlValues: GraphQLEnumValue[]): any;
|
|
3
|
-
export declare function convertFromGQLEnum(val: string, tsValues: string[], gqlValues: GraphQLEnumValue[]): string;
|
package/graphql/enums.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFromGQLEnum = exports.convertToGQLEnum = void 0;
|
|
4
|
-
function convertToGQLEnum(val, tsValues, gqlValues) {
|
|
5
|
-
for (let i = 0; i < tsValues.length; i++) {
|
|
6
|
-
let tsVal = tsValues[i];
|
|
7
|
-
let gqlValue = gqlValues[i];
|
|
8
|
-
if (val === tsVal) {
|
|
9
|
-
return gqlValue.value;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return val;
|
|
13
|
-
}
|
|
14
|
-
exports.convertToGQLEnum = convertToGQLEnum;
|
|
15
|
-
function convertFromGQLEnum(val, tsValues, gqlValues) {
|
|
16
|
-
for (let i = 0; i < tsValues.length; i++) {
|
|
17
|
-
let tsVal = tsValues[i];
|
|
18
|
-
let gqlValue = gqlValues[i];
|
|
19
|
-
if (val === gqlValue.value) {
|
|
20
|
-
return tsVal;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return val;
|
|
24
|
-
}
|
|
25
|
-
exports.convertFromGQLEnum = convertFromGQLEnum;
|
|
@@ -1,114 +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 compilerOptions_1 = require("../tsc/compilerOptions");
|
|
28
|
-
const ast_1 = require("../tsc/ast");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
async function main() {
|
|
32
|
-
const options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
33
|
-
let files = glob_1.glob.sync("src/ent/*.ts");
|
|
34
|
-
const target = (0, compilerOptions_1.getTarget)(options.target?.toString());
|
|
35
|
-
files.forEach((file) => {
|
|
36
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
37
|
-
let traversed = false;
|
|
38
|
-
let nodes = [];
|
|
39
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
40
|
-
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
41
|
-
nodes.push({ node });
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
45
|
-
// only do classes which extend a base class e.g. User extends UserBase
|
|
46
|
-
if (!classInfo || classInfo.extends !== classInfo.name + "Base") {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
// need to check for PrivacyPolicy import...
|
|
50
|
-
traversed = true;
|
|
51
|
-
let klassContents = "";
|
|
52
|
-
for (const mm of node.members) {
|
|
53
|
-
if (isPrivacyPolicy(mm)) {
|
|
54
|
-
const property = mm;
|
|
55
|
-
// if invalid privacy policy, bounce
|
|
56
|
-
if (!property.initializer) {
|
|
57
|
-
traversed = false;
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const pp = property.initializer.getFullText(sourceFile);
|
|
61
|
-
const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
62
|
-
return ${pp}
|
|
63
|
-
}`;
|
|
64
|
-
klassContents += code;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
klassContents += mm.getFullText(sourceFile);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
71
|
-
nodes.push({ rawString: classInfo.wrapClassContents(klassContents) });
|
|
72
|
-
// console.debug(classInfo.wrapClassContents(klassContents));
|
|
73
|
-
});
|
|
74
|
-
// if traversed, overwrite.
|
|
75
|
-
if (!traversed) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
let newContents = "";
|
|
79
|
-
for (const node of nodes) {
|
|
80
|
-
if (node.node) {
|
|
81
|
-
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
82
|
-
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
83
|
-
newImports: ["PrivacyPolicy"],
|
|
84
|
-
});
|
|
85
|
-
if (transformed) {
|
|
86
|
-
newContents += transformed;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
newContents += node.node.getFullText(sourceFile);
|
|
91
|
-
}
|
|
92
|
-
else if (node.rawString) {
|
|
93
|
-
newContents += node.rawString;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
throw new Error(`malformed node with no node or rawString`);
|
|
97
|
-
}
|
|
98
|
-
fs.writeFileSync(file, newContents);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
(0, child_process_1.execSync)("prettier src/ent/*.ts --write");
|
|
102
|
-
}
|
|
103
|
-
function isPrivacyPolicy(mm) {
|
|
104
|
-
return (mm.kind === typescript_1.default.SyntaxKind.PropertyDeclaration &&
|
|
105
|
-
mm.name.escapedText === "privacyPolicy");
|
|
106
|
-
}
|
|
107
|
-
main()
|
|
108
|
-
.then(() => {
|
|
109
|
-
process.exit(0);
|
|
110
|
-
})
|
|
111
|
-
.catch((err) => {
|
|
112
|
-
console.error(err);
|
|
113
|
-
process.exit(1);
|
|
114
|
-
});
|