@fogpipe/forma-core 0.12.0 → 0.14.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 (40) hide show
  1. package/README.md +12 -12
  2. package/dist/{chunk-U2OXXFEH.js → chunk-BDICNCE2.js} +1 -1
  3. package/dist/chunk-BDICNCE2.js.map +1 -0
  4. package/dist/{chunk-ZSW7NIMY.js → chunk-NKA3L2LJ.js} +64 -15
  5. package/dist/chunk-NKA3L2LJ.js.map +1 -0
  6. package/dist/engine/calculate.d.ts.map +1 -1
  7. package/dist/engine/enabled.d.ts.map +1 -1
  8. package/dist/engine/index.cjs +62 -13
  9. package/dist/engine/index.cjs.map +1 -1
  10. package/dist/engine/index.d.ts +8 -8
  11. package/dist/engine/index.d.ts.map +1 -1
  12. package/dist/engine/index.js +2 -2
  13. package/dist/engine/readonly.d.ts.map +1 -1
  14. package/dist/engine/required.d.ts.map +1 -1
  15. package/dist/engine/validate.d.ts.map +1 -1
  16. package/dist/engine/visibility.d.ts.map +1 -1
  17. package/dist/feel/index.cjs.map +1 -1
  18. package/dist/feel/index.js +1 -1
  19. package/dist/index.cjs +62 -13
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +2 -2
  22. package/dist/types.d.ts +16 -0
  23. package/dist/types.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/__tests__/feel.test.ts +67 -76
  26. package/src/__tests__/format.test.ts +19 -6
  27. package/src/__tests__/validate.test.ts +62 -20
  28. package/src/__tests__/visibility.test.ts +217 -85
  29. package/src/engine/calculate.ts +13 -10
  30. package/src/engine/enabled.ts +16 -6
  31. package/src/engine/index.ts +8 -28
  32. package/src/engine/readonly.ts +16 -6
  33. package/src/engine/required.ts +7 -5
  34. package/src/engine/validate.ts +43 -22
  35. package/src/engine/visibility.ts +40 -16
  36. package/src/feel/index.ts +12 -12
  37. package/src/format/index.ts +1 -1
  38. package/src/types.ts +46 -7
  39. package/dist/chunk-U2OXXFEH.js.map +0 -1
  40. package/dist/chunk-ZSW7NIMY.js.map +0 -1
