@oh-my-pi/omptype 17.2.6 → 17.2.8
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/CHANGELOG.md +40 -2
- package/README.md +83 -14
- package/dist/js/ark.js +16 -0
- package/dist/js/compile.js +942 -0
- package/dist/js/errors.js +394 -0
- package/dist/js/from-json-schema.js +234 -0
- package/dist/js/index.js +13 -0
- package/dist/js/infer.js +2 -0
- package/dist/js/interp.js +858 -0
- package/dist/js/ir.js +1700 -0
- package/dist/js/json-schema.js +312 -0
- package/dist/js/keywords.js +340 -0
- package/dist/js/type.js +3062 -0
- package/dist/js/typebox.js +355 -0
- package/dist/js/zod.js +269 -0
- package/dist/types/ark.d.ts +3 -11
- package/dist/types/compile.d.ts +2 -0
- package/dist/types/errors.d.ts +53 -16
- package/dist/types/from-json-schema.d.ts +9 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/infer.d.ts +147 -31
- package/dist/types/interp.d.ts +14 -5
- package/dist/types/ir.d.ts +129 -9
- package/dist/types/json-schema.d.ts +15 -1
- package/dist/types/keywords.d.ts +7 -0
- package/dist/types/type.d.ts +525 -60
- package/dist/types/typebox.d.ts +78 -50
- package/dist/types/zod.d.ts +1 -1
- package/package.json +24 -8
- package/src/ark.ts +4 -14
- package/src/compile.ts +887 -154
- package/src/errors.ts +347 -37
- package/src/from-json-schema.ts +231 -0
- package/src/index.ts +4 -4
- package/src/infer.ts +363 -81
- package/src/interp.ts +585 -102
- package/src/ir.ts +1444 -128
- package/src/json-schema.ts +162 -19
- package/src/keywords.ts +380 -0
- package/src/type.ts +3842 -198
- package/src/typebox.ts +142 -99
- package/src/zod.ts +41 -28
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [17.2.8] - 2026-08-04
|
|
6
|
+
|
|
5
7
|
### Added
|
|
6
8
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
+
- Added `io: 'input'` and `io: 'output'` options to `toJsonSchema()`, supporting input validation shapes and piped `.to()` target types
|
|
10
|
+
- Added Standard Schema V1 interop: every schema exposes `~standard` with synchronous validation, enabling direct use with `@t3-oss/env`, tRPC, and other Standard Schema consumers.
|
|
11
|
+
- Added `fromJsonSchema()`, rebuilding callable schemas from JSON Schema documents (draft-07 / draft-2020-12 structural keywords, string formats, `$defs` recursion, enums, and `anyOf`/`oneOf`/`allOf` composition) — the inverse of `Type.toJsonSchema()`.
|
|
12
|
+
- Added `$defs`/`$ref` emission for recursive alias schemas in `toJsonSchema()` (draft-07 converts to `definitions`), preventing unbounded recursion on cyclic scopes.
|
|
13
|
+
- Added `AnyType`, a minimal structural constraint for generic functions accepting any schema without descending the recursive fluent surface.
|
|
14
|
+
- Root `.default()` values now materialize for `undefined` input in direct calls and at the Standard Schema boundary (factories run per call).
|
|
15
|
+
- `.narrow()`/`.filter()` boolean overloads accept `OmpErrors` returns, so `cond || ctx.reject(...)` recipes typecheck.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Restored low-overhead schema construction by lazily activating advanced normalization and compatibility machinery.
|
|
20
|
+
- `.default()` is typed input-side (`i | (() => i)`) and marks the schema's input as optional (`i | undefined`).
|
|
21
|
+
- Parse keywords (`string.integer.parse`, `parse.number`, ...) now infer their morph output inside union strings, and input-side inference is union-aware.
|
|
22
|
+
- Object-literal inference for `.merge()`/`.or()`/`.and()` unwraps embedded schema values (output and input sides).
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Alias intersections defer through memoized lazy nodes, so cyclic scope schemas no longer overflow the stack in `.and()` or morph-union determinism checks.
|
|
27
|
+
|
|
28
|
+
## [17.2.7] - 2026-08-03
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- Introduced omptype, an ArkType-compatible schema validation library featuring a lazy JIT runtime that compiles specialized validators on the third call for ultra-fast hot-path validation and low construction overhead.
|
|
33
|
+
- Added support for a rich string definition DSL (primitives, literals, unions, arrays, bounds, inline defaults, and optional keys), object definitions (including index signatures and strict key rejection/deletion), and comprehensive composition methods (.or, .and, .array, .pipe, .narrow, .describe, .default, .allows, .assert).
|
|
34
|
+
- Added TypeBox-style (@oh-my-pi/omptype/typebox) and Zod-style (@oh-my-pi/omptype/zod) authoring adapters that produce native omptype schemas.
|
|
35
|
+
- Added support for recursive named scopes, modules, runtime generics, fixed/optional/variadic tuples, Date literals/bounds, disjointness-aware intersections, separate input/output inference, and draft-2020-12 JSON Schema emission.
|
|
36
|
+
- Shipped transpiled ESM and TypeScript declarations in the npm package to support plain Node.js environments, while preserving TS source resolution for Bun consumers.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- Optimized the lazy JIT compiler to support tuples, refinements, morphs, intersections, instances, and recursive aliases, while reducing schema construction overhead.
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- Fixed a TypeScript compiler error (TS2589: "type instantiation is excessively deep") when using generic fluent composition methods on nested schemas.
|
|
45
|
+
- Fixed type.raw() results (BaseType) to correctly expose fluent composition methods like .array(), .or(), and .pipe().
|
|
46
|
+
- Fixed an issue in the TypeBox adapter where keyword-carrying schemas (e.g., uniqueItems arrays) would throw an error during JSON Schema emission.
|
package/README.md
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# @oh-my-pi/omptype
|
|
2
2
|
|
|
3
|
-
Fast, ArkType-compatible schema validation for
|
|
4
|
-
interpreter and lazily compile after repeated use,
|
|
5
|
-
without giving up hot-path validation speed.
|
|
3
|
+
Fast, ArkType-compatible schema validation for JavaScript and TypeScript.
|
|
4
|
+
Schemas start with a small interpreter and lazily compile after repeated use,
|
|
5
|
+
keeping construction cheap without giving up hot-path validation speed.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
+
npm install @oh-my-pi/omptype
|
|
11
|
+
# or
|
|
10
12
|
bun add @oh-my-pi/omptype
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Runs on Node 20+ (published as compiled ESM with bundled type declarations)
|
|
16
|
+
and Bun 1.3.14+ (which resolves the TypeScript source directly via the `bun`
|
|
17
|
+
export condition). No runtime dependencies.
|
|
14
18
|
|
|
15
19
|
## Usage
|
|
16
20
|
|
|
@@ -18,9 +22,9 @@ Omptype requires Bun 1.3.14 or newer.
|
|
|
18
22
|
import { type } from "@oh-my-pi/omptype";
|
|
19
23
|
|
|
20
24
|
const Config = type({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
name: "string",
|
|
26
|
+
"retries?": "number.integer >= 0",
|
|
27
|
+
enabled: "boolean = true",
|
|
24
28
|
});
|
|
25
29
|
|
|
26
30
|
const config = Config.assert({ name: "worker" });
|
|
@@ -28,13 +32,42 @@ const config = Config.assert({ name: "worker" });
|
|
|
28
32
|
|
|
29
33
|
const result = Config({ name: 42 });
|
|
30
34
|
if (result instanceof type.errors) {
|
|
31
|
-
|
|
35
|
+
console.error(result.summary);
|
|
32
36
|
}
|
|
33
37
|
```
|
|
34
38
|
|
|
35
|
-
Schemas are callable and expose `.
|
|
36
|
-
`.
|
|
37
|
-
`.
|
|
39
|
+
Schemas are callable and expose composition (`.or()`, `.and()`, `.array()`,
|
|
40
|
+
`.pipe()`, `.narrow()`), object transforms (`.pick()`, `.omit()`, `.partial()`,
|
|
41
|
+
`.required()`, `.merge()`, `.map()`), refinements, semantic comparison, error
|
|
42
|
+
configuration, and JSON Schema emission.
|
|
43
|
+
|
|
44
|
+
Built-in keyword modules include `type.string.email`, `type.string.uuid.v4`,
|
|
45
|
+
`type.string.date.iso.parse`, `type.string.normalize.NFKC`,
|
|
46
|
+
`type.number.integer`, and the parsers under `type.parse`.
|
|
47
|
+
|
|
48
|
+
## Named and recursive schemas
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const models = type
|
|
52
|
+
.scope({
|
|
53
|
+
User: { name: "string", "manager?": "User" },
|
|
54
|
+
Users: "User[]",
|
|
55
|
+
PublicUser: "Pick<User, 'name'>",
|
|
56
|
+
})
|
|
57
|
+
.export();
|
|
58
|
+
|
|
59
|
+
models.User.assert({ name: "Ada", manager: { name: "Grace" } });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Scopes resolve aliases lazily, including cycles. `type.module()` exports a
|
|
63
|
+
scope directly, `type.define()` preserves literal definitions, and
|
|
64
|
+
`type.generic("<value>", definition)` builds parameterized runtime schemas.
|
|
65
|
+
|
|
66
|
+
Failed validation returns `OmpErrors`; each entry exposes `code`, `path`,
|
|
67
|
+
`expected`, `actual`, `problem`, and `message`, while the aggregate exposes
|
|
68
|
+
`summary` and `byPath`. `.configure()` accepts string or callback overrides for
|
|
69
|
+
error text. `.toJsonSchema()` accepts `target`, `dialect`, and `fallback`
|
|
70
|
+
options.
|
|
38
71
|
|
|
39
72
|
## Compatibility adapters
|
|
40
73
|
|
|
@@ -51,9 +84,45 @@ const ZodUser = z.object({ name: z.string() });
|
|
|
51
84
|
const user = ZodUser.parse({ name: "Ada" });
|
|
52
85
|
```
|
|
53
86
|
|
|
54
|
-
`@oh-my-pi/omptype/ark` provides the repository's ArkType compatibility facade
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
`@oh-my-pi/omptype/ark` provides the repository's ArkType compatibility facade
|
|
88
|
+
and re-exports the same `type` and `scope` implementations.
|
|
89
|
+
|
|
90
|
+
## Performance
|
|
91
|
+
|
|
92
|
+
Run the benchmark from the repository root:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
bun packages/omptype/bench/bench.ts
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The harness first requires every candidate to accept, reject, and transform the
|
|
99
|
+
same fixtures correctly. Compile and cold-start results use 400 unique object
|
|
100
|
+
schemas and report the fastest of five repetitions. Hot validation mixes valid
|
|
101
|
+
and invalid inputs after 2,000 warmup calls. The valid-only row uses each
|
|
102
|
+
library's public boolean path after 20,000 warmup calls.
|
|
103
|
+
|
|
104
|
+
Representative result on an Apple M4 Max with Darwin 25.6.0 and Bun 1.3.14:
|
|
105
|
+
|
|
106
|
+
| Phase | omptype | ArkType | Zod | TypeBox |
|
|
107
|
+
| ----------------------- | ---------: | ----------------: | ----------------: | --------------: |
|
|
108
|
+
| Compile `type()` | **509ns** | 271.08µs (532.3×) | 77.95µs (153.1×) | 27.36µs (53.7×) |
|
|
109
|
+
| Compile + 2 validations | **2.18µs** | 526.46µs (241.5×) | 222.55µs (102.1×) | 46.90µs (21.5×) |
|
|
110
|
+
|
|
111
|
+
| Hot workload | omptype | ArkType | Zod | TypeBox |
|
|
112
|
+
| -------------------------- | -------: | --------------: | --------------: | --------------: |
|
|
113
|
+
| `flat-small` | **25ns** | 5.10µs (203.7×) | 4.55µs (181.4×) | 1.23µs (49.2×) |
|
|
114
|
+
| `enum-union` | **27ns** | 4.92µs (185.0×) | 4.38µs (164.7×) | 2.20µs (83.0×) |
|
|
115
|
+
| `nested-arrays` | **29ns** | 4.80µs (163.0×) | 7.05µs (239.6×) | 3.01µs (102.2×) |
|
|
116
|
+
| `strict-defaults` | **40ns** | 4.85µs (122.1×) | 6.71µs (169.2×) | 4.92µs (123.9×) |
|
|
117
|
+
| `delete-extras` | **22ns** | 4.12µs (191.6×) | 2.55µs (118.6×) | 2.07µs (96.0×) |
|
|
118
|
+
| `record-mixed` | **43ns** | 4.32µs (100.4×) | 8.80µs (204.5×) | 3.35µs (77.9×) |
|
|
119
|
+
| `deep-message` | **31ns** | 6.32µs (202.5×) | 9.16µs (293.7×) | 5.13µs (164.5×) |
|
|
120
|
+
| `nested-arrays` valid-only | **15ns** | 28ns (1.8×) | 1.05µs (68.3×) | 45ns (2.9×) |
|
|
121
|
+
|
|
122
|
+
Lower times are better. Parenthetical values show how many times slower each
|
|
123
|
+
candidate was than omptype in this run. Results vary with hardware, runtime,
|
|
124
|
+
thermal state, and dependency versions; use the command above for local
|
|
125
|
+
measurements.
|
|
57
126
|
|
|
58
127
|
## License
|
|
59
128
|
|
package/dist/js/ark.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArkType compatibility facade — `@oh-my-pi/omptype/ark`.
|
|
3
|
+
*
|
|
4
|
+
* Lets code written against arktype keep its imports and names while running
|
|
5
|
+
* on the omptype lazy-JIT runtime: swap `from "arktype"` for
|
|
6
|
+
* `from "@oh-my-pi/omptype/ark"` and nothing else changes. New code should
|
|
7
|
+
* import `@oh-my-pi/omptype` directly.
|
|
8
|
+
*
|
|
9
|
+
* Compatibility affordance: `ArkError` / `ArkErrors` alias `OmpError` /
|
|
10
|
+
* `OmpErrors`. All schema builders, including recursive `scope()`, are
|
|
11
|
+
* re-exported unchanged.
|
|
12
|
+
*/
|
|
13
|
+
import { OmpError, OmpErrors } from "./errors.js";
|
|
14
|
+
export * from "./index.js";
|
|
15
|
+
export const ArkError = OmpError;
|
|
16
|
+
export const ArkErrors = OmpErrors;
|