@atscript/moost-wf 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.
Files changed (2) hide show
  1. package/dist/index.mjs +29 -7
  2. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -83,6 +83,33 @@ function serializeFormSchema(type) {
83
83
  return schema;
84
84
  }
85
85
  //#endregion
86
+ //#region ../ui/src/form/error-utils.ts
87
+ /**
88
+ * Framework-agnostic helpers for working with form-error maps keyed by
89
+ * dotted path. Used by AsForm to drive error badges and auto-open
90
+ * collapsed sections; safe to share with React (or any other) bindings.
91
+ *
92
+ * Convention:
93
+ * - Keys are dotted paths (`a.b.c`); empty string and `__form` denote
94
+ * the form-level error.
95
+ * - Values may be `string | undefined`; falsy entries are dropped on
96
+ * merge.
97
+ */
98
+ /** Error-map key of the form-level error. */
99
+ const FORM_ERROR_KEY = "__form";
100
+ /**
101
+ * Turn a validator's error list into an error map keyed by path. A
102
+ * root-level error (empty path) becomes the form-level error
103
+ * ({@link FORM_ERROR_KEY}). The first error per path wins: a failing
104
+ * container rule is reported before the container's own shape / length
105
+ * checks at the same path.
106
+ */
107
+ function validatorErrorsToMap(errors) {
108
+ const out = {};
109
+ for (const err of errors) out[err.path || "__form"] ??= err.message;
110
+ return out;
111
+ }
112
+ //#endregion
86
113
  //#region src/wf-io/validator-cache.ts
87
114
  const cache = /* @__PURE__ */ new WeakMap();
88
115
  /**
@@ -107,11 +134,6 @@ function getCachedValidator(type, opts) {
107
134
  }
108
135
  //#endregion
109
136
  //#region src/wf-io/use-atscript-wf.ts
110
- function flattenValidatorErrors(err) {
111
- const out = {};
112
- for (const e of err.errors) out[e.path] = e.message;
113
- return out;
114
- }
115
137
  function isValidatorError(err) {
116
138
  return err !== null && typeof err === "object" && "errors" in err && Array.isArray(err.errors);
117
139
  }
@@ -120,7 +142,7 @@ function useAtscriptWf(type) {
120
142
  function requireInput({ errors, formMessage } = {}) {
121
143
  const passContext = extractPassContext(type, wfState.ctx() ?? {});
122
144
  const mergedErrors = errors ? { ...errors } : formMessage ? {} : void 0;
123
- if (formMessage && mergedErrors) mergedErrors.__form = formMessage;
145
+ if (formMessage && mergedErrors) mergedErrors[FORM_ERROR_KEY] = formMessage;
124
146
  const context = mergedErrors ? {
125
147
  ...passContext,
126
148
  errors: mergedErrors
@@ -136,7 +158,7 @@ function useAtscriptWf(type) {
136
158
  try {
137
159
  validator.validate(input);
138
160
  } catch (err) {
139
- if (isValidatorError(err)) throw requireInput({ errors: flattenValidatorErrors(err) });
161
+ if (isValidatorError(err)) throw requireInput({ errors: validatorErrorsToMap(err.errors) });
140
162
  throw err;
141
163
  }
142
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/moost-wf",
3
- "version": "0.1.157",
3
+ "version": "0.1.158",
4
4
  "description": "Workflow form integration for moost — decorators, interceptors, and serialization driven by atscript type metadata",
5
5
  "keywords": [
6
6
  "atscript",
@@ -56,11 +56,11 @@
56
56
  "access": "public"
57
57
  },
58
58
  "devDependencies": {
59
- "@atscript/core": "^0.1.107",
60
- "@atscript/db": "^0.1.159",
61
- "@atscript/db-sql-tools": "^0.1.159",
62
- "@atscript/db-sqlite": "^0.1.159",
63
- "@atscript/typescript": "^0.1.107",
59
+ "@atscript/core": "^0.1.108",
60
+ "@atscript/db": "^0.1.161",
61
+ "@atscript/db-sql-tools": "^0.1.161",
62
+ "@atscript/db-sqlite": "^0.1.161",
63
+ "@atscript/typescript": "^0.1.108",
64
64
  "@moostjs/event-wf": "^0.6.52",
65
65
  "@prostojs/wf": "^0.2.1",
66
66
  "@uniqu/core": "^0.1.15",
@@ -69,13 +69,13 @@
69
69
  "@wooksjs/event-wf": "^0.7.30",
70
70
  "@wooksjs/http-body": "^0.7.30",
71
71
  "moost": "^0.6.52",
72
- "unplugin-atscript": "^0.1.107",
72
+ "unplugin-atscript": "^0.1.108",
73
73
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14",
74
- "@atscript/ui": "^0.1.157"
74
+ "@atscript/ui": "^0.1.158"
75
75
  },
76
76
  "peerDependencies": {
77
- "@atscript/core": "^0.1.107",
78
- "@atscript/typescript": "^0.1.107",
77
+ "@atscript/core": "^0.1.108",
78
+ "@atscript/typescript": "^0.1.108",
79
79
  "@moostjs/event-wf": "^0.6.52",
80
80
  "@wooksjs/event-core": "^0.7.30",
81
81
  "@wooksjs/event-wf": "^0.7.30",