@atscript/ui 0.1.157 → 0.1.158

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 CHANGED
@@ -1786,6 +1786,97 @@ function deepClone(value, unwrap) {
1786
1786
  return out;
1787
1787
  }
1788
1788
  //#endregion
1789
+ //#region src/form/error-utils.ts
1790
+ /**
1791
+ * Framework-agnostic helpers for working with form-error maps keyed by
1792
+ * dotted path. Used by AsForm to drive error badges and auto-open
1793
+ * collapsed sections; safe to share with React (or any other) bindings.
1794
+ *
1795
+ * Convention:
1796
+ * - Keys are dotted paths (`a.b.c`); empty string and `__form` denote
1797
+ * the form-level error.
1798
+ * - Values may be `string | undefined`; falsy entries are dropped on
1799
+ * merge.
1800
+ */
1801
+ /** Error-map key of the form-level error. */
1802
+ const FORM_ERROR_KEY = "__form";
1803
+ /**
1804
+ * Turn a validator's error list into an error map keyed by path. A
1805
+ * root-level error (empty path) becomes the form-level error
1806
+ * ({@link FORM_ERROR_KEY}). The first error per path wins: a failing
1807
+ * container rule is reported before the container's own shape / length
1808
+ * checks at the same path.
1809
+ */
1810
+ function validatorErrorsToMap(errors) {
1811
+ const out = {};
1812
+ for (const err of errors) out[err.path || "__form"] ??= err.message;
1813
+ return out;
1814
+ }
1815
+ /**
1816
+ * Merge any number of partial error maps into a single dense
1817
+ * `Record<path, message>`. Falsy values are skipped — later sources do
1818
+ * NOT overwrite earlier ones with an empty value.
1819
+ */
1820
+ function mergeErrorMaps(...maps) {
1821
+ const merged = {};
1822
+ for (const m of maps) {
1823
+ if (!m) continue;
1824
+ for (const k of Object.keys(m)) {
1825
+ const v = m[k];
1826
+ if (v) merged[k] = v;
1827
+ }
1828
+ }
1829
+ return merged;
1830
+ }
1831
+ /**
1832
+ * Return `errors` without the entries whose key is in `paths`.
1833
+ *
1834
+ * Identity-preserving: when no key matches, the ORIGINAL `errors` object
1835
+ * is returned unchanged — callers compare `result !== errors` to detect
1836
+ * that something was pruned and skip spurious reactive writes.
1837
+ */
1838
+ function omitPaths(errors, paths) {
1839
+ let pruned = null;
1840
+ for (const key in errors) if (paths.has(key)) {
1841
+ pruned ??= { ...errors };
1842
+ delete pruned[key];
1843
+ }
1844
+ return pruned ?? errors;
1845
+ }
1846
+ /**
1847
+ * Yield every ancestor prefix of a dotted path, longest-first
1848
+ * (`a.b.c` → `a.b.c`, `a.b`, `a`). Returns the path itself first so
1849
+ * callers can include it in the iteration without a special case.
1850
+ *
1851
+ * Empty paths and the form-level key (`__form`) yield nothing.
1852
+ */
1853
+ function* iteratePathAncestors(path) {
1854
+ if (!path || path === "__form") return;
1855
+ let pos = path.length;
1856
+ while (pos > 0) {
1857
+ yield path.slice(0, pos);
1858
+ const dot = path.lastIndexOf(".", pos - 1);
1859
+ if (dot < 0) return;
1860
+ pos = dot;
1861
+ }
1862
+ }
1863
+ /**
1864
+ * Build an indexed `Map<absolutePath, descendantErrorCount>` so each
1865
+ * struct in the tree can render an error-count badge in O(1).
1866
+ *
1867
+ * For every error path, the count is incremented on the path itself
1868
+ * AND every dotted-path ancestor — so a struct at `a.b` reports the
1869
+ * total of all errors at `a.b` or below.
1870
+ */
1871
+ function buildDescendantErrorCounts(errors) {
1872
+ const map = /* @__PURE__ */ new Map();
1873
+ for (const errPath of Object.keys(errors)) {
1874
+ if (!errors[errPath]) continue;
1875
+ for (const prefix of iteratePathAncestors(errPath)) map.set(prefix, (map.get(prefix) ?? 0) + 1);
1876
+ }
1877
+ return map;
1878
+ }
1879
+ //#endregion
1789
1880
  //#region src/form/validate.ts
1790
1881
  const dbPlugin = (0, _atscript_db_validator.createDbValidatorPlugin)();
1791
1882
  const INSERT_CONTEXT = { mode: "insert" };
