@oh-my-pi/omptype 17.2.9 → 17.2.10
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 +6 -0
- package/README.md +15 -15
- package/dist/js/type.js +25 -0
- package/dist/types/type.d.ts +10 -0
- package/package.json +2 -3
- package/src/type.ts +37 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -103,21 +103,21 @@ library's public boolean path after 20,000 warmup calls.
|
|
|
103
103
|
|
|
104
104
|
Representative result on an Apple M4 Max with Darwin 25.6.0 and Bun 1.3.14:
|
|
105
105
|
|
|
106
|
-
| Phase | omptype | ArkType |
|
|
107
|
-
| ----------------------- | ---------: | ----------------: |
|
|
108
|
-
| Compile `type()` | **509ns** | 271.08µs (532.3×) |
|
|
109
|
-
| Compile + 2 validations | **2.18µs** | 526.46µs (241.5×) |
|
|
110
|
-
|
|
111
|
-
| Hot workload | omptype | ArkType |
|
|
112
|
-
| -------------------------- | -------: | --------------: | --------------: |
|
|
113
|
-
| `flat-small` | **25ns** | 5.10µs (203.7×) |
|
|
114
|
-
| `enum-union` | **27ns** | 4.92µs (185.0×) |
|
|
115
|
-
| `nested-arrays` | **29ns** | 4.80µs (163.0×) |
|
|
116
|
-
| `strict-defaults` | **40ns** | 4.85µs (122.1×) |
|
|
117
|
-
| `delete-extras` | **22ns** | 4.12µs (191.6×) |
|
|
118
|
-
| `record-mixed` | **43ns** | 4.32µs (100.4×) |
|
|
119
|
-
| `deep-message` | **31ns** | 6.32µs (202.5×) |
|
|
120
|
-
| `nested-arrays` valid-only | **15ns** | 28ns (1.8×) |
|
|
106
|
+
| Phase | omptype | ArkType | TypeBox |
|
|
107
|
+
| ----------------------- | ---------: | ----------------: | --------------: |
|
|
108
|
+
| Compile `type()` | **509ns** | 271.08µs (532.3×) | 27.36µs (53.7×) |
|
|
109
|
+
| Compile + 2 validations | **2.18µs** | 526.46µs (241.5×) | 46.90µs (21.5×) |
|
|
110
|
+
|
|
111
|
+
| Hot workload | omptype | ArkType | TypeBox |
|
|
112
|
+
| -------------------------- | -------: | --------------: | --------------: |
|
|
113
|
+
| `flat-small` | **25ns** | 5.10µs (203.7×) | 1.23µs (49.2×) |
|
|
114
|
+
| `enum-union` | **27ns** | 4.92µs (185.0×) | 2.20µs (83.0×) |
|
|
115
|
+
| `nested-arrays` | **29ns** | 4.80µs (163.0×) | 3.01µs (102.2×) |
|
|
116
|
+
| `strict-defaults` | **40ns** | 4.85µs (122.1×) | 4.92µs (123.9×) |
|
|
117
|
+
| `delete-extras` | **22ns** | 4.12µs (191.6×) | 2.07µs (96.0×) |
|
|
118
|
+
| `record-mixed` | **43ns** | 4.32µs (100.4×) | 3.35µs (77.9×) |
|
|
119
|
+
| `deep-message` | **31ns** | 6.32µs (202.5×) | 5.13µs (164.5×) |
|
|
120
|
+
| `nested-arrays` valid-only | **15ns** | 28ns (1.8×) | 45ns (2.9×) |
|
|
121
121
|
|
|
122
122
|
Lower times are better. Parenthetical values show how many times slower each
|
|
123
123
|
candidate was than omptype in this run. Results vary with hardware, runtime,
|
package/dist/js/type.js
CHANGED
|
@@ -2580,6 +2580,26 @@ function naryStatics(resolve) {
|
|
|
2580
2580
|
return buildOr(definitions);
|
|
2581
2581
|
}
|
|
2582
2582
|
type.or = or;
|
|
2583
|
+
/** Build an array schema from an element definition. */
|
|
2584
|
+
function array(definition) {
|
|
2585
|
+
return type(definition).array();
|
|
2586
|
+
}
|
|
2587
|
+
type.array = array;
|
|
2588
|
+
/** Build a union from a runtime array of definitions. */
|
|
2589
|
+
function union(definitions) {
|
|
2590
|
+
return buildOr(definitions);
|
|
2591
|
+
}
|
|
2592
|
+
type.union = union;
|
|
2593
|
+
/** Build a tuple schema from a runtime array of definitions. */
|
|
2594
|
+
function tuple(definitions) {
|
|
2595
|
+
return type(definitions);
|
|
2596
|
+
}
|
|
2597
|
+
type.tuple = tuple;
|
|
2598
|
+
/** Build an open record schema from key and value definitions. */
|
|
2599
|
+
function record(key, value) {
|
|
2600
|
+
return type.keywords.Record(key, value);
|
|
2601
|
+
}
|
|
2602
|
+
type.record = record;
|
|
2583
2603
|
/** Build an intersection from zero or more definitions. */
|
|
2584
2604
|
function and(...definitions) {
|
|
2585
2605
|
return buildAnd(definitions);
|
|
@@ -2769,6 +2789,11 @@ function naryStatics(resolve) {
|
|
|
2769
2789
|
return makeType(ir, [], {});
|
|
2770
2790
|
}
|
|
2771
2791
|
type.enumerated = enumerated;
|
|
2792
|
+
/** Build a literal union from a runtime array. */
|
|
2793
|
+
function enumeration(values) {
|
|
2794
|
+
return enumerated(...values);
|
|
2795
|
+
}
|
|
2796
|
+
type.enumeration = enumeration;
|
|
2772
2797
|
/** Enumerate an enum-like object's forward values, excluding numeric reverse mappings. */
|
|
2773
2798
|
// biome-ignore lint/suspicious/noShadowRestrictedNames: Object.prototype.valueOf method name API
|
|
2774
2799
|
function valueOf(values) {
|
package/dist/types/type.d.ts
CHANGED
|
@@ -400,6 +400,14 @@ export declare namespace type {
|
|
|
400
400
|
export type errors = OmpErrors;
|
|
401
401
|
/** Build a union from zero or more definitions. */
|
|
402
402
|
export function or<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryOrOutput<definitions>, NaryOrInput<definitions>>;
|
|
403
|
+
/** Build an array schema from an element definition. */
|
|
404
|
+
export function array<const definition>(definition: definition): FluentType<InferDef<definition>[], InferDefIn<definition>[]>;
|
|
405
|
+
/** Build a union from a runtime array of definitions. */
|
|
406
|
+
export function union<const definitions extends readonly unknown[]>(definitions: definitions): FluentType<NaryOrOutput<definitions>, NaryOrInput<definitions>>;
|
|
407
|
+
/** Build a tuple schema from a runtime array of definitions. */
|
|
408
|
+
export function tuple<const definitions extends readonly unknown[]>(definitions: definitions): FluentType<InferDef<definitions>, InferDefIn<definitions>>;
|
|
409
|
+
/** Build an open record schema from key and value definitions. */
|
|
410
|
+
export function record<const key, const value>(key: key, value: value): FluentType<Record<Extract<InferDef<key>, PropertyKey>, InferDef<value>>, Record<Extract<InferDefIn<key>, PropertyKey>, InferDefIn<value>>>;
|
|
403
411
|
/** Build an intersection from zero or more definitions. */
|
|
404
412
|
export function and<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryAndOutput<definitions>, NaryAndInput<definitions>>;
|
|
405
413
|
/** Right-biased object merge over zero or more definitions. */
|
|
@@ -463,6 +471,8 @@ export declare namespace type {
|
|
|
463
471
|
export function unit<const value>(value: value): FluentType<value>;
|
|
464
472
|
/** Union of literal values from a runtime array. */
|
|
465
473
|
export function enumerated<const values extends readonly unknown[]>(...values: values): FluentType<values[number]>;
|
|
474
|
+
/** Build a literal union from a runtime array. */
|
|
475
|
+
export function enumeration<const values extends readonly unknown[]>(values: values): FluentType<values[number]>;
|
|
466
476
|
/** Enumerate an enum-like object's forward values, excluding numeric reverse mappings. */
|
|
467
477
|
export function valueOf<const values extends Record<PropertyKey, unknown>>(values: values): FluentType<values[keyof values]>;
|
|
468
478
|
/** Fluent first-match dispatcher, also exported as standalone `match`. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/omptype",
|
|
4
|
-
"version": "17.2.
|
|
4
|
+
"version": "17.2.10",
|
|
5
5
|
"description": "ArkType-compatible runtime schema validation with lazy JIT compilation",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"@sinclair/typebox": "^0.34.0",
|
|
39
39
|
"@types/bun": "^1.3.14",
|
|
40
40
|
"arkregex": "0.0.8",
|
|
41
|
-
"arktype": "2.2.3"
|
|
42
|
-
"zod": "^4"
|
|
41
|
+
"arktype": "2.2.3"
|
|
43
42
|
},
|
|
44
43
|
"engines": {
|
|
45
44
|
"node": ">=20",
|
package/src/type.ts
CHANGED
|
@@ -3302,6 +3302,38 @@ export namespace type {
|
|
|
3302
3302
|
return buildOr<NaryOrOutput<definitions>, NaryOrInput<definitions>>(definitions);
|
|
3303
3303
|
}
|
|
3304
3304
|
|
|
3305
|
+
/** Build an array schema from an element definition. */
|
|
3306
|
+
export function array<const definition>(
|
|
3307
|
+
definition: definition,
|
|
3308
|
+
): FluentType<InferDef<definition>[], InferDefIn<definition>[]> {
|
|
3309
|
+
return type(definition).array();
|
|
3310
|
+
}
|
|
3311
|
+
|
|
3312
|
+
/** Build a union from a runtime array of definitions. */
|
|
3313
|
+
export function union<const definitions extends readonly unknown[]>(
|
|
3314
|
+
definitions: definitions,
|
|
3315
|
+
): FluentType<NaryOrOutput<definitions>, NaryOrInput<definitions>> {
|
|
3316
|
+
return buildOr<NaryOrOutput<definitions>, NaryOrInput<definitions>>(definitions);
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
/** Build a tuple schema from a runtime array of definitions. */
|
|
3320
|
+
export function tuple<const definitions extends readonly unknown[]>(
|
|
3321
|
+
definitions: definitions,
|
|
3322
|
+
): FluentType<InferDef<definitions>, InferDefIn<definitions>> {
|
|
3323
|
+
return type(definitions);
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
/** Build an open record schema from key and value definitions. */
|
|
3327
|
+
export function record<const key, const value>(
|
|
3328
|
+
key: key,
|
|
3329
|
+
value: value,
|
|
3330
|
+
): FluentType<
|
|
3331
|
+
Record<Extract<InferDef<key>, PropertyKey>, InferDef<value>>,
|
|
3332
|
+
Record<Extract<InferDefIn<key>, PropertyKey>, InferDefIn<value>>
|
|
3333
|
+
> {
|
|
3334
|
+
return keywords.Record(key, value);
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3305
3337
|
/** Build an intersection from zero or more definitions. */
|
|
3306
3338
|
export function and<const definitions extends readonly unknown[]>(
|
|
3307
3339
|
...definitions: definitions
|
|
@@ -3566,6 +3598,11 @@ export namespace type {
|
|
|
3566
3598
|
return makeType<values[number]>(ir, [], {});
|
|
3567
3599
|
}
|
|
3568
3600
|
|
|
3601
|
+
/** Build a literal union from a runtime array. */
|
|
3602
|
+
export function enumeration<const values extends readonly unknown[]>(values: values): FluentType<values[number]> {
|
|
3603
|
+
return enumerated(...values);
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3569
3606
|
/** Enumerate an enum-like object's forward values, excluding numeric reverse mappings. */
|
|
3570
3607
|
// biome-ignore lint/suspicious/noShadowRestrictedNames: Object.prototype.valueOf method name API
|
|
3571
3608
|
export function valueOf<const values extends Record<PropertyKey, unknown>>(
|