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