@railway-ts/pipelines 0.1.12 → 0.1.13

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/README.md +110 -101
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,13 +2,39 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@railway-ts/pipelines.svg)](https://www.npmjs.com/package/@railway-ts/pipelines) [![Build Status](https://github.com/sakobu/railway-ts-pipelines/workflows/CI/badge.svg)](https://github.com/sakobu/railway-ts-pipelines/actions) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue)](https://www.typescriptlang.org/) [![Coverage](https://img.shields.io/codecov/c/github/sakobu/railway-ts-pipelines)](https://codecov.io/gh/sakobu/railway-ts-pipelines)
4
4
 
5
- Railway-oriented programming for TypeScript. Result and Option types that don't suck.
5
+ Railway-oriented programming for TypeScript. Typed `Result<T, E>` pipelines with first-class validation and optional `Option<T>` support — small, modular, and fully tree-shakable.
6
6
 
7
- Small, focused API surface. Errors propagate automatically, you handle them once at the end.
7
+ ## Why?
8
8
 
9
- Fully tree-shakable — import only what you need:
9
+ Most TypeScript projects end up combining:
10
10
 
11
- `option` 402 B · `result` 582 B · `composition` 233 B · `schema` ~3 kB — **~4.2 kB total** minified + brotli
11
+ - A validation library (Zod, Valibot, Yup)
12
+ - A Result library (neverthrow, fp-ts, custom)
13
+ - Manual async error wiring
14
+
15
+ This library unifies those around a single `Result<T, E>` model so validation, async operations, and business logic compose without adapters.
16
+
17
+ No runtime. No global context. No required framework. Import only what you need.
18
+
19
+ ## Design
20
+
21
+ The library is layered and modular:
22
+
23
+ - **Result** — explicit success/failure, no exceptions
24
+ - **Option** — nullable handling without null checks
25
+ - **Schema** — parse unknown input into typed values
26
+ - **Composition** — build sync and async pipelines
27
+
28
+ Each layer works independently. Combine them when it makes sense.
29
+
30
+ Fully tree-shakable:
31
+
32
+ - `result` — 582 B
33
+ - `option` — 402 B
34
+ - `composition` — 233 B
35
+ - `schema` — ~3 kB
36
+
37
+ **~4.2 kB total** (minified + brotli)
12
38
 
13
39
  ## Install
14
40
 
@@ -59,63 +85,48 @@ await compute({ x: '10', y: '2' }).then(console.log); // { valid: true, data: 5
59
85
 
60
86
  Validate at boundaries, chain operations, branch once at the end. Errors propagate automatically.
61
87
 
62
- ## Documentation
63
-
64
- - **[Getting Started](docs/GETTING_STARTED.md)** — Guided walkthrough from first principles to full pipelines
65
- - **[Recipes](docs/RECIPES.md)** — Point-free composition, error recovery, async pipelines, validation patterns
66
- - **[Advanced](docs/ADVANCED.md)** — Symbol branding, type inference, implementation details
67
- - **[Examples](examples/)** — Working code you can run
68
-
69
- For a complete real-world pipeline, see the [Launch Decision Pipeline](docs/RECIPES.md#full-example-launch-decision-pipeline) -- validates input, fetches weather data, and makes a GO/NO-GO decision.
70
-
71
- ## What's Included
72
-
73
- - **Result\<T, E\>** -- typed success/failure with map, flatMap, match, and recovery
74
- - **Option\<T\>** -- nullable handling without null checks
75
- - **Schema validation** -- parse unknown data, accumulate all errors, infer TypeScript types
76
- - **Composition** -- `pipe`, `flow`, `pipeAsync`, `flowAsync`, `curry`
77
- - **Async** -- sync-preserving overloads, parallel field validation, seamless sync/async mixing
78
- - **Standard Schema v1** -- `toStandardSchema()` for tRPC, TanStack Form, React Hook Form, and other consumers
79
-
80
- ## Ecosystem
81
-
82
- - **[@railway-ts/use-form](https://github.com/sakobu/railway-ts-use-form)** -- Type-safe React form hook. Define a schema here, get validated forms with autocomplete, error handling, and native HTML bindings.
88
+ ## Real-World Edge Case
83
89
 
84
- ## API Reference
85
-
86
- ### Option
87
-
88
- Handle nullable values without `if (x !== null)` everywhere.
90
+ Cross-field validation + async operations:
89
91
 
90
92
  ```typescript
91
- import { pipe } from '@railway-ts/pipelines/composition';
92
- import { some, mapWith, match } from '@railway-ts/pipelines/option';
93
-
94
- const user = some({ name: 'Alice', age: 25 });
95
- const name = pipe(
96
- user,
97
- mapWith((u) => u.name),
93
+ import {
94
+ object,
95
+ required,
96
+ chain,
97
+ string,
98
+ minLength,
99
+ refineAt,
100
+ validate,
101
+ } from '@railway-ts/pipelines/schema';
102
+ import { pipeAsync } from '@railway-ts/pipelines/composition';
103
+ import { flatMapWith, tapWith } from '@railway-ts/pipelines/result';
104
+
105
+ const signupSchema = chain(
106
+ object({
107
+ password: required(chain(string(), minLength(8))),
108
+ confirmPassword: required(string()),
109
+ }),
110
+ refineAt('confirmPassword', (d) => d.password === d.confirmPassword, 'Passwords must match'),
98
111
  );
99
112
 
100
- match(name, {
101
- some: (n) => console.log(n),
102
- none: () => console.log('No user'),
103
- }); // Output: Alice
113
+ const result = await pipeAsync(
114
+ validate(input, signupSchema),
115
+ flatMapWith(createUser),
116
+ tapWith((user) => sendWelcomeEmail(user.email)),
117
+ );
104
118
  ```
105
119
 
106
- | Category | Functions |
107
- | ------------- | ------------------------------------------------- |
108
- | **Core** | `some`, `none`, `isSome`, `isNone` |
109
- | **Transform** | `map`, `flatMap`, `bimap`, `filter`, `tap` |
110
- | **Curried** | `mapWith`, `flatMapWith`, `filterWith`, `tapWith` |
111
- | **Unwrap** | `unwrap`, `unwrapOr`, `unwrapOrElse` |
112
- | **Combine** | `combine` |
113
- | **Convert** | `fromNullable`, `mapToResult` |
114
- | **Branch** | `match` |
120
+ - Accumulates validation errors
121
+ - Supports cross-field constraints
122
+ - Mixes sync + async steps seamlessly
123
+ - Branch once at the end
124
+
125
+ ## Core Modules
115
126
 
116
127
  ### Result
117
128
 
118
- Explicit error handling. No exceptions, no try-catch pyramids.
129
+ Typed success/failure without exceptions.
119
130
 
120
131
  ```typescript
121
132
  import { pipe } from '@railway-ts/pipelines/composition';
@@ -134,20 +145,35 @@ match(result, {
134
145
  }); // Output: 15
135
146
  ```
136
147
 
137
- | Category | Functions |
138
- | ------------- | ------------------------------------------------------------------------------------------------ |
139
- | **Core** | `ok`, `err`, `isOk`, `isErr` |
140
- | **Transform** | `map`, `mapErr`, `flatMap`, `bimap`, `filter`, `tap`, `tapErr` |
141
- | **Curried** | `mapWith`, `flatMapWith`, `mapErrWith`, `filterWith`, `tapWith`, `tapErrWith` |
142
- | **Recovery** | `orElse`, `orElseWith` |
143
- | **Unwrap** | `unwrap`, `unwrapOr`, `unwrapOrElse` |
144
- | **Combine** | `combine`, `combineAll` |
145
- | **Convert** | `fromTry`, `fromTryWithError`, `fromPromise`, `fromPromiseWithError`, `toPromise`, `mapToOption` |
146
- | **Branch** | `match` |
148
+ `ok` · `err` · `isOk` · `isErr` · `map` · `flatMap` · `mapErr` · `bimap` · `filter` · `tap` · `tapErr` · `orElse` · `combine` · `combineAll` · `fromPromise` · `fromTry` · `match` · `unwrapOr` — [full API](docs/API.md#result)
149
+
150
+ ### Option
151
+
152
+ Nullable handling without `if (x !== null)` everywhere.
153
+
154
+ ```typescript
155
+ import { pipe } from '@railway-ts/pipelines/composition';
156
+ import { some, mapWith, match } from '@railway-ts/pipelines/option';
157
+
158
+ const user = some({ name: 'Alice', age: 25 });
159
+ const name = pipe(
160
+ user,
161
+ mapWith((u) => u.name),
162
+ );
163
+
164
+ match(name, {
165
+ some: (n) => console.log(n),
166
+ none: () => console.log('No user'),
167
+ }); // Output: Alice
168
+ ```
169
+
170
+ `some` · `none` · `isSome` · `isNone` · `map` · `flatMap` · `bimap` · `filter` · `tap` · `combine` · `fromNullable` · `mapToResult` · `match` · `unwrapOr` — [full API](docs/API.md#option)
171
+
172
+ Use independently, or convert to Result when needed.
147
173
 
148
174
  ### Schema
149
175
 
150
- Parse untrusted data into typed values. Accumulates all validation errors.
176
+ Parse unknown data into typed values. Accumulates all validation errors.
151
177
 
152
178
  > **Standard Schema v1 compliant** — use `toStandardSchema()` for interop with tRPC, TanStack Form, React Hook Form, and other Standard Schema consumers. See [Recipes -> Standard Schema Interop](docs/RECIPES.md#standard-schema-interop).
153
179
 
@@ -178,28 +204,11 @@ const result = validate(input, userSchema);
178
204
  // Result<User, ValidationError[]>
179
205
  ```
180
206
 
181
- | Category | Functions |
182
- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
- | **Primitives** | `string`, `number`, `boolean`, `date`, `bigint` |
184
- | **Parsers** | `parseNumber`, `parseString`, `parseBool`, `parseBigInt`, `parseDate`, `parseISODate`, `parseJSON`, `parseURL`, `parseEnum` |
185
- | **Structures** | `object`, `array`, `tuple`, `tupleOf` |
186
- | **Unions** | `union`, `discriminatedUnion`, `literal` |
187
- | **Modifiers** | `required`, `optional`, `nullable`, `emptyAsOptional` |
188
- | **String Constraints** | `minLength`, `maxLength`, `pattern`, `nonEmpty`, `email`, `phoneNumber` |
189
- | **Number Constraints** | `min`, `max`, `integer`, `finite`, `between`, `positive`, `negative`, `nonZero`, `divisibleBy`, `precision` |
190
- | **Date Constraints** | `dateRange`, `pastDate`, `futureDate`, `todayOrFuture` |
191
- | **Enums** | `stringEnum`, `enumValue`, `oneOf` |
192
- | **Boolean Constraints** | `matches` |
193
- | **Array Constraints** | `minItems`, `maxItems`, `notEmpty`, `unique` |
194
- | **Combinators** | `chain`, `transform`, `refine` |
195
- | **Cross-field** | `refineAt`, `refineAtAsync` |
196
- | **Async** | `chainAsync`, `refineAsync`, `refineAtAsync` |
197
- | **Utilities** | `validate`, `validateAndFormatResult`, `formatErrors`, `toStandardSchema`, `ROOT_ERROR_KEY` |
198
- | **Types** | `Validator`, `AsyncValidator`, `MaybeAsyncValidator`, `Schema`, `SyncSchema`, `InferSchemaType`, `ValidatorMapOutput`, `ValidationError`, `ValidationResult`, `StandardSchemaV1` |
207
+ `object` · `array` · `tuple` · `required` · `optional` · `chain` · `string` · `parseNumber` · `email` · `min` · `max` · `union` · `discriminatedUnion` · `refine` · `refineAt` · `transform` · `validate` · `toStandardSchema` — [full API](docs/API.md#schema)
199
208
 
200
209
  ### Composition
201
210
 
202
- Build pipelines. No nested function calls.
211
+ Build readable pipelines. No nested function calls.
203
212
 
204
213
  ```typescript
205
214
  import { pipe, flow, pipeAsync, flowAsync } from '@railway-ts/pipelines/composition';
@@ -226,32 +235,32 @@ const processOrder = flowAsync(validateOrder, chargePayment, createShipment);
226
235
  await processOrder(orderInput);
227
236
  ```
228
237
 
229
- | Category | Functions |
230
- | --------- | -------------------------------------------------------- |
231
- | **Sync** | `pipe`, `flow`, `curry`, `uncurry`, `tupled`, `untupled` |
232
- | **Async** | `pipeAsync`, `flowAsync` |
233
- | **Types** | `MaybeAsync` |
238
+ `pipe` · `flow` · `pipeAsync` · `flowAsync` · `curry` · `uncurry` · `tupled` · `untupled` — [full API](docs/API.md#composition)
234
239
 
235
- ## Examples
240
+ Sync and async composition share the same mental model.
236
241
 
237
- Clone and run:
242
+ ## Ecosystem
238
243
 
239
- ```bash
240
- git clone https://github.com/sakobu/railway-ts-pipelines.git
241
- cd railway-ts-pipelines
242
- bun install
243
- bun run examples/index.ts
244
- ```
244
+ - **[@railway-ts/use-form](https://github.com/sakobu/railway-ts-use-form)** — Type-safe React form hook built directly on the Schema layer. Define a schema once — use it for validation, type inference, and form state.
245
+
246
+ ## Documentation
247
+
248
+ - **[Getting Started](docs/GETTING_STARTED.md)** — Learn the concepts, one at a time
249
+ - **[Recipes](docs/RECIPES.md)** — Patterns for real work: async pipelines, error recovery, validation, Standard Schema
250
+ - **[API Reference](docs/API.md)** — Every function signature and description
251
+ - **[Examples](examples/)** — Working code you can run
252
+
253
+ For a complete real-world pipeline, see the [Launch Decision Pipeline](docs/RECIPES.md#full-example-launch-decision-pipeline) -- validates input, fetches weather data, and makes a GO/NO-GO decision.
245
254
 
246
- **What's in there:**
255
+ ## Philosophy
247
256
 
248
- - `option/` - Nullable handling patterns, curried helpers
249
- - `result/` - Error handling patterns, curried helpers, recovery
250
- - `schema/` - Validation (basic, unions, tuples, async validation)
251
- - `composition/` - Function composition (sync and async)
252
- - `complete-pipelines/` - Full examples with validation + async + logic
257
+ - Explicit over implicit
258
+ - No exceptions for control flow
259
+ - No required runtime
260
+ - No hidden global state
261
+ - Import only what you use
253
262
 
254
- Start with `examples/complete-pipelines/async-launch.ts` for a real-world pattern.
263
+ Small pieces. Composable layers. One error model.
255
264
 
256
265
  ## Contributing
257
266
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@railway-ts/pipelines",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Railway-oriented pipelines for TypeScript: a lightweight fp-style Result/Option and schema layer for handling errors and validating boundaries.",
5
5
  "type": "module",
6
6
  "exports": {