@digdir/designsystemet 1.0.6 → 1.0.7

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.
@@ -1,1267 +1,11 @@
1
1
  // src/scripts/createJsonSchema.ts
2
- import { writeFile } from "node:fs/promises";
3
- import { resolve } from "node:path";
4
- import { z as z2 } from "zod";
5
-
6
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/Options.js
7
- var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
8
- var defaultOptions = {
9
- name: void 0,
10
- $refStrategy: "root",
11
- basePath: ["#"],
12
- effectStrategy: "input",
13
- pipeStrategy: "all",
14
- dateStrategy: "format:date-time",
15
- mapStrategy: "entries",
16
- removeAdditionalStrategy: "passthrough",
17
- allowedAdditionalProperties: true,
18
- rejectedAdditionalProperties: false,
19
- definitionPath: "definitions",
20
- target: "jsonSchema7",
21
- strictUnions: false,
22
- definitions: {},
23
- errorMessages: false,
24
- markdownDescription: false,
25
- patternStrategy: "escape",
26
- applyRegexFlags: false,
27
- emailStrategy: "format:email",
28
- base64Strategy: "contentEncoding:base64",
29
- nameStrategy: "ref"
30
- };
31
- var getDefaultOptions = (options) => typeof options === "string" ? {
32
- ...defaultOptions,
33
- name: options
34
- } : {
35
- ...defaultOptions,
36
- ...options
37
- };
38
-
39
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/Refs.js
40
- var getRefs = (options) => {
41
- const _options = getDefaultOptions(options);
42
- const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
43
- return {
44
- ..._options,
45
- currentPath,
46
- propertyPath: void 0,
47
- seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
48
- def._def,
49
- {
50
- def: def._def,
51
- path: [..._options.basePath, _options.definitionPath, name],
52
- // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
53
- jsonSchema: void 0
54
- }
55
- ]))
56
- };
57
- };
58
-
59
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
60
- function addErrorMessage(res, key, errorMessage, refs) {
61
- if (!refs?.errorMessages)
62
- return;
63
- if (errorMessage) {
64
- res.errorMessage = {
65
- ...res.errorMessage,
66
- [key]: errorMessage
67
- };
68
- }
69
- }
70
- function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
71
- res[key] = value;
72
- addErrorMessage(res, key, errorMessage, refs);
73
- }
74
-
75
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/selectParser.js
76
- import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
77
-
78
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
79
- function parseAnyDef() {
80
- return {};
81
- }
82
-
83
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
84
- import { ZodFirstPartyTypeKind } from "zod";
85
- function parseArrayDef(def, refs) {
86
- const res = {
87
- type: "array"
88
- };
89
- if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
90
- res.items = parseDef(def.type._def, {
91
- ...refs,
92
- currentPath: [...refs.currentPath, "items"]
93
- });
94
- }
95
- if (def.minLength) {
96
- setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
97
- }
98
- if (def.maxLength) {
99
- setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
100
- }
101
- if (def.exactLength) {
102
- setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
103
- setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
104
- }
105
- return res;
106
- }
107
-
108
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
109
- function parseBigintDef(def, refs) {
110
- const res = {
111
- type: "integer",
112
- format: "int64"
113
- };
114
- if (!def.checks)
115
- return res;
116
- for (const check of def.checks) {
117
- switch (check.kind) {
118
- case "min":
119
- if (refs.target === "jsonSchema7") {
120
- if (check.inclusive) {
121
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
122
- } else {
123
- setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
124
- }
125
- } else {
126
- if (!check.inclusive) {
127
- res.exclusiveMinimum = true;
128
- }
129
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
130
- }
131
- break;
132
- case "max":
133
- if (refs.target === "jsonSchema7") {
134
- if (check.inclusive) {
135
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
136
- } else {
137
- setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
138
- }
139
- } else {
140
- if (!check.inclusive) {
141
- res.exclusiveMaximum = true;
142
- }
143
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
144
- }
145
- break;
146
- case "multipleOf":
147
- setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
148
- break;
149
- }
150
- }
151
- return res;
152
- }
153
-
154
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
155
- function parseBooleanDef() {
156
- return {
157
- type: "boolean"
158
- };
159
- }
160
-
161
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
162
- function parseBrandedDef(_def, refs) {
163
- return parseDef(_def.type._def, refs);
164
- }
165
-
166
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
167
- var parseCatchDef = (def, refs) => {
168
- return parseDef(def.innerType._def, refs);
169
- };
170
-
171
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
172
- function parseDateDef(def, refs, overrideDateStrategy) {
173
- const strategy = overrideDateStrategy ?? refs.dateStrategy;
174
- if (Array.isArray(strategy)) {
175
- return {
176
- anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
177
- };
178
- }
179
- switch (strategy) {
180
- case "string":
181
- case "format:date-time":
182
- return {
183
- type: "string",
184
- format: "date-time"
185
- };
186
- case "format:date":
187
- return {
188
- type: "string",
189
- format: "date"
190
- };
191
- case "integer":
192
- return integerDateParser(def, refs);
193
- }
194
- }
195
- var integerDateParser = (def, refs) => {
196
- const res = {
197
- type: "integer",
198
- format: "unix-time"
199
- };
200
- if (refs.target === "openApi3") {
201
- return res;
202
- }
203
- for (const check of def.checks) {
204
- switch (check.kind) {
205
- case "min":
206
- setResponseValueAndErrors(
207
- res,
208
- "minimum",
209
- check.value,
210
- // This is in milliseconds
211
- check.message,
212
- refs
213
- );
214
- break;
215
- case "max":
216
- setResponseValueAndErrors(
217
- res,
218
- "maximum",
219
- check.value,
220
- // This is in milliseconds
221
- check.message,
222
- refs
223
- );
224
- break;
225
- }
226
- }
227
- return res;
228
- };
229
-
230
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
231
- function parseDefaultDef(_def, refs) {
232
- return {
233
- ...parseDef(_def.innerType._def, refs),
234
- default: _def.defaultValue()
235
- };
236
- }
237
-
238
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
239
- function parseEffectsDef(_def, refs) {
240
- return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
241
- }
242
-
243
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
244
- function parseEnumDef(def) {
245
- return {
246
- type: "string",
247
- enum: Array.from(def.values)
248
- };
249
- }
250
-
251
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
252
- var isJsonSchema7AllOfType = (type) => {
253
- if ("type" in type && type.type === "string")
254
- return false;
255
- return "allOf" in type;
256
- };
257
- function parseIntersectionDef(def, refs) {
258
- const allOf = [
259
- parseDef(def.left._def, {
260
- ...refs,
261
- currentPath: [...refs.currentPath, "allOf", "0"]
262
- }),
263
- parseDef(def.right._def, {
264
- ...refs,
265
- currentPath: [...refs.currentPath, "allOf", "1"]
266
- })
267
- ].filter((x) => !!x);
268
- let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
269
- const mergedAllOf = [];
270
- allOf.forEach((schema2) => {
271
- if (isJsonSchema7AllOfType(schema2)) {
272
- mergedAllOf.push(...schema2.allOf);
273
- if (schema2.unevaluatedProperties === void 0) {
274
- unevaluatedProperties = void 0;
275
- }
276
- } else {
277
- let nestedSchema = schema2;
278
- if ("additionalProperties" in schema2 && schema2.additionalProperties === false) {
279
- const { additionalProperties, ...rest } = schema2;
280
- nestedSchema = rest;
281
- } else {
282
- unevaluatedProperties = void 0;
283
- }
284
- mergedAllOf.push(nestedSchema);
285
- }
286
- });
287
- return mergedAllOf.length ? {
288
- allOf: mergedAllOf,
289
- ...unevaluatedProperties
290
- } : void 0;
291
- }
292
-
293
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
294
- function parseLiteralDef(def, refs) {
295
- const parsedType = typeof def.value;
296
- if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
297
- return {
298
- type: Array.isArray(def.value) ? "array" : "object"
299
- };
300
- }
301
- if (refs.target === "openApi3") {
302
- return {
303
- type: parsedType === "bigint" ? "integer" : parsedType,
304
- enum: [def.value]
305
- };
306
- }
307
- return {
308
- type: parsedType === "bigint" ? "integer" : parsedType,
309
- const: def.value
310
- };
311
- }
312
-
313
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
314
- import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
315
-
316
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
317
- var emojiRegex = void 0;
318
- var zodPatterns = {
319
- /**
320
- * `c` was changed to `[cC]` to replicate /i flag
321
- */
322
- cuid: /^[cC][^\s-]{8,}$/,
323
- cuid2: /^[0-9a-z]+$/,
324
- ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
325
- /**
326
- * `a-z` was added to replicate /i flag
327
- */
328
- email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
329
- /**
330
- * Constructed a valid Unicode RegExp
331
- *
332
- * Lazily instantiate since this type of regex isn't supported
333
- * in all envs (e.g. React Native).
334
- *
335
- * See:
336
- * https://github.com/colinhacks/zod/issues/2433
337
- * Fix in Zod:
338
- * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
339
- */
340
- emoji: () => {
341
- if (emojiRegex === void 0) {
342
- emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
343
- }
344
- return emojiRegex;
345
- },
346
- /**
347
- * Unused
348
- */
349
- uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
350
- /**
351
- * Unused
352
- */
353
- ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
354
- ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
355
- /**
356
- * Unused
357
- */
358
- ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
359
- ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
360
- base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
361
- base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
362
- nanoid: /^[a-zA-Z0-9_-]{21}$/,
363
- jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
364
- };
365
- function parseStringDef(def, refs) {
366
- const res = {
367
- type: "string"
368
- };
369
- if (def.checks) {
370
- for (const check of def.checks) {
371
- switch (check.kind) {
372
- case "min":
373
- setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
374
- break;
375
- case "max":
376
- setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
377
- break;
378
- case "email":
379
- switch (refs.emailStrategy) {
380
- case "format:email":
381
- addFormat(res, "email", check.message, refs);
382
- break;
383
- case "format:idn-email":
384
- addFormat(res, "idn-email", check.message, refs);
385
- break;
386
- case "pattern:zod":
387
- addPattern(res, zodPatterns.email, check.message, refs);
388
- break;
389
- }
390
- break;
391
- case "url":
392
- addFormat(res, "uri", check.message, refs);
393
- break;
394
- case "uuid":
395
- addFormat(res, "uuid", check.message, refs);
396
- break;
397
- case "regex":
398
- addPattern(res, check.regex, check.message, refs);
399
- break;
400
- case "cuid":
401
- addPattern(res, zodPatterns.cuid, check.message, refs);
402
- break;
403
- case "cuid2":
404
- addPattern(res, zodPatterns.cuid2, check.message, refs);
405
- break;
406
- case "startsWith":
407
- addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
408
- break;
409
- case "endsWith":
410
- addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
411
- break;
412
- case "datetime":
413
- addFormat(res, "date-time", check.message, refs);
414
- break;
415
- case "date":
416
- addFormat(res, "date", check.message, refs);
417
- break;
418
- case "time":
419
- addFormat(res, "time", check.message, refs);
420
- break;
421
- case "duration":
422
- addFormat(res, "duration", check.message, refs);
423
- break;
424
- case "length":
425
- setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
426
- setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
427
- break;
428
- case "includes": {
429
- addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
430
- break;
431
- }
432
- case "ip": {
433
- if (check.version !== "v6") {
434
- addFormat(res, "ipv4", check.message, refs);
435
- }
436
- if (check.version !== "v4") {
437
- addFormat(res, "ipv6", check.message, refs);
438
- }
439
- break;
440
- }
441
- case "base64url":
442
- addPattern(res, zodPatterns.base64url, check.message, refs);
443
- break;
444
- case "jwt":
445
- addPattern(res, zodPatterns.jwt, check.message, refs);
446
- break;
447
- case "cidr": {
448
- if (check.version !== "v6") {
449
- addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
450
- }
451
- if (check.version !== "v4") {
452
- addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
453
- }
454
- break;
455
- }
456
- case "emoji":
457
- addPattern(res, zodPatterns.emoji(), check.message, refs);
458
- break;
459
- case "ulid": {
460
- addPattern(res, zodPatterns.ulid, check.message, refs);
461
- break;
462
- }
463
- case "base64": {
464
- switch (refs.base64Strategy) {
465
- case "format:binary": {
466
- addFormat(res, "binary", check.message, refs);
467
- break;
468
- }
469
- case "contentEncoding:base64": {
470
- setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
471
- break;
472
- }
473
- case "pattern:zod": {
474
- addPattern(res, zodPatterns.base64, check.message, refs);
475
- break;
476
- }
477
- }
478
- break;
479
- }
480
- case "nanoid": {
481
- addPattern(res, zodPatterns.nanoid, check.message, refs);
482
- }
483
- case "toLowerCase":
484
- case "toUpperCase":
485
- case "trim":
486
- break;
487
- default:
488
- /* @__PURE__ */ ((_) => {
489
- })(check);
490
- }
491
- }
492
- }
493
- return res;
494
- }
495
- function escapeLiteralCheckValue(literal, refs) {
496
- return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
497
- }
498
- var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
499
- function escapeNonAlphaNumeric(source) {
500
- let result = "";
501
- for (let i = 0; i < source.length; i++) {
502
- if (!ALPHA_NUMERIC.has(source[i])) {
503
- result += "\\";
504
- }
505
- result += source[i];
506
- }
507
- return result;
508
- }
509
- function addFormat(schema2, value, message, refs) {
510
- if (schema2.format || schema2.anyOf?.some((x) => x.format)) {
511
- if (!schema2.anyOf) {
512
- schema2.anyOf = [];
513
- }
514
- if (schema2.format) {
515
- schema2.anyOf.push({
516
- format: schema2.format,
517
- ...schema2.errorMessage && refs.errorMessages && {
518
- errorMessage: { format: schema2.errorMessage.format }
519
- }
520
- });
521
- delete schema2.format;
522
- if (schema2.errorMessage) {
523
- delete schema2.errorMessage.format;
524
- if (Object.keys(schema2.errorMessage).length === 0) {
525
- delete schema2.errorMessage;
526
- }
527
- }
528
- }
529
- schema2.anyOf.push({
530
- format: value,
531
- ...message && refs.errorMessages && { errorMessage: { format: message } }
532
- });
533
- } else {
534
- setResponseValueAndErrors(schema2, "format", value, message, refs);
535
- }
536
- }
537
- function addPattern(schema2, regex, message, refs) {
538
- if (schema2.pattern || schema2.allOf?.some((x) => x.pattern)) {
539
- if (!schema2.allOf) {
540
- schema2.allOf = [];
541
- }
542
- if (schema2.pattern) {
543
- schema2.allOf.push({
544
- pattern: schema2.pattern,
545
- ...schema2.errorMessage && refs.errorMessages && {
546
- errorMessage: { pattern: schema2.errorMessage.pattern }
547
- }
548
- });
549
- delete schema2.pattern;
550
- if (schema2.errorMessage) {
551
- delete schema2.errorMessage.pattern;
552
- if (Object.keys(schema2.errorMessage).length === 0) {
553
- delete schema2.errorMessage;
554
- }
555
- }
556
- }
557
- schema2.allOf.push({
558
- pattern: stringifyRegExpWithFlags(regex, refs),
559
- ...message && refs.errorMessages && { errorMessage: { pattern: message } }
560
- });
561
- } else {
562
- setResponseValueAndErrors(schema2, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
563
- }
564
- }
565
- function stringifyRegExpWithFlags(regex, refs) {
566
- if (!refs.applyRegexFlags || !regex.flags) {
567
- return regex.source;
568
- }
569
- const flags = {
570
- i: regex.flags.includes("i"),
571
- m: regex.flags.includes("m"),
572
- s: regex.flags.includes("s")
573
- // `.` matches newlines
574
- };
575
- const source = flags.i ? regex.source.toLowerCase() : regex.source;
576
- let pattern = "";
577
- let isEscaped = false;
578
- let inCharGroup = false;
579
- let inCharRange = false;
580
- for (let i = 0; i < source.length; i++) {
581
- if (isEscaped) {
582
- pattern += source[i];
583
- isEscaped = false;
584
- continue;
585
- }
586
- if (flags.i) {
587
- if (inCharGroup) {
588
- if (source[i].match(/[a-z]/)) {
589
- if (inCharRange) {
590
- pattern += source[i];
591
- pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
592
- inCharRange = false;
593
- } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
594
- pattern += source[i];
595
- inCharRange = true;
596
- } else {
597
- pattern += `${source[i]}${source[i].toUpperCase()}`;
598
- }
599
- continue;
600
- }
601
- } else if (source[i].match(/[a-z]/)) {
602
- pattern += `[${source[i]}${source[i].toUpperCase()}]`;
603
- continue;
604
- }
605
- }
606
- if (flags.m) {
607
- if (source[i] === "^") {
608
- pattern += `(^|(?<=[\r
609
- ]))`;
610
- continue;
611
- } else if (source[i] === "$") {
612
- pattern += `($|(?=[\r
613
- ]))`;
614
- continue;
615
- }
616
- }
617
- if (flags.s && source[i] === ".") {
618
- pattern += inCharGroup ? `${source[i]}\r
619
- ` : `[${source[i]}\r
620
- ]`;
621
- continue;
622
- }
623
- pattern += source[i];
624
- if (source[i] === "\\") {
625
- isEscaped = true;
626
- } else if (inCharGroup && source[i] === "]") {
627
- inCharGroup = false;
628
- } else if (!inCharGroup && source[i] === "[") {
629
- inCharGroup = true;
630
- }
631
- }
632
- try {
633
- new RegExp(pattern);
634
- } catch {
635
- console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
636
- return regex.source;
637
- }
638
- return pattern;
639
- }
640
-
641
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
642
- function parseRecordDef(def, refs) {
643
- if (refs.target === "openAi") {
644
- console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
645
- }
646
- if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
647
- return {
648
- type: "object",
649
- required: def.keyType._def.values,
650
- properties: def.keyType._def.values.reduce((acc, key) => ({
651
- ...acc,
652
- [key]: parseDef(def.valueType._def, {
653
- ...refs,
654
- currentPath: [...refs.currentPath, "properties", key]
655
- }) ?? {}
656
- }), {}),
657
- additionalProperties: refs.rejectedAdditionalProperties
658
- };
659
- }
660
- const schema2 = {
661
- type: "object",
662
- additionalProperties: parseDef(def.valueType._def, {
663
- ...refs,
664
- currentPath: [...refs.currentPath, "additionalProperties"]
665
- }) ?? refs.allowedAdditionalProperties
666
- };
667
- if (refs.target === "openApi3") {
668
- return schema2;
669
- }
670
- if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
671
- const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
672
- return {
673
- ...schema2,
674
- propertyNames: keyType
675
- };
676
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
677
- return {
678
- ...schema2,
679
- propertyNames: {
680
- enum: def.keyType._def.values
681
- }
682
- };
683
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
684
- const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
685
- return {
686
- ...schema2,
687
- propertyNames: keyType
688
- };
689
- }
690
- return schema2;
691
- }
692
-
693
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
694
- function parseMapDef(def, refs) {
695
- if (refs.mapStrategy === "record") {
696
- return parseRecordDef(def, refs);
697
- }
698
- const keys = parseDef(def.keyType._def, {
699
- ...refs,
700
- currentPath: [...refs.currentPath, "items", "items", "0"]
701
- }) || {};
702
- const values = parseDef(def.valueType._def, {
703
- ...refs,
704
- currentPath: [...refs.currentPath, "items", "items", "1"]
705
- }) || {};
706
- return {
707
- type: "array",
708
- maxItems: 125,
709
- items: {
710
- type: "array",
711
- items: [keys, values],
712
- minItems: 2,
713
- maxItems: 2
714
- }
715
- };
716
- }
717
-
718
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
719
- function parseNativeEnumDef(def) {
720
- const object = def.values;
721
- const actualKeys = Object.keys(def.values).filter((key) => {
722
- return typeof object[object[key]] !== "number";
723
- });
724
- const actualValues = actualKeys.map((key) => object[key]);
725
- const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
726
- return {
727
- type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
728
- enum: actualValues
729
- };
730
- }
731
-
732
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
733
- function parseNeverDef() {
734
- return {
735
- not: {}
736
- };
737
- }
738
-
739
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
740
- function parseNullDef(refs) {
741
- return refs.target === "openApi3" ? {
742
- enum: ["null"],
743
- nullable: true
744
- } : {
745
- type: "null"
746
- };
747
- }
748
-
749
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
750
- var primitiveMappings = {
751
- ZodString: "string",
752
- ZodNumber: "number",
753
- ZodBigInt: "integer",
754
- ZodBoolean: "boolean",
755
- ZodNull: "null"
756
- };
757
- function parseUnionDef(def, refs) {
758
- if (refs.target === "openApi3")
759
- return asAnyOf(def, refs);
760
- const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
761
- if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
762
- const types = options.reduce((types2, x) => {
763
- const type = primitiveMappings[x._def.typeName];
764
- return type && !types2.includes(type) ? [...types2, type] : types2;
765
- }, []);
766
- return {
767
- type: types.length > 1 ? types : types[0]
768
- };
769
- } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
770
- const types = options.reduce((acc, x) => {
771
- const type = typeof x._def.value;
772
- switch (type) {
773
- case "string":
774
- case "number":
775
- case "boolean":
776
- return [...acc, type];
777
- case "bigint":
778
- return [...acc, "integer"];
779
- case "object":
780
- if (x._def.value === null)
781
- return [...acc, "null"];
782
- case "symbol":
783
- case "undefined":
784
- case "function":
785
- default:
786
- return acc;
787
- }
788
- }, []);
789
- if (types.length === options.length) {
790
- const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
791
- return {
792
- type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
793
- enum: options.reduce((acc, x) => {
794
- return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
795
- }, [])
796
- };
797
- }
798
- } else if (options.every((x) => x._def.typeName === "ZodEnum")) {
799
- return {
800
- type: "string",
801
- enum: options.reduce((acc, x) => [
802
- ...acc,
803
- ...x._def.values.filter((x2) => !acc.includes(x2))
804
- ], [])
805
- };
806
- }
807
- return asAnyOf(def, refs);
808
- }
809
- var asAnyOf = (def, refs) => {
810
- const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
811
- ...refs,
812
- currentPath: [...refs.currentPath, "anyOf", `${i}`]
813
- })).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
814
- return anyOf.length ? { anyOf } : void 0;
815
- };
816
-
817
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
818
- function parseNullableDef(def, refs) {
819
- if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
820
- if (refs.target === "openApi3") {
821
- return {
822
- type: primitiveMappings[def.innerType._def.typeName],
823
- nullable: true
824
- };
825
- }
826
- return {
827
- type: [
828
- primitiveMappings[def.innerType._def.typeName],
829
- "null"
830
- ]
831
- };
832
- }
833
- if (refs.target === "openApi3") {
834
- const base2 = parseDef(def.innerType._def, {
835
- ...refs,
836
- currentPath: [...refs.currentPath]
837
- });
838
- if (base2 && "$ref" in base2)
839
- return { allOf: [base2], nullable: true };
840
- return base2 && { ...base2, nullable: true };
841
- }
842
- const base = parseDef(def.innerType._def, {
843
- ...refs,
844
- currentPath: [...refs.currentPath, "anyOf", "0"]
845
- });
846
- return base && { anyOf: [base, { type: "null" }] };
847
- }
848
-
849
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
850
- function parseNumberDef(def, refs) {
851
- const res = {
852
- type: "number"
853
- };
854
- if (!def.checks)
855
- return res;
856
- for (const check of def.checks) {
857
- switch (check.kind) {
858
- case "int":
859
- res.type = "integer";
860
- addErrorMessage(res, "type", check.message, refs);
861
- break;
862
- case "min":
863
- if (refs.target === "jsonSchema7") {
864
- if (check.inclusive) {
865
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
866
- } else {
867
- setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
868
- }
869
- } else {
870
- if (!check.inclusive) {
871
- res.exclusiveMinimum = true;
872
- }
873
- setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
874
- }
875
- break;
876
- case "max":
877
- if (refs.target === "jsonSchema7") {
878
- if (check.inclusive) {
879
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
880
- } else {
881
- setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
882
- }
883
- } else {
884
- if (!check.inclusive) {
885
- res.exclusiveMaximum = true;
886
- }
887
- setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
888
- }
889
- break;
890
- case "multipleOf":
891
- setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
892
- break;
893
- }
894
- }
895
- return res;
896
- }
897
-
898
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
899
- import { ZodOptional } from "zod";
900
- function parseObjectDef(def, refs) {
901
- const forceOptionalIntoNullable = refs.target === "openAi";
902
- const result = {
903
- type: "object",
904
- properties: {}
905
- };
906
- const required = [];
907
- const shape = def.shape();
908
- for (const propName in shape) {
909
- let propDef = shape[propName];
910
- if (propDef === void 0 || propDef._def === void 0) {
911
- continue;
912
- }
913
- let propOptional = safeIsOptional(propDef);
914
- if (propOptional && forceOptionalIntoNullable) {
915
- if (propDef instanceof ZodOptional) {
916
- propDef = propDef._def.innerType;
917
- }
918
- if (!propDef.isNullable()) {
919
- propDef = propDef.nullable();
920
- }
921
- propOptional = false;
922
- }
923
- const parsedDef = parseDef(propDef._def, {
924
- ...refs,
925
- currentPath: [...refs.currentPath, "properties", propName],
926
- propertyPath: [...refs.currentPath, "properties", propName]
927
- });
928
- if (parsedDef === void 0) {
929
- continue;
930
- }
931
- result.properties[propName] = parsedDef;
932
- if (!propOptional) {
933
- required.push(propName);
934
- }
935
- }
936
- if (required.length) {
937
- result.required = required;
938
- }
939
- const additionalProperties = decideAdditionalProperties(def, refs);
940
- if (additionalProperties !== void 0) {
941
- result.additionalProperties = additionalProperties;
942
- }
943
- return result;
944
- }
945
- function decideAdditionalProperties(def, refs) {
946
- if (def.catchall._def.typeName !== "ZodNever") {
947
- return parseDef(def.catchall._def, {
948
- ...refs,
949
- currentPath: [...refs.currentPath, "additionalProperties"]
950
- });
951
- }
952
- switch (def.unknownKeys) {
953
- case "passthrough":
954
- return refs.allowedAdditionalProperties;
955
- case "strict":
956
- return refs.rejectedAdditionalProperties;
957
- case "strip":
958
- return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
959
- }
960
- }
961
- function safeIsOptional(schema2) {
962
- try {
963
- return schema2.isOptional();
964
- } catch {
965
- return true;
966
- }
967
- }
968
-
969
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
970
- var parseOptionalDef = (def, refs) => {
971
- if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
972
- return parseDef(def.innerType._def, refs);
973
- }
974
- const innerSchema = parseDef(def.innerType._def, {
975
- ...refs,
976
- currentPath: [...refs.currentPath, "anyOf", "1"]
977
- });
978
- return innerSchema ? {
979
- anyOf: [
980
- {
981
- not: {}
982
- },
983
- innerSchema
984
- ]
985
- } : {};
986
- };
987
-
988
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
989
- var parsePipelineDef = (def, refs) => {
990
- if (refs.pipeStrategy === "input") {
991
- return parseDef(def.in._def, refs);
992
- } else if (refs.pipeStrategy === "output") {
993
- return parseDef(def.out._def, refs);
994
- }
995
- const a = parseDef(def.in._def, {
996
- ...refs,
997
- currentPath: [...refs.currentPath, "allOf", "0"]
998
- });
999
- const b = parseDef(def.out._def, {
1000
- ...refs,
1001
- currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
1002
- });
1003
- return {
1004
- allOf: [a, b].filter((x) => x !== void 0)
1005
- };
1006
- };
1007
-
1008
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
1009
- function parsePromiseDef(def, refs) {
1010
- return parseDef(def.type._def, refs);
1011
- }
1012
-
1013
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
1014
- function parseSetDef(def, refs) {
1015
- const items = parseDef(def.valueType._def, {
1016
- ...refs,
1017
- currentPath: [...refs.currentPath, "items"]
1018
- });
1019
- const schema2 = {
1020
- type: "array",
1021
- uniqueItems: true,
1022
- items
1023
- };
1024
- if (def.minSize) {
1025
- setResponseValueAndErrors(schema2, "minItems", def.minSize.value, def.minSize.message, refs);
1026
- }
1027
- if (def.maxSize) {
1028
- setResponseValueAndErrors(schema2, "maxItems", def.maxSize.value, def.maxSize.message, refs);
1029
- }
1030
- return schema2;
1031
- }
1032
-
1033
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
1034
- function parseTupleDef(def, refs) {
1035
- if (def.rest) {
1036
- return {
1037
- type: "array",
1038
- minItems: def.items.length,
1039
- items: def.items.map((x, i) => parseDef(x._def, {
1040
- ...refs,
1041
- currentPath: [...refs.currentPath, "items", `${i}`]
1042
- })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
1043
- additionalItems: parseDef(def.rest._def, {
1044
- ...refs,
1045
- currentPath: [...refs.currentPath, "additionalItems"]
1046
- })
1047
- };
1048
- } else {
1049
- return {
1050
- type: "array",
1051
- minItems: def.items.length,
1052
- maxItems: def.items.length,
1053
- items: def.items.map((x, i) => parseDef(x._def, {
1054
- ...refs,
1055
- currentPath: [...refs.currentPath, "items", `${i}`]
1056
- })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
1057
- };
1058
- }
1059
- }
1060
-
1061
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
1062
- function parseUndefinedDef() {
1063
- return {
1064
- not: {}
1065
- };
1066
- }
1067
-
1068
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
1069
- function parseUnknownDef() {
1070
- return {};
1071
- }
1072
-
1073
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
1074
- var parseReadonlyDef = (def, refs) => {
1075
- return parseDef(def.innerType._def, refs);
1076
- };
1077
-
1078
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/selectParser.js
1079
- var selectParser = (def, typeName, refs) => {
1080
- switch (typeName) {
1081
- case ZodFirstPartyTypeKind3.ZodString:
1082
- return parseStringDef(def, refs);
1083
- case ZodFirstPartyTypeKind3.ZodNumber:
1084
- return parseNumberDef(def, refs);
1085
- case ZodFirstPartyTypeKind3.ZodObject:
1086
- return parseObjectDef(def, refs);
1087
- case ZodFirstPartyTypeKind3.ZodBigInt:
1088
- return parseBigintDef(def, refs);
1089
- case ZodFirstPartyTypeKind3.ZodBoolean:
1090
- return parseBooleanDef();
1091
- case ZodFirstPartyTypeKind3.ZodDate:
1092
- return parseDateDef(def, refs);
1093
- case ZodFirstPartyTypeKind3.ZodUndefined:
1094
- return parseUndefinedDef();
1095
- case ZodFirstPartyTypeKind3.ZodNull:
1096
- return parseNullDef(refs);
1097
- case ZodFirstPartyTypeKind3.ZodArray:
1098
- return parseArrayDef(def, refs);
1099
- case ZodFirstPartyTypeKind3.ZodUnion:
1100
- case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
1101
- return parseUnionDef(def, refs);
1102
- case ZodFirstPartyTypeKind3.ZodIntersection:
1103
- return parseIntersectionDef(def, refs);
1104
- case ZodFirstPartyTypeKind3.ZodTuple:
1105
- return parseTupleDef(def, refs);
1106
- case ZodFirstPartyTypeKind3.ZodRecord:
1107
- return parseRecordDef(def, refs);
1108
- case ZodFirstPartyTypeKind3.ZodLiteral:
1109
- return parseLiteralDef(def, refs);
1110
- case ZodFirstPartyTypeKind3.ZodEnum:
1111
- return parseEnumDef(def);
1112
- case ZodFirstPartyTypeKind3.ZodNativeEnum:
1113
- return parseNativeEnumDef(def);
1114
- case ZodFirstPartyTypeKind3.ZodNullable:
1115
- return parseNullableDef(def, refs);
1116
- case ZodFirstPartyTypeKind3.ZodOptional:
1117
- return parseOptionalDef(def, refs);
1118
- case ZodFirstPartyTypeKind3.ZodMap:
1119
- return parseMapDef(def, refs);
1120
- case ZodFirstPartyTypeKind3.ZodSet:
1121
- return parseSetDef(def, refs);
1122
- case ZodFirstPartyTypeKind3.ZodLazy:
1123
- return () => def.getter()._def;
1124
- case ZodFirstPartyTypeKind3.ZodPromise:
1125
- return parsePromiseDef(def, refs);
1126
- case ZodFirstPartyTypeKind3.ZodNaN:
1127
- case ZodFirstPartyTypeKind3.ZodNever:
1128
- return parseNeverDef();
1129
- case ZodFirstPartyTypeKind3.ZodEffects:
1130
- return parseEffectsDef(def, refs);
1131
- case ZodFirstPartyTypeKind3.ZodAny:
1132
- return parseAnyDef();
1133
- case ZodFirstPartyTypeKind3.ZodUnknown:
1134
- return parseUnknownDef();
1135
- case ZodFirstPartyTypeKind3.ZodDefault:
1136
- return parseDefaultDef(def, refs);
1137
- case ZodFirstPartyTypeKind3.ZodBranded:
1138
- return parseBrandedDef(def, refs);
1139
- case ZodFirstPartyTypeKind3.ZodReadonly:
1140
- return parseReadonlyDef(def, refs);
1141
- case ZodFirstPartyTypeKind3.ZodCatch:
1142
- return parseCatchDef(def, refs);
1143
- case ZodFirstPartyTypeKind3.ZodPipeline:
1144
- return parsePipelineDef(def, refs);
1145
- case ZodFirstPartyTypeKind3.ZodFunction:
1146
- case ZodFirstPartyTypeKind3.ZodVoid:
1147
- case ZodFirstPartyTypeKind3.ZodSymbol:
1148
- return void 0;
1149
- default:
1150
- return /* @__PURE__ */ ((_) => void 0)(typeName);
1151
- }
1152
- };
1153
-
1154
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/parseDef.js
1155
- function parseDef(def, refs, forceResolution = false) {
1156
- const seenItem = refs.seen.get(def);
1157
- if (refs.override) {
1158
- const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
1159
- if (overrideResult !== ignoreOverride) {
1160
- return overrideResult;
1161
- }
1162
- }
1163
- if (seenItem && !forceResolution) {
1164
- const seenSchema = get$ref(seenItem, refs);
1165
- if (seenSchema !== void 0) {
1166
- return seenSchema;
1167
- }
1168
- }
1169
- const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
1170
- refs.seen.set(def, newItem);
1171
- const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
1172
- const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
1173
- if (jsonSchema) {
1174
- addMeta(def, refs, jsonSchema);
1175
- }
1176
- if (refs.postProcess) {
1177
- const postProcessResult = refs.postProcess(jsonSchema, def, refs);
1178
- newItem.jsonSchema = jsonSchema;
1179
- return postProcessResult;
1180
- }
1181
- newItem.jsonSchema = jsonSchema;
1182
- return jsonSchema;
1183
- }
1184
- var get$ref = (item, refs) => {
1185
- switch (refs.$refStrategy) {
1186
- case "root":
1187
- return { $ref: item.path.join("/") };
1188
- case "relative":
1189
- return { $ref: getRelativePath(refs.currentPath, item.path) };
1190
- case "none":
1191
- case "seen": {
1192
- if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
1193
- console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
1194
- return {};
1195
- }
1196
- return refs.$refStrategy === "seen" ? {} : void 0;
1197
- }
1198
- }
1199
- };
1200
- var getRelativePath = (pathA, pathB) => {
1201
- let i = 0;
1202
- for (; i < pathA.length && i < pathB.length; i++) {
1203
- if (pathA[i] !== pathB[i])
1204
- break;
1205
- }
1206
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
1207
- };
1208
- var addMeta = (def, refs, jsonSchema) => {
1209
- if (def.description) {
1210
- jsonSchema.description = def.description;
1211
- if (refs.markdownDescription) {
1212
- jsonSchema.markdownDescription = def.description;
1213
- }
1214
- }
1215
- return jsonSchema;
1216
- };
1217
-
1218
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.4/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
1219
- var zodToJsonSchema = (schema2, options) => {
1220
- const refs = getRefs(options);
1221
- const definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema3]) => ({
1222
- ...acc,
1223
- [name2]: parseDef(schema3._def, {
1224
- ...refs,
1225
- currentPath: [...refs.basePath, refs.definitionPath, name2]
1226
- }, true) ?? {}
1227
- }), {}) : void 0;
1228
- const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
1229
- const main = parseDef(schema2._def, name === void 0 ? refs : {
1230
- ...refs,
1231
- currentPath: [...refs.basePath, refs.definitionPath, name]
1232
- }, false) ?? {};
1233
- const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1234
- if (title !== void 0) {
1235
- main.title = title;
1236
- }
1237
- const combined = name === void 0 ? definitions ? {
1238
- ...main,
1239
- [refs.definitionPath]: definitions
1240
- } : main : {
1241
- $ref: [
1242
- ...refs.$refStrategy === "relative" ? [] : refs.basePath,
1243
- refs.definitionPath,
1244
- name
1245
- ].join("/"),
1246
- [refs.definitionPath]: {
1247
- ...definitions,
1248
- [name]: main
1249
- }
1250
- };
1251
- if (refs.target === "jsonSchema7") {
1252
- combined.$schema = "http://json-schema.org/draft-07/schema#";
1253
- } else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
1254
- combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
1255
- }
1256
- if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
1257
- console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
1258
- }
1259
- return combined;
1260
- };
2
+ import { writeFile } from "fs/promises";
3
+ import { resolve } from "path";
4
+ import { z as z2 } from "zod/v4";
1261
5
 
