@kizunajs/fetch 2.0.0-beta.3 → 2.0.0-beta.4

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/server.cjs CHANGED
@@ -27,6 +27,15 @@ var TypeCollector = class {
27
27
  }
28
28
  };
29
29
  const quote = (value) => JSON.stringify(value);
30
+ /**
31
+ * A literal as the type the JSON carries, so `z.literal(true)` is `true`.
32
+ */
33
+ const literalType = (value) => {
34
+ if (typeof value === "string") return quote(value);
35
+ if (typeof value === "bigint") return `${value}n`;
36
+ if (value === void 0) return "undefined";
37
+ return String(value);
38
+ };
30
39
  const indent$1 = (text, depth = 1) => text.split("\n").map((line) => line.length > 0 ? " ".repeat(depth) + line : line).join("\n");
31
40
  /**
32
41
  * A property name, quoted only when it is not a plain identifier.
@@ -165,14 +174,21 @@ const typeOf = (schema, collector, hint) => {
165
174
  return side ? typeOf(side, collector, hint) : "unknown";
166
175
  }
167
176
  const modelName = (0, kizunajs_generator.readMetaId)(schema);
168
- if (modelName !== void 0 && def.type === "object") {
177
+ if (modelName !== void 0) {
169
178
  if (collector.claim(modelName)) collector.add({
170
179
  name: modelName,
171
180
  description: (0, kizunajs_generator.readMetaDescription)(schema),
172
- body: objectBody(schema, collector, modelName)
181
+ body: structuralType(schema, collector, modelName)
173
182
  });
174
183
  return modelName;
175
184
  }
185
+ return structuralType(schema, collector, hint);
186
+ };
187
+ /**
188
+ * The type a schema describes by its shape, its name already spent by the caller.
189
+ */
190
+ const structuralType = (schema, collector, hint) => {
191
+ const def = (0, kizunajs_generator.readDef)(schema);
176
192
  switch (def.type) {
177
193
  case "string": return "string";
178
194
  case "number":
@@ -188,11 +204,11 @@ const typeOf = (schema, collector, hint) => {
188
204
  case "undefined": return "undefined";
189
205
  case "literal": {
190
206
  const values = def.values ?? [];
191
- return values.length > 0 ? values.map((value) => quote(String(value))).join(" | ") : "never";
207
+ return values.length > 0 ? values.map(literalType).join(" | ") : "never";
192
208
  }
193
209
  case "enum": {
194
210
  const values = Object.values(def.entries ?? {});
195
- return values.length > 0 ? values.map((value) => quote(String(value))).join(" | ") : "never";
211
+ return values.length > 0 ? values.map(literalType).join(" | ") : "never";
196
212
  }
197
213
  case "array": return def.element ? `Array<${typeOf(def.element, collector, `${hint}Item`)}>` : "unknown[]";
198
214
  case "object": return objectBody(schema, collector, hint);
package/dist/server.mjs CHANGED
@@ -26,6 +26,15 @@ var TypeCollector = class {
26
26
  }
27
27
  };
28
28
  const quote = (value) => JSON.stringify(value);
29
+ /**
30
+ * A literal as the type the JSON carries, so `z.literal(true)` is `true`.
31
+ */
32
+ const literalType = (value) => {
33
+ if (typeof value === "string") return quote(value);
34
+ if (typeof value === "bigint") return `${value}n`;
35
+ if (value === void 0) return "undefined";
36
+ return String(value);
37
+ };
29
38
  const indent$1 = (text, depth = 1) => text.split("\n").map((line) => line.length > 0 ? " ".repeat(depth) + line : line).join("\n");
30
39
  /**
31
40
  * A property name, quoted only when it is not a plain identifier.
@@ -164,14 +173,21 @@ const typeOf = (schema, collector, hint) => {
164
173
  return side ? typeOf(side, collector, hint) : "unknown";
165
174
  }
166
175
  const modelName = readMetaId(schema);
167
- if (modelName !== void 0 && def.type === "object") {
176
+ if (modelName !== void 0) {
168
177
  if (collector.claim(modelName)) collector.add({
169
178
  name: modelName,
170
179
  description: readMetaDescription(schema),
171
- body: objectBody(schema, collector, modelName)
180
+ body: structuralType(schema, collector, modelName)
172
181
  });
173
182
  return modelName;
174
183
  }
184
+ return structuralType(schema, collector, hint);
185
+ };
186
+ /**
187
+ * The type a schema describes by its shape, its name already spent by the caller.
188
+ */
189
+ const structuralType = (schema, collector, hint) => {
190
+ const def = readDef(schema);
175
191
  switch (def.type) {
176
192
  case "string": return "string";
177
193
  case "number":
@@ -187,11 +203,11 @@ const typeOf = (schema, collector, hint) => {
187
203
  case "undefined": return "undefined";
188
204
  case "literal": {
189
205
  const values = def.values ?? [];
190
- return values.length > 0 ? values.map((value) => quote(String(value))).join(" | ") : "never";
206
+ return values.length > 0 ? values.map(literalType).join(" | ") : "never";
191
207
  }
192
208
  case "enum": {
193
209
  const values = Object.values(def.entries ?? {});
194
- return values.length > 0 ? values.map((value) => quote(String(value))).join(" | ") : "never";
210
+ return values.length > 0 ? values.map(literalType).join(" | ") : "never";
195
211
  }
196
212
  case "array": return def.element ? `Array<${typeOf(def.element, collector, `${hint}Item`)}>` : "unknown[]";
197
213
  case "object": return objectBody(schema, collector, hint);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/fetch",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "Typed fetch client for Kizuna.js APIs",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "zod": "^4.0.0",
71
- "kizunajs": "2.0.0-beta.3"
71
+ "kizunajs": "2.0.0-beta.4"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/express": "^5.0.0",
@@ -76,8 +76,8 @@
76
76
  "tsdown": "^0.21.0",
77
77
  "typescript": "^6.0.3",
78
78
  "zod": "^4.0.0",
79
- "kizunajs": "2.0.0-beta.3",
80
- "@kizunajs/express": "2.0.0-beta.3"
79
+ "kizunajs": "2.0.0-beta.4",
80
+ "@kizunajs/express": "2.0.0-beta.4"
81
81
  },
82
82
  "scripts": {
83
83
  "build": "tsdown src/index.ts src/server.ts --format esm,cjs --dts --clean --external kizunajs --external zod",