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