1262
6
  // src/config.ts
1263
7
  import * as R7 from "ramda";
1264
- import { z } from "zod";
8
+ import { z } from "zod/v4";
1265
9
 
1266
10
  // src/colors/utils.ts
1267
11
  import chroma from "chroma-js";
@@ -1563,45 +307,35 @@ var hexPatterns = [
1563
307
  ];
1564
308
  var reservedColorsPattern = `^(?!(?:${RESERVED_COLORS.join("|")})$)`;
1565
309
  var colorRegex = new RegExp(`^${hexPatterns.join("|")}$`);
1566
- var colorSchema = z.string({
1567
- description: `A hex color, which is used for creating a color scale. Invalid color names: ${RESERVED_COLORS.join(", ")}`
1568
- }).regex(colorRegex).transform(convertToHex);
310
+ var colorSchema = z.string().regex(colorRegex).transform(convertToHex).describe(
311
+ `A hex color, which is used for creating a color scale. Invalid color names: ${RESERVED_COLORS.join(", ")}`
312
+ );
1569
313
  var colorCategorySchema = z.record(
1570
314
  z.string().regex(new RegExp(reservedColorsPattern, "i"), {
1571
- message: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
315
+ error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
1572
316
  }),
1573
317
  colorSchema,
1574
318
  {
1575
- description: "One or more color definitions",
1576
- invalid_type_error: "Color definitions must be hex color values"
319
+ error: "Color definitions must be hex color values"
1577
320
  }
1578
321
  ).refine((colors) => !Object.keys(colors).some((key) => RESERVED_COLORS.includes(key.toLowerCase())), {
1579
- message: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
1580
- });
1581
- var themeSchema = z.object(
1582
- {
1583
- colors: z.object(
1584
- {
1585
- main: colorCategorySchema,
1586
- support: colorCategorySchema.optional().default({}),
1587
- neutral: colorSchema
1588
- },
1589
- { description: "Defines the colors for this theme" }
1590
- ),
1591
- typography: z.object(
1592
- {
1593
- fontFamily: z.string({ description: "Sets the font-family for this theme" })
1594
- },
1595
- { description: "Defines the typography for a given theme" }
1596
- ).optional(),
1597
- borderRadius: z.number({ description: "Defines the border-radius for this theme" }).optional()
1598
- },
1599
- { description: "An object defining a theme. The property name holding the object becomes the theme name." }
1600
- );
322
+ error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
323
+ }).describe("An object with one or more color definitions. The property name is used as the color name.");
324
+ var themeSchema = z.object({
325
+ colors: z.object({
326
+ main: colorCategorySchema,
327
+ support: colorCategorySchema.optional().default({}),
328
+ neutral: colorSchema
329
+ }).meta({ description: "Defines the colors for this theme" }),
330
+ typography: z.object({
331
+ fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
332
+ }).describe("Defines the typography for a given theme").optional(),
333
+ borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
334
+ }).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
1601
335
  var configFileSchema = z.object({
1602
- outDir: z.string({ description: "Path to the output directory for the created design tokens" }).optional(),
1603
- clean: z.boolean({ description: "Delete the output directory before building or creating tokens" }).optional(),
1604
- themes: z.record(themeSchema, {
336
+ outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }).optional(),
337
+ clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional(),
338
+ themes: z.record(z.string(), themeSchema).meta({
1605
339
  description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
1606
340
  })
1607
341
  });
@@ -1613,7 +347,13 @@ var schema = z2.object({
1613
347
  }).extend(configFileSchema.shape);
1614
348
  writeFile(
1615
349
  resolve(import.meta.dirname, "../../dist/config.schema.json"),
1616
- JSON.stringify(zodToJsonSchema(schema), void 0, 2),
350
+ JSON.stringify(
351
+ z2.toJSONSchema(schema, {
352
+ unrepresentable: "any"
353
+ }),
354
+ void 0,
355
+ 2
356
+ ),
1617
357
  {
1618
358
  encoding: "utf-8"
1619
359
  }