@ray-js/robot-data-stream 0.0.14 → 0.0.15-beta.1

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 (156) hide show
  1. package/lib/mqtt/createCommonOptions.d.ts +4 -2
  2. package/lib/mqtt/createCommonOptions.js +10 -5
  3. package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
  4. package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
  5. package/lib/mqtt/mqttProvider.d.ts +19 -1
  6. package/lib/mqtt/mqttProvider.js +69 -8
  7. package/lib/mqtt/promise.d.ts +57 -4
  8. package/lib/mqtt/promise.js +115 -36
  9. package/lib/mqtt/type/fun.d.ts +49 -0
  10. package/lib/mqtt/type/fun.js +145 -0
  11. package/lib/mqtt/type/index.d.ts +0 -7
  12. package/lib/mqtt/type/index.js +0 -1
  13. package/lib/mqtt/type/protocols/base.d.ts +5 -0
  14. package/lib/mqtt/type/protocols/base.js +32 -0
  15. package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
  16. package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
  17. package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
  18. package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
  19. package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
  20. package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
  21. package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
  22. package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
  23. package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
  24. package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
  25. package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
  26. package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
  27. package/lib/mqtt/type/protocols/index.d.ts +20 -0
  28. package/lib/mqtt/type/protocols/index.js +20 -0
  29. package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
  30. package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
  31. package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
  32. package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
  33. package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
  34. package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
  35. package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
  36. package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
  37. package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
  38. package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
  39. package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
  40. package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
  41. package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
  42. package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
  43. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
  44. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
  45. package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
  46. package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
  47. package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
  48. package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
  49. package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
  50. package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
  51. package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
  52. package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
  53. package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
  54. package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
  55. package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
  56. package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
  57. package/lib/mqtt/useCarpet.d.ts +7 -67
  58. package/lib/mqtt/useCarpet.js +101 -181
  59. package/lib/mqtt/useCarpetClean.d.ts +2 -11
  60. package/lib/mqtt/useCarpetClean.js +24 -51
  61. package/lib/mqtt/useDevInfo.d.ts +8 -6
  62. package/lib/mqtt/useDevInfo.js +44 -36
  63. package/lib/mqtt/useDeviceModel.d.ts +6 -19
  64. package/lib/mqtt/useDeviceModel.js +29 -42
  65. package/lib/mqtt/useFurnitureModel.d.ts +6 -18
  66. package/lib/mqtt/useFurnitureModel.js +29 -43
  67. package/lib/mqtt/useHistoryMap.d.ts +2 -18
  68. package/lib/mqtt/useHistoryMap.js +102 -119
  69. package/lib/mqtt/usePartDivision.d.ts +2 -9
  70. package/lib/mqtt/usePartDivision.js +48 -57
  71. package/lib/mqtt/usePartMerge.d.ts +2 -8
  72. package/lib/mqtt/usePartMerge.js +34 -49
  73. package/lib/mqtt/usePassword.d.ts +6 -13
  74. package/lib/mqtt/usePassword.js +84 -74
  75. package/lib/mqtt/useQuiteHours.d.ts +4 -37
  76. package/lib/mqtt/useQuiteHours.js +66 -100
  77. package/lib/mqtt/useResetMap.d.ts +2 -8
  78. package/lib/mqtt/useResetMap.js +27 -34
  79. package/lib/mqtt/useRoomProperty.d.ts +8 -9
  80. package/lib/mqtt/useRoomProperty.js +67 -65
  81. package/lib/mqtt/useSchedule.d.ts +3 -23
  82. package/lib/mqtt/useSchedule.js +72 -101
  83. package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
  84. package/lib/mqtt/useSelectRoomClean.js +107 -133
  85. package/lib/mqtt/useSpotClean.d.ts +5 -15
  86. package/lib/mqtt/useSpotClean.js +68 -121
  87. package/lib/mqtt/useVirtualArea.d.ts +6 -17
  88. package/lib/mqtt/useVirtualArea.js +109 -119
  89. package/lib/mqtt/useVirtualWall.d.ts +2 -18
  90. package/lib/mqtt/useVirtualWall.js +69 -90
  91. package/lib/mqtt/useVoice.d.ts +2 -16
  92. package/lib/mqtt/useVoice.js +48 -68
  93. package/lib/mqtt/useWifiMap.d.ts +6 -5
  94. package/lib/mqtt/useWifiMap.js +43 -42
  95. package/lib/mqtt/useZoneClean.d.ts +2 -21
  96. package/lib/mqtt/useZoneClean.js +125 -137
  97. package/lib/myLib/zod/mini/index.d.cts +1 -0
  98. package/lib/myLib/zod/mini/index.d.ts +1 -0
  99. package/lib/myLib/zod/mini/index.js +1 -0
  100. package/lib/myLib/zod/mini/package.json +6 -0
  101. package/lib/myLib/zod/src/mini/index.d.ts +1 -0
  102. package/lib/myLib/zod/src/mini/index.js +1 -0
  103. package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
  104. package/lib/myLib/zod/src/v4/core/api.js +1256 -0
  105. package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
  106. package/lib/myLib/zod/src/v4/core/checks.js +816 -0
  107. package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
  108. package/lib/myLib/zod/src/v4/core/config.js +5 -0
  109. package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
  110. package/lib/myLib/zod/src/v4/core/core.js +95 -0
  111. package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
  112. package/lib/myLib/zod/src/v4/core/doc.js +42 -0
  113. package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
  114. package/lib/myLib/zod/src/v4/core/errors.js +232 -0
  115. package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
  116. package/lib/myLib/zod/src/v4/core/index.js +15 -0
  117. package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
  118. package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
  119. package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
  120. package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
  121. package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
  122. package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
  123. package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
  124. package/lib/myLib/zod/src/v4/core/parse.js +147 -0
  125. package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
  126. package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
  127. package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
  128. package/lib/myLib/zod/src/v4/core/registries.js +51 -0
  129. package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
  130. package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
  131. package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
  132. package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
  133. package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
  134. package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
  135. package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
  136. package/lib/myLib/zod/src/v4/core/util.js +656 -0
  137. package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
  138. package/lib/myLib/zod/src/v4/core/versions.js +5 -0
  139. package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
  140. package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
  141. package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
  142. package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
  143. package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
  144. package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
  145. package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
  146. package/lib/myLib/zod/src/v4/mini/external.js +16 -0
  147. package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
  148. package/lib/myLib/zod/src/v4/mini/index.js +3 -0
  149. package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
  150. package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
  151. package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
  152. package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
  153. package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
  154. package/lib/utils/index.d.ts +1 -0
  155. package/lib/utils/index.js +2 -1
  156. package/package.json +5 -3