@@ -257,7 +257,10 @@ function getComputationOrder(computed) {
257
257
  const fieldNames = Object.keys(computed);
258
258
  const deps = /* @__PURE__ */ new Map();
259
259
  for (const name of fieldNames) {
260
- deps.set(name, findComputedDependencies(computed[name].expression, fieldNames));
260
+ deps.set(
261
+ name,
262
+ findComputedDependencies(computed[name].expression, fieldNames)
263
+ );
261
264
  }
262
265
  const sorted = [];
263
266
  const visited = /* @__PURE__ */ new Set();
@@ -345,10 +348,15 @@ function processArrayItemOptions(arrayPath, fieldDef, arrayData, baseContext, re
345
348
  item,
346
349
  itemIndex: i
347
350
  };
348
- for (const [itemFieldName, itemFieldDef] of Object.entries(fieldDef.itemFields)) {
351
+ for (const [itemFieldName, itemFieldDef] of Object.entries(
352
+ fieldDef.itemFields
353
+ )) {
349
354
  if (isSelectionField(itemFieldDef) && itemFieldDef.options && itemFieldDef.options.length > 0) {
350
355
  const itemFieldPath = `${arrayPath}[${i}].${itemFieldName}`;
351
- result[itemFieldPath] = filterOptionsByContext(itemFieldDef.options, itemContext);
356
+ result[itemFieldPath] = filterOptionsByContext(
357
+ itemFieldDef.options,
358
+ itemContext
359
+ );
352
360
  }
353
361
  }
354
362
  }
@@ -394,10 +402,15 @@ function evaluateArrayItemVisibility(arrayPath, fieldDef, arrayData, baseContext
394
402
  item,
395
403
  itemIndex: i
396
404
  };
397
- for (const [fieldName, itemFieldDef] of Object.entries(fieldDef.itemFields)) {
405
+ for (const [fieldName, itemFieldDef] of Object.entries(
406
+ fieldDef.itemFields
407
+ )) {
398
408
  const itemFieldPath = `${arrayPath}[${i}].${fieldName}`;
399
409
  if (itemFieldDef.visibleWhen) {
400
- result[itemFieldPath] = evaluateBoolean(itemFieldDef.visibleWhen, itemContext);
410
+ result[itemFieldPath] = evaluateBoolean(
411
+ itemFieldDef.visibleWhen,
412
+ itemContext
413
+ );
401
414
  } else {
402
415
  result[itemFieldPath] = true;
403
416
  }
@@ -457,7 +470,13 @@ function getOptionsVisibility(data, spec, options = {}) {
457
470
  if (isArrayField(fieldDef) && fieldDef.itemFields) {
458
471
  const arrayData = data[fieldPath];
459
472
  if (Array.isArray(arrayData)) {
460
- processArrayItemOptions(fieldPath, fieldDef, arrayData, baseContext, result);
473
+ processArrayItemOptions(
474
+ fieldPath,
475
+ fieldDef,
476
+ arrayData,
477
+ baseContext,
478
+ result
479
+ );
461
480
  }
462
481
  }
463
482
  }
@@ -504,7 +523,9 @@ function getRequired(data, spec, options = {}) {
504
523
  item,
505
524
  itemIndex: i
506
525
  };
507
- for (const [itemFieldName, itemFieldDef] of Object.entries(fieldDef.itemFields)) {
526
+ for (const [itemFieldName, itemFieldDef] of Object.entries(
527
+ fieldDef.itemFields
528
+ )) {
508
529
  const itemFieldPath = `${fieldPath}[${i}].${itemFieldName}`;
509
530
  result[itemFieldPath] = isFieldRequired(
510
531
  itemFieldPath,
@@ -560,7 +581,15 @@ function getEnabled(data, spec, options = {}) {
560
581
  if (fieldDef.type === "array" && fieldDef.itemFields) {
561
582
  const arrayData = data[fieldPath];
562
583
  if (Array.isArray(arrayData)) {
563
- evaluateArrayItemEnabled(fieldPath, fieldDef, arrayData, data, computed, spec, result);
584
+ evaluateArrayItemEnabled(
585
+ fieldPath,
586
+ fieldDef,
587
+ arrayData,
588
+ data,
589
+ computed,
590
+ spec,
591
+ result
592
+ );
564
593
  }
565
594
  }
566
595
  }
@@ -583,7 +612,9 @@ function evaluateArrayItemEnabled(arrayPath, fieldDef, arrayData, data, computed
583
612
  item,
584
613
  itemIndex: i
585
614
  };
586
- for (const [itemFieldName, itemFieldDef] of Object.entries(fieldDef.itemFields)) {
615
+ for (const [itemFieldName, itemFieldDef] of Object.entries(
616
+ fieldDef.itemFields
617
+ )) {
587
618
  const itemFieldPath = `${arrayPath}[${i}].${itemFieldName}`;
588
619
  result[itemFieldPath] = isFieldEnabled(itemFieldDef, itemContext);
589
620
  }
@@ -625,7 +656,15 @@ function getReadonly(data, spec, options = {}) {
625
656
  if (fieldDef.type === "array" && fieldDef.itemFields) {
626
657
  const arrayData = data[fieldPath];
627
658
  if (Array.isArray(arrayData)) {
628
- evaluateArrayItemReadonly(fieldPath, fieldDef, arrayData, data, computed, spec, result);
659
+ evaluateArrayItemReadonly(
660
+ fieldPath,
661
+ fieldDef,
662
+ arrayData,
663
+ data,
664
+ computed,
665
+ spec,
666
+ result
667
+ );
629
668
  }
630
669
  }
631
670
  }
@@ -648,7 +687,9 @@ function evaluateArrayItemReadonly(arrayPath, fieldDef, arrayData, data, compute
648
687
  item,
649
688
  itemIndex: i
650
689
  };
651
- for (const [itemFieldName, itemFieldDef] of Object.entries(fieldDef.itemFields)) {
690
+ for (const [itemFieldName, itemFieldDef] of Object.entries(
691
+ fieldDef.itemFields
692
+ )) {
652
693
  const itemFieldPath = `${arrayPath}[${i}].${itemFieldName}`;
653
694
  result[itemFieldPath] = isFieldReadonly(itemFieldDef, itemContext);
654
695
  }
@@ -728,7 +769,11 @@ function validateField(path, value, fieldDef, schemaProperty, spec, data, comput
728
769
  }
729
770
  }
730
771
  if (fieldDef.validations && !isEmpty(value)) {
731
- const customErrors = validateCustomRules(path, fieldDef.validations, context);
772
+ const customErrors = validateCustomRules(
773
+ path,
774
+ fieldDef.validations,
775
+ context
776
+ );
732
777
  errors.push(...customErrors);
733
778
  }
734
779
  if (Array.isArray(value) && fieldDef.type === "array") {
@@ -1076,7 +1121,11 @@ function validateArrayItem(arrayPath, index, item, itemFields, itemSchema, spec,
1076
1121
  }
1077
1122
  }
1078
1123
  if ((fieldDef == null ? void 0 : fieldDef.validations) && !isEmpty(value)) {
1079
- const customErrors = validateCustomRules(itemFieldPath, fieldDef.validations, context);
1124
+ const customErrors = validateCustomRules(
1125
+ itemFieldPath,
1126
+ fieldDef.validations,
1127
+ context
1128
+ );
1080
1129
  errors.push(...customErrors);
1081
1130
  }
1082
1131
  }