@orkestrel/contract 0.0.7 → 0.0.9
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 +13 -5
- package/dist/src/core/index.cjs +1870 -611
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +696 -143
- package/dist/src/core/index.d.ts +696 -143
- package/dist/src/core/index.js +1855 -611
- package/dist/src/core/index.js.map +1 -1
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @orkestrel/contract
|
|
2
2
|
|
|
3
3
|
The zero-dependency contract toolkit — runtime type guards, guard combinators, coerce-and-extract
|
|
4
|
-
parsers, and a shape DSL that compiles once into a guard, parser, JSON Schema, and
|
|
5
|
-
can never drift. The foundation package of the `@orkestrel` line.
|
|
4
|
+
parsers, and a shape DSL that compiles once into a guard, parser, fault report, JSON Schema, and
|
|
5
|
+
generator that can never drift. The foundation package of the `@orkestrel` line.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -12,13 +12,19 @@ npm install @orkestrel/contract
|
|
|
12
12
|
|
|
13
13
|
## Requirements
|
|
14
14
|
|
|
15
|
-
- Node.js >=
|
|
15
|
+
- Node.js >= 22.12
|
|
16
16
|
- TypeScript-first (ships its own `.d.ts` types)
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
createContract,
|
|
23
|
+
integerShape,
|
|
24
|
+
objectShape,
|
|
25
|
+
seededRandom,
|
|
26
|
+
stringShape,
|
|
27
|
+
} from '@orkestrel/contract'
|
|
22
28
|
|
|
23
29
|
const user = createContract(
|
|
24
30
|
objectShape({
|
|
@@ -29,7 +35,9 @@ const user = createContract(
|
|
|
29
35
|
|
|
30
36
|
user.is({ name: 'Ada', age: 36 }) // true
|
|
31
37
|
user.parse({ name: 'Ada', age: '36' }) // { name: 'Ada', age: 36 } — coerces, or undefined
|
|
32
|
-
user.
|
|
38
|
+
user.explain({ name: '', age: 36 }) // [{ reason: 'constraint', path: ['name'], constraint: 'min', limit: 1, … }]
|
|
39
|
+
user.schema // the owned, deeply frozen compiled JSON Schema
|
|
40
|
+
user.generate(seededRandom(42)) // reproducible seed data; omit the arg for a wall-clock-seeded source
|
|
33
41
|
```
|
|
34
42
|
|
|
35
43
|
## Guide
|