@linxiraos/pi-omptype 1.0.0 → 1.0.2
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 +17 -2
- package/README.md +7 -7
- package/package.json +61 -69
- package/src/type.ts +36 -0
- package/src/typebox.ts +7 -2
- package/dist/js/ark.js +0 -16
- package/dist/js/compile.js +0 -942
- package/dist/js/errors.js +0 -394
- package/dist/js/from-json-schema.js +0 -234
- package/dist/js/index.js +0 -13
- package/dist/js/infer.js +0 -2
- package/dist/js/interp.js +0 -858
- package/dist/js/ir.js +0 -1700
- package/dist/js/json-schema.js +0 -312
- package/dist/js/keywords.js +0 -340
- package/dist/js/type.js +0 -3087
- package/dist/js/typebox.js +0 -368
- package/dist/js/zod.js +0 -269
- package/dist/types/ark.d.ts +0 -18
- package/dist/types/compile.d.ts +0 -7
- package/dist/types/errors.d.ts +0 -100
- package/dist/types/from-json-schema.d.ts +0 -9
- package/dist/types/index.d.ts +0 -13
- package/dist/types/infer.d.ts +0 -165
- package/dist/types/interp.d.ts +0 -33
- package/dist/types/ir.d.ts +0 -235
- package/dist/types/json-schema.d.ts +0 -22
- package/dist/types/keywords.d.ts +0 -7
- package/dist/types/type.d.ts +0 -575
- package/dist/types/typebox.d.ts +0 -212
- package/dist/types/zod.d.ts +0 -100
package/CHANGELOG.md
CHANGED
|
@@ -2,11 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [1.0.2] - 2026-08-15
|
|
6
|
+
|
|
7
|
+
## [17.3.1] - 2026-08-13
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Fixed TypeBox adapter omitting pattern, non-URL format, and multipleOf constraints from the emitted JSON Schema.
|
|
12
|
+
|
|
13
|
+
## [17.3.0] - 2026-08-13
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Added `type.withJsonSchema(schema, json)` to wrap a validation-only schema, ensuring JSON Schema emission yields the provided `json` verbatim even when nested inside objects, arrays, or unions. Schemas with defaults or output-changing morphs are rejected to prevent transformed outputs from being discarded.
|
|
18
|
+
|
|
5
19
|
## [17.2.10] - 2026-08-06
|
|
6
20
|
|
|
7
21
|
### Changed
|
|
8
22
|
|
|
9
|
-
- Reimplemented the Zod compatibility facade (`@
|
|
23
|
+
- Reimplemented the Zod compatibility facade (`@linxiraos/pi-omptype/zod`) to run purely on internal mechanics, removing the dependency on `zod`.
|
|
10
24
|
|
|
11
25
|
## [17.2.9] - 2026-08-05
|
|
12
26
|
|
|
@@ -43,7 +57,7 @@
|
|
|
43
57
|
|
|
44
58
|
- 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.
|
|
45
59
|
- 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).
|
|
46
|
-
- Added TypeBox-style (@
|
|
60
|
+
- Added TypeBox-style (@linxiraos/pi-omptype/typebox) and Zod-style (@linxiraos/pi-omptype/zod) authoring adapters that produce native omptype schemas.
|
|
47
61
|
- 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.
|
|
48
62
|
- Shipped transpiled ESM and TypeScript declarations in the npm package to support plain Node.js environments, while preserving TS source resolution for Bun consumers.
|
|
49
63
|
|
|
@@ -56,3 +70,4 @@
|
|
|
56
70
|
- Fixed a TypeScript compiler error (TS2589: "type instantiation is excessively deep") when using generic fluent composition methods on nested schemas.
|
|
57
71
|
- Fixed type.raw() results (BaseType) to correctly expose fluent composition methods like .array(), .or(), and .pipe().
|
|
58
72
|
- Fixed an issue in the TypeBox adapter where keyword-carrying schemas (e.g., uniqueItems arrays) would throw an error during JSON Schema emission.
|
|
73
|
+
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @linxiraos/pi-omptype
|
|
2
2
|
|
|
3
3
|
Fast, ArkType-compatible schema validation for JavaScript and TypeScript.
|
|
4
4
|
Schemas start with a small interpreter and lazily compile after repeated use,
|
|
@@ -7,9 +7,9 @@ keeping construction cheap without giving up hot-path validation speed.
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @linxiraos/pi-omptype
|
|
11
11
|
# or
|
|
12
|
-
bun add @
|
|
12
|
+
bun add @linxiraos/pi-omptype
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Runs on Node 20+ (published as compiled ESM with bundled type declarations)
|
|
@@ -19,7 +19,7 @@ export condition). No runtime dependencies.
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import { type } from "@
|
|
22
|
+
import { type } from "@linxiraos/pi-omptype";
|
|
23
23
|
|
|
24
24
|
const Config = type({
|
|
25
25
|
name: "string",
|
|
@@ -74,8 +74,8 @@ options.
|
|
|
74
74
|
TypeBox-style and Zod-style builders produce native omptype schemas:
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
-
import { Type, type Static } from "@
|
|
78
|
-
import { z } from "@
|
|
77
|
+
import { Type, type Static } from "@linxiraos/pi-omptype/typebox";
|
|
78
|
+
import { z } from "@linxiraos/pi-omptype/zod";
|
|
79
79
|
|
|
80
80
|
const TypeBoxUser = Type.Object({ name: Type.String() });
|
|
81
81
|
type TypeBoxUser = Static<typeof TypeBoxUser>;
|
|
@@ -84,7 +84,7 @@ const ZodUser = z.object({ name: z.string() });
|
|
|
84
84
|
const user = ZodUser.parse({ name: "Ada" });
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
`@
|
|
87
|
+
`@linxiraos/pi-omptype/ark` provides the repository's ArkType compatibility facade
|
|
88
88
|
and re-exports the same `type` and `scope` implementations.
|
|
89
89
|
|
|
90
90
|
## Performance
|
package/package.json
CHANGED
|
@@ -1,71 +1,63 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"default": "./dist/js/*.js"
|
|
64
|
-
},
|
|
65
|
-
"./*.js": {
|
|
66
|
-
"types": "./dist/types/*.d.ts",
|
|
67
|
-
"bun": "./src/*.ts",
|
|
68
|
-
"default": "./dist/js/*.js"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@linxiraos/pi-omptype",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "ArkType-compatible runtime schema validation with lazy JIT compilation",
|
|
6
|
+
"homepage": "https://omp.sh",
|
|
7
|
+
"author": "Can Boluk",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
|
|
12
|
+
"directory": "packages/omptype"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/can1357/oh-my-pi/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"schema",
|
|
19
|
+
"validation",
|
|
20
|
+
"arktype",
|
|
21
|
+
"jit"
|
|
22
|
+
],
|
|
23
|
+
"main": "./src/index.ts",
|
|
24
|
+
"types": "./src/index.ts",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"check": "biome check . && bun run check:types",
|
|
27
|
+
"check:types": "tsgo -p tsconfig.json --noEmit",
|
|
28
|
+
"lint": "biome lint .",
|
|
29
|
+
"fix": "biome check --write --unsafe .",
|
|
30
|
+
"fmt": "biome format --write .",
|
|
31
|
+
"test": "bun test --parallel",
|
|
32
|
+
"bench": "bun bench/bench.ts"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@ark/attest": "0.56.3",
|
|
36
|
+
"@ark/schema": "0.56.2",
|
|
37
|
+
"@ark/util": "0.56.2",
|
|
38
|
+
"@sinclair/typebox": "^0.34.0",
|
|
39
|
+
"@types/bun": "catalog:",
|
|
40
|
+
"arkregex": "0.0.8",
|
|
41
|
+
"arktype": "2.2.3"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=20",
|
|
45
|
+
"bun": ">=1.3.14"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"src",
|
|
49
|
+
"README.md",
|
|
50
|
+
"CHANGELOG.md"
|
|
51
|
+
],
|
|
52
|
+
"exports": {
|
|
53
|
+
".": {
|
|
54
|
+
"types": "./src/index.ts",
|
|
55
|
+
"import": "./src/index.ts"
|
|
56
|
+
},
|
|
57
|
+
"./*": {
|
|
58
|
+
"types": "./src/*.ts",
|
|
59
|
+
"import": "./src/*.ts"
|
|
60
|
+
},
|
|
61
|
+
"./*.js": "./src/*.ts"
|
|
62
|
+
}
|
|
71
63
|
}
|
package/src/type.ts
CHANGED
|
@@ -3675,6 +3675,42 @@ export namespace type {
|
|
|
3675
3675
|
export function raw(def: unknown): BaseType {
|
|
3676
3676
|
return makeType(parseDef(def), [], {}) as unknown as BaseType;
|
|
3677
3677
|
}
|
|
3678
|
+
|
|
3679
|
+
/**
|
|
3680
|
+
* Return a validation-only schema that emits `json` verbatim — even when
|
|
3681
|
+
* embedded in an object, array, or union.
|
|
3682
|
+
*
|
|
3683
|
+
* A `.toJsonSchema()` method override cannot survive nesting: a parent schema
|
|
3684
|
+
* emits each child's IR directly and never calls the child's method, so the
|
|
3685
|
+
* override silently disappears from the wire schema. This stores the override
|
|
3686
|
+
* on the IR instead.
|
|
3687
|
+
*
|
|
3688
|
+
* # Errors
|
|
3689
|
+
*
|
|
3690
|
+
* Throws when `schema` has a default or output-changing morph/pipe. A refine
|
|
3691
|
+
* can preserve validation and the input value, but silently discarding a
|
|
3692
|
+
* transformed output would violate the returned {@link Type}.
|
|
3693
|
+
*/
|
|
3694
|
+
export function withJsonSchema<t, i = t>(schema: Type<t, i>, json: Record<string, unknown>): Type<t, i> {
|
|
3695
|
+
const internal = schema as unknown as InternalType;
|
|
3696
|
+
if (internal.hasDefault || hasMorph(internal.ir) || internal[kSteps].some(step => step.kind === "pipe")) {
|
|
3697
|
+
throw new OmpTypeError("type.withJsonSchema cannot wrap schemas with defaults or output-changing morphs");
|
|
3698
|
+
}
|
|
3699
|
+
return makeType<t, i>(
|
|
3700
|
+
{
|
|
3701
|
+
k: "refine",
|
|
3702
|
+
base: { k: "unknown" },
|
|
3703
|
+
pred: value => {
|
|
3704
|
+
const result = schema(value);
|
|
3705
|
+
return result instanceof OmpErrors ? result : true;
|
|
3706
|
+
},
|
|
3707
|
+
expected: schema.expression,
|
|
3708
|
+
json: { ...json },
|
|
3709
|
+
},
|
|
3710
|
+
[],
|
|
3711
|
+
{},
|
|
3712
|
+
);
|
|
3713
|
+
}
|
|
3678
3714
|
}
|
|
3679
3715
|
|
|
3680
3716
|
// Reserved words cannot be declared as namespace bindings, but ArkType exposes
|
package/src/typebox.ts
CHANGED
|
@@ -220,7 +220,11 @@ function tString(opts?: StringOpts): TString {
|
|
|
220
220
|
const valid = formatPredicate(format);
|
|
221
221
|
schema = schema.narrow((value, ctx) => valid(value) || ctx.mustBe(`a string in ${format} format`));
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
const result = applyMeta(schema, opts);
|
|
224
|
+
const keywords: Record<string, unknown> = {};
|
|
225
|
+
if (opts?.pattern !== undefined) keywords.pattern = opts.pattern;
|
|
226
|
+
if (opts?.format !== undefined) keywords.format = opts.format === "url" ? "uri" : opts.format;
|
|
227
|
+
return opts?.pattern !== undefined || opts?.format !== undefined ? withJsonSchemaKeywords(result, keywords) : result;
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
function formatPredicate(format: string): (value: string) => boolean {
|
|
@@ -290,7 +294,8 @@ function tNumber(opts?: NumberOpts, integer = false): TNumber {
|
|
|
290
294
|
);
|
|
291
295
|
});
|
|
292
296
|
}
|
|
293
|
-
|
|
297
|
+
const result = applyMeta(schema, opts);
|
|
298
|
+
return opts?.multipleOf !== undefined ? withJsonSchemaKeywords(result, { multipleOf: opts.multipleOf }) : result;
|
|
294
299
|
}
|
|
295
300
|
|
|
296
301
|
function tLiteral<const V extends string | number | boolean | null>(value: V, opts?: Meta): TLiteral<V> {
|
package/dist/js/ark.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ArkType compatibility facade — `@linxiraos/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 "@linxiraos/pi-omptype/ark"` and nothing else changes. New code should
|
|
7
|
-
* import `@linxiraos/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;
|