@oh-my-pi/omptype 17.2.6 → 17.2.7

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 CHANGED
@@ -2,7 +2,22 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [17.2.7] - 2026-08-03
6
+
5
7
  ### Added
6
8
 
7
- - Initial release: ArkType-compatible schema validation with a lazy JIT runtime. Schemas interpret their first two calls and compile a specialized validator via `new Function` on the third, making `type()` construction ~100x cheaper than arktype while beating its hot-path validation speed. Supports the string definition DSL (primitives, literals, unions, arrays, bounds, `number.integer`, `string.url`, inline defaults, value-suffix `?` optionals), object definitions (`"+": "reject"/"delete"`, `"[string]"` index signatures), `type.errors`/`OmpErrors` with per-entry `path`/`problem`, `type.enumerated`, `type.raw`, keyword statics, composition methods (`.or/.and/.array/.pipe/.narrow/.describe/.default/.allows/.assert`), static inference via `typeof schema.infer`, and draft-2020-12 `toJsonSchema()` emission.
8
- - TypeBox-style (`@oh-my-pi/omptype/typebox`) and Zod-style (`@oh-my-pi/omptype/zod`) authoring adapters producing native omptype schemas.
9
+ - 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.
10
+ - 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).
11
+ - Added TypeBox-style (@oh-my-pi/omptype/typebox) and Zod-style (@oh-my-pi/omptype/zod) authoring adapters that produce native omptype schemas.
12
+ - 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.
13
+ - Shipped transpiled ESM and TypeScript declarations in the npm package to support plain Node.js environments, while preserving TS source resolution for Bun consumers.
14
+
15
+ ### Changed
16
+
17
+ - Optimized the lazy JIT compiler to support tuples, refinements, morphs, intersections, instances, and recursive aliases, while reducing schema construction overhead.
18
+
19
+ ### Fixed
20
+
21
+ - Fixed a TypeScript compiler error (TS2589: "type instantiation is excessively deep") when using generic fluent composition methods on nested schemas.
22
+ - Fixed type.raw() results (BaseType) to correctly expose fluent composition methods like .array(), .or(), and .pipe().
23
+ - 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 Bun. Schemas start with a small
4
- interpreter and lazily compile after repeated use, keeping construction cheap
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
- Omptype requires Bun 1.3.14 or newer.
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
- name: "string",
22
- "retries?": "number.integer >= 0",
23
- enabled: "boolean = true",
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
- console.error(result.summary);
35
+ console.error(result.summary);
32
36
  }
33
37
  ```
34
38
 
35
- Schemas are callable and expose `.assert()`, `.allows()`, `.toJsonSchema()`,
36
- `.or()`, `.and()`, `.array()`, `.pipe()`, `.narrow()`, `.describe()`, and
37
- `.default()`.
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
- Its `scope()` export remains available as an alias-free no-op for existing
56
- callers; new code should import `type` directly from `@oh-my-pi/omptype`.
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;