@tuyau/core 0.1.0 → 0.1.1
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.
|
@@ -127,10 +127,22 @@ var ApiTypesGenerator = class {
|
|
|
127
127
|
return true;
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Generate a type name based on the route pattern and methods
|
|
132
|
+
*
|
|
133
|
+
* GET /users/:id => UsersIdGet
|
|
134
|
+
*/
|
|
135
|
+
#generateTypeName(route) {
|
|
136
|
+
const remappedSegments = route.pattern.split("/").filter(Boolean).map((segment) => segment.startsWith(":") ? "id" : segment).join(" ");
|
|
137
|
+
const methods = string.pascalCase(route.methods.join(" "));
|
|
138
|
+
return string.pascalCase(remappedSegments) + methods;
|
|
139
|
+
}
|
|
140
|
+
#generateRoutesNameArray(routes, typesByPattern) {
|
|
131
141
|
return routes.map(({ name, pattern, methods }) => {
|
|
132
142
|
const params = matchit.parse(pattern).filter((node) => node.type !== 0).map((node) => node.val);
|
|
133
|
-
|
|
143
|
+
let typeName = this.#generateTypeName({ pattern, methods });
|
|
144
|
+
if (!typesByPattern[typeName])
|
|
145
|
+
typeName = "unknown";
|
|
134
146
|
return { params, name, path: pattern, method: methods, types: typeName };
|
|
135
147
|
}).filter((route) => !!route.name);
|
|
136
148
|
}
|
|
@@ -196,21 +208,20 @@ var ApiTypesGenerator = class {
|
|
|
196
208
|
currentLevel = currentLevel[segment];
|
|
197
209
|
if (i !== segments.length - 1)
|
|
198
210
|
return;
|
|
199
|
-
const typeName =
|
|
211
|
+
const typeName = this.#generateTypeName(route);
|
|
200
212
|
typesByPattern[typeName] = {
|
|
201
213
|
request: schemaImport ? `MakeTuyauRequest<${schemaImport}>` : "unknown",
|
|
202
214
|
response: `MakeTuyauResponse<import('${relativePath}').default['${routeHandler.method}']>`
|
|
203
215
|
};
|
|
204
216
|
currentLevel.$url = {};
|
|
205
|
-
for (const method of methods)
|
|
206
|
-
currentLevel[method] =
|
|
207
|
-
}
|
|
217
|
+
for (const method of methods)
|
|
218
|
+
currentLevel[method] = typeName;
|
|
208
219
|
});
|
|
209
220
|
}
|
|
210
221
|
await this.#writeApiFile({
|
|
211
222
|
definition,
|
|
212
223
|
typesByPattern,
|
|
213
|
-
routesNameArray: this.#generateRoutesNameArray(routes)
|
|
224
|
+
routesNameArray: this.#generateRoutesNameArray(routes, typesByPattern)
|
|
214
225
|
});
|
|
215
226
|
}
|
|
216
227
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"clean": "del-cli build",
|
|
65
|
-
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
65
|
+
"copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
|
|
66
66
|
"typecheck": "tsc --noEmit",
|
|
67
67
|
"format": "prettier --write .",
|
|
68
68
|
"quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
|
|
File without changes
|