@oh-my-pi/omptype 17.2.6 → 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.
@@ -1,27 +1,96 @@
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, InferObjectLiteralIn, 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";
5
+ export interface NarrowErrorInput {
6
+ readonly expected: string;
7
+ readonly actual?: unknown;
8
+ readonly path?: readonly PropertyKey[];
9
+ readonly relativePath?: readonly PropertyKey[];
10
+ }
4
11
  /** Context passed to `.narrow()` / `.pipe()` callbacks. */
5
12
  export interface NarrowContext {
6
- /** Record `must be <expectation>` and signal failure. */
13
+ readonly path: readonly PropertyKey[];
14
+ error(error: string | NarrowErrorInput): OmpErrors;
7
15
  mustBe(expectation: string): false;
8
- /** Record a custom problem and signal failure. */
9
- reject(problem: string): false;
10
- }
11
- /** Options accepted by `Type.toJsonSchema` (ArkType-compatible; emission is always draft 2020-12). */
12
- export interface ToJsonSchemaOptions {
13
- target?: string;
14
- dialect?: string;
15
- fallback?: (ctx: {
16
- base: Record<string, unknown>;
17
- }) => unknown;
18
- }
19
- interface SchemaInference<out t> {
16
+ reject(problem: string | NarrowErrorInput): OmpErrors | false;
17
+ }
18
+ /** Schema metadata and validation-message overrides accepted by `.configure()`. */
19
+ export interface SchemaConfig extends ErrorConfig {
20
+ readonly description?: string;
21
+ }
22
+ /** Options accepted by `Type.toJsonSchema`. */
23
+ export interface ToJsonSchemaOptions extends JsonSchemaOptions {
24
+ }
25
+ declare const brand: unique symbol;
26
+ /** Inference-only nominal brand attached by `.brand(name)`. */
27
+ export type Brand<t, name extends string> = t & {
28
+ readonly [brand]: name;
29
+ };
30
+ interface SchemaInference<out t, i = t> {
20
31
  readonly [IR_BRAND]: true;
21
32
  readonly infer: t;
33
+ readonly inferIn: i;
34
+ }
35
+ /** Property descriptor exposed by object schemas and consumed by `.map()`. */
36
+ export interface TypeProperty {
37
+ readonly kind: "required" | "optional";
38
+ readonly key: PropertyKey;
39
+ readonly value: FluentType<unknown>;
40
+ readonly default?: unknown;
41
+ readonly meta: Readonly<Record<string, unknown>>;
42
+ }
43
+ /** Structural node returned by `.select()`. */
44
+ export interface SelectedNode {
45
+ readonly kind: string;
46
+ readonly node: IR;
47
+ readonly unit?: unknown;
48
+ }
49
+ /**
50
+ * Standard Schema V1 (https://standardschema.dev) — the cross-library
51
+ * validation interface consumed by tools like @t3-oss/env, tRPC, and
52
+ * Hono validators. Inlined per the spec's recommendation; no dependency.
53
+ */
54
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
55
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
56
+ }
57
+ export declare namespace StandardSchemaV1 {
58
+ interface Props<Input = unknown, Output = Input> {
59
+ readonly version: 1;
60
+ readonly vendor: string;
61
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
62
+ readonly types?: Types<Input, Output> | undefined;
63
+ readonly jsonSchema: {
64
+ readonly input: (options: StandardJsonSchemaOptions) => Record<string, unknown>;
65
+ readonly output: (options: StandardJsonSchemaOptions) => Record<string, unknown>;
66
+ };
67
+ }
68
+ type Result<Output> = SuccessResult<Output> | FailureResult;
69
+ interface SuccessResult<Output> {
70
+ readonly value: Output;
71
+ readonly issues?: undefined;
72
+ }
73
+ interface FailureResult {
74
+ readonly issues: readonly Issue[];
75
+ }
76
+ interface Issue {
77
+ readonly message: string;
78
+ readonly path?: readonly PropertyKey[] | undefined;
79
+ }
80
+ interface Types<Input = unknown, Output = Input> {
81
+ readonly input: Input;
82
+ readonly output: Output;
83
+ }
84
+ }
85
+ export interface StandardJsonSchemaOptions {
86
+ readonly target: "draft-2020-12" | "draft-07" | string;
87
+ readonly libraryOptions?: {
88
+ readonly dialect?: string | null;
89
+ readonly fallback?: JsonSchemaOptions["fallback"];
90
+ };
22
91
  }
23
92
  /** A compiled schema: callable validator plus composition methods. */
