@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,551 @@
1
+ import { resolveParameterSchema } from '../../../chunk-MADPN2PJ.js';
2
+ import { dereferenceLocalSchema } from '../../../chunk-KX3LFFOV.js';
3
+ import { Faker, en } from '@faker-js/faker';
4
+ import Ajv from 'ajv/dist/2020.js';
5
+ import addFormats from 'ajv-formats';
6
+
7
+ var generateSync;
8
+ var DEFAULT_OPTIONS = {
9
+ humanize: true,
10
+ useDefault: true,
11
+ seed: Date.now(),
12
+ maxArrayItems: 3,
13
+ maxDepth: 5,
14
+ strictSchemaValidation: true,
15
+ validationRetryCount: 5
16
+ };
17
+ var ajv = new Ajv({ allErrors: true, strict: false, addUsedSchema: false });
18
+ addFormats(ajv);
19
+ var validators = /* @__PURE__ */ new WeakMap();
20
+ function isRecord(value) {
21
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22
+ }
23
+ function isReference(value) {
24
+ return isRecord(value) && typeof value.$ref === "string";
25
+ }
26
+ function isFiniteNumber(value) {
27
+ return typeof value === "number" && Number.isFinite(value);
28
+ }
29
+ function normalizeTypes(schema) {
30
+ const t = schema.type;
31
+ if (typeof t === "string") return [t];
32
+ if (Array.isArray(t))
33
+ return t.filter((x) => typeof x === "string");
34
+ return [];
35
+ }
36
+ function getSchemaFormat(schema) {
37
+ return typeof schema.format === "string" ? schema.format : void 0;
38
+ }
39
+ function getParameterName(context) {
40
+ return context.parameter.name.trim().toLowerCase();
41
+ }
42
+ function tokenizeParameterName(name) {
43
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-./:[\]{}]+/g, " ").split(/\s+/).filter(Boolean).map((token) => token.toLowerCase());
44
+ }
45
+ function hasToken(tokens, candidates) {
46
+ return candidates.some((candidate) => tokens.includes(candidate));
47
+ }
48
+ function hasAnyToken(tokens, candidates) {
49
+ return candidates.some(
50
+ (candidate) => tokens.some((t) => t.includes(candidate))
51
+ );
52
+ }
53
+ function resolveEnumValue(schema, fakerInstance, humanize) {
54
+ if (schema.const !== void 0) return schema.const;
55
+ if (!Array.isArray(schema.enum) || schema.enum.length === 0) return void 0;
56
+ return humanize ? fakerInstance.helpers.arrayElement(schema.enum) : schema.enum[0];
57
+ }
58
+ function getStringBounds(schema) {
59
+ return {
60
+ min: isFiniteNumber(schema.minLength) ? Math.max(0, schema.minLength) : void 0,
61
+ max: isFiniteNumber(schema.maxLength) ? Math.max(0, schema.maxLength) : void 0
62
+ };
63
+ }
64
+ function constrainString(value, schema) {
65
+ const { min, max } = getStringBounds(schema);
66
+ let result = value;
67
+ if (max !== void 0 && result.length > max) result = result.slice(0, max);
68
+ if (min !== void 0 && result.length < min)
69
+ result = result.padEnd(min, "x");
70
+ return result;
71
+ }
72
+ function getNumberBounds(schema, integer) {
73
+ const fallbackMin = 1;
74
+ const fallbackMax = integer ? 100 : 100;
75
+ let min = isFiniteNumber(schema.minimum) ? schema.minimum : fallbackMin;
76
+ let max = isFiniteNumber(schema.maximum) ? schema.maximum : fallbackMax;
77
+ if (typeof schema.exclusiveMinimum === "number") {
78
+ min = integer ? Math.max(min, Math.floor(schema.exclusiveMinimum) + 1) : Math.max(min, schema.exclusiveMinimum + Number.EPSILON);
79
+ }
80
+ if (typeof schema.exclusiveMaximum === "number") {
81
+ max = integer ? Math.min(max, Math.ceil(schema.exclusiveMaximum) - 1) : Math.min(max, schema.exclusiveMaximum - Number.EPSILON);
82
+ }
83
+ if (max < min) max = min;
84
+ return { min, max };
85
+ }
86
+ function generateInteger(schema, fakerInstance) {
87
+ const { min, max } = getNumberBounds(schema, true);
88
+ const multipleOf = isFiniteNumber(schema.multipleOf) && schema.multipleOf > 0 ? schema.multipleOf : void 0;
89
+ if (multipleOf) {
90
+ const minMultiple = Math.ceil(min / multipleOf);
91
+ const maxMultiple = Math.floor(max / multipleOf);
92
+ if (maxMultiple >= minMultiple) {
93
+ return fakerInstance.number.int({ min: minMultiple, max: maxMultiple }) * multipleOf;
94
+ }
95
+ }
96
+ return fakerInstance.number.int({
97
+ min: Math.ceil(min),
98
+ max: Math.floor(max)
99
+ });
100
+ }
101
+ function generateNumber(schema, fakerInstance) {
102
+ const { min, max } = getNumberBounds(schema, false);
103
+ const multipleOf = isFiniteNumber(schema.multipleOf) && schema.multipleOf > 0 ? schema.multipleOf : void 0;
104
+ if (multipleOf) {
105
+ const minMultiple = Math.ceil(min / multipleOf);
106
+ const maxMultiple = Math.floor(max / multipleOf);
107
+ if (maxMultiple >= minMultiple) {
108
+ return fakerInstance.number.int({ min: minMultiple, max: maxMultiple }) * multipleOf;
109
+ }
110
+ }
111
+ return fakerInstance.number.float({ min, max, fractionDigits: 2 });
112
+ }
113
+ function generateDate(schema, fakerInstance) {
114
+ const date = fakerInstance.date.recent({ days: 30 });
115
+ return getSchemaFormat(schema) === "date" ? date.toISOString().slice(0, 10) : date.toISOString();
116
+ }
117
+ function generateTime(fakerInstance) {
118
+ return fakerInstance.date.recent({ days: 1 }).toISOString().slice(11, 19);
119
+ }
120
+ function generateStringByParameterName(schema, context, fakerInstance) {
121
+ const parameterName = getParameterName(context);
122
+ const tokens = tokenizeParameterName(parameterName);
123
+ const format = getSchemaFormat(schema);
124
+ switch (format) {
125
+ case "email":
126
+ return fakerInstance.internet.email();
127
+ case "uuid":
128
+ return fakerInstance.string.uuid();
129
+ case "uri":
130
+ case "uri-reference":
131
+ return fakerInstance.internet.url();
132
+ case "hostname":
133
+ return fakerInstance.internet.domainName();
134
+ case "ipv4":
135
+ return fakerInstance.internet.ip();
136
+ case "ipv6":
137
+ return fakerInstance.internet.ipv6();
138
+ case "date":
139
+ case "date-time":
140
+ return generateDate(schema, fakerInstance);
141
+ case "time":
142
+ return generateTime(fakerInstance);
143
+ case "password":
144
+ return fakerInstance.internet.password({ length: 14, memorable: false });
145
+ }
146
+ if (hasAnyToken(tokens, ["uuid", "guid"])) return fakerInstance.string.uuid();
147
+ if (hasToken(tokens, ["id", "identifier", "key"])) {
148
+ return `usr_${fakerInstance.string.alphanumeric({ length: 10, casing: "lower" })}`;
149
+ }
150
+ if (hasAnyToken(tokens, ["firstname", "givenname"]))
151
+ return fakerInstance.person.firstName();
152
+ if (hasAnyToken(tokens, ["lastname", "surname", "familyname"]))
153
+ return fakerInstance.person.lastName();
154
+ if (hasAnyToken(tokens, ["fullname", "displayname", "username"]))
155
+ return fakerInstance.person.fullName();
156
+ if (hasAnyToken(tokens, ["email", "mail"]))
157
+ return fakerInstance.internet.email();
158
+ if (hasAnyToken(tokens, ["phone", "mobile", "telephone"]))
159
+ return fakerInstance.phone.number();
160
+ if (hasAnyToken(tokens, ["url", "uri", "website", "homepage", "link"]))
161
+ return fakerInstance.internet.url();
162
+ if (hasAnyToken(tokens, ["country", "countrycode"])) {
163
+ return hasAnyToken(tokens, ["code"]) ? fakerInstance.location.countryCode() : fakerInstance.location.country();
164
+ }
165
+ if (hasAnyToken(tokens, ["city"])) return fakerInstance.location.city();
166
+ if (hasAnyToken(tokens, ["state", "province", "region"]))
167
+ return fakerInstance.location.state();
168
+ if (hasAnyToken(tokens, ["zip", "zipcode", "postalcode", "postcode"]))
169
+ return fakerInstance.location.zipCode();
170
+ if (hasAnyToken(tokens, ["street", "address"]))
171
+ return fakerInstance.location.streetAddress();
172
+ if (hasAnyToken(tokens, ["company", "organization", "organisation"]))
173
+ return fakerInstance.company.name();
174
+ if (hasAnyToken(tokens, ["job", "title", "position", "role"]))
175
+ return fakerInstance.person.jobTitle();
176
+ if (hasAnyToken(tokens, [
177
+ "token",
178
+ "access_token",
179
+ "accesstoken",
180
+ "refresh_token",
181
+ "refreshtoken"
182
+ ])) {
183
+ return fakerInstance.string.alphanumeric({ length: 32, casing: "mixed" });
184
+ }
185
+ if (hasAnyToken(tokens, ["api_key", "apikey", "secret", "secretkey"])) {
186
+ return fakerInstance.string.alphanumeric({ length: 32, casing: "mixed" });
187
+ }
188
+ if (hasAnyToken(tokens, ["search", "query", "keyword", "q"])) {
189
+ return fakerInstance.helpers.arrayElement([
190
+ "laptop",
191
+ "coffee",
192
+ "openapi",
193
+ "developer tools",
194
+ "wireless headphones",
195
+ "running shoes",
196
+ "travel backpack"
197
+ ]);
198
+ }
199
+ if (hasAnyToken(tokens, ["slug"])) {
200
+ return fakerInstance.helpers.slugify(fakerInstance.commerce.productName()).toLowerCase();
201
+ }
202
+ if (hasAnyToken(tokens, ["product", "productname", "item"]))
203
+ return fakerInstance.commerce.productName();
204
+ if (hasAnyToken(tokens, ["description", "summary"]))
205
+ return fakerInstance.commerce.productDescription();
206
+ if (hasAnyToken(tokens, ["price", "amount", "cost", "total", "balance"])) {
207
+ return fakerInstance.commerce.price({ min: 10, max: 500, dec: 2 });
208
+ }
209
+ if (hasAnyToken(tokens, [
210
+ "date",
211
+ "birthday",
212
+ "birthdate",
213
+ "createdat",
214
+ "updatedat",
215
+ "deletedat",
216
+ "timestamp"
217
+ ])) {
218
+ return generateDate(schema, fakerInstance);
219
+ }
220
+ if (hasAnyToken(tokens, ["message", "comment", "note", "text"])) {
221
+ return fakerInstance.lorem.sentence({ min: 5, max: 12 });
222
+ }
223
+ return void 0;
224
+ }
225
+ function tryValidateValue(value, schema) {
226
+ try {
227
+ let validate = validators.get(schema);
228
+ if (!validate) {
229
+ validate = ajv.compile(schema);
230
+ validators.set(schema, validate);
231
+ ajv.removeSchema(schema);
232
+ }
233
+ return Boolean(validate(value));
234
+ } catch {
235
+ return false;
236
+ }
237
+ }
238
+ function generateSafeFallback(schema, genCtx, fakerInstance) {
239
+ const types = normalizeTypes(schema);
240
+ const pickedType = types.length ? fakerInstance.helpers.arrayElement(types) : void 0;
241
+ switch (pickedType) {
242
+ case "string":
243
+ return fakerInstance.string.alpha({ length: 10, casing: "mixed" });
244
+ case "integer":
245
+ return 1;
246
+ case "number":
247
+ return 1.5;
248
+ case "boolean":
249
+ return false;
250
+ case "array":
251
+ return [];
252
+ case "object":
253
+ return {};
254
+ case "null":
255
+ return null;
256
+ default:
257
+ return `${genCtx.parameter.name || "value"}-example`;
258
+ }
259
+ }
260
+ function prepareSchemaForJsf(schema, options) {
261
+ const maps = /* @__PURE__ */ new Set([
262
+ "properties",
263
+ "patternProperties",
264
+ "$defs",
265
+ "definitions",
266
+ "dependentSchemas"
267
+ ]);
268
+ const arrays = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf", "prefixItems"]);
269
+ const singles = /* @__PURE__ */ new Set([
270
+ "items",
271
+ "contains",
272
+ "additionalProperties",
273
+ "unevaluatedProperties",
274
+ "unevaluatedItems",
275
+ "not",
276
+ "if",
277
+ "then",
278
+ "else",
279
+ "propertyNames"
280
+ ]);
281
+ const visit = (value) => {
282
+ if (!isRecord(value)) return value;
283
+ const result = { ...value };
284
+ if (value.type === "array" || value.items !== void 0) {
285
+ if (isFiniteNumber(value.minItems) && value.minItems > options.maxArrayItems)
286
+ throw new RangeError(
287
+ "Array minimum exceeds the generation item budget."
288
+ );
289
+ result.maxItems = Math.min(
290
+ isFiniteNumber(value.maxItems) ? value.maxItems : options.maxArrayItems,
291
+ options.maxArrayItems
292
+ );
293
+ }
294
+ if (value.type === "string" || value.minLength !== void 0 || value.maxLength !== void 0) {
295
+ if (isFiniteNumber(value.minLength) && value.minLength > 16384)
296
+ throw new RangeError(
297
+ "String minimum exceeds the generation length budget."
298
+ );
299
+ result.maxLength = Math.min(
300
+ isFiniteNumber(value.maxLength) ? value.maxLength : 16384,
301
+ 16384
302
+ );
303
+ }
304
+ for (const [key, item] of Object.entries(value)) {
305
+ if (maps.has(key) && isRecord(item))
306
+ result[key] = Object.fromEntries(
307
+ Object.entries(item).map(([name, child]) => [name, visit(child)])
308
+ );
309
+ else if (arrays.has(key) && Array.isArray(item))
310
+ result[key] = item.map(visit);
311
+ else if (singles.has(key)) result[key] = visit(item);
312
+ }
313
+ return result;
314
+ };
315
+ return visit(schema);
316
+ }
317
+ function generateGenericSchemaValue(schema, genCtx, options, fakerInstance) {
318
+ const preparedSchema = prepareSchemaForJsf(schema, options);
319
+ try {
320
+ const raw = generateSync(
321
+ preparedSchema,
322
+ {
323
+ seed: options.seed,
324
+ maxDepth: options.maxDepth,
325
+ maxDefaultItems: options.maxArrayItems,
326
+ optionalsProbability: 0.35,
327
+ alwaysFakeOptionals: false,
328
+ fillProperties: true,
329
+ useDefaultValue: options.useDefault,
330
+ useExamplesValue: false,
331
+ extensions: { faker: fakerInstance },
332
+ failOnInvalidTypes: false
333
+ }
334
+ );
335
+ if (!options.strictSchemaValidation || tryValidateValue(raw, schema)) {
336
+ return raw;
337
+ }
338
+ for (let i = 0; i <= options.validationRetryCount; i++) {
339
+ const retryVal = generateSync(
340
+ preparedSchema,
341
+ {
342
+ seed: options.seed + i,
343
+ maxDepth: options.maxDepth,
344
+ maxDefaultItems: options.maxArrayItems,
345
+ optionalsProbability: 0.35,
346
+ alwaysFakeOptionals: false,
347
+ fillProperties: true,
348
+ useDefaultValue: options.useDefault,
349
+ useExamplesValue: false,
350
+ extensions: { faker: fakerInstance },
351
+ failOnInvalidTypes: false
352
+ }
353
+ );
354
+ if (tryValidateValue(retryVal, schema)) return retryVal;
355
+ }
356
+ return raw;
357
+ } catch {
358
+ return generateSafeFallback(schema, genCtx, fakerInstance);
359
+ }
360
+ }
361
+ function generateStringWithRetry(schema, context, fakerInstance, humanize, strict, retry) {
362
+ const enumVal = resolveEnumValue(schema, fakerInstance, humanize);
363
+ if (enumVal !== void 0) {
364
+ const candidate2 = constrainString(String(enumVal), schema);
365
+ if (!strict || tryValidateValue(candidate2, schema)) return candidate2;
366
+ }
367
+ const humanVal = generateStringByParameterName(
368
+ schema,
369
+ context,
370
+ fakerInstance
371
+ );
372
+ if (humanVal !== void 0) {
373
+ const candidate2 = constrainString(humanVal, schema);
374
+ if (!strict || tryValidateValue(candidate2, schema)) return candidate2;
375
+ }
376
+ if (schema.pattern && typeof schema.pattern === "string") {
377
+ try {
378
+ const jsfVal = generateSync(schema);
379
+ if (typeof jsfVal === "string") {
380
+ if (!strict || tryValidateValue(jsfVal, schema)) return jsfVal;
381
+ }
382
+ } catch {
383
+ }
384
+ }
385
+ const { min, max } = getStringBounds(schema);
386
+ if (min !== void 0 && min > 16384)
387
+ throw new RangeError(
388
+ "String minimum exceeds the generation length budget."
389
+ );
390
+ const length = fakerInstance.number.int({
391
+ min: min ?? Math.min(8, max ?? 8),
392
+ max: Math.min(max ?? Math.max(min ?? 8, 24), 16384)
393
+ });
394
+ const candidate = constrainString(
395
+ fakerInstance.string.alpha({ length, casing: "mixed" }),
396
+ schema
397
+ );
398
+ if (!strict || tryValidateValue(candidate, schema)) return candidate;
399
+ if (retry <= 0) return candidate;
400
+ return generateStringWithRetry(
401
+ schema,
402
+ context,
403
+ fakerInstance,
404
+ humanize,
405
+ strict,
406
+ retry - 1
407
+ );
408
+ }
409
+ function generateArrayValue(schema, genCtx, options, fakerInstance) {
410
+ if (genCtx.depth >= options.maxDepth) return [];
411
+ const minItems = isFiniteNumber(schema.minItems) ? Math.max(0, schema.minItems) : Math.min(
412
+ 1,
413
+ isFiniteNumber(schema.maxItems) ? Math.max(0, schema.maxItems) : 1
414
+ );
415
+ if (minItems > options.maxArrayItems)
416
+ throw new RangeError("Array minimum exceeds the generation item budget.");
417
+ const maxItems = isFiniteNumber(schema.maxItems) ? Math.min(options.maxArrayItems, Math.max(minItems, schema.maxItems)) : options.maxArrayItems;
418
+ const count = fakerInstance.number.int({ min: minItems, max: maxItems });
419
+ if (!schema.items || isReference(schema.items)) return [];
420
+ return Array.from(
421
+ { length: count },
422
+ (_, index) => generateFromSchema(
423
+ schema.items === true ? {} : schema.items,
424
+ { ...genCtx, rowIndex: genCtx.rowIndex + index, depth: genCtx.depth + 1 },
425
+ options,
426
+ fakerInstance
427
+ )
428
+ );
429
+ }
430
+ function generateObjectValue(schema, genCtx, options, fakerInstance) {
431
+ if (genCtx.depth >= options.maxDepth) return {};
432
+ const generated = generateGenericSchemaValue(
433
+ schema,
434
+ genCtx,
435
+ options,
436
+ fakerInstance
437
+ );
438
+ return isRecord(generated) ? generated : {};
439
+ }
440
+ function generateFromSchema(schema, genCtx, options, fakerInstance) {
441
+ if (genCtx.depth >= options.maxDepth) {
442
+ return generateSafeFallback(schema, genCtx, fakerInstance);
443
+ }
444
+ const enumVal = resolveEnumValue(schema, fakerInstance, options.humanize);
445
+ if (enumVal !== void 0) {
446
+ if (!options.strictSchemaValidation || tryValidateValue(enumVal, schema)) {
447
+ return enumVal;
448
+ }
449
+ }
450
+ const types = normalizeTypes(schema);
451
+ const targetType = types.length ? fakerInstance.helpers.arrayElement(types) : void 0;
452
+ switch (targetType) {
453
+ case "string":
454
+ return generateStringWithRetry(
455
+ schema,
456
+ genCtx,
457
+ fakerInstance,
458
+ options.humanize,
459
+ options.strictSchemaValidation,
460
+ options.validationRetryCount
461
+ );
462
+ case "integer": {
463
+ for (let i = 0; i <= options.validationRetryCount; i++) {
464
+ const candidate = generateInteger(schema, fakerInstance);
465
+ if (!options.strictSchemaValidation || tryValidateValue(candidate, schema))
466
+ return candidate;
467
+ }
468
+ return generateInteger(schema, fakerInstance);
469
+ }
470
+ case "number": {
471
+ for (let i = 0; i <= options.validationRetryCount; i++) {
472
+ const candidate = generateNumber(schema, fakerInstance);
473
+ if (!options.strictSchemaValidation || tryValidateValue(candidate, schema))
474
+ return candidate;
475
+ }
476
+ return generateNumber(schema, fakerInstance);
477
+ }
478
+ case "boolean": {
479
+ for (let i = 0; i <= options.validationRetryCount; i++) {
480
+ const candidate = typeof enumVal === "boolean" ? enumVal : fakerInstance.datatype.boolean();
481
+ if (!options.strictSchemaValidation || tryValidateValue(candidate, schema)) {
482
+ return candidate;
483
+ }
484
+ }
485
+ return false;
486
+ }
487
+ case "array":
488
+ return generateArrayValue(schema, genCtx, options, fakerInstance);
489
+ case "object":
490
+ return generateObjectValue(schema, genCtx, options, fakerInstance);
491
+ case "null": {
492
+ const candidate = null;
493
+ if (!options.strictSchemaValidation || tryValidateValue(candidate, schema)) {
494
+ return candidate;
495
+ }
496
+ return generateSafeFallback(schema, genCtx, fakerInstance);
497
+ }
498
+ default:
499
+ return generateGenericSchemaValue(schema, genCtx, options, fakerInstance);
500
+ }
501
+ }
502
+ async function generateParameterValue(context, inputOptions) {
503
+ context.signal?.throwIfAborted();
504
+ generateSync ??= (await import('json-schema-faker')).generateSync;
505
+ const options = { ...DEFAULT_OPTIONS, ...inputOptions };
506
+ for (const [key, maximum] of [
507
+ ["maxArrayItems", 1e3],
508
+ ["maxDepth", 32],
509
+ ["validationRetryCount", 20]
510
+ ]) {
511
+ const value2 = options[key];
512
+ if (!Number.isInteger(value2) || value2 < (key === "validationRetryCount" ? 0 : 1) || value2 > maximum) {
513
+ throw new RangeError(`Invalid generator option: ${key}`);
514
+ }
515
+ }
516
+ const fakerInstance = options.fakerInstance ?? new Faker({ locale: en });
517
+ if (inputOptions?.seed !== void 0 && !inputOptions?.fakerInstance) {
518
+ fakerInstance.seed(options.seed);
519
+ }
520
+ context.signal?.throwIfAborted();
521
+ let rawSchema = resolveParameterSchema(context.parameter, context.document) ?? context.parameter.schema;
522
+ if (rawSchema === void 0)
523
+ return `${context.parameter.name || "parameter"}-value`;
524
+ const resolvedSchema = dereferenceLocalSchema(
525
+ rawSchema,
526
+ context.document ?? rawSchema
527
+ );
528
+ if (resolvedSchema === false)
529
+ throw new Error("No value satisfies a false schema.");
530
+ const derefedSchema = resolvedSchema === true ? {} : resolvedSchema;
531
+ const generationSchema = prepareSchemaForJsf(
532
+ derefedSchema,
533
+ options
534
+ );
535
+ const genCtx = { ...context, depth: 0 };
536
+ context.signal?.throwIfAborted();
537
+ const value = generateFromSchema(
538
+ generationSchema,
539
+ genCtx,
540
+ options,
541
+ fakerInstance
542
+ );
543
+ if (options.strictSchemaValidation && !tryValidateValue(value, derefedSchema)) {
544
+ throw new Error(
545
+ "Unable to generate a value satisfying this schema. Provide an example or a custom generator."
546
+ );
547
+ }
548
+ return value;
549
+ }
550
+
551
+ export { generateParameterValue };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ require('../../chunk-OBHJC3I2.cjs');
4
+ var chunkQZADGAP3_cjs = require('../../chunk-QZADGAP3.cjs');
5
+ require('../../chunk-4H3LXOL4.cjs');
6
+ require('../../chunk-GTZH37JS.cjs');
7
+ require('../../chunk-YWDKCX6N.cjs');
8
+
9
+
10
+
11
+ Object.defineProperty(exports, "SCHEMA_TYPES", {
12
+ enumerable: true,
13
+ get: function () { return chunkQZADGAP3_cjs.SCHEMA_TYPES; }
14
+ });
15
+ Object.defineProperty(exports, "SchemaTreeEditor", {
16
+ enumerable: true,
17
+ get: function () { return chunkQZADGAP3_cjs.SchemaTreeEditor; }
18
+ });