@opencrvs/toolkit 2.0.0-rc.0f51ec5 → 2.0.0-rc.0fb1707
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/application-config/index.js +32 -44
- package/dist/commons/api/router.d.ts +15 -15
- package/dist/commons/application-config/index.d.ts +0 -1
- package/dist/commons/conditionals/conditionals.d.ts +4 -348
- package/dist/commons/conditionals/validate.d.ts +2 -51
- package/dist/commons/events/FieldConfig.d.ts +50 -377
- package/dist/commons/events/FieldValue.d.ts +0 -6
- package/dist/commons/events/field.d.ts +1 -47
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/conditionals/index.js +1 -48
- package/dist/events/index.js +77 -187
- package/dist/notification/index.js +34 -145
- package/opencrvs-toolkit-2.0.0-rc.0fb1707.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.0f51ec5.tgz +0 -0
|
@@ -917,7 +917,6 @@ var DateRangeFieldValue = z12.object({
|
|
|
917
917
|
var EmailValue = z12.email();
|
|
918
918
|
var CheckboxFieldValue = z12.boolean();
|
|
919
919
|
var NumberFieldValue = z12.number();
|
|
920
|
-
var SignatureFieldValue = FileFieldValue;
|
|
921
920
|
var ButtonFieldValue = z12.number();
|
|
922
921
|
var VerificationStatusValue = z12.enum([
|
|
923
922
|
"verified",
|
|
@@ -1666,18 +1665,8 @@ var FieldReference = import_v43.default.object({
|
|
|
1666
1665
|
$$field: FieldId.describe("Id of the field to reference"),
|
|
1667
1666
|
$$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
|
|
1668
1667
|
'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
|
|
1669
|
-
),
|
|
1670
|
-
$$code: import_v43.default.string().optional().describe(
|
|
1671
|
-
"Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
|
|
1672
|
-
)
|
|
1673
|
-
}).describe(
|
|
1674
|
-
"Reference to a field value, with an optional client-side computation applied."
|
|
1675
|
-
);
|
|
1676
|
-
var ComputedDefaultValue = import_v43.default.object({
|
|
1677
|
-
$$code: import_v43.default.string().describe(
|
|
1678
|
-
"Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
|
|
1679
1668
|
)
|
|
1680
|
-
}).describe("
|
|
1669
|
+
}).describe("Reference to a field by its ID");
|
|
1681
1670
|
var ValidationConfig = import_v43.default.object({
|
|
1682
1671
|
validator: Conditional.describe(
|
|
1683
1672
|
"Conditional expression that must hold for the field value to be considered valid."
|
|
@@ -1718,7 +1707,7 @@ var BaseField = import_v43.default.object({
|
|
|
1718
1707
|
"Indicates whether the field can be modified during record correction."
|
|
1719
1708
|
),
|
|
1720
1709
|
value: FieldReference.or(import_v43.default.array(FieldReference)).optional().describe(
|
|
1721
|
-
"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.
|
|
1710
|
+
"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."
|
|
1722
1711
|
),
|
|
1723
1712
|
analytics: import_v43.default.boolean().default(false).optional().describe(
|
|
1724
1713
|
"Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
|
|
@@ -1732,7 +1721,7 @@ var Divider = BaseField.extend({
|
|
|
1732
1721
|
});
|
|
1733
1722
|
var TextField = BaseField.extend({
|
|
1734
1723
|
type: import_v43.default.literal(FieldType.TEXT),
|
|
1735
|
-
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField
|
|
1724
|
+
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
1736
1725
|
configuration: import_v43.default.object({
|
|
1737
1726
|
maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
|
|
1738
1727
|
type: import_v43.default.enum(["text", "password"]).optional(),
|
|
@@ -1745,7 +1734,7 @@ var TextField = BaseField.extend({
|
|
|
1745
1734
|
});
|
|
1746
1735
|
var NumberField = BaseField.extend({
|
|
1747
1736
|
type: import_v43.default.literal(FieldType.NUMBER),
|
|
1748
|
-
defaultValue: NumberFieldValue.
|
|
1737
|
+
defaultValue: NumberFieldValue.optional(),
|
|
1749
1738
|
configuration: import_v43.default.object({
|
|
1750
1739
|
min: import_v43.default.number().optional().describe("Minimum value"),
|
|
1751
1740
|
max: import_v43.default.number().optional().describe("Maximum value"),
|
|
@@ -1758,7 +1747,7 @@ var NumberField = BaseField.extend({
|
|
|
1758
1747
|
});
|
|
1759
1748
|
var TextAreaField = BaseField.extend({
|
|
1760
1749
|
type: import_v43.default.literal(FieldType.TEXTAREA),
|
|
1761
|
-
defaultValue: NonEmptyTextValue.
|
|
1750
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
1762
1751
|
configuration: import_v43.default.object({
|
|
1763
1752
|
maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
|
|
1764
1753
|
rows: import_v43.default.number().optional().describe("Number of visible text lines"),
|
|
@@ -1792,7 +1781,7 @@ var SignatureField = BaseField.extend({
|
|
|
1792
1781
|
signaturePromptLabel: TranslationConfig.describe(
|
|
1793
1782
|
"Title of the signature modal"
|
|
1794
1783
|
),
|
|
1795
|
-
defaultValue:
|
|
1784
|
+
defaultValue: FieldValue.optional(),
|
|
1796
1785
|
configuration: import_v43.default.object({
|
|
1797
1786
|
maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
1798
1787
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
|
|
@@ -1808,14 +1797,14 @@ var EmailField = BaseField.extend({
|
|
|
1808
1797
|
configuration: import_v43.default.object({
|
|
1809
1798
|
maxLength: import_v43.default.number().optional().describe("Maximum length of the text")
|
|
1810
1799
|
}).default({ maxLength: 255 }).optional(),
|
|
1811
|
-
defaultValue: NonEmptyTextValue.
|
|
1800
|
+
defaultValue: NonEmptyTextValue.optional()
|
|
1812
1801
|
}).meta({
|
|
1813
1802
|
description: "An email input field",
|
|
1814
1803
|
id: "EmailField"
|
|
1815
1804
|
});
|
|
1816
1805
|
var DateField = BaseField.extend({
|
|
1817
1806
|
type: import_v43.default.literal(FieldType.DATE),
|
|
1818
|
-
defaultValue: SerializedNowDateTime.or(PlainDate).
|
|
1807
|
+
defaultValue: SerializedNowDateTime.or(PlainDate).optional().describe("Default date value(yyyy-MM-dd)"),
|
|
1819
1808
|
configuration: import_v43.default.object({
|
|
1820
1809
|
notice: TranslationConfig.describe(
|
|
1821
1810
|
"Text to display above the date input"
|
|
@@ -1827,7 +1816,7 @@ var DateField = BaseField.extend({
|
|
|
1827
1816
|
});
|
|
1828
1817
|
var AgeField = BaseField.extend({
|
|
1829
1818
|
type: import_v43.default.literal(FieldType.AGE),
|
|
1830
|
-
defaultValue: NumberFieldValue.
|
|
1819
|
+
defaultValue: NumberFieldValue.optional(),
|
|
1831
1820
|
configuration: import_v43.default.object({
|
|
1832
1821
|
asOfDate: FieldReference,
|
|
1833
1822
|
prefix: TranslationConfig.optional(),
|
|
@@ -1839,7 +1828,7 @@ var AgeField = BaseField.extend({
|
|
|
1839
1828
|
});
|
|
1840
1829
|
var TimeField = BaseField.extend({
|
|
1841
1830
|
type: import_v43.default.literal(FieldType.TIME),
|
|
1842
|
-
defaultValue: SerializedNowDateTime.or(TimeValue).
|
|
1831
|
+
defaultValue: SerializedNowDateTime.or(TimeValue).optional().describe("Default time value (HH-mm)"),
|
|
1843
1832
|
configuration: import_v43.default.object({
|
|
1844
1833
|
use12HourFormat: import_v43.default.boolean().optional().describe("Whether to use 12-hour format"),
|
|
1845
1834
|
notice: TranslationConfig.describe(
|
|
@@ -1852,7 +1841,7 @@ var TimeField = BaseField.extend({
|
|
|
1852
1841
|
});
|
|
1853
1842
|
var DateRangeField = BaseField.extend({
|
|
1854
1843
|
type: import_v43.default.literal(FieldType.DATE_RANGE),
|
|
1855
|
-
defaultValue: DateRangeFieldValue.
|
|
1844
|
+
defaultValue: DateRangeFieldValue.optional(),
|
|
1856
1845
|
configuration: import_v43.default.object({
|
|
1857
1846
|
notice: TranslationConfig.describe(
|
|
1858
1847
|
"Text to display above the date input"
|
|
@@ -1931,7 +1920,7 @@ var PageHeader = BaseField.extend({
|
|
|
1931
1920
|
});
|
|
1932
1921
|
var File = BaseField.extend({
|
|
1933
1922
|
type: import_v43.default.literal(FieldType.FILE),
|
|
1934
|
-
defaultValue: FileFieldValue.
|
|
1923
|
+
defaultValue: FileFieldValue.optional(),
|
|
1935
1924
|
configuration: import_v43.default.object({
|
|
1936
1925
|
maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
1937
1926
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
|
|
@@ -1958,7 +1947,7 @@ var SelectOption = import_v43.default.object({
|
|
|
1958
1947
|
});
|
|
1959
1948
|
var NumberWithUnitField = BaseField.extend({
|
|
1960
1949
|
type: import_v43.default.literal(FieldType.NUMBER_WITH_UNIT),
|
|
1961
|
-
defaultValue: NumberWithUnitFieldValue.
|
|
1950
|
+
defaultValue: NumberWithUnitFieldValue.optional(),
|
|
1962
1951
|
options: import_v43.default.array(SelectOption).describe("A list of options for the unit select"),
|
|
1963
1952
|
configuration: import_v43.default.object({
|
|
1964
1953
|
min: import_v43.default.number().optional().describe("Minimum value of the number field"),
|
|
@@ -1973,7 +1962,7 @@ var NumberWithUnitField = BaseField.extend({
|
|
|
1973
1962
|
});
|
|
1974
1963
|
var RadioGroup = BaseField.extend({
|
|
1975
1964
|
type: import_v43.default.literal(FieldType.RADIO_GROUP),
|
|
1976
|
-
defaultValue: TextValue.
|
|
1965
|
+
defaultValue: TextValue.optional(),
|
|
1977
1966
|
options: import_v43.default.array(SelectOption).describe("A list of options"),
|
|
1978
1967
|
configuration: import_v43.default.object({
|
|
1979
1968
|
styles: import_v43.default.object({
|
|
@@ -1998,7 +1987,7 @@ var BulletList = BaseField.extend({
|
|
|
1998
1987
|
});
|
|
1999
1988
|
var Select = BaseField.extend({
|
|
2000
1989
|
type: import_v43.default.literal(FieldType.SELECT),
|
|
2001
|
-
defaultValue: TextValue.
|
|
1990
|
+
defaultValue: TextValue.optional(),
|
|
2002
1991
|
options: import_v43.default.array(SelectOption).describe("A list of options"),
|
|
2003
1992
|
noOptionsMessage: TranslationConfig.optional().describe(
|
|
2004
1993
|
`
|
|
@@ -2020,7 +2009,7 @@ var SelectDateRangeOption = import_v43.default.object({
|
|
|
2020
2009
|
});
|
|
2021
2010
|
var SelectDateRangeField = BaseField.extend({
|
|
2022
2011
|
type: import_v43.default.literal(FieldType.SELECT_DATE_RANGE),
|
|
2023
|
-
defaultValue: SelectDateRangeValue.
|
|
2012
|
+
defaultValue: SelectDateRangeValue.optional(),
|
|
2024
2013
|
options: import_v43.default.array(SelectDateRangeOption).describe("A list of options")
|
|
2025
2014
|
}).meta({
|
|
2026
2015
|
description: "A date range selection field",
|
|
@@ -2037,7 +2026,7 @@ var NameField = BaseField.extend({
|
|
|
2037
2026
|
firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2038
2027
|
middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2039
2028
|
surname: SerializedUserField.or(NonEmptyTextValue).optional()
|
|
2040
|
-
}).
|
|
2029
|
+
}).optional(),
|
|
2041
2030
|
configuration: import_v43.default.object({
|
|
2042
2031
|
name: NameConfig.default({
|
|
2043
2032
|
firstname: { required: true },
|
|
@@ -2061,14 +2050,14 @@ var NameField = BaseField.extend({
|
|
|
2061
2050
|
id: "NameField"
|
|
2062
2051
|
});
|
|
2063
2052
|
var PhoneField = BaseField.extend({
|
|
2064
|
-
defaultValue: NonEmptyTextValue.
|
|
2053
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
2065
2054
|
type: import_v43.default.literal(FieldType.PHONE)
|
|
2066
2055
|
}).meta({
|
|
2067
2056
|
description: "A field for entering a phone number",
|
|
2068
2057
|
id: "PhoneField"
|
|
2069
2058
|
});
|
|
2070
2059
|
var IdField = BaseField.extend({
|
|
2071
|
-
defaultValue: NonEmptyTextValue.
|
|
2060
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
2072
2061
|
type: import_v43.default.literal(FieldType.ID)
|
|
2073
2062
|
}).meta({
|
|
2074
2063
|
description: "A field for entering an ID",
|
|
@@ -2076,14 +2065,14 @@ var IdField = BaseField.extend({
|
|
|
2076
2065
|
});
|
|
2077
2066
|
var Checkbox = BaseField.extend({
|
|
2078
2067
|
type: import_v43.default.literal(FieldType.CHECKBOX),
|
|
2079
|
-
defaultValue: CheckboxFieldValue.
|
|
2068
|
+
defaultValue: CheckboxFieldValue.default(false)
|
|
2080
2069
|
}).meta({
|
|
2081
2070
|
description: "A boolean checkbox field",
|
|
2082
2071
|
id: "Checkbox"
|
|
2083
2072
|
});
|
|
2084
2073
|
var Country = BaseField.extend({
|
|
2085
2074
|
type: import_v43.default.literal(FieldType.COUNTRY),
|
|
2086
|
-
defaultValue: NonEmptyTextValue.
|
|
2075
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
2087
2076
|
optionOverrides: import_v43.default.array(SelectOption.omit({ label: true })).optional().describe(
|
|
2088
2077
|
"Conditionals for specific countries. Countries not listed are always shown and enabled."
|
|
2089
2078
|
)
|
|
@@ -2101,7 +2090,7 @@ var AdministrativeAreas = import_v43.default.enum([
|
|
|
2101
2090
|
]);
|
|
2102
2091
|
var AdministrativeAreaField = BaseField.extend({
|
|
2103
2092
|
type: import_v43.default.literal(FieldType.ADMINISTRATIVE_AREA),
|
|
2104
|
-
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField
|
|
2093
|
+
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
2105
2094
|
configuration: import_v43.default.object({
|
|
2106
2095
|
partOf: FieldReference.optional().describe("Parent location"),
|
|
2107
2096
|
type: AdministrativeAreas,
|
|
@@ -2113,7 +2102,7 @@ var AdministrativeAreaField = BaseField.extend({
|
|
|
2113
2102
|
});
|
|
2114
2103
|
var LocationInput = BaseField.extend({
|
|
2115
2104
|
type: import_v43.default.literal(FieldType.LOCATION),
|
|
2116
|
-
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField
|
|
2105
|
+
defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
2117
2106
|
configuration: import_v43.default.object({
|
|
2118
2107
|
locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
|
|
2119
2108
|
allowedLocations: AllowedLocations
|
|
@@ -2125,7 +2114,7 @@ var LocationInput = BaseField.extend({
|
|
|
2125
2114
|
var FileUploadWithOptions = BaseField.extend({
|
|
2126
2115
|
type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
|
|
2127
2116
|
options: import_v43.default.array(SelectOption).describe("A list of options"),
|
|
2128
|
-
defaultValue: FileFieldWithOptionValue.
|
|
2117
|
+
defaultValue: FileFieldWithOptionValue.optional(),
|
|
2129
2118
|
configuration: import_v43.default.object({
|
|
2130
2119
|
maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2131
2120
|
maxImageSize: import_v43.default.object({
|
|
@@ -2141,12 +2130,12 @@ var FileUploadWithOptions = BaseField.extend({
|
|
|
2141
2130
|
});
|
|
2142
2131
|
var Facility = BaseField.extend({
|
|
2143
2132
|
type: import_v43.default.literal(FieldType.FACILITY),
|
|
2144
|
-
defaultValue: NonEmptyTextValue.
|
|
2133
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
2145
2134
|
configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
|
|
2146
2135
|
}).describe("Input field for a facility");
|
|
2147
2136
|
var Office = BaseField.extend({
|
|
2148
2137
|
type: import_v43.default.literal(FieldType.OFFICE),
|
|
2149
|
-
defaultValue: NonEmptyTextValue.
|
|
2138
|
+
defaultValue: NonEmptyTextValue.optional(),
|
|
2150
2139
|
configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
|
|
2151
2140
|
}).describe("Input field for an office");
|
|
2152
2141
|
var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
|
|
@@ -2182,7 +2171,7 @@ var Address = BaseField.extend({
|
|
|
2182
2171
|
).optional(),
|
|
2183
2172
|
allowedLocations: AllowedLocations
|
|
2184
2173
|
}).optional(),
|
|
2185
|
-
defaultValue: DefaultAddressFieldValue.
|
|
2174
|
+
defaultValue: DefaultAddressFieldValue.optional()
|
|
2186
2175
|
}).meta({
|
|
2187
2176
|
description: "Address input field \u2013 a combination of location and text fields",
|
|
2188
2177
|
id: "Address"
|
|
@@ -2229,7 +2218,7 @@ var ButtonConfiguration = import_v43.default.object({
|
|
|
2229
2218
|
});
|
|
2230
2219
|
var ButtonField = BaseField.extend({
|
|
2231
2220
|
type: import_v43.default.literal(FieldType.BUTTON),
|
|
2232
|
-
defaultValue: ButtonFieldValue.
|
|
2221
|
+
defaultValue: ButtonFieldValue.optional(),
|
|
2233
2222
|
configuration: ButtonConfiguration
|
|
2234
2223
|
}).meta({
|
|
2235
2224
|
description: "A generic button that can be used to trigger an action",
|
|
@@ -2257,7 +2246,7 @@ var AlphaPrintButton = BaseField.extend({
|
|
|
2257
2246
|
});
|
|
2258
2247
|
var HttpField = BaseField.extend({
|
|
2259
2248
|
type: import_v43.default.literal(FieldType.HTTP),
|
|
2260
|
-
defaultValue: HttpFieldValue.
|
|
2249
|
+
defaultValue: HttpFieldValue.optional(),
|
|
2261
2250
|
configuration: import_v43.default.object({
|
|
2262
2251
|
trigger: FieldReference.optional().describe(
|
|
2263
2252
|
"Reference to the field that triggers the HTTP request when its value changes. If not provided, the HTTP request is triggered once on component mount."
|
|
@@ -2343,7 +2332,7 @@ var LinkButtonField = BaseField.extend({
|
|
|
2343
2332
|
});
|
|
2344
2333
|
var VerificationStatus = BaseField.extend({
|
|
2345
2334
|
type: import_v43.default.literal(FieldType.VERIFICATION_STATUS),
|
|
2346
|
-
defaultValue: VerificationStatusValue.
|
|
2335
|
+
defaultValue: VerificationStatusValue.optional(),
|
|
2347
2336
|
configuration: import_v43.default.object({
|
|
2348
2337
|
status: TranslationConfig.describe("Text to display on the status pill."),
|
|
2349
2338
|
description: TranslationConfig.describe(
|
|
@@ -2365,7 +2354,7 @@ var QueryParamReaderField = BaseField.extend({
|
|
|
2365
2354
|
});
|
|
2366
2355
|
var QrReaderField = BaseField.extend({
|
|
2367
2356
|
type: import_v43.default.literal(FieldType.QR_READER),
|
|
2368
|
-
defaultValue: QrReaderFieldValue.
|
|
2357
|
+
defaultValue: QrReaderFieldValue.optional(),
|
|
2369
2358
|
configuration: import_v43.default.object({
|
|
2370
2359
|
validator: import_v43.default.any().meta({
|
|
2371
2360
|
description: "JSON Schema to validate the scanned QR code data against before populating the form fields.",
|
|
@@ -2378,7 +2367,7 @@ var QrReaderField = BaseField.extend({
|
|
|
2378
2367
|
});
|
|
2379
2368
|
var IdReaderField = BaseField.extend({
|
|
2380
2369
|
type: import_v43.default.literal(FieldType.ID_READER),
|
|
2381
|
-
defaultValue: IdReaderFieldValue.
|
|
2370
|
+
defaultValue: IdReaderFieldValue.optional(),
|
|
2382
2371
|
methods: import_v43.default.array(
|
|
2383
2372
|
import_v43.default.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
|
|
2384
2373
|
)
|
|
@@ -3043,37 +3032,7 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
3043
3032
|
}
|
|
3044
3033
|
return current;
|
|
3045
3034
|
}
|
|
3046
|
-
function todayISO() {
|
|
3047
|
-
return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
|
|
3048
|
-
}
|
|
3049
|
-
var compiledFunctionCache = /* @__PURE__ */ new Map();
|
|
3050
|
-
function compileClientFunction(code) {
|
|
3051
|
-
let fn = compiledFunctionCache.get(code);
|
|
3052
|
-
if (!fn) {
|
|
3053
|
-
fn = new Function(`return (${code})`)();
|
|
3054
|
-
compiledFunctionCache.set(code, fn);
|
|
3055
|
-
}
|
|
3056
|
-
return fn;
|
|
3057
|
-
}
|
|
3058
3035
|
(0, import_ajv_formats.default)(ajv);
|
|
3059
|
-
function buildClientFunctionContext(input) {
|
|
3060
|
-
return {
|
|
3061
|
-
$form: input.form,
|
|
3062
|
-
$now: todayISO(),
|
|
3063
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
3064
|
-
$online: isOnline(),
|
|
3065
|
-
$user: input.validatorContext?.user,
|
|
3066
|
-
$event: input.validatorContext?.event,
|
|
3067
|
-
$leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
|
|
3068
|
-
user: input.systemVariables?.user,
|
|
3069
|
-
$window: input.systemVariables?.$window,
|
|
3070
|
-
locations: input.locations,
|
|
3071
|
-
adminLevelIds: input.adminLevelIds
|
|
3072
|
-
};
|
|
3073
|
-
}
|
|
3074
|
-
function runClientFunction(code, data, context) {
|
|
3075
|
-
return compileClientFunction(code)(data, context);
|
|
3076
|
-
}
|
|
3077
3036
|
ajv.addKeyword({
|
|
3078
3037
|
keyword: "daysFromDate",
|
|
3079
3038
|
type: "string",
|
|
@@ -3118,35 +3077,12 @@ ajv.addKeyword({
|
|
|
3118
3077
|
$data: true,
|
|
3119
3078
|
errors: true,
|
|
3120
3079
|
// @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
|
|
3121
|
-
validate(
|
|
3080
|
+
validate(schema, data, _2, dataContext) {
|
|
3122
3081
|
const locationIdInput = data;
|
|
3123
3082
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
3124
3083
|
return locations.some((location) => location.id === locationIdInput);
|
|
3125
3084
|
}
|
|
3126
3085
|
});
|
|
3127
|
-
ajv.addKeyword({
|
|
3128
|
-
keyword: "customClientValidator",
|
|
3129
|
-
schemaType: "object",
|
|
3130
|
-
errors: true,
|
|
3131
|
-
// @ts-expect-error -- AJV's public types don't expose `rootData`. All
|
|
3132
|
-
// `validate()` callers build root data via `buildClientFunctionContext`,
|
|
3133
|
-
// so the cast holds.
|
|
3134
|
-
validate(schema, data, _2, dataContext) {
|
|
3135
|
-
return Boolean(
|
|
3136
|
-
runClientFunction(
|
|
3137
|
-
schema.code,
|
|
3138
|
-
data,
|
|
3139
|
-
dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
|
|
3140
|
-
)
|
|
3141
|
-
);
|
|
3142
|
-
}
|
|
3143
|
-
});
|
|
3144
|
-
function isOnline() {
|
|
3145
|
-
if (typeof window !== "undefined" && typeof navigator !== "undefined") {
|
|
3146
|
-
return navigator.onLine;
|
|
3147
|
-
}
|
|
3148
|
-
return true;
|
|
3149
|
-
}
|
|
3150
3086
|
|
|
3151
3087
|
// ../commons/src/utils.ts
|
|
3152
3088
|
var z32 = __toESM(require("zod/v4"));
|
|
@@ -3765,54 +3701,7 @@ function createFieldConditionals(fieldId) {
|
|
|
3765
3701
|
}
|
|
3766
3702
|
},
|
|
3767
3703
|
required: [fieldId]
|
|
3768
|
-
})
|
|
3769
|
-
/**
|
|
3770
|
-
* Custom client-side validator. The provided function is serialised and executed
|
|
3771
|
-
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
3772
|
-
* available inside the function body — all logic must be self-contained.
|
|
3773
|
-
*
|
|
3774
|
-
* @example
|
|
3775
|
-
* field('nid').customClientValidator((value) => {
|
|
3776
|
-
* // LUHN check — all logic must be inline
|
|
3777
|
-
* const digits = String(value).split('').map(Number)
|
|
3778
|
-
* // ...
|
|
3779
|
-
* return isValid
|
|
3780
|
-
* })
|
|
3781
|
-
*/
|
|
3782
|
-
customClientValidator(validationFn) {
|
|
3783
|
-
const code = validationFn.toString();
|
|
3784
|
-
return defineFormConditional({
|
|
3785
|
-
type: "object",
|
|
3786
|
-
properties: wrapToPath(
|
|
3787
|
-
{ [fieldId]: { customClientValidator: { code } } },
|
|
3788
|
-
this.$$subfield
|
|
3789
|
-
),
|
|
3790
|
-
required: [fieldId]
|
|
3791
|
-
});
|
|
3792
|
-
},
|
|
3793
|
-
/**
|
|
3794
|
-
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
3795
|
-
* that can be used as the `value` property or a DATA component entry.
|
|
3796
|
-
* The function receives the referenced field's value as the first argument and
|
|
3797
|
-
* the full form context as the second; its return value replaces the field reference.
|
|
3798
|
-
* The function is serialised and executed just-in-time on the client only.
|
|
3799
|
-
* External references (e.g. lodash) are not available inside the function body.
|
|
3800
|
-
*
|
|
3801
|
-
* For computing a default value without referencing a specific field, use
|
|
3802
|
-
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
3803
|
-
*
|
|
3804
|
-
* @example
|
|
3805
|
-
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
3806
|
-
* Number(aValue) + Number(ctx.$form.b)
|
|
3807
|
-
* )
|
|
3808
|
-
*/
|
|
3809
|
-
customClientEvaluation(computationFn) {
|
|
3810
|
-
return {
|
|
3811
|
-
$$code: computationFn.toString(),
|
|
3812
|
-
$$field: fieldId,
|
|
3813
|
-
$$subfield: this.$$subfield
|
|
3814
|
-
};
|
|
3815
|
-
}
|
|
3704
|
+
})
|
|
3816
3705
|
};
|
|
3817
3706
|
}
|
|
3818
3707
|
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|