@powerduck/schema-designer 0.1.0

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 (102) hide show
  1. package/README.md +217 -0
  2. package/dist/InlineSchemaEditor-BssSx3SI.d.ts +6 -0
  3. package/dist/InlineSchemaEditor-Bua-lDhE.d.cts +6 -0
  4. package/dist/chunk-2XUQB6BQ.js +1896 -0
  5. package/dist/chunk-4H3LXOL4.cjs +1900 -0
  6. package/dist/chunk-7LG4MVMD.cjs +2 -0
  7. package/dist/chunk-BXFABOMJ.js +1475 -0
  8. package/dist/chunk-FTALJIVZ.js +1 -0
  9. package/dist/chunk-GTZH37JS.cjs +1120 -0
  10. package/dist/chunk-GWHDTTQK.js +1437 -0
  11. package/dist/chunk-GXXD6ITE.cjs +1477 -0
  12. package/dist/chunk-HI5FBHCO.js +1057 -0
  13. package/dist/chunk-KX3LFFOV.js +88 -0
  14. package/dist/chunk-MADPN2PJ.js +185 -0
  15. package/dist/chunk-NOUORNCI.cjs +1452 -0
  16. package/dist/chunk-O6PTRJQ5.js +1195 -0
  17. package/dist/chunk-OBHJC3I2.cjs +2 -0
  18. package/dist/chunk-OOSNM45O.cjs +264 -0
  19. package/dist/chunk-P5B3HSPY.js +244 -0
  20. package/dist/chunk-PBE36BVA.js +1 -0
  21. package/dist/chunk-PVEYKCM6.js +1 -0
  22. package/dist/chunk-QZADGAP3.cjs +1218 -0
  23. package/dist/chunk-S7GNTGEE.js +1 -0
  24. package/dist/chunk-SMBDRWV2.cjs +2 -0
  25. package/dist/chunk-THYDOHOP.cjs +2 -0
  26. package/dist/chunk-WRHWOMZQ.cjs +190 -0
  27. package/dist/chunk-YNKP5JJA.cjs +32 -0
  28. package/dist/chunk-YWDKCX6N.cjs +91 -0
  29. package/dist/chunk-ZHNYNFGL.js +28 -0
  30. package/dist/compat/inline.cjs +137 -0
  31. package/dist/compat/inline.css +275 -0
  32. package/dist/compat/inline.d.cts +6 -0
  33. package/dist/compat/inline.d.ts +6 -0
  34. package/dist/compat/inline.js +4 -0
  35. package/dist/compat/parameters.cjs +90 -0
  36. package/dist/compat/parameters.css +997 -0
  37. package/dist/compat/parameters.d.cts +70 -0
  38. package/dist/compat/parameters.d.ts +70 -0
  39. package/dist/compat/parameters.js +9 -0
  40. package/dist/compat/tree.cjs +142 -0
  41. package/dist/compat/tree.css +1069 -0
  42. package/dist/compat/tree.d.cts +4 -0
  43. package/dist/compat/tree.d.ts +4 -0
  44. package/dist/compat/tree.js +5 -0
  45. package/dist/compat/variable-editor.cjs +82 -0
  46. package/dist/compat/variable-editor.d.cts +68 -0
  47. package/dist/compat/variable-editor.d.ts +68 -0
  48. package/dist/compat/variable-editor.js +1 -0
  49. package/dist/core/index.cjs +197 -0
  50. package/dist/core/index.d.cts +21 -0
  51. package/dist/core/index.d.ts +21 -0
  52. package/dist/core/index.js +4 -0
  53. package/dist/index.cjs +35 -0
  54. package/dist/index.css +1791 -0
  55. package/dist/index.d.cts +9 -0
  56. package/dist/index.d.ts +9 -0
  57. package/dist/index.js +10 -0
  58. package/dist/parameterValue-2pL9n-3q.d.ts +8 -0
  59. package/dist/parameterValue-Cky9Lnd3.d.cts +8 -0
  60. package/dist/react/index.cjs +35 -0
  61. package/dist/react/index.css +1791 -0
  62. package/dist/react/index.d.cts +9 -0
  63. package/dist/react/index.d.ts +9 -0
  64. package/dist/react/index.js +10 -0
  65. package/dist/react/inlineSchemaEditor/index.cjs +97 -0
  66. package/dist/react/inlineSchemaEditor/index.css +275 -0
  67. package/dist/react/inlineSchemaEditor/index.d.cts +6 -0
  68. package/dist/react/inlineSchemaEditor/index.d.ts +6 -0
  69. package/dist/react/inlineSchemaEditor/index.js +4 -0
  70. package/dist/react/parametersTable/index.cjs +22 -0
  71. package/dist/react/parametersTable/index.css +997 -0
  72. package/dist/react/parametersTable/index.d.cts +7 -0
  73. package/dist/react/parametersTable/index.d.ts +7 -0
  74. package/dist/react/parametersTable/index.js +9 -0
  75. package/dist/react/parametersTable/libs/generateValue.cjs +558 -0
  76. package/dist/react/parametersTable/libs/generateValue.d.cts +17 -0
  77. package/dist/react/parametersTable/libs/generateValue.d.ts +17 -0
  78. package/dist/react/parametersTable/libs/generateValue.js +551 -0
  79. package/dist/react/schemaTreeEditor/index.cjs +18 -0
  80. package/dist/react/schemaTreeEditor/index.css +1069 -0
  81. package/dist/react/schemaTreeEditor/index.d.cts +7 -0
  82. package/dist/react/schemaTreeEditor/index.d.ts +7 -0
  83. package/dist/react/schemaTreeEditor/index.js +5 -0
  84. package/dist/react/variableTextEditor/index.cjs +11 -0
  85. package/dist/react/variableTextEditor/index.css +306 -0
  86. package/dist/react/variableTextEditor/index.d.cts +6 -0
  87. package/dist/react/variableTextEditor/index.d.ts +6 -0
  88. package/dist/react/variableTextEditor/index.js +2 -0
  89. package/dist/schema-CKAPsYeW.d.cts +41 -0
  90. package/dist/schema-o7OJRaJ8.d.ts +41 -0
  91. package/dist/styles.css +1791 -0
  92. package/dist/tree-D06Xa6_N.d.ts +95 -0
  93. package/dist/tree-Dq1Rk-CF.d.cts +95 -0
  94. package/dist/types-B27Dw9do.d.cts +163 -0
  95. package/dist/types-B27Dw9do.d.ts +163 -0
  96. package/dist/types-Bk9rzr6l.d.cts +48 -0
  97. package/dist/types-D2jEaM9Z.d.cts +145 -0
  98. package/dist/types-D2jEaM9Z.d.ts +145 -0
  99. package/dist/types-xAihO_KW.d.ts +48 -0
  100. package/dist/variableTextEditor.types-ClzvARvK.d.cts +49 -0
  101. package/dist/variableTextEditor.types-ClzvARvK.d.ts +49 -0
  102. package/package.json +130 -0
@@ -0,0 +1,1057 @@
1
+ import { resolveLocalReference } from './chunk-KX3LFFOV.js';
2
+
3
+ // src/core/tree.ts
4
+ var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
5
+ function isUnsafeKey(key) {
6
+ return UNSAFE_KEYS.has(key);
7
+ }
8
+ function samePath(a, b) {
9
+ return a.length === b.length && a.every((segment, index) => segment === b[index]);
10
+ }
11
+ function isPlainObject(value) {
12
+ if (value === null || typeof value !== "object" || Array.isArray(value))
13
+ return false;
14
+ const proto = Object.getPrototypeOf(value);
15
+ return proto === Object.prototype || proto === null;
16
+ }
17
+ function safeRun(scope, fn, fallback, onError, path) {
18
+ try {
19
+ return fn();
20
+ } catch (cause) {
21
+ try {
22
+ onError?.({
23
+ scope,
24
+ message: cause instanceof Error ? cause.message : String(cause),
25
+ cause,
26
+ path
27
+ });
28
+ } catch {
29
+ }
30
+ return fallback;
31
+ }
32
+ }
33
+ var MAX_CLONE_DEPTH = 512;
34
+ function cloneSchema(value, seen, depth = 0) {
35
+ if (value === null || typeof value !== "object") return value;
36
+ if (depth > MAX_CLONE_DEPTH) {
37
+ throw new RangeError(
38
+ `Schema exceeds maximum clone depth of ${MAX_CLONE_DEPTH}`
39
+ );
40
+ }
41
+ const memo = seen ?? /* @__PURE__ */ new WeakMap();
42
+ const source = value;
43
+ if (memo.has(source)) return memo.get(source);
44
+ if (Array.isArray(value)) {
45
+ const out2 = new Array(value.length);
46
+ memo.set(source, out2);
47
+ for (let i = 0; i < value.length; i += 1) {
48
+ out2[i] = cloneSchema(value[i], memo, depth + 1);
49
+ }
50
+ return out2;
51
+ }
52
+ const out = /* @__PURE__ */ Object.create(null);
53
+ memo.set(source, out);
54
+ for (const key of Object.keys(value)) {
55
+ Object.defineProperty(out, key, {
56
+ value: cloneSchema(
57
+ value[key],
58
+ memo,
59
+ depth + 1
60
+ ),
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true
64
+ });
65
+ }
66
+ return out;
67
+ }
68
+ function setIn(root, path, value) {
69
+ if (path.length === 0) return value ?? root;
70
+ const [head, ...rest] = path;
71
+ if (Array.isArray(root)) {
72
+ const index = Number(head);
73
+ if (!Number.isInteger(index) || index < 0 || index >= root.length)
74
+ return root;
75
+ const child2 = root[index];
76
+ const nextChild2 = rest.length === 0 ? value : setIn(
77
+ isPlainObject(child2) || Array.isArray(child2) ? child2 : {},
78
+ rest,
79
+ value
80
+ );
81
+ if (nextChild2 === child2) return root;
82
+ const copy = root.slice();
83
+ copy[index] = nextChild2;
84
+ return copy;
85
+ }
86
+ const container = root;
87
+ const child = Object.hasOwn(container, head) ? container[head] : void 0;
88
+ const nextChild = rest.length === 0 ? value : setIn(
89
+ isPlainObject(child) || Array.isArray(child) ? child : {},
90
+ rest,
91
+ value
92
+ );
93
+ if (nextChild === child) return root;
94
+ return { ...container, [head]: nextChild };
95
+ }
96
+ function getIn(root, path) {
97
+ let cursor = root;
98
+ for (const token of path) {
99
+ if (Array.isArray(cursor)) {
100
+ const index = Number(token);
101
+ if (!Number.isInteger(index)) return void 0;
102
+ cursor = cursor[index];
103
+ continue;
104
+ }
105
+ if (!isPlainObject(cursor)) return void 0;
106
+ if (!Object.prototype.hasOwnProperty.call(cursor, token)) return void 0;
107
+ cursor = cursor[token];
108
+ }
109
+ return cursor;
110
+ }
111
+ function deleteIn(root, path) {
112
+ if (path.length === 0) return root;
113
+ const parentPath = path.slice(0, -1);
114
+ const key = path[path.length - 1];
115
+ const parent = getIn(root, parentPath);
116
+ if (Array.isArray(parent)) {
117
+ const index = Number(key);
118
+ if (!/^(0|[1-9][0-9]*)$/.test(key) || index >= parent.length) return root;
119
+ return setIn(
120
+ root,
121
+ parentPath,
122
+ parent.filter((_, position) => position !== index)
123
+ );
124
+ }
125
+ if (!isPlainObject(parent) || !Object.prototype.hasOwnProperty.call(parent, key))
126
+ return root;
127
+ const next = /* @__PURE__ */ Object.create(null);
128
+ for (const existing of Object.keys(parent)) {
129
+ if (existing === key) continue;
130
+ next[existing] = parent[existing];
131
+ }
132
+ return setIn(root, parentPath, next);
133
+ }
134
+ function patchSchema(root, path, patch) {
135
+ const target = getIn(root, path);
136
+ const base = isPlainObject(target) ? target : {};
137
+ const next = { ...base };
138
+ let changed = false;
139
+ for (const key of Object.keys(patch)) {
140
+ const value = patch[key];
141
+ if (value === void 0) {
142
+ if (Object.prototype.hasOwnProperty.call(next, key)) {
143
+ delete next[key];
144
+ changed = true;
145
+ }
146
+ continue;
147
+ }
148
+ if (next[key] !== value) {
149
+ Object.defineProperty(next, key, {
150
+ value,
151
+ enumerable: true,
152
+ writable: true,
153
+ configurable: true
154
+ });
155
+ changed = true;
156
+ }
157
+ }
158
+ if (!changed) return root;
159
+ return setIn(root, path, next);
160
+ }
161
+ function reorderKeys(source, fromKey, toIndex) {
162
+ if (!isPlainObject(source)) return source;
163
+ const keys = Object.keys(source);
164
+ const from = keys.indexOf(fromKey);
165
+ if (from < 0) return source;
166
+ const target = Math.max(0, Math.min(keys.length - 1, toIndex));
167
+ if (target === from) return source;
168
+ keys.splice(from, 1);
169
+ keys.splice(target, 0, fromKey);
170
+ const out = /* @__PURE__ */ Object.create(null);
171
+ for (const key of keys) {
172
+ out[key] = source[key];
173
+ }
174
+ return out;
175
+ }
176
+ function renameKey(source, fromKey, toKey) {
177
+ if (!isPlainObject(source) || fromKey === toKey) return source;
178
+ if (!Object.prototype.hasOwnProperty.call(source, fromKey)) return source;
179
+ if (Object.prototype.hasOwnProperty.call(source, toKey)) return source;
180
+ const out = /* @__PURE__ */ Object.create(null);
181
+ for (const key of Object.keys(source)) {
182
+ if (key === fromKey) out[toKey] = source[key];
183
+ else out[key] = source[key];
184
+ }
185
+ return out;
186
+ }
187
+ function insertKeyAfter(source, afterKey, key, value) {
188
+ const base = isPlainObject(source) ? source : {};
189
+ const out = /* @__PURE__ */ Object.create(null);
190
+ let inserted = false;
191
+ for (const existing of Object.keys(base)) {
192
+ out[existing] = base[existing];
193
+ if (existing === afterKey) {
194
+ out[key] = value;
195
+ inserted = true;
196
+ }
197
+ }
198
+ if (!inserted) out[key] = value;
199
+ return out;
200
+ }
201
+ function uniqueKey(source, base) {
202
+ const owner = isPlainObject(source) ? source : {};
203
+ if (!Object.prototype.hasOwnProperty.call(owner, base)) return base;
204
+ let counter = 2;
205
+ while (Object.prototype.hasOwnProperty.call(owner, `${base}${counter}`))
206
+ counter += 1;
207
+ return `${base}${counter}`;
208
+ }
209
+ var KEY_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$-]*$/;
210
+ function isValidKey(key) {
211
+ return typeof key === "string";
212
+ }
213
+ function setRequired(root, ownerPath, key, required) {
214
+ const owner = getIn(root, ownerPath);
215
+ const current = isPlainObject(owner) && Array.isArray(owner.required) ? owner.required : [];
216
+ const has = current.includes(key);
217
+ if (has === required) return root;
218
+ const next = required ? [...current, key] : current.filter((item) => item !== key);
219
+ if (next.length === 0) {
220
+ const base = isPlainObject(owner) ? { ...owner } : {};
221
+ delete base.required;
222
+ return setIn(root, ownerPath, base);
223
+ }
224
+ return patchSchema(root, ownerPath, { required: next });
225
+ }
226
+ function renameRequired(root, ownerPath, fromKey, toKey) {
227
+ const owner = getIn(root, ownerPath);
228
+ if (!isPlainObject(owner) || !Array.isArray(owner.required)) return root;
229
+ if (!owner.required.includes(fromKey)) return root;
230
+ return patchSchema(root, ownerPath, {
231
+ required: owner.required.map((item) => item === fromKey ? toKey : item)
232
+ });
233
+ }
234
+ function removeRequired(root, ownerPath, key) {
235
+ return setRequired(root, ownerPath, key, false);
236
+ }
237
+ var REF_PREFIX = "#/";
238
+ var MAX_REF_HOPS = 64;
239
+ function decodePointerToken(token) {
240
+ return token.replace(/~1/g, "/").replace(/~0/g, "~");
241
+ }
242
+ function resolveRef(ref, root, onError) {
243
+ if (typeof ref !== "string" || ref !== "#" && !ref.startsWith(REF_PREFIX) || !isPlainObject(root)) {
244
+ return null;
245
+ }
246
+ return safeRun(
247
+ "resolveRef",
248
+ () => {
249
+ let current = ref;
250
+ const visited = /* @__PURE__ */ new Set();
251
+ for (let hop = 0; hop < MAX_REF_HOPS; hop += 1) {
252
+ if (visited.has(current)) return null;
253
+ visited.add(current);
254
+ if (current !== "#" && !current.startsWith(REF_PREFIX)) return null;
255
+ const tokens = decodeURIComponent(current.slice(REF_PREFIX.length)).split("/").map(decodePointerToken);
256
+ const cursor = resolveLocalReference(current, root);
257
+ if (typeof cursor === "boolean")
258
+ return { schema: cursor, name: tokens[tokens.length - 1] ?? current };
259
+ if (!isPlainObject(cursor)) return null;
260
+ const next = cursor.$ref;
261
+ if (typeof next !== "string") {
262
+ const name = tokens[tokens.length - 1] ?? current;
263
+ return { schema: cursor, name };
264
+ }
265
+ current = next;
266
+ }
267
+ return null;
268
+ },
269
+ null,
270
+ onError
271
+ );
272
+ }
273
+ function signatureOf(schema) {
274
+ if (!isPlainObject(schema)) return "";
275
+ const top = Object.keys(schema);
276
+ const props = isPlainObject(schema.properties) ? Object.keys(schema.properties) : [];
277
+ const required = Array.isArray(schema.required) ? schema.required.length : 0;
278
+ return `${top.length}|${top.join(",")}|${props.join(",")}|${required}`;
279
+ }
280
+ function verifyExternalSchema(next, previous, previousSignature, onError) {
281
+ if (!isPlainObject(next)) {
282
+ onError?.({
283
+ scope: "commit",
284
+ message: "schema prop must be a plain object"
285
+ });
286
+ return {
287
+ schema: previous ?? {},
288
+ mutated: false,
289
+ signature: previousSignature
290
+ };
291
+ }
292
+ const signature = signatureOf(next);
293
+ const mutated = previous === next && signature !== previousSignature;
294
+ return { schema: next, mutated, signature };
295
+ }
296
+ function schemaTypeOf(schema) {
297
+ if (!isPlainObject(schema)) return "string";
298
+ const raw = schema.type;
299
+ if (Array.isArray(raw)) {
300
+ const first = raw.find((item) => item !== "null");
301
+ return first ?? "string";
302
+ }
303
+ if (typeof raw === "string") return raw;
304
+ if (isPlainObject(schema.properties)) return "object";
305
+ if (isPlainObject(schema.items)) return "array";
306
+ return "string";
307
+ }
308
+ function typeLabel(schema) {
309
+ const base = schemaTypeOf(schema);
310
+ if (base === "array" && isPlainObject(schema?.items)) {
311
+ return `array of ${schemaTypeOf(schema?.items)}`;
312
+ }
313
+ if (schema?.format) return `${base} \xB7 ${schema.format}`;
314
+ if (Array.isArray(schema?.enum) && schema.enum.length > 0) return "enum";
315
+ return base;
316
+ }
317
+ function isExpandable(schema) {
318
+ if (!isPlainObject(schema)) return false;
319
+ if (isPlainObject(schema.properties) && Object.keys(schema.properties).length > 0)
320
+ return true;
321
+ if (isPlainObject(schema.items) || typeof schema.items === "boolean")
322
+ return true;
323
+ if ([schema.prefixItems, schema.allOf, schema.anyOf, schema.oneOf].some(
324
+ (items) => Array.isArray(items) && items.length
325
+ ))
326
+ return true;
327
+ return false;
328
+ }
329
+ function defaultSchemaFor(type) {
330
+ switch (type) {
331
+ case "object":
332
+ return { type: "object", properties: {} };
333
+ case "array":
334
+ return { type: "array", items: { type: "string" } };
335
+ default:
336
+ return { type };
337
+ }
338
+ }
339
+ function changeSchemaType(schema, nextType) {
340
+ const next = cloneSchema(schema);
341
+ next.type = nextType;
342
+ const remove = (...keys) => {
343
+ for (const key of keys) delete next[key];
344
+ };
345
+ if (nextType !== "string") {
346
+ remove("minLength", "maxLength", "pattern");
347
+ }
348
+ if (nextType !== "number" && nextType !== "integer") {
349
+ remove(
350
+ "minimum",
351
+ "maximum",
352
+ "exclusiveMinimum",
353
+ "exclusiveMaximum",
354
+ "multipleOf"
355
+ );
356
+ }
357
+ if (nextType !== "array") {
358
+ remove(
359
+ "items",
360
+ "prefixItems",
361
+ "minItems",
362
+ "maxItems",
363
+ "uniqueItems",
364
+ "contains",
365
+ "minContains",
366
+ "maxContains"
367
+ );
368
+ }
369
+ if (nextType !== "object") {
370
+ remove(
371
+ "properties",
372
+ "required",
373
+ "additionalProperties",
374
+ "patternProperties",
375
+ "propertyNames",
376
+ "minProperties",
377
+ "maxProperties",
378
+ "dependentRequired",
379
+ "dependentSchemas",
380
+ "unevaluatedProperties"
381
+ );
382
+ }
383
+ if (nextType === "object" && !isPlainObject(next.properties)) {
384
+ next.properties = {};
385
+ }
386
+ if (nextType === "array" && !Object.prototype.hasOwnProperty.call(next, "items")) {
387
+ next.items = { type: "string" };
388
+ }
389
+ return next;
390
+ }
391
+ function refBlockSegment(isRefRoot, insideRef, hasChildren) {
392
+ if (isRefRoot) return hasChildren ? "head" : "single";
393
+ if (insideRef) return "body";
394
+ return "none";
395
+ }
396
+ function walk(value, key, path, parentPath, depth, required, insideRef, context) {
397
+ if (context.out.length >= context.maxRows) {
398
+ context.overflow.hit = true;
399
+ return;
400
+ }
401
+ if (typeof value !== "boolean" && !isPlainObject(value)) return;
402
+ const schema = typeof value === "boolean" ? {} : value;
403
+ const id = pointerId(path) || "$root";
404
+ let resolved = schema;
405
+ let resolvedValue = value;
406
+ let refName;
407
+ let recursive = false;
408
+ let isRefRoot = false;
409
+ if (isPlainObject(schema) && typeof schema.$ref === "string") {
410
+ isRefRoot = true;
411
+ if (context.refStack.includes(schema.$ref)) {
412
+ recursive = true;
413
+ refName = schema.$ref.split("/").pop();
414
+ } else {
415
+ const hit = resolveRef(
416
+ schema.$ref,
417
+ context.document ?? context.root,
418
+ context.onError
419
+ );
420
+ if (hit) {
421
+ resolvedValue = hit.schema;
422
+ resolved = typeof hit.schema === "boolean" ? {} : hit.schema;
423
+ refName = hit.name;
424
+ } else {
425
+ recursive = false;
426
+ refName = schema.$ref.split("/").pop();
427
+ }
428
+ }
429
+ }
430
+ const expandable = depth < 128 && !recursive && isExpandable(resolved);
431
+ const expanded = expandable && (context.expandAll || context.expanded.has(id));
432
+ const readOnly = insideRef;
433
+ const node = {
434
+ id,
435
+ key,
436
+ path,
437
+ parentPath,
438
+ depth,
439
+ kind: parentPath.length === 0 && key === "" ? "root" : parentPath[parentPath.length - 1] !== "properties" ? "items" : "property",
440
+ schema,
441
+ value,
442
+ resolved,
443
+ resolvedValue,
444
+ required,
445
+ expandable,
446
+ expanded,
447
+ refName,
448
+ recursive,
449
+ refSegment: refBlockSegment(isRefRoot, insideRef, expanded),
450
+ readOnly,
451
+ sortable: !insideRef && parentPath[parentPath.length - 1] === "properties"
452
+ };
453
+ context.out.push(node);
454
+ if (!expanded) return;
455
+ const childInsideRef = insideRef || isRefRoot;
456
+ const nextRefStack = isRefRoot && typeof schema.$ref === "string" ? [...context.refStack, schema.$ref] : context.refStack;
457
+ const childContext = {
458
+ ...context,
459
+ refStack: nextRefStack,
460
+ out: context.out
461
+ };
462
+ const requiredSet = Array.isArray(resolved.required) ? new Set(resolved.required) : /* @__PURE__ */ new Set();
463
+ const basePath = path;
464
+ if (isPlainObject(resolved.properties)) {
465
+ const keys = Object.keys(resolved.properties);
466
+ for (const childKey of keys) {
467
+ if (context.out.length >= context.maxRows) {
468
+ context.overflow.hit = true;
469
+ break;
470
+ }
471
+ walk(
472
+ resolved.properties[childKey],
473
+ childKey,
474
+ [...basePath, "properties", childKey],
475
+ [...basePath, "properties"],
476
+ depth + 1,
477
+ requiredSet.has(childKey),
478
+ childInsideRef,
479
+ childContext
480
+ );
481
+ }
482
+ }
483
+ if (isPlainObject(resolved.items) || typeof resolved.items === "boolean") {
484
+ walk(
485
+ resolved.items,
486
+ "items",
487
+ [...basePath, "items"],
488
+ basePath,
489
+ depth + 1,
490
+ false,
491
+ childInsideRef,
492
+ childContext
493
+ );
494
+ }
495
+ for (const keyword of ["prefixItems", "allOf", "anyOf", "oneOf"]) {
496
+ const entries = resolved[keyword];
497
+ if (!Array.isArray(entries)) continue;
498
+ for (let index = 0; index < entries.length; index++) {
499
+ if (context.out.length >= context.maxRows) {
500
+ context.overflow.hit = true;
501
+ break;
502
+ }
503
+ walk(
504
+ entries[index],
505
+ `${keyword}[${index}]`,
506
+ [...basePath, keyword, String(index)],
507
+ [...basePath, keyword],
508
+ depth + 1,
509
+ false,
510
+ childInsideRef,
511
+ childContext
512
+ );
513
+ }
514
+ }
515
+ if (isRefRoot) {
516
+ const last = context.out[context.out.length - 1];
517
+ if (last && last !== node) last.refSegment = "tail";
518
+ }
519
+ }
520
+ function flattenSchema(options) {
521
+ const { root, onError } = options;
522
+ return safeRun(
523
+ "flatten",
524
+ () => {
525
+ const out = [];
526
+ const overflow = { hit: false };
527
+ const context = {
528
+ ...options,
529
+ maxRows: Number.isFinite(options.maxRows) ? Math.max(1, Math.floor(options.maxRows)) : 5e3,
530
+ out,
531
+ refStack: [],
532
+ overflow
533
+ };
534
+ if (!isPlainObject(root)) return { nodes: out, overflow: false };
535
+ const requiredSet = Array.isArray(root.required) ? new Set(root.required) : /* @__PURE__ */ new Set();
536
+ if (isPlainObject(root.properties)) {
537
+ for (const key of Object.keys(root.properties)) {
538
+ if (context.out.length >= context.maxRows) {
539
+ context.overflow.hit = true;
540
+ break;
541
+ }
542
+ walk(
543
+ root.properties[key],
544
+ key,
545
+ ["properties", key],
546
+ ["properties"],
547
+ 0,
548
+ requiredSet.has(key),
549
+ false,
550
+ context
551
+ );
552
+ }
553
+ }
554
+ if (isPlainObject(root.properties)) {
555
+ for (const keyword of [
556
+ "items",
557
+ "prefixItems",
558
+ "allOf",
559
+ "anyOf",
560
+ "oneOf"
561
+ ]) {
562
+ const value = root[keyword];
563
+ const entries = Array.isArray(value) ? value : keyword === "items" && (isPlainObject(value) || typeof value === "boolean") ? [value] : [];
564
+ for (let index = 0; index < entries.length; index++) {
565
+ const singleton = keyword === "items" && !Array.isArray(value);
566
+ walk(
567
+ entries[index],
568
+ singleton ? keyword : `${keyword}[${index}]`,
569
+ singleton ? [keyword] : [keyword, String(index)],
570
+ singleton ? [] : [keyword],
571
+ 0,
572
+ false,
573
+ false,
574
+ context
575
+ );
576
+ if (context.overflow.hit) break;
577
+ }
578
+ }
579
+ }
580
+ if (!isPlainObject(root.properties) && (root.type || root.$ref || root.items !== void 0 || root.prefixItems || root.allOf || root.anyOf || root.oneOf)) {
581
+ walk(root, "", [], [], 0, false, false, context);
582
+ }
583
+ return { nodes: out, overflow: overflow.hit };
584
+ },
585
+ { nodes: [], overflow: false },
586
+ onError
587
+ );
588
+ }
589
+ function pruneExpanded(expanded, removedPath) {
590
+ const prefix = pointerId(removedPath);
591
+ let changed = false;
592
+ const next = /* @__PURE__ */ new Set();
593
+ for (const id of expanded) {
594
+ if (id === prefix || id.startsWith(`${prefix}/`)) {
595
+ changed = true;
596
+ continue;
597
+ }
598
+ next.add(id);
599
+ }
600
+ return changed ? next : expanded;
601
+ }
602
+ function remapExpanded(expanded, fromPath, toPath) {
603
+ const from = pointerId(fromPath);
604
+ const to = pointerId(toPath);
605
+ if (from === to) return expanded;
606
+ let changed = false;
607
+ const next = /* @__PURE__ */ new Set();
608
+ for (const id of expanded) {
609
+ if (id === from) {
610
+ next.add(to);
611
+ changed = true;
612
+ } else if (id.startsWith(`${from}/`)) {
613
+ next.add(`${to}${id.slice(from.length)}`);
614
+ changed = true;
615
+ } else {
616
+ next.add(id);
617
+ }
618
+ }
619
+ return changed ? next : expanded;
620
+ }
621
+ function requiredOwnerPath(parentPath) {
622
+ if (parentPath.length === 0) return null;
623
+ if (parentPath[parentPath.length - 1] !== "properties") return null;
624
+ return parentPath.slice(0, -1);
625
+ }
626
+ function stripUndefined(source) {
627
+ const out = /* @__PURE__ */ Object.create(null);
628
+ for (const key of Object.keys(source)) {
629
+ if (source[key] !== void 0) out[key] = source[key];
630
+ }
631
+ return out;
632
+ }
633
+ function pointerId(path) {
634
+ return path.map((segment) => segment.replace(/~/g, "~0").replace(/\//g, "~1")).join("/");
635
+ }
636
+
637
+ // src/core/schema.ts
638
+ function isRecord(value) {
639
+ return typeof value === "object" && value !== null && !Array.isArray(value);
640
+ }
641
+ function isSchema(value) {
642
+ return isRecord(value);
643
+ }
644
+ function toSchemaRecord(schema) {
645
+ if (!isRecord(schema)) return {};
646
+ return { ...schema };
647
+ }
648
+ var cloneSchema2 = cloneSchema;
649
+ function asOpenApiSchema(value) {
650
+ return value;
651
+ }
652
+ function compactSchema(value) {
653
+ const result = {};
654
+ for (const [key, item] of Object.entries(value)) {
655
+ if (item !== void 0)
656
+ Object.defineProperty(result, key, {
657
+ value: item,
658
+ enumerable: true,
659
+ configurable: true,
660
+ writable: true
661
+ });
662
+ }
663
+ return result;
664
+ }
665
+ function mergeSchema(schema, patch) {
666
+ return compactSchema({ ...toSchemaRecord(schema), ...toSchemaRecord(patch) });
667
+ }
668
+ var INLINE_SCHEMA_TYPES = /* @__PURE__ */ new Set([
669
+ "string",
670
+ "number",
671
+ "integer",
672
+ "boolean",
673
+ "array",
674
+ "object",
675
+ "null",
676
+ "any"
677
+ ]);
678
+ function normalizeSchemaType(value) {
679
+ if (typeof value === "string" && INLINE_SCHEMA_TYPES.has(value)) {
680
+ return value;
681
+ }
682
+ return "any";
683
+ }
684
+ function getSchemaType(schema) {
685
+ const record = toSchemaRecord(schema);
686
+ const type = record.type;
687
+ if (Array.isArray(type))
688
+ return type.length === 1 ? normalizeSchemaType(type[0]) : "any";
689
+ if (typeof type === "string") return normalizeSchemaType(type);
690
+ if ("properties" in record || "additionalProperties" in record || "patternProperties" in record || "required" in record)
691
+ return "object";
692
+ if ("items" in record || "prefixItems" in record || "contains" in record)
693
+ return "array";
694
+ if (typeof record.const === "boolean") return "boolean";
695
+ if (typeof record.const === "number")
696
+ return Number.isInteger(record.const) ? "integer" : "number";
697
+ if (record.const === null) return "null";
698
+ if (Array.isArray(record.enum) && record.enum.length > 0) {
699
+ const first = record.enum[0];
700
+ if (typeof first === "boolean") return "boolean";
701
+ if (typeof first === "number")
702
+ return Number.isInteger(first) ? "integer" : "number";
703
+ if (first === null) return "null";
704
+ if (Array.isArray(first)) return "array";
705
+ if (isRecord(first)) return "object";
706
+ if (typeof first === "string") return "string";
707
+ }
708
+ return "any";
709
+ }
710
+ var TYPE_FIELDS = [
711
+ "format",
712
+ "minLength",
713
+ "maxLength",
714
+ "pattern",
715
+ "minimum",
716
+ "maximum",
717
+ "exclusiveMinimum",
718
+ "exclusiveMaximum",
719
+ "multipleOf",
720
+ "items",
721
+ "prefixItems",
722
+ "minItems",
723
+ "maxItems",
724
+ "uniqueItems",
725
+ "contains",
726
+ "minContains",
727
+ "maxContains",
728
+ "unevaluatedItems",
729
+ "properties",
730
+ "required",
731
+ "additionalProperties",
732
+ "minProperties",
733
+ "maxProperties",
734
+ "patternProperties",
735
+ "propertyNames",
736
+ "dependentRequired",
737
+ "dependentSchemas",
738
+ "unevaluatedProperties",
739
+ "contentEncoding",
740
+ "contentMediaType",
741
+ "discriminator"
742
+ ];
743
+ function createSchemaForType(type, previous) {
744
+ if (previous && getSchemaType(previous) === type) return previous;
745
+ const base = cloneSchema2(previous ?? {});
746
+ for (const key of TYPE_FIELDS) delete base[key];
747
+ if (type === "any") {
748
+ delete base.type;
749
+ return compactSchema(base);
750
+ }
751
+ base.type = type;
752
+ if (type === "object") {
753
+ base.properties = {};
754
+ base.required = void 0;
755
+ }
756
+ if (type === "array") {
757
+ base.items = {
758
+ type: "string"
759
+ };
760
+ }
761
+ if (type === "boolean") {
762
+ delete base.format;
763
+ }
764
+ if (type === "null") {
765
+ delete base.default;
766
+ delete base.example;
767
+ delete base.examples;
768
+ delete base.enum;
769
+ delete base.const;
770
+ }
771
+ return compactSchema(base);
772
+ }
773
+ function normalizeFormatOptions(options) {
774
+ return Array.from(new Set((options ?? []).filter(Boolean)));
775
+ }
776
+ function parseOptionalNumber(value) {
777
+ if (value.trim() === "") return void 0;
778
+ const num = Number(value);
779
+ return Number.isFinite(num) ? num : void 0;
780
+ }
781
+ function toInputValue(value) {
782
+ return value === void 0 || value === null ? "" : String(value);
783
+ }
784
+ function stringifySchemaValue(value) {
785
+ if (value === void 0) return "";
786
+ if (typeof value === "string") return value;
787
+ if (value === null) return "null";
788
+ try {
789
+ return JSON.stringify(value, null, 2);
790
+ } catch {
791
+ return "";
792
+ }
793
+ }
794
+ function canParseSchemaValue(value, type) {
795
+ if (!value.trim()) return true;
796
+ if (type === "null") return value.trim() === "null";
797
+ if (type === "array") {
798
+ try {
799
+ return Array.isArray(JSON.parse(value));
800
+ } catch {
801
+ return false;
802
+ }
803
+ }
804
+ if (type === "object") {
805
+ try {
806
+ const parsed = JSON.parse(value);
807
+ return isRecord(parsed);
808
+ } catch {
809
+ return false;
810
+ }
811
+ }
812
+ if (type === "any") {
813
+ try {
814
+ JSON.parse(value);
815
+ return true;
816
+ } catch {
817
+ return true;
818
+ }
819
+ }
820
+ if (type === "number") return Number.isFinite(Number(value));
821
+ if (type === "integer") return Number.isInteger(Number(value));
822
+ if (type === "boolean") return value === "true" || value === "false";
823
+ return true;
824
+ }
825
+ function parseSchemaValue(value, type) {
826
+ if (type === "string") return value;
827
+ if (value.trim() === "") return void 0;
828
+ if (type === "number")
829
+ return Number.isFinite(Number(value)) ? Number(value) : void 0;
830
+ if (type === "integer") {
831
+ const parsed = Number(value);
832
+ return Number.isInteger(parsed) ? parsed : void 0;
833
+ }
834
+ if (type === "boolean") {
835
+ if (value === "true") return true;
836
+ if (value === "false") return false;
837
+ return void 0;
838
+ }
839
+ if (type === "null") return value.trim() === "null" ? null : void 0;
840
+ if (type === "array") {
841
+ try {
842
+ const parsed = JSON.parse(value);
843
+ return Array.isArray(parsed) ? parsed : void 0;
844
+ } catch {
845
+ return void 0;
846
+ }
847
+ }
848
+ if (type === "object") {
849
+ try {
850
+ const parsed = JSON.parse(value);
851
+ return isRecord(parsed) ? parsed : void 0;
852
+ } catch {
853
+ return void 0;
854
+ }
855
+ }
856
+ if (type === "any") {
857
+ try {
858
+ return JSON.parse(value);
859
+ } catch {
860
+ return value;
861
+ }
862
+ }
863
+ return value;
864
+ }
865
+ function getEnumValues(schema) {
866
+ const value = toSchemaRecord(schema).enum;
867
+ return Array.isArray(value) ? [...value] : [];
868
+ }
869
+ function getProperties(schema) {
870
+ const properties = toSchemaRecord(schema).properties;
871
+ if (!isRecord(properties)) return {};
872
+ const result = {};
873
+ Object.entries(properties).forEach(([key, value]) => {
874
+ Object.defineProperty(result, key, {
875
+ value: typeof value === "boolean" || isRecord(value) ? value : {},
876
+ enumerable: true,
877
+ configurable: true,
878
+ writable: true
879
+ });
880
+ });
881
+ return result;
882
+ }
883
+ function getRequiredProperties(schema) {
884
+ const required = toSchemaRecord(schema).required;
885
+ return new Set(
886
+ Array.isArray(required) ? required.filter((item) => typeof item === "string") : []
887
+ );
888
+ }
889
+ function updateProperty(schema, name, propertySchema) {
890
+ const nextProperties = getProperties(schema);
891
+ Object.defineProperty(nextProperties, name, {
892
+ value: propertySchema,
893
+ enumerable: true,
894
+ writable: true,
895
+ configurable: true
896
+ });
897
+ return compactSchema({
898
+ ...toSchemaRecord(schema),
899
+ type: "object",
900
+ properties: nextProperties
901
+ });
902
+ }
903
+ function removeProperty(schema, name) {
904
+ const nextProperties = getProperties(schema);
905
+ delete nextProperties[name];
906
+ const required = Array.from(getRequiredProperties(schema)).filter(
907
+ (item) => item !== name
908
+ );
909
+ return compactSchema({
910
+ ...toSchemaRecord(schema),
911
+ properties: nextProperties,
912
+ required: required.length ? required : void 0
913
+ });
914
+ }
915
+ function renameProperty(schema, oldName, newName) {
916
+ if (oldName === newName) return schema;
917
+ const nextProperties = getProperties(schema);
918
+ if (!Object.hasOwn(nextProperties, oldName) || Object.hasOwn(nextProperties, newName))
919
+ return schema;
920
+ const renamedProperties = Object.fromEntries(
921
+ Object.entries(nextProperties).map(([key, value]) => [
922
+ key === oldName ? newName : key,
923
+ value
924
+ ])
925
+ );
926
+ const required = Array.from(getRequiredProperties(schema)).map(
927
+ (item) => item === oldName ? newName : item
928
+ );
929
+ return compactSchema({
930
+ ...toSchemaRecord(schema),
931
+ properties: renamedProperties,
932
+ required: required.length ? required : void 0
933
+ });
934
+ }
935
+ function setPropertyRequired(schema, name, required) {
936
+ const next = getRequiredProperties(schema);
937
+ if (required) next.add(name);
938
+ else next.delete(name);
939
+ return compactSchema({
940
+ ...toSchemaRecord(schema),
941
+ required: next.size ? Array.from(next) : void 0
942
+ });
943
+ }
944
+ function getArrayItems(schema) {
945
+ const items = toSchemaRecord(schema).items;
946
+ return typeof items === "boolean" || isRecord(items) ? items : void 0;
947
+ }
948
+ function getPrefixItems(schema) {
949
+ const value = toSchemaRecord(schema).prefixItems;
950
+ return Array.isArray(value) ? value.filter(
951
+ (item) => typeof item === "boolean" || isRecord(item)
952
+ ) : [];
953
+ }
954
+ function getComposition(schema, key) {
955
+ const value = toSchemaRecord(schema)[key];
956
+ return Array.isArray(value) ? value.filter(
957
+ (item) => typeof item === "boolean" || isRecord(item)
958
+ ) : [];
959
+ }
960
+ function setComposition(schema, key, values) {
961
+ return compactSchema({
962
+ ...toSchemaRecord(schema),
963
+ [key]: values.length ? values : void 0
964
+ });
965
+ }
966
+ function getReferenceOptions(schema) {
967
+ const record = toSchemaRecord(schema);
968
+ const refs = [];
969
+ const components = toSchemaRecord(record.components);
970
+ const schemas = toSchemaRecord(components.schemas);
971
+ Object.keys(schemas).forEach(
972
+ (key) => refs.push(
973
+ `#/components/schemas/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`
974
+ )
975
+ );
976
+ const defs = toSchemaRecord(record.$defs);
977
+ Object.keys(defs).forEach(
978
+ (key) => refs.push(`#/$defs/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`)
979
+ );
980
+ const legacyDefs = toSchemaRecord(record.definitions);
981
+ Object.keys(legacyDefs).forEach(
982
+ (key) => refs.push(`#/definitions/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`)
983
+ );
984
+ return refs;
985
+ }
986
+ function getSchemaSummary(schema) {
987
+ if (typeof schema === "boolean")
988
+ return schema ? "Any value" : "No values allowed";
989
+ const record = toSchemaRecord(schema);
990
+ if (typeof record.$ref === "string" && record.$ref)
991
+ return `Reference: ${record.$ref}`;
992
+ const type = getSchemaType(schema);
993
+ if (type === "object") {
994
+ const count = Object.keys(getProperties(schema)).length;
995
+ return `${type} \xB7 ${count} propert${count === 1 ? "y" : "ies"}`;
996
+ }
997
+ if (type === "array") {
998
+ return Object.hasOwn(record, "items") ? "array \xB7 typed items" : "array";
999
+ }
1000
+ if (Array.isArray(record.enum) && record.enum.length)
1001
+ return `${type} \xB7 enum (${record.enum.length})`;
1002
+ if (typeof record.description === "string" && record.description.trim())
1003
+ return `${type} \xB7 ${record.description.trim()}`;
1004
+ return type;
1005
+ }
1006
+ function diffSchemaLines(before, after) {
1007
+ const a = before.split("\n");
1008
+ const b = after.split("\n");
1009
+ if (before === after) return a.map((value) => ({ kind: "same", value }));
1010
+ if (a.length * b.length > 25e4) {
1011
+ let prefix = 0;
1012
+ while (prefix < a.length && prefix < b.length && a[prefix] === b[prefix])
1013
+ prefix++;
1014
+ let suffix = 0;
1015
+ while (suffix < a.length - prefix && suffix < b.length - prefix && a[a.length - 1 - suffix] === b[b.length - 1 - suffix])
1016
+ suffix++;
1017
+ return [
1018
+ ...a.slice(0, prefix).map((value) => ({ kind: "same", value })),
1019
+ ...a.slice(prefix, a.length - suffix).map((value) => ({ kind: "removed", value })),
1020
+ ...b.slice(prefix, b.length - suffix).map((value) => ({ kind: "added", value })),
1021
+ ...a.slice(a.length - suffix).map((value) => ({ kind: "same", value }))
1022
+ ];
1023
+ }
1024
+ const dp = Array.from(
1025
+ { length: a.length + 1 },
1026
+ () => Array(b.length + 1).fill(0)
1027
+ );
1028
+ for (let i2 = a.length - 1; i2 >= 0; i2 -= 1) {
1029
+ for (let j2 = b.length - 1; j2 >= 0; j2 -= 1) {
1030
+ dp[i2][j2] = a[i2] === b[j2] ? dp[i2 + 1][j2 + 1] + 1 : Math.max(dp[i2 + 1][j2], dp[i2][j2 + 1]);
1031
+ }
1032
+ }
1033
+ const result = [];
1034
+ let i = 0;
1035
+ let j = 0;
1036
+ while (i < a.length && j < b.length) {
1037
+ if (a[i] === b[j]) {
1038
+ result.push({ kind: "same", value: a[i] });
1039
+ i += 1;
1040
+ j += 1;
1041
+ } else if (dp[i + 1][j] >= dp[i][j + 1]) {
1042
+ result.push({ kind: "removed", value: a[i] });
1043
+ i += 1;
1044
+ } else {
1045
+ result.push({ kind: "added", value: b[j] });
1046
+ j += 1;
1047
+ }
1048
+ }
1049
+ while (i < a.length) result.push({ kind: "removed", value: a[i++] });
1050
+ while (j < b.length) result.push({ kind: "added", value: b[j++] });
1051
+ return result;
1052
+ }
1053
+ function setEnumValues(schema, values) {
1054
+ return mergeSchema(schema, { enum: values.length ? values : void 0 });
1055
+ }
1056
+
1057
+ export { KEY_PATTERN, asOpenApiSchema, canParseSchemaValue, changeSchemaType, cloneSchema, cloneSchema2, compactSchema, createSchemaForType, defaultSchemaFor, deleteIn, diffSchemaLines, flattenSchema, getArrayItems, getComposition, getEnumValues, getIn, getPrefixItems, getProperties, getReferenceOptions, getRequiredProperties, getSchemaSummary, getSchemaType, insertKeyAfter, isExpandable, isPlainObject, isRecord, isSchema, isUnsafeKey, isValidKey, mergeSchema, normalizeFormatOptions, normalizeSchemaType, parseOptionalNumber, parseSchemaValue, patchSchema, pointerId, pruneExpanded, remapExpanded, removeProperty, removeRequired, renameKey, renameProperty, renameRequired, reorderKeys, requiredOwnerPath, resolveRef, safeRun, samePath, schemaTypeOf, setComposition, setEnumValues, setIn, setPropertyRequired, setRequired, stringifySchemaValue, stripUndefined, toInputValue, toSchemaRecord, typeLabel, uniqueKey, updateProperty, verifyExternalSchema };