@opencrvs/toolkit 1.9.13-rc.f568f39 → 1.9.13-rc.f6200fe

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.
@@ -1488,11 +1488,23 @@ var FieldId = import_zod17.z.string().refine(
1488
1488
  })
1489
1489
  ).describe("Unique identifier for the field");
1490
1490
  var FieldReference = import_zod17.z.object({
1491
- $$field: FieldId,
1491
+ $$field: FieldId.describe(
1492
+ "Field whose value is passed as the first argument to the computation"
1493
+ ),
1492
1494
  $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
1493
1495
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1496
+ ),
1497
+ $$code: import_zod17.z.string().optional().describe(
1498
+ "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
1499
+ )
1500
+ }).describe(
1501
+ "Reference to a field value, with an optional client-side computation applied."
1502
+ );
1503
+ var ComputedDefaultValue = import_zod17.z.object({
1504
+ $$code: import_zod17.z.string().describe(
1505
+ "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
1494
1506
  )
1495
- }).describe("Reference to a field by its ID");
1507
+ }).describe("A context-only computation used as a field default value.");
1496
1508
  var ValidationConfig = import_zod17.z.object({
1497
1509
  validator: Conditional,
1498
1510
  message: TranslationConfig
@@ -1526,7 +1538,7 @@ var BaseField = import_zod17.z.object({
1526
1538
  "Indicates whether the field can be modified during record correction."
1527
1539
  ),
1528
1540
  value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
1529
- "Reference to the source field or fields. When a value is defined, it is copied from the parent field when changed. If multiple references are provided, the first truthy value is used."
1541
+ "Reference to the source field or fields. When a value is defined, it is copied from the parent field when changed. If multiple references are provided, the first truthy value is used. A FieldReference with $$code computes the value via a custom client-side function."
1530
1542
  ),
1531
1543
  analytics: import_zod17.z.boolean().default(false).optional().describe(
1532
1544
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -1537,7 +1549,7 @@ var Divider = BaseField.extend({
1537
1549
  });
1538
1550
  var TextField = BaseField.extend({
1539
1551
  type: import_zod17.z.literal(FieldType.TEXT),
1540
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1552
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
1541
1553
  configuration: import_zod17.z.object({
1542
1554
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1543
1555
  type: import_zod17.z.enum(["text", "password"]).optional(),
@@ -1547,7 +1559,7 @@ var TextField = BaseField.extend({
1547
1559
  }).describe("Text input");
1548
1560
  var NumberField = BaseField.extend({
1549
1561
  type: import_zod17.z.literal(FieldType.NUMBER),
1550
- defaultValue: NumberFieldValue.optional(),
1562
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1551
1563
  configuration: import_zod17.z.object({
1552
1564
  min: import_zod17.z.number().optional().describe("Minimum value"),
1553
1565
  max: import_zod17.z.number().optional().describe("Maximum value"),
@@ -1557,7 +1569,7 @@ var NumberField = BaseField.extend({
1557
1569
  }).describe("Number input");
1558
1570
  var TextAreaField = BaseField.extend({
1559
1571
  type: import_zod17.z.literal(FieldType.TEXTAREA),
1560
- defaultValue: NonEmptyTextValue.optional(),
1572
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1561
1573
  configuration: import_zod17.z.object({
1562
1574
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1563
1575
  rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
@@ -1588,7 +1600,7 @@ var SignatureField = BaseField.extend({
1588
1600
  signaturePromptLabel: TranslationConfig.describe(
1589
1601
  "Title of the signature modal"
1590
1602
  ),
1591
- defaultValue: SignatureFieldValue.optional(),
1603
+ defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
1592
1604
  configuration: import_zod17.z.object({
1593
1605
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1594
1606
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -1601,11 +1613,11 @@ var EmailField = BaseField.extend({
1601
1613
  configuration: import_zod17.z.object({
1602
1614
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
1603
1615
  }).default({ maxLength: 10 }).optional(),
1604
- defaultValue: NonEmptyTextValue.optional()
1616
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1605
1617
  });
1606
1618
  var DateField = BaseField.extend({
1607
1619
  type: import_zod17.z.literal(FieldType.DATE),
1608
- defaultValue: SerializedNowDateTime.or(PlainDate).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
1620
+ defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
1609
1621
  configuration: import_zod17.z.object({
1610
1622
  notice: TranslationConfig.describe(
1611
1623
  "Text to display above the date input"
@@ -1614,7 +1626,7 @@ var DateField = BaseField.extend({
1614
1626
  }).describe("A single date input (yyyy-MM-dd)");
1615
1627
  var AgeField = BaseField.extend({
1616
1628
  type: import_zod17.z.literal(FieldType.AGE),
1617
- defaultValue: NumberFieldValue.optional(),
1629
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1618
1630
  configuration: import_zod17.z.object({
1619
1631
  asOfDate: FieldReference,
1620
1632
  prefix: TranslationConfig.optional(),
@@ -1623,7 +1635,7 @@ var AgeField = BaseField.extend({
1623
1635
  }).describe("An age input field which uses the current date as the asOfDate");
1624
1636
  var TimeField = BaseField.extend({
1625
1637
  type: import_zod17.z.literal(FieldType.TIME),
1626
- defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
1638
+ defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
1627
1639
  configuration: import_zod17.z.object({
1628
1640
  use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
1629
1641
  notice: TranslationConfig.describe(
@@ -1633,7 +1645,7 @@ var TimeField = BaseField.extend({
1633
1645
  }).describe("A single date input (HH-mm)");
1634
1646
  var DateRangeField = BaseField.extend({
1635
1647
  type: import_zod17.z.literal(FieldType.DATE_RANGE),
1636
- defaultValue: DateRangeFieldValue.optional(),
1648
+ defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
1637
1649
  configuration: import_zod17.z.object({
1638
1650
  notice: TranslationConfig.describe(
1639
1651
  "Text to display above the date input"
@@ -1667,7 +1679,7 @@ var PageHeader = BaseField.extend({
1667
1679
  }).describe("A read-only header component for form pages");
1668
1680
  var File = BaseField.extend({
1669
1681
  type: import_zod17.z.literal(FieldType.FILE),
1670
- defaultValue: FileFieldValue.optional(),
1682
+ defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
1671
1683
  configuration: import_zod17.z.object({
1672
1684
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1673
1685
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -1691,7 +1703,7 @@ var SelectOption = import_zod17.z.object({
1691
1703
  });
1692
1704
  var NumberWithUnitField = BaseField.extend({
1693
1705
  type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
1694
- defaultValue: NumberWithUnitFieldValue.optional(),
1706
+ defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
1695
1707
  options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
1696
1708
  configuration: import_zod17.z.object({
1697
1709
  min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
@@ -1703,7 +1715,7 @@ var NumberWithUnitField = BaseField.extend({
1703
1715
  }).describe("Number with unit input");
1704
1716
  var RadioGroup = BaseField.extend({
1705
1717
  type: import_zod17.z.literal(FieldType.RADIO_GROUP),
1706
- defaultValue: TextValue.optional(),
1718
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1707
1719
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1708
1720
  configuration: import_zod17.z.object({
1709
1721
  styles: import_zod17.z.object({
@@ -1722,7 +1734,7 @@ var BulletList = BaseField.extend({
1722
1734
  }).describe("A list of bullet points");
1723
1735
  var Select = BaseField.extend({
1724
1736
  type: import_zod17.z.literal(FieldType.SELECT),
1725
- defaultValue: TextValue.optional(),
1737
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1726
1738
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1727
1739
  noOptionsMessage: TranslationConfig.optional().describe(
1728
1740
  `
@@ -1741,7 +1753,7 @@ var SelectDateRangeOption = import_zod17.z.object({
1741
1753
  });
1742
1754
  var SelectDateRangeField = BaseField.extend({
1743
1755
  type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
1744
- defaultValue: SelectDateRangeValue.optional(),
1756
+ defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
1745
1757
  options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
1746
1758
  }).describe("Select input with date range options");
1747
1759
  var NameConfig = import_zod17.z.object({
@@ -1755,7 +1767,7 @@ var NameField = BaseField.extend({
1755
1767
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
1756
1768
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
1757
1769
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
1758
- }).optional(),
1770
+ }).or(ComputedDefaultValue).optional(),
1759
1771
  configuration: import_zod17.z.object({
1760
1772
  name: NameConfig.default({
1761
1773
  firstname: { required: true },
@@ -1776,20 +1788,20 @@ var NameField = BaseField.extend({
1776
1788
  }).optional()
1777
1789
  }).describe("Name input field");
1778
1790
  var PhoneField = BaseField.extend({
1779
- defaultValue: NonEmptyTextValue.optional(),
1791
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1780
1792
  type: import_zod17.z.literal(FieldType.PHONE)
1781
1793
  }).describe("Phone input field");
1782
1794
  var IdField = BaseField.extend({
1783
- defaultValue: NonEmptyTextValue.optional(),
1795
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1784
1796
  type: import_zod17.z.literal(FieldType.ID)
1785
1797
  }).describe("ID input field");
1786
1798
  var Checkbox = BaseField.extend({
1787
1799
  type: import_zod17.z.literal(FieldType.CHECKBOX),
1788
- defaultValue: CheckboxFieldValue.default(false)
1800
+ defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
1789
1801
  }).describe("Boolean checkbox field");
1790
1802
  var Country = BaseField.extend({
1791
1803
  type: import_zod17.z.literal(FieldType.COUNTRY),
1792
- defaultValue: NonEmptyTextValue.optional(),
1804
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1793
1805
  optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
1794
1806
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
1795
1807
  )
@@ -1805,12 +1817,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
1805
1817
  }).describe("Administrative area options");
1806
1818
  var AdministrativeArea = BaseField.extend({
1807
1819
  type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
1808
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1820
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
1809
1821
  configuration: AdministrativeAreaConfiguration
1810
1822
  }).describe("Administrative area input field e.g. facility, office");
1811
1823
  var LocationInput = BaseField.extend({
1812
1824
  type: import_zod17.z.literal(FieldType.LOCATION),
1813
- defaultValue: NonEmptyTextValue.optional(),
1825
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1814
1826
  configuration: import_zod17.z.object({
1815
1827
  searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
1816
1828
  })
@@ -1818,7 +1830,7 @@ var LocationInput = BaseField.extend({
1818
1830
  var FileUploadWithOptions = BaseField.extend({
1819
1831
  type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
1820
1832
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1821
- defaultValue: FileFieldWithOptionValue.optional(),
1833
+ defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
1822
1834
  configuration: import_zod17.z.object({
1823
1835
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1824
1836
  maxImageSize: import_zod17.z.object({
@@ -1831,11 +1843,11 @@ var FileUploadWithOptions = BaseField.extend({
1831
1843
  });
1832
1844
  var Facility = BaseField.extend({
1833
1845
  type: import_zod17.z.literal(FieldType.FACILITY),
1834
- defaultValue: NonEmptyTextValue.optional()
1846
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1835
1847
  }).describe("Input field for a facility");
1836
1848
  var Office = BaseField.extend({
1837
1849
  type: import_zod17.z.literal(FieldType.OFFICE),
1838
- defaultValue: NonEmptyTextValue.optional()
1850
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1839
1851
  }).describe("Input field for an office");
1840
1852
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
1841
1853
  administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
@@ -1869,7 +1881,7 @@ var Address = BaseField.extend({
1869
1881
  })
1870
1882
  ).optional()
1871
1883
  }).optional(),
1872
- defaultValue: DefaultAddressFieldValue.optional()
1884
+ defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
1873
1885
  }).describe("Address input field \u2013 a combination of location and text fields");
1874
1886
  var StaticDataEntry = import_zod17.z.object({
1875
1887
  id: import_zod17.z.string().describe("ID for the data entry."),
@@ -1888,7 +1900,7 @@ var DataField = BaseField.extend({
1888
1900
  }).describe("Data field for displaying read-only data");
1889
1901
  var ButtonField = BaseField.extend({
1890
1902
  type: import_zod17.z.literal(FieldType.BUTTON),
1891
- defaultValue: ButtonFieldValue.optional(),
1903
+ defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
1892
1904
  configuration: import_zod17.z.object({
1893
1905
  icon: import_zod17.z.string().optional().describe(
1894
1906
  "Icon for the button. You can find icons from OpenCRVS UI-Kit."
@@ -1913,7 +1925,7 @@ var AlphaPrintButton = BaseField.extend({
1913
1925
  }).describe("Print button field for printing certificates");
1914
1926
  var HttpField = BaseField.extend({
1915
1927
  type: import_zod17.z.literal(FieldType.HTTP),
1916
- defaultValue: HttpFieldValue.optional(),
1928
+ defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
1917
1929
  configuration: import_zod17.z.object({
1918
1930
  trigger: FieldReference,
1919
1931
  url: import_zod17.z.string().describe("URL to send the HTTP request to"),
@@ -1968,7 +1980,7 @@ var LinkButtonField = BaseField.extend({
1968
1980
  }).describe("Button that opens a link");
1969
1981
  var VerificationStatus = BaseField.extend({
1970
1982
  type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
1971
- defaultValue: VerificationStatusValue.optional(),
1983
+ defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
1972
1984
  configuration: import_zod17.z.object({
1973
1985
  status: TranslationConfig.describe("Text to display on the status pill."),
1974
1986
  description: TranslationConfig.describe(
@@ -1986,7 +1998,7 @@ var QueryParamReaderField = BaseField.extend({
1986
1998
  );
1987
1999
  var QrReaderField = BaseField.extend({
1988
2000
  type: import_zod17.z.literal(FieldType.QR_READER),
1989
- defaultValue: QrReaderFieldValue.optional(),
2001
+ defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
1990
2002
  configuration: import_zod17.z.object({
1991
2003
  validator: import_zod17.z.custom(
1992
2004
  (val) => typeof val === "object" && val !== null
@@ -1995,7 +2007,7 @@ var QrReaderField = BaseField.extend({
1995
2007
  });
1996
2008
  var IdReaderField = BaseField.extend({
1997
2009
  type: import_zod17.z.literal(FieldType.ID_READER),
1998
- defaultValue: IdReaderFieldValue.optional(),
2010
+ defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
1999
2011
  methods: import_zod17.z.array(
2000
2012
  import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2001
2013
  )
@@ -2556,7 +2568,37 @@ function resolveDataPath(rootData, dataPath, instancePath) {
2556
2568
  }
2557
2569
  return current;
2558
2570
  }
2571
+ function todayISO() {
2572
+ return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
2573
+ }
2574
+ var compiledFunctionCache = /* @__PURE__ */ new Map();
2575
+ function compileClientFunction(code) {
2576
+ let fn = compiledFunctionCache.get(code);
2577
+ if (!fn) {
2578
+ fn = new Function(`return (${code})`)();
2579
+ compiledFunctionCache.set(code, fn);
2580
+ }
2581
+ return fn;
2582
+ }
2559
2583
  (0, import_ajv_formats.default)(ajv);
2584
+ function buildClientFunctionContext(input) {
2585
+ return {
2586
+ $form: input.form,
2587
+ $now: todayISO(),
2588
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
2589
+ $online: isOnline(),
2590
+ $user: input.validatorContext?.user,
2591
+ $event: input.validatorContext?.event,
2592
+ $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
2593
+ user: input.systemVariables?.user,
2594
+ $window: input.systemVariables?.$window,
2595
+ locations: input.locations,
2596
+ adminLevelIds: input.adminLevelIds
2597
+ };
2598
+ }
2599
+ function runClientFunction(code, data, context) {
2600
+ return compileClientFunction(code)(data, context);
2601
+ }
2560
2602
  ajv.addKeyword({
2561
2603
  keyword: "daysFromDate",
2562
2604
  type: "string",
@@ -2601,12 +2643,35 @@ ajv.addKeyword({
2601
2643
  $data: true,
2602
2644
  errors: true,
2603
2645
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
2604
- validate(schema, data, _2, dataContext) {
2646
+ validate(_schema, data, _2, dataContext) {
2605
2647
  const locationIdInput = data;
2606
2648
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
2607
2649
  return locations.some((location) => location.id === locationIdInput);
2608
2650
  }
2609
2651
  });
2652
+ ajv.addKeyword({
2653
+ keyword: "customClientValidator",
2654
+ schemaType: "object",
2655
+ errors: true,
2656
+ // @ts-expect-error -- AJV's public types don't expose `rootData`. All
2657
+ // `validate()` callers build root data via `buildClientFunctionContext`,
2658
+ // so the cast holds.
2659
+ validate(schema, data, _2, dataContext) {
2660
+ return Boolean(
2661
+ runClientFunction(
2662
+ schema.code,
2663
+ data,
2664
+ dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
2665
+ )
2666
+ );
2667
+ }
2668
+ });
2669
+ function isOnline() {
2670
+ if (typeof window !== "undefined" && typeof navigator !== "undefined") {
2671
+ return navigator.onLine;
2672
+ }
2673
+ return true;
2674
+ }
2610
2675
 
2611
2676
  // ../commons/src/utils.ts
2612
2677
  var z29 = __toESM(require("zod"));
@@ -3229,7 +3294,54 @@ function createFieldConditionals(fieldId) {
3229
3294
  }
3230
3295
  },
3231
3296
  required: [fieldId]
3232
- })
3297
+ }),
3298
+ /**
3299
+ * Custom client-side validator. The provided function is serialised and executed
3300
+ * just-in-time on the client only. External references (e.g. lodash) are not
3301
+ * available inside the function body — all logic must be self-contained.
3302
+ *
3303
+ * @example
3304
+ * field('nid').customClientValidator((value) => {
3305
+ * // LUHN check — all logic must be inline
3306
+ * const digits = String(value).split('').map(Number)
3307
+ * // ...
3308
+ * return isValid
3309
+ * })
3310
+ */
3311
+ customClientValidator(validationFn) {
3312
+ const code = validationFn.toString();
3313
+ return defineFormConditional({
3314
+ type: "object",
3315
+ properties: wrapToPath(
3316
+ { [fieldId]: { customClientValidator: { code } } },
3317
+ this.$$subfield
3318
+ ),
3319
+ required: [fieldId]
3320
+ });
3321
+ },
3322
+ /**
3323
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
3324
+ * that can be used as the `value` property or a DATA component entry.
3325
+ * The function receives the referenced field's value as the first argument and
3326
+ * the full form context as the second; its return value replaces the field reference.
3327
+ * The function is serialised and executed just-in-time on the client only.
3328
+ * External references (e.g. lodash) are not available inside the function body.
3329
+ *
3330
+ * For computing a default value without referencing a specific field, use
3331
+ * `evaluate(fn)` in the `defaultValue` property instead.
3332
+ *
3333
+ * @example
3334
+ * field('a').customClientEvaluation((aValue, ctx) =>
3335
+ * Number(aValue) + Number(ctx.$form.b)
3336
+ * )
3337
+ */
3338
+ customClientEvaluation(computationFn) {
3339
+ return {
3340
+ $$code: computationFn.toString(),
3341
+ $$field: fieldId,
3342
+ $$subfield: this.$$subfield
3343
+ };
3344
+ }
3233
3345
  };
3234
3346
  }
3235
3347
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.13-rc.f568f39",
3
+ "version": "1.9.13-rc.f6200fe",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {
@@ -16,6 +16,10 @@
16
16
  "build": "./build.sh",
17
17
  "build:all": "lerna run build --include-dependencies --scope @opencrvs/toolkit && ./build.sh"
18
18
  },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/opencrvs/opencrvs-core.git"
22
+ },
19
23
  "dependencies": {
20
24
  "@trpc/client": "11.4.3",
21
25
  "@trpc/server": "11.4.3",