@nlozgachev/pipelined 0.66.0 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -205,6 +205,19 @@ if (Validation.is.failed(outcome)) {
205
205
  console.log(outcome.errors);
206
206
  // ["Username must be at least 3 characters", "Email must contain an @ symbol"]
207
207
  }
208
+
209
+ // Or keep errors partitioned per field for UI forms:
210
+ const validateForm = Validation.keyed.make({
211
+ username: validateUsername,
212
+ email: validateEmail,
213
+ });
214
+
215
+ const formState = validateForm({ username: "a", email: "invalid" });
216
+
217
+ if (Validation.keyed.is.failed(formState)) {
218
+ const errors = Validation.keyed.getErrors(formState);
219
+ // Some({ username: ["Username must be at least 3 characters"], email: ["Email must contain an @ symbol"] })
220
+ }
208
221
  ```
209
222
 
210
223
  ### Eliminating impossible UI states
@@ -287,7 +300,7 @@ const fetchUser = Op.interpret(
287
300
  Op.create(
288
301
  (signal) => (id: string) =>
289
302
  fetch(`/users/${id}`, { signal }).then((r) => r.json() as Promise<User>),
290
- (e) => new ApiError(e),
303
+ { onError: (e) => new ApiError(e) },
291
304
  ),
292
305
  {
293
306
  strategy: "restartable",
@@ -334,7 +347,7 @@ const searchOp = Op.create(
334
347
  fetch(`/search?q=${query}`, { signal }).then((r) =>
335
348
  r.json() as Promise<SearchResult[]>
336
349
  ),
337
- (e) => new SearchError(e),
350
+ { onError: (e) => new SearchError(e) },
338
351
  );
339
352
 
340
353
  const search = Op.interpret(searchOp, {
@@ -360,7 +373,7 @@ const submitOp = Op.create(
360
373
  fetch("/orders", { method: "POST", body: data, signal }).then((r) =>
361
374
  r.json()
362
375
  ),
363
- (e) => new ApiError(e),
376
+ { onError: (e) => new ApiError(e) },
364
377
  );
365
378
 
366
379
  const submit = Op.interpret(submitOp, {
@@ -552,11 +565,11 @@ if (Result.is.ok(email)) {
552
565
  - **`@nlozgachev/pipelined/core`**: Core context containers, async runtimes, optics, and logic
553
566
  abstractions (<11 KB gzipped).
554
567
  - **`@nlozgachev/pipelined/data`**: Curried, data-last utilities for collections, numbers, strings,
555
- and JSON (<7 KB gzipped).
568
+ and JSON (<10 KB gzipped).
556
569
  - **`@nlozgachev/pipelined/composition`**: Pure higher-order function combinators (`pipe`, `flow`,
557
570
  `compose`, `curry`, `uncurry`, `converge`, `juxt`, `memoize`, `tap`, `on`, `not`, `flip`, `fn`)
558
571
  (<2 KB gzipped).
559
- - **`@nlozgachev/pipelined/types`**: Type-level utilities (`Brand`, `Duration`, `RetryPolicy`) (<400
572
+ - **`@nlozgachev/pipelined/types`**: Type-level utilities (`Brand`, `Duration`, `RetryPolicy`) (<450
560
573
  B gzipped).
561
574
 
562
575
  Every utility in the library is benchmarked against its native equivalent. While currying introduces