@vafast/cli 0.1.1 → 0.1.3
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/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{sync-DU-mhmR1.js → sync-Bokzgg9Z.js} +14 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,13 +40,22 @@ function arrayToType(schema) {
|
|
|
40
40
|
* 对象类型转换
|
|
41
41
|
*/
|
|
42
42
|
function objectToType(schema) {
|
|
43
|
+
const patternProps = schema.patternProperties;
|
|
44
|
+
if (patternProps) {
|
|
45
|
+
const patterns = Object.values(patternProps);
|
|
46
|
+
if (patterns.length > 0 && patterns[0]) {
|
|
47
|
+
const valueType = schemaToType(patterns[0]);
|
|
48
|
+
return `Record<string, ${valueType}>`;
|
|
49
|
+
}
|
|
50
|
+
return "Record<string, unknown>";
|
|
51
|
+
}
|
|
43
52
|
if (!schema.properties) {
|
|
44
53
|
if (schema.additionalProperties === true) return "Record<string, unknown>";
|
|
45
54
|
if (typeof schema.additionalProperties === "object") {
|
|
46
55
|
const valueType = schemaToType(schema.additionalProperties);
|
|
47
56
|
return `Record<string, ${valueType}>`;
|
|
48
57
|
}
|
|
49
|
-
return "
|
|
58
|
+
return "Record<string, unknown>";
|
|
50
59
|
}
|
|
51
60
|
const required = new Set(schema.required || []);
|
|
52
61
|
const props = [];
|
|
@@ -55,7 +64,7 @@ function objectToType(schema) {
|
|
|
55
64
|
const optional = required.has(key) ? "" : "?";
|
|
56
65
|
props.push(`${key}${optional}: ${propType}`);
|
|
57
66
|
}
|
|
58
|
-
if (props.length === 0) return "
|
|
67
|
+
if (props.length === 0) return "Record<string, unknown>";
|
|
59
68
|
return `{ ${props.join("; ")} }`;
|
|
60
69
|
}
|
|
61
70
|
|
|
@@ -141,8 +150,9 @@ function generateRouteTreeType(tree, indent) {
|
|
|
141
150
|
const lines = [];
|
|
142
151
|
const pad = " ".repeat(indent);
|
|
143
152
|
for (const [key, node] of tree) {
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
const needsQuotes = /[^a-zA-Z0-9_$]/.test(key) || /^\d/.test(key);
|
|
154
|
+
const propName = needsQuotes ? `'${key}'` : key;
|
|
155
|
+
lines.push(`${pad}${propName}: {`);
|
|
146
156
|
for (const [method, route] of node.methods) {
|
|
147
157
|
const methodType = generateMethodType(route);
|
|
148
158
|
if (route.description) lines.push(`${pad} /** ${route.description} */`);
|