24
- export interface Type<out t = unknown> {
93
+ export interface Type<out t = unknown, i = t> {
25
94
  (data: unknown): t | OmpErrors;
26
95
  readonly [IR_BRAND]: true;
27
96
  /** Structural IR (base type; runtime steps live in `steps`). */
@@ -31,70 +100,466 @@ export interface Type<out t = unknown> {
31
100
  readonly hasDefault: boolean;
32
101
  readonly defaultValue?: unknown;
33
102
  readonly description?: string;
103
+ /** Canonical ArkType-compatible expression for diagnostics. */
104
+ readonly expression: string;
105
+ /** Canonical structural node representation. */
106
+ readonly json: unknown;
34
107
  /** Full validate+morph pipeline; identical to calling the schema. */
35
108
  readonly run: (data: unknown) => unknown;
109
+ /** ArkType-compatible inference alias (type-only; undefined at runtime). */
110
+ readonly t: t;
111
+ /** Scope that parsed this schema (or the ambient Ark-compatible scope). */
112
+ readonly $: TypeScope | {
113
+ readonly internal: {
114
+ readonly name: "ark";
115
+ };
116
+ };
36
117
  /** Inference-only output type (no runtime value). */
37
118
  readonly infer: t;
119
+ /** Standalone validator for the schema's accepted input. */
120
+ readonly in: FluentType<i>;
121
+ /** Standalone validator for its known output, or `unknown` after an opaque morph. */
122
+ readonly out: FluentType<t>;
38
123
  /** Inference-only input type (no runtime value). */
39
- readonly inferIn: t;
124
+ readonly inferIn: i;
40
125
  /** Structural + narrow check without running pipes. */
41
- allows(data: unknown): data is t;
126
+ allows(data: unknown): data is i;
42
127
  /** Validate and return output, throwing `TraversalError` on failure. */
43
128
  assert(data: unknown): t;
44
- /** JSON Schema (draft 2020-12) for this schema's structural base. */
129
+ /** Validate a statically typed input and return its output. */
130
+ from(data: i): t;
131
+ /** JSON Schema for this schema's structural base. */
45
132
  toJsonSchema(options?: ToJsonSchemaOptions): Record<string, unknown>;
133
+ /** Standard Schema V1 interop (synchronous validation). */
134
+ readonly "~standard": StandardSchemaV1.Props<i, t>;
46
135
  }
47
- /** Schema returned by omptype builders, with precise object-literal composition inference. */
48
- export interface FluentType<t = unknown> extends Type<t> {
49
- describe(description: string): FluentType<t>;
50
- default(value: t | (() => t)): FluentType<t>;
51
- or<r>(def: SchemaInference<r>): FluentType<t | r>;
52
- or<const def extends string>(def: def): FluentType<t | InferString<def>>;
53
- or<const def extends Record<string, unknown>>(def: def): FluentType<t | InferObjectLiteral<def>>;
136
+ type MergeTypes<left, right> = left extends object ? right extends object ? Omit<left, keyof right> & right : right : right;
137
+ type SimplifyNary<t> = t extends object ? {
138
+ [key in keyof t]: t[key];
139
+ } : t;
140
+ type UnionToIntersection<union> = (union extends unknown ? (value: union) => void : never) extends (value: infer intersection) => void ? intersection : never;
141
+ type NaryOrOutput<definitions extends readonly unknown[]> = InferDef<definitions[number]>;
142
+ type NaryOrInput<definitions extends readonly unknown[]> = InferDefIn<definitions[number]>;
143
+ type NaryAndOutput<definitions extends readonly unknown[]> = definitions extends readonly [] ? unknown : SimplifyNary<UnionToIntersection<InferDef<definitions[number]>>>;
144
+ type NaryAndInput<definitions extends readonly unknown[]> = definitions extends readonly [] ? unknown : SimplifyNary<UnionToIntersection<InferDefIn<definitions[number]>>>;
145
+ type ReduceNaryMergeOutput<definitions extends readonly unknown[], result = {}> = definitions extends readonly [
146
+ infer head,
147
+ ...infer tail
148
+ ] ? ReduceNaryMergeOutput<tail, SimplifyNary<MergeTypes<result, InferDef<head>>>> : definitions extends readonly [] ? result : {};
149
+ type ReduceNaryMergeInput<definitions extends readonly unknown[], result = {}> = definitions extends readonly [
150
+ infer head,
151
+ ...infer tail
152
+ ] ? ReduceNaryMergeInput<tail, SimplifyNary<MergeTypes<result, InferDefIn<head>>>> : definitions extends readonly [] ? result : {};
153
+ type NaryMergeOutput<definitions extends readonly unknown[]> = definitions extends readonly [] ? object : ReduceNaryMergeOutput<definitions>;
154
+ type NaryMergeInput<definitions extends readonly unknown[]> = definitions extends readonly [] ? object : ReduceNaryMergeInput<definitions>;
155
+ type PipeItemOutput<item> = item extends SchemaInference<infer output, unknown> ? output : item extends (data: never, ...arguments_: never[]) => infer output ? Exclude<output, OmpErrors> : InferDef<item>;
156
+ type NaryPipeOutput<items extends readonly unknown[]> = items extends readonly [...(readonly unknown[]), infer last] ? PipeItemOutput<last> : unknown;
157
+ type NaryPipeInput<items extends readonly unknown[]> = items extends readonly [infer first, ...(readonly unknown[])] ? first extends SchemaInference<unknown, infer input> ? input : first extends (data: infer input, ...arguments_: never[]) => unknown ? input : InferDefIn<first> : unknown;
158
+ interface FluentMethods<t, i> {
159
+ describe(description: string): FluentType<t, i>;
160
+ configure(config: SchemaConfig, selector?: "self" | ConfigureSelector): FluentType<t, i>;
161
+ default(value: i | (() => i)): FluentType<t, i | undefined>;
162
+ optional(): readonly [SchemaInference<t, i>, "?"];
163
+ or<r, ri>(def: SchemaInference<r, ri>): FluentType<t | r, i | ri>;
164
+ or<const def extends string>(def: def): FluentType<t | InferString<def>, i | InferString<def>>;
165
+ or<const def extends Record<string, unknown>>(def: def): FluentType<t | InferObjectLiteral<def>, i | InferObjectLiteralIn<def>>;
54
166
  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>>;
167
+ and<r, ri>(def: SchemaInference<r, ri>): FluentType<t & r, i & ri>;
168
+ and<const def extends Record<string, unknown>>(def: def): FluentType<t & InferObjectLiteral<def>, i & InferObjectLiteralIn<def>>;
57
169
  and(def: Def): FluentType<unknown>;
58
- array(): FluentType<t[]>;
59
- atLeastLength(bound: number): FluentType<t>;
60
- atMostLength(bound: number): FluentType<t>;
61
- atLeast(bound: number): FluentType<t>;
62
- atMost(bound: number): FluentType<t>;
63
- pipe<r>(fn: (data: t, ctx: NarrowContext) => r): FluentType<Exclude<r, OmpErrors>>;
64
- narrow<narrowed extends t>(fn: (data: t, ctx: NarrowContext) => data is narrowed): FluentType<narrowed>;
65
- narrow(fn: (data: t, ctx: NarrowContext) => boolean): FluentType<t>;
170
+ equals(def: Def): boolean;
171
+ ifEquals(def: Def): FluentType<t, i> | undefined;
172
+ ifExtends(def: Def): FluentType<t, i> | undefined;
173
+ extends(def: Def): boolean;
174
+ overlaps(def: Def): boolean;
175
+ distribute<r>(mapper: (branch: FluentType<unknown>) => SchemaInference<r>, reducer?: (branches: readonly SchemaInference<r>[]) => SchemaInference<unknown>): FluentType<r>;
176
+ select(kind: string): readonly SelectedNode[];
177
+ array(): FluentType<t[], i[]>;
178
+ atLeastLength(bound: number): FluentType<t, i>;
179
+ atMostLength(bound: number): FluentType<t, i>;
180
+ moreThanLength(bound: number): FluentType<t, i>;
181
+ lessThanLength(bound: number): FluentType<t, i>;
182
+ exactlyLength(bound: number): FluentType<t, i>;
183
+ atLeast(bound: number): FluentType<t, i>;
184
+ atMost(bound: number): FluentType<t, i>;
185
+ moreThan(bound: number): FluentType<t, i>;
186
+ lessThan(bound: number): FluentType<t, i>;
187
+ divisibleBy(divisor: number): FluentType<t, i>;
188
+ positive(): FluentType<t, i>;
189
+ negative(): FluentType<t, i>;
190
+ nonNegative(): FluentType<t, i>;
191
+ nonPositive(): FluentType<t, i>;
192
+ matching(pattern: RegExp): FluentType<t, i>;
193
+ atOrAfter(bound: Date | number): FluentType<t, i>;
194
+ atOrBefore(bound: Date | number): FluentType<t, i>;
195
+ laterThan(bound: Date | number): FluentType<t, i>;
196
+ earlierThan(bound: Date | number): FluentType<t, i>;
197
+ readonly pipe: PipeMethod<t, i>;
198
+ to<const def>(def: def): FluentType<InferDef<def>, i>;
199
+ filter<narrowed extends i>(fn: (data: i, ctx: NarrowContext) => data is narrowed): FluentType<t, narrowed>;
200
+ filter(fn: (data: i, ctx: NarrowContext) => boolean | OmpErrors): FluentType<t, i>;
201
+ narrow<narrowed extends t>(fn: (data: t, ctx: NarrowContext) => data is narrowed): FluentType<narrowed, i>;
202
+ narrow(fn: (data: t, ctx: NarrowContext) => boolean | OmpErrors): FluentType<t, i>;
203
+ brand<const name extends string>(name: name): FluentType<Brand<t, name>, i>;
204
+ as<castTo>(): FluentType<castTo, i>;
205
+ readonly(): FluentType<Readonly<t>, i>;
206
+ extract<r, ri>(def: SchemaInference<r, ri>): FluentType<Extract<t, r>, Extract<i, ri>>;
207
+ extract<const def extends string>(def: def): FluentType<Extract<t, InferString<def>>, Extract<i, InferString<def>>>;
208
+ extract(def: Def): FluentType<unknown>;
209
+ exclude<r, ri>(def: SchemaInference<r, ri>): FluentType<Exclude<t, r>, Exclude<i, ri>>;
210
+ exclude<const def extends string>(def: def): FluentType<Exclude<t, InferString<def>>, Exclude<i, InferString<def>>>;
211
+ exclude(def: Def): FluentType<unknown>;
212
+ onUndeclaredKey(behavior: "ignore" | "reject" | "delete"): FluentType<t, i>;
213
+ onDeepUndeclaredKey(behavior: "ignore" | "reject" | "delete"): FluentType<t, i>;
214
+ }
215
+ interface PipeMethod<t, i> {
216
+ <r>(fn: (data: t, ctx: NarrowContext) => r): FluentType<Exclude<r, OmpErrors>, i>;
217
+ <r, ri>(schema: SchemaInference<r, ri>): FluentType<r, i>;
218
+ (...steps: readonly unknown[]): FluentType<unknown, i>;
219
+ readonly try: {
220
+ <r>(fn: (data: t, ctx: NarrowContext) => r): FluentType<Exclude<r, OmpErrors>, i>;
221
+ (...steps: readonly unknown[]): FluentType<unknown, i>;
222
+ };
223
+ }
224
+ type InputObject<i> = i extends object ? i : object;
225
+ interface ObjectMethods<t extends object, i> {
226
+ readonly props: readonly TypeProperty[];
227
+ map(mapper: (property: TypeProperty) => TypeProperty | readonly TypeProperty[]): FluentType<Record<PropertyKey, unknown>>;
228
+ keyof(): FluentType<Extract<keyof t, PropertyKey>, Extract<keyof InputObject<i>, PropertyKey>>;
229
+ get<const path extends readonly PropertyKey[]>(...path: path): FluentType<unknown>;
230
+ pick<const keys extends readonly (keyof t)[]>(...keys: keys): FluentType<Pick<t, keys[number]>, Pick<InputObject<i>, Extract<keys[number], keyof InputObject<i>>>>;
231
+ omit<const keys extends readonly (keyof t)[]>(...keys: keys): FluentType<Omit<t, keys[number]>, Omit<InputObject<i>, Extract<keys[number], keyof InputObject<i>>>>;
232
+ partial(): FluentType<Partial<t>, Partial<InputObject<i>>>;
233
+ required(): FluentType<Required<t>, Required<InputObject<i>>>;
234
+ merge<r, ri>(def: SchemaInference<r, ri>): FluentType<MergeTypes<t, r>, MergeTypes<i, ri>>;
235
+ merge<const def extends Record<string, unknown>>(def: def): FluentType<MergeTypes<t, InferObjectLiteral<def>>, MergeTypes<i, InferObjectLiteralIn<def>>>;
236
+ merge(def: Def): FluentType<unknown>;
237
+ }
238
+ type ObjectMethodsFor<t, i> = [t] extends [never] ? unknown : [t] extends [readonly unknown[]] ? unknown : [t] extends [object] ? ObjectMethods<t & object, i> : unknown;
239
+ /** Callable schema with fluent methods specialized to its output and input. */
240
+ export type FluentType<t = unknown, i = t> = Type<t, i> & FluentMethods<t, i> & ObjectMethodsFor<t, i>;
241
+ type FnDefinition = Def | SchemaInference<unknown, unknown>;
242
+ /** Function returned by `type.fn`: arguments and an optional return are validated at every call. */
243
+ export type TypedFunction<parameters extends readonly unknown[] = readonly unknown[], returns = unknown, declaredReturns = returns> = ((...arguments_: parameters) => returns) & {
244
+ readonly params: FluentType<parameters>;
245
+ readonly returns: FluentType<declaredReturns>;
246
+ readonly expression: string;
247
+ readonly raw: (...arguments_: parameters) => returns;
248
+ };
249
+ type InferFnDefinition<definition> = definition extends SchemaInference<infer output, unknown> ? output : InferDef<definition>;
250
+ type InferFnParameters<definitions extends readonly unknown[], accumulator extends readonly unknown[] = []> = definitions extends readonly [infer head, ...infer tail] ? head extends ":" ? accumulator : InferFnParameters<tail, readonly [...accumulator, InferFnDefinition<head>]> : accumulator;
251
+ type InferFnReturn<definitions extends readonly unknown[], inferred> = definitions extends readonly [
252
+ ...(readonly unknown[]),
253
+ ":",
254
+ infer returns
255
+ ] ? InferFnDefinition<returns> : inferred;
256
+ type DeclaredFnReturn<definitions extends readonly unknown[]> = definitions extends readonly [
257
+ ...(readonly unknown[]),
258
+ ":",
259
+ infer returns
260
+ ] ? InferFnDefinition<returns> : unknown;
261
+ type FnFactory<definitions extends readonly FnDefinition[]> = <result>(implementation: (...arguments_: InferFnParameters<definitions>) => InferFnReturn<definitions, result>) => TypedFunction<InferFnParameters<definitions>, InferFnReturn<definitions, result>, DeclaredFnReturn<definitions>>;
262
+ /** Parses function parameter schemas and validates calls and declared returns. */
263
+ export interface FnParser {
264
+ <const definitions extends readonly FnDefinition[]>(...definitions: definitions): FnFactory<definitions>;
265
+ raw<const definitions extends readonly FnDefinition[]>(...definitions: definitions): FnFactory<definitions>;
66
266
  }
67
267
  /** Runtime constructor-like value used by ArkType-compatible `instanceof Type` checks. */
68
268
  export declare const Type: () => void;
69
- /**
70
- * The `type()` builder: parses a definition into a callable schema.
71
- *
72
- * The `const def` generic drives static inference (`typeof schema.infer`);
73
- * the runtime is definition-shape-agnostic, hence the cast.
74
- */
75
- export declare function type<const def>(def: def): FluentType<InferDef<def>>;
269
+ export interface ConfigureSelector {
270
+ readonly kind?: string;
271
+ readonly where?: (node: {
272
+ readonly domain?: string;
273
+ readonly kind: string;
274
+ }) => boolean;
275
+ }
276
+ /** Callable runtime generic returned by `type("<t>", def)` and `type.generic(...)`. */
277
+ export type Generic = (...arguments_: readonly unknown[]) => BaseType;
278
+ /** Schema arguments passed to a callback-bodied runtime generic. */
279
+ export interface GenericArguments {
280
+ readonly [name: string]: BaseType;
281
+ }
282
+ export interface GenericBuilder {
283
+ (definition: (arguments_: GenericArguments) => unknown, hkt?: unknown): Generic;
284
+ (definition: unknown, hkt?: unknown): Generic;
285
+ }
286
+ export declare function type<const definition>(parameters: `<${string}>`, definition: definition): Generic;
287
+ export declare function type<const def>(def: def): FluentType<InferDef<def>, InferDefIn<def>>;
288
+ export declare function type<input, output>(def: SchemaInference<input> | string, operator: "=>", morph: (data: input, ctx: NarrowContext) => output): FluentType<Exclude<output, OmpErrors>, input>;
289
+ export declare function type<const input, const output>(def: input, operator: "|>", out: output): FluentType<InferDef<output>, InferDefIn<input>>;
290
+ export declare function type<const expression extends readonly unknown[]>(...definition: expression): FluentType<InferDef<expression>, InferDefIn<expression>>;
291
+ /** String keyword with a parser that morphs validated text to another output. */
292
+ export interface ParsedStringKeyword<parsed> extends FluentType<string> {
293
+ readonly parse: FluentType<parsed, string>;
294
+ }
295
+ /** Morphing string keyword paired with its non-morphing preformatted validator. */
296
+ export interface PreformattedKeyword extends FluentType<string, string> {
297
+ readonly preformatted: FluentType<string>;
298
+ }
299
+ /** Base64 keyword with its URL-safe alphabet variant. */
300
+ export interface Base64Keyword extends FluentType<string> {
301
+ readonly url: FluentType<string>;
302
+ }
303
+ /** Date-string keyword family. */
304
+ export interface DateStringKeyword extends ParsedStringKeyword<Date> {
305
+ readonly iso: ParsedStringKeyword<Date>;
306
+ readonly epoch: ParsedStringKeyword<Date>;
307
+ }
308
+ /** IP address keyword family. */
309
+ export interface IpKeyword extends FluentType<string> {
310
+ readonly v4: FluentType<string>;
311
+ readonly v6: FluentType<string>;
312
+ }
313
+ /** UUID keyword family. */
314
+ export interface UuidKeyword extends FluentType<string> {
315
+ readonly v1: FluentType<string>;
316
+ readonly v2: FluentType<string>;
317
+ readonly v3: FluentType<string>;
318
+ readonly v4: FluentType<string>;
319
+ readonly v5: FluentType<string>;
320
+ readonly v6: FluentType<string>;
321
+ readonly v7: FluentType<string>;
322
+ readonly v8: FluentType<string>;
323
+ }
324
+ /** String normalization keyword family. */
325
+ export interface NormalizeKeyword extends PreformattedKeyword {
326
+ readonly NFC: PreformattedKeyword;
327
+ readonly NFD: PreformattedKeyword;
328
+ readonly NFKC: PreformattedKeyword;
329
+ readonly NFKD: PreformattedKeyword;
330
+ }
331
+ /** Runtime string parsers exposed under `type.parse`. */
332
+ export interface ParseKeyword {
333
+ readonly number: FluentType<number, string>;
334
+ readonly integer: FluentType<number, string>;
335
+ readonly json: FluentType<unknown, string>;
336
+ readonly date: FluentType<Date, string>;
337
+ readonly url: FluentType<URL, string>;
338
+ readonly boolean: FluentType<boolean, string>;
339
+ readonly bigint: FluentType<bigint, string>;
340
+ }
341
+ /** Full string keyword module attached to `type.string`. */
342
+ export interface StringKeyword extends FluentType<string> {
343
+ readonly alpha: FluentType<string>;
344
+ readonly alphanumeric: FluentType<string>;
345
+ readonly base64: Base64Keyword;
346
+ readonly capitalize: PreformattedKeyword;
347
+ readonly creditCard: FluentType<string>;
348
+ readonly date: DateStringKeyword;
349
+ readonly digits: FluentType<string>;
350
+ readonly email: FluentType<string>;
351
+ readonly hex: FluentType<string>;
352
+ readonly integer: ParsedStringKeyword<number>;
353
+ readonly ip: IpKeyword;
354
+ readonly json: ParsedStringKeyword<unknown>;
355
+ readonly lower: PreformattedKeyword;
356
+ readonly normalize: NormalizeKeyword;
357
+ readonly numeric: ParsedStringKeyword<number>;
358
+ readonly regex: FluentType<string>;
359
+ readonly semver: FluentType<string>;
360
+ readonly trim: PreformattedKeyword;
361
+ readonly upper: PreformattedKeyword;
362
+ readonly url: ParsedStringKeyword<URL>;
363
+ readonly uuid: UuidKeyword;
364
+ }
365
+ /** Number keyword module attached to `type.number`. */
366
+ export interface NumberKeyword extends FluentType<number> {
367
+ readonly integer: FluentType<number>;
368
+ }
369
+ type Constructed<ctor> = ctor extends abstract new (...args: never[]) => infer instance ? instance : never;
370
+ type MatchDefault<input = unknown, output = unknown> = "assert" | "never" | "reject" | ((input: input, ...args: readonly unknown[]) => output);
371
+ type MatchCaseOutput<cases> = {
372
+ [key in keyof cases]: cases[key] extends (...args: never[]) => infer output ? output : never;
373
+ }[keyof cases];
374
+ /** A finalized matcher. Like a schema, it returns structured errors unless finalized with `"assert"`. */
375
+ export type Matcher<input = unknown, output = unknown> = FluentType<output, input> & (<const value extends input>(value: value, ...args: readonly unknown[]) => output | OmpErrors);
376
+ /** Fluent first-match parser exposed as `match` and `type.match`. */
377
+ export interface MatchParser<input = unknown, output = never> {
378
+ <const cases extends Record<PropertyKey, unknown>>(cases: cases): MatchParser<input, output | MatchCaseOutput<cases>> | Matcher<input, output | MatchCaseOutput<cases>>;
379
+ case<const definition, result>(definition: definition, resolver: (value: InferDef<definition>, ...args: readonly unknown[]) => result): MatchParser<input, output | result>;
380
+ match<const cases extends Record<PropertyKey, unknown>>(cases: cases): MatchParser<input, output | MatchCaseOutput<cases>> | Matcher<input, output | MatchCaseOutput<cases>>;
381
+ default<const result>(fallback: MatchDefault<input, result>): Matcher<input, output | result>;
382
+ at<const key extends PropertyKey>(key: key): MatchParser<input, output>;
383
+ at<const key extends PropertyKey, cases extends Record<PropertyKey, unknown>>(key: key, cases: cases): MatchParser<input, output | MatchCaseOutput<cases>> | Matcher<input, output | MatchCaseOutput<cases>>;
384
+ strings<const cases extends Record<PropertyKey, unknown>>(cases: cases): MatchParser<input, output | MatchCaseOutput<cases>> | Matcher<input, output | MatchCaseOutput<cases>>;
385
+ in<narrowed>(): MatchParser<narrowed, output>;
386
+ in<const definition>(definition: definition): MatchParser<InferDef<definition>, output>;
387
+ }
388
+ /** Build a fluent first-match dispatcher from schema definitions. */
389
+ declare const matchBuilder: MatchParser;
390
+ export { matchBuilder as match };
391
+ /** Declares a schema output type while preserving its inferred input. */
392
+ export interface DeclaredParser<declared> {
393
+ type<const definition>(definition: definition): FluentType<declared, InferDefIn<definition>>;
394
+ }
395
+ /** Fix a schema's externally declared static type without changing its runtime validation. */
396
+ export declare function declare<declared, _options = {}>(): DeclaredParser<declared>;
76
397
  export declare namespace type {
77
398
  /** Error aggregate returned by failed validations (`result instanceof type.errors`). */
78
- const errors: typeof OmpErrors;
79
- type errors = OmpErrors;
80
- /** Keyword statics for fluent building, e.g. `type.number.atLeast(5)`. */
81
- const string: FluentType<string>;
82
- const number: FluentType<number>;
83
- const boolean: FluentType<boolean>;
84
- const unknown: FluentType<unknown>;
85
- /** Union of literal values from a runtime array (`type.enumerated(...list)`). */
86
- function enumerated<const values extends readonly unknown[]>(...values: values): FluentType<values[number]>;
87
- /** Untyped builder for runtime-assembled definitions (`type.raw({...})`). */
88
- function raw(def: unknown): BaseType;
399
+ export const errors: typeof OmpErrors;
400
+ export type errors = OmpErrors;
401
+ /** Build a union from zero or more definitions. */
402
+ export function or<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryOrOutput<definitions>, NaryOrInput<definitions>>;
403
+ /** Build an intersection from zero or more definitions. */
404
+ export function and<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryAndOutput<definitions>, NaryAndInput<definitions>>;
405
+ /** Right-biased object merge over zero or more definitions. */
406
+ export function merge<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryMergeOutput<definitions>, NaryMergeInput<definitions>>;
407
+ /** Compose Types, definitions, and morph callbacks from left to right. */
408
+ export function pipe<const definitions extends readonly unknown[]>(...definitions: definitions): FluentType<NaryPipeOutput<definitions>, NaryPipeInput<definitions>>;
409
+ /** String validator and its refinement/morph keyword module. */
410
+ export const string: StringKeyword;
411
+ /** Runtime parser keyword family. */
412
+ export const parse: ParseKeyword;
413
+ /** Number validator with integer refinement. */
414
+ export const number: NumberKeyword;
415
+ /** Schema-valued key representing any non-negative integer array index. */
416
+ export const arrayIndex: FluentType<string, string>;
417
+ /** Boolean validator. */
418
+ export const boolean: FluentType<boolean, boolean>;
419
+ /** Bigint validator. */
420
+ export const bigint: FluentType<bigint, bigint>;
421
+ /** Symbol validator. */
422
+ export const symbol: FluentType<symbol, symbol>;
423
+ /** Non-null object validator. */
424
+ export const object: FluentType<object, object>;
425
+ /** Unknown validator. */
426
+ export const unknown: FluentType<unknown, unknown>;
427
+ /** Alias of the unknown validator. */
428
+ export const any: FluentType<unknown, unknown>;
429
+ /** Validator that rejects every value. */
430
+ export const never: FluentType<never, never>;
431
+ /** ArkType's built-in keyword namespace, including invokable utility generics. */
432
+ export const keywords: {
433
+ number: {
434
+ integer: FluentType<number, number>;
435
+ };
436
+ Map: FluentType<Map<unknown, unknown>, Map<unknown, unknown>>;
437
+ Set: FluentType<Set<unknown>, Set<unknown>>;
438
+ RegExp: FluentType<RegExp, RegExp>;
439
+ File: FluentType<File, File>;
440
+ Error: FluentType<Error, Error>;
441
+ Function: FluentType<Function, Function>;
442
+ Array: {
443
+ liftFrom<const definition>(definition: definition): FluentType<InferDef<definition>[], InferDefIn<definition> | InferDefIn<definition>[]>;
444
+ };
445
+ Record<const key, const value>(key: key, value: value): FluentType<Record<Extract<InferDef<key>, PropertyKey>, InferDef<value>>, Record<Extract<InferDefIn<key>, PropertyKey>, InferDefIn<value>>>;
446
+ Partial<const definition>(definition: definition): FluentType<Partial<InferDef<definition>>, Partial<InputObject<InferDefIn<definition>>>>;
447
+ Required<const definition>(definition: definition): FluentType<Required<InferDef<definition>>, Required<InputObject<InferDefIn<definition>>>>;
448
+ Pick<const definition, const keys extends readonly PropertyKey[]>(definition: definition, ...keys: keys): FluentType<Pick<InferDef<definition>, Extract<keys[number], keyof InferDef<definition>>>, Pick<InputObject<InferDefIn<definition>>, Extract<keys[number], keyof InputObject<InferDefIn<definition>>>>>;
449
+ Omit<const definition, const keys extends readonly PropertyKey[]>(definition: definition, ...keys: keys): FluentType<Omit<InferDef<definition>, Extract<keys[number], keyof InferDef<definition>>>, Omit<InputObject<InferDefIn<definition>>, Extract<keys[number], keyof InputObject<InferDefIn<definition>>>>>;
450
+ Merge<const left, const right>(left: left, right: right): FluentType<MergeTypes<InferDef<left>, InferDef<right>>, MergeTypes<InferDefIn<left>, InferDefIn<right>>>;
451
+ object: {
452
+ json: FluentType<unknown, unknown>;
453
+ };
454
+ unknown: {
455
+ any: FluentType<unknown, unknown>;
456
+ };
457
+ };
458
+ /** Date instance validator. */
459
+ export const Date: FluentType<Date, Date>;
460
+ /** Validate instances of `ctor`. */
461
+ export function instanceOf<const ctor extends Constructor>(ctor: ctor): FluentType<Constructed<ctor>>;
462
+ /** Validate one exact unit value. */
463
+ export function unit<const value>(value: value): FluentType<value>;
464
+ /** Union of literal values from a runtime array. */
465
+ export function enumerated<const values extends readonly unknown[]>(...values: values): FluentType<values[number]>;
466
+ /** Enumerate an enum-like object's forward values, excluding numeric reverse mappings. */
467
+ export function valueOf<const values extends Record<PropertyKey, unknown>>(values: values): FluentType<values[keyof values]>;
468
+ /** Fluent first-match dispatcher, also exported as standalone `match`. */
469
+ export const match: MatchParser;
470
+ /** Preserve a definition's literal type while authoring reusable modules. */
471
+ export function define<const definition>(definition: definition): definition;
472
+ /** Build a function whose arguments and optional declared return are validated. */
473
+ export const fn: FnParser;
474
+ /** Fix an externally declared static type while retaining runtime validation. */
475
+ export const declare: <declared, _options = {}>() => DeclaredParser<declared>;
476
+ /** Build a lazy named scope from aliases and recursive definitions. */
477
+ export function scope(aliases: Record<string, unknown>, options?: ScopeOptions): TypeScope;
478
+ /** Compile a named schema module whose definitions may reference each other. */
479
+ export function module<const definitions extends Record<string, unknown>>(definitions: definitions, options?: ScopeOptions): {
480
+ [name in keyof definitions]: Type<InferDef<definitions[name]>, InferDefIn<definitions[name]>>;
481
+ };
482
+ type GenericParameterSpec = string | readonly [name: string, constraint: unknown];
483
+ /** Build a generic directly from an angle-bracket declaration. */
484
+ export function generic<const definition>(parameters: `<${string}>`, definition: definition): Generic;
485
+ /** Build a curried generic from named, optionally constrained parameters. */
486
+ export function generic(...parameters: readonly GenericParameterSpec[]): GenericBuilder;
487
+ /** Untyped builder for runtime-assembled definitions. */
488
+ export function raw(def: unknown): BaseType;
489
+ export {};
89
490
  }
90
491
  export interface ScopeOptions {
91
492
  jitless?: boolean;
493
+ clone?: false | ((input: unknown) => unknown);
494
+ divisor?: SchemaConfig;
495
+ }
496
+ /** Callable builder bound to one alias scope. */
497
+ export type ScopedBuilder = (<const definition>(definition: definition) => FluentType<InferDef<definition>, InferDefIn<definition>>) & typeof type;
498
+ /** Named schema scope with scoped parsing, imports, and bound module exports. */
499
+ export interface TypeScope {
500
+ readonly type: ScopedBuilder;
501
+ readonly match: MatchParser;
502
+ readonly json: Record<string, unknown>;
503
+ define<const definition>(definition: definition): definition;
504
+ resolve(name: string): BaseType;
505
+ import(...names: readonly string[]): Record<string, unknown>;
506
+ export(...names: readonly string[]): Record<string, BaseType>;
507
+ }
508
+ /** Build a scope whose aliases resolve lazily, including recursive cycles. */
509
+ export declare function scope(aliases: Record<string, unknown>, options?: ScopeOptions): TypeScope;
510
+ export declare namespace scope {
511
+ /** Preserve a scope definition's literal shape without constructing it. */
512
+ function define<const aliases>(definitions: aliases): aliases;
92
513
  }
93
- /** ArkType-compatible scope wrapper; omptype's global builder is already lazy. */
94
- export declare function scope(_aliases: Record<string, unknown>, _options?: ScopeOptions): {
95
- type: typeof type;
96
- };
97
514
  /** A schema whose output type is not statically known (`type.raw` results). */
98
- export type BaseType = FluentType<unknown>;
515
+ export type BaseType = FluentType<unknown, unknown>;
516
+ /**
517
+ * Minimal structural constraint matching any omptype schema.
518
+ *
519
+ * `FluentType`'s recursive fluent surface makes `T extends FluentType<...>`
520
+ * checks descend until TypeScript's depth limiter reports spurious
521
+ * incompatibilities, and its invariant input parameter rejects concrete
522
+ * schemas outright. This interface exposes only the schema marker plus the
523
+ * members generic helpers commonly need — method syntax keeps parameter
524
+ * positions bivariant, and returns recurse shallowly through `AnyType`.
525
+ */
526
+ export interface AnyType {
527
+ (data: unknown): unknown;
528
+ readonly [IR_BRAND]: true;
529
+ readonly ir: IR;
530
+ readonly infer: unknown;
531
+ readonly inferIn: unknown;
532
+ readonly hasDefault: boolean;
533
+ readonly description?: string;
534
+ run(data: unknown): unknown;
535
+ assert(data: unknown): unknown;
536
+ allows(data: unknown): boolean;
537
+ toJsonSchema(options?: ToJsonSchemaOptions): Record<string, unknown>;
538
+ describe(description: string): AnyType;
539
+ default(value: unknown): AnyType;
540
+ or(def: Def): AnyType;
541
+ and(def: Def): AnyType;
542
+ pipe(fn: (data: never, ctx: NarrowContext) => unknown): AnyType;
543
+ narrow(fn: (data: never, ctx: NarrowContext) => unknown): AnyType;
544
+ array(): AnyType;
545
+ }
546
+ declare const submoduleType: unique symbol;
547
+ type BoundAlias<value> = value extends Submodule<infer aliases> ? Submodule<aliases> : FluentType<value>;
548
+ /** Exported aliases from a scope, each bound to that scope's resolver. */
549
+ export type Module<aliases extends Record<string, unknown>> = {
550
+ readonly [name in keyof aliases]: BoundAlias<aliases[name]>;
551
+ };
552
+ /** A module nested under an alias rather than directly parseable as a schema. */
553
+ export type Submodule<aliases extends Record<string, unknown>> = {
554
+ readonly [submoduleType]?: aliases;
555
+ } & {
556
+ readonly [name in keyof aliases]: BoundAlias<aliases[name]>;
557
+ };
558
+ /** A selected module export whose schemas retain access to the full scope. */
559
+ export type BoundModule<exports extends Record<string, unknown>, _allAliases extends Record<string, unknown> = exports> = Module<exports>;
560
+ /** Type-level view of a named scope. */
561
+ export type Scope<aliases extends Record<string, unknown>> = TypeScope & {
562
+ readonly t: aliases;
563
+ };
99
564
  /** `hasMorph` re-export for diagnostics/tooling. */
100
565
  export { hasMorph };