@@ -1854,6 +1945,9 @@ function getDefaultValidatorPlugins() {
1854
1945
  * ATScript's @expect.* validation runs automatically; server-managed db
1855
1946
  * fields (every `derived` field, absent `@db.default*` / version) pass.
1856
1947
  * For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
1948
+ *
1949
+ * Errors are keyed by dotted path. A root-level error (a failing
1950
+ * `@ui.form.validate` on the form's interface) is keyed `__form`.
1857
1951
  */
1858
1952
  function getFormValidator(def, opts) {
1859
1953
  const derived = collectDerivedProps(def);
@@ -1873,9 +1967,7 @@ function getFormValidator(def, opts) {
1873
1967
  data: callOpts.data,
1874
1968
  context: callOpts.context ?? {}
1875
1969
  })) return {};
1876
- const errors = {};
1877
- for (const err of validator.errors) errors[err.path] = err.message;
1878
- return errors;
1970
+ return validatorErrorsToMap(validator.errors);
1879
1971
  };
1880
1972
  }
1881
1973
  /**
@@ -1887,8 +1979,12 @@ function getFormValidator(def, opts) {
1887
1979
  * a branch's verdict depends on its children — those keep the full walk.
1888
1980
  */
1889
1981
  const skipDescendantsPlugin = (ctx) => ctx.path === "" ? void 0 : true;
