@vafast/cli 0.1.2 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- import { syncTypes } from "./sync-DU-mhmR1.js";
1
+ import { syncTypes } from "./sync-Bokzgg9Z.js";
2
2
  import { cac } from "cac";
3
3
 
4
4
  //#region src/cli.ts
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { schemaToType, syncTypes } from "./sync-DU-mhmR1.js";
1
+ import { schemaToType, syncTypes } from "./sync-Bokzgg9Z.js";
2
2
 
3
3
  export { schemaToType, syncTypes };
@@ -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
- if (key === ":id") lines.push(`${pad}':id': {`);
145
- else lines.push(`${pad}${key}: {`);
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} */`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vafast/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Vafast CLI - 类型同步和开发工具",
5
5
  "type": "module",
6
6
  "bin": {