@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 +17 -2
- package/README.md +83 -14
- package/dist/js/ark.js +16 -0
- package/dist/js/compile.js +747 -0
- package/dist/js/errors.js +199 -0
- package/dist/js/index.js +12 -0
- package/dist/js/infer.js +2 -0
- package/dist/js/interp.js +476 -0
- package/dist/js/ir.js +930 -0
- package/dist/js/json-schema.js +273 -0
- package/dist/js/keywords.js +233 -0
- package/dist/js/type.js +1078 -0
- package/dist/js/typebox.js +346 -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 +51 -15
- package/dist/types/index.d.ts +3 -4
- package/dist/types/infer.d.ts +107 -30
- package/dist/types/interp.d.ts +5 -3
- package/dist/types/ir.d.ts +76 -7
- package/dist/types/json-schema.d.ts +6 -1
- package/dist/types/keywords.d.ts +7 -0
- package/dist/types/type.d.ts +238 -49
- package/dist/types/zod.d.ts +1 -1
- package/package.json +20 -8
- package/src/ark.ts +4 -14
- package/src/compile.ts +432 -54
- package/src/errors.ts +146 -34
- package/src/index.ts +3 -4
- package/src/infer.ts +284 -77
- package/src/interp.ts +153 -9
- package/src/ir.ts +636 -89
- package/src/json-schema.ts +109 -14
- package/src/keywords.ts +270 -0
- package/src/type.ts +1302 -147
- package/src/typebox.ts +1 -1
- package/src/zod.ts +40 -27
package/dist/types/type.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { OmpErrors } from "./errors.js";
|
|
2
|
-
import type { InferDef, InferObjectLiteral, InferString } from "./infer.js";
|
|
3
|
-
import { type Def, hasMorph, type IR, IR_BRAND } from "./ir.js";
|
|
1
|
+
import { type ErrorConfig, OmpErrors } from "./errors.js";
|
|
2
|
+
import type { InferDef, InferDefIn, InferObjectLiteral, InferString } from "./infer.js";
|
|
3
|
+
import { type Constructor, type Def, hasMorph, type IR, IR_BRAND } from "./ir.js";
|
|
4
|
+
import { type JsonSchemaOptions } from "./json-schema.js";
|
|
4
5
|
/** Context passed to `.narrow()` / `.pipe()` callbacks. */
|
|
5
6
|
export interface NarrowContext {
|
|
6
7
|
/** Record `must be <expectation>` and signal failure. */
|
|
@@ -8,20 +9,39 @@ export interface NarrowContext {
|
|
|
8
9
|
/** Record a custom problem and signal failure. */
|
|
9
10
|
reject(problem: string): false;
|
|
10
11
|
}
|
|
11
|
-
/**
|
|
12
|
-
export interface
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}) => unknown;
|
|
12
|
+
/** Schema metadata and validation-message overrides accepted by `.configure()`. */
|
|
13
|
+
export interface SchemaConfig extends ErrorConfig {
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Options accepted by `Type.toJsonSchema`. */
|
|
17
|
+
export interface ToJsonSchemaOptions extends JsonSchemaOptions {
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
declare const brand: unique symbol;
|
|
20
|
+
/** Inference-only nominal brand attached by `.brand(name)`. */
|
|
21
|
+
export type Brand<t, name extends string> = t & {
|
|
22
|
+
readonly [brand]: name;
|
|
23
|
+
};
|
|
24
|
+
interface SchemaInference<out t, i = t> {
|
|
20
25
|
readonly [IR_BRAND]: true;
|
|
21
26
|
readonly infer: t;
|
|
27
|
+
readonly inferIn: i;
|
|
28
|
+
}
|
|
29
|
+
/** Property descriptor exposed by object schemas and consumed by `.map()`. */
|
|
30
|
+
export interface TypeProperty {
|
|
31
|
+
readonly kind: "required" | "optional";
|
|
32
|
+
readonly key: PropertyKey;
|
|
33
|
+
readonly value: FluentType<unknown>;
|
|
34
|
+
readonly default?: unknown;
|
|
35
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
36
|
+
}
|
|
37
|
+
/** Structural node returned by `.select()`. */
|
|
38
|
+
export interface SelectedNode {
|
|
39
|
+
readonly kind: string;
|
|
40
|
+
readonly node: IR;
|
|
41
|
+
readonly unit?: unknown;
|
|
22
42
|
}
|
|
23
43
|
/** A compiled schema: callable validator plus composition methods. */
|
|
24
|
-
export interface Type<out t = unknown> {
|
|
44
|
+
export interface Type<out t = unknown, i = t> {
|
|
25
45
|
(data: unknown): t | OmpErrors;
|
|
26
46
|
readonly [IR_BRAND]: true;
|
|
27
47
|
/** Structural IR (base type; runtime steps live in `steps`). */
|
|
@@ -36,65 +56,234 @@ export interface Type<out t = unknown> {
|
|
|
36
56
|
/** Inference-only output type (no runtime value). */
|
|
37
57
|
readonly infer: t;
|
|
38
58
|
/** Inference-only input type (no runtime value). */
|
|
39
|
-
readonly inferIn:
|
|
59
|
+
readonly inferIn: i;
|
|
40
60
|
/** Structural + narrow check without running pipes. */
|
|
41
|
-
allows(data: unknown): data is
|
|
61
|
+
allows(data: unknown): data is i;
|
|
42
62
|
/** Validate and return output, throwing `TraversalError` on failure. */
|
|
43
63
|
assert(data: unknown): t;
|
|
44
|
-
/**
|
|
64
|
+
/** Validate a statically typed input and return its output. */
|
|
65
|
+
from(data: i): t;
|
|
66
|
+
/** JSON Schema for this schema's structural base. */
|
|
45
67
|
toJsonSchema(options?: ToJsonSchemaOptions): Record<string, unknown>;
|
|
46
68
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
describe(description: string): FluentType<t>;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
or<
|
|
69
|
+
type MergeTypes<left, right> = left extends object ? right extends object ? Omit<left, keyof right> & right : right : right;
|
|
70
|
+
interface FluentMethods<t, i> {
|
|
71
|
+
describe(description: string): FluentType<t, i>;
|
|
72
|
+
configure(config: SchemaConfig): FluentType<t, i>;
|
|
73
|
+
default(value: t | (() => t)): FluentType<t, i>;
|
|
74
|
+
optional(): readonly [SchemaInference<t, i>, "?"];
|
|
75
|
+
or<r, ri>(def: SchemaInference<r, ri>): FluentType<t | r, i | ri>;
|
|
76
|
+
or<const def extends string>(def: def): FluentType<t | InferString<def>, i | InferString<def>>;
|
|
77
|
+
or<const def extends Record<string, unknown>>(def: def): FluentType<t | InferObjectLiteral<def>, i | InferObjectLiteral<def>>;
|
|
54
78
|
or(def: Def): FluentType<unknown>;
|
|
55
|
-
and<r>(def: SchemaInference<r>): FluentType<t & r>;
|
|
56
|
-
and<const def extends Record<string, unknown>>(def: def): FluentType<t & InferObjectLiteral<def>>;
|
|
79
|
+
and<r, ri>(def: SchemaInference<r, ri>): FluentType<t & r, i & ri>;
|
|
80
|
+
and<const def extends Record<string, unknown>>(def: def): FluentType<t & InferObjectLiteral<def>, i & InferObjectLiteral<def>>;
|
|
57
81
|
and(def: Def): FluentType<unknown>;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
equals(def: Def): boolean;
|
|
83
|
+
ifEquals(def: Def): FluentType<t, i> | undefined;
|
|
84
|
+
extends(def: Def): boolean;
|
|
85
|
+
overlaps(def: Def): boolean;
|
|
86
|
+
distribute<r>(mapper: (branch: FluentType<unknown>) => SchemaInference<r>): FluentType<r>;
|
|
87
|
+
select(kind: string): readonly SelectedNode[];
|
|
88
|
+
array(): FluentType<t[], i[]>;
|
|
89
|
+
atLeastLength(bound: number): FluentType<t, i>;
|
|
90
|
+
atMostLength(bound: number): FluentType<t, i>;
|
|
91
|
+
moreThanLength(bound: number): FluentType<t, i>;
|
|
92
|
+
lessThanLength(bound: number): FluentType<t, i>;
|
|
93
|
+
exactlyLength(bound: number): FluentType<t, i>;
|
|
94
|
+
atLeast(bound: number): FluentType<t, i>;
|
|
95
|
+
atMost(bound: number): FluentType<t, i>;
|
|
96
|
+
moreThan(bound: number): FluentType<t, i>;
|
|
97
|
+
lessThan(bound: number): FluentType<t, i>;
|
|
98
|
+
divisibleBy(divisor: number): FluentType<t, i>;
|
|
99
|
+
positive(): FluentType<t, i>;
|
|
100
|
+
negative(): FluentType<t, i>;
|
|
101
|
+
nonNegative(): FluentType<t, i>;
|
|
102
|
+
nonPositive(): FluentType<t, i>;
|
|
103
|
+
matching(pattern: RegExp): FluentType<t, i>;
|
|
104
|
+
atOrAfter(bound: Date): FluentType<t, i>;
|
|
105
|
+
atOrBefore(bound: Date): FluentType<t, i>;
|
|
106
|
+
laterThan(bound: Date): FluentType<t, i>;
|
|
107
|
+
earlierThan(bound: Date): FluentType<t, i>;
|
|
108
|
+
pipe<r>(fn: (data: t, ctx: NarrowContext) => r): FluentType<Exclude<r, OmpErrors>, i>;
|
|
109
|
+
to<const def>(def: def): FluentType<InferDef<def>, i>;
|
|
110
|
+
filter<narrowed extends i>(fn: (data: i, ctx: NarrowContext) => data is narrowed): FluentType<t, narrowed>;
|
|
111
|
+
filter(fn: (data: i, ctx: NarrowContext) => boolean): FluentType<t, i>;
|
|
112
|
+
narrow<narrowed extends t>(fn: (data: t, ctx: NarrowContext) => data is narrowed): FluentType<narrowed, i>;
|
|
113
|
+
narrow(fn: (data: t, ctx: NarrowContext) => boolean): FluentType<t, i>;
|
|
114
|
+
brand<const name extends string>(name: name): FluentType<Brand<t, name>, i>;
|
|
115
|
+
as<castTo>(): FluentType<castTo, i>;
|
|
116
|
+
extract<r, ri>(def: SchemaInference<r, ri>): FluentType<Extract<t, r>, Extract<i, ri>>;
|
|
117
|
+
extract<const def extends string>(def: def): FluentType<Extract<t, InferString<def>>, Extract<i, InferString<def>>>;
|
|
118
|
+
extract(def: Def): FluentType<unknown>;
|
|
119
|
+
exclude<r, ri>(def: SchemaInference<r, ri>): FluentType<Exclude<t, r>, Exclude<i, ri>>;
|
|
120
|
+
exclude<const def extends string>(def: def): FluentType<Exclude<t, InferString<def>>, Exclude<i, InferString<def>>>;
|
|
121
|
+
exclude(def: Def): FluentType<unknown>;
|
|
122
|
+
onUndeclaredKey(behavior: "ignore" | "reject" | "delete"): FluentType<t, i>;
|
|
123
|
+
onDeepUndeclaredKey(behavior: "ignore" | "reject" | "delete"): FluentType<t, i>;
|
|
66
124
|
}
|
|
125
|
+
type InputObject<i> = i extends object ? i : object;
|
|
126
|
+
interface ObjectMethods<t extends object, i> {
|
|
127
|
+
readonly props: readonly TypeProperty[];
|
|
128
|
+
map(mapper: (property: TypeProperty) => TypeProperty | readonly TypeProperty[]): FluentType<Record<PropertyKey, unknown>>;
|
|
129
|
+
keyof(): FluentType<Extract<keyof t, PropertyKey>, Extract<keyof InputObject<i>, PropertyKey>>;
|
|
130
|
+
get<key extends keyof t>(key: key): FluentType<t[key], key extends keyof InputObject<i> ? InputObject<i>[key] : unknown>;
|
|
131
|
+
pick<const keys extends readonly (keyof t)[]>(...keys: keys): FluentType<Pick<t, keys[number]>, Pick<InputObject<i>, Extract<keys[number], keyof InputObject<i>>>>;
|
|
132
|
+
omit<const keys extends readonly (keyof t)[]>(...keys: keys): FluentType<Omit<t, keys[number]>, Omit<InputObject<i>, Extract<keys[number], keyof InputObject<i>>>>;
|
|
133
|
+
partial(): FluentType<Partial<t>, Partial<InputObject<i>>>;
|
|
134
|
+
required(): FluentType<Required<t>, Required<InputObject<i>>>;
|
|
135
|
+
merge<r, ri>(def: SchemaInference<r, ri>): FluentType<MergeTypes<t, r>, MergeTypes<i, ri>>;
|
|
136
|
+
merge<const def extends Record<string, unknown>>(def: def): FluentType<MergeTypes<t, InferObjectLiteral<def>>, MergeTypes<i, InferObjectLiteral<def>>>;
|
|
137
|
+
merge(def: Def): FluentType<unknown>;
|
|
138
|
+
}
|
|
139
|
+
type ObjectMethodsFor<t, i> = [t] extends [never] ? unknown : [t] extends [readonly unknown[]] ? unknown : [t] extends [object] ? ObjectMethods<t & object, i> : unknown;
|
|
140
|
+
/** Callable schema with fluent methods specialized to its output and input. */
|
|
141
|
+
export type FluentType<t = unknown, i = t> = Type<t, i> & FluentMethods<t, i> & ObjectMethodsFor<t, i>;
|
|
67
142
|
/** Runtime constructor-like value used by ArkType-compatible `instanceof Type` checks. */
|
|
68
143
|
export declare const Type: () => void;
|
|
69
144
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* The `const def` generic drives static inference (`typeof schema.infer`);
|
|
73
|
-
* the runtime is definition-shape-agnostic, hence the cast.
|
|
145
|
+
* Parse a definition into a callable schema with distinct input/output inference.
|
|
74
146
|
*/
|
|
75
|
-
export declare function type<const def>(def: def): FluentType<InferDef<def>>;
|
|
147
|
+
export declare function type<const def>(def: def): FluentType<InferDef<def>, InferDefIn<def>>;
|
|
148
|
+
/** String keyword with a parser that morphs validated text to another output. */
|
|
149
|
+
export interface ParsedStringKeyword<parsed> extends FluentType<string> {
|
|
150
|
+
readonly parse: FluentType<parsed, string>;
|
|
151
|
+
}
|
|
152
|
+
/** Morphing string keyword paired with its non-morphing preformatted validator. */
|
|
153
|
+
export interface PreformattedKeyword extends FluentType<string, string> {
|
|
154
|
+
readonly preformatted: FluentType<string>;
|
|
155
|
+
}
|
|
156
|
+
/** Base64 keyword with its URL-safe alphabet variant. */
|
|
157
|
+
export interface Base64Keyword extends FluentType<string> {
|
|
158
|
+
readonly url: FluentType<string>;
|
|
159
|
+
}
|
|
160
|
+
/** Date-string keyword family. */
|
|
161
|
+
export interface DateStringKeyword extends ParsedStringKeyword<Date> {
|
|
162
|
+
readonly iso: ParsedStringKeyword<Date>;
|
|
163
|
+
readonly epoch: ParsedStringKeyword<Date>;
|
|
164
|
+
}
|
|
165
|
+
/** IP address keyword family. */
|
|
166
|
+
export interface IpKeyword extends FluentType<string> {
|
|
167
|
+
readonly v4: FluentType<string>;
|
|
168
|
+
readonly v6: FluentType<string>;
|
|
169
|
+
}
|
|
170
|
+
/** UUID keyword family. */
|
|
171
|
+
export interface UuidKeyword extends FluentType<string> {
|
|
172
|
+
readonly v1: FluentType<string>;
|
|
173
|
+
readonly v2: FluentType<string>;
|
|
174
|
+
readonly v3: FluentType<string>;
|
|
175
|
+
readonly v4: FluentType<string>;
|
|
176
|
+
readonly v5: FluentType<string>;
|
|
177
|
+
readonly v6: FluentType<string>;
|
|
178
|
+
readonly v7: FluentType<string>;
|
|
179
|
+
readonly v8: FluentType<string>;
|
|
180
|
+
}
|
|
181
|
+
/** String normalization keyword family. */
|
|
182
|
+
export interface NormalizeKeyword extends PreformattedKeyword {
|
|
183
|
+
readonly NFC: PreformattedKeyword;
|
|
184
|
+
readonly NFD: PreformattedKeyword;
|
|
185
|
+
readonly NFKC: PreformattedKeyword;
|
|
186
|
+
readonly NFKD: PreformattedKeyword;
|
|
187
|
+
}
|
|
188
|
+
/** Runtime string parsers exposed under `type.parse`. */
|
|
189
|
+
export interface ParseKeyword {
|
|
190
|
+
readonly number: FluentType<number, string>;
|
|
191
|
+
readonly integer: FluentType<number, string>;
|
|
192
|
+
readonly json: FluentType<unknown, string>;
|
|
193
|
+
readonly date: FluentType<Date, string>;
|
|
194
|
+
readonly url: FluentType<URL, string>;
|
|
195
|
+
readonly boolean: FluentType<boolean, string>;
|
|
196
|
+
readonly bigint: FluentType<bigint, string>;
|
|
197
|
+
}
|
|
198
|
+
/** Full string keyword module attached to `type.string`. */
|
|
199
|
+
export interface StringKeyword extends FluentType<string> {
|
|
200
|
+
readonly alpha: FluentType<string>;
|
|
201
|
+
readonly alphanumeric: FluentType<string>;
|
|
202
|
+
readonly base64: Base64Keyword;
|
|
203
|
+
readonly capitalize: PreformattedKeyword;
|
|
204
|
+
readonly creditCard: FluentType<string>;
|
|
205
|
+
readonly date: DateStringKeyword;
|
|
206
|
+
readonly digits: FluentType<string>;
|
|
207
|
+
readonly email: FluentType<string>;
|
|
208
|
+
readonly hex: FluentType<string>;
|
|
209
|
+
readonly integer: ParsedStringKeyword<number>;
|
|
210
|
+
readonly ip: IpKeyword;
|
|
211
|
+
readonly json: ParsedStringKeyword<unknown>;
|
|
212
|
+
readonly lower: PreformattedKeyword;
|
|
213
|
+
readonly normalize: NormalizeKeyword;
|
|
214
|
+
readonly numeric: ParsedStringKeyword<number>;
|
|
215
|
+
readonly regex: FluentType<string>;
|
|
216
|
+
readonly semver: FluentType<string>;
|
|
217
|
+
readonly trim: PreformattedKeyword;
|
|
218
|
+
readonly upper: PreformattedKeyword;
|
|
219
|
+
readonly url: ParsedStringKeyword<URL>;
|
|
220
|
+
readonly uuid: UuidKeyword;
|
|
221
|
+
}
|
|
222
|
+
/** Number keyword module attached to `type.number`. */
|
|
223
|
+
export interface NumberKeyword extends FluentType<number> {
|
|
224
|
+
readonly integer: FluentType<number>;
|
|
225
|
+
}
|
|
226
|
+
type Constructed<ctor> = ctor extends abstract new (...args: never[]) => infer instance ? instance : never;
|
|
76
227
|
export declare namespace type {
|
|
77
228
|
/** Error aggregate returned by failed validations (`result instanceof type.errors`). */
|
|
78
229
|
const errors: typeof OmpErrors;
|
|
79
230
|
type errors = OmpErrors;
|
|
80
|
-
/**
|
|
81
|
-
const string:
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
231
|
+
/** String validator and its refinement/morph keyword module. */
|
|
232
|
+
const string: StringKeyword;
|
|
233
|
+
/** Runtime parser keyword family. */
|
|
234
|
+
const parse: ParseKeyword;
|
|
235
|
+
/** Number validator with integer refinement. */
|
|
236
|
+
const number: NumberKeyword;
|
|
237
|
+
/** Boolean validator. */
|
|
238
|
+
const boolean: FluentType<boolean, boolean>;
|
|
239
|
+
/** Bigint validator. */
|
|
240
|
+
const bigint: FluentType<bigint, bigint>;
|
|
241
|
+
/** Symbol validator. */
|
|
242
|
+
const symbol: FluentType<symbol, symbol>;
|
|
243
|
+
/** Non-null object validator. */
|
|
244
|
+
const object: FluentType<object, object>;
|
|
245
|
+
/** Unknown validator. */
|
|
246
|
+
const unknown: FluentType<unknown, unknown>;
|
|
247
|
+
/** Alias of the unknown validator. */
|
|
248
|
+
const any: FluentType<unknown, unknown>;
|
|
249
|
+
/** Validator that rejects every value. */
|
|
250
|
+
const never: FluentType<never, never>;
|
|
251
|
+
/** Date instance validator. */
|
|
252
|
+
const Date: FluentType<Date, Date>;
|
|
253
|
+
/** Validate instances of `ctor`. */
|
|
254
|
+
function instanceOf<const ctor extends Constructor>(ctor: ctor): FluentType<Constructed<ctor>>;
|
|
255
|
+
/** Validate one exact unit value. */
|
|
256
|
+
function unit<const value>(value: value): FluentType<value>;
|
|
257
|
+
/** Union of literal values from a runtime array. */
|
|
86
258
|
function enumerated<const values extends readonly unknown[]>(...values: values): FluentType<values[number]>;
|
|
87
|
-
/**
|
|
259
|
+
/** Build a first-match dispatcher from schema-expression keys and a `default` case. */
|
|
260
|
+
function match<const cases extends Record<string, unknown>>(cases: cases): (value: unknown) => unknown;
|
|
261
|
+
/** Preserve a definition's literal type while authoring reusable modules. */
|
|
262
|
+
function define<const definition>(definition: definition): definition;
|
|
263
|
+
/** Build a lazy named scope from aliases and recursive definitions. */
|
|
264
|
+
function scope(aliases: Record<string, unknown>, options?: ScopeOptions): TypeScope;
|
|
265
|
+
/** Compile a named schema module whose definitions may reference each other. */
|
|
266
|
+
function module<const definitions extends Record<string, unknown>>(definitions: definitions): {
|
|
267
|
+
[name in keyof definitions]: Type<InferDef<definitions[name]>, InferDefIn<definitions[name]>>;
|
|
268
|
+
};
|
|
269
|
+
/** Build a runtime generic whose parameter names are supplied as `"<t, u>"`. */
|
|
270
|
+
function generic<const definition>(parameters: string, definition: definition): (...arguments_: readonly unknown[]) => BaseType;
|
|
271
|
+
/** Untyped builder for runtime-assembled definitions. */
|
|
88
272
|
function raw(def: unknown): BaseType;
|
|
89
273
|
}
|
|
90
274
|
export interface ScopeOptions {
|
|
91
275
|
jitless?: boolean;
|
|
92
276
|
}
|
|
93
|
-
/**
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
277
|
+
/** Callable builder bound to one alias scope. */
|
|
278
|
+
export type ScopedBuilder = <const definition>(definition: definition) => FluentType<InferDef<definition>, InferDefIn<definition>>;
|
|
279
|
+
/** Named schema scope with a scoped builder and compiled module export. */
|
|
280
|
+
export interface TypeScope {
|
|
281
|
+
readonly type: ScopedBuilder;
|
|
282
|
+
export(): Record<string, BaseType>;
|
|
283
|
+
}
|
|
284
|
+
/** Build a scope whose aliases resolve lazily, including recursive cycles. */
|
|
285
|
+
export declare function scope(aliases: Record<string, unknown>, options?: ScopeOptions): TypeScope;
|
|
97
286
|
/** A schema whose output type is not statically known (`type.raw` results). */
|
|
98
|
-
export type BaseType = FluentType<unknown>;
|
|
287
|
+
export type BaseType = FluentType<unknown, unknown>;
|
|
99
288
|
/** `hasMorph` re-export for diagnostics/tooling. */
|
|
100
289
|
export { hasMorph };
|
package/dist/types/zod.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type ZodLikeSafeParseResult<Out> = {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
/** A callable omptype schema carrying the Zod-v4-style fluent surface. */
|
|
24
|
-
export interface ZodLikeSchema<out Out> extends Type<Out> {
|
|
24
|
+
export interface ZodLikeSchema<out Out> extends Type<Out, unknown> {
|
|
25
25
|
readonly _output: Out;
|
|
26
26
|
/** @internal Used while composing object property IR. */
|
|
27
27
|
readonly isOptional: boolean;
|
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.7",
|
|
5
5
|
"description": "ArkType-compatible runtime schema validation with lazy JIT compilation",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"arktype",
|
|
21
21
|
"jit"
|
|
22
22
|
],
|
|
23
|
-
"main": "./
|
|
23
|
+
"main": "./dist/js/index.js",
|
|
24
24
|
"types": "./dist/types/index.d.ts",
|
|
25
25
|
"scripts": {
|
|
26
26
|
"check": "biome check . && bun run check:types",
|
|
@@ -28,29 +28,41 @@
|
|
|
28
28
|
"lint": "biome lint .",
|
|
29
29
|
"fix": "biome check --write --unsafe .",
|
|
30
30
|
"fmt": "biome format --write .",
|
|
31
|
-
"test": "bun test --parallel"
|
|
31
|
+
"test": "bun test --parallel",
|
|
32
|
+
"bench": "bun bench/bench.ts"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
+
"@sinclair/typebox": "^0.34.0",
|
|
36
|
+
"@types/bun": "^1.3.14",
|
|
37
|
+
"arktype": "2.2.3",
|
|
38
|
+
"zod": "^4"
|
|
35
39
|
},
|
|
36
40
|
"engines": {
|
|
41
|
+
"node": ">=20",
|
|
37
42
|
"bun": ">=1.3.14"
|
|
38
43
|
},
|
|
39
44
|
"files": [
|
|
40
45
|
"src",
|
|
41
46
|
"README.md",
|
|
42
47
|
"CHANGELOG.md",
|
|
43
|
-
"dist/types"
|
|
48
|
+
"dist/types",
|
|
49
|
+
"dist/js"
|
|
44
50
|
],
|
|
45
51
|
"exports": {
|
|
46
52
|
".": {
|
|
47
53
|
"types": "./dist/types/index.d.ts",
|
|
48
|
-
"
|
|
54
|
+
"bun": "./src/index.ts",
|
|
55
|
+
"default": "./dist/js/index.js"
|
|
49
56
|
},
|
|
50
57
|
"./*": {
|
|
51
58
|
"types": "./dist/types/*.d.ts",
|
|
52
|
-
"
|
|
59
|
+
"bun": "./src/*.ts",
|
|
60
|
+
"default": "./dist/js/*.js"
|
|
53
61
|
},
|
|
54
|
-
"./*.js":
|
|
62
|
+
"./*.js": {
|
|
63
|
+
"types": "./dist/types/*.d.ts",
|
|
64
|
+
"bun": "./src/*.ts",
|
|
65
|
+
"default": "./dist/js/*.js"
|
|
66
|
+
}
|
|
55
67
|
}
|
|
56
68
|
}
|
package/src/ark.ts
CHANGED
|
@@ -6,13 +6,11 @@
|
|
|
6
6
|
* `from "@oh-my-pi/omptype/ark"` and nothing else changes. New code should
|
|
7
7
|
* import `@oh-my-pi/omptype` directly.
|
|
8
8
|
*
|
|
9
|
-
* Compatibility
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
* obsolete — omptype always starts interpreted and JIT-compiles lazily.
|
|
9
|
+
* Compatibility affordance: `ArkError` / `ArkErrors` alias `OmpError` /
|
|
10
|
+
* `OmpErrors`. All schema builders, including recursive `scope()`, are
|
|
11
|
+
* re-exported unchanged.
|
|
13
12
|
*/
|
|
14
|
-
import { OmpError, OmpErrors
|
|
15
|
-
import { type } from "./type";
|
|
13
|
+
import { OmpError, OmpErrors } from "./errors";
|
|
16
14
|
|
|
17
15
|
export * from "./index";
|
|
18
16
|
|
|
@@ -20,11 +18,3 @@ export const ArkError = OmpError;
|
|
|
20
18
|
export type ArkError = OmpError;
|
|
21
19
|
export const ArkErrors = OmpErrors;
|
|
22
20
|
export type ArkErrors = OmpErrors;
|
|
23
|
-
|
|
24
|
-
/** ArkType `scope()` shim: only the alias-free `scope({}, config?)` form is supported. */
|
|
25
|
-
export function scope(aliases: Record<string, never>, _config?: { jitless?: boolean }): { type: typeof type } {
|
|
26
|
-
for (const key in aliases) {
|
|
27
|
-
throw new OmpTypeError(`scope aliases are not supported (found "${key}"); define types directly`);
|
|
28
|
-
}
|
|
29
|
-
return { type };
|
|
30
|
-
}
|