@railway-ts/pipelines 0.1.22 → 0.1.24
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/schema/index.cjs +93 -3
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +88 -3
- package/dist/schema/index.d.ts +88 -3
- package/dist/schema/index.mjs +88 -4
- package/dist/schema/index.mjs.map +1 -1
- package/docs/API.md +57 -0
- package/docs/GETTING_STARTED.md +12 -0
- package/docs/RECIPES.md +48 -0
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -902,6 +902,46 @@ function phoneNumber(message?: string): Validator<string>;
|
|
|
902
902
|
|
|
903
903
|
Ensure a string is a valid phone number. Accepts international formats with `+`, spaces, dashes, and parentheses.
|
|
904
904
|
|
|
905
|
+
#### `uuid`
|
|
906
|
+
|
|
907
|
+
```typescript
|
|
908
|
+
function uuid(message?: string): Validator<string>;
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
Ensure a string is a valid RFC 4122 UUID.
|
|
912
|
+
|
|
913
|
+
#### `isoDate`
|
|
914
|
+
|
|
915
|
+
```typescript
|
|
916
|
+
function isoDate(message?: string): Validator<string>;
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
Ensure a string is a valid ISO 8601 date (`YYYY-MM-DD`). Validates both format and calendar correctness (rejects Feb 30, etc.).
|
|
920
|
+
|
|
921
|
+
#### `isoTime`
|
|
922
|
+
|
|
923
|
+
```typescript
|
|
924
|
+
function isoTime(message?: string): Validator<string>;
|
|
925
|
+
```
|
|
926
|
+
|
|
927
|
+
Ensure a string is a valid ISO 8601 / RFC 3339 time. Format: `HH:mm:ss[.fractional][Z|±HH:mm]`. Timezone is optional.
|
|
928
|
+
|
|
929
|
+
#### `isoDateTime`
|
|
930
|
+
|
|
931
|
+
```typescript
|
|
932
|
+
function isoDateTime(message?: string): Validator<string>;
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
Ensure a string is a valid ISO 8601 / RFC 3339 datetime. Format: `YYYY-MM-DDTHH:mm:ss[.fractional][Z|±HH:mm]`. Validates both date calendar correctness and time bounds.
|
|
936
|
+
|
|
937
|
+
#### `isoDuration`
|
|
938
|
+
|
|
939
|
+
```typescript
|
|
940
|
+
function isoDuration(message?: string): Validator<string>;
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
Ensure a string is a valid ISO 8601 duration (`PnYnMnDTnHnMnS` or `PnW`).
|
|
944
|
+
|
|
905
945
|
### Number Constraints
|
|
906
946
|
|
|
907
947
|
#### `min`
|
|
@@ -1266,6 +1306,23 @@ Run a validator against a value. Returns sync when the validator is sync.
|
|
|
1266
1306
|
|
|
1267
1307
|
Pass `{ abortEarly: true }` to stop on the first validation error instead of collecting all errors. The third argument can be either a base `path` (string array) for error reporting, or an options object. When both are needed, pass `path` third and `options` fourth.
|
|
1268
1308
|
|
|
1309
|
+
#### `is`
|
|
1310
|
+
|
|
1311
|
+
```typescript
|
|
1312
|
+
function is(value: unknown, validator: Validator<unknown, unknown>): boolean;
|
|
1313
|
+
function is(value: unknown, validator: MaybeAsyncValidator<unknown, unknown>): boolean | Promise<boolean>;
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
Check if a value passes validation. Returns `true` if valid, `false` if not. Shorthand for `isOk(validate(value, validator))`.
|
|
1317
|
+
|
|
1318
|
+
Uses `abortEarly` internally for efficiency — stops on the first error. Returns a `Promise<boolean>` when given an async validator.
|
|
1319
|
+
|
|
1320
|
+
```typescript
|
|
1321
|
+
is('hello', string()); // true
|
|
1322
|
+
is(42, string()); // false
|
|
1323
|
+
await is('dave', asyncValidator); // true (async)
|
|
1324
|
+
```
|
|
1325
|
+
|
|
1269
1326
|
#### `validateAndFormatResult`
|
|
1270
1327
|
|
|
1271
1328
|
```typescript
|
package/docs/GETTING_STARTED.md
CHANGED
|
@@ -245,6 +245,18 @@ match(result, {
|
|
|
245
245
|
>
|
|
246
246
|
> See [Recipes: Abort Early](RECIPES.md#abort-early) for details.
|
|
247
247
|
|
|
248
|
+
> **Tip:** If you only need a boolean (pass/fail), use `is()`:
|
|
249
|
+
>
|
|
250
|
+
> ```typescript
|
|
251
|
+
> import { is } from '@railway-ts/pipelines/schema';
|
|
252
|
+
>
|
|
253
|
+
> if (is(input, userSchema)) {
|
|
254
|
+
> // input is valid
|
|
255
|
+
> }
|
|
256
|
+
> ```
|
|
257
|
+
>
|
|
258
|
+
> See [API Reference: `is`](API.md#is) for details.
|
|
259
|
+
|
|
248
260
|
---
|
|
249
261
|
|
|
250
262
|
## Step 7: Putting It All Together
|
package/docs/RECIPES.md
CHANGED
|
@@ -285,6 +285,33 @@ const result = validateAndFormatResult(input, userSchema, { abortEarly: true });
|
|
|
285
285
|
|
|
286
286
|
`abortEarly` propagates through nested `object()`, `array()`, `tuple()`, and `tupleOf()` validators — the entire tree stops as soon as the first error is found.
|
|
287
287
|
|
|
288
|
+
### Quick Validity Check
|
|
289
|
+
|
|
290
|
+
Use `is()` when you only need a boolean — no error details, no `Result` unwrapping:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { is, string, chain, minLength, object, required, email } from '@railway-ts/pipelines/schema';
|
|
294
|
+
|
|
295
|
+
// Primitives
|
|
296
|
+
is('hello', string()); // true
|
|
297
|
+
is(42, string()); // false
|
|
298
|
+
|
|
299
|
+
// Composed validators
|
|
300
|
+
const shortString = chain(string(), minLength(5));
|
|
301
|
+
is('hello', shortString); // true
|
|
302
|
+
is('hi', shortString); // false
|
|
303
|
+
|
|
304
|
+
// Objects
|
|
305
|
+
const userSchema = object({
|
|
306
|
+
name: required(chain(string(), minLength(2))),
|
|
307
|
+
email: required(chain(string(), email())),
|
|
308
|
+
});
|
|
309
|
+
is({ name: 'Alice', email: 'alice@example.com' }, userSchema); // true
|
|
310
|
+
is({ name: 'Alice', email: 'nope' }, userSchema); // false
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
`is()` uses `abortEarly` internally — it short-circuits on the first error since you only need pass/fail.
|
|
314
|
+
|
|
288
315
|
### Conditional Validation
|
|
289
316
|
|
|
290
317
|
```typescript
|
|
@@ -618,6 +645,27 @@ const birthDate = chain(parseDate(), pastDate());
|
|
|
618
645
|
const eventDate = chain(parseISODate(), dateRange(new Date('2025-01-01'), new Date('2025-12-31')));
|
|
619
646
|
```
|
|
620
647
|
|
|
648
|
+
### String Format Validators
|
|
649
|
+
|
|
650
|
+
```typescript
|
|
651
|
+
import { chain, string, uuid, isoDate, isoTime, isoDateTime, isoDuration } from '@railway-ts/pipelines/schema';
|
|
652
|
+
|
|
653
|
+
// UUID
|
|
654
|
+
const id = chain(string(), uuid());
|
|
655
|
+
|
|
656
|
+
// ISO date (YYYY-MM-DD)
|
|
657
|
+
const dateStr = chain(string(), isoDate());
|
|
658
|
+
|
|
659
|
+
// ISO time with optional timezone
|
|
660
|
+
const timeStr = chain(string(), isoTime());
|
|
661
|
+
|
|
662
|
+
// Full ISO datetime
|
|
663
|
+
const timestamp = chain(string(), isoDateTime());
|
|
664
|
+
|
|
665
|
+
// ISO duration (e.g. P1Y2M3DT4H5M6S)
|
|
666
|
+
const duration = chain(string(), isoDuration());
|
|
667
|
+
```
|
|
668
|
+
|
|
621
669
|
### Empty-String Handling
|
|
622
670
|
|
|
623
671
|
`emptyAsOptional` treats empty strings (and `null`/`undefined`) as `undefined` instead of failing validation. Useful for HTML forms where blank fields submit as `""`:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@railway-ts/pipelines",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
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": {
|