@temporary-name/server 1.9.3-alpha.e2d8d164da72fb570c2b14a4fa956c80f9e33cdc → 1.9.3-alpha.edd373b82156a10608d43b19a44b75ae72e72de7

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.
Files changed (44) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -6
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  4. package/dist/adapters/fetch/index.d.mts +8 -86
  5. package/dist/adapters/fetch/index.d.ts +8 -86
  6. package/dist/adapters/fetch/index.mjs +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -63
  8. package/dist/adapters/node/index.d.ts +8 -63
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +10 -7
  11. package/dist/adapters/standard/index.d.ts +10 -7
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +376 -242
  15. package/dist/index.d.ts +376 -242
  16. package/dist/index.mjs +482 -359
  17. package/dist/openapi/index.d.mts +18 -53
  18. package/dist/openapi/index.d.ts +18 -53
  19. package/dist/openapi/index.mjs +337 -347
  20. package/dist/shared/server.BCY45g2x.mjs +160 -0
  21. package/dist/shared/server.BETu17rq.mjs +319 -0
  22. package/dist/shared/server.B_oW_rPl.mjs +525 -0
  23. package/dist/shared/server.C1RJffw4.mjs +30 -0
  24. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  25. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  26. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  27. package/dist/shared/server.Cq7SBLD5.mjs +403 -0
  28. package/dist/shared/server.DGH2Bq4t.d.mts +41 -0
  29. package/dist/shared/server.nQoUObAJ.d.ts +41 -0
  30. package/dist/shared/server.zsKBRxsz.d.mts +388 -0
  31. package/dist/shared/server.zsKBRxsz.d.ts +388 -0
  32. package/package.json +10 -28
  33. package/dist/plugins/index.d.mts +0 -160
  34. package/dist/plugins/index.d.ts +0 -160
  35. package/dist/plugins/index.mjs +0 -288
  36. package/dist/shared/server.B93y_8tj.d.mts +0 -23
  37. package/dist/shared/server.BYYf0Wn6.mjs +0 -202
  38. package/dist/shared/server.C3RuMHWl.d.mts +0 -192
  39. package/dist/shared/server.C3RuMHWl.d.ts +0 -192
  40. package/dist/shared/server.CT1xhSmE.d.mts +0 -56
  41. package/dist/shared/server.CqTex_jI.mjs +0 -265
  42. package/dist/shared/server.D_fags8X.d.ts +0 -23
  43. package/dist/shared/server.Kxw442A9.mjs +0 -247
  44. package/dist/shared/server.cjcgLdr1.d.ts +0 -56
