@tuyau/core 0.2.3 → 0.3.0
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/build/commands/generate.js +18 -10
- package/package.json +6 -6
|
@@ -98,11 +98,6 @@ var ApiTypesGenerator = class {
|
|
|
98
98
|
return void 0;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* We have multiple ways to get the request payload :
|
|
102
|
-
* - First we check if a FormRequest is used
|
|
103
|
-
* - Other we check if we have a Single Action Controller
|
|
104
|
-
* - Otherwise, we check if a request.validateUsing is used
|
|
105
|
-
*
|
|
106
101
|
* This method will returns the path to the schema file
|
|
107
102
|
*/
|
|
108
103
|
#extractRequest(handlerData) {
|
|
@@ -113,9 +108,9 @@ var ApiTypesGenerator = class {
|
|
|
113
108
|
}
|
|
114
109
|
return false;
|
|
115
110
|
});
|
|
116
|
-
if (validateUsingCallNode)
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
if (!validateUsingCallNode) return;
|
|
112
|
+
const schema = validateUsingCallNode.getArguments()[0];
|
|
113
|
+
if (Node.isIdentifier(schema)) {
|
|
119
114
|
const definition = schema.getDefinitions().at(0);
|
|
120
115
|
const importType = this.#getIdentifierImportType(schema);
|
|
121
116
|
const isReExportedFromThisFile = definition ? handlerData.file.getExportedDeclarations().has(definition.getNode().getText()) : false;
|
|
@@ -128,7 +123,20 @@ var ApiTypesGenerator = class {
|
|
|
128
123
|
const propName = importType === "default" ? "default" : schema.getText();
|
|
129
124
|
return `InferInput<typeof import('${relativeImportPath}')['${propName}']>`;
|
|
130
125
|
}
|
|
131
|
-
|
|
126
|
+
if (Node.isPropertyAccessExpression(schema)) {
|
|
127
|
+
const baseExpression = schema.getExpression();
|
|
128
|
+
const propertyName = schema.getName();
|
|
129
|
+
if (Node.isIdentifier(baseExpression)) {
|
|
130
|
+
const className = baseExpression.getText();
|
|
131
|
+
const classDeclaration = handlerData.file.getClass(className);
|
|
132
|
+
if (!classDeclaration) return;
|
|
133
|
+
const staticProperty = classDeclaration.getStaticMember(propertyName);
|
|
134
|
+
if (!staticProperty) return;
|
|
135
|
+
const importPath = classDeclaration.getSourceFile().getFilePath();
|
|
136
|
+
const relativeImportPath = slash(relative(this.#getDestinationDirectory(), importPath));
|
|
137
|
+
return `InferInput<typeof import('${relativeImportPath}').default['${propertyName}']>`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
132
140
|
}
|
|
133
141
|
/**
|
|
134
142
|
* Generate the final interface containing all routes, request, and response
|
|
@@ -215,7 +223,7 @@ var ApiTypesGenerator = class {
|
|
|
215
223
|
if (!file) throw new Error("Unable to create the api.ts file");
|
|
216
224
|
const isTuyauInertiaInstalled = await this.#isTuyauInertiaInstalled();
|
|
217
225
|
file.removeText().insertText(0, (writer) => {
|
|
218
|
-
writer.writeLine(`/* eslint-disable */`).writeLine("// --------------------------------------------------").writeLine("// This file is auto-generated by Tuyau. Do not edit manually !").writeLine("// --------------------------------------------------").writeLine("").writeLine(`import type { MakeTuyauRequest, MakeTuyauResponse } from '@tuyau/utils/types'`).writeLine(`import type { InferInput } from '@vinejs/vine/types'`).newLine();
|
|
226
|
+
writer.writeLine(`// @ts-nocheck`).writeLine(`/* eslint-disable */`).writeLine("// --------------------------------------------------").writeLine("// This file is auto-generated by Tuyau. Do not edit manually !").writeLine("// --------------------------------------------------").writeLine("").writeLine(`import type { MakeTuyauRequest, MakeTuyauResponse } from '@tuyau/utils/types'`).writeLine(`import type { InferInput } from '@vinejs/vine/types'`).newLine();
|
|
219
227
|
Object.entries(options.typesByPattern).forEach(([key, value]) => {
|
|
220
228
|
writer.writeLine(`type ${key} = {`);
|
|
221
229
|
writer.writeLine(` request: ${value.request}`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"@adonisjs/core": "^6.2.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"ts-morph": "^
|
|
26
|
+
"ts-morph": "^25.0.0",
|
|
27
27
|
"@tuyau/utils": "0.0.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@adonisjs/assembler": "^7.8.2",
|
|
31
|
-
"@adonisjs/core": "^6.
|
|
32
|
-
"@poppinss/cliui": "^6.4.
|
|
31
|
+
"@adonisjs/core": "^6.17.1",
|
|
32
|
+
"@poppinss/cliui": "^6.4.2",
|
|
33
33
|
"@poppinss/matchit": "^3.1.2",
|
|
34
|
-
"@types/node": "^22.10.
|
|
35
|
-
"@tuyau/client": "0.2.
|
|
34
|
+
"@types/node": "^22.10.7",
|
|
35
|
+
"@tuyau/client": "0.2.3"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public",
|