@dudousxd/nestjs-inertia-codegen 1.0.5 → 1.0.7
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/CHANGELOG.md +18 -0
- package/dist/cli/main.cjs +75 -29
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.js +75 -29
- package/dist/cli/main.js.map +1 -1
- package/dist/index.cjs +75 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -29
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog — @dudousxd/nestjs-inertia-codegen
|
|
2
2
|
|
|
3
|
+
## 1.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix(core): use data-page="app" attribute on script tag for Inertia v3 protocol compatibility
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @dudousxd/nestjs-inertia@1.0.7
|
|
11
|
+
|
|
12
|
+
## 1.0.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- fix(codegen): resolve interfaces, type aliases, and enums — not just classes. Conditional @tanstack/query-core import.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies []:
|
|
19
|
+
- @dudousxd/nestjs-inertia@1.0.6
|
|
20
|
+
|
|
3
21
|
## 1.0.5
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/cli/main.cjs
CHANGED
|
@@ -354,16 +354,19 @@ function buildRouterTypeAccess(name) {
|
|
|
354
354
|
__name(buildRouterTypeAccess, "buildRouterTypeAccess");
|
|
355
355
|
function buildApiFile(routes) {
|
|
356
356
|
const contracted = routes.filter((r) => r.contract);
|
|
357
|
+
const hasGetRoutes = contracted.some((r) => r.method === "GET");
|
|
357
358
|
const lines = [
|
|
358
359
|
"// Generated by @dudousxd/nestjs-inertia-codegen. Do not edit.",
|
|
359
|
-
"",
|
|
360
|
-
"import { queryOptions } from '@tanstack/query-core';",
|
|
361
|
-
"import { route } from './routes.js';",
|
|
362
|
-
"import { createFetcher } from '@dudousxd/nestjs-inertia-client';",
|
|
363
|
-
"",
|
|
364
|
-
"export const fetcher = createFetcher();",
|
|
365
360
|
""
|
|
366
361
|
];
|
|
362
|
+
if (hasGetRoutes) {
|
|
363
|
+
lines.push("import { queryOptions } from '@tanstack/query-core';");
|
|
364
|
+
}
|
|
365
|
+
lines.push("import { route } from './routes.js';");
|
|
366
|
+
lines.push("import { createFetcher } from '@dudousxd/nestjs-inertia-client';");
|
|
367
|
+
lines.push("");
|
|
368
|
+
lines.push("export const fetcher = createFetcher();");
|
|
369
|
+
lines.push("");
|
|
367
370
|
if (contracted.length === 0) {
|
|
368
371
|
lines.push("export type ApiRouter = Record<string, never>;");
|
|
369
372
|
lines.push("");
|
|
@@ -878,7 +881,42 @@ function extractParams(path) {
|
|
|
878
881
|
}));
|
|
879
882
|
}
|
|
880
883
|
__name(extractParams, "extractParams");
|
|
881
|
-
function
|
|
884
|
+
function findTypeInFile(name, file) {
|
|
885
|
+
const cls = file.getClass(name);
|
|
886
|
+
if (cls) return {
|
|
887
|
+
kind: "class",
|
|
888
|
+
decl: cls,
|
|
889
|
+
file
|
|
890
|
+
};
|
|
891
|
+
const iface = file.getInterface(name);
|
|
892
|
+
if (iface) return {
|
|
893
|
+
kind: "interface",
|
|
894
|
+
decl: iface,
|
|
895
|
+
file
|
|
896
|
+
};
|
|
897
|
+
const alias = file.getTypeAlias(name);
|
|
898
|
+
if (alias) {
|
|
899
|
+
const typeNode = alias.getTypeNode();
|
|
900
|
+
return {
|
|
901
|
+
kind: "typeAlias",
|
|
902
|
+
text: typeNode ? typeNode.getText() : "unknown"
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
const enumDecl = file.getEnum(name);
|
|
906
|
+
if (enumDecl) {
|
|
907
|
+
const members = enumDecl.getMembers().map((m) => {
|
|
908
|
+
const val = m.getValue();
|
|
909
|
+
return typeof val === "string" ? JSON.stringify(val) : JSON.stringify(m.getName());
|
|
910
|
+
});
|
|
911
|
+
return {
|
|
912
|
+
kind: "enum",
|
|
913
|
+
members
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
return null;
|
|
917
|
+
}
|
|
918
|
+
__name(findTypeInFile, "findTypeInFile");
|
|
919
|
+
function resolveImportedType(name, sourceFile, project) {
|
|
882
920
|
for (const importDecl of sourceFile.getImportDeclarations()) {
|
|
883
921
|
const namedImport = importDecl.getNamedImports().find((n) => n.getName() === name);
|
|
884
922
|
if (!namedImport) continue;
|
|
@@ -898,25 +936,19 @@ function resolveImportedClass(name, sourceFile, project) {
|
|
|
898
936
|
continue;
|
|
899
937
|
}
|
|
900
938
|
}
|
|
901
|
-
const
|
|
902
|
-
if (
|
|
903
|
-
cls,
|
|
904
|
-
file: importedFile
|
|
905
|
-
};
|
|
939
|
+
const result = findTypeInFile(name, importedFile);
|
|
940
|
+
if (result) return result;
|
|
906
941
|
}
|
|
907
942
|
}
|
|
908
943
|
return null;
|
|
909
944
|
}
|
|
910
|
-
__name(
|
|
911
|
-
function
|
|
912
|
-
const local =
|
|
913
|
-
if (local) return
|
|
914
|
-
|
|
915
|
-
file: sourceFile
|
|
916
|
-
};
|
|
917
|
-
return resolveImportedClass(name, sourceFile, project);
|
|
945
|
+
__name(resolveImportedType, "resolveImportedType");
|
|
946
|
+
function findType(name, sourceFile, project) {
|
|
947
|
+
const local = findTypeInFile(name, sourceFile);
|
|
948
|
+
if (local) return local;
|
|
949
|
+
return resolveImportedType(name, sourceFile, project);
|
|
918
950
|
}
|
|
919
|
-
__name(
|
|
951
|
+
__name(findType, "findType");
|
|
920
952
|
function resolveTypeNodeToString(typeNode, sourceFile, project, depth) {
|
|
921
953
|
if (depth <= 0) return "unknown";
|
|
922
954
|
if (import_ts_morph.Node.isArrayTypeNode(typeNode)) {
|
|
@@ -945,9 +977,9 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth) {
|
|
|
945
977
|
}
|
|
946
978
|
return "unknown";
|
|
947
979
|
}
|
|
948
|
-
const resolved =
|
|
980
|
+
const resolved = findType(name, sourceFile, project);
|
|
949
981
|
if (resolved) {
|
|
950
|
-
return
|
|
982
|
+
return expandTypeDecl(resolved, project, depth - 1);
|
|
951
983
|
}
|
|
952
984
|
return name;
|
|
953
985
|
}
|
|
@@ -960,10 +992,24 @@ function resolveTypeNodeToString(typeNode, sourceFile, project, depth) {
|
|
|
960
992
|
return typeNode.getText();
|
|
961
993
|
}
|
|
962
994
|
__name(resolveTypeNodeToString, "resolveTypeNodeToString");
|
|
963
|
-
function
|
|
995
|
+
function expandTypeDecl(result, project, depth) {
|
|
996
|
+
if (depth < 0) return "unknown";
|
|
997
|
+
switch (result.kind) {
|
|
998
|
+
case "class":
|
|
999
|
+
return resolvePropertied(result.decl, result.file, project, depth);
|
|
1000
|
+
case "interface":
|
|
1001
|
+
return resolvePropertied(result.decl, result.file, project, depth);
|
|
1002
|
+
case "typeAlias":
|
|
1003
|
+
return result.text;
|
|
1004
|
+
case "enum":
|
|
1005
|
+
return result.members.join(" | ");
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
__name(expandTypeDecl, "expandTypeDecl");
|
|
1009
|
+
function resolvePropertied(decl, sourceFile, project, depth) {
|
|
964
1010
|
if (depth < 0) return "unknown";
|
|
965
1011
|
const lines = [];
|
|
966
|
-
for (const prop of
|
|
1012
|
+
for (const prop of decl.getProperties()) {
|
|
967
1013
|
const propName = prop.getName();
|
|
968
1014
|
const isOptional = prop.hasQuestionToken();
|
|
969
1015
|
const propTypeNode = prop.getTypeNode();
|
|
@@ -975,7 +1021,7 @@ function resolveClassDeclaration(cls, sourceFile, project, depth) {
|
|
|
975
1021
|
}
|
|
976
1022
|
return `{ ${lines.join("; ")} }`;
|
|
977
1023
|
}
|
|
978
|
-
__name(
|
|
1024
|
+
__name(resolvePropertied, "resolvePropertied");
|
|
979
1025
|
function extractBodyType(method, sourceFile, project) {
|
|
980
1026
|
for (const param of method.getParameters()) {
|
|
981
1027
|
const bodyDecorator = param.getDecorators().find((d) => d.getName() === "Body");
|
|
@@ -1055,9 +1101,9 @@ __name(extractResponseType, "extractResponseType");
|
|
|
1055
1101
|
function resolveIdentifierToClassType(node, sourceFile, project, depth) {
|
|
1056
1102
|
if (!import_ts_morph.Node.isIdentifier(node)) return "unknown";
|
|
1057
1103
|
const name = node.getText();
|
|
1058
|
-
const resolved =
|
|
1104
|
+
const resolved = findType(name, sourceFile, project);
|
|
1059
1105
|
if (resolved) {
|
|
1060
|
-
return
|
|
1106
|
+
return expandTypeDecl(resolved, project, depth - 1);
|
|
1061
1107
|
}
|
|
1062
1108
|
return name;
|
|
1063
1109
|
}
|
|
@@ -1386,7 +1432,7 @@ async function watch(config, onChange) {
|
|
|
1386
1432
|
__name(watch, "watch");
|
|
1387
1433
|
|
|
1388
1434
|
// src/index.ts
|
|
1389
|
-
var VERSION = "1.0.
|
|
1435
|
+
var VERSION = "1.0.7";
|
|
1390
1436
|
|
|
1391
1437
|
// src/cli/codegen.ts
|
|
1392
1438
|
async function runCodegen(opts = {}) {
|