@swirls/sdk 0.0.7 → 0.0.8
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/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-YLVKU5J3.js +13775 -0
- package/dist/client/client.js +2 -0
- package/dist/config/config.js +8 -4
- package/dist/form/form.js +132 -129
- package/dist/form/generate.js +741 -2
- package/package.json +11 -9
package/dist/form/generate.js
CHANGED
|
@@ -1,6 +1,745 @@
|
|
|
1
|
+
import "../chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
|
|
4
|
+
var parseAnyOf = (schema, refs) => {
|
|
5
|
+
return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], {
|
|
6
|
+
...refs,
|
|
7
|
+
path: [...refs.path, "anyOf", 0]
|
|
8
|
+
}) : `z.union([${schema.anyOf.map((schema2, i) => parseSchema(schema2, { ...refs, path: [...refs.path, "anyOf", i] })).join(", ")}])` : `z.any()`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseBoolean.js
|
|
12
|
+
var parseBoolean = (_schema) => {
|
|
13
|
+
return "z.boolean()";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseDefault.js
|
|
17
|
+
var parseDefault = (_schema) => {
|
|
18
|
+
return "z.any()";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseMultipleType.js
|
|
22
|
+
var parseMultipleType = (schema, refs) => {
|
|
23
|
+
return `z.union([${schema.type.map((type) => parseSchema({ ...schema, type }, { ...refs, withoutDefaults: true })).join(", ")}])`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNot.js
|
|
27
|
+
var parseNot = (schema, refs) => {
|
|
28
|
+
return `z.any().refine((value) => !${parseSchema(schema.not, {
|
|
29
|
+
...refs,
|
|
30
|
+
path: [...refs.path, "not"]
|
|
31
|
+
})}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNull.js
|
|
35
|
+
var parseNull = (_schema) => {
|
|
36
|
+
return "z.null()";
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/utils/half.js
|
|
40
|
+
var half = (arr) => {
|
|
41
|
+
return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAllOf.js
|
|
45
|
+
var originalIndex = /* @__PURE__ */ Symbol("Original index");
|
|
46
|
+
var ensureOriginalIndex = (arr) => {
|
|
47
|
+
let newArr = [];
|
|
48
|
+
for (let i = 0; i < arr.length; i++) {
|
|
49
|
+
const item = arr[i];
|
|
50
|
+
if (typeof item === "boolean") {
|
|
51
|
+
newArr.push(item ? { [originalIndex]: i } : { [originalIndex]: i, not: {} });
|
|
52
|
+
} else if (originalIndex in item) {
|
|
53
|
+
return arr;
|
|
54
|
+
} else {
|
|
55
|
+
newArr.push({ ...item, [originalIndex]: i });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return newArr;
|
|
59
|
+
};
|
|
60
|
+
function parseAllOf(schema, refs) {
|
|
61
|
+
if (schema.allOf.length === 0) {
|
|
62
|
+
return "z.never()";
|
|
63
|
+
} else if (schema.allOf.length === 1) {
|
|
64
|
+
const item = schema.allOf[0];
|
|
65
|
+
return parseSchema(item, {
|
|
66
|
+
...refs,
|
|
67
|
+
path: [...refs.path, "allOf", item[originalIndex]]
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
const [left, right] = half(ensureOriginalIndex(schema.allOf));
|
|
71
|
+
return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({
|
|
72
|
+
allOf: right
|
|
73
|
+
}, refs)})`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/utils/withMessage.js
|
|
78
|
+
function withMessage(schema, key, get) {
|
|
79
|
+
const value = schema[key];
|
|
80
|
+
let r = "";
|
|
81
|
+
if (value !== void 0) {
|
|
82
|
+
const got = get({ value, json: JSON.stringify(value) });
|
|
83
|
+
if (got) {
|
|
84
|
+
const opener = got[0];
|
|
85
|
+
const prefix = got.length === 3 ? got[1] : "";
|
|
86
|
+
const closer = got.length === 3 ? got[2] : got[1];
|
|
87
|
+
r += opener;
|
|
88
|
+
if (schema.errorMessage?.[key] !== void 0) {
|
|
89
|
+
r += prefix + JSON.stringify(schema.errorMessage[key]);
|
|
90
|
+
}
|
|
91
|
+
r;
|
|
92
|
+
r += closer;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return r;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseArray.js
|
|
99
|
+
var parseArray = (schema, refs) => {
|
|
100
|
+
if (Array.isArray(schema.items)) {
|
|
101
|
+
return `z.tuple([${schema.items.map((v, i) => parseSchema(v, { ...refs, path: [...refs.path, "items", i] }))}])`;
|
|
102
|
+
}
|
|
103
|
+
let r = !schema.items ? "z.array(z.any())" : `z.array(${parseSchema(schema.items, {
|
|
104
|
+
...refs,
|
|
105
|
+
path: [...refs.path, "items"]
|
|
106
|
+
})})`;
|
|
107
|
+
r += withMessage(schema, "minItems", ({ json }) => [
|
|
108
|
+
`.min(${json}`,
|
|
109
|
+
", ",
|
|
110
|
+
")"
|
|
111
|
+
]);
|
|
112
|
+
r += withMessage(schema, "maxItems", ({ json }) => [
|
|
113
|
+
`.max(${json}`,
|
|
114
|
+
", ",
|
|
115
|
+
")"
|
|
116
|
+
]);
|
|
117
|
+
if (schema.uniqueItems === true) {
|
|
118
|
+
r += withMessage(schema, "uniqueItems", () => [
|
|
119
|
+
".unique(",
|
|
120
|
+
"",
|
|
121
|
+
")"
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
return r;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseConst.js
|
|
128
|
+
var parseConst = (schema) => {
|
|
129
|
+
return `z.literal(${JSON.stringify(schema.const)})`;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseEnum.js
|
|
133
|
+
var parseEnum = (schema) => {
|
|
134
|
+
if (schema.enum.length === 0) {
|
|
135
|
+
return "z.never()";
|
|
136
|
+
} else if (schema.enum.length === 1) {
|
|
137
|
+
return `z.literal(${JSON.stringify(schema.enum[0])})`;
|
|
138
|
+
} else if (schema.enum.every((x) => typeof x === "string")) {
|
|
139
|
+
return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
|
|
140
|
+
} else {
|
|
141
|
+
return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseIfThenElse.js
|
|
146
|
+
var parseIfThenElse = (schema, refs) => {
|
|
147
|
+
const $if = parseSchema(schema.if, { ...refs, path: [...refs.path, "if"] });
|
|
148
|
+
const $then = parseSchema(schema.then, {
|
|
149
|
+
...refs,
|
|
150
|
+
path: [...refs.path, "then"]
|
|
151
|
+
});
|
|
152
|
+
const $else = parseSchema(schema.else, {
|
|
153
|
+
...refs,
|
|
154
|
+
path: [...refs.path, "else"]
|
|
155
|
+
});
|
|
156
|
+
return `z.union([${$then}, ${$else}]).superRefine((value,ctx) => {
|
|
157
|
+
const result = ${$if}.safeParse(value).success
|
|
158
|
+
? ${$then}.safeParse(value)
|
|
159
|
+
: ${$else}.safeParse(value);
|
|
160
|
+
if (!result.success) {
|
|
161
|
+
result.error.errors.forEach((error) => ctx.addIssue(error))
|
|
162
|
+
}
|
|
163
|
+
})`;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNumber.js
|
|
167
|
+
var parseNumber = (schema) => {
|
|
168
|
+
let r = "z.number()";
|
|
169
|
+
if (schema.type === "integer") {
|
|
170
|
+
r += withMessage(schema, "type", () => [".int(", ")"]);
|
|
171
|
+
} else {
|
|
172
|
+
r += withMessage(schema, "format", ({ value }) => {
|
|
173
|
+
if (value === "int64") {
|
|
174
|
+
return [".int(", ")"];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
r += withMessage(schema, "multipleOf", ({ value, json }) => {
|
|
179
|
+
if (value === 1) {
|
|
180
|
+
if (r.startsWith("z.number().int(")) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
return [".int(", ")"];
|
|
184
|
+
}
|
|
185
|
+
return [`.multipleOf(${json}`, ", ", ")"];
|
|
186
|
+
});
|
|
187
|
+
if (typeof schema.minimum === "number") {
|
|
188
|
+
if (schema.exclusiveMinimum === true) {
|
|
189
|
+
r += withMessage(schema, "minimum", ({ json }) => [
|
|
190
|
+
`.gt(${json}`,
|
|
191
|
+
", ",
|
|
192
|
+
")"
|
|
193
|
+
]);
|
|
194
|
+
} else {
|
|
195
|
+
r += withMessage(schema, "minimum", ({ json }) => [
|
|
196
|
+
`.gte(${json}`,
|
|
197
|
+
", ",
|
|
198
|
+
")"
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
} else if (typeof schema.exclusiveMinimum === "number") {
|
|
202
|
+
r += withMessage(schema, "exclusiveMinimum", ({ json }) => [
|
|
203
|
+
`.gt(${json}`,
|
|
204
|
+
", ",
|
|
205
|
+
")"
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
if (typeof schema.maximum === "number") {
|
|
209
|
+
if (schema.exclusiveMaximum === true) {
|
|
210
|
+
r += withMessage(schema, "maximum", ({ json }) => [
|
|
211
|
+
`.lt(${json}`,
|
|
212
|
+
", ",
|
|
213
|
+
")"
|
|
214
|
+
]);
|
|
215
|
+
} else {
|
|
216
|
+
r += withMessage(schema, "maximum", ({ json }) => [
|
|
217
|
+
`.lte(${json}`,
|
|
218
|
+
", ",
|
|
219
|
+
")"
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
} else if (typeof schema.exclusiveMaximum === "number") {
|
|
223
|
+
r += withMessage(schema, "exclusiveMaximum", ({ json }) => [
|
|
224
|
+
`.lt(${json}`,
|
|
225
|
+
", ",
|
|
226
|
+
")"
|
|
227
|
+
]);
|
|
228
|
+
}
|
|
229
|
+
return r;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseOneOf.js
|
|
233
|
+
var parseOneOf = (schema, refs) => {
|
|
234
|
+
return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
|
|
235
|
+
...refs,
|
|
236
|
+
path: [...refs.path, "oneOf", 0]
|
|
237
|
+
}) : `z.any().superRefine((x, ctx) => {
|
|
238
|
+
const schemas = [${schema.oneOf.map((schema2, i) => parseSchema(schema2, {
|
|
239
|
+
...refs,
|
|
240
|
+
path: [...refs.path, "oneOf", i]
|
|
241
|
+
})).join(", ")}];
|
|
242
|
+
const errors = schemas.reduce<z.ZodError[]>(
|
|
243
|
+
(errors, schema) =>
|
|
244
|
+
((result) =>
|
|
245
|
+
result.error ? [...errors, result.error] : errors)(
|
|
246
|
+
schema.safeParse(x),
|
|
247
|
+
),
|
|
248
|
+
[],
|
|
249
|
+
);
|
|
250
|
+
if (schemas.length - errors.length !== 1) {
|
|
251
|
+
ctx.addIssue({
|
|
252
|
+
path: ctx.path,
|
|
253
|
+
code: "invalid_union",
|
|
254
|
+
unionErrors: errors,
|
|
255
|
+
message: "Invalid input: Should pass single schema",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
})` : "z.any()";
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/utils/jsdocs.js
|
|
262
|
+
var expandJsdocs = (jsdocs) => {
|
|
263
|
+
const lines = jsdocs.split("\n");
|
|
264
|
+
const result = lines.length === 1 ? lines[0] : `
|
|
265
|
+
${lines.map((x) => `* ${x}`).join("\n")}
|
|
266
|
+
`;
|
|
267
|
+
return `/**${result}*/
|
|
268
|
+
`;
|
|
269
|
+
};
|
|
270
|
+
var addJsdocs = (schema, parsed) => {
|
|
271
|
+
const description = schema.description;
|
|
272
|
+
if (!description) {
|
|
273
|
+
return parsed;
|
|
274
|
+
}
|
|
275
|
+
return `
|
|
276
|
+
${expandJsdocs(description)}${parsed}`;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseObject.js
|
|
280
|
+
function parseObject(objectSchema, refs) {
|
|
281
|
+
let properties = void 0;
|
|
282
|
+
if (objectSchema.properties) {
|
|
283
|
+
if (!Object.keys(objectSchema.properties).length) {
|
|
284
|
+
properties = "z.object({})";
|
|
285
|
+
} else {
|
|
286
|
+
properties = "z.object({ ";
|
|
287
|
+
properties += Object.keys(objectSchema.properties).map((key) => {
|
|
288
|
+
const propSchema = objectSchema.properties[key];
|
|
289
|
+
let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
|
|
290
|
+
...refs,
|
|
291
|
+
path: [...refs.path, "properties", key]
|
|
292
|
+
})}`;
|
|
293
|
+
if (refs.withJsdocs && typeof propSchema === "object") {
|
|
294
|
+
result = addJsdocs(propSchema, result);
|
|
295
|
+
}
|
|
296
|
+
const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
|
|
297
|
+
const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
|
|
298
|
+
const optional = !hasDefault && !required;
|
|
299
|
+
return optional ? `${result}.optional()` : result;
|
|
300
|
+
}).join(", ");
|
|
301
|
+
properties += " })";
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
|
|
305
|
+
...refs,
|
|
306
|
+
path: [...refs.path, "additionalProperties"]
|
|
307
|
+
}) : void 0;
|
|
308
|
+
let patternProperties = void 0;
|
|
309
|
+
if (objectSchema.patternProperties) {
|
|
310
|
+
const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
|
|
311
|
+
return [
|
|
312
|
+
key,
|
|
313
|
+
parseSchema(value, {
|
|
314
|
+
...refs,
|
|
315
|
+
path: [...refs.path, "patternProperties", key]
|
|
316
|
+
})
|
|
317
|
+
];
|
|
318
|
+
}, {}));
|
|
319
|
+
patternProperties = "";
|
|
320
|
+
if (properties) {
|
|
321
|
+
if (additionalProperties) {
|
|
322
|
+
patternProperties += `.catchall(z.union([${[
|
|
323
|
+
...Object.values(parsedPatternProperties),
|
|
324
|
+
additionalProperties
|
|
325
|
+
].join(", ")}]))`;
|
|
326
|
+
} else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
327
|
+
patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
328
|
+
} else {
|
|
329
|
+
patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
if (additionalProperties) {
|
|
333
|
+
patternProperties += `z.record(z.union([${[
|
|
334
|
+
...Object.values(parsedPatternProperties),
|
|
335
|
+
additionalProperties
|
|
336
|
+
].join(", ")}]))`;
|
|
337
|
+
} else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
338
|
+
patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
339
|
+
} else {
|
|
340
|
+
patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
patternProperties += ".superRefine((value, ctx) => {\n";
|
|
344
|
+
patternProperties += "for (const key in value) {\n";
|
|
345
|
+
if (additionalProperties) {
|
|
346
|
+
if (objectSchema.properties) {
|
|
347
|
+
patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)
|
|
348
|
+
`;
|
|
349
|
+
} else {
|
|
350
|
+
patternProperties += `let evaluated = false
|
|
351
|
+
`;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
for (const key in objectSchema.patternProperties) {
|
|
355
|
+
patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
|
|
356
|
+
if (additionalProperties) {
|
|
357
|
+
patternProperties += "evaluated = true\n";
|
|
358
|
+
}
|
|
359
|
+
patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
|
|
360
|
+
patternProperties += "if (!result.success) {\n";
|
|
361
|
+
patternProperties += `ctx.addIssue({
|
|
362
|
+
path: [...ctx.path, key],
|
|
363
|
+
code: 'custom',
|
|
364
|
+
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
365
|
+
params: {
|
|
366
|
+
issues: result.error.issues
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
`;
|
|
370
|
+
patternProperties += "}\n";
|
|
371
|
+
patternProperties += "}\n";
|
|
372
|
+
}
|
|
373
|
+
if (additionalProperties) {
|
|
374
|
+
patternProperties += "if (!evaluated) {\n";
|
|
375
|
+
patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
376
|
+
patternProperties += "if (!result.success) {\n";
|
|
377
|
+
patternProperties += `ctx.addIssue({
|
|
378
|
+
path: [...ctx.path, key],
|
|
379
|
+
code: 'custom',
|
|
380
|
+
message: \`Invalid input: must match catchall schema\`,
|
|
381
|
+
params: {
|
|
382
|
+
issues: result.error.issues
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
`;
|
|
386
|
+
patternProperties += "}\n";
|
|
387
|
+
patternProperties += "}\n";
|
|
388
|
+
}
|
|
389
|
+
patternProperties += "}\n";
|
|
390
|
+
patternProperties += "})";
|
|
391
|
+
}
|
|
392
|
+
let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? `z.record(${additionalProperties})` : "z.record(z.any())";
|
|
393
|
+
if (its.an.anyOf(objectSchema)) {
|
|
394
|
+
output += `.and(${parseAnyOf({
|
|
395
|
+
...objectSchema,
|
|
396
|
+
anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
397
|
+
}, refs)})`;
|
|
398
|
+
}
|
|
399
|
+
if (its.a.oneOf(objectSchema)) {
|
|
400
|
+
output += `.and(${parseOneOf({
|
|
401
|
+
...objectSchema,
|
|
402
|
+
oneOf: objectSchema.oneOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
403
|
+
}, refs)})`;
|
|
404
|
+
}
|
|
405
|
+
if (its.an.allOf(objectSchema)) {
|
|
406
|
+
output += `.and(${parseAllOf({
|
|
407
|
+
...objectSchema,
|
|
408
|
+
allOf: objectSchema.allOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
409
|
+
}, refs)})`;
|
|
410
|
+
}
|
|
411
|
+
return output;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseString.js
|
|
415
|
+
var parseString = (schema) => {
|
|
416
|
+
let r = "z.string()";
|
|
417
|
+
r += withMessage(schema, "format", ({ value }) => {
|
|
418
|
+
switch (value) {
|
|
419
|
+
case "email":
|
|
420
|
+
return [".email(", ")"];
|
|
421
|
+
case "ip":
|
|
422
|
+
return [".ip(", ")"];
|
|
423
|
+
case "ipv4":
|
|
424
|
+
return ['.ip({ version: "v4"', ", message: ", " })"];
|
|
425
|
+
case "ipv6":
|
|
426
|
+
return ['.ip({ version: "v6"', ", message: ", " })"];
|
|
427
|
+
case "uri":
|
|
428
|
+
return [".url(", ")"];
|
|
429
|
+
case "uuid":
|
|
430
|
+
return [".uuid(", ")"];
|
|
431
|
+
case "date-time":
|
|
432
|
+
return [".datetime({ offset: true", ", message: ", " })"];
|
|
433
|
+
case "time":
|
|
434
|
+
return [".time(", ")"];
|
|
435
|
+
case "date":
|
|
436
|
+
return [".date(", ")"];
|
|
437
|
+
case "binary":
|
|
438
|
+
return [".base64(", ")"];
|
|
439
|
+
case "duration":
|
|
440
|
+
return [".duration(", ")"];
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
r += withMessage(schema, "pattern", ({ json }) => [
|
|
444
|
+
`.regex(new RegExp(${json})`,
|
|
445
|
+
", ",
|
|
446
|
+
")"
|
|
447
|
+
]);
|
|
448
|
+
r += withMessage(schema, "minLength", ({ json }) => [
|
|
449
|
+
`.min(${json}`,
|
|
450
|
+
", ",
|
|
451
|
+
")"
|
|
452
|
+
]);
|
|
453
|
+
r += withMessage(schema, "maxLength", ({ json }) => [
|
|
454
|
+
`.max(${json}`,
|
|
455
|
+
", ",
|
|
456
|
+
")"
|
|
457
|
+
]);
|
|
458
|
+
r += withMessage(schema, "contentEncoding", ({ value }) => {
|
|
459
|
+
if (value === "base64") {
|
|
460
|
+
return [".base64(", ")"];
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
|
|
464
|
+
if (value === "application/json") {
|
|
465
|
+
return [
|
|
466
|
+
'.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',
|
|
467
|
+
", ",
|
|
468
|
+
")"
|
|
469
|
+
];
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
if (contentMediaType != "") {
|
|
473
|
+
r += contentMediaType;
|
|
474
|
+
r += withMessage(schema, "contentSchema", ({ value }) => {
|
|
475
|
+
if (value && value instanceof Object) {
|
|
476
|
+
return [
|
|
477
|
+
`.pipe(${parseSchema(value)}`,
|
|
478
|
+
", ",
|
|
479
|
+
")"
|
|
480
|
+
];
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
return r;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseSimpleDiscriminatedOneOf.js
|
|
488
|
+
var parseSimpleDiscriminatedOneOf = (schema, refs) => {
|
|
489
|
+
return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
|
|
490
|
+
...refs,
|
|
491
|
+
path: [...refs.path, "oneOf", 0]
|
|
492
|
+
}) : `z.discriminatedUnion("${schema.discriminator.propertyName}", [${schema.oneOf.map((schema2, i) => parseSchema(schema2, {
|
|
493
|
+
...refs,
|
|
494
|
+
path: [...refs.path, "oneOf", i]
|
|
495
|
+
})).join(", ")}])` : "z.any()";
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/utils/omit.js
|
|
499
|
+
var omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
|
|
500
|
+
if (!keys.includes(key)) {
|
|
501
|
+
acc[key] = obj[key];
|
|
502
|
+
}
|
|
503
|
+
return acc;
|
|
504
|
+
}, {});
|
|
505
|
+
|
|
506
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNullable.js
|
|
507
|
+
var parseNullable = (schema, refs) => {
|
|
508
|
+
return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseSchema.js
|
|
512
|
+
var parseSchema = (schema, refs = { seen: /* @__PURE__ */ new Map(), path: [] }, blockMeta) => {
|
|
513
|
+
if (typeof schema !== "object")
|
|
514
|
+
return schema ? "z.any()" : "z.never()";
|
|
515
|
+
if (refs.parserOverride) {
|
|
516
|
+
const custom = refs.parserOverride(schema, refs);
|
|
517
|
+
if (typeof custom === "string") {
|
|
518
|
+
return custom;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
let seen = refs.seen.get(schema);
|
|
522
|
+
if (seen) {
|
|
523
|
+
if (seen.r !== void 0) {
|
|
524
|
+
return seen.r;
|
|
525
|
+
}
|
|
526
|
+
if (refs.depth === void 0 || seen.n >= refs.depth) {
|
|
527
|
+
return "z.any()";
|
|
528
|
+
}
|
|
529
|
+
seen.n += 1;
|
|
530
|
+
} else {
|
|
531
|
+
seen = { r: void 0, n: 0 };
|
|
532
|
+
refs.seen.set(schema, seen);
|
|
533
|
+
}
|
|
534
|
+
let parsed = selectParser(schema, refs);
|
|
535
|
+
if (!blockMeta) {
|
|
536
|
+
if (!refs.withoutDescribes) {
|
|
537
|
+
parsed = addDescribes(schema, parsed);
|
|
538
|
+
}
|
|
539
|
+
if (!refs.withoutDefaults) {
|
|
540
|
+
parsed = addDefaults(schema, parsed);
|
|
541
|
+
}
|
|
542
|
+
parsed = addAnnotations(schema, parsed);
|
|
543
|
+
}
|
|
544
|
+
seen.r = parsed;
|
|
545
|
+
return parsed;
|
|
546
|
+
};
|
|
547
|
+
var addDescribes = (schema, parsed) => {
|
|
548
|
+
if (schema.description) {
|
|
549
|
+
parsed += `.describe(${JSON.stringify(schema.description)})`;
|
|
550
|
+
}
|
|
551
|
+
return parsed;
|
|
552
|
+
};
|
|
553
|
+
var addDefaults = (schema, parsed) => {
|
|
554
|
+
if (schema.default !== void 0) {
|
|
555
|
+
parsed += `.default(${JSON.stringify(schema.default)})`;
|
|
556
|
+
}
|
|
557
|
+
return parsed;
|
|
558
|
+
};
|
|
559
|
+
var addAnnotations = (schema, parsed) => {
|
|
560
|
+
if (schema.readOnly) {
|
|
561
|
+
parsed += ".readonly()";
|
|
562
|
+
}
|
|
563
|
+
return parsed;
|
|
564
|
+
};
|
|
565
|
+
var selectParser = (schema, refs) => {
|
|
566
|
+
if (its.a.nullable(schema)) {
|
|
567
|
+
return parseNullable(schema, refs);
|
|
568
|
+
} else if (its.an.object(schema)) {
|
|
569
|
+
return parseObject(schema, refs);
|
|
570
|
+
} else if (its.an.array(schema)) {
|
|
571
|
+
return parseArray(schema, refs);
|
|
572
|
+
} else if (its.an.anyOf(schema)) {
|
|
573
|
+
return parseAnyOf(schema, refs);
|
|
574
|
+
} else if (its.an.allOf(schema)) {
|
|
575
|
+
return parseAllOf(schema, refs);
|
|
576
|
+
} else if (its.a.simpleDiscriminatedOneOf(schema)) {
|
|
577
|
+
return parseSimpleDiscriminatedOneOf(schema, refs);
|
|
578
|
+
} else if (its.a.oneOf(schema)) {
|
|
579
|
+
return parseOneOf(schema, refs);
|
|
580
|
+
} else if (its.a.not(schema)) {
|
|
581
|
+
return parseNot(schema, refs);
|
|
582
|
+
} else if (its.an.enum(schema)) {
|
|
583
|
+
return parseEnum(schema);
|
|
584
|
+
} else if (its.a.const(schema)) {
|
|
585
|
+
return parseConst(schema);
|
|
586
|
+
} else if (its.a.multipleType(schema)) {
|
|
587
|
+
return parseMultipleType(schema, refs);
|
|
588
|
+
} else if (its.a.primitive(schema, "string")) {
|
|
589
|
+
return parseString(schema);
|
|
590
|
+
} else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) {
|
|
591
|
+
return parseNumber(schema);
|
|
592
|
+
} else if (its.a.primitive(schema, "boolean")) {
|
|
593
|
+
return parseBoolean(schema);
|
|
594
|
+
} else if (its.a.primitive(schema, "null")) {
|
|
595
|
+
return parseNull(schema);
|
|
596
|
+
} else if (its.a.conditional(schema)) {
|
|
597
|
+
return parseIfThenElse(schema, refs);
|
|
598
|
+
} else {
|
|
599
|
+
return parseDefault(schema);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var its = {
|
|
603
|
+
an: {
|
|
604
|
+
object: (x) => x.type === "object",
|
|
605
|
+
array: (x) => x.type === "array",
|
|
606
|
+
anyOf: (x) => x.anyOf !== void 0,
|
|
607
|
+
allOf: (x) => x.allOf !== void 0,
|
|
608
|
+
enum: (x) => x.enum !== void 0
|
|
609
|
+
},
|
|
610
|
+
a: {
|
|
611
|
+
nullable: (x) => x.nullable === true,
|
|
612
|
+
multipleType: (x) => Array.isArray(x.type),
|
|
613
|
+
not: (x) => x.not !== void 0,
|
|
614
|
+
const: (x) => x.const !== void 0,
|
|
615
|
+
primitive: (x, p) => x.type === p,
|
|
616
|
+
conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
|
|
617
|
+
simpleDiscriminatedOneOf: (x) => {
|
|
618
|
+
if (!x.oneOf || !Array.isArray(x.oneOf) || x.oneOf.length === 0 || !x.discriminator || typeof x.discriminator !== "object" || !("propertyName" in x.discriminator) || typeof x.discriminator.propertyName !== "string") {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
const discriminatorProp = x.discriminator.propertyName;
|
|
622
|
+
return x.oneOf.every((schema) => {
|
|
623
|
+
if (!schema || typeof schema !== "object" || schema.type !== "object" || !schema.properties || typeof schema.properties !== "object" || !(discriminatorProp in schema.properties)) {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
const property = schema.properties[discriminatorProp];
|
|
627
|
+
return property && typeof property === "object" && property.type === "string" && // Ensure discriminator has a constant value (const or single-value enum)
|
|
628
|
+
(property.const !== void 0 || property.enum && Array.isArray(property.enum) && property.enum.length === 1) && // Ensure discriminator property is required
|
|
629
|
+
Array.isArray(schema.required) && schema.required.includes(discriminatorProp);
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
oneOf: (x) => x.oneOf !== void 0
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// ../../node_modules/.bun/json-schema-to-zod@2.7.0/node_modules/json-schema-to-zod/dist/esm/jsonSchemaToZod.js
|
|
637
|
+
var jsonSchemaToZod = (schema, { module, name, type, noImport, ...rest } = {}) => {
|
|
638
|
+
if (type && (!name || module !== "esm")) {
|
|
639
|
+
throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
|
|
640
|
+
}
|
|
641
|
+
let result = parseSchema(schema, {
|
|
642
|
+
module,
|
|
643
|
+
name,
|
|
644
|
+
path: [],
|
|
645
|
+
seen: /* @__PURE__ */ new Map(),
|
|
646
|
+
...rest
|
|
647
|
+
});
|
|
648
|
+
const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
|
|
649
|
+
if (module === "cjs") {
|
|
650
|
+
result = `${jsdocs}module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
|
|
651
|
+
`;
|
|
652
|
+
if (!noImport) {
|
|
653
|
+
result = `${jsdocs}const { z } = require("zod")
|
|
654
|
+
|
|
655
|
+
${result}`;
|
|
656
|
+
}
|
|
657
|
+
} else if (module === "esm") {
|
|
658
|
+
result = `${jsdocs}export ${name ? `const ${name} =` : `default`} ${result}
|
|
659
|
+
`;
|
|
660
|
+
if (!noImport) {
|
|
661
|
+
result = `import { z } from "zod"
|
|
662
|
+
|
|
663
|
+
${result}`;
|
|
664
|
+
}
|
|
665
|
+
} else if (name) {
|
|
666
|
+
result = `${jsdocs}const ${name} = ${result}`;
|
|
667
|
+
}
|
|
668
|
+
if (type && name) {
|
|
669
|
+
let typeName = typeof type === "string" ? type : `${name[0].toUpperCase()}${name.substring(1)}`;
|
|
670
|
+
result += `export type ${typeName} = z.infer<typeof ${name}>
|
|
671
|
+
`;
|
|
672
|
+
}
|
|
673
|
+
return result;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// ../../node_modules/.bun/text-lower-case@1.2.9/node_modules/text-lower-case/dist.es2015/index.js
|
|
677
|
+
function lowerCase(str) {
|
|
678
|
+
if (!str)
|
|
679
|
+
return "";
|
|
680
|
+
return str.toLowerCase();
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// ../../node_modules/.bun/text-no-case@1.2.9/node_modules/text-no-case/dist.es2015/index.js
|
|
684
|
+
var DEFAULT_SPLIT_REGEXP = [
|
|
685
|
+
/(\p{Ll}|\p{N})(\p{Lu})/gu,
|
|
686
|
+
/(\p{Lu})(\p{Lu}\p{Ll})/gu
|
|
687
|
+
];
|
|
688
|
+
var DEFAULT_STRIP_REGEXP = /[^\p{L}\p{N}]+/gu;
|
|
689
|
+
function noCase(input, options = {}) {
|
|
690
|
+
if (!input)
|
|
691
|
+
return "";
|
|
692
|
+
const { splitRegexp = DEFAULT_SPLIT_REGEXP, stripRegexp = DEFAULT_STRIP_REGEXP, transform = lowerCase, delimiter = " " } = options;
|
|
693
|
+
const result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
694
|
+
let start = 0;
|
|
695
|
+
let end = result.length;
|
|
696
|
+
while (result.charAt(start) === "\0")
|
|
697
|
+
start++;
|
|
698
|
+
while (result.charAt(end - 1) === "\0")
|
|
699
|
+
end--;
|
|
700
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
701
|
+
}
|
|
702
|
+
function replace(input, re, value) {
|
|
703
|
+
if (re instanceof RegExp)
|
|
704
|
+
return input.replace(re, value);
|
|
705
|
+
return re.reduce((result, pattern) => result.replace(pattern, value), input);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// ../../node_modules/.bun/text-pascal-case@1.2.9/node_modules/text-pascal-case/dist.es2015/index.js
|
|
709
|
+
function pascalCaseTransform(input, index) {
|
|
710
|
+
const firstChar = input.charAt(0);
|
|
711
|
+
const lowerChars = input.slice(1).toLowerCase();
|
|
712
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
713
|
+
return `_${firstChar}${lowerChars}`;
|
|
714
|
+
}
|
|
715
|
+
return `${firstChar.toUpperCase()}${lowerChars}`;
|
|
716
|
+
}
|
|
717
|
+
function pascalCase(input, options = {}) {
|
|
718
|
+
if (!input)
|
|
719
|
+
return "";
|
|
720
|
+
return noCase(input, {
|
|
721
|
+
delimiter: "",
|
|
722
|
+
transform: pascalCaseTransform,
|
|
723
|
+
...options
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// ../../node_modules/.bun/text-camel-case@1.2.9/node_modules/text-camel-case/dist.es2015/index.js
|
|
728
|
+
function camelCaseTransform(input, index) {
|
|
729
|
+
if (index === 0)
|
|
730
|
+
return input.toLowerCase();
|
|
731
|
+
return pascalCaseTransform(input, index);
|
|
732
|
+
}
|
|
733
|
+
function camelCase(input, options = {}) {
|
|
734
|
+
if (!input)
|
|
735
|
+
return "";
|
|
736
|
+
return pascalCase(input, {
|
|
737
|
+
transform: camelCaseTransform,
|
|
738
|
+
...options
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
|
|
1
742
|
// src/form/generate.ts
|
|
2
|
-
import { jsonSchemaToZod } from "json-schema-to-zod";
|
|
3
|
-
import { camelCase, pascalCase } from "text-case";
|
|
4
743
|
function generateFormsCode(forms, header) {
|
|
5
744
|
const imports = [
|
|
6
745
|
`import { registerForm } from '@swirls/sdk/form'`,
|