@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test1
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 +25 -14
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +89 -28
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +34 -14
- package/action/index.d.ts +4 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +43 -12
- package/action/orchestrator.js +461 -101
- 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 +56 -23
- package/core/base.js +7 -1
- package/core/clause.d.ts +103 -39
- package/core/clause.js +430 -66
- package/core/config.d.ts +13 -3
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -3
- package/core/context.js +22 -3
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +21 -9
- package/core/ent.d.ts +99 -95
- package/core/ent.js +550 -602
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +5 -2
- package/core/loaders/assoc_count_loader.js +19 -3
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +23 -17
- package/core/loaders/index.d.ts +1 -2
- package/core/loaders/index.js +1 -5
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +4 -21
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +226 -79
- package/core/loaders/query_loader.d.ts +7 -13
- package/core/loaders/query_loader.js +60 -24
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +8 -3
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -16
- package/core/privacy.js +68 -51
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +10 -2
- package/core/query/custom_clause_query.d.ts +29 -0
- package/core/query/custom_clause_query.js +105 -0
- package/core/query/custom_query.d.ts +19 -2
- package/core/query/custom_query.js +111 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +18 -4
- package/core/query/query.js +135 -58
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +186 -55
- package/core/query/shared_test.d.ts +9 -2
- package/core/query/shared_test.js +529 -236
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +108 -22
- package/graphql/graphql.js +183 -137
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -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 +23 -5
- package/index.js +35 -10
- package/package.json +19 -19
- package/parse_schema/parse.d.ts +33 -9
- package/parse_schema/parse.js +182 -33
- 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 +232 -72
- 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 +171 -64
- 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 +37 -41
- package/testutils/builder.js +66 -46
- 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} +251 -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 +31 -19
- 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 +48 -0
- package/testutils/fake_data/test_helpers.d.ts +14 -6
- package/testutils/fake_data/test_helpers.js +31 -15
- package/testutils/fake_data/user_query.d.ts +16 -6
- package/testutils/fake_data/user_query.js +72 -23
- 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 +15 -3
- package/tsc/ast.js +114 -23
- 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/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -141
- package/scripts/transform_actions.js +0 -266
- package/scripts/transform_code.d.ts +0 -1
- package/scripts/transform_code.js +0 -111
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_actions.d.ts → move_types.d.ts} +0 -0
package/tsc/ast.js
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getImportInfo = exports.isRelativeGeneratedImport = exports.isRelativeImport = exports.updateImportPath = exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
|
|
29
|
+
exports.getCustomInfo = exports.transformRelative = exports.getImportInfo = exports.isSrcGeneratedImport = exports.isRelativeGeneratedImport = exports.isRelativeImport = exports.updateImportPath = exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
|
|
7
30
|
const typescript_1 = __importDefault(require("typescript"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const js_yaml_1 = require("js-yaml");
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const const_1 = require("../core/const");
|
|
8
35
|
function getPreText(fileContents, node, sourceFile) {
|
|
9
36
|
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
10
37
|
}
|
|
@@ -31,8 +58,7 @@ function getClassInfo(fileContents, sourceFile, node) {
|
|
|
31
58
|
}
|
|
32
59
|
}
|
|
33
60
|
}
|
|
34
|
-
|
|
35
|
-
if (!className || !node.heritageClauses || !classExtends) {
|
|
61
|
+
if (!className) {
|
|
36
62
|
return undefined;
|
|
37
63
|
}
|
|
38
64
|
let hasExport = false;
|
|
@@ -82,26 +108,22 @@ exports.getClassInfo = getClassInfo;
|
|
|
82
108
|
function transformImport(fileContents, importNode, sourceFile, opts) {
|
|
83
109
|
// remove quotes too
|
|
84
110
|
const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
85
|
-
if (opts
|
|
86
|
-
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
if (text !== "@snowtop/ent" &&
|
|
92
|
-
text !== "@snowtop/ent/schema" &&
|
|
93
|
-
text !== "@snowtop/ent/schema/") {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
111
|
+
if (text != opts.transformPath) {
|
|
112
|
+
return;
|
|
96
113
|
}
|
|
97
114
|
const impInfo = getImportInfo(importNode, sourceFile);
|
|
98
115
|
if (!impInfo) {
|
|
99
116
|
return;
|
|
100
117
|
}
|
|
101
|
-
|
|
118
|
+
let { imports, start, end, importText, default: def } = impInfo;
|
|
102
119
|
let removeImportsMap = {};
|
|
103
120
|
if (opts?.removeImports) {
|
|
104
|
-
opts.removeImports.forEach((imp) =>
|
|
121
|
+
opts.removeImports.forEach((imp) => {
|
|
122
|
+
removeImportsMap[imp] = true;
|
|
123
|
+
if (def === imp) {
|
|
124
|
+
def = "";
|
|
125
|
+
}
|
|
126
|
+
});
|
|
105
127
|
}
|
|
106
128
|
let finalImports = new Set();
|
|
107
129
|
for (let i = 0; i < imports.length; i++) {
|
|
@@ -121,11 +143,18 @@ function transformImport(fileContents, importNode, sourceFile, opts) {
|
|
|
121
143
|
opts.newImports.forEach((imp) => finalImports.add(imp));
|
|
122
144
|
}
|
|
123
145
|
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
146
|
+
if (!finalImports.size) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
124
149
|
return (comment +
|
|
125
150
|
"import " +
|
|
126
|
-
|
|
151
|
+
// add default
|
|
152
|
+
(def || "") +
|
|
153
|
+
// should probably always be "{" now that we support default
|
|
154
|
+
(start >= 0 ? importText.substring(0, start + 1) : "{") +
|
|
127
155
|
Array.from(finalImports).join(", ") +
|
|
128
|
-
|
|
156
|
+
// should probably always be "}"
|
|
157
|
+
(end >= 0 ? importText.substring(end) : "}") +
|
|
129
158
|
' from "' +
|
|
130
159
|
text +
|
|
131
160
|
'";');
|
|
@@ -165,23 +194,85 @@ function isRelativeGeneratedImport(node, sourceFile) {
|
|
|
165
194
|
text.indexOf("/generated") !== -1);
|
|
166
195
|
}
|
|
167
196
|
exports.isRelativeGeneratedImport = isRelativeGeneratedImport;
|
|
197
|
+
function isSrcGeneratedImport(node, sourceFile) {
|
|
198
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
199
|
+
return text.startsWith("src") && text.includes("/generated");
|
|
200
|
+
}
|
|
201
|
+
exports.isSrcGeneratedImport = isSrcGeneratedImport;
|
|
202
|
+
// TODO doesn't support default + {} yet
|
|
168
203
|
function getImportInfo(imp, sourceFile) {
|
|
169
204
|
const importText = imp.importClause?.getText(sourceFile) || "";
|
|
170
205
|
const start = importText.indexOf("{");
|
|
171
206
|
const end = importText.lastIndexOf("}");
|
|
172
207
|
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
173
|
-
if (start === -1 || end === -1) {
|
|
208
|
+
if ((start === -1 || end === -1) && !importText.length) {
|
|
174
209
|
return;
|
|
175
210
|
}
|
|
211
|
+
let imports = [];
|
|
212
|
+
let def;
|
|
213
|
+
if (start !== -1 && end !== -1) {
|
|
214
|
+
imports = importText
|
|
215
|
+
.substring(start + 1, end)
|
|
216
|
+
//.trim()
|
|
217
|
+
.split(",");
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
def = importText;
|
|
221
|
+
}
|
|
176
222
|
return {
|
|
177
223
|
importPath: text,
|
|
178
224
|
importText,
|
|
179
225
|
start,
|
|
180
226
|
end,
|
|
181
|
-
imports
|
|
182
|
-
|
|
183
|
-
//.trim()
|
|
184
|
-
.split(","),
|
|
227
|
+
imports,
|
|
228
|
+
default: def,
|
|
185
229
|
};
|
|
186
230
|
}
|
|
187
231
|
exports.getImportInfo = getImportInfo;
|
|
232
|
+
function transformRelative(file, importPath, relative) {
|
|
233
|
+
if (!relative || !importPath.startsWith("src")) {
|
|
234
|
+
return importPath;
|
|
235
|
+
}
|
|
236
|
+
const fileFullPath = path.join(process.cwd(), file);
|
|
237
|
+
const impFullPath = path.join(process.cwd(), importPath);
|
|
238
|
+
// relative path is from directory
|
|
239
|
+
return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
|
|
240
|
+
}
|
|
241
|
+
exports.transformRelative = transformRelative;
|
|
242
|
+
function normalizePath(p) {
|
|
243
|
+
if (p.endsWith("..")) {
|
|
244
|
+
return p + "/";
|
|
245
|
+
}
|
|
246
|
+
if (!p.startsWith("..")) {
|
|
247
|
+
return "./" + p;
|
|
248
|
+
}
|
|
249
|
+
return p;
|
|
250
|
+
}
|
|
251
|
+
// also used in parse schema logic
|
|
252
|
+
function getCustomInfo() {
|
|
253
|
+
let yaml = {};
|
|
254
|
+
let relativeImports = false;
|
|
255
|
+
try {
|
|
256
|
+
yaml = (0, js_yaml_1.load)(fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
|
|
257
|
+
encoding: "utf8",
|
|
258
|
+
}));
|
|
259
|
+
relativeImports = yaml?.codegen?.relativeImports || false;
|
|
260
|
+
if (yaml?.codegen?.templatizedViewer) {
|
|
261
|
+
return {
|
|
262
|
+
viewerInfo: yaml.codegen.templatizedViewer,
|
|
263
|
+
relativeImports,
|
|
264
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (e) { }
|
|
269
|
+
return {
|
|
270
|
+
viewerInfo: {
|
|
271
|
+
path: const_1.PACKAGE,
|
|
272
|
+
name: "Viewer",
|
|
273
|
+
},
|
|
274
|
+
relativeImports,
|
|
275
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
exports.getCustomInfo = getCustomInfo;
|
package/tsc/compilerOptions.js
CHANGED
|
@@ -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];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function moveGenerated(relativeImports: boolean): void;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.moveGenerated = void 0;
|
|
30
|
+
const glob = __importStar(require("glob"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const fs = __importStar(require("fs"));
|
|
33
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
34
|
+
const ast_1 = require("./ast");
|
|
35
|
+
const transform_1 = require("./transform");
|
|
36
|
+
class MoveFiles {
|
|
37
|
+
constructor(globPath) {
|
|
38
|
+
this.globPath = globPath;
|
|
39
|
+
}
|
|
40
|
+
move() {
|
|
41
|
+
const files = glob.sync(this.globPath);
|
|
42
|
+
moveFiles(files);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class TransformImports {
|
|
46
|
+
constructor(glob, prettierGlob, relativeImports, checkRelativeImportsValid) {
|
|
47
|
+
this.glob = glob;
|
|
48
|
+
this.prettierGlob = prettierGlob;
|
|
49
|
+
this.relativeImports = relativeImports;
|
|
50
|
+
this.checkRelativeImportsValid = checkRelativeImportsValid;
|
|
51
|
+
this.globOptions = {
|
|
52
|
+
ignore: ["node_modules/**"],
|
|
53
|
+
};
|
|
54
|
+
this.cwd = process.cwd();
|
|
55
|
+
}
|
|
56
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
57
|
+
if (!typescript_1.default.isImportDeclaration(node)) {
|
|
58
|
+
return { node };
|
|
59
|
+
}
|
|
60
|
+
let dirPath = path.join(this.cwd, file, "..");
|
|
61
|
+
const newImportPath = this.getNewImportPath(node, file, sourceFile, dirPath);
|
|
62
|
+
if (!newImportPath) {
|
|
63
|
+
return { node };
|
|
64
|
+
}
|
|
65
|
+
const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
|
|
66
|
+
return {
|
|
67
|
+
traversed: true,
|
|
68
|
+
rawString: v,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
getNewImportPath(node, file, sourceFile, dirPath) {
|
|
72
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
73
|
+
// it's relative and has generated in there, continue
|
|
74
|
+
// do relative imports path regardless of if relative imports is on or not
|
|
75
|
+
if ((0, ast_1.isRelativeGeneratedImport)(node, sourceFile)) {
|
|
76
|
+
const oldPath = path.join(dirPath, text);
|
|
77
|
+
const relFromRoot = path.relative(".", oldPath);
|
|
78
|
+
const conv = transformPath(relFromRoot);
|
|
79
|
+
if (!conv || conv.newFile === relFromRoot) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return path.relative(dirPath, conv.newFile);
|
|
83
|
+
}
|
|
84
|
+
if (this.checkRelativeImportsValid && (0, ast_1.isRelativeImport)(node, sourceFile)) {
|
|
85
|
+
const parts = file.split(path.sep);
|
|
86
|
+
if (parts.length === 5 &&
|
|
87
|
+
parts.slice(0, 3).join(path.sep) ===
|
|
88
|
+
["src", "graphql", "generated"].join(path.sep)) {
|
|
89
|
+
// we have custom graphql import paths
|
|
90
|
+
// src/graphql/generated/mutations|resolvers/foo_type.ts
|
|
91
|
+
// which used to be
|
|
92
|
+
// src/graphql/mutations|resolvers/generated/foo_type.ts
|
|
93
|
+
// we probably have a broken import.
|
|
94
|
+
// try and fix it...
|
|
95
|
+
let temp = parts[2];
|
|
96
|
+
parts[2] = parts[3];
|
|
97
|
+
parts[3] = temp;
|
|
98
|
+
const oldPath = parts.join(path.sep);
|
|
99
|
+
let oldDir = path.join(this.cwd, oldPath, "..");
|
|
100
|
+
let importPath = path.join(oldDir, text);
|
|
101
|
+
let exists = fs.statSync(importPath + ".ts", { throwIfNoEntry: false });
|
|
102
|
+
if (!exists) {
|
|
103
|
+
// doesn't exist. sadly has to be fixed manually. could theoretically also be a directory but we shouldn't have that
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
return path.relative(dirPath, importPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// if relative imports, we done.
|
|
110
|
+
if (this.relativeImports) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// non relative, only transform src paths with generated
|
|
114
|
+
if ((0, ast_1.isSrcGeneratedImport)(node, sourceFile)) {
|
|
115
|
+
const conv = transformPath(text);
|
|
116
|
+
if (!conv || conv.newFile === text) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
return conv.newFile;
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function transformPath(old) {
|
|
125
|
+
const parts = old.split(path.sep);
|
|
126
|
+
if (parts.length < 3) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const changedParts = parts
|
|
130
|
+
.slice(0, 2)
|
|
131
|
+
.concat("generated")
|
|
132
|
+
.concat(parts.slice(2).filter((v) => v !== "generated"));
|
|
133
|
+
const newFile = changedParts.join(path.sep);
|
|
134
|
+
return { changedParts, newFile };
|
|
135
|
+
}
|
|
136
|
+
function moveFiles(files) {
|
|
137
|
+
files.forEach((file) => {
|
|
138
|
+
const conv = transformPath(file);
|
|
139
|
+
if (!conv) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const { changedParts, newFile } = conv;
|
|
143
|
+
if (file === newFile) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// check if directory exists, if not, create recursive dir
|
|
147
|
+
const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
|
|
148
|
+
const statInfo = fs.statSync(p, { throwIfNoEntry: false });
|
|
149
|
+
if (!statInfo) {
|
|
150
|
+
fs.mkdirSync(p, {
|
|
151
|
+
recursive: true,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// move file to new location
|
|
155
|
+
fs.renameSync(file, newFile);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function moveGenerated(relativeImports) {
|
|
159
|
+
new MoveFiles("src/ent/**/generated/**/**.ts").move();
|
|
160
|
+
new MoveFiles("src/graphql/**/generated/**/**.ts").move();
|
|
161
|
+
(0, transform_1.transform)(new TransformImports("src/ent/**/*.ts", "src/ent/**/*.ts", relativeImports));
|
|
162
|
+
(0, transform_1.transform)(new TransformImports("src/graphql/**/*.ts", "src/graphql/**/*.ts", relativeImports, true));
|
|
163
|
+
}
|
|
164
|
+
exports.moveGenerated = moveGenerated;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as glob from "glob";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
interface TraverseChildResponse {
|
|
4
|
+
node?: ts.Node;
|
|
5
|
+
rawString?: string;
|
|
6
|
+
traversed?: boolean;
|
|
7
|
+
imports?: Map<string, string[]>;
|
|
8
|
+
removeImports?: string[];
|
|
9
|
+
allowSeenImportsAdded?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface TransformFile {
|
|
12
|
+
glob: string;
|
|
13
|
+
globOptions?: glob.GlobOptions;
|
|
14
|
+
preprocessFile?: (contents: string, file: string, sourceFile: ts.SourceFile) => boolean;
|
|
15
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): TraverseChildResponse | undefined;
|
|
16
|
+
filter?(files: string[]): string[];
|
|
17
|
+
fileToWrite?(file: string): string;
|
|
18
|
+
postProcess?(file: string): void;
|
|
19
|
+
prettierGlob?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function transform(transform: TransformFile): void;
|
|
22
|
+
export {};
|
package/tsc/transform.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.transform = void 0;
|
|
30
|
+
const glob = __importStar(require("glob"));
|
|
31
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
32
|
+
const child_process_1 = require("child_process");
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
const ast_1 = require("./ast");
|
|
35
|
+
const compilerOptions_1 = require("./compilerOptions");
|
|
36
|
+
function normalizePath(p) {
|
|
37
|
+
if (p.endsWith("..")) {
|
|
38
|
+
return p + "/";
|
|
39
|
+
}
|
|
40
|
+
return p;
|
|
41
|
+
}
|
|
42
|
+
function transform(transform) {
|
|
43
|
+
let files = glob.sync(transform.glob, transform.globOptions ?? {});
|
|
44
|
+
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
45
|
+
if (transform.filter) {
|
|
46
|
+
const f2 = files.map((f) => (typeof f === "string" ? f : f.path));
|
|
47
|
+
files = transform.filter(f2);
|
|
48
|
+
}
|
|
49
|
+
files.forEach((file) => {
|
|
50
|
+
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
51
|
+
let nodes = [];
|
|
52
|
+
let imports = new Map();
|
|
53
|
+
let removeImports = [];
|
|
54
|
+
let traversed = false;
|
|
55
|
+
let allowSeenImportsAdded = false;
|
|
56
|
+
let seenImports = new Map();
|
|
57
|
+
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
58
|
+
if (typescript_1.default.isImportDeclaration(node)) {
|
|
59
|
+
const imp = (0, ast_1.getImportInfo)(node, sourceFile);
|
|
60
|
+
if (imp) {
|
|
61
|
+
imp.imports.forEach((v) => {
|
|
62
|
+
v = v.trim();
|
|
63
|
+
v && seenImports.set(v, true);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const ret = transform.traverseChild(sourceFile, contents, file, node);
|
|
68
|
+
if (!ret) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (ret.node || ret.rawString) {
|
|
72
|
+
nodes.push(ret);
|
|
73
|
+
}
|
|
74
|
+
if (ret.imports) {
|
|
75
|
+
for (const [k, v] of ret.imports) {
|
|
76
|
+
imports.set(k, v);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (ret.traversed) {
|
|
80
|
+
traversed = ret.traversed;
|
|
81
|
+
}
|
|
82
|
+
if (ret.removeImports?.length) {
|
|
83
|
+
removeImports.push(...ret.removeImports);
|
|
84
|
+
}
|
|
85
|
+
if (ret.allowSeenImportsAdded) {
|
|
86
|
+
allowSeenImportsAdded = ret.allowSeenImportsAdded;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
if (!traversed) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let newContents = "";
|
|
93
|
+
let afterProcessed = false;
|
|
94
|
+
let seen = new Map();
|
|
95
|
+
const processAfterImport = () => {
|
|
96
|
+
// do this for the first non-import node we see
|
|
97
|
+
// we want to add new imports to end of imports and there's an assumption that imports are ordered
|
|
98
|
+
// at top of file
|
|
99
|
+
// TODO account for placement after first comment
|
|
100
|
+
if (!afterProcessed) {
|
|
101
|
+
for (const [imp, list] of imports) {
|
|
102
|
+
if (seen.has(imp)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// this says only add things you haven't seen
|
|
106
|
+
// we want to add something we've seen in this case
|
|
107
|
+
let final = list;
|
|
108
|
+
if (!allowSeenImportsAdded) {
|
|
109
|
+
final = list.filter((v) => !seenImports.has(v));
|
|
110
|
+
}
|
|
111
|
+
if (final.length) {
|
|
112
|
+
newContents += `\nimport { ${final.join(", ")} } from "${imp}";\n`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
afterProcessed = true;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
for (const node of nodes) {
|
|
119
|
+
if (node.node) {
|
|
120
|
+
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
121
|
+
const impInfo = (0, ast_1.getImportInfo)(node.node, sourceFile);
|
|
122
|
+
// console.debug(impInfo);
|
|
123
|
+
if (impInfo) {
|
|
124
|
+
const impPath = normalizePath(impInfo.importPath);
|
|
125
|
+
const list = imports.get(impPath);
|
|
126
|
+
// path exists, we care about it
|
|
127
|
+
if (list !== undefined) {
|
|
128
|
+
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
129
|
+
// if we've done this path before, don't try and add
|
|
130
|
+
// but still try and do any removals since we don't know which of the imports
|
|
131
|
+
// has it
|
|
132
|
+
newImports: seen.has(impPath) ? undefined : list,
|
|
133
|
+
removeImports,
|
|
134
|
+
// don't use normalized path here, we wanna use the path that's in code...
|
|
135
|
+
transformPath: impInfo.importPath,
|
|
136
|
+
});
|
|
137
|
+
if (transformed) {
|
|
138
|
+
newContents += transformed;
|
|
139
|
+
seen.set(impPath, true);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (!typescript_1.default.isExportDeclaration(node.node) &&
|
|
147
|
+
!isRequireStatement(node.node, sourceFile)) {
|
|
148
|
+
processAfterImport();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
newContents += node.node.getFullText(sourceFile);
|
|
152
|
+
}
|
|
153
|
+
else if (node.rawString) {
|
|
154
|
+
processAfterImport();
|
|
155
|
+
newContents += node.rawString;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw new Error(`malformed node with no node or rawString`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let writeFile = file;
|
|
162
|
+
if (transform.fileToWrite) {
|
|
163
|
+
writeFile = transform.fileToWrite(file);
|
|
164
|
+
}
|
|
165
|
+
fs.writeFileSync(writeFile, newContents);
|
|
166
|
+
if (transform.postProcess) {
|
|
167
|
+
transform.postProcess(file);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
if (transform.prettierGlob) {
|
|
171
|
+
(0, child_process_1.execSync)(`prettier ${transform.prettierGlob} --write`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.transform = transform;
|
|
175
|
+
function isRequireStatement(node, sourceFile) {
|
|
176
|
+
if (node.kind !== typescript_1.default.SyntaxKind.VariableStatement) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const v = node;
|
|
180
|
+
const text = v.declarationList.declarations[0].getFullText(sourceFile);
|
|
181
|
+
return text.includes("require(");
|
|
182
|
+
}
|
|
@@ -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
|
+
}
|