1890
- function skipsDescendants(prop) {
1891
- const kind = prop.type.kind;
1982
+ /**
1983
+ * Whether a type kind is a container that carries its own children:
1984
+ * `object`, `array` or `tuple`. Union / intersection kinds are not
1985
+ * containers — they evaluate their branches at their own path.
1986
+ */
1987
+ function isContainerKind(kind) {
1892
1988
  return kind === "object" || kind === "array" || kind === "tuple";
1893
1989
  }
1894
1990
  /**
@@ -1902,7 +1998,7 @@ function skipsDescendants(prop) {
1902
1998
  function createFieldValidator(prop, opts) {
1903
1999
  let cached;
1904
2000
  return (value, externalCtx) => {
1905
- cached ??= new _atscript_typescript_utils.Validator(prop, { plugins: opts?.rootOnly && skipsDescendants(prop) ? [
2001
+ cached ??= new _atscript_typescript_utils.Validator(prop, { plugins: opts?.rootOnly && isContainerKind(prop.type.kind) ? [
1906
2002
  skipDescendantsPlugin,
1907
2003
  serverManagedPlugin,
1908
2004
  ...defaultValidatorPlugins
@@ -2565,84 +2661,6 @@ function walkUnionFields(fields, prefix, before, after) {
2565
2661
  return false;
2566
2662
  }
2567
2663
  //#endregion
2568
- //#region src/form/error-utils.ts
2569
- /**
2570
- * Framework-agnostic helpers for working with form-error maps keyed by
2571
- * dotted path. Used by AsForm to drive error badges and auto-open
2572
- * collapsed sections; safe to share with React (or any other) bindings.
2573
- *
2574
- * Convention:
2575
- * - Keys are dotted paths (`a.b.c`); empty string and `__form` denote
2576
- * the form-level error.
2577
- * - Values may be `string | undefined`; falsy entries are dropped on
2578
- * merge.
2579
- */
2580
- const FORM_ERROR_KEY = "__form";
2581
- /**
2582
- * Merge any number of partial error maps into a single dense
2583
- * `Record<path, message>`. Falsy values are skipped — later sources do
2584
- * NOT overwrite earlier ones with an empty value.
2585
- */
2586
- function mergeErrorMaps(...maps) {
2587
- const merged = {};
2588
- for (const m of maps) {
2589
- if (!m) continue;
2590
- for (const k of Object.keys(m)) {
2591
- const v = m[k];
2592
- if (v) merged[k] = v;
2593
- }
2594
- }
2595
- return merged;
2596
- }
2597
- /**
2598
- * Return `errors` without the entries whose key is in `paths`.
2599
- *
2600
- * Identity-preserving: when no key matches, the ORIGINAL `errors` object
2601
- * is returned unchanged — callers compare `result !== errors` to detect
2602
- * that something was pruned and skip spurious reactive writes.
2603
- */
2604
- function omitPaths(errors, paths) {
2605
- let pruned = null;
2606
- for (const key in errors) if (paths.has(key)) {
2607
- pruned ??= { ...errors };
2608
- delete pruned[key];
2609
- }
2610
- return pruned ?? errors;
2611
- }
2612
- /**
2613
- * Yield every ancestor prefix of a dotted path, longest-first
2614
- * (`a.b.c` → `a.b.c`, `a.b`, `a`). Returns the path itself first so
2615
- * callers can include it in the iteration without a special case.
2616
- *
2617
- * Empty paths and the form-level key (`__form`) yield nothing.
2618
- */
2619
- function* iteratePathAncestors(path) {
2620
- if (!path || path === FORM_ERROR_KEY) return;
2621
- let pos = path.length;
2622
- while (pos > 0) {
2623
- yield path.slice(0, pos);
2624
- const dot = path.lastIndexOf(".", pos - 1);
2625
- if (dot < 0) return;
2626
- pos = dot;
2627
- }
2628
- }
2629
- /**
2630
- * Build an indexed `Map<absolutePath, descendantErrorCount>` so each
2631
- * struct in the tree can render an error-count badge in O(1).
2632
- *
2633
- * For every error path, the count is incremented on the path itself
2634
- * AND every dotted-path ancestor — so a struct at `a.b` reports the
2635
- * total of all errors at `a.b` or below.
2636
- */
2637
- function buildDescendantErrorCounts(errors) {
2638
- const map = /* @__PURE__ */ new Map();
2639
- for (const errPath of Object.keys(errors)) {
2640
- if (!errors[errPath]) continue;
2641
- for (const prefix of iteratePathAncestors(errPath)) map.set(prefix, (map.get(prefix) ?? 0) + 1);
2642
- }
2643
- return map;
2644
- }
2645
- //#endregion
2646
2664
  //#region src/form/grid.ts
2647
2665
  /** Grid layout parsing for `@ui.form.grid.colSpan` / `@ui.form.grid.rowSpan`. */
2648
2666
  const DEFAULT_COL_SPAN = 12;
@@ -3167,6 +3185,7 @@ exports.DB_UNIT_REF = DB_UNIT_REF;
3167
3185
  exports.DEFAULT_COL_SPAN = DEFAULT_COL_SPAN;
3168
3186
  exports.DEFAULT_ROW_SPAN = DEFAULT_ROW_SPAN;
3169
3187
  exports.EXPECT_MAX_LENGTH = EXPECT_MAX_LENGTH;
3188
+ exports.FORM_ERROR_KEY = FORM_ERROR_KEY;
3170
3189
  exports.META_DEFAULT = META_DEFAULT;
3171
3190
  exports.META_DESCRIPTION = META_DESCRIPTION;
3172
3191
  exports.META_ID = META_ID;
@@ -3290,6 +3309,7 @@ exports.hasComputedAnnotations = hasComputedAnnotations;
3290
3309
  exports.hasFieldMeta = hasFieldMeta;
3291
3310
  exports.invalidateValueHelpCache = invalidateValueHelpCache;
3292
3311
  exports.isArrayField = isArrayField;
3312
+ exports.isContainerKind = isContainerKind;
3293
3313
  exports.isFieldHidden = isFieldHidden;
3294
3314
  exports.isObjectField = isObjectField;
3295
3315
  exports.isPathDirty = isPathDirty;
@@ -3335,4 +3355,5 @@ exports.setValueHelpCacheTtl = setValueHelpCacheTtl;
3335
3355
  exports.splitDecimalString = splitDecimalString;
3336
3356
  exports.str = str;
3337
3357
  exports.unionVariantChanged = unionVariantChanged;
3358
+ exports.validatorErrorsToMap = validatorErrorsToMap;
3338
3359
  exports.valueHelpDictPaths = valueHelpDictPaths;
package/dist/index.d.cts CHANGED
@@ -693,6 +693,9 @@ declare function getDefaultValidatorPlugins(): TValidatorPlugin[];
693
693
  * ATScript's @expect.* validation runs automatically; server-managed db
694
694
  * fields (every `derived` field, absent `@db.default*` / version) pass.
695
695
  * For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
696
+ *
697
+ * Errors are keyed by dotted path. A root-level error (a failing
698
+ * `@ui.form.validate` on the form's interface) is keyed `__form`.
696
699
  */
697
700
  declare function getFormValidator(def: FormDef, opts?: Partial<TValidatorOptions>): (callOpts: TFormValidatorCallOptions) => Record<string, string>;
698
701
  /** Options for createFieldValidator. */
@@ -700,6 +703,12 @@ interface TFieldValidatorOptions {
700
703
  /** Only report errors at the root path (for structure/array container validation). */
701
704
  rootOnly?: boolean;
702
705
  }
706
+ /**
707
+ * Whether a type kind is a container that carries its own children:
708
+ * `object`, `array` or `tuple`. Union / intersection kinds are not
709
+ * containers — they evaluate their branches at their own path.
710
+ */
711
+ declare function isContainerKind(kind: string): boolean;
703
712
  /**
704
713
  * Creates a cached validator function for a single ATScript prop.
705
714
  *
@@ -954,6 +963,19 @@ declare function unionVariantChanged(def: FormDef, before: Record<string, unknow
954
963
  * - Values may be `string | undefined`; falsy entries are dropped on
955
964
  * merge.
956
965
  */
966
+ /** Error-map key of the form-level error. */
967
+ declare const FORM_ERROR_KEY = "__form";
968
+ /**
969
+ * Turn a validator's error list into an error map keyed by path. A
970
+ * root-level error (empty path) becomes the form-level error
971
+ * ({@link FORM_ERROR_KEY}). The first error per path wins: a failing
972
+ * container rule is reported before the container's own shape / length
973
+ * checks at the same path.
974
+ */
975
+ declare function validatorErrorsToMap(errors: ReadonlyArray<{
976
+ path: string;
977
+ message: string;
978
+ }>): Record<string, string>;
957
979
  /**
958
980
  * Merge any number of partial error maps into a single dense
959
981
  * `Record<path, message>`. Falsy values are skipped — later sources do
@@ -1665,4 +1687,4 @@ interface TModelRoute {
1665
1687
  */
1666
1688
  declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
1667
1689
  //#endregion
1668
- export { type ClientFactory, type ClientFactoryOptions, type CloneUnwrap, type ColumnDef, type ColumnValueKind, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaEntryOptions, type MetaResponse, NUMERIC_VALUE_KINDS, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
1690
+ export { type ClientFactory, type ClientFactoryOptions, type CloneUnwrap, type ColumnDef, type ColumnValueKind, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, FORM_ERROR_KEY, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaEntryOptions, type MetaResponse, NUMERIC_VALUE_KINDS, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isContainerKind, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, validatorErrorsToMap, valueHelpDictPaths };
package/dist/index.d.mts CHANGED
@@ -693,6 +693,9 @@ declare function getDefaultValidatorPlugins(): TValidatorPlugin[];
693
693
  * ATScript's @expect.* validation runs automatically; server-managed db
694
694
  * fields (every `derived` field, absent `@db.default*` / version) pass.
695
695
  * For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
696
+ *
697
+ * Errors are keyed by dotted path. A root-level error (a failing
698
+ * `@ui.form.validate` on the form's interface) is keyed `__form`.
696
699
  */
697
700
  declare function getFormValidator(def: FormDef, opts?: Partial<TValidatorOptions>): (callOpts: TFormValidatorCallOptions) => Record<string, string>;
698
701
  /** Options for createFieldValidator. */
@@ -700,6 +703,12 @@ interface TFieldValidatorOptions {
700
703
  /** Only report errors at the root path (for structure/array container validation). */
701
704
  rootOnly?: boolean;
702
705
  }
706
+ /**
707
+ * Whether a type kind is a container that carries its own children:
708
+ * `object`, `array` or `tuple`. Union / intersection kinds are not
709
+ * containers — they evaluate their branches at their own path.
710
+ */
711
+ declare function isContainerKind(kind: string): boolean;
703
712
  /**
704
713
  * Creates a cached validator function for a single ATScript prop.
705
714
  *
@@ -954,6 +963,19 @@ declare function unionVariantChanged(def: FormDef, before: Record<string, unknow
954
963
  * - Values may be `string | undefined`; falsy entries are dropped on
955
964
  * merge.
956
965
  */
966
+ /** Error-map key of the form-level error. */
967
+ declare const FORM_ERROR_KEY = "__form";
968
+ /**
969
+ * Turn a validator's error list into an error map keyed by path. A
970
+ * root-level error (empty path) becomes the form-level error
971
+ * ({@link FORM_ERROR_KEY}). The first error per path wins: a failing
972
+ * container rule is reported before the container's own shape / length
973
+ * checks at the same path.
974
+ */
975
+ declare function validatorErrorsToMap(errors: ReadonlyArray<{
976
+ path: string;
977
+ message: string;
978
+ }>): Record<string, string>;
957
979
  /**
958
980
  * Merge any number of partial error maps into a single dense
959
981
  * `Record<path, message>`. Falsy values are skipped — later sources do
@@ -1665,4 +1687,4 @@ interface TModelRoute {
1665
1687
  */
1666
1688
  declare function buildModelRoutes(models: readonly TAtscriptAnnotatedType[]): TModelRoute[];
1667
1689
  //#endregion
1668
- export { type ClientFactory, type ClientFactoryOptions, type CloneUnwrap, type ColumnDef, type ColumnValueKind, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaEntryOptions, type MetaResponse, NUMERIC_VALUE_KINDS, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
1690
+ export { type ClientFactory, type ClientFactoryOptions, type CloneUnwrap, type ColumnDef, type ColumnValueKind, type CreateFormDefOptions, type CurrencyDisplay, DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, type DecimalParts, EXPECT_MAX_LENGTH, FORM_ERROR_KEY, type FieldMeta, type FieldResolver, type FormActionInfo, type FormArrayFieldDef, type FormDef, type FormDiffOptions, type FormDiffResult, type FormFieldChange, type FormFieldDef, type FormObjectFieldDef, type FormRebaseOptions, type FormRebaseResult, type FormTupleFieldDef, type FormUnionFieldDef, type FormUnionVariant, type FormatDecimalOptions, type GridSpanArgs, type GridSpec, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, type MeasurementInfo, type MetaCacheEntry, type MetaEntryOptions, type MetaResponse, NUMERIC_VALUE_KINDS, type PaginationControl, type RelationInfo, type ResolvedValueHelp, type SearchIndexInfo, type SortControl, StaticFieldResolver, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TFieldValidatorOptions, type TFormAction, type TFormEntryOptions, type TFormValidatorCallOptions, type TFormValueResolver, type TModelRoute, type TResolveOptions, type TableActionsModel, type TableDef, type TableQueryState, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, type ValueHelpInfo, type ValueHelpResult, type ValueHelpSearchOptions, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isContainerKind, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, validatorErrorsToMap, valueHelpDictPaths };
package/dist/index.mjs CHANGED
@@ -1785,6 +1785,97 @@ function deepClone(value, unwrap) {
1785
1785
  return out;
1786
1786
  }
1787
1787
  //#endregion
1788
+ //#region src/form/error-utils.ts
1789
+ /**
1790
+ * Framework-agnostic helpers for working with form-error maps keyed by
1791
+ * dotted path. Used by AsForm to drive error badges and auto-open
1792
+ * collapsed sections; safe to share with React (or any other) bindings.
1793
+ *
1794
+ * Convention:
1795
+ * - Keys are dotted paths (`a.b.c`); empty string and `__form` denote
1796
+ * the form-level error.
1797
+ * - Values may be `string | undefined`; falsy entries are dropped on
1798
+ * merge.
1799
+ */
1800
+ /** Error-map key of the form-level error. */
1801
+ const FORM_ERROR_KEY = "__form";
1802
+ /**
1803
+ * Turn a validator's error list into an error map keyed by path. A
1804
+ * root-level error (empty path) becomes the form-level error
1805
+ * ({@link FORM_ERROR_KEY}). The first error per path wins: a failing
1806
+ * container rule is reported before the container's own shape / length
1807
+ * checks at the same path.
1808
+ */
1809
+ function validatorErrorsToMap(errors) {
1810
+ const out = {};
1811
+ for (const err of errors) out[err.path || "__form"] ??= err.message;
1812
+ return out;
1813
+ }
1814
+ /**
1815
+ * Merge any number of partial error maps into a single dense
1816
+ * `Record<path, message>`. Falsy values are skipped — later sources do
1817
+ * NOT overwrite earlier ones with an empty value.
1818
+ */
1819
+ function mergeErrorMaps(...maps) {
1820
+ const merged = {};
1821
+ for (const m of maps) {
1822
+ if (!m) continue;
1823
+ for (const k of Object.keys(m)) {
1824
+ const v = m[k];
1825
+ if (v) merged[k] = v;
1826
+ }
1827
+ }
1828
+ return merged;
1829
+ }
1830
+ /**
1831
+ * Return `errors` without the entries whose key is in `paths`.
1832
+ *
1833
+ * Identity-preserving: when no key matches, the ORIGINAL `errors` object
1834
+ * is returned unchanged — callers compare `result !== errors` to detect
1835
+ * that something was pruned and skip spurious reactive writes.
1836
+ */
1837
+ function omitPaths(errors, paths) {
1838
+ let pruned = null;
1839
+ for (const key in errors) if (paths.has(key)) {
1840
+ pruned ??= { ...errors };
1841
+ delete pruned[key];
1842
+ }
1843
+ return pruned ?? errors;
1844
+ }
1845
+ /**
1846
+ * Yield every ancestor prefix of a dotted path, longest-first
1847
+ * (`a.b.c` → `a.b.c`, `a.b`, `a`). Returns the path itself first so
1848
+ * callers can include it in the iteration without a special case.
1849
+ *
1850
+ * Empty paths and the form-level key (`__form`) yield nothing.
1851
+ */
1852
+ function* iteratePathAncestors(path) {
1853
+ if (!path || path === "__form") return;
1854
+ let pos = path.length;
1855
+ while (pos > 0) {
1856
+ yield path.slice(0, pos);
1857
+ const dot = path.lastIndexOf(".", pos - 1);
1858
+ if (dot < 0) return;
1859
+ pos = dot;
1860
+ }
1861
+ }
1862
+ /**
1863
+ * Build an indexed `Map<absolutePath, descendantErrorCount>` so each
1864
+ * struct in the tree can render an error-count badge in O(1).
1865
+ *
1866
+ * For every error path, the count is incremented on the path itself
1867
+ * AND every dotted-path ancestor — so a struct at `a.b` reports the
1868
+ * total of all errors at `a.b` or below.
1869
+ */
1870
+ function buildDescendantErrorCounts(errors) {
1871
+ const map = /* @__PURE__ */ new Map();
1872
+ for (const errPath of Object.keys(errors)) {
1873
+ if (!errors[errPath]) continue;
1874
+ for (const prefix of iteratePathAncestors(errPath)) map.set(prefix, (map.get(prefix) ?? 0) + 1);
1875
+ }
1876
+ return map;
1877
+ }
1878
+ //#endregion
1788
1879
  //#region src/form/validate.ts
1789
1880
  const dbPlugin = createDbValidatorPlugin();
1790
1881
  const INSERT_CONTEXT = { mode: "insert" };
@@ -1853,6 +1944,9 @@ function getDefaultValidatorPlugins() {
1853
1944
  * ATScript's @expect.* validation runs automatically; server-managed db
1854
1945
  * fields (every `derived` field, absent `@db.default*` / version) pass.
1855
1946
  * For custom `ui.fn.*` validators, install ui-fns and pass its plugin via `opts.plugins`.
1947
+ *
1948
+ * Errors are keyed by dotted path. A root-level error (a failing
1949
+ * `@ui.form.validate` on the form's interface) is keyed `__form`.
1856
1950
  */
1857
1951
  function getFormValidator(def, opts) {
1858
1952
  const derived = collectDerivedProps(def);
@@ -1872,9 +1966,7 @@ function getFormValidator(def, opts) {
1872
1966
  data: callOpts.data,
1873
1967
  context: callOpts.context ?? {}
1874
1968
  })) return {};
1875
- const errors = {};
1876
- for (const err of validator.errors) errors[err.path] = err.message;
1877
- return errors;
1969
+ return validatorErrorsToMap(validator.errors);
1878
1970
  };
1879
1971
  }
1880
1972
  /**
@@ -1886,8 +1978,12 @@ function getFormValidator(def, opts) {
1886
1978
  * a branch's verdict depends on its children — those keep the full walk.
1887
1979
  */
1888
1980
  const skipDescendantsPlugin = (ctx) => ctx.path === "" ? void 0 : true;
1889
- function skipsDescendants(prop) {
1890
- const kind = prop.type.kind;
1981
+ /**
1982
+ * Whether a type kind is a container that carries its own children:
1983
+ * `object`, `array` or `tuple`. Union / intersection kinds are not
1984
+ * containers — they evaluate their branches at their own path.
1985
+ */
1986
+ function isContainerKind(kind) {
1891
1987
  return kind === "object" || kind === "array" || kind === "tuple";
1892
1988
  }
1893
1989
  /**
@@ -1901,7 +1997,7 @@ function skipsDescendants(prop) {
1901
1997
  function createFieldValidator(prop, opts) {
1902
1998
  let cached;
1903
1999
  return (value, externalCtx) => {
1904
- cached ??= new Validator(prop, { plugins: opts?.rootOnly && skipsDescendants(prop) ? [
2000
+ cached ??= new Validator(prop, { plugins: opts?.rootOnly && isContainerKind(prop.type.kind) ? [
1905
2001
  skipDescendantsPlugin,
1906
2002
  serverManagedPlugin,
1907
2003
  ...defaultValidatorPlugins
@@ -2564,84 +2660,6 @@ function walkUnionFields(fields, prefix, before, after) {
2564
2660
  return false;
2565
2661
  }
2566
2662
  //#endregion
2567
- //#region src/form/error-utils.ts
2568
- /**
2569
- * Framework-agnostic helpers for working with form-error maps keyed by
2570
- * dotted path. Used by AsForm to drive error badges and auto-open
2571
- * collapsed sections; safe to share with React (or any other) bindings.
2572
- *
2573
- * Convention:
2574
- * - Keys are dotted paths (`a.b.c`); empty string and `__form` denote
2575
- * the form-level error.
2576
- * - Values may be `string | undefined`; falsy entries are dropped on
2577
- * merge.
2578
- */
2579
- const FORM_ERROR_KEY = "__form";
2580
- /**
2581
- * Merge any number of partial error maps into a single dense
2582
- * `Record<path, message>`. Falsy values are skipped — later sources do
2583
- * NOT overwrite earlier ones with an empty value.
2584
- */
2585
- function mergeErrorMaps(...maps) {
2586
- const merged = {};
2587
- for (const m of maps) {
2588
- if (!m) continue;
2589
- for (const k of Object.keys(m)) {
2590
- const v = m[k];
2591
- if (v) merged[k] = v;
2592
- }
2593
- }
2594
- return merged;
2595
- }
2596
- /**
2597
- * Return `errors` without the entries whose key is in `paths`.
2598
- *
2599
- * Identity-preserving: when no key matches, the ORIGINAL `errors` object
2600
- * is returned unchanged — callers compare `result !== errors` to detect
2601
- * that something was pruned and skip spurious reactive writes.
2602
- */
2603
- function omitPaths(errors, paths) {
2604
- let pruned = null;
2605
- for (const key in errors) if (paths.has(key)) {
2606
- pruned ??= { ...errors };
2607
- delete pruned[key];
2608
- }
2609
- return pruned ?? errors;
2610
- }
2611
- /**
2612
- * Yield every ancestor prefix of a dotted path, longest-first
2613
- * (`a.b.c` → `a.b.c`, `a.b`, `a`). Returns the path itself first so
2614
- * callers can include it in the iteration without a special case.
2615
- *
2616
- * Empty paths and the form-level key (`__form`) yield nothing.
2617
- */
2618
- function* iteratePathAncestors(path) {
2619
- if (!path || path === FORM_ERROR_KEY) return;
2620
- let pos = path.length;
2621
- while (pos > 0) {
2622
- yield path.slice(0, pos);
2623
- const dot = path.lastIndexOf(".", pos - 1);
2624
- if (dot < 0) return;
2625
- pos = dot;
2626
- }
2627
- }
2628
- /**
2629
- * Build an indexed `Map<absolutePath, descendantErrorCount>` so each
2630
- * struct in the tree can render an error-count badge in O(1).
2631
- *
2632
- * For every error path, the count is incremented on the path itself
2633
- * AND every dotted-path ancestor — so a struct at `a.b` reports the
2634
- * total of all errors at `a.b` or below.
2635
- */
2636
- function buildDescendantErrorCounts(errors) {
2637
- const map = /* @__PURE__ */ new Map();
2638
- for (const errPath of Object.keys(errors)) {
2639
- if (!errors[errPath]) continue;
2640
- for (const prefix of iteratePathAncestors(errPath)) map.set(prefix, (map.get(prefix) ?? 0) + 1);
2641
- }
2642
- return map;
2643
- }
2644
- //#endregion
2645
2663
  //#region src/form/grid.ts
2646
2664
  /** Grid layout parsing for `@ui.form.grid.colSpan` / `@ui.form.grid.rowSpan`. */
2647
2665
  const DEFAULT_COL_SPAN = 12;
@@ -3156,4 +3174,4 @@ function resolvePath(model, table, view) {
3156
3174
  return path.length > 0 ? path : void 0;
3157
3175
  }
3158
3176
  //#endregion
3159
- export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, EXPECT_MAX_LENGTH, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, NUMERIC_VALUE_KINDS, StaticFieldResolver, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, valueHelpDictPaths };
3177
+ export { DB_AMOUNT_CURRENCY, DB_AMOUNT_CURRENCY_REF, DB_COLUMN_PRECISION, DB_HTTP_PATH, DB_REL_FK, DB_UNIT, DB_UNIT_REF, DEFAULT_COL_SPAN, DEFAULT_ROW_SPAN, EXPECT_MAX_LENGTH, FORM_ERROR_KEY, META_DEFAULT, META_DESCRIPTION, META_ID, META_LABEL, META_READONLY, META_REQUIRED, META_SENSITIVE, NUMERIC_VALUE_KINDS, StaticFieldResolver, UI_DICT_ATTR, UI_DICT_DESCR, UI_DICT_FILTERABLE, UI_DICT_LABEL, UI_DICT_SEARCHABLE, UI_DICT_SORTABLE, UI_FORM_ACTION, UI_FORM_ATTR, UI_FORM_AUTOCOMPLETE, UI_FORM_CLASSES, UI_FORM_COMPONENT, UI_FORM_DISABLED, UI_FORM_FN_ATTR, UI_FORM_FN_CLASSES, UI_FORM_FN_DESCRIPTION, UI_FORM_FN_DISABLED, UI_FORM_FN_HIDDEN, UI_FORM_FN_HINT, UI_FORM_FN_LABEL, UI_FORM_FN_OPTIONS, UI_FORM_FN_PLACEHOLDER, UI_FORM_FN_PREFIX, UI_FORM_FN_READONLY, UI_FORM_FN_STYLES, UI_FORM_FN_SUBMIT_DISABLED, UI_FORM_FN_SUBMIT_TEXT, UI_FORM_FN_TITLE, UI_FORM_FN_VALUE, UI_FORM_GRID_COL_SPAN, UI_FORM_GRID_ROW_SPAN, UI_FORM_HIDDEN, UI_FORM_HINT, UI_FORM_LABEL_SINGULAR, UI_FORM_OPTIONS, UI_FORM_ORDER, UI_FORM_PLACEHOLDER, UI_FORM_PREFIX, UI_FORM_PREFIX_ICON, UI_FORM_PREFIX_REF, UI_FORM_STYLES, UI_FORM_SUBMIT_TEXT, UI_FORM_SUFFIX, UI_FORM_SUFFIX_ICON, UI_FORM_SUFFIX_REF, UI_FORM_TYPE, UI_FORM_VALIDATE, UI_NAV_GROUP, UI_NAV_HIDDEN, UI_NAV_ORDER, UI_TABLE_ATTR, UI_TABLE_CLASSES, UI_TABLE_COMPONENT, UI_TABLE_EXCLUDE, UI_TABLE_FN_ATTR, UI_TABLE_FN_CLASSES, UI_TABLE_FN_PREFIX, UI_TABLE_FN_STYLES, UI_TABLE_ORDER, UI_TABLE_SELECT_WITH, UI_TABLE_STYLES, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE, ValueHelpClient, WF_ACTION_WITH_DATA, applyFormChanges, asArray, buildDescendantErrorCounts, buildFormDiff, buildFormRebase, buildGridClasses, buildModelRoutes, buildUnionVariants, collectDirtyPaths, createFieldValidator, createFormData, createFormDef, createFormValueResolver, createTableDef, deepClone, deepEqual, defaultResolver, deleteByPath, detectUnionVariant, enforceScale, escapeRegex, extractFieldLiteralOptions, extractLiteralOptions, extractMeasurement, extractValueHelp, fetchDistinctValues, formatDecimalForDisplay, getByPath, getColumn, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getDeclaredFormActions, getDefaultClientFactory, getDefaultValidatorPlugins, getFieldMeta, getFilterableColumns, getFormValidator, getMetaCacheIdentity, getMetaEntry, getMetaTableDef, getResolver, getSortableColumns, getThousandsSeparator, groupInteger, hasComputedAnnotations, hasFieldMeta, invalidateValueHelpCache, isArrayField, isContainerKind, isFieldHidden, isObjectField, isPathDirty, isPickerDeclined, isPureLiteralUnion, isTupleField, isUnionField, iteratePathAncestors, joinDecimalString, joinPath, mergeErrorMaps, navigateHrefFor, omitPaths, onMetaCacheReset, optKey, optLabel, optionLabel, optionValue, parseColSpan, parseDecimalInput, parseRowSpan, parseStaticAttrs, parseStaticOptions, resetDefaultClientFactory, resetMetaCache, resetValueHelpCache, resolveAttrs, resolveFieldProp, resolveFormProp, resolveGridSpec, resolveOptions, resolveSingularLabel, resolveStatic, resolveValueHelp, retainMetaEntry, setByPath, setDefaultClientFactory, setDefaultValidatorPlugins, setMetaCacheIdentity, setMetaCacheMaxEntries, setResolver, setValueHelpCacheTtl, splitDecimalString, str, unionVariantChanged, validatorErrorsToMap, valueHelpDictPaths };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.157",
3
+ "version": "0.1.158",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",
@@ -47,20 +47,20 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@atscript/db-client": "^0.1.159"
50
+ "@atscript/db-client": "^0.1.161"
51
51
  },
52
52
  "devDependencies": {
53
- "@atscript/core": "^0.1.107",
54
- "@atscript/db": "^0.1.159",
55
- "@atscript/typescript": "^0.1.107",
53
+ "@atscript/core": "^0.1.108",
54
+ "@atscript/db": "^0.1.161",
55
+ "@atscript/typescript": "^0.1.108",
56
56
  "@uniqu/core": "^0.1.15",
57
- "unplugin-atscript": "^0.1.107",
57
+ "unplugin-atscript": "^0.1.108",
58
58
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
59
59
  },
60
60
  "peerDependencies": {
61
- "@atscript/core": "^0.1.107",
62
- "@atscript/db": "^0.1.159",
63
- "@atscript/typescript": "^0.1.107"
61
+ "@atscript/core": "^0.1.108",
62
+ "@atscript/db": "^0.1.161",
63
+ "@atscript/typescript": "^0.1.108"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "vp pack",