@@ -0,0 +1,525 @@
1
+ import { isAsyncIteratorObject, ORPCError, toArray } from '@temporary-name/shared';
2
+ import { mapEventIterator } from '@temporary-name/standard-server';
3
+ import { custom, safeParseAsync } from '@temporary-name/zod';
4
+ import { V as ValidationError } from './server.BETu17rq.mjs';
5
+ import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@temporary-name/server/openapi';
6
+ import { registry, globalRegistry } from 'zod/v4/core';
7
+
8
+ const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
9
+ function eventIterator(yields, returns) {
10
+ const schema = custom(
11
+ (iterator) => isAsyncIteratorObject(iterator)
12
+ ).transform((iterator) => {
13
+ const mapped = mapEventIterator(iterator, {
14
+ async value(value, done) {
15
+ const schema2 = done ? returns : yields;
16
+ if (!schema2) {
17
+ return value;
18
+ }
19
+ const result = await safeParseAsync(schema2, value);
20
+ if (result.success) {
21
+ return result.data;
22
+ } else {
23
+ throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
24
+ message: "Event iterator validation failed",
25
+ cause: new ValidationError({
26
+ issues: result.error.issues,
27
+ message: "Event iterator validation failed",
28
+ data: value
29
+ })
30
+ });
31
+ }
32
+ },
33
+ error: async (error) => error
34
+ });
35
+ return mapped;
36
+ });
37
+ schema[EVENT_ITERATOR_DETAILS_SYMBOL] = {
38
+ yields,
39
+ returns
40
+ };
41
+ return schema;
42
+ }
43
+ function getEventIteratorSchemaDetails(schema) {
44
+ if (schema === void 0) {
45
+ return void 0;
46
+ }
47
+ return schema[EVENT_ITERATOR_DETAILS_SYMBOL];
48
+ }
49
+
50
+ var JsonSchemaXNativeType = /* @__PURE__ */ ((JsonSchemaXNativeType2) => {
51
+ JsonSchemaXNativeType2["BigInt"] = "bigint";
52
+ JsonSchemaXNativeType2["RegExp"] = "regexp";
53
+ JsonSchemaXNativeType2["Date"] = "date";
54
+ JsonSchemaXNativeType2["Url"] = "url";
55
+ JsonSchemaXNativeType2["Set"] = "set";
56
+ JsonSchemaXNativeType2["Map"] = "map";
57
+ return JsonSchemaXNativeType2;
58
+ })(JsonSchemaXNativeType || {});
59
+
60
+ const JSON_SCHEMA_REGISTRY = registry();
61
+ const JSON_SCHEMA_INPUT_REGISTRY = registry();
62
+ const JSON_SCHEMA_OUTPUT_REGISTRY = registry();
63
+
64
+ class ZodToJsonSchemaConverter {
65
+ maxLazyDepth;
66
+ maxStructureDepth;
67
+ anyJsonSchema;
68
+ unsupportedJsonSchema;
69
+ undefinedJsonSchema;
70
+ constructor(options = {}) {
71
+ this.maxLazyDepth = options.maxLazyDepth ?? 2;
72
+ this.maxStructureDepth = options.maxStructureDepth ?? 10;
73
+ this.anyJsonSchema = options.anyJsonSchema ?? {};
74
+ this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
75
+ this.undefinedJsonSchema = options.undefinedJsonSchema ?? { not: {} };
76
+ }
77
+ convert = (schema, options) => {
78
+ return this.#convert(schema, options, 0, 0);
79
+ };
80
+ #convert(schema, options, lazyDepth, structureDepth, isHandledCustomJSONSchema = false) {
81
+ if (structureDepth > this.maxStructureDepth) {
82
+ return [false, this.anyJsonSchema];
83
+ }
84
+ if (!options.minStructureDepthForRef || options.minStructureDepthForRef <= structureDepth) {
85
+ const components = toArray(options.components);
86
+ for (const component of components) {
87
+ if (component.schema === schema && component.allowedStrategies.includes(options.strategy)) {
88
+ return [component.required, { $ref: component.ref }];
89
+ }
90
+ }
91
+ }
92
+ if (!isHandledCustomJSONSchema) {
93
+ const customJSONSchema = this.#getCustomJsonSchema(schema, options);
94
+ if (customJSONSchema) {
95
+ const [required, json] = this.#convert(schema, options, lazyDepth, structureDepth, true);
96
+ return [required, { ...json, ...customJSONSchema }];
97
+ }
98
+ }
99
+ switch (schema._zod.def.type) {
100
+ case "string": {
101
+ const string = schema;
102
+ const json = { type: "string" };
103
+ const { minimum, maximum, format, patterns, contentEncoding } = string._zod.bag;
104
+ if (typeof minimum === "number") {
105
+ json.minLength = minimum;
106
+ }
107
+ if (typeof maximum === "number") {
108
+ json.maxLength = maximum;
109
+ }
110
+ if (typeof contentEncoding === "string") {
111
+ json.contentEncoding = this.#handleContentEncoding(contentEncoding);
112
+ }
113
+ if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
114
+ json.format = this.#handleStringFormat(format);
115
+ }
116
+ if (patterns instanceof Set && json.contentEncoding === void 0 && json.format === void 0) {
117
+ for (const pattern of patterns) {
118
+ if (json.pattern === void 0) {
119
+ json.pattern = pattern.source;
120
+ } else {
121
+ json.allOf ??= [];
122
+ json.allOf.push({ pattern: pattern.source });
123
+ }
124
+ }
125
+ }
126
+ if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
127
+ json.pattern = /^[\w-]+\.[\w-]+\.[\w-]+$/.source;
128
+ }
129
+ return [true, json];
130
+ }
131
+ case "number": {
132
+ const number = schema;
133
+ const json = { type: "number" };
134
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = number._zod.bag;
135
+ if (typeof format === "string" && format?.includes("int")) {
136
+ json.type = "integer";
137
+ }
138
+ if (typeof minimum === "number") {
139
+ json.minimum = minimum;
140
+ }
141
+ if (typeof maximum === "number") {
142
+ json.maximum = maximum;
143
+ }
144
+ if (typeof exclusiveMinimum === "number") {
145
+ json.exclusiveMinimum = exclusiveMinimum;
146
+ }
147
+ if (typeof exclusiveMaximum === "number") {
148
+ json.exclusiveMaximum = exclusiveMaximum;
149
+ }
150
+ if (typeof multipleOf === "number") {
151
+ json.multipleOf = multipleOf;
152
+ }
153
+ return [true, json];
154
+ }
155
+ case "boolean": {
156
+ return [true, { type: "boolean" }];
157
+ }
158
+ case "bigint": {
159
+ return [
160
+ true,
161
+ {
162
+ type: "string",
163
+ pattern: "^-?[0-9]+$",
164
+ "x-native-type": JsonSchemaXNativeType.BigInt
165
+ }
166
+ ];
167
+ }
168
+ case "date": {
169
+ return [
170
+ true,
171
+ {
172
+ type: "string",
173
+ format: JSONSchemaFormat.DateTime,
174
+ "x-native-type": JsonSchemaXNativeType.Date
175
+ }
176
+ ];
177
+ }
178
+ case "null": {
179
+ return [true, { type: "null" }];
180
+ }
181
+ case "undefined":
182
+ case "void": {
183
+ return [false, this.undefinedJsonSchema];
184
+ }
185
+ case "any": {
186
+ return [false, this.anyJsonSchema];
187
+ }
188
+ case "unknown": {
189
+ return [false, this.anyJsonSchema];
190
+ }
191
+ case "never": {
192
+ return [true, this.unsupportedJsonSchema];
193
+ }
194
+ case "array": {
195
+ const array = schema;
196
+ const json = { type: "array" };
197
+ const { minimum, maximum } = array._zod.bag;
198
+ if (typeof minimum === "number") {
199
+ json.minItems = minimum;
200
+ }
201
+ if (typeof maximum === "number") {
202
+ json.maxItems = maximum;
203
+ }
204
+ json.items = this.#handleArrayItemJsonSchema(
205
+ this.#convert(array._zod.def.element, options, lazyDepth, structureDepth + 1),
206
+ options
207
+ );
208
+ return [true, json];
209
+ }
210
+ case "object": {
211
+ const object = schema;
212
+ const json = { type: "object" };
213
+ for (const [key, value] of Object.entries(object._zod.def.shape)) {
214
+ const [itemRequired, itemJson] = this.#convert(value, options, lazyDepth, structureDepth + 1);
215
+ json.properties ??= {};
216
+ json.properties[key] = itemJson;
217
+ if (itemRequired) {
218
+ json.required ??= [];
219
+ json.required.push(key);
220
+ }
221
+ }
222
+ if (object._zod.def.catchall) {
223
+ if (object._zod.def.catchall._zod.def.type === "never") {
224
+ json.additionalProperties = false;
225
+ } else {
226
+ const [_, addJson] = this.#convert(
227
+ object._zod.def.catchall,
228
+ options,
229
+ lazyDepth,
230
+ structureDepth + 1
231
+ );
232
+ json.additionalProperties = addJson;
233
+ }
234
+ }
235
+ return [true, json];
236
+ }
237
+ case "union": {
238
+ const union = schema;
239
+ const anyOf = [];
240
+ let required = true;
241
+ for (const item of union._zod.def.options) {
242
+ const [itemRequired, itemJson] = this.#convert(item, options, lazyDepth, structureDepth);
243
+ if (!itemRequired) {
244
+ required = false;
245
+ }
246
+ if (options.strategy === "input") {
247
+ if (itemJson !== this.undefinedJsonSchema && itemJson !== this.unsupportedJsonSchema) {
248
+ anyOf.push(itemJson);
249
+ }
250
+ } else {
251
+ if (itemJson !== this.undefinedJsonSchema) {
252
+ anyOf.push(itemJson);
253
+ }
254
+ }
255
+ }
256
+ return [required, anyOf.length === 1 ? anyOf[0] : { anyOf }];
257
+ }
258
+ case "intersection": {
259
+ const intersection = schema;
260
+ const json = { allOf: [] };
261
+ let required = false;
262
+ for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
263
+ const [itemRequired, itemJson] = this.#convert(item, options, lazyDepth, structureDepth);
264
+ json.allOf.push(itemJson);
265
+ if (itemRequired) {
266
+ required = true;
267
+ }
268
+ }
269
+ return [required, json];
270
+ }
271
+ case "tuple": {
272
+ const tuple = schema;
273
+ const json = { type: "array", prefixItems: [] };
274
+ for (const item of tuple._zod.def.items) {
275
+ json.prefixItems.push(
276
+ this.#handleArrayItemJsonSchema(
277
+ this.#convert(item, options, lazyDepth, structureDepth + 1),
278
+ options
279
+ )
280
+ );
281
+ }
282
+ if (tuple._zod.def.rest) {
283
+ json.items = this.#handleArrayItemJsonSchema(
284
+ this.#convert(tuple._zod.def.rest, options, lazyDepth, structureDepth + 1),
285
+ options
286
+ );
287
+ }
288
+ const { minimum, maximum } = tuple._zod.bag;
289
+ if (typeof minimum === "number") {
290
+ json.minItems = minimum;
291
+ }
292
+ if (typeof maximum === "number") {
293
+ json.maxItems = maximum;
294
+ }
295
+ return [true, json];
296
+ }
297
+ case "record": {
298
+ const record = schema;
299
+ const json = { type: "object" };
300
+ json.propertyNames = this.#convert(
301
+ record._zod.def.keyType,
302
+ options,
303
+ lazyDepth,
304
+ structureDepth + 1
305
+ )[1];
306
+ json.additionalProperties = this.#convert(
307
+ record._zod.def.valueType,
308
+ options,
309
+ lazyDepth,
310
+ structureDepth + 1
311
+ )[1];
312
+ return [true, json];
313
+ }
314
+ case "map": {
315
+ const map = schema;
316
+ return [
317
+ true,
318
+ {
319
+ type: "array",
320
+ items: {
321
+ type: "array",
322
+ prefixItems: [
323
+ this.#handleArrayItemJsonSchema(
324
+ this.#convert(map._zod.def.keyType, options, lazyDepth, structureDepth + 1),
325
+ options
326
+ ),
327
+ this.#handleArrayItemJsonSchema(
328
+ this.#convert(map._zod.def.valueType, options, lazyDepth, structureDepth + 1),
329
+ options
330
+ )
331
+ ],
332
+ maxItems: 2,
333
+ minItems: 2
334
+ },
335
+ "x-native-type": JsonSchemaXNativeType.Map
336
+ }
337
+ ];
338
+ }
339
+ case "set": {
340
+ const set = schema;
341
+ return [
342
+ true,
343
+ {
344
+ type: "array",
345
+ uniqueItems: true,
346
+ items: this.#handleArrayItemJsonSchema(
347
+ this.#convert(set._zod.def.valueType, options, lazyDepth, structureDepth + 1),
348
+ options
349
+ ),
350
+ "x-native-type": JsonSchemaXNativeType.Set
351
+ }
352
+ ];
353
+ }
354
+ case "enum": {
355
+ const enum_ = schema;
356
+ return [true, { enum: Object.values(enum_._zod.def.entries) }];
357
+ }
358
+ case "literal": {
359
+ const literal = schema;
360
+ let required = true;
361
+ const values = /* @__PURE__ */ new Set();
362
+ for (const value of literal._zod.def.values) {
363
+ if (value === void 0) {
364
+ required = false;
365
+ } else {
366
+ values.add(typeof value === "bigint" ? value.toString() : value);
367
+ }
368
+ }
369
+ const json = values.size === 0 ? this.undefinedJsonSchema : values.size === 1 ? { const: values.values().next().value } : { enum: Array.from(values) };
370
+ return [required, json];
371
+ }
372
+ case "file": {
373
+ const file = schema;
374
+ const oneOf = [];
375
+ const { mime } = file._zod.bag;
376
+ if (mime === void 0 || Array.isArray(mime) && mime.every((m) => typeof m === "string")) {
377
+ for (const type of mime ?? ["*/*"]) {
378
+ oneOf.push({
379
+ type: "string",
380
+ contentMediaType: type
381
+ });
382
+ }
383
+ }
384
+ return [true, oneOf.length === 1 ? oneOf[0] : { anyOf: oneOf }];
385
+ }
386
+ case "transform": {
387
+ return [false, this.anyJsonSchema];
388
+ }
389
+ case "nullable": {
390
+ const nullable = schema;
391
+ const [required, json] = this.#convert(
392
+ nullable._zod.def.innerType,
393
+ options,
394
+ lazyDepth,
395
+ structureDepth
396
+ );
397
+ return [required, { anyOf: [json, { type: "null" }] }];
398
+ }
399
+ case "nonoptional": {
400
+ const nonoptional = schema;
401
+ const [, json] = this.#convert(nonoptional._zod.def.innerType, options, lazyDepth, structureDepth);
402
+ return [true, json];
403
+ }
404
+ case "success": {
405
+ return [true, { type: "boolean" }];
406
+ }
407
+ case "default":
408
+ case "prefault": {
409
+ const default_ = schema;
410
+ const [, json] = this.#convert(default_._zod.def.innerType, options, lazyDepth, structureDepth);
411
+ return [
412
+ false,
413
+ {
414
+ ...json,
415
+ default: default_._zod.def.defaultValue
416
+ }
417
+ ];
418
+ }
419
+ case "catch": {
420
+ const catch_ = schema;
421
+ return this.#convert(catch_._zod.def.innerType, options, lazyDepth, structureDepth);
422
+ }
423
+ case "nan": {
424
+ return [true, options.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
425
+ }
426
+ case "pipe": {
427
+ const pipe = schema;
428
+ return this.#convert(
429
+ options.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out,
430
+ options,
431
+ lazyDepth,
432
+ structureDepth
433
+ );
434
+ }
435
+ case "readonly": {
436
+ const readonly_ = schema;
437
+ const [required, json] = this.#convert(
438
+ readonly_._zod.def.innerType,
439
+ options,
440
+ lazyDepth,
441
+ structureDepth
442
+ );
443
+ return [required, { ...json, readOnly: true }];
444
+ }
445
+ case "template_literal": {
446
+ const templateLiteral = schema;
447
+ return [
448
+ true,
449
+ {
450
+ type: "string",
451
+ pattern: templateLiteral._zod.pattern.source
452
+ }
453
+ ];
454
+ }
455
+ case "optional": {
456
+ const optional = schema;
457
+ const [, json] = this.#convert(optional._zod.def.innerType, options, lazyDepth, structureDepth);
458
+ return [false, json];
459
+ }
460
+ case "lazy": {
461
+ const lazy = schema;
462
+ const currentLazyDepth = lazyDepth + 1;
463
+ if (currentLazyDepth > this.maxLazyDepth) {
464
+ return [false, this.anyJsonSchema];
465
+ }
466
+ return this.#convert(lazy._zod.def.getter(), options, currentLazyDepth, structureDepth);
467
+ }
468
+ default: {
469
+ schema._zod.def.type;
470
+ return [true, this.unsupportedJsonSchema];
471
+ }
472
+ }
473
+ }
474
+ #getCustomJsonSchema(schema, options) {
475
+ if (options.strategy === "input" && JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
476
+ return JSON_SCHEMA_INPUT_REGISTRY.get(schema);
477
+ }
478
+ if (options.strategy === "output" && JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
479
+ return JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
480
+ }
481
+ if (JSON_SCHEMA_REGISTRY.has(schema)) {
482
+ return JSON_SCHEMA_REGISTRY.get(schema);
483
+ }
484
+ const global = globalRegistry.get(schema);
485
+ if (global) {
486
+ return {
487
+ title: global.title,
488
+ description: global.description,
489
+ examples: Array.isArray(global.examples) ? global.examples : void 0
490
+ };
491
+ }
492
+ }
493
+ #handleArrayItemJsonSchema([required, schema], options) {
494
+ if (required || options.strategy === "input" || schema.default !== void 0) {
495
+ return schema;
496
+ }
497
+ if (schema === this.undefinedJsonSchema) {
498
+ return { type: "null" };
499
+ }
500
+ return {
501
+ anyOf: [
502
+ // schema can contain { type: 'null' } so we should use anyOf instead of oneOf
503
+ schema,
504
+ { type: "null" }
505
+ ]
506
+ };
507
+ }
508
+ #handleStringFormat(format) {
509
+ if (format === "guid") {
510
+ return JSONSchemaFormat.UUID;
511
+ }
512
+ if (format === "url") {
513
+ return JSONSchemaFormat.URI;
514
+ }
515
+ if (format === "datetime") {
516
+ return JSONSchemaFormat.DateTime;
517
+ }
518
+ return Object.values(JSONSchemaFormat).includes(format) ? format : void 0;
519
+ }
520
+ #handleContentEncoding(contentEncoding) {
521
+ return Object.values(JSONSchemaContentEncoding).includes(contentEncoding) ? contentEncoding : void 0;
522
+ }
523
+ }
524
+
525
+ export { JsonSchemaXNativeType as J, ZodToJsonSchemaConverter as Z, JSON_SCHEMA_REGISTRY as a, JSON_SCHEMA_INPUT_REGISTRY as b, JSON_SCHEMA_OUTPUT_REGISTRY as c, eventIterator as e, getEventIteratorSchemaDetails as g };
@@ -0,0 +1,30 @@
1
+ import { parse, serialize } from 'cookie';
2
+
3
+ function setCookie(headers, name, value, options = {}) {
4
+ if (headers === void 0) {
5
+ return;
6
+ }
7
+ const cookieString = serialize(name, value, {
8
+ path: "/",
9
+ ...options
10
+ });
11
+ headers.append("Set-Cookie", cookieString);
12
+ }
13
+ function getCookie(headers, name, options = {}) {
14
+ if (headers === void 0) {
15
+ return void 0;
16
+ }
17
+ const cookieHeader = headers.get("cookie");
18
+ if (cookieHeader === null) {
19
+ return void 0;
20
+ }
21
+ return parse(cookieHeader, options)[name];
22
+ }
23
+ function deleteCookie(headers, name, options = {}) {
24
+ return setCookie(headers, name, "", {
25
+ ...options,
26
+ maxAge: 0
27
+ });
28
+ }
29
+
30
+ export { deleteCookie as d, getCookie as g, setCookie as s };
@@ -0,0 +1,40 @@
1
+ import { isObject } from '@temporary-name/shared';
2
+
3
+ function jsonSerialize(data, hasBlobRef = { value: false }) {
4
+ if (data instanceof Blob) {
5
+ hasBlobRef.value = true;
6
+ return [data, hasBlobRef.value];
7
+ }
8
+ if (data instanceof Set) {
9
+ return jsonSerialize(Array.from(data), hasBlobRef);
10
+ }
11
+ if (data instanceof Map) {
12
+ return jsonSerialize(Array.from(data.entries()), hasBlobRef);
13
+ }
14
+ if (Array.isArray(data)) {
15
+ const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
16
+ return [json, hasBlobRef.value];
17
+ }
18
+ if (isObject(data)) {
19
+ const json = {};
20
+ for (const k in data) {
21
+ if (k === "toJSON" && typeof data[k] === "function") {
22
+ continue;
23
+ }
24
+ json[k] = jsonSerialize(data[k], hasBlobRef)[0];
25
+ }
26
+ return [json, hasBlobRef.value];
27
+ }
28
+ if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
29
+ return [data.toString(), hasBlobRef.value];
30
+ }
31
+ if (data instanceof Date) {
32
+ return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
33
+ }
34
+ if (Number.isNaN(data)) {
35
+ return [null, hasBlobRef.value];
36
+ }
37
+ return [data, hasBlobRef.value];
38
+ }
39
+
40
+ export { jsonSerialize as j };
@@ -0,0 +1,51 @@
1
+ import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
2
+
3
+ interface ZodToJsonSchemaConverterOptions {
4
+ /**
5
+ * Max depth of lazy type.
6
+ *
7
+ * Used anyJsonSchema (`{}`) when exceed max depth
8
+ *
9
+ * @default 2
10
+ */
11
+ maxLazyDepth?: number;
12
+ /**
13
+ * Max depth of nested types.
14
+ *
15
+ * Used anyJsonSchema (`{}`) when exceed max depth
16
+ *
17
+ * @default 10
18
+ */
19
+ maxStructureDepth?: number;
20
+ /**
21
+ * The schema to be used to represent the any | unknown type.
22
+ *
23
+ * @default { }
24
+ */
25
+ anyJsonSchema?: Exclude<JSONSchema, boolean>;
26
+ /**
27
+ * The schema to be used when the Zod schema is unsupported.
28
+ *
29
+ * @default { not: {} }
30
+ */
31
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
32
+ /**
33
+ * The schema to be used to represent the undefined type.
34
+ *
35
+ * @default { not: {} }
36
+ */
37
+ undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
38
+ }
39
+ declare class ZodToJsonSchemaConverter {
40
+ #private;
41
+ private readonly maxLazyDepth;
42
+ private readonly maxStructureDepth;
43
+ private readonly anyJsonSchema;
44
+ private readonly unsupportedJsonSchema;
45
+ private readonly undefinedJsonSchema;
46
+ constructor(options?: ZodToJsonSchemaConverterOptions);
47
+ convert: SchemaConverter;
48
+ }
49
+
50
+ export { ZodToJsonSchemaConverter as a };
51
+ export type { ZodToJsonSchemaConverterOptions as Z };
@@ -0,0 +1,51 @@
1
+ import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
2
+
3
+ interface ZodToJsonSchemaConverterOptions {
4
+ /**
5
+ * Max depth of lazy type.
6
+ *
7
+ * Used anyJsonSchema (`{}`) when exceed max depth
8
+ *
9
+ * @default 2
10
+ */
11
+ maxLazyDepth?: number;
12
+ /**
13
+ * Max depth of nested types.
14
+ *
15
+ * Used anyJsonSchema (`{}`) when exceed max depth
16
+ *
17
+ * @default 10
18
+ */
19
+ maxStructureDepth?: number;
20
+ /**
21
+ * The schema to be used to represent the any | unknown type.
22
+ *
23
+ * @default { }
24
+ */
25
+ anyJsonSchema?: Exclude<JSONSchema, boolean>;
26
+ /**
27
+ * The schema to be used when the Zod schema is unsupported.
28
+ *
29
+ * @default { not: {} }
30
+ */
31
+ unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
32
+ /**
33
+ * The schema to be used to represent the undefined type.
34
+ *
35
+ * @default { not: {} }
36
+ */
37
+ undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
38
+ }
39
+ declare class ZodToJsonSchemaConverter {
40
+ #private;
41
+ private readonly maxLazyDepth;
42
+ private readonly maxStructureDepth;
43
+ private readonly anyJsonSchema;
44
+ private readonly unsupportedJsonSchema;
45
+ private readonly undefinedJsonSchema;
46
+ constructor(options?: ZodToJsonSchemaConverterOptions);
47
+ convert: SchemaConverter;
48
+ }
49
+
50
+ export { ZodToJsonSchemaConverter as a };
51
+ export type { ZodToJsonSchemaConverterOptions as Z };