ccusage 11.0.0 → 11.0.2
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/README.md +23 -1
- package/dist/arktype-C-GObzDh-Bx7Fdrqj.js +2 -0
- package/dist/{calculate-cost-2IwHSzmi.js → calculate-cost-D3IraeGW.js} +16 -4
- package/dist/calculate-cost.d.ts +26 -2
- package/dist/calculate-cost.js +2 -3
- package/dist/core-eFvU0K4V.js +689 -0
- package/dist/{data-loader-BAoqS297.js → data-loader-B2EwZ_7B.js} +446 -392
- package/dist/{data-loader-DPQaq8_n.d.ts → data-loader-dbZm5kOW.d.ts} +116 -25
- package/dist/data-loader.d.ts +3 -3
- package/dist/data-loader.js +4 -5
- package/dist/{debug-DzFJHzM5.js → debug-D4Ka6IrY.js} +21 -12
- package/dist/debug.d.ts +17 -0
- package/dist/debug.js +5 -6
- package/dist/{dist-BZzwBtZs.js → dist-Cb1UHXV5.js} +1 -5
- package/dist/dist-DCvt9hEv.js +1 -4
- package/dist/effect-WSjEuzC9-CZCpOgOT.js +6 -0
- package/dist/{esm-BU3FhOe-.js → esm-D74K9ESq.js} +2 -111
- package/dist/{index-CISmcbXk-CW1Gj6Ab.js → index-CISmcbXk-DpuCarFe.js} +6 -9
- package/dist/index.js +1912 -105
- package/dist/{logger-D3WD64Tx.js → logger-DPEwxrOW.js} +9 -22
- package/dist/logger.d.ts +9 -4
- package/dist/logger.js +2 -3
- package/dist/{mcp-1J7r1g6-.js → mcp-CklIto13.js} +366 -947
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +7 -8
- package/dist/{pricing-fetcher-D-eJQBEJ.js → pricing-fetcher-DDs53oR8.js} +151 -14
- package/dist/{pricing-fetcher-BkSZh4lR.d.ts → pricing-fetcher-DHaTs-k2.d.ts} +67 -2
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +3 -4
- package/dist/{prompt-DtZgx4wU.js → prompt-CUbwSrjo.js} +1 -5
- package/dist/sury-DmrZ3_Oj-Lq7x0IZW.js +6 -0
- package/dist/{types-BlyCnKwN.js → types-5-VF7WcO.js} +1 -22
- package/dist/valibot-CQk-M5rL-btpzU8Qa.js +6 -0
- package/dist/{zod-Db63SLXj-BIXn64AP.js → zod-Db63SLXj-BqWqpKnQ.js} +4 -8
- package/package.json +1 -2
- package/dist/arktype-C-GObzDh-CNoBqQrr.js +0 -5
- package/dist/chunk-BLXvPPr8.js +0 -30
- package/dist/core-DHCbAXJf.js +0 -693
- package/dist/effect-WSjEuzC9-DHMVzzyB.js +0 -10
- package/dist/sury-DmrZ3_Oj-Cpjsc2Lm.js +0 -10
- package/dist/utils.table-USks3NGv.js +0 -1844
- package/dist/utils.table.d.ts +0 -27
- package/dist/utils.table.js +0 -3
- package/dist/valibot-CQk-M5rL-BcaCeUrF.js +0 -10
package/dist/core-DHCbAXJf.js
DELETED
|
@@ -1,693 +0,0 @@
|
|
|
1
|
-
//#region node_modules/zod/dist/esm/v4/core/util.js
|
|
2
|
-
function getEnumValues(entries) {
|
|
3
|
-
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
4
|
-
const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
5
|
-
return values;
|
|
6
|
-
}
|
|
7
|
-
function cached(getter) {
|
|
8
|
-
const set = false;
|
|
9
|
-
return { get value() {
|
|
10
|
-
if (!set) {
|
|
11
|
-
const value = getter();
|
|
12
|
-
Object.defineProperty(this, "value", { value });
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
throw new Error("cached value already set");
|
|
16
|
-
} };
|
|
17
|
-
}
|
|
18
|
-
const allowsEval = cached(() => {
|
|
19
|
-
try {
|
|
20
|
-
const F = Function;
|
|
21
|
-
new F("");
|
|
22
|
-
return true;
|
|
23
|
-
} catch (_) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const NUMBER_FORMAT_RANGES = {
|
|
28
|
-
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
29
|
-
int32: [-2147483648, 2147483647],
|
|
30
|
-
uint32: [0, 4294967295],
|
|
31
|
-
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
32
|
-
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region node_modules/zod/dist/esm/v4/core/registries.js
|
|
37
|
-
const $output = Symbol("ZodOutput");
|
|
38
|
-
const $input = Symbol("ZodInput");
|
|
39
|
-
var $ZodRegistry = class {
|
|
40
|
-
constructor() {
|
|
41
|
-
this._map = /* @__PURE__ */ new WeakMap();
|
|
42
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
43
|
-
}
|
|
44
|
-
add(schema, ..._meta) {
|
|
45
|
-
const meta = _meta[0];
|
|
46
|
-
this._map.set(schema, meta);
|
|
47
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
48
|
-
if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
49
|
-
this._idmap.set(meta.id, schema);
|
|
50
|
-
}
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
remove(schema) {
|
|
54
|
-
this._map.delete(schema);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
get(schema) {
|
|
58
|
-
const p = schema._zod.parent;
|
|
59
|
-
if (p) {
|
|
60
|
-
const pm = { ...this.get(p) ?? {} };
|
|
61
|
-
delete pm.id;
|
|
62
|
-
return {
|
|
63
|
-
...pm,
|
|
64
|
-
...this._map.get(schema)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return this._map.get(schema);
|
|
68
|
-
}
|
|
69
|
-
has(schema) {
|
|
70
|
-
return this._map.has(schema);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function registry() {
|
|
74
|
-
return new $ZodRegistry();
|
|
75
|
-
}
|
|
76
|
-
const globalRegistry = /* @__PURE__ */ registry();
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region node_modules/zod/dist/esm/v4/core/to-json-schema.js
|
|
80
|
-
var JSONSchemaGenerator = class {
|
|
81
|
-
constructor(params) {
|
|
82
|
-
this.counter = 0;
|
|
83
|
-
this.metadataRegistry = params?.metadata ?? globalRegistry;
|
|
84
|
-
this.target = params?.target ?? "draft-2020-12";
|
|
85
|
-
this.unrepresentable = params?.unrepresentable ?? "throw";
|
|
86
|
-
this.override = params?.override ?? (() => {});
|
|
87
|
-
this.io = params?.io ?? "output";
|
|
88
|
-
this.seen = /* @__PURE__ */ new Map();
|
|
89
|
-
}
|
|
90
|
-
process(schema, _params = {
|
|
91
|
-
path: [],
|
|
92
|
-
schemaPath: []
|
|
93
|
-
}) {
|
|
94
|
-
var _a;
|
|
95
|
-
const def = schema._zod.def;
|
|
96
|
-
const formatMap = {
|
|
97
|
-
guid: "uuid",
|
|
98
|
-
url: "uri",
|
|
99
|
-
datetime: "date-time",
|
|
100
|
-
json_string: "json-string",
|
|
101
|
-
regex: ""
|
|
102
|
-
};
|
|
103
|
-
const seen = this.seen.get(schema);
|
|
104
|
-
if (seen) {
|
|
105
|
-
seen.count++;
|
|
106
|
-
const isCycle = _params.schemaPath.includes(schema);
|
|
107
|
-
if (isCycle) seen.cycle = _params.path;
|
|
108
|
-
return seen.schema;
|
|
109
|
-
}
|
|
110
|
-
const result = {
|
|
111
|
-
schema: {},
|
|
112
|
-
count: 1,
|
|
113
|
-
cycle: void 0
|
|
114
|
-
};
|
|
115
|
-
this.seen.set(schema, result);
|
|
116
|
-
if (schema._zod.toJSONSchema) result.schema = schema._zod.toJSONSchema();
|
|
117
|
-
const params = {
|
|
118
|
-
..._params,
|
|
119
|
-
schemaPath: [..._params.schemaPath, schema],
|
|
120
|
-
path: _params.path
|
|
121
|
-
};
|
|
122
|
-
const parent = schema._zod.parent;
|
|
123
|
-
if (parent) {
|
|
124
|
-
result.ref = parent;
|
|
125
|
-
this.process(parent, params);
|
|
126
|
-
this.seen.get(parent).isParent = true;
|
|
127
|
-
} else {
|
|
128
|
-
const _json = result.schema;
|
|
129
|
-
switch (def.type) {
|
|
130
|
-
case "string": {
|
|
131
|
-
const json = _json;
|
|
132
|
-
json.type = "string";
|
|
133
|
-
const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
|
|
134
|
-
if (typeof minimum === "number") json.minLength = minimum;
|
|
135
|
-
if (typeof maximum === "number") json.maxLength = maximum;
|
|
136
|
-
if (format) {
|
|
137
|
-
json.format = formatMap[format] ?? format;
|
|
138
|
-
if (json.format === "") delete json.format;
|
|
139
|
-
}
|
|
140
|
-
if (contentEncoding) json.contentEncoding = contentEncoding;
|
|
141
|
-
if (patterns && patterns.size > 0) {
|
|
142
|
-
const regexes = [...patterns];
|
|
143
|
-
if (regexes.length === 1) json.pattern = regexes[0].source;
|
|
144
|
-
else if (regexes.length > 1) result.schema.allOf = [...regexes.map((regex) => ({
|
|
145
|
-
...this.target === "draft-7" ? { type: "string" } : {},
|
|
146
|
-
pattern: regex.source
|
|
147
|
-
}))];
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case "number": {
|
|
152
|
-
const json = _json;
|
|
153
|
-
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
154
|
-
if (typeof format === "string" && format.includes("int")) json.type = "integer";
|
|
155
|
-
else json.type = "number";
|
|
156
|
-
if (typeof exclusiveMinimum === "number") json.exclusiveMinimum = exclusiveMinimum;
|
|
157
|
-
if (typeof minimum === "number") {
|
|
158
|
-
json.minimum = minimum;
|
|
159
|
-
if (typeof exclusiveMinimum === "number") if (exclusiveMinimum >= minimum) delete json.minimum;
|
|
160
|
-
else delete json.exclusiveMinimum;
|
|
161
|
-
}
|
|
162
|
-
if (typeof exclusiveMaximum === "number") json.exclusiveMaximum = exclusiveMaximum;
|
|
163
|
-
if (typeof maximum === "number") {
|
|
164
|
-
json.maximum = maximum;
|
|
165
|
-
if (typeof exclusiveMaximum === "number") if (exclusiveMaximum <= maximum) delete json.maximum;
|
|
166
|
-
else delete json.exclusiveMaximum;
|
|
167
|
-
}
|
|
168
|
-
if (typeof multipleOf === "number") json.multipleOf = multipleOf;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
case "boolean": {
|
|
172
|
-
const json = _json;
|
|
173
|
-
json.type = "boolean";
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
case "bigint": {
|
|
177
|
-
if (this.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case "symbol": {
|
|
181
|
-
if (this.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
case "undefined": {
|
|
185
|
-
const json = _json;
|
|
186
|
-
json.type = "null";
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
case "null": {
|
|
190
|
-
_json.type = "null";
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
case "any": break;
|
|
194
|
-
case "unknown": break;
|
|
195
|
-
case "never": {
|
|
196
|
-
_json.not = {};
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case "void": {
|
|
200
|
-
if (this.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
case "date": {
|
|
204
|
-
if (this.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
case "array": {
|
|
208
|
-
const json = _json;
|
|
209
|
-
const { minimum, maximum } = schema._zod.bag;
|
|
210
|
-
if (typeof minimum === "number") json.minItems = minimum;
|
|
211
|
-
if (typeof maximum === "number") json.maxItems = maximum;
|
|
212
|
-
json.type = "array";
|
|
213
|
-
json.items = this.process(def.element, {
|
|
214
|
-
...params,
|
|
215
|
-
path: [...params.path, "items"]
|
|
216
|
-
});
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
case "object": {
|
|
220
|
-
const json = _json;
|
|
221
|
-
json.type = "object";
|
|
222
|
-
json.properties = {};
|
|
223
|
-
const shape = def.shape;
|
|
224
|
-
for (const key in shape) json.properties[key] = this.process(shape[key], {
|
|
225
|
-
...params,
|
|
226
|
-
path: [
|
|
227
|
-
...params.path,
|
|
228
|
-
"properties",
|
|
229
|
-
key
|
|
230
|
-
]
|
|
231
|
-
});
|
|
232
|
-
const allKeys = new Set(Object.keys(shape));
|
|
233
|
-
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
234
|
-
const v = def.shape[key]._zod;
|
|
235
|
-
if (this.io === "input") return v.optin === void 0;
|
|
236
|
-
else return v.optout === void 0;
|
|
237
|
-
}));
|
|
238
|
-
if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
|
|
239
|
-
if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
|
|
240
|
-
else if (!def.catchall) {
|
|
241
|
-
if (this.io === "output") json.additionalProperties = false;
|
|
242
|
-
} else if (def.catchall) json.additionalProperties = this.process(def.catchall, {
|
|
243
|
-
...params,
|
|
244
|
-
path: [...params.path, "additionalProperties"]
|
|
245
|
-
});
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
case "union": {
|
|
249
|
-
const json = _json;
|
|
250
|
-
json.anyOf = def.options.map((x, i) => this.process(x, {
|
|
251
|
-
...params,
|
|
252
|
-
path: [
|
|
253
|
-
...params.path,
|
|
254
|
-
"anyOf",
|
|
255
|
-
i
|
|
256
|
-
]
|
|
257
|
-
}));
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
case "intersection": {
|
|
261
|
-
const json = _json;
|
|
262
|
-
const a = this.process(def.left, {
|
|
263
|
-
...params,
|
|
264
|
-
path: [
|
|
265
|
-
...params.path,
|
|
266
|
-
"allOf",
|
|
267
|
-
0
|
|
268
|
-
]
|
|
269
|
-
});
|
|
270
|
-
const b = this.process(def.right, {
|
|
271
|
-
...params,
|
|
272
|
-
path: [
|
|
273
|
-
...params.path,
|
|
274
|
-
"allOf",
|
|
275
|
-
1
|
|
276
|
-
]
|
|
277
|
-
});
|
|
278
|
-
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
279
|
-
const allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
|
|
280
|
-
json.allOf = allOf;
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
case "tuple": {
|
|
284
|
-
const json = _json;
|
|
285
|
-
json.type = "array";
|
|
286
|
-
const prefixItems = def.items.map((x, i) => this.process(x, {
|
|
287
|
-
...params,
|
|
288
|
-
path: [
|
|
289
|
-
...params.path,
|
|
290
|
-
"prefixItems",
|
|
291
|
-
i
|
|
292
|
-
]
|
|
293
|
-
}));
|
|
294
|
-
if (this.target === "draft-2020-12") json.prefixItems = prefixItems;
|
|
295
|
-
else json.items = prefixItems;
|
|
296
|
-
if (def.rest) {
|
|
297
|
-
const rest = this.process(def.rest, {
|
|
298
|
-
...params,
|
|
299
|
-
path: [...params.path, "items"]
|
|
300
|
-
});
|
|
301
|
-
if (this.target === "draft-2020-12") json.items = rest;
|
|
302
|
-
else json.additionalItems = rest;
|
|
303
|
-
}
|
|
304
|
-
if (def.rest) json.items = this.process(def.rest, {
|
|
305
|
-
...params,
|
|
306
|
-
path: [...params.path, "items"]
|
|
307
|
-
});
|
|
308
|
-
const { minimum, maximum } = schema._zod.bag;
|
|
309
|
-
if (typeof minimum === "number") json.minItems = minimum;
|
|
310
|
-
if (typeof maximum === "number") json.maxItems = maximum;
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
case "record": {
|
|
314
|
-
const json = _json;
|
|
315
|
-
json.type = "object";
|
|
316
|
-
json.propertyNames = this.process(def.keyType, {
|
|
317
|
-
...params,
|
|
318
|
-
path: [...params.path, "propertyNames"]
|
|
319
|
-
});
|
|
320
|
-
json.additionalProperties = this.process(def.valueType, {
|
|
321
|
-
...params,
|
|
322
|
-
path: [...params.path, "additionalProperties"]
|
|
323
|
-
});
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
case "map": {
|
|
327
|
-
if (this.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
case "set": {
|
|
331
|
-
if (this.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
case "enum": {
|
|
335
|
-
const json = _json;
|
|
336
|
-
const values = getEnumValues(def.entries);
|
|
337
|
-
if (values.every((v) => typeof v === "number")) json.type = "number";
|
|
338
|
-
if (values.every((v) => typeof v === "string")) json.type = "string";
|
|
339
|
-
json.enum = values;
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
case "literal": {
|
|
343
|
-
const json = _json;
|
|
344
|
-
const vals = [];
|
|
345
|
-
for (const val of def.values) if (val === void 0) {
|
|
346
|
-
if (this.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
347
|
-
} else if (typeof val === "bigint") if (this.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
348
|
-
else vals.push(Number(val));
|
|
349
|
-
else vals.push(val);
|
|
350
|
-
if (vals.length === 0) {} else if (vals.length === 1) {
|
|
351
|
-
const val = vals[0];
|
|
352
|
-
json.type = val === null ? "null" : typeof val;
|
|
353
|
-
json.const = val;
|
|
354
|
-
} else {
|
|
355
|
-
if (vals.every((v) => typeof v === "number")) json.type = "number";
|
|
356
|
-
if (vals.every((v) => typeof v === "string")) json.type = "string";
|
|
357
|
-
if (vals.every((v) => typeof v === "boolean")) json.type = "string";
|
|
358
|
-
if (vals.every((v) => v === null)) json.type = "null";
|
|
359
|
-
json.enum = vals;
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case "file": {
|
|
364
|
-
const json = _json;
|
|
365
|
-
const file = {
|
|
366
|
-
type: "string",
|
|
367
|
-
format: "binary",
|
|
368
|
-
contentEncoding: "binary"
|
|
369
|
-
};
|
|
370
|
-
const { minimum, maximum, mime } = schema._zod.bag;
|
|
371
|
-
if (minimum !== void 0) file.minLength = minimum;
|
|
372
|
-
if (maximum !== void 0) file.maxLength = maximum;
|
|
373
|
-
if (mime) if (mime.length === 1) {
|
|
374
|
-
file.contentMediaType = mime[0];
|
|
375
|
-
Object.assign(json, file);
|
|
376
|
-
} else json.anyOf = mime.map((m) => {
|
|
377
|
-
const mFile = {
|
|
378
|
-
...file,
|
|
379
|
-
contentMediaType: m
|
|
380
|
-
};
|
|
381
|
-
return mFile;
|
|
382
|
-
});
|
|
383
|
-
else Object.assign(json, file);
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
case "transform": {
|
|
387
|
-
if (this.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
case "nullable": {
|
|
391
|
-
const inner = this.process(def.innerType, params);
|
|
392
|
-
_json.anyOf = [inner, { type: "null" }];
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
case "nonoptional": {
|
|
396
|
-
this.process(def.innerType, params);
|
|
397
|
-
result.ref = def.innerType;
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
case "success": {
|
|
401
|
-
const json = _json;
|
|
402
|
-
json.type = "boolean";
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
case "default": {
|
|
406
|
-
this.process(def.innerType, params);
|
|
407
|
-
result.ref = def.innerType;
|
|
408
|
-
_json.default = def.defaultValue;
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
case "prefault": {
|
|
412
|
-
this.process(def.innerType, params);
|
|
413
|
-
result.ref = def.innerType;
|
|
414
|
-
if (this.io === "input") _json._prefault = def.defaultValue;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
case "catch": {
|
|
418
|
-
this.process(def.innerType, params);
|
|
419
|
-
result.ref = def.innerType;
|
|
420
|
-
let catchValue;
|
|
421
|
-
try {
|
|
422
|
-
catchValue = def.catchValue(void 0);
|
|
423
|
-
} catch {
|
|
424
|
-
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
425
|
-
}
|
|
426
|
-
_json.default = catchValue;
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
case "nan": {
|
|
430
|
-
if (this.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
case "template_literal": {
|
|
434
|
-
const json = _json;
|
|
435
|
-
const pattern = schema._zod.pattern;
|
|
436
|
-
if (!pattern) throw new Error("Pattern not found in template literal");
|
|
437
|
-
json.type = "string";
|
|
438
|
-
json.pattern = pattern.source;
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
case "pipe": {
|
|
442
|
-
const innerType = this.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
443
|
-
this.process(innerType, params);
|
|
444
|
-
result.ref = innerType;
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
case "readonly": {
|
|
448
|
-
this.process(def.innerType, params);
|
|
449
|
-
result.ref = def.innerType;
|
|
450
|
-
_json.readOnly = true;
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
|
-
case "promise": {
|
|
454
|
-
this.process(def.innerType, params);
|
|
455
|
-
result.ref = def.innerType;
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
case "optional": {
|
|
459
|
-
this.process(def.innerType, params);
|
|
460
|
-
result.ref = def.innerType;
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
case "lazy": {
|
|
464
|
-
const innerType = schema._zod.innerType;
|
|
465
|
-
this.process(innerType, params);
|
|
466
|
-
result.ref = innerType;
|
|
467
|
-
break;
|
|
468
|
-
}
|
|
469
|
-
case "custom": {
|
|
470
|
-
if (this.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
default: {}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
const meta = this.metadataRegistry.get(schema);
|
|
477
|
-
if (meta) Object.assign(result.schema, meta);
|
|
478
|
-
if (this.io === "input" && isTransforming(schema)) {
|
|
479
|
-
delete result.schema.examples;
|
|
480
|
-
delete result.schema.default;
|
|
481
|
-
}
|
|
482
|
-
if (this.io === "input" && result.schema._prefault) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
|
|
483
|
-
delete result.schema._prefault;
|
|
484
|
-
const _result = this.seen.get(schema);
|
|
485
|
-
return _result.schema;
|
|
486
|
-
}
|
|
487
|
-
emit(schema, _params) {
|
|
488
|
-
const params = {
|
|
489
|
-
cycles: _params?.cycles ?? "ref",
|
|
490
|
-
reused: _params?.reused ?? "inline",
|
|
491
|
-
external: _params?.external ?? void 0
|
|
492
|
-
};
|
|
493
|
-
const root = this.seen.get(schema);
|
|
494
|
-
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
495
|
-
const makeURI = (entry) => {
|
|
496
|
-
const defsSegment = this.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
497
|
-
if (params.external) {
|
|
498
|
-
const externalId = params.external.registry.get(entry[0])?.id;
|
|
499
|
-
if (externalId) return { ref: params.external.uri(externalId) };
|
|
500
|
-
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${this.counter++}`;
|
|
501
|
-
entry[1].defId = id;
|
|
502
|
-
return {
|
|
503
|
-
defId: id,
|
|
504
|
-
ref: `${params.external.uri("__shared")}#/${defsSegment}/${id}`
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
if (entry[1] === root) return { ref: "#" };
|
|
508
|
-
const uriPrefix = `#`;
|
|
509
|
-
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
510
|
-
const defId = entry[1].schema.id ?? `__schema${this.counter++}`;
|
|
511
|
-
return {
|
|
512
|
-
defId,
|
|
513
|
-
ref: defUriPrefix + defId
|
|
514
|
-
};
|
|
515
|
-
};
|
|
516
|
-
const extractToDef = (entry) => {
|
|
517
|
-
if (entry[1].schema.$ref) return;
|
|
518
|
-
const seen = entry[1];
|
|
519
|
-
const { ref, defId } = makeURI(entry);
|
|
520
|
-
seen.def = { ...seen.schema };
|
|
521
|
-
if (defId) seen.defId = defId;
|
|
522
|
-
const schema$1 = seen.schema;
|
|
523
|
-
for (const key in schema$1) delete schema$1[key];
|
|
524
|
-
schema$1.$ref = ref;
|
|
525
|
-
};
|
|
526
|
-
for (const entry of this.seen.entries()) {
|
|
527
|
-
const seen = entry[1];
|
|
528
|
-
if (schema === entry[0]) {
|
|
529
|
-
extractToDef(entry);
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
if (params.external) {
|
|
533
|
-
const ext = params.external.registry.get(entry[0])?.id;
|
|
534
|
-
if (schema !== entry[0] && ext) {
|
|
535
|
-
extractToDef(entry);
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const id = this.metadataRegistry.get(entry[0])?.id;
|
|
540
|
-
if (id) {
|
|
541
|
-
extractToDef(entry);
|
|
542
|
-
continue;
|
|
543
|
-
}
|
|
544
|
-
if (seen.cycle) {
|
|
545
|
-
if (params.cycles === "throw") throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
|
|
546
|
-
|
|
547
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
|
|
548
|
-
else if (params.cycles === "ref") extractToDef(entry);
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
|
-
if (seen.count > 1) {
|
|
552
|
-
if (params.reused === "ref") {
|
|
553
|
-
extractToDef(entry);
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
const flattenRef = (zodSchema, params$1) => {
|
|
559
|
-
const seen = this.seen.get(zodSchema);
|
|
560
|
-
const schema$1 = seen.def ?? seen.schema;
|
|
561
|
-
const _cached = { ...schema$1 };
|
|
562
|
-
if (seen.ref === null) return;
|
|
563
|
-
const ref = seen.ref;
|
|
564
|
-
seen.ref = null;
|
|
565
|
-
if (ref) {
|
|
566
|
-
flattenRef(ref, params$1);
|
|
567
|
-
const refSchema = this.seen.get(ref).schema;
|
|
568
|
-
if (refSchema.$ref && params$1.target === "draft-7") {
|
|
569
|
-
schema$1.allOf = schema$1.allOf ?? [];
|
|
570
|
-
schema$1.allOf.push(refSchema);
|
|
571
|
-
} else {
|
|
572
|
-
Object.assign(schema$1, refSchema);
|
|
573
|
-
Object.assign(schema$1, _cached);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (!seen.isParent) this.override({
|
|
577
|
-
zodSchema,
|
|
578
|
-
jsonSchema: schema$1
|
|
579
|
-
});
|
|
580
|
-
};
|
|
581
|
-
for (const entry of [...this.seen.entries()].reverse()) flattenRef(entry[0], { target: this.target });
|
|
582
|
-
const result = {};
|
|
583
|
-
if (this.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
584
|
-
else if (this.target === "draft-7") result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
585
|
-
else console.warn(`Invalid target: ${this.target}`);
|
|
586
|
-
Object.assign(result, root.def);
|
|
587
|
-
const defs = params.external?.defs ?? {};
|
|
588
|
-
for (const entry of this.seen.entries()) {
|
|
589
|
-
const seen = entry[1];
|
|
590
|
-
if (seen.def && seen.defId) defs[seen.defId] = seen.def;
|
|
591
|
-
}
|
|
592
|
-
if (!params.external && Object.keys(defs).length > 0) if (this.target === "draft-2020-12") result.$defs = defs;
|
|
593
|
-
else result.definitions = defs;
|
|
594
|
-
try {
|
|
595
|
-
return JSON.parse(JSON.stringify(result));
|
|
596
|
-
} catch (_err) {
|
|
597
|
-
throw new Error("Error converting schema to JSON.");
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
function toJSONSchema(input, _params) {
|
|
602
|
-
if (input instanceof $ZodRegistry) {
|
|
603
|
-
const gen$1 = new JSONSchemaGenerator(_params);
|
|
604
|
-
const defs = {};
|
|
605
|
-
for (const entry of input._idmap.entries()) {
|
|
606
|
-
const [_, schema] = entry;
|
|
607
|
-
gen$1.process(schema);
|
|
608
|
-
}
|
|
609
|
-
const schemas = {};
|
|
610
|
-
const external = {
|
|
611
|
-
registry: input,
|
|
612
|
-
uri: _params?.uri || ((id) => id),
|
|
613
|
-
defs
|
|
614
|
-
};
|
|
615
|
-
for (const entry of input._idmap.entries()) {
|
|
616
|
-
const [key, schema] = entry;
|
|
617
|
-
schemas[key] = gen$1.emit(schema, {
|
|
618
|
-
..._params,
|
|
619
|
-
external
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
if (Object.keys(defs).length > 0) {
|
|
623
|
-
const defsSegment = gen$1.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
624
|
-
schemas.__shared = { [defsSegment]: defs };
|
|
625
|
-
}
|
|
626
|
-
return { schemas };
|
|
627
|
-
}
|
|
628
|
-
const gen = new JSONSchemaGenerator(_params);
|
|
629
|
-
gen.process(input);
|
|
630
|
-
return gen.emit(input, _params);
|
|
631
|
-
}
|
|
632
|
-
function isTransforming(_schema, _ctx) {
|
|
633
|
-
const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
|
|
634
|
-
if (ctx.seen.has(_schema)) return false;
|
|
635
|
-
ctx.seen.add(_schema);
|
|
636
|
-
const schema = _schema;
|
|
637
|
-
const def = schema._zod.def;
|
|
638
|
-
switch (def.type) {
|
|
639
|
-
case "string":
|
|
640
|
-
case "number":
|
|
641
|
-
case "bigint":
|
|
642
|
-
case "boolean":
|
|
643
|
-
case "date":
|
|
644
|
-
case "symbol":
|
|
645
|
-
case "undefined":
|
|
646
|
-
case "null":
|
|
647
|
-
case "any":
|
|
648
|
-
case "unknown":
|
|
649
|
-
case "never":
|
|
650
|
-
case "void":
|
|
651
|
-
case "literal":
|
|
652
|
-
case "enum":
|
|
653
|
-
case "nan":
|
|
654
|
-
case "file":
|
|
655
|
-
case "template_literal": return false;
|
|
656
|
-
case "array": return isTransforming(def.element, ctx);
|
|
657
|
-
case "object": {
|
|
658
|
-
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
case "union": {
|
|
662
|
-
for (const option of def.options) if (isTransforming(option, ctx)) return true;
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
case "intersection": return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
666
|
-
case "tuple": {
|
|
667
|
-
for (const item of def.items) if (isTransforming(item, ctx)) return true;
|
|
668
|
-
if (def.rest && isTransforming(def.rest, ctx)) return true;
|
|
669
|
-
return false;
|
|
670
|
-
}
|
|
671
|
-
case "record": return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
672
|
-
case "map": return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
673
|
-
case "set": return isTransforming(def.valueType, ctx);
|
|
674
|
-
case "promise":
|
|
675
|
-
case "optional":
|
|
676
|
-
case "nonoptional":
|
|
677
|
-
case "nullable":
|
|
678
|
-
case "readonly": return isTransforming(def.innerType, ctx);
|
|
679
|
-
case "lazy": return isTransforming(def.getter(), ctx);
|
|
680
|
-
case "default": return isTransforming(def.innerType, ctx);
|
|
681
|
-
case "prefault": return isTransforming(def.innerType, ctx);
|
|
682
|
-
case "custom": return false;
|
|
683
|
-
case "transform": return true;
|
|
684
|
-
case "pipe": return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
685
|
-
case "success": return false;
|
|
686
|
-
case "catch": return false;
|
|
687
|
-
default:
|
|
688
|
-
}
|
|
689
|
-
throw new Error(`Unknown schema type: ${def.type}`);
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
//#endregion
|
|
693
|
-
export { toJSONSchema };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { tryImport } from "./index-CISmcbXk-CW1Gj6Ab.js";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/xsschema/dist/effect-WSjEuzC9.js
|
|
4
|
-
const getToJsonSchemaFn = async () => {
|
|
5
|
-
const { JSONSchema } = await tryImport(import("effect"), "effect");
|
|
6
|
-
return (schema) => JSONSchema.make(schema);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { getToJsonSchemaFn };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { tryImport } from "./index-CISmcbXk-CW1Gj6Ab.js";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/xsschema/dist/sury-DmrZ3_Oj.js
|
|
4
|
-
const getToJsonSchemaFn = async () => {
|
|
5
|
-
const { toJSONSchema } = await tryImport(import("sury"), "sury");
|
|
6
|
-
return (schema) => toJSONSchema(schema);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { getToJsonSchemaFn };
|