@makehq/forman-schema 1.3.4 → 1.4.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/dist/index.cjs +62 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +62 -17
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -247,6 +247,7 @@ function handleArrayType(field, result, context) {
|
|
|
247
247
|
function handleSelectType(field, result, context) {
|
|
248
248
|
const optionsOrGroups = isObject(field.options) ? field.options.store : field.options;
|
|
249
249
|
const nested = isObject(field.options) ? isObject(field.options.nested) ? field.options.nested.store : field.options.nested : void 0;
|
|
250
|
+
const nestedContainsStrings = Array.isArray(nested) && nested.some((item) => typeof item === "string");
|
|
250
251
|
const domain = isObject(field.options) ? isObject(field.options.nested) && field.options.nested.domain ? field.options.nested.domain : void 0 : void 0;
|
|
251
252
|
if (typeof optionsOrGroups === "string") {
|
|
252
253
|
Object.defineProperty(result, "x-fetch", {
|
|
@@ -268,12 +269,33 @@ function handleSelectType(field, result, context) {
|
|
|
268
269
|
})) {
|
|
269
270
|
result.oneOf = (options || []).map((option) => {
|
|
270
271
|
const localNested = (isObject(option.nested) ? option.nested.store : option.nested) || nested;
|
|
272
|
+
const localNestedContainsStrings = Array.isArray(localNested) && localNested.some((item) => typeof item === "string");
|
|
271
273
|
const localDomain = (isObject(option.nested) && option.nested.domain ? option.nested.domain : domain) || context.domain;
|
|
272
274
|
if (localNested) {
|
|
273
275
|
context.addConditionalFields(
|
|
274
276
|
field.name,
|
|
275
277
|
option.value,
|
|
276
|
-
typeof localNested === "string" ? appendQueryString(localNested, localDomain, [...context.tail, field.name]) :
|
|
278
|
+
typeof localNested === "string" ? appendQueryString(localNested, localDomain, [...context.tail, field.name]) : localNestedContainsStrings ? {
|
|
279
|
+
type: "object",
|
|
280
|
+
allOf: localNested.map(
|
|
281
|
+
(item) => typeof item === "string" ? {
|
|
282
|
+
$ref: appendQueryString(item, localDomain, [
|
|
283
|
+
...context.tail,
|
|
284
|
+
field.name
|
|
285
|
+
])
|
|
286
|
+
} : toJSONSchemaInternal(
|
|
287
|
+
{
|
|
288
|
+
type: "collection",
|
|
289
|
+
spec: [item]
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
...context,
|
|
293
|
+
domain: localDomain,
|
|
294
|
+
tail: [...context.tail, field.name]
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
} : toJSONSchemaInternal(
|
|
277
299
|
{ type: "collection", spec: localNested },
|
|
278
300
|
{
|
|
279
301
|
...context,
|
|
@@ -293,7 +315,7 @@ function handleSelectType(field, result, context) {
|
|
|
293
315
|
}
|
|
294
316
|
}
|
|
295
317
|
if (nested && domain && domain !== context.domain) {
|
|
296
|
-
if (typeof nested === "string") {
|
|
318
|
+
if (typeof nested === "string" || nestedContainsStrings) {
|
|
297
319
|
throw new SchemaConversionError("Dynamic nested fields with domain change are not supported.");
|
|
298
320
|
}
|
|
299
321
|
let root = context.roots[domain];
|
|
@@ -312,7 +334,19 @@ function handleSelectType(field, result, context) {
|
|
|
312
334
|
configurable: true,
|
|
313
335
|
enumerable: true,
|
|
314
336
|
writable: true,
|
|
315
|
-
value: typeof nested === "string" ? { $ref: appendQueryString(nested, context.domain, [...context.tail, field.name]) } :
|
|
337
|
+
value: typeof nested === "string" ? { $ref: appendQueryString(nested, context.domain, [...context.tail, field.name]) } : nestedContainsStrings ? {
|
|
338
|
+
type: "object",
|
|
339
|
+
allOf: nested.map(
|
|
340
|
+
(item) => typeof item === "string" ? { $ref: appendQueryString(item, context.domain, [...context.tail, field.name]) } : toJSONSchemaInternal(
|
|
341
|
+
{ type: "collection", spec: [item] },
|
|
342
|
+
{
|
|
343
|
+
...context,
|
|
344
|
+
domain: domain || context.domain,
|
|
345
|
+
tail: [...context.tail, field.name]
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
)
|
|
349
|
+
} : toJSONSchemaInternal(
|
|
316
350
|
{ type: "collection", spec: nested },
|
|
317
351
|
{
|
|
318
352
|
...context,
|
|
@@ -729,21 +763,32 @@ async function handleNestedFields(nested, value, field, context) {
|
|
|
729
763
|
tail: field.name ? [...context.tail, { name: field.name, value }] : context.tail
|
|
730
764
|
};
|
|
731
765
|
if (typeof store === "string") {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
766
|
+
store = [store];
|
|
767
|
+
}
|
|
768
|
+
if (Array.isArray(store) && store.some((item) => typeof item === "string")) {
|
|
769
|
+
const resolvedStore = [];
|
|
770
|
+
for (const item of store) {
|
|
771
|
+
if (typeof item === "string") {
|
|
772
|
+
try {
|
|
773
|
+
resolvedStore.push(...await context.resolveRemote(item, context));
|
|
774
|
+
} catch (error) {
|
|
775
|
+
return {
|
|
776
|
+
valid: false,
|
|
777
|
+
errors: [
|
|
778
|
+
...errors,
|
|
779
|
+
{
|
|
780
|
+
domain: context.domain,
|
|
781
|
+
path: context.path.join("."),
|
|
782
|
+
message: `Failed to resolve remote resource ${item}: ${error}`
|
|
783
|
+
}
|
|
784
|
+
]
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
} else {
|
|
788
|
+
resolvedStore.push(item);
|
|
789
|
+
}
|
|
746
790
|
}
|
|
791
|
+
store = resolvedStore;
|
|
747
792
|
}
|
|
748
793
|
if (store && domain && domain !== context.domain) {
|
|
749
794
|
if (!context.roots[domain]) {
|
package/dist/index.d.cts
CHANGED
|
@@ -138,7 +138,7 @@ type FormanSchemaExtendedOptions = {
|
|
|
138
138
|
/**
|
|
139
139
|
* Nested fields
|
|
140
140
|
*/
|
|
141
|
-
type FormanSchemaNested = FormanSchemaField[] | string | FormanSchemaExtendedNested;
|
|
141
|
+
type FormanSchemaNested = (FormanSchemaField | string)[] | string | FormanSchemaExtendedNested;
|
|
142
142
|
/**
|
|
143
143
|
* Extended nested fields
|
|
144
144
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ type FormanSchemaExtendedOptions = {
|
|
|
138
138
|
/**
|
|
139
139
|
* Nested fields
|
|
140
140
|
*/
|
|
141
|
-
type FormanSchemaNested = FormanSchemaField[] | string | FormanSchemaExtendedNested;
|
|
141
|
+
type FormanSchemaNested = (FormanSchemaField | string)[] | string | FormanSchemaExtendedNested;
|
|
142
142
|
/**
|
|
143
143
|
* Extended nested fields
|
|
144
144
|
*/
|
package/dist/index.js
CHANGED
|
@@ -218,6 +218,7 @@ function handleArrayType(field, result, context) {
|
|
|
218
218
|
function handleSelectType(field, result, context) {
|
|
219
219
|
const optionsOrGroups = isObject(field.options) ? field.options.store : field.options;
|
|
220
220
|
const nested = isObject(field.options) ? isObject(field.options.nested) ? field.options.nested.store : field.options.nested : void 0;
|
|
221
|
+
const nestedContainsStrings = Array.isArray(nested) && nested.some((item) => typeof item === "string");
|
|
221
222
|
const domain = isObject(field.options) ? isObject(field.options.nested) && field.options.nested.domain ? field.options.nested.domain : void 0 : void 0;
|
|
222
223
|
if (typeof optionsOrGroups === "string") {
|
|
223
224
|
Object.defineProperty(result, "x-fetch", {
|
|
@@ -239,12 +240,33 @@ function handleSelectType(field, result, context) {
|
|
|
239
240
|
})) {
|
|
240
241
|
result.oneOf = (options || []).map((option) => {
|
|
241
242
|
const localNested = (isObject(option.nested) ? option.nested.store : option.nested) || nested;
|
|
243
|
+
const localNestedContainsStrings = Array.isArray(localNested) && localNested.some((item) => typeof item === "string");
|
|
242
244
|
const localDomain = (isObject(option.nested) && option.nested.domain ? option.nested.domain : domain) || context.domain;
|
|
243
245
|
if (localNested) {
|
|
244
246
|
context.addConditionalFields(
|
|
245
247
|
field.name,
|
|
246
248
|
option.value,
|
|
247
|
-
typeof localNested === "string" ? appendQueryString(localNested, localDomain, [...context.tail, field.name]) :
|
|
249
|
+
typeof localNested === "string" ? appendQueryString(localNested, localDomain, [...context.tail, field.name]) : localNestedContainsStrings ? {
|
|
250
|
+
type: "object",
|
|
251
|
+
allOf: localNested.map(
|
|
252
|
+
(item) => typeof item === "string" ? {
|
|
253
|
+
$ref: appendQueryString(item, localDomain, [
|
|
254
|
+
...context.tail,
|
|
255
|
+
field.name
|
|
256
|
+
])
|
|
257
|
+
} : toJSONSchemaInternal(
|
|
258
|
+
{
|
|
259
|
+
type: "collection",
|
|
260
|
+
spec: [item]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
...context,
|
|
264
|
+
domain: localDomain,
|
|
265
|
+
tail: [...context.tail, field.name]
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
} : toJSONSchemaInternal(
|
|
248
270
|
{ type: "collection", spec: localNested },
|
|
249
271
|
{
|
|
250
272
|
...context,
|
|
@@ -264,7 +286,7 @@ function handleSelectType(field, result, context) {
|
|
|
264
286
|
}
|
|
265
287
|
}
|
|
266
288
|
if (nested && domain && domain !== context.domain) {
|
|
267
|
-
if (typeof nested === "string") {
|
|
289
|
+
if (typeof nested === "string" || nestedContainsStrings) {
|
|
268
290
|
throw new SchemaConversionError("Dynamic nested fields with domain change are not supported.");
|
|
269
291
|
}
|
|
270
292
|
let root = context.roots[domain];
|
|
@@ -283,7 +305,19 @@ function handleSelectType(field, result, context) {
|
|
|
283
305
|
configurable: true,
|
|
284
306
|
enumerable: true,
|
|
285
307
|
writable: true,
|
|
286
|
-
value: typeof nested === "string" ? { $ref: appendQueryString(nested, context.domain, [...context.tail, field.name]) } :
|
|
308
|
+
value: typeof nested === "string" ? { $ref: appendQueryString(nested, context.domain, [...context.tail, field.name]) } : nestedContainsStrings ? {
|
|
309
|
+
type: "object",
|
|
310
|
+
allOf: nested.map(
|
|
311
|
+
(item) => typeof item === "string" ? { $ref: appendQueryString(item, context.domain, [...context.tail, field.name]) } : toJSONSchemaInternal(
|
|
312
|
+
{ type: "collection", spec: [item] },
|
|
313
|
+
{
|
|
314
|
+
...context,
|
|
315
|
+
domain: domain || context.domain,
|
|
316
|
+
tail: [...context.tail, field.name]
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
)
|
|
320
|
+
} : toJSONSchemaInternal(
|
|
287
321
|
{ type: "collection", spec: nested },
|
|
288
322
|
{
|
|
289
323
|
...context,
|
|
@@ -700,21 +734,32 @@ async function handleNestedFields(nested, value, field, context) {
|
|
|
700
734
|
tail: field.name ? [...context.tail, { name: field.name, value }] : context.tail
|
|
701
735
|
};
|
|
702
736
|
if (typeof store === "string") {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
737
|
+
store = [store];
|
|
738
|
+
}
|
|
739
|
+
if (Array.isArray(store) && store.some((item) => typeof item === "string")) {
|
|
740
|
+
const resolvedStore = [];
|
|
741
|
+
for (const item of store) {
|
|
742
|
+
if (typeof item === "string") {
|
|
743
|
+
try {
|
|
744
|
+
resolvedStore.push(...await context.resolveRemote(item, context));
|
|
745
|
+
} catch (error) {
|
|
746
|
+
return {
|
|
747
|
+
valid: false,
|
|
748
|
+
errors: [
|
|
749
|
+
...errors,
|
|
750
|
+
{
|
|
751
|
+
domain: context.domain,
|
|
752
|
+
path: context.path.join("."),
|
|
753
|
+
message: `Failed to resolve remote resource ${item}: ${error}`
|
|
754
|
+
}
|
|
755
|
+
]
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
} else {
|
|
759
|
+
resolvedStore.push(item);
|
|
760
|
+
}
|
|
717
761
|
}
|
|
762
|
+
store = resolvedStore;
|
|
718
763
|
}
|
|
719
764
|
if (store && domain && domain !== context.domain) {
|
|
720
765
|
if (!context.roots[domain]) {
|