@@ -0,0 +1,593 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.every.js";
4
+ import "core-js/modules/esnext.iterator.filter.js";
5
+ import "core-js/modules/esnext.iterator.map.js";
6
+ import { extractDefs, finalize, initializeContext, process } from "./to-json-schema.js";
7
+ import { getEnumValues } from "./util.js";
8
+ const formatMap = {
9
+ guid: "uuid",
10
+ url: "uri",
11
+ datetime: "date-time",
12
+ json_string: "json-string",
13
+ regex: "" // do not set
14
+ };
15
+
16
+ // ==================== SIMPLE TYPE PROCESSORS ====================
17
+
18
+ export const stringProcessor = (schema, ctx, _json) => {
19
+ const json = _json;
20
+ json.type = "string";
21
+ const {
22
+ minimum,
23
+ maximum,
24
+ format,
25
+ patterns,
26
+ contentEncoding
27
+ } = schema._zod.bag;
28
+ if (typeof minimum === "number") json.minLength = minimum;
29
+ if (typeof maximum === "number") json.maxLength = maximum;
30
+ // custom pattern overrides format
31
+ if (format) {
32
+ var _formatMap;
33
+ json.format = (_formatMap = formatMap[format]) !== null && _formatMap !== void 0 ? _formatMap : format;
34
+ if (json.format === "") delete json.format; // empty format is not valid
35
+
36
+ // JSON Schema format: "time" requires a full time with offset or Z
37
+ // z.iso.time() does not include timezone information, so format: "time" should never be used
38
+ if (format === "time") {
39
+ delete json.format;
40
+ }
41
+ }
42
+ if (contentEncoding) json.contentEncoding = contentEncoding;
43
+ if (patterns && patterns.size > 0) {
44
+ const regexes = [...patterns];
45
+ if (regexes.length === 1) json.pattern = regexes[0].source;else if (regexes.length > 1) {
46
+ json.allOf = [...regexes.map(regex => _objectSpread(_objectSpread({}, ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? {
47
+ type: "string"
48
+ } : {}), {}, {
49
+ pattern: regex.source
50
+ }))];
51
+ }
52
+ }
53
+ };
54
+ export const numberProcessor = (schema, ctx, _json) => {
55
+ const json = _json;
56
+ const {
57
+ minimum,
58
+ maximum,
59
+ format,
60
+ multipleOf,
61
+ exclusiveMaximum,
62
+ exclusiveMinimum
63
+ } = schema._zod.bag;
64
+ if (typeof format === "string" && format.includes("int")) json.type = "integer";else json.type = "number";
65
+ if (typeof exclusiveMinimum === "number") {
66
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
67
+ json.minimum = exclusiveMinimum;
68
+ json.exclusiveMinimum = true;
69
+ } else {
70
+ json.exclusiveMinimum = exclusiveMinimum;
71
+ }
72
+ }
73
+ if (typeof minimum === "number") {
74
+ json.minimum = minimum;
75
+ if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
76
+ if (exclusiveMinimum >= minimum) delete json.minimum;else delete json.exclusiveMinimum;
77
+ }
78
+ }
79
+ if (typeof exclusiveMaximum === "number") {
80
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
81
+ json.maximum = exclusiveMaximum;
82
+ json.exclusiveMaximum = true;
83
+ } else {
84
+ json.exclusiveMaximum = exclusiveMaximum;
85
+ }
86
+ }
87
+ if (typeof maximum === "number") {
88
+ json.maximum = maximum;
89
+ if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
90
+ if (exclusiveMaximum <= maximum) delete json.maximum;else delete json.exclusiveMaximum;
91
+ }
92
+ }
93
+ if (typeof multipleOf === "number") json.multipleOf = multipleOf;
94
+ };
95
+ export const booleanProcessor = (_schema, _ctx, json) => {
96
+ json.type = "boolean";
97
+ };
98
+ export const bigintProcessor = (_schema, ctx) => {
99
+ if (ctx.unrepresentable === "throw") {
100
+ throw new Error("BigInt cannot be represented in JSON Schema");
101
+ }
102
+ };
103
+ export const symbolProcessor = (_schema, ctx) => {
104
+ if (ctx.unrepresentable === "throw") {
105
+ throw new Error("Symbols cannot be represented in JSON Schema");
106
+ }
107
+ };
108
+ export const nullProcessor = (_schema, ctx, json) => {
109
+ if (ctx.target === "openapi-3.0") {
110
+ json.type = "string";
111
+ json.nullable = true;
112
+ json.enum = [null];
113
+ } else {
114
+ json.type = "null";
115
+ }
116
+ };
117
+ export const undefinedProcessor = (_schema, ctx) => {
118
+ if (ctx.unrepresentable === "throw") {
119
+ throw new Error("Undefined cannot be represented in JSON Schema");
120
+ }
121
+ };
122
+ export const voidProcessor = (_schema, ctx) => {
123
+ if (ctx.unrepresentable === "throw") {
124
+ throw new Error("Void cannot be represented in JSON Schema");
125
+ }
126
+ };
127
+ export const neverProcessor = (_schema, _ctx, json) => {
128
+ json.not = {};
129
+ };
130
+ export const anyProcessor = () => {
131
+ // empty schema accepts anything
132
+ };
133
+ export const unknownProcessor = () => {
134
+ // empty schema accepts anything
135
+ };
136
+ export const dateProcessor = (_schema, ctx) => {
137
+ if (ctx.unrepresentable === "throw") {
138
+ throw new Error("Date cannot be represented in JSON Schema");
139
+ }
140
+ };
141
+ export const enumProcessor = (schema, _ctx, json) => {
142
+ const def = schema._zod.def;
143
+ const values = getEnumValues(def.entries);
144
+ // Number enums can have both string and number values
145
+ if (values.every(v => typeof v === "number")) json.type = "number";
146
+ if (values.every(v => typeof v === "string")) json.type = "string";
147
+ json.enum = values;
148
+ };
149
+ export const literalProcessor = (schema, ctx, json) => {
150
+ const def = schema._zod.def;
151
+ const vals = [];
152
+ for (const val of def.values) {
153
+ if (val === undefined) {
154
+ if (ctx.unrepresentable === "throw") {
155
+ throw new Error("Literal `undefined` cannot be represented in JSON Schema");
156
+ }
157
+ } else if (typeof val === "bigint") {
158
+ if (ctx.unrepresentable === "throw") {
159
+ throw new Error("BigInt literals cannot be represented in JSON Schema");
160
+ } else {
161
+ vals.push(Number(val));
162
+ }
163
+ } else {
164
+ vals.push(val);
165
+ }
166
+ }
167
+ if (vals.length === 0) {
168
+ // do nothing (an undefined literal was stripped)
169
+ } else if (vals.length === 1) {
170
+ const val = vals[0];
171
+ json.type = val === null ? "null" : typeof val;
172
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
173
+ json.enum = [val];
174
+ } else {
175
+ json.const = val;
176
+ }
177
+ } else {
178
+ if (vals.every(v => typeof v === "number")) json.type = "number";
179
+ if (vals.every(v => typeof v === "string")) json.type = "string";
180
+ if (vals.every(v => typeof v === "boolean")) json.type = "boolean";
181
+ if (vals.every(v => v === null)) json.type = "null";
182
+ json.enum = vals;
183
+ }
184
+ };
185
+ export const nanProcessor = (_schema, ctx) => {
186
+ if (ctx.unrepresentable === "throw") {
187
+ throw new Error("NaN cannot be represented in JSON Schema");
188
+ }
189
+ };
190
+ export const templateLiteralProcessor = (schema, _ctx, json) => {
191
+ const _json = json;
192
+ const pattern = schema._zod.pattern;
193
+ if (!pattern) throw new Error("Pattern not found in template literal");
194
+ _json.type = "string";
195
+ _json.pattern = pattern.source;
196
+ };
197
+ export const fileProcessor = (schema, _ctx, json) => {
198
+ const _json = json;
199
+ const file = {
200
+ type: "string",
201
+ format: "binary",
202
+ contentEncoding: "binary"
203
+ };
204
+ const {
205
+ minimum,
206
+ maximum,
207
+ mime
208
+ } = schema._zod.bag;
209
+ if (minimum !== undefined) file.minLength = minimum;
210
+ if (maximum !== undefined) file.maxLength = maximum;
211
+ if (mime) {
212
+ if (mime.length === 1) {
213
+ file.contentMediaType = mime[0];
214
+ Object.assign(_json, file);
215
+ } else {
216
+ Object.assign(_json, file); // shared props at root
217
+ _json.anyOf = mime.map(m => ({
218
+ contentMediaType: m
219
+ })); // only contentMediaType differs
220
+ }
221
+ } else {
222
+ Object.assign(_json, file);
223
+ }
224
+ };
225
+ export const successProcessor = (_schema, _ctx, json) => {
226
+ json.type = "boolean";
227
+ };
228
+ export const customProcessor = (_schema, ctx) => {
229
+ if (ctx.unrepresentable === "throw") {
230
+ throw new Error("Custom types cannot be represented in JSON Schema");
231
+ }
232
+ };
233
+ export const functionProcessor = (_schema, ctx) => {
234
+ if (ctx.unrepresentable === "throw") {
235
+ throw new Error("Function types cannot be represented in JSON Schema");
236
+ }
237
+ };
238
+ export const transformProcessor = (_schema, ctx) => {
239
+ if (ctx.unrepresentable === "throw") {
240
+ throw new Error("Transforms cannot be represented in JSON Schema");
241
+ }
242
+ };
243
+ export const mapProcessor = (_schema, ctx) => {
244
+ if (ctx.unrepresentable === "throw") {
245
+ throw new Error("Map cannot be represented in JSON Schema");
246
+ }
247
+ };
248
+ export const setProcessor = (_schema, ctx) => {
249
+ if (ctx.unrepresentable === "throw") {
250
+ throw new Error("Set cannot be represented in JSON Schema");
251
+ }
252
+ };
253
+
254
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
255
+
256
+ export const arrayProcessor = (schema, ctx, _json, params) => {
257
+ const json = _json;
258
+ const def = schema._zod.def;
259
+ const {
260
+ minimum,
261
+ maximum
262
+ } = schema._zod.bag;
263
+ if (typeof minimum === "number") json.minItems = minimum;
264
+ if (typeof maximum === "number") json.maxItems = maximum;
265
+ json.type = "array";
266
+ json.items = process(def.element, ctx, _objectSpread(_objectSpread({}, params), {}, {
267
+ path: [...params.path, "items"]
268
+ }));
269
+ };
270
+ export const objectProcessor = (schema, ctx, _json, params) => {
271
+ var _def$catchall;
272
+ const json = _json;
273
+ const def = schema._zod.def;
274
+ json.type = "object";
275
+ json.properties = {};
276
+ const shape = def.shape;
277
+ for (const key in shape) {
278
+ json.properties[key] = process(shape[key], ctx, _objectSpread(_objectSpread({}, params), {}, {
279
+ path: [...params.path, "properties", key]
280
+ }));
281
+ }
282
+
283
+ // required keys
284
+ const allKeys = new Set(Object.keys(shape));
285
+ const requiredKeys = new Set([...allKeys].filter(key => {
286
+ const v = def.shape[key]._zod;
287
+ if (ctx.io === "input") {
288
+ return v.optin === undefined;
289
+ } else {
290
+ return v.optout === undefined;
291
+ }
292
+ }));
293
+ if (requiredKeys.size > 0) {
294
+ json.required = Array.from(requiredKeys);
295
+ }
296
+
297
+ // catchall
298
+ if (((_def$catchall = def.catchall) === null || _def$catchall === void 0 ? void 0 : _def$catchall._zod.def.type) === "never") {
299
+ // strict
300
+ json.additionalProperties = false;
301
+ } else if (!def.catchall) {
302
+ // regular
303
+ if (ctx.io === "output") json.additionalProperties = false;
304
+ } else if (def.catchall) {
305
+ json.additionalProperties = process(def.catchall, ctx, _objectSpread(_objectSpread({}, params), {}, {
306
+ path: [...params.path, "additionalProperties"]
307
+ }));
308
+ }
309
+ };
310
+ export const unionProcessor = (schema, ctx, json, params) => {
311
+ const def = schema._zod.def;
312
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
313
+ // This includes both z.xor() and discriminated unions
314
+ const isExclusive = def.inclusive === false;
315
+ const options = def.options.map((x, i) => process(x, ctx, _objectSpread(_objectSpread({}, params), {}, {
316
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
317
+ })));
318
+ if (isExclusive) {
319
+ json.oneOf = options;
320
+ } else {
321
+ json.anyOf = options;
322
+ }
323
+ };
324
+ export const intersectionProcessor = (schema, ctx, json, params) => {
325
+ const def = schema._zod.def;
326
+ const a = process(def.left, ctx, _objectSpread(_objectSpread({}, params), {}, {
327
+ path: [...params.path, "allOf", 0]
328
+ }));
329
+ const b = process(def.right, ctx, _objectSpread(_objectSpread({}, params), {}, {
330
+ path: [...params.path, "allOf", 1]
331
+ }));
332
+ const isSimpleIntersection = val => "allOf" in val && Object.keys(val).length === 1;
333
+ const allOf = [...(isSimpleIntersection(a) ? a.allOf : [a]), ...(isSimpleIntersection(b) ? b.allOf : [b])];
334
+ json.allOf = allOf;
335
+ };
336
+ export const tupleProcessor = (schema, ctx, _json, params) => {
337
+ const json = _json;
338
+ const def = schema._zod.def;
339
+ json.type = "array";
340
+ const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
341
+ const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
342
+ const prefixItems = def.items.map((x, i) => process(x, ctx, _objectSpread(_objectSpread({}, params), {}, {
343
+ path: [...params.path, prefixPath, i]
344
+ })));
345
+ const rest = def.rest ? process(def.rest, ctx, _objectSpread(_objectSpread({}, params), {}, {
346
+ path: [...params.path, restPath, ...(ctx.target === "openapi-3.0" ? [def.items.length] : [])]
347
+ })) : null;
348
+ if (ctx.target === "draft-2020-12") {
349
+ json.prefixItems = prefixItems;
350
+ if (rest) {
351
+ json.items = rest;
352
+ }
353
+ } else if (ctx.target === "openapi-3.0") {
354
+ json.items = {
355
+ anyOf: prefixItems
356
+ };
357
+ if (rest) {
358
+ json.items.anyOf.push(rest);
359
+ }
360
+ json.minItems = prefixItems.length;
361
+ if (!rest) {
362
+ json.maxItems = prefixItems.length;
363
+ }
364
+ } else {
365
+ json.items = prefixItems;
366
+ if (rest) {
367
+ json.additionalItems = rest;
368
+ }
369
+ }
370
+
371
+ // length
372
+ const {
373
+ minimum,
374
+ maximum
375
+ } = schema._zod.bag;
376
+ if (typeof minimum === "number") json.minItems = minimum;
377
+ if (typeof maximum === "number") json.maxItems = maximum;
378
+ };
379
+ export const recordProcessor = (schema, ctx, _json, params) => {
380
+ const json = _json;
381
+ const def = schema._zod.def;
382
+ json.type = "object";
383
+
384
+ // For looseRecord with regex patterns, use patternProperties
385
+ // This correctly represents "only validate keys matching the pattern" semantics
386
+ // and composes well with allOf (intersections)
387
+ const keyType = def.keyType;
388
+ const keyBag = keyType._zod.bag;
389
+ const patterns = keyBag === null || keyBag === void 0 ? void 0 : keyBag.patterns;
390
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
391
+ // Use patternProperties for looseRecord with regex patterns
392
+ const valueSchema = process(def.valueType, ctx, _objectSpread(_objectSpread({}, params), {}, {
393
+ path: [...params.path, "patternProperties", "*"]
394
+ }));
395
+ json.patternProperties = {};
396
+ for (const pattern of patterns) {
397
+ json.patternProperties[pattern.source] = valueSchema;
398
+ }
399
+ } else {
400
+ // Default behavior: use propertyNames + additionalProperties
401
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
402
+ json.propertyNames = process(def.keyType, ctx, _objectSpread(_objectSpread({}, params), {}, {
403
+ path: [...params.path, "propertyNames"]
404
+ }));
405
+ }
406
+ json.additionalProperties = process(def.valueType, ctx, _objectSpread(_objectSpread({}, params), {}, {
407
+ path: [...params.path, "additionalProperties"]
408
+ }));
409
+ }
410
+
411
+ // Add required for keys with discrete values (enum, literal, etc.)
412
+ const keyValues = keyType._zod.values;
413
+ if (keyValues) {
414
+ const validKeyValues = [...keyValues].filter(v => typeof v === "string" || typeof v === "number");
415
+ if (validKeyValues.length > 0) {
416
+ json.required = validKeyValues;
417
+ }
418
+ }
419
+ };
420
+ export const nullableProcessor = (schema, ctx, json, params) => {
421
+ const def = schema._zod.def;
422
+ const inner = process(def.innerType, ctx, params);
423
+ const seen = ctx.seen.get(schema);
424
+ if (ctx.target === "openapi-3.0") {
425
+ seen.ref = def.innerType;
426
+ json.nullable = true;
427
+ } else {
428
+ json.anyOf = [inner, {
429
+ type: "null"
430
+ }];
431
+ }
432
+ };
433
+ export const nonoptionalProcessor = (schema, ctx, _json, params) => {
434
+ const def = schema._zod.def;
435
+ process(def.innerType, ctx, params);
436
+ const seen = ctx.seen.get(schema);
437
+ seen.ref = def.innerType;
438
+ };
439
+ export const defaultProcessor = (schema, ctx, json, params) => {
440
+ const def = schema._zod.def;
441
+ process(def.innerType, ctx, params);
442
+ const seen = ctx.seen.get(schema);
443
+ seen.ref = def.innerType;
444
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
445
+ };
446
+ export const prefaultProcessor = (schema, ctx, json, params) => {
447
+ const def = schema._zod.def;
448
+ process(def.innerType, ctx, params);
449
+ const seen = ctx.seen.get(schema);
450
+ seen.ref = def.innerType;
451
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
452
+ };
453
+ export const catchProcessor = (schema, ctx, json, params) => {
454
+ const def = schema._zod.def;
455
+ process(def.innerType, ctx, params);
456
+ const seen = ctx.seen.get(schema);
457
+ seen.ref = def.innerType;
458
+ let catchValue;
459
+ try {
460
+ catchValue = def.catchValue(undefined);
461
+ } catch {
462
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
463
+ }
464
+ json.default = catchValue;
465
+ };
466
+ export const pipeProcessor = (schema, ctx, _json, params) => {
467
+ const def = schema._zod.def;
468
+ const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
469
+ process(innerType, ctx, params);
470
+ const seen = ctx.seen.get(schema);
471
+ seen.ref = innerType;
472
+ };
473
+ export const readonlyProcessor = (schema, ctx, json, params) => {
474
+ const def = schema._zod.def;
475
+ process(def.innerType, ctx, params);
476
+ const seen = ctx.seen.get(schema);
477
+ seen.ref = def.innerType;
478
+ json.readOnly = true;
479
+ };
480
+ export const promiseProcessor = (schema, ctx, _json, params) => {
481
+ const def = schema._zod.def;
482
+ process(def.innerType, ctx, params);
483
+ const seen = ctx.seen.get(schema);
484
+ seen.ref = def.innerType;
485
+ };
486
+ export const optionalProcessor = (schema, ctx, _json, params) => {
487
+ const def = schema._zod.def;
488
+ process(def.innerType, ctx, params);
489
+ const seen = ctx.seen.get(schema);
490
+ seen.ref = def.innerType;
491
+ };
492
+ export const lazyProcessor = (schema, ctx, _json, params) => {
493
+ const innerType = schema._zod.innerType;
494
+ process(innerType, ctx, params);
495
+ const seen = ctx.seen.get(schema);
496
+ seen.ref = innerType;
497
+ };
498
+
499
+ // ==================== ALL PROCESSORS ====================
500
+
501
+ export const allProcessors = {
502
+ string: stringProcessor,
503
+ number: numberProcessor,
504
+ boolean: booleanProcessor,
505
+ bigint: bigintProcessor,
506
+ symbol: symbolProcessor,
507
+ null: nullProcessor,
508
+ undefined: undefinedProcessor,
509
+ void: voidProcessor,
510
+ never: neverProcessor,
511
+ any: anyProcessor,
512
+ unknown: unknownProcessor,
513
+ date: dateProcessor,
514
+ enum: enumProcessor,
515
+ literal: literalProcessor,
516
+ nan: nanProcessor,
517
+ template_literal: templateLiteralProcessor,
518
+ file: fileProcessor,
519
+ success: successProcessor,
520
+ custom: customProcessor,
521
+ function: functionProcessor,
522
+ transform: transformProcessor,
523
+ map: mapProcessor,
524
+ set: setProcessor,
525
+ array: arrayProcessor,
526
+ object: objectProcessor,
527
+ union: unionProcessor,
528
+ intersection: intersectionProcessor,
529
+ tuple: tupleProcessor,
530
+ record: recordProcessor,
531
+ nullable: nullableProcessor,
532
+ nonoptional: nonoptionalProcessor,
533
+ default: defaultProcessor,
534
+ prefault: prefaultProcessor,
535
+ catch: catchProcessor,
536
+ pipe: pipeProcessor,
537
+ readonly: readonlyProcessor,
538
+ promise: promiseProcessor,
539
+ optional: optionalProcessor,
540
+ lazy: lazyProcessor
541
+ };
542
+
543
+ // ==================== TOP-LEVEL toJSONSchema ====================
544
+
545
+ export function toJSONSchema(input, params) {
546
+ if ("_idmap" in input) {
547
+ // Registry case
548
+ const registry = input;
549
+ const ctx = initializeContext(_objectSpread(_objectSpread({}, params), {}, {
550
+ processors: allProcessors
551
+ }));
552
+ const defs = {};
553
+
554
+ // First pass: process all schemas to build the seen map
555
+ for (const entry of registry._idmap.entries()) {
556
+ const [_, schema] = entry;
557
+ process(schema, ctx);
558
+ }
559
+ const schemas = {};
560
+ const external = {
561
+ registry,
562
+ uri: params === null || params === void 0 ? void 0 : params.uri,
563
+ defs
564
+ };
565
+
566
+ // Update the context with external configuration
567
+ ctx.external = external;
568
+
569
+ // Second pass: emit each schema
570
+ for (const entry of registry._idmap.entries()) {
571
+ const [key, schema] = entry;
572
+ extractDefs(ctx, schema);
573
+ schemas[key] = finalize(ctx, schema);
574
+ }
575
+ if (Object.keys(defs).length > 0) {
576
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
577
+ schemas.__shared = {
578
+ [defsSegment]: defs
579
+ };
580
+ }
581
+ return {
582
+ schemas
583
+ };
584
+ }
585
+
586
+ // Single schema case
587
+ const ctx = initializeContext(_objectSpread(_objectSpread({}, params), {}, {
588
+ processors: allProcessors
589
+ }));
590
+ process(input, ctx);
591
+ extractDefs(ctx, input);
592
+ return finalize(ctx, input);
593
+ }
@@ -0,0 +1,88 @@
1
+ export type Schema = ObjectSchema | ArraySchema | StringSchema | NumberSchema | IntegerSchema | BooleanSchema | NullSchema;
2
+ export type _JSONSchema = boolean | JSONSchema;
3
+ export type JSONSchema = {
4
+ [k: string]: unknown;
5
+ $schema?: "https://json-schema.org/draft/2020-12/schema" | "http://json-schema.org/draft-07/schema#" | "http://json-schema.org/draft-04/schema#";
6
+ $id?: string;
7
+ $anchor?: string;
8
+ $ref?: string;
9
+ $dynamicRef?: string;
10
+ $dynamicAnchor?: string;
11
+ $vocabulary?: Record<string, boolean>;
12
+ $comment?: string;
13
+ $defs?: Record<string, JSONSchema>;
14
+ type?: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
15
+ additionalItems?: _JSONSchema;
16
+ unevaluatedItems?: _JSONSchema;
17
+ prefixItems?: _JSONSchema[];
18
+ items?: _JSONSchema | _JSONSchema[];
19
+ contains?: _JSONSchema;
20
+ additionalProperties?: _JSONSchema;
21
+ unevaluatedProperties?: _JSONSchema;
22
+ properties?: Record<string, _JSONSchema>;
23
+ patternProperties?: Record<string, _JSONSchema>;
24
+ dependentSchemas?: Record<string, _JSONSchema>;
25
+ propertyNames?: _JSONSchema;
26
+ if?: _JSONSchema;
27
+ then?: _JSONSchema;
28
+ else?: _JSONSchema;
29
+ allOf?: JSONSchema[];
30
+ anyOf?: JSONSchema[];
31
+ oneOf?: JSONSchema[];
32
+ not?: _JSONSchema;
33
+ multipleOf?: number;
34
+ maximum?: number;
35
+ exclusiveMaximum?: number | boolean;
36
+ minimum?: number;
37
+ exclusiveMinimum?: number | boolean;
38
+ maxLength?: number;
39
+ minLength?: number;
40
+ pattern?: string;
41
+ maxItems?: number;
42
+ minItems?: number;
43
+ uniqueItems?: boolean;
44
+ maxContains?: number;
45
+ minContains?: number;
46
+ maxProperties?: number;
47
+ minProperties?: number;
48
+ required?: string[];
49
+ dependentRequired?: Record<string, string[]>;
50
+ enum?: Array<string | number | boolean | null>;
51
+ const?: string | number | boolean | null;
52
+ id?: string;
53
+ title?: string;
54
+ description?: string;
55
+ default?: unknown;
56
+ deprecated?: boolean;
57
+ readOnly?: boolean;
58
+ writeOnly?: boolean;
59
+ nullable?: boolean;
60
+ examples?: unknown[];
61
+ format?: string;
62
+ contentMediaType?: string;
63
+ contentEncoding?: string;
64
+ contentSchema?: JSONSchema;
65
+ _prefault?: unknown;
66
+ };
67
+ export type BaseSchema = JSONSchema;
68
+ export interface ObjectSchema extends JSONSchema {
69
+ type: "object";
70
+ }
71
+ export interface ArraySchema extends JSONSchema {
72
+ type: "array";
73
+ }
74
+ export interface StringSchema extends JSONSchema {
75
+ type: "string";
76
+ }
77
+ export interface NumberSchema extends JSONSchema {
78
+ type: "number";
79
+ }
80
+ export interface IntegerSchema extends JSONSchema {
81
+ type: "integer";
82
+ }
83
+ export interface BooleanSchema extends JSONSchema {
84
+ type: "boolean";
85
+ }
86
+ export interface NullSchema extends JSONSchema {
87
+ type: "null";
88
+ }
@@ -0,0 +1 @@
1
+ export {};