@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,488 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { globalRegistry } from "./registries.js";
3
+
4
+ /**
5
+ * Parameters for the toJSONSchema function.
6
+ */
7
+
8
+ /**
9
+ * Parameters for the toJSONSchema function when passing a registry.
10
+ */
11
+
12
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
13
+ // return {
14
+ // processor: inputs.processor,
15
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
16
+ // target: inputs.target ?? "draft-2020-12",
17
+ // unrepresentable: inputs.unrepresentable ?? "throw",
18
+ // };
19
+ // }
20
+
21
+ export function initializeContext(params) {
22
+ var _params$target, _params$processors, _params$metadata, _params$unrepresentab, _ref, _params$io, _params$cycles, _params$reused, _params$external;
23
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
24
+ let target = (_params$target = params === null || params === void 0 ? void 0 : params.target) !== null && _params$target !== void 0 ? _params$target : "draft-2020-12";
25
+ if (target === "draft-4") target = "draft-04";
26
+ if (target === "draft-7") target = "draft-07";
27
+ return {
28
+ processors: (_params$processors = params.processors) !== null && _params$processors !== void 0 ? _params$processors : {},
29
+ metadataRegistry: (_params$metadata = params === null || params === void 0 ? void 0 : params.metadata) !== null && _params$metadata !== void 0 ? _params$metadata : globalRegistry,
30
+ target,
31
+ unrepresentable: (_params$unrepresentab = params === null || params === void 0 ? void 0 : params.unrepresentable) !== null && _params$unrepresentab !== void 0 ? _params$unrepresentab : "throw",
32
+ override: (_ref = params === null || params === void 0 ? void 0 : params.override) !== null && _ref !== void 0 ? _ref : () => {},
33
+ io: (_params$io = params === null || params === void 0 ? void 0 : params.io) !== null && _params$io !== void 0 ? _params$io : "output",
34
+ counter: 0,
35
+ seen: new Map(),
36
+ cycles: (_params$cycles = params === null || params === void 0 ? void 0 : params.cycles) !== null && _params$cycles !== void 0 ? _params$cycles : "ref",
37
+ reused: (_params$reused = params === null || params === void 0 ? void 0 : params.reused) !== null && _params$reused !== void 0 ? _params$reused : "inline",
38
+ external: (_params$external = params === null || params === void 0 ? void 0 : params.external) !== null && _params$external !== void 0 ? _params$external : undefined
39
+ };
40
+ }
41
+ export function process(schema, ctx) {
42
+ var _schema$_zod$toJSONSc, _schema$_zod;
43
+ let _params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
44
+ path: [],
45
+ schemaPath: []
46
+ };
47
+ const def = schema._zod.def;
48
+
49
+ // check for schema in seens
50
+ const seen = ctx.seen.get(schema);
51
+ if (seen) {
52
+ seen.count++;
53
+
54
+ // check if cycle
55
+ const isCycle = _params.schemaPath.includes(schema);
56
+ if (isCycle) {
57
+ seen.cycle = _params.path;
58
+ }
59
+ return seen.schema;
60
+ }
61
+
62
+ // initialize
63
+ const result = {
64
+ schema: {},
65
+ count: 1,
66
+ cycle: undefined,
67
+ path: _params.path
68
+ };
69
+ ctx.seen.set(schema, result);
70
+
71
+ // custom method overrides default behavior
72
+ const overrideSchema = (_schema$_zod$toJSONSc = (_schema$_zod = schema._zod).toJSONSchema) === null || _schema$_zod$toJSONSc === void 0 ? void 0 : _schema$_zod$toJSONSc.call(_schema$_zod);
73
+ if (overrideSchema) {
74
+ result.schema = overrideSchema;
75
+ } else {
76
+ const params = _objectSpread(_objectSpread({}, _params), {}, {
77
+ schemaPath: [..._params.schemaPath, schema],
78
+ path: _params.path
79
+ });
80
+ if (schema._zod.processJSONSchema) {
81
+ schema._zod.processJSONSchema(ctx, result.schema, params);
82
+ } else {
83
+ const _json = result.schema;
84
+ const processor = ctx.processors[def.type];
85
+ if (!processor) {
86
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
87
+ }
88
+ processor(schema, ctx, _json, params);
89
+ }
90
+ const parent = schema._zod.parent;
91
+ if (parent) {
92
+ // Also set ref if processor didn't (for inheritance)
93
+ if (!result.ref) result.ref = parent;
94
+ process(parent, ctx, params);
95
+ ctx.seen.get(parent).isParent = true;
96
+ }
97
+ }
98
+
99
+ // metadata
100
+ const meta = ctx.metadataRegistry.get(schema);
101
+ if (meta) Object.assign(result.schema, meta);
102
+ if (ctx.io === "input" && isTransforming(schema)) {
103
+ // examples/defaults only apply to output type of pipe
104
+ delete result.schema.examples;
105
+ delete result.schema.default;
106
+ }
107
+
108
+ // set prefault as default
109
+ if (ctx.io === "input" && result.schema._prefault) result.schema.default ??= result.schema._prefault;
110
+ delete result.schema._prefault;
111
+
112
+ // pulling fresh from ctx.seen in case it was overwritten
113
+ const _result = ctx.seen.get(schema);
114
+ return _result.schema;
115
+ }
116
+ export function extractDefs(ctx, schema) {
117
+ // iterate over seen map;
118
+ const root = ctx.seen.get(schema);
119
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
120
+
121
+ // Track ids to detect duplicates across different schemas
122
+ const idToSchema = new Map();
123
+ for (const entry of ctx.seen.entries()) {
124
+ var _ctx$metadataRegistry;
125
+ const id = (_ctx$metadataRegistry = ctx.metadataRegistry.get(entry[0])) === null || _ctx$metadataRegistry === void 0 ? void 0 : _ctx$metadataRegistry.id;
126
+ if (id) {
127
+ const existing = idToSchema.get(id);
128
+ if (existing && existing !== entry[0]) {
129
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
130
+ }
131
+ idToSchema.set(id, entry[0]);
132
+ }
133
+ }
134
+
135
+ // returns a ref to the schema
136
+ // defId will be empty if the ref points to an external schema (or #)
137
+ const makeURI = entry => {
138
+ var _entry$1$schema$id;
139
+ // comparing the seen objects because sometimes
140
+ // multiple schemas map to the same seen object.
141
+ // e.g. lazy
142
+
143
+ // external is configured
144
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
145
+ if (ctx.external) {
146
+ var _ctx$external$registr, _ctx$external$uri, _ref2, _entry$1$defId;
147
+ const externalId = (_ctx$external$registr = ctx.external.registry.get(entry[0])) === null || _ctx$external$registr === void 0 ? void 0 : _ctx$external$registr.id; // ?? "__shared";// `__schema${ctx.counter++}`;
148
+
149
+ // check if schema is in the external registry
150
+ const uriGenerator = (_ctx$external$uri = ctx.external.uri) !== null && _ctx$external$uri !== void 0 ? _ctx$external$uri : id => id;
151
+ if (externalId) {
152
+ return {
153
+ ref: uriGenerator(externalId)
154
+ };
155
+ }
156
+
157
+ // otherwise, add to __shared
158
+ const id = (_ref2 = (_entry$1$defId = entry[1].defId) !== null && _entry$1$defId !== void 0 ? _entry$1$defId : entry[1].schema.id) !== null && _ref2 !== void 0 ? _ref2 : `schema${ctx.counter++}`;
159
+ entry[1].defId = id; // set defId so it will be reused if needed
160
+ return {
161
+ defId: id,
162
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
163
+ };
164
+ }
165
+ if (entry[1] === root) {
166
+ return {
167
+ ref: "#"
168
+ };
169
+ }
170
+
171
+ // self-contained schema
172
+
173
+ const defId = (_entry$1$schema$id = entry[1].schema.id) !== null && _entry$1$schema$id !== void 0 ? _entry$1$schema$id : `__schema${ctx.counter++}`;
174
+ return {
175
+ defId,
176
+ ref: `${`#`}/${defsSegment}/` + defId
177
+ };
178
+ };
179
+
180
+ // stored cached version in `def` property
181
+ // remove all properties, set $ref
182
+ const extractToDef = entry => {
183
+ // if the schema is already a reference, do not extract it
184
+ if (entry[1].schema.$ref) {
185
+ return;
186
+ }
187
+ const seen = entry[1];
188
+ const {
189
+ ref,
190
+ defId
191
+ } = makeURI(entry);
192
+ seen.def = _objectSpread({}, seen.schema);
193
+ // defId won't be set if the schema is a reference to an external schema
194
+ // or if the schema is the root schema
195
+ if (defId) seen.defId = defId;
196
+ // wipe away all properties except $ref
197
+ const schema = seen.schema;
198
+ for (const key in schema) {
199
+ delete schema[key];
200
+ }
201
+ schema.$ref = ref;
202
+ };
203
+
204
+ // throw on cycles
205
+
206
+ // break cycles
207
+ if (ctx.cycles === "throw") {
208
+ for (const entry of ctx.seen.entries()) {
209
+ const seen = entry[1];
210
+ if (seen.cycle) {
211
+ var _seen$cycle;
212
+ throw new Error("Cycle detected: " + `#/${(_seen$cycle = seen.cycle) === null || _seen$cycle === void 0 ? void 0 : _seen$cycle.join("/")}/<root>` + '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
213
+ }
214
+ }
215
+ }
216
+
217
+ // extract schemas into $defs
218
+ for (const entry of ctx.seen.entries()) {
219
+ var _ctx$metadataRegistry2;
220
+ const seen = entry[1];
221
+
222
+ // convert root schema to # $ref
223
+ if (schema === entry[0]) {
224
+ extractToDef(entry); // this has special handling for the root schema
225
+ continue;
226
+ }
227
+
228
+ // extract schemas that are in the external registry
229
+ if (ctx.external) {
230
+ var _ctx$external$registr2;
231
+ const ext = (_ctx$external$registr2 = ctx.external.registry.get(entry[0])) === null || _ctx$external$registr2 === void 0 ? void 0 : _ctx$external$registr2.id;
232
+ if (schema !== entry[0] && ext) {
233
+ extractToDef(entry);
234
+ continue;
235
+ }
236
+ }
237
+
238
+ // extract schemas with `id` meta
239
+ const id = (_ctx$metadataRegistry2 = ctx.metadataRegistry.get(entry[0])) === null || _ctx$metadataRegistry2 === void 0 ? void 0 : _ctx$metadataRegistry2.id;
240
+ if (id) {
241
+ extractToDef(entry);
242
+ continue;
243
+ }
244
+
245
+ // break cycles
246
+ if (seen.cycle) {
247
+ // any
248
+ extractToDef(entry);
249
+ continue;
250
+ }
251
+
252
+ // extract reused schemas
253
+ if (seen.count > 1) {
254
+ if (ctx.reused === "ref") {
255
+ extractToDef(entry);
256
+ // biome-ignore lint:
257
+ continue;
258
+ }
259
+ }
260
+ }
261
+ }
262
+ export function finalize(ctx, schema) {
263
+ var _ctx$external, _root$def, _ctx$external$defs, _ctx$external2;
264
+ const root = ctx.seen.get(schema);
265
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
266
+
267
+ // flatten refs - inherit properties from parent schemas
268
+ const flattenRef = zodSchema => {
269
+ var _seen$def, _seen$path;
270
+ const seen = ctx.seen.get(zodSchema);
271
+
272
+ // already processed
273
+ if (seen.ref === null) return;
274
+ const schema = (_seen$def = seen.def) !== null && _seen$def !== void 0 ? _seen$def : seen.schema;
275
+ const _cached = _objectSpread({}, schema);
276
+ const ref = seen.ref;
277
+ seen.ref = null; // prevent infinite recursion
278
+
279
+ if (ref) {
280
+ flattenRef(ref);
281
+ const refSeen = ctx.seen.get(ref);
282
+ const refSchema = refSeen.schema;
283
+
284
+ // merge referenced schema into current
285
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
286
+ var _schema$allOf;
287
+ // older drafts can't combine $ref with other properties
288
+ schema.allOf = (_schema$allOf = schema.allOf) !== null && _schema$allOf !== void 0 ? _schema$allOf : [];
289
+ schema.allOf.push(refSchema);
290
+ } else {
291
+ Object.assign(schema, refSchema);
292
+ }
293
+ // restore child's own properties (child wins)
294
+ Object.assign(schema, _cached);
295
+ const isParentRef = zodSchema._zod.parent === ref;
296
+
297
+ // For parent chain, child is a refinement - remove parent-only properties
298
+ if (isParentRef) {
299
+ for (const key in schema) {
300
+ if (key === "$ref" || key === "allOf") continue;
301
+ if (!(key in _cached)) {
302
+ delete schema[key];
303
+ }
304
+ }
305
+ }
306
+
307
+ // When ref was extracted to $defs, remove properties that match the definition
308
+ if (refSchema.$ref) {
309
+ for (const key in schema) {
310
+ if (key === "$ref" || key === "allOf") continue;
311
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) {
312
+ delete schema[key];
313
+ }
314
+ }
315
+ }
316
+ }
317
+
318
+ // If parent was extracted (has $ref), propagate $ref to this schema
319
+ // This handles cases like: readonly().meta({id}).describe()
320
+ // where processor sets ref to innerType but parent should be referenced
321
+ const parent = zodSchema._zod.parent;
322
+ if (parent && parent !== ref) {
323
+ // Ensure parent is processed first so its def has inherited properties
324
+ flattenRef(parent);
325
+ const parentSeen = ctx.seen.get(parent);
326
+ if (parentSeen !== null && parentSeen !== void 0 && parentSeen.schema.$ref) {
327
+ schema.$ref = parentSeen.schema.$ref;
328
+ // De-duplicate with parent's definition
329
+ if (parentSeen.def) {
330
+ for (const key in schema) {
331
+ if (key === "$ref" || key === "allOf") continue;
332
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) {
333
+ delete schema[key];
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+
340
+ // execute overrides
341
+ ctx.override({
342
+ zodSchema: zodSchema,
343
+ jsonSchema: schema,
344
+ path: (_seen$path = seen.path) !== null && _seen$path !== void 0 ? _seen$path : []
345
+ });
346
+ };
347
+ for (const entry of [...ctx.seen.entries()].reverse()) {
348
+ flattenRef(entry[0]);
349
+ }
350
+ const result = {};
351
+ if (ctx.target === "draft-2020-12") {
352
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
353
+ } else if (ctx.target === "draft-07") {
354
+ result.$schema = "http://json-schema.org/draft-07/schema#";
355
+ } else if (ctx.target === "draft-04") {
356
+ result.$schema = "http://json-schema.org/draft-04/schema#";
357
+ } else if (ctx.target === "openapi-3.0") {
358
+ // OpenAPI 3.0 schema objects should not include a $schema property
359
+ }
360
+ if ((_ctx$external = ctx.external) !== null && _ctx$external !== void 0 && _ctx$external.uri) {
361
+ var _ctx$external$registr3;
362
+ const id = (_ctx$external$registr3 = ctx.external.registry.get(schema)) === null || _ctx$external$registr3 === void 0 ? void 0 : _ctx$external$registr3.id;
363
+ if (!id) throw new Error("Schema is missing an `id` property");
364
+ result.$id = ctx.external.uri(id);
365
+ }
366
+ Object.assign(result, (_root$def = root.def) !== null && _root$def !== void 0 ? _root$def : root.schema);
367
+
368
+ // build defs object
369
+ const defs = (_ctx$external$defs = (_ctx$external2 = ctx.external) === null || _ctx$external2 === void 0 ? void 0 : _ctx$external2.defs) !== null && _ctx$external$defs !== void 0 ? _ctx$external$defs : {};
370
+ for (const entry of ctx.seen.entries()) {
371
+ const seen = entry[1];
372
+ if (seen.def && seen.defId) {
373
+ defs[seen.defId] = seen.def;
374
+ }
375
+ }
376
+
377
+ // set definitions in result
378
+ if (!ctx.external) {
379
+ if (Object.keys(defs).length > 0) {
380
+ if (ctx.target === "draft-2020-12") {
381
+ result.$defs = defs;
382
+ } else {
383
+ result.definitions = defs;
384
+ }
385
+ }
386
+ }
387
+ try {
388
+ // this "finalizes" this schema and ensures all cycles are removed
389
+ // each call to finalize() is functionally independent
390
+ // though the seen map is shared
391
+ const finalized = JSON.parse(JSON.stringify(result));
392
+ Object.defineProperty(finalized, "~standard", {
393
+ value: _objectSpread(_objectSpread({}, schema["~standard"]), {}, {
394
+ jsonSchema: {
395
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
396
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
397
+ }
398
+ }),
399
+ enumerable: false,
400
+ writable: false
401
+ });
402
+ return finalized;
403
+ } catch (_err) {
404
+ throw new Error("Error converting schema to JSON.");
405
+ }
406
+ }
407
+ function isTransforming(_schema, _ctx) {
408
+ const ctx = _ctx !== null && _ctx !== void 0 ? _ctx : {
409
+ seen: new Set()
410
+ };
411
+ if (ctx.seen.has(_schema)) return false;
412
+ ctx.seen.add(_schema);
413
+ const def = _schema._zod.def;
414
+ if (def.type === "transform") return true;
415
+ if (def.type === "array") return isTransforming(def.element, ctx);
416
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
417
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
418
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
419
+ return isTransforming(def.innerType, ctx);
420
+ }
421
+ if (def.type === "intersection") {
422
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
423
+ }
424
+ if (def.type === "record" || def.type === "map") {
425
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
426
+ }
427
+ if (def.type === "pipe") {
428
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
429
+ }
430
+ if (def.type === "object") {
431
+ for (const key in def.shape) {
432
+ if (isTransforming(def.shape[key], ctx)) return true;
433
+ }
434
+ return false;
435
+ }
436
+ if (def.type === "union") {
437
+ for (const option of def.options) {
438
+ if (isTransforming(option, ctx)) return true;
439
+ }
440
+ return false;
441
+ }
442
+ if (def.type === "tuple") {
443
+ for (const item of def.items) {
444
+ if (isTransforming(item, ctx)) return true;
445
+ }
446
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
447
+ return false;
448
+ }
449
+ return false;
450
+ }
451
+ /**
452
+ * Creates a toJSONSchema method for a schema instance.
453
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
454
+ */
455
+ export const createToJSONSchemaMethod = function (schema) {
456
+ let processors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
457
+ return params => {
458
+ const ctx = initializeContext(_objectSpread(_objectSpread({}, params), {}, {
459
+ processors
460
+ }));
461
+ process(schema, ctx);
462
+ extractDefs(ctx, schema);
463
+ return finalize(ctx, schema);
464
+ };
465
+ };
466
+
467
+ /**
468
+ * Creates a toJSONSchema method for a schema instance.
469
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
470
+ */
471
+
472
+ export const createStandardJSONSchemaMethod = function (schema, io) {
473
+ let processors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
474
+ return params => {
475
+ const {
476
+ libraryOptions,
477
+ target
478
+ } = params !== null && params !== void 0 ? params : {};
479
+ const ctx = initializeContext(_objectSpread(_objectSpread({}, libraryOptions !== null && libraryOptions !== void 0 ? libraryOptions : {}), {}, {
480
+ target,
481
+ io,
482
+ processors
483
+ }));
484
+ process(schema, ctx);
485
+ extractDefs(ctx, schema);
486
+ return finalize(ctx, schema);
487
+ };
488
+ };
@@ -0,0 +1,199 @@
1
+ import type * as checks from "./checks.js";
2
+ import type { $ZodConfig } from "./core.js";
3
+ import type * as errors from "./errors.js";
4
+ import type * as schemas from "./schemas.js";
5
+ export type JSONType = string | number | boolean | null | JSONType[] | {
6
+ [key: string]: JSONType;
7
+ };
8
+ export type JWTAlgorithm = "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "PS256" | "PS384" | "PS512" | "EdDSA" | (string & {});
9
+ export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha384" | "sha512";
10
+ export type HashEncoding = "hex" | "base64" | "base64url";
11
+ export type HashFormat = `${HashAlgorithm}_${HashEncoding}`;
12
+ export type IPVersion = "v4" | "v6";
13
+ export type MimeTypes = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "application/javascript" | "application/pdf" | "application/zip" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/octet-stream" | "application/graphql" | "text/html" | "text/plain" | "text/css" | "text/javascript" | "text/csv" | "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml" | "image/webp" | "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "video/mp4" | "video/webm" | "video/ogg" | "font/woff" | "font/woff2" | "font/ttf" | "font/otf" | "multipart/form-data" | (string & {});
14
+ export type ParsedTypes = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "file" | "date" | "array" | "map" | "set" | "nan" | "null" | "promise";
15
+ export type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : false;
16
+ export type AssertNotEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? false : true;
17
+ export type AssertExtends<T, U> = T extends U ? T : never;
18
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
19
+ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
20
+ export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
21
+ export type MakePartial<T, K extends keyof T> = Omit<T, K> & InexactPartial<Pick<T, K>>;
22
+ export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
23
+ export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
24
+ export type NoUndefined<T> = T extends undefined ? never : T;
25
+ export type Whatever = {} | undefined | null;
26
+ export type LoosePartial<T extends object> = InexactPartial<T> & {
27
+ [k: string]: unknown;
28
+ };
29
+ export type Mask<Keys extends PropertyKey> = {
30
+ [K in Keys]?: true;
31
+ };
32
+ export type Writeable<T> = {
33
+ -readonly [P in keyof T]: T[P];
34
+ } & {};
35
+ export type InexactPartial<T> = {
36
+ [P in keyof T]?: T[P] | undefined;
37
+ };
38
+ export type EmptyObject = Record<string, never>;
39
+ export type BuiltIn = (((...args: any[]) => any) | (new (...args: any[]) => any)) | {
40
+ readonly [Symbol.toStringTag]: string;
41
+ } | Date | Error | Generator | Promise<unknown> | RegExp;
42
+ export type MakeReadonly<T> = T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : T extends Set<infer V> ? ReadonlySet<V> : T extends [infer Head, ...infer Tail] ? readonly [Head, ...Tail] : T extends Array<infer V> ? ReadonlyArray<V> : T extends BuiltIn ? T : Readonly<T>;
43
+ export type SomeObject = Record<PropertyKey, any>;
44
+ export type Identity<T> = T;
45
+ export type Flatten<T> = Identity<{
46
+ [k in keyof T]: T[k];
47
+ }>;
48
+ export type Mapped<T> = {
49
+ [k in keyof T]: T[k];
50
+ };
51
+ export type Prettify<T> = {
52
+ [K in keyof T]: T[K];
53
+ } & {};
54
+ export type NoNeverKeys<T> = {
55
+ [k in keyof T]: [T[k]] extends [never] ? never : k;
56
+ }[keyof T];
57
+ export type NoNever<T> = Identity<{
58
+ [k in NoNeverKeys<T>]: k extends keyof T ? T[k] : never;
59
+ }>;
60
+ export type Extend<A extends SomeObject, B extends SomeObject> = Flatten<keyof A & keyof B extends never ? A & B : {
61
+ [K in keyof A as K extends keyof B ? never : K]: A[K];
62
+ } & {
63
+ [K in keyof B]: B[K];
64
+ }>;
65
+ export type TupleItems = ReadonlyArray<schemas.SomeType>;
66
+ export type AnyFunc = (...args: any[]) => any;
67
+ export type IsProp<T, K extends keyof T> = T[K] extends AnyFunc ? never : K;
68
+ export type MaybeAsync<T> = T | Promise<T>;
69
+ export type KeyOf<T> = keyof OmitIndexSignature<T>;
70
+ export type OmitIndexSignature<T> = {
71
+ [K in keyof T as string extends K ? never : K extends string ? K : never]: T[K];
72
+ };
73
+ export type ExtractIndexSignature<T> = {
74
+ [K in keyof T as string extends K ? K : K extends string ? never : K]: T[K];
75
+ };
76
+ export type Keys<T extends object> = keyof OmitIndexSignature<T>;
77
+ export type SchemaClass<T extends schemas.SomeType> = {
78
+ new (def: T["_zod"]["def"]): T;
79
+ };
80
+ export type EnumValue = string | number;
81
+ export type EnumLike = Readonly<Record<string, EnumValue>>;
82
+ export type ToEnum<T extends EnumValue> = Flatten<{
83
+ [k in T]: k;
84
+ }>;
85
+ export type KeysEnum<T extends object> = ToEnum<Exclude<keyof T, symbol>>;
86
+ export type KeysArray<T extends object> = Flatten<(keyof T & string)[]>;
87
+ export type Literal = string | number | bigint | boolean | null | undefined;
88
+ export type LiteralArray = Array<Literal>;
89
+ export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
90
+ export type PrimitiveArray = Array<Primitive>;
91
+ export type HasSize = {
92
+ size: number;
93
+ };
94
+ export type HasLength = {
95
+ length: number;
96
+ };
97
+ export type Numeric = number | bigint | Date;
98
+ export type SafeParseResult<T> = SafeParseSuccess<T> | SafeParseError<T>;
99
+ export type SafeParseSuccess<T> = {
100
+ success: true;
101
+ data: T;
102
+ error?: never;
103
+ };
104
+ export type SafeParseError<T> = {
105
+ success: false;
106
+ data?: never;
107
+ error: errors.$ZodError<T>;
108
+ };
109
+ export type PropValues = Record<string, Set<Primitive>>;
110
+ export type PrimitiveSet = Set<Primitive>;
111
+ export declare function assertEqual<A, B>(val: AssertEqual<A, B>): AssertEqual<A, B>;
112
+ export declare function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<A, B>;
113
+ export declare function assertIs<T>(_arg: T): void;
114
+ export declare function assertNever(_x: never): never;
115
+ export declare function assert<T>(_: any): asserts _ is T;
116
+ export declare function getEnumValues(entries: EnumLike): EnumValue[];
117
+ export declare function joinValues<T extends Primitive[]>(array: T, separator?: string): string;
118
+ export declare function jsonStringifyReplacer(_: string, value: any): any;
119
+ export declare function cached<T>(getter: () => T): {
120
+ value: T;
121
+ };
122
+ export declare function nullish(input: any): boolean;
123
+ export declare function cleanRegex(source: string): string;
124
+ export declare function floatSafeRemainder(val: number, step: number): number;
125
+ export declare function defineLazy<T, K extends keyof T>(object: T, key: K, getter: () => T[K]): void;
126
+ export declare function objectClone(obj: object): any;
127
+ export declare function assignProp<T extends object, K extends PropertyKey>(target: T, prop: K, value: K extends keyof T ? T[K] : any): void;
128
+ export declare function mergeDefs(...defs: Record<string, any>[]): any;
129
+ export declare function cloneDef(schema: schemas.$ZodType): any;
130
+ export declare function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any;
131
+ export declare function promiseAllObject<T extends object>(promisesObj: T): Promise<{
132
+ [k in keyof T]: Awaited<T[k]>;
133
+ }>;
134
+ export declare function randomString(length?: number): string;
135
+ export declare function esc(str: string): string;
136
+ export declare function slugify(input: string): string;
137
+ export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
138
+ export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
139
+ export declare const allowsEval: {
140
+ value: boolean;
141
+ };
142
+ export declare function isPlainObject(o: any): o is Record<PropertyKey, unknown>;
143
+ export declare function shallowClone(o: any): any;
144
+ export declare function numKeys(data: any): number;
145
+ export declare const getParsedType: (data: any) => ParsedTypes;
146
+ export declare const propertyKeyTypes: Set<string>;
147
+ export declare const primitiveTypes: Set<string>;
148
+ export declare function escapeRegex(str: string): string;
149
+ export declare function clone<T extends schemas.$ZodType>(inst: T, def?: T["_zod"]["def"], params?: {
150
+ parent: boolean;
151
+ }): T;
152
+ export type EmptyToNever<T> = keyof T extends never ? never : T;
153
+ export type Normalize<T> = T extends undefined ? never : T extends Record<any, any> ? Flatten<{
154
+ [k in keyof Omit<T, "error" | "message">]: T[k];
155
+ } & ("error" extends keyof T ? {
156
+ error?: Exclude<T["error"], string>;
157
+ } : unknown)> : never;
158
+ export declare function normalizeParams<T>(_params: T): Normalize<T>;
159
+ export declare function createTransparentProxy<T extends object>(getter: () => T): T;
160
+ export declare function stringifyPrimitive(value: any): string;
161
+ export declare function optionalKeys(shape: schemas.$ZodShape): string[];
162
+ export type CleanKey<T extends PropertyKey> = T extends `?${infer K}` ? K : T extends `${infer K}?` ? K : T;
163
+ export type ToCleanMap<T extends schemas.$ZodLooseShape> = {
164
+ [k in keyof T]: k extends `?${infer K}` ? K : k extends `${infer K}?` ? K : k;
165
+ };
166
+ export type FromCleanMap<T extends schemas.$ZodLooseShape> = {
167
+ [k in keyof T as k extends `?${infer K}` ? K : k extends `${infer K}?` ? K : k]: k;
168
+ };
169
+ export declare const NUMBER_FORMAT_RANGES: Record<checks.$ZodNumberFormats, [number, number]>;
170
+ export declare const BIGINT_FORMAT_RANGES: Record<checks.$ZodBigIntFormats, [bigint, bigint]>;
171
+ export declare function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>): any;
172
+ export declare function omit(schema: schemas.$ZodObject, mask: object): any;
173
+ export declare function extend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
174
+ export declare function safeExtend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any;
175
+ export declare function merge(a: schemas.$ZodObject, b: schemas.$ZodObject): any;
176
+ export declare function partial(Class: SchemaClass<schemas.$ZodOptional> | null, schema: schemas.$ZodObject, mask: object | undefined): any;
177
+ export declare function required(Class: SchemaClass<schemas.$ZodNonOptional>, schema: schemas.$ZodObject, mask: object | undefined): any;
178
+ export type Constructor<T, Def extends any[] = any[]> = new (...args: Def) => T;
179
+ export declare function aborted(x: schemas.ParsePayload, startIndex?: number): boolean;
180
+ export declare function prefixIssues(path: PropertyKey, issues: errors.$ZodRawIssue[]): errors.$ZodRawIssue[];
181
+ export declare function unwrapMessage(message: string | {
182
+ message: string;
183
+ } | undefined | null): string | undefined;
184
+ export declare function finalizeIssue(iss: errors.$ZodRawIssue, ctx: schemas.ParseContextInternal | undefined, config: $ZodConfig): errors.$ZodIssue;
185
+ export declare function getSizableOrigin(input: any): "set" | "map" | "file" | "unknown";
186
+ export declare function getLengthableOrigin(input: any): "array" | "string" | "unknown";
187
+ export declare function parsedType(data: unknown): errors.$ZodInvalidTypeExpected;
188
+ export declare function issue(_iss: string, input: any, inst: any): errors.$ZodRawIssue;
189
+ export declare function issue(_iss: errors.$ZodRawIssue): errors.$ZodRawIssue;
190
+ export declare function cleanEnum(obj: Record<string, EnumValue>): EnumValue[];
191
+ export declare function base64ToUint8Array(base64: string): InstanceType<typeof Uint8Array>;
192
+ export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
193
+ export declare function base64urlToUint8Array(base64url: string): InstanceType<typeof Uint8Array>;
194
+ export declare function uint8ArrayToBase64url(bytes: Uint8Array): string;
195
+ export declare function hexToUint8Array(hex: string): InstanceType<typeof Uint8Array>;
196
+ export declare function uint8ArrayToHex(bytes: Uint8Array): string;
197
+ export declare abstract class Class {
198
+ constructor(..._args: any[]);
199
+ }