@oh-my-pi/omptype 17.2.7 → 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 +23 -0
- package/dist/js/compile.js +414 -219
- package/dist/js/errors.js +236 -41
- package/dist/js/from-json-schema.js +234 -0
- package/dist/js/index.js +1 -0
- package/dist/js/interp.js +514 -132
- package/dist/js/ir.js +972 -202
- package/dist/js/json-schema.js +73 -34
- package/dist/js/keywords.js +108 -1
- package/dist/js/type.js +2156 -172
- package/dist/js/typebox.js +41 -32
- package/dist/js/zod.js +2 -2
- package/dist/types/compile.d.ts +1 -1
- package/dist/types/errors.d.ts +19 -18
- package/dist/types/from-json-schema.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/infer.d.ts +45 -6
- package/dist/types/interp.d.ts +9 -2
- package/dist/types/ir.d.ts +57 -6
- package/dist/types/json-schema.d.ts +10 -1
- package/dist/types/type.d.ts +324 -48
- package/dist/types/typebox.d.ts +78 -50
- package/package.json +5 -1
- package/src/compile.ts +598 -243
- package/src/errors.ts +247 -49
- package/src/from-json-schema.ts +231 -0
- package/src/index.ts +1 -0
- package/src/infer.ts +107 -32
- package/src/interp.ts +457 -118
- package/src/ir.ts +981 -212
- package/src/json-schema.ts +82 -34
- package/src/keywords.ts +111 -1
- package/src/type.ts +2760 -271
- package/src/typebox.ts +141 -98
- package/src/zod.ts +1 -1
package/dist/types/typebox.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { EmbeddableSchema } from "./ir.js";
|
|
2
|
+
import { type NarrowContext, type Type as OmpType, type ToJsonSchemaOptions } from "./type.js";
|
|
2
3
|
export interface Meta {
|
|
3
4
|
title?: string;
|
|
4
5
|
description?: string;
|
|
@@ -25,7 +26,7 @@ export interface ArrayOpts extends Meta {
|
|
|
25
26
|
uniqueItems?: boolean;
|
|
26
27
|
}
|
|
27
28
|
export interface ObjectOpts extends Meta {
|
|
28
|
-
additionalProperties?: boolean |
|
|
29
|
+
additionalProperties?: boolean | AnySchema;
|
|
29
30
|
}
|
|
30
31
|
declare const OPTIONAL_INNER: unique symbol;
|
|
31
32
|
declare const OBJECT_INFO: unique symbol;
|
|
@@ -45,53 +46,80 @@ interface LegacyTypeBoxCompat<T> {
|
|
|
45
46
|
/** Zod-style compatibility parser used by legacy extensions. */
|
|
46
47
|
safeParse(input: unknown): TypeBoxSafeParseResult<T>;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Erased schema surface accepted anywhere this facade takes a schema, native
|
|
51
|
+
* omptype schemas included (those carry no legacy compat members).
|
|
52
|
+
*
|
|
53
|
+
* Members use method syntax so parameter positions stay bivariant: the typed
|
|
54
|
+
* {@link TTyped} form is invariant in its static type (its `in`/`out`
|
|
55
|
+
* validators are), so a concrete `TString` is not assignable to
|
|
56
|
+
* `TTyped<unknown>`. Erasing here is what keeps `TString`, `TObject<…>` and
|
|
57
|
+
* friends assignable to a plain schema annotation.
|
|
58
|
+
*/
|
|
59
|
+
export interface AnySchema extends EmbeddableSchema {
|
|
60
|
+
(data: unknown): unknown;
|
|
61
|
+
readonly infer: unknown;
|
|
62
|
+
readonly hasSteps: boolean;
|
|
63
|
+
toJsonSchema(options?: ToJsonSchemaOptions): Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Every schema this facade returns: the TypeBox `TSchema` analog. Erased like
|
|
67
|
+
* {@link AnySchema}, plus the legacy compat members builder results carry.
|
|
68
|
+
*/
|
|
69
|
+
export interface TSchema extends AnySchema {
|
|
70
|
+
/** TypeBox compatibility validator used by legacy extension loaders. */
|
|
71
|
+
__validator(data: unknown): unknown;
|
|
72
|
+
/** Zod-style compatibility parser used by legacy extensions. */
|
|
73
|
+
safeParse(input: unknown): TypeBoxSafeParseResult<unknown>;
|
|
74
|
+
}
|
|
75
|
+
/** Schema carrying a statically known type; every `TXxx` alias resolves here. */
|
|
76
|
+
export type TTyped<T> = OmpType<T> & LegacyTypeBoxCompat<T>;
|
|
77
|
+
export type Static<T extends AnySchema> = T["infer"];
|
|
78
|
+
export type TAny = TTyped<unknown>;
|
|
79
|
+
export type TUnknown = TTyped<unknown>;
|
|
80
|
+
export type TNever = TTyped<never>;
|
|
81
|
+
export type TNull = TTyped<null>;
|
|
82
|
+
export type TString = TTyped<string>;
|
|
83
|
+
export type TNumber = TTyped<number>;
|
|
84
|
+
export type TInteger = TTyped<number>;
|
|
85
|
+
export type TBoolean = TTyped<boolean>;
|
|
86
|
+
export type TLiteral<V extends string | number | boolean | null> = TTyped<V>;
|
|
87
|
+
export type TArray<E extends AnySchema> = TTyped<Static<E>[]>;
|
|
88
|
+
export type TTuple<E extends readonly AnySchema[] = readonly AnySchema[]> = TTyped<{
|
|
61
89
|
-readonly [K in keyof E]: Static<E[K]>;
|
|
62
90
|
}>;
|
|
63
|
-
export type TOptional<E extends
|
|
91
|
+
export type TOptional<E extends AnySchema> = TTyped<Static<E> | undefined> & {
|
|
64
92
|
readonly [OPTIONAL_INNER]: E;
|
|
65
93
|
};
|
|
66
|
-
export type TUnion<E extends readonly
|
|
67
|
-
export type TIntersect<E extends readonly
|
|
68
|
-
export type TEnum<E extends readonly (string | number)[] = readonly (string | number)[]> =
|
|
69
|
-
export type TRecord<K extends
|
|
70
|
-
export type TNullable<E extends
|
|
71
|
-
export type TReadonly<E extends
|
|
72
|
-
export type TUnsafe<T = unknown> =
|
|
73
|
-
type OptionalKeys<P extends Record<string,
|
|
94
|
+
export type TUnion<E extends readonly AnySchema[] = readonly AnySchema[]> = TTyped<Static<E[number]>>;
|
|
95
|
+
export type TIntersect<E extends readonly AnySchema[] = readonly AnySchema[]> = TTyped<UnionToIntersection<Static<E[number]>>>;
|
|
96
|
+
export type TEnum<E extends readonly (string | number)[] = readonly (string | number)[]> = TTyped<E[number]>;
|
|
97
|
+
export type TRecord<K extends AnySchema, V extends AnySchema> = TTyped<Record<Extract<Static<K>, PropertyKey>, Static<V>>>;
|
|
98
|
+
export type TNullable<E extends AnySchema> = TTyped<Static<E> | null>;
|
|
99
|
+
export type TReadonly<E extends AnySchema> = TTyped<Readonly<Static<E>>>;
|
|
100
|
+
export type TUnsafe<T = unknown> = TTyped<T>;
|
|
101
|
+
type OptionalKeys<P extends Record<string, AnySchema>> = {
|
|
74
102
|
[K in keyof P]-?: P[K] extends {
|
|
75
|
-
readonly [OPTIONAL_INNER]:
|
|
103
|
+
readonly [OPTIONAL_INNER]: AnySchema;
|
|
76
104
|
} ? K : never;
|
|
77
105
|
}[keyof P];
|
|
78
|
-
type RequiredKeys<P extends Record<string,
|
|
79
|
-
type ObjectStatic<P extends Record<string,
|
|
106
|
+
type RequiredKeys<P extends Record<string, AnySchema>> = Exclude<keyof P, OptionalKeys<P>>;
|
|
107
|
+
type ObjectStatic<P extends Record<string, AnySchema>> = {
|
|
80
108
|
[K in RequiredKeys<P>]: Static<P[K]>;
|
|
81
109
|
} & {
|
|
82
110
|
[K in OptionalKeys<P>]?: Exclude<Static<P[K]>, undefined>;
|
|
83
111
|
};
|
|
84
|
-
export type TObject<P extends Record<string,
|
|
85
|
-
type RequiredProps<P extends Record<string,
|
|
112
|
+
export type TObject<P extends Record<string, AnySchema> = Record<string, AnySchema>> = TTyped<ObjectStatic<P>>;
|
|
113
|
+
type RequiredProps<P extends Record<string, AnySchema>> = {
|
|
86
114
|
[K in keyof P]: P[K] extends TOptional<infer E> ? E : P[K];
|
|
87
115
|
};
|
|
88
116
|
interface RuntimeType<T> extends OmpType<T> {
|
|
89
|
-
[OPTIONAL_INNER]?:
|
|
117
|
+
[OPTIONAL_INNER]?: AnySchema;
|
|
90
118
|
[OBJECT_INFO]?: ObjectInfo;
|
|
91
119
|
describe(description: string): RuntimeType<T>;
|
|
92
120
|
default(value: T | (() => T)): RuntimeType<T>;
|
|
93
|
-
or<
|
|
94
|
-
and<
|
|
121
|
+
or<schema extends AnySchema>(schema: schema): RuntimeType<T | Static<schema>>;
|
|
122
|
+
and<schema extends AnySchema>(schema: schema): RuntimeType<T & Static<schema>>;
|
|
95
123
|
array(): RuntimeType<T[]>;
|
|
96
124
|
atLeastLength(bound: number): RuntimeType<T>;
|
|
97
125
|
atMostLength(bound: number): RuntimeType<T>;
|
|
@@ -102,27 +130,27 @@ interface RuntimeType<T> extends OmpType<T> {
|
|
|
102
130
|
}
|
|
103
131
|
type CompatRuntime<T> = RuntimeType<T> & LegacyTypeBoxCompat<T>;
|
|
104
132
|
type ObjectInfo = {
|
|
105
|
-
props: Record<string,
|
|
106
|
-
additionalProperties?: boolean |
|
|
133
|
+
props: Record<string, AnySchema>;
|
|
134
|
+
additionalProperties?: boolean | AnySchema;
|
|
107
135
|
};
|
|
108
136
|
declare function tString(opts?: StringOpts): TString;
|
|
109
137
|
declare function tLiteral<const V extends string | number | boolean | null>(value: V, opts?: Meta): TLiteral<V>;
|
|
110
138
|
declare function tNever(opts?: Meta): TNever;
|
|
111
|
-
declare function tUnion<const E extends readonly
|
|
112
|
-
declare function tIntersect<const E extends readonly
|
|
139
|
+
declare function tUnion<const E extends readonly AnySchema[]>(schemas: E, opts?: Meta): TUnion<E>;
|
|
140
|
+
declare function tIntersect<const E extends readonly AnySchema[]>(schemas: E, opts?: Meta): TTyped<UnionToIntersection<Static<E[number]>>>;
|
|
113
141
|
type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
|
|
114
|
-
declare function tEnum<const E extends Record<string, string | number> | readonly (string | number)[]>(values: E, opts?: Meta):
|
|
115
|
-
declare function tArray<E extends
|
|
116
|
-
declare function tTuple<const E extends readonly
|
|
117
|
-
declare function tObject<const P extends Record<string,
|
|
118
|
-
declare function tRecord<K extends
|
|
119
|
-
declare function tOptional<E extends
|
|
120
|
-
declare function tNullable<E extends
|
|
121
|
-
declare function tPartial<P extends Record<string,
|
|
122
|
-
declare function tRequired<P extends Record<string,
|
|
123
|
-
declare function tPick<P extends Record<string,
|
|
124
|
-
declare function tOmit<P extends Record<string,
|
|
125
|
-
declare function tComposite<const E extends readonly TObject<Record<string,
|
|
142
|
+
declare function tEnum<const E extends Record<string, string | number> | readonly (string | number)[]>(values: E, opts?: Meta): TTyped<E extends readonly (infer V)[] ? V : E[keyof E]>;
|
|
143
|
+
declare function tArray<E extends AnySchema>(item: E, opts?: ArrayOpts): TArray<E>;
|
|
144
|
+
declare function tTuple<const E extends readonly AnySchema[]>(items: E, opts?: Meta): TTuple<E>;
|
|
145
|
+
declare function tObject<const P extends Record<string, AnySchema>>(properties: P, opts?: ObjectOpts): TObject<P>;
|
|
146
|
+
declare function tRecord<K extends AnySchema, V extends AnySchema>(key: K, value: V, opts?: Meta): TRecord<K, V>;
|
|
147
|
+
declare function tOptional<E extends AnySchema>(schema: E, opts?: Meta): TOptional<E>;
|
|
148
|
+
declare function tNullable<E extends AnySchema>(schema: E, opts?: Meta): TTyped<Static<E> | null>;
|
|
149
|
+
declare function tPartial<P extends Record<string, AnySchema>>(schema: TObject<P>): TTyped<Partial<ObjectStatic<P>>>;
|
|
150
|
+
declare function tRequired<P extends Record<string, AnySchema>>(schema: TObject<P>): TObject<RequiredProps<P>>;
|
|
151
|
+
declare function tPick<P extends Record<string, AnySchema>, const K extends readonly (keyof P)[]>(schema: TObject<P>, keys: K): TObject<Pick<P, K[number]>>;
|
|
152
|
+
declare function tOmit<P extends Record<string, AnySchema>, const K extends readonly (keyof P)[]>(schema: TObject<P>, keys: K): TObject<Omit<P, K[number]>>;
|
|
153
|
+
declare function tComposite<const E extends readonly TObject<Record<string, AnySchema>>[]>(schemas: E, opts?: ObjectOpts): TTyped<UnionToIntersection<Static<E[number]>>>;
|
|
126
154
|
declare function tUnsafe<T = unknown>(_jsonSchema?: Record<string, unknown>): TUnsafe<T>;
|
|
127
155
|
export declare const Type: {
|
|
128
156
|
readonly String: typeof tString;
|
|
@@ -143,7 +171,7 @@ export declare const Type: {
|
|
|
143
171
|
readonly Record: typeof tRecord;
|
|
144
172
|
readonly Optional: typeof tOptional;
|
|
145
173
|
readonly Nullable: typeof tNullable;
|
|
146
|
-
readonly Readonly: <E extends
|
|
174
|
+
readonly Readonly: <E extends AnySchema>(schema: E) => TReadonly<E>;
|
|
147
175
|
readonly Partial: typeof tPartial;
|
|
148
176
|
readonly Required: typeof tRequired;
|
|
149
177
|
readonly Pick: typeof tPick;
|
|
@@ -172,7 +200,7 @@ declare const _default: {
|
|
|
172
200
|
readonly Record: typeof tRecord;
|
|
173
201
|
readonly Optional: typeof tOptional;
|
|
174
202
|
readonly Nullable: typeof tNullable;
|
|
175
|
-
readonly Readonly: <E extends
|
|
203
|
+
readonly Readonly: <E extends AnySchema>(schema: E) => TReadonly<E>;
|
|
176
204
|
readonly Partial: typeof tPartial;
|
|
177
205
|
readonly Required: typeof tRequired;
|
|
178
206
|
readonly Pick: typeof tPick;
|
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.8",
|
|
5
5
|
"description": "ArkType-compatible runtime schema validation with lazy JIT compilation",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -32,8 +32,12 @@
|
|
|
32
32
|
"bench": "bun bench/bench.ts"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
+
"@ark/attest": "0.56.3",
|
|
36
|
+
"@ark/schema": "0.56.2",
|
|
37
|
+
"@ark/util": "0.56.2",
|
|
35
38
|
"@sinclair/typebox": "^0.34.0",
|
|
36
39
|
"@types/bun": "^1.3.14",
|
|
40
|
+
"arkregex": "0.0.8",
|
|
37
41
|
"arktype": "2.2.3",
|
|
38
42
|
"zod": "^4"
|
|
39
43
|
},
|