@boon4681/giri 0.0.3-alpha-1 → 0.0.3-alpha-2
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/dist/adapters/hono.js.map +1 -1
- package/dist/cli.js +265 -104
- package/dist/cli.js.map +1 -1
- package/dist/index.js +171 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47,10 +47,10 @@ var init_es5 = __esm({
|
|
|
47
47
|
// src/generator/schema/program.ts
|
|
48
48
|
function createSchemaProgram(paths, routeFiles) {
|
|
49
49
|
let options = { ...DEFAULT_OPTIONS };
|
|
50
|
-
const configPath =
|
|
50
|
+
const configPath = import_typescript3.default.findConfigFile(paths.cwd, import_typescript3.default.sys.fileExists, "tsconfig.json");
|
|
51
51
|
if (configPath) {
|
|
52
|
-
const parsed =
|
|
53
|
-
...
|
|
52
|
+
const parsed = import_typescript3.default.getParsedCommandLineOfConfigFile(configPath, {}, {
|
|
53
|
+
...import_typescript3.default.sys,
|
|
54
54
|
onUnRecoverableConfigFileDiagnostic: () => {
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -58,17 +58,17 @@ function createSchemaProgram(paths, routeFiles) {
|
|
|
58
58
|
options = { ...parsed.options, noEmit: true };
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return import_typescript3.default.createProgram(routeFiles, options);
|
|
62
62
|
}
|
|
63
|
-
var
|
|
63
|
+
var import_typescript3, DEFAULT_OPTIONS;
|
|
64
64
|
var init_program = __esm({
|
|
65
65
|
"src/generator/schema/program.ts"() {
|
|
66
66
|
"use strict";
|
|
67
|
-
|
|
67
|
+
import_typescript3 = __toESM(require("typescript"));
|
|
68
68
|
DEFAULT_OPTIONS = {
|
|
69
|
-
target:
|
|
70
|
-
module:
|
|
71
|
-
moduleResolution:
|
|
69
|
+
target: import_typescript3.default.ScriptTarget.ES2022,
|
|
70
|
+
module: import_typescript3.default.ModuleKind.NodeNext,
|
|
71
|
+
moduleResolution: import_typescript3.default.ModuleResolutionKind.NodeNext,
|
|
72
72
|
strict: true,
|
|
73
73
|
skipLibCheck: true,
|
|
74
74
|
noEmit: true
|
|
@@ -102,7 +102,7 @@ function literalValuesOf(types) {
|
|
|
102
102
|
for (const member of types) {
|
|
103
103
|
if (member.isStringLiteral() || member.isNumberLiteral()) {
|
|
104
104
|
values.push(member.value);
|
|
105
|
-
} else if (member.flags &
|
|
105
|
+
} else if (member.flags & import_typescript4.default.TypeFlags.BooleanLiteral) {
|
|
106
106
|
values.push(intrinsicName(member) === "true");
|
|
107
107
|
} else {
|
|
108
108
|
return void 0;
|
|
@@ -111,7 +111,7 @@ function literalValuesOf(types) {
|
|
|
111
111
|
return values;
|
|
112
112
|
}
|
|
113
113
|
function walkUnion(type, ctx) {
|
|
114
|
-
const flag =
|
|
114
|
+
const flag = import_typescript4.default.TypeFlags.Undefined | import_typescript4.default.TypeFlags.Void | import_typescript4.default.TypeFlags.Never;
|
|
115
115
|
const members = type.types.filter((member) => !(member.flags & flag));
|
|
116
116
|
if (members.length === 1) {
|
|
117
117
|
return walkType(members[0], ctx);
|
|
@@ -124,13 +124,13 @@ function walkUnion(type, ctx) {
|
|
|
124
124
|
}
|
|
125
125
|
function buildObjectSchema(type, ctx) {
|
|
126
126
|
const { checker } = ctx;
|
|
127
|
-
const indexInfo = checker.getIndexInfoOfType(type,
|
|
127
|
+
const indexInfo = checker.getIndexInfoOfType(type, import_typescript4.default.IndexKind.String) ?? checker.getIndexInfoOfType(type, import_typescript4.default.IndexKind.Number);
|
|
128
128
|
const properties = {};
|
|
129
129
|
const required = [];
|
|
130
130
|
for (const symbol of checker.getPropertiesOfType(type)) {
|
|
131
131
|
const name = symbol.getName();
|
|
132
132
|
const propType = checker.getTypeOfSymbolAtLocation(symbol, ctx.location);
|
|
133
|
-
const optional = Boolean(symbol.getFlags() &
|
|
133
|
+
const optional = Boolean(symbol.getFlags() & import_typescript4.default.SymbolFlags.Optional) || Boolean(propType.flags & import_typescript4.default.TypeFlags.Union && propType.types.some((t) => t.flags & import_typescript4.default.TypeFlags.Undefined));
|
|
134
134
|
properties[name] = walkType(propType, ctx);
|
|
135
135
|
if (!optional) {
|
|
136
136
|
required.push(name);
|
|
@@ -189,16 +189,16 @@ function walkObject(type, ctx) {
|
|
|
189
189
|
}
|
|
190
190
|
function walkType(type, ctx) {
|
|
191
191
|
const flags = type.flags;
|
|
192
|
-
if (flags & (
|
|
192
|
+
if (flags & (import_typescript4.default.TypeFlags.Any | import_typescript4.default.TypeFlags.Unknown)) {
|
|
193
193
|
return {};
|
|
194
194
|
}
|
|
195
|
-
if (flags &
|
|
195
|
+
if (flags & import_typescript4.default.TypeFlags.Null) {
|
|
196
196
|
return { type: "null" };
|
|
197
197
|
}
|
|
198
|
-
if (flags & (
|
|
198
|
+
if (flags & (import_typescript4.default.TypeFlags.Undefined | import_typescript4.default.TypeFlags.Void)) {
|
|
199
199
|
return {};
|
|
200
200
|
}
|
|
201
|
-
if (flags & (
|
|
201
|
+
if (flags & (import_typescript4.default.TypeFlags.BigInt | import_typescript4.default.TypeFlags.BigIntLiteral)) {
|
|
202
202
|
ctx.warnings.push("bigint is not JSON-serializable (JSON.stringify throws); documented as string.");
|
|
203
203
|
return { type: "string" };
|
|
204
204
|
}
|
|
@@ -208,45 +208,45 @@ function walkType(type, ctx) {
|
|
|
208
208
|
if (type.isNumberLiteral()) {
|
|
209
209
|
return { type: "number", const: type.value };
|
|
210
210
|
}
|
|
211
|
-
if (flags &
|
|
211
|
+
if (flags & import_typescript4.default.TypeFlags.BooleanLiteral) {
|
|
212
212
|
return { type: "boolean", const: intrinsicName(type) === "true" };
|
|
213
213
|
}
|
|
214
|
-
if (flags &
|
|
214
|
+
if (flags & import_typescript4.default.TypeFlags.String) {
|
|
215
215
|
return { type: "string" };
|
|
216
216
|
}
|
|
217
|
-
if (flags &
|
|
217
|
+
if (flags & import_typescript4.default.TypeFlags.Number) {
|
|
218
218
|
return { type: "number" };
|
|
219
219
|
}
|
|
220
|
-
if (flags &
|
|
220
|
+
if (flags & import_typescript4.default.TypeFlags.Boolean) {
|
|
221
221
|
return { type: "boolean" };
|
|
222
222
|
}
|
|
223
223
|
if (type.isUnion()) {
|
|
224
224
|
return walkUnion(type, ctx);
|
|
225
225
|
}
|
|
226
|
-
if (flags &
|
|
226
|
+
if (flags & import_typescript4.default.TypeFlags.Object || type.isIntersection()) {
|
|
227
227
|
return walkObject(type, ctx);
|
|
228
228
|
}
|
|
229
229
|
return {};
|
|
230
230
|
}
|
|
231
|
-
var
|
|
231
|
+
var import_typescript4;
|
|
232
232
|
var init_json_schema = __esm({
|
|
233
233
|
"src/generator/schema/json-schema.ts"() {
|
|
234
234
|
"use strict";
|
|
235
|
-
|
|
235
|
+
import_typescript4 = __toESM(require("typescript"));
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
// src/generator/schema/responses.ts
|
|
240
240
|
function findHandleFunction(source) {
|
|
241
241
|
let found;
|
|
242
|
-
const isExported = (node) =>
|
|
242
|
+
const isExported = (node) => import_typescript5.default.canHaveModifiers(node) && (import_typescript5.default.getModifiers(node)?.some((m) => m.kind === import_typescript5.default.SyntaxKind.ExportKeyword) ?? false);
|
|
243
243
|
for (const statement of source.statements) {
|
|
244
|
-
if (
|
|
244
|
+
if (import_typescript5.default.isFunctionDeclaration(statement) && statement.name?.text === "handle" && isExported(statement)) {
|
|
245
245
|
found = statement;
|
|
246
246
|
}
|
|
247
|
-
if (
|
|
247
|
+
if (import_typescript5.default.isVariableStatement(statement) && isExported(statement)) {
|
|
248
248
|
for (const declaration of statement.declarationList.declarations) {
|
|
249
|
-
if (
|
|
249
|
+
if (import_typescript5.default.isIdentifier(declaration.name) && declaration.name.text === "handle" && declaration.initializer && (import_typescript5.default.isArrowFunction(declaration.initializer) || import_typescript5.default.isFunctionExpression(declaration.initializer))) {
|
|
250
250
|
found = declaration.initializer;
|
|
251
251
|
}
|
|
252
252
|
}
|
|
@@ -255,7 +255,7 @@ function findHandleFunction(source) {
|
|
|
255
255
|
return found;
|
|
256
256
|
}
|
|
257
257
|
function collectReturnExpressions(fn) {
|
|
258
|
-
if (
|
|
258
|
+
if (import_typescript5.default.isArrowFunction(fn) && !import_typescript5.default.isBlock(fn.body)) {
|
|
259
259
|
return [fn.body];
|
|
260
260
|
}
|
|
261
261
|
if (!fn.body) {
|
|
@@ -263,15 +263,15 @@ function collectReturnExpressions(fn) {
|
|
|
263
263
|
}
|
|
264
264
|
const expressions = [];
|
|
265
265
|
const visit = (node) => {
|
|
266
|
-
if (
|
|
266
|
+
if (import_typescript5.default.isFunctionDeclaration(node) || import_typescript5.default.isFunctionExpression(node) || import_typescript5.default.isArrowFunction(node)) {
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
|
-
if (
|
|
269
|
+
if (import_typescript5.default.isReturnStatement(node) && node.expression) {
|
|
270
270
|
expressions.push(node.expression);
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
import_typescript5.default.forEachChild(node, visit);
|
|
273
273
|
};
|
|
274
|
-
|
|
274
|
+
import_typescript5.default.forEachChild(fn.body, visit);
|
|
275
275
|
return expressions;
|
|
276
276
|
}
|
|
277
277
|
function propertyType(checker, type, name, location) {
|
|
@@ -285,10 +285,10 @@ function isTypedResponse2(checker, type) {
|
|
|
285
285
|
}
|
|
286
286
|
function firstParameterName(fn) {
|
|
287
287
|
const [first] = fn.parameters;
|
|
288
|
-
return first &&
|
|
288
|
+
return first && import_typescript5.default.isIdentifier(first.name) ? first.name.text : void 0;
|
|
289
289
|
}
|
|
290
290
|
function readFromCall(checker, expression, contextName) {
|
|
291
|
-
if (!
|
|
291
|
+
if (!import_typescript5.default.isCallExpression(expression) || !import_typescript5.default.isPropertyAccessExpression(expression.expression)) {
|
|
292
292
|
return void 0;
|
|
293
293
|
}
|
|
294
294
|
const method = expression.expression.name.text;
|
|
@@ -296,7 +296,7 @@ function readFromCall(checker, expression, contextName) {
|
|
|
296
296
|
return void 0;
|
|
297
297
|
}
|
|
298
298
|
const target = expression.expression.expression;
|
|
299
|
-
const directContextCall = contextName &&
|
|
299
|
+
const directContextCall = contextName && import_typescript5.default.isIdentifier(target) && target.text === contextName;
|
|
300
300
|
if (!directContextCall && !isTypedResponse2(checker, checker.getTypeAtLocation(expression))) {
|
|
301
301
|
return void 0;
|
|
302
302
|
}
|
|
@@ -372,11 +372,11 @@ function extractRouteResponses(program, file) {
|
|
|
372
372
|
result.$defs = ctx.defs;
|
|
373
373
|
return result;
|
|
374
374
|
}
|
|
375
|
-
var
|
|
375
|
+
var import_typescript5;
|
|
376
376
|
var init_responses = __esm({
|
|
377
377
|
"src/generator/schema/responses.ts"() {
|
|
378
378
|
"use strict";
|
|
379
|
-
|
|
379
|
+
import_typescript5 = __toESM(require("typescript"));
|
|
380
380
|
init_json_schema();
|
|
381
381
|
}
|
|
382
382
|
});
|
|
@@ -817,6 +817,7 @@ var import_node_fs2 = require("fs");
|
|
|
817
817
|
var import_promises = require("fs/promises");
|
|
818
818
|
var import_node_path2 = require("path");
|
|
819
819
|
var import_tinyglobby = require("tinyglobby");
|
|
820
|
+
var import_typescript = __toESM(require("typescript"));
|
|
820
821
|
var METHOD_ORDER = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
821
822
|
var METHOD_FROM_FILE = new Map(
|
|
822
823
|
METHOD_ORDER.map((method) => [`+${method.toLowerCase()}`, method])
|
|
@@ -834,6 +835,108 @@ function methodFromFile(fileName) {
|
|
|
834
835
|
const stem = fileName.replace(/\.(?:[cm]?[jt]s|[jt]sx)$/, "").toLowerCase();
|
|
835
836
|
return METHOD_FROM_FILE.get(stem);
|
|
836
837
|
}
|
|
838
|
+
function hasExportModifier(node) {
|
|
839
|
+
return import_typescript.default.canHaveModifiers(node) && (import_typescript.default.getModifiers(node)?.some((modifier) => modifier.kind === import_typescript.default.SyntaxKind.ExportKeyword) ?? false);
|
|
840
|
+
}
|
|
841
|
+
function hasDeclareModifier(node) {
|
|
842
|
+
return import_typescript.default.canHaveModifiers(node) && (import_typescript.default.getModifiers(node)?.some((modifier) => modifier.kind === import_typescript.default.SyntaxKind.DeclareKeyword) ?? false);
|
|
843
|
+
}
|
|
844
|
+
function propertyName(node) {
|
|
845
|
+
if (import_typescript.default.isIdentifier(node) || import_typescript.default.isStringLiteralLike(node) || import_typescript.default.isNumericLiteral(node)) {
|
|
846
|
+
return node.text;
|
|
847
|
+
}
|
|
848
|
+
if (import_typescript.default.isPropertyAccessExpression(node)) {
|
|
849
|
+
return node.name.text;
|
|
850
|
+
}
|
|
851
|
+
if (import_typescript.default.isElementAccessExpression(node) && node.argumentExpression) {
|
|
852
|
+
const argument = node.argumentExpression;
|
|
853
|
+
if (import_typescript.default.isStringLiteralLike(argument)) {
|
|
854
|
+
return argument.text;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return void 0;
|
|
858
|
+
}
|
|
859
|
+
function isExportsObject(node) {
|
|
860
|
+
return import_typescript.default.isIdentifier(node) && node.text === "exports";
|
|
861
|
+
}
|
|
862
|
+
function isModuleExports(node) {
|
|
863
|
+
return import_typescript.default.isPropertyAccessExpression(node) && import_typescript.default.isIdentifier(node.expression) && node.expression.text === "module" && node.name.text === "exports";
|
|
864
|
+
}
|
|
865
|
+
function isCommonJsHandleTarget(node) {
|
|
866
|
+
if (!import_typescript.default.isPropertyAccessExpression(node) && !import_typescript.default.isElementAccessExpression(node)) {
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
return propertyName(node) === "handle" && (isExportsObject(node.expression) || isModuleExports(node.expression));
|
|
870
|
+
}
|
|
871
|
+
function objectExportsHandle(node) {
|
|
872
|
+
if (!import_typescript.default.isObjectLiteralExpression(node)) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
return node.properties.some((property) => {
|
|
876
|
+
if (import_typescript.default.isShorthandPropertyAssignment(property)) {
|
|
877
|
+
return property.name.text === "handle";
|
|
878
|
+
}
|
|
879
|
+
return (import_typescript.default.isPropertyAssignment(property) || import_typescript.default.isMethodDeclaration(property)) && propertyName(property.name) === "handle";
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
function hasNamedHandleExport(source) {
|
|
883
|
+
for (const statement of source.statements) {
|
|
884
|
+
if (hasExportModifier(statement) && !hasDeclareModifier(statement) && import_typescript.default.isFunctionDeclaration(statement) && statement.name?.text === "handle") {
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
887
|
+
if (hasExportModifier(statement) && !hasDeclareModifier(statement) && import_typescript.default.isVariableStatement(statement)) {
|
|
888
|
+
if (statement.declarationList.declarations.some(
|
|
889
|
+
(declaration) => import_typescript.default.isIdentifier(declaration.name) && declaration.name.text === "handle"
|
|
890
|
+
)) {
|
|
891
|
+
return true;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (import_typescript.default.isExportDeclaration(statement) && !statement.isTypeOnly && statement.exportClause && import_typescript.default.isNamedExports(statement.exportClause)) {
|
|
895
|
+
if (statement.exportClause.elements.some(
|
|
896
|
+
(element) => !element.isTypeOnly && element.name.text === "handle"
|
|
897
|
+
)) {
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
if (!import_typescript.default.isExpressionStatement(statement) || !import_typescript.default.isBinaryExpression(statement.expression)) {
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
const assignment = statement.expression;
|
|
905
|
+
if (assignment.operatorToken.kind !== import_typescript.default.SyntaxKind.EqualsToken) {
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (isCommonJsHandleTarget(assignment.left) || isModuleExports(assignment.left) && objectExportsHandle(assignment.right)) {
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return false;
|
|
913
|
+
}
|
|
914
|
+
function parseSource(file) {
|
|
915
|
+
return import_typescript.default.createSourceFile(
|
|
916
|
+
file,
|
|
917
|
+
(0, import_node_fs2.readFileSync)(file, "utf8"),
|
|
918
|
+
import_typescript.default.ScriptTarget.Latest,
|
|
919
|
+
true
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
function parseDiagnostics(source) {
|
|
923
|
+
return source.parseDiagnostics ?? [];
|
|
924
|
+
}
|
|
925
|
+
function formatSyntaxDiagnostic(diagnostic) {
|
|
926
|
+
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
927
|
+
const message = import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
928
|
+
return `${diagnostic.file.fileName}:${position.line + 1}:${position.character + 1} - error TS${diagnostic.code}: ${message}`;
|
|
929
|
+
}
|
|
930
|
+
function assertRouteHandleExport(file) {
|
|
931
|
+
const source = parseSource(file);
|
|
932
|
+
const diagnostics = parseDiagnostics(source);
|
|
933
|
+
if (diagnostics.length > 0) {
|
|
934
|
+
throw new SyntaxError(diagnostics.map(formatSyntaxDiagnostic).join("\n"));
|
|
935
|
+
}
|
|
936
|
+
if (!hasNamedHandleExport(source)) {
|
|
937
|
+
throw new Error(`${file} must export a named handle function.`);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
837
940
|
function sharedFileIn(dir, cache) {
|
|
838
941
|
if (cache?.has(dir)) {
|
|
839
942
|
return cache.get(dir);
|
|
@@ -1097,6 +1200,11 @@ function resolveGiriPaths(config, cwd = process.cwd()) {
|
|
|
1097
1200
|
async function buildGiriApp(config, options = {}) {
|
|
1098
1201
|
const paths = resolveGiriPaths(config, options.cwd);
|
|
1099
1202
|
const routes = await scanRoutes(paths.routesDir);
|
|
1203
|
+
if (options.lazy) {
|
|
1204
|
+
for (const route of routes) {
|
|
1205
|
+
assertRouteHandleExport(route.file);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1100
1208
|
const app = config.adapter.createApp();
|
|
1101
1209
|
ensureGiriAliasResolver(paths.outDir);
|
|
1102
1210
|
if (options.lazy && (!options.loaderRegistered || !options.aliasResolverRegistered)) {
|
|
@@ -1577,7 +1685,7 @@ async function writeParamTypes(paths, folders) {
|
|
|
1577
1685
|
|
|
1578
1686
|
// src/generator/route-meta.ts
|
|
1579
1687
|
var import_node_fs6 = require("fs");
|
|
1580
|
-
var
|
|
1688
|
+
var import_typescript2 = __toESM(require("typescript"));
|
|
1581
1689
|
|
|
1582
1690
|
// src/generator/inputs.ts
|
|
1583
1691
|
function sanitize(schema) {
|
|
@@ -1639,33 +1747,33 @@ function readInput(routeModule) {
|
|
|
1639
1747
|
}
|
|
1640
1748
|
return input.body || input.query ? input : void 0;
|
|
1641
1749
|
}
|
|
1642
|
-
function
|
|
1643
|
-
return
|
|
1750
|
+
function hasExportModifier2(node) {
|
|
1751
|
+
return import_typescript2.default.canHaveModifiers(node) && (import_typescript2.default.getModifiers(node)?.some((modifier) => modifier.kind === import_typescript2.default.SyntaxKind.ExportKeyword) ?? false);
|
|
1644
1752
|
}
|
|
1645
1753
|
function unwrapExpression(expression) {
|
|
1646
1754
|
let current = expression;
|
|
1647
|
-
while (
|
|
1755
|
+
while (import_typescript2.default.isParenthesizedExpression(current) || import_typescript2.default.isAsExpression(current) || import_typescript2.default.isSatisfiesExpression(current)) {
|
|
1648
1756
|
current = current.expression;
|
|
1649
1757
|
}
|
|
1650
1758
|
return current;
|
|
1651
1759
|
}
|
|
1652
1760
|
function staticBoolean(expression) {
|
|
1653
1761
|
const value = unwrapExpression(expression);
|
|
1654
|
-
if (value.kind ===
|
|
1762
|
+
if (value.kind === import_typescript2.default.SyntaxKind.TrueKeyword) {
|
|
1655
1763
|
return true;
|
|
1656
1764
|
}
|
|
1657
|
-
if (value.kind ===
|
|
1765
|
+
if (value.kind === import_typescript2.default.SyntaxKind.FalseKeyword) {
|
|
1658
1766
|
return false;
|
|
1659
1767
|
}
|
|
1660
1768
|
return void 0;
|
|
1661
1769
|
}
|
|
1662
1770
|
function staticString(expression) {
|
|
1663
1771
|
const value = unwrapExpression(expression);
|
|
1664
|
-
return
|
|
1772
|
+
return import_typescript2.default.isStringLiteralLike(value) ? value.text : void 0;
|
|
1665
1773
|
}
|
|
1666
1774
|
function staticStringArray(expression) {
|
|
1667
1775
|
const value = unwrapExpression(expression);
|
|
1668
|
-
if (!
|
|
1776
|
+
if (!import_typescript2.default.isArrayLiteralExpression(value)) {
|
|
1669
1777
|
return void 0;
|
|
1670
1778
|
}
|
|
1671
1779
|
const strings = [];
|
|
@@ -1678,8 +1786,8 @@ function staticStringArray(expression) {
|
|
|
1678
1786
|
}
|
|
1679
1787
|
return strings;
|
|
1680
1788
|
}
|
|
1681
|
-
function
|
|
1682
|
-
if (
|
|
1789
|
+
function propertyName2(name) {
|
|
1790
|
+
if (import_typescript2.default.isIdentifier(name) || import_typescript2.default.isStringLiteral(name) || import_typescript2.default.isNumericLiteral(name)) {
|
|
1683
1791
|
return name.text;
|
|
1684
1792
|
}
|
|
1685
1793
|
return void 0;
|
|
@@ -1687,7 +1795,7 @@ function propertyName(name) {
|
|
|
1687
1795
|
function collectImportedNames(source) {
|
|
1688
1796
|
const names = /* @__PURE__ */ new Set();
|
|
1689
1797
|
for (const statement of source.statements) {
|
|
1690
|
-
if (!
|
|
1798
|
+
if (!import_typescript2.default.isImportDeclaration(statement)) {
|
|
1691
1799
|
continue;
|
|
1692
1800
|
}
|
|
1693
1801
|
const clause = statement.importClause;
|
|
@@ -1698,10 +1806,10 @@ function collectImportedNames(source) {
|
|
|
1698
1806
|
names.add(clause.name.text);
|
|
1699
1807
|
}
|
|
1700
1808
|
const bindings = clause.namedBindings;
|
|
1701
|
-
if (bindings &&
|
|
1809
|
+
if (bindings && import_typescript2.default.isNamespaceImport(bindings)) {
|
|
1702
1810
|
names.add(bindings.name.text);
|
|
1703
1811
|
}
|
|
1704
|
-
if (bindings &&
|
|
1812
|
+
if (bindings && import_typescript2.default.isNamedImports(bindings)) {
|
|
1705
1813
|
for (const element of bindings.elements) {
|
|
1706
1814
|
names.add(element.name.text);
|
|
1707
1815
|
}
|
|
@@ -1716,11 +1824,11 @@ function expressionReferencesImportedMiddleware(expression, importedNames) {
|
|
|
1716
1824
|
if (found) {
|
|
1717
1825
|
return;
|
|
1718
1826
|
}
|
|
1719
|
-
if (
|
|
1827
|
+
if (import_typescript2.default.isIdentifier(node) && importedNames.has(node.text) && !allowedImportedHelpers.has(node.text)) {
|
|
1720
1828
|
found = true;
|
|
1721
1829
|
return;
|
|
1722
1830
|
}
|
|
1723
|
-
|
|
1831
|
+
import_typescript2.default.forEachChild(node, visit);
|
|
1724
1832
|
};
|
|
1725
1833
|
visit(expression);
|
|
1726
1834
|
return found;
|
|
@@ -1731,15 +1839,15 @@ function parseStaticOpenApi(expression) {
|
|
|
1731
1839
|
if (boolean !== void 0) {
|
|
1732
1840
|
return boolean;
|
|
1733
1841
|
}
|
|
1734
|
-
if (!
|
|
1842
|
+
if (!import_typescript2.default.isObjectLiteralExpression(value)) {
|
|
1735
1843
|
return void 0;
|
|
1736
1844
|
}
|
|
1737
1845
|
const openapi = {};
|
|
1738
1846
|
for (const property of value.properties) {
|
|
1739
|
-
if (!
|
|
1847
|
+
if (!import_typescript2.default.isPropertyAssignment(property)) {
|
|
1740
1848
|
return void 0;
|
|
1741
1849
|
}
|
|
1742
|
-
const name =
|
|
1850
|
+
const name = propertyName2(property.name);
|
|
1743
1851
|
if (!name) {
|
|
1744
1852
|
return void 0;
|
|
1745
1853
|
}
|
|
@@ -1776,7 +1884,7 @@ function parseStaticOpenApi(expression) {
|
|
|
1776
1884
|
function readStaticModuleMeta(file) {
|
|
1777
1885
|
let source;
|
|
1778
1886
|
try {
|
|
1779
|
-
source =
|
|
1887
|
+
source = import_typescript2.default.createSourceFile(file, (0, import_node_fs6.readFileSync)(file, "utf8"), import_typescript2.default.ScriptTarget.Latest, true);
|
|
1780
1888
|
} catch {
|
|
1781
1889
|
return void 0;
|
|
1782
1890
|
}
|
|
@@ -1785,15 +1893,15 @@ function readStaticModuleMeta(file) {
|
|
|
1785
1893
|
const canSkipMiddlewareRuntime = !sourceText.includes("defineMiddleware") && !sourceText.includes(".openapi");
|
|
1786
1894
|
const meta = { middlewareSecurity: false };
|
|
1787
1895
|
for (const statement of source.statements) {
|
|
1788
|
-
if (
|
|
1896
|
+
if (import_typescript2.default.isImportDeclaration(statement) || import_typescript2.default.isInterfaceDeclaration(statement) || import_typescript2.default.isTypeAliasDeclaration(statement) || import_typescript2.default.isEmptyStatement(statement) || !hasExportModifier2(statement)) {
|
|
1789
1897
|
continue;
|
|
1790
1898
|
}
|
|
1791
|
-
if (
|
|
1899
|
+
if (import_typescript2.default.isFunctionDeclaration(statement) && statement.name?.text === "handle") {
|
|
1792
1900
|
continue;
|
|
1793
1901
|
}
|
|
1794
|
-
if (
|
|
1902
|
+
if (import_typescript2.default.isVariableStatement(statement)) {
|
|
1795
1903
|
for (const declaration of statement.declarationList.declarations) {
|
|
1796
|
-
if (!
|
|
1904
|
+
if (!import_typescript2.default.isIdentifier(declaration.name)) {
|
|
1797
1905
|
return void 0;
|
|
1798
1906
|
}
|
|
1799
1907
|
const name = declaration.name.text;
|
|
@@ -1807,7 +1915,7 @@ function readStaticModuleMeta(file) {
|
|
|
1807
1915
|
}
|
|
1808
1916
|
meta.openapi = openapi;
|
|
1809
1917
|
} else if (name === "handle") {
|
|
1810
|
-
if (!declaration.initializer || !
|
|
1918
|
+
if (!declaration.initializer || !import_typescript2.default.isArrowFunction(declaration.initializer) && !import_typescript2.default.isFunctionExpression(declaration.initializer)) {
|
|
1811
1919
|
return void 0;
|
|
1812
1920
|
}
|
|
1813
1921
|
continue;
|
|
@@ -2335,7 +2443,7 @@ var import_node_path15 = require("path");
|
|
|
2335
2443
|
// src/loader/import-graph.ts
|
|
2336
2444
|
var import_node_fs9 = require("fs");
|
|
2337
2445
|
var import_node_path13 = require("path");
|
|
2338
|
-
var
|
|
2446
|
+
var import_typescript6 = __toESM(require("typescript"));
|
|
2339
2447
|
var import_tinyglobby3 = require("tinyglobby");
|
|
2340
2448
|
|
|
2341
2449
|
// src/loader/module-loader.ts
|