@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,88 @@
1
+ // src/core/references.ts
2
+ var maps = /* @__PURE__ */ new Set([
3
+ "properties",
4
+ "patternProperties",
5
+ "$defs",
6
+ "definitions",
7
+ "dependentSchemas"
8
+ ]);
9
+ var arrays = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf", "prefixItems"]);
10
+ var singles = /* @__PURE__ */ new Set([
11
+ "items",
12
+ "contains",
13
+ "not",
14
+ "if",
15
+ "then",
16
+ "else",
17
+ "additionalProperties",
18
+ "unevaluatedProperties",
19
+ "unevaluatedItems",
20
+ "propertyNames"
21
+ ]);
22
+ function resolveLocalReference(reference, document) {
23
+ if (reference === "#") return document;
24
+ if (!reference.startsWith("#/")) return void 0;
25
+ let tokens;
26
+ try {
27
+ tokens = decodeURIComponent(reference.slice(2)).split("/").map((token) => token.replace(/~1/g, "/").replace(/~0/g, "~"));
28
+ } catch {
29
+ return void 0;
30
+ }
31
+ let value = document;
32
+ for (const token of tokens) {
33
+ if (value === null || typeof value !== "object" || !Object.hasOwn(value, token))
34
+ return void 0;
35
+ value = value[token];
36
+ }
37
+ return value;
38
+ }
39
+ function dereferenceLocalSchema(schema, document = schema, maxDepth = 64) {
40
+ const depthLimit = Number.isFinite(maxDepth) ? Math.max(0, Math.min(128, Math.floor(maxDepth))) : 64;
41
+ let visitedNodes = 0;
42
+ const visit = (value, depth, refs) => {
43
+ if (++visitedNodes > 2e4)
44
+ throw new RangeError("Schema reference node budget exceeded");
45
+ if (depth > depthLimit)
46
+ throw new RangeError("Schema reference depth exceeded");
47
+ if (Array.isArray(value))
48
+ return value.map((item) => visit(item, depth + 1, refs));
49
+ if (value === null || typeof value !== "object") return value;
50
+ const record = value;
51
+ if (typeof record.$ref === "string") {
52
+ if (refs.has(record.$ref))
53
+ throw new Error(
54
+ `Recursive reference cannot be generated: ${record.$ref}`
55
+ );
56
+ const target = resolveLocalReference(record.$ref, document);
57
+ if (target === void 0)
58
+ throw new Error(`Unresolved local reference: ${record.$ref}`);
59
+ const nextRefs = new Set(refs).add(record.$ref);
60
+ const resolved = visit(target, depth + 1, nextRefs);
61
+ const { $ref, ...siblings } = record;
62
+ if (!Object.keys(siblings).length) return resolved;
63
+ return { allOf: [resolved, visit(siblings, depth + 1, refs)] };
64
+ }
65
+ return Object.fromEntries(
66
+ Object.entries(record).map(([key, item]) => {
67
+ if (maps.has(key) && item && typeof item === "object" && !Array.isArray(item)) {
68
+ return [
69
+ key,
70
+ Object.fromEntries(
71
+ Object.entries(item).map(([name, child]) => [
72
+ name,
73
+ visit(child, depth + 1, refs)
74
+ ])
75
+ )
76
+ ];
77
+ }
78
+ return [
79
+ key,
80
+ arrays.has(key) || singles.has(key) ? visit(item, depth + 1, refs) : item
81
+ ];
82
+ })
83
+ );
84
+ };
85
+ return visit(schema, 0, /* @__PURE__ */ new Set());
86
+ }
87
+
88
+ export { dereferenceLocalSchema, resolveLocalReference };
@@ -0,0 +1,185 @@
1
+ import { resolveLocalReference } from './chunk-KX3LFFOV.js';
2
+
3
+ // src/react/parametersTable/libs/parameterValue.ts
4
+ function isReference(value) {
5
+ return typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string";
6
+ }
7
+ function resolveObject(value, document) {
8
+ const seen = /* @__PURE__ */ new Set();
9
+ let result = value;
10
+ while (isReference(result)) {
11
+ if (!document || seen.has(result.$ref) || seen.size >= 64) return void 0;
12
+ seen.add(result.$ref);
13
+ const target = resolveLocalReference(result.$ref, document);
14
+ if (!target || typeof target !== "object" || Array.isArray(target))
15
+ return void 0;
16
+ const { $ref, ...siblings } = result;
17
+ result = { ...target, ...siblings };
18
+ }
19
+ return result && typeof result === "object" && !Array.isArray(result) ? result : void 0;
20
+ }
21
+ function resolveSchema(value, document) {
22
+ if (typeof value === "boolean") return value;
23
+ if (isReference(value) && document) {
24
+ const seen = /* @__PURE__ */ new Set();
25
+ let current = value;
26
+ while (isReference(current)) {
27
+ if (seen.has(current.$ref) || seen.size >= 64) return void 0;
28
+ seen.add(current.$ref);
29
+ const target = resolveLocalReference(current.$ref, document);
30
+ if (typeof target === "boolean") {
31
+ if (!target) return false;
32
+ const { $ref: $ref2, ...siblings2 } = current;
33
+ return Object.keys(siblings2).length ? siblings2 : true;
34
+ }
35
+ if (!target || typeof target !== "object" || Array.isArray(target))
36
+ return void 0;
37
+ const { $ref, ...siblings } = current;
38
+ current = { ...target, ...siblings };
39
+ }
40
+ return current;
41
+ }
42
+ return resolveObject(value, document);
43
+ }
44
+ function resolveExamplesMap(examples, document) {
45
+ if (!examples) {
46
+ return void 0;
47
+ }
48
+ const entries = Object.entries(examples);
49
+ for (const [name, rawExample] of entries) {
50
+ const example = resolveObject(rawExample, document);
51
+ if (!example) continue;
52
+ if (Object.prototype.hasOwnProperty.call(example, "value")) {
53
+ return {
54
+ value: example.value,
55
+ source: "examples",
56
+ exampleName: name
57
+ };
58
+ }
59
+ if (Object.prototype.hasOwnProperty.call(example, "dataValue")) {
60
+ return {
61
+ value: example.dataValue,
62
+ source: "examples",
63
+ exampleName: name
64
+ };
65
+ }
66
+ if (example.serializedValue !== void 0) {
67
+ return {
68
+ value: example.serializedValue,
69
+ source: "examples",
70
+ exampleName: name
71
+ };
72
+ }
73
+ if (example.externalValue) {
74
+ return {
75
+ value: void 0,
76
+ source: "external-example",
77
+ exampleName: name,
78
+ externalValue: example.externalValue
79
+ };
80
+ }
81
+ }
82
+ return void 0;
83
+ }
84
+ function resolveContent(parameter, document) {
85
+ if (!parameter.content) {
86
+ return {};
87
+ }
88
+ const entries = Object.entries(parameter.content);
89
+ if (entries.length === 0) {
90
+ return {};
91
+ }
92
+ const mediaType = resolveObject(entries[0][1], document);
93
+ if (!mediaType) {
94
+ return {};
95
+ }
96
+ const schema = resolveSchema(mediaType.schema, document);
97
+ if (mediaType.example !== void 0) {
98
+ return {
99
+ schema,
100
+ value: {
101
+ value: mediaType.example,
102
+ source: "example"
103
+ }
104
+ };
105
+ }
106
+ const examplesValue = resolveExamplesMap(mediaType.examples, document);
107
+ return {
108
+ schema,
109
+ value: examplesValue
110
+ };
111
+ }
112
+ function resolveParameterSchema(parameter, document) {
113
+ if (parameter.schema !== void 0)
114
+ return resolveSchema(parameter.schema, document);
115
+ return resolveContent(parameter, document).schema;
116
+ }
117
+ function resolveParameterValue(parameter, document) {
118
+ if (parameter.example !== void 0) {
119
+ return {
120
+ value: parameter.example,
121
+ source: "example"
122
+ };
123
+ }
124
+ const examplesValue = resolveExamplesMap(parameter.examples, document);
125
+ if (examplesValue) {
126
+ return examplesValue;
127
+ }
128
+ const content = resolveContent(parameter, document);
129
+ if (content.value) {
130
+ return content.value;
131
+ }
132
+ const schema = resolveParameterSchema(parameter, document);
133
+ if (schema && typeof schema === "object") {
134
+ if (schema.example !== void 0) {
135
+ return {
136
+ value: schema.example,
137
+ source: "schema-example"
138
+ };
139
+ }
140
+ if (Array.isArray(schema.examples) && schema.examples.length) {
141
+ return { value: schema.examples[0], source: "schema-example" };
142
+ }
143
+ if (schema.default !== void 0) {
144
+ return {
145
+ value: schema.default,
146
+ source: "schema-default"
147
+ };
148
+ }
149
+ }
150
+ return {
151
+ value: void 0,
152
+ source: "missing"
153
+ };
154
+ }
155
+ function resolveParameterType(parameter, document) {
156
+ const schema = resolveParameterSchema(parameter, document);
157
+ if (typeof schema === "boolean") return schema ? "any" : "never";
158
+ if (!schema) {
159
+ return "unknown";
160
+ }
161
+ if (Array.isArray(schema.type)) {
162
+ return schema.type.join(" | ");
163
+ }
164
+ if (schema.type) {
165
+ if (schema.format) {
166
+ return `${schema.type} (${schema.format})`;
167
+ }
168
+ return schema.type;
169
+ }
170
+ if (schema.oneOf) {
171
+ return "oneOf";
172
+ }
173
+ if (schema.anyOf) {
174
+ return "anyOf";
175
+ }
176
+ if (schema.allOf) {
177
+ return "allOf";
178
+ }
179
+ if (schema.$ref) {
180
+ return "reference";
181
+ }
182
+ return "unknown";
183
+ }
184
+
185
+ export { isReference, resolveParameterSchema, resolveParameterType, resolveParameterValue };