@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.
@@ -1,4 +1,5 @@
1
- import { type NarrowContext, type Type as OmpType } from "./type.js";
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 | TSchema;
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
- export type TSchema<T = unknown> = OmpType<T> & LegacyTypeBoxCompat<T>;
49
- export type Static<T extends TSchema> = T["infer"];
50
- export type TAny = TSchema<unknown>;
51
- export type TUnknown = TSchema<unknown>;
52
- export type TNever = TSchema<never>;
53
- export type TNull = TSchema<null>;
54
- export type TString = TSchema<string>;
55
- export type TNumber = TSchema<number>;
56
- export type TInteger = TSchema<number>;
57
- export type TBoolean = TSchema<boolean>;
58
- export type TLiteral<V extends string | number | boolean | null> = TSchema<V>;
59
- export type TArray<E extends TSchema> = TSchema<Static<E>[]>;
60
- export type TTuple<E extends readonly TSchema[] = readonly TSchema[]> = TSchema<{
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 TSchema> = TSchema<Static<E> | undefined> & {
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 TSchema[] = readonly TSchema[]> = TSchema<Static<E[number]>>;
67
- export type TIntersect<E extends readonly TSchema[] = readonly TSchema[]> = TSchema<UnionToIntersection<Static<E[number]>>>;
68
- export type TEnum<E extends readonly (string | number)[] = readonly (string | number)[]> = TSchema<E[number]>;
69
- export type TRecord<K extends TSchema, V extends TSchema> = TSchema<Record<Extract<Static<K>, PropertyKey>, Static<V>>>;
70
- export type TNullable<E extends TSchema> = TSchema<Static<E> | null>;
71
- export type TReadonly<E extends TSchema> = TSchema<Readonly<Static<E>>>;
72
- export type TUnsafe<T = unknown> = TSchema<T>;
73
- type OptionalKeys<P extends Record<string, TSchema>> = {
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]: TSchema;
103
+ readonly [OPTIONAL_INNER]: AnySchema;
76
104
  } ? K : never;
77
105
  }[keyof P];
78
- type RequiredKeys<P extends Record<string, TSchema>> = Exclude<keyof P, OptionalKeys<P>>;
79
- type ObjectStatic<P extends Record<string, TSchema>> = {
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, TSchema> = Record<string, TSchema>> = TSchema<ObjectStatic<P>>;
85
- type RequiredProps<P extends Record<string, TSchema>> = {
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]?: TSchema;
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<R>(schema: OmpType<R>): RuntimeType<T | R>;
94
- and<R>(schema: OmpType<R>): RuntimeType<T & R>;
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, TSchema>;
106
- additionalProperties?: boolean | TSchema;
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 TSchema[]>(schemas: E, opts?: Meta): TUnion<E>;
112
- declare function tIntersect<const E extends readonly TSchema[]>(schemas: E, opts?: Meta): TSchema<UnionToIntersection<Static<E[number]>>>;
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): TSchema<E extends readonly (infer V)[] ? V : E[keyof E]>;
115
- declare function tArray<E extends TSchema>(item: E, opts?: ArrayOpts): TArray<E>;
116
- declare function tTuple<const E extends readonly TSchema[]>(items: E, opts?: Meta): TTuple<E>;
117
- declare function tObject<const P extends Record<string, TSchema>>(properties: P, opts?: ObjectOpts): TObject<P>;
118
- declare function tRecord<K extends TSchema, V extends TSchema>(key: K, value: V, opts?: Meta): TRecord<K, V>;
119
- declare function tOptional<E extends TSchema>(schema: E, opts?: Meta): TOptional<E>;
120
- declare function tNullable<E extends TSchema>(schema: E, opts?: Meta): TSchema<Static<E> | null>;
121
- declare function tPartial<P extends Record<string, TSchema>>(schema: TObject<P>): TSchema<Partial<ObjectStatic<P>>>;
122
- declare function tRequired<P extends Record<string, TSchema>>(schema: TObject<P>): TObject<RequiredProps<P>>;
123
- declare function tPick<P extends Record<string, TSchema>, const K extends readonly (keyof P)[]>(schema: TObject<P>, keys: K): TObject<Pick<P, K[number]>>;
124
- declare function tOmit<P extends Record<string, TSchema>, const K extends readonly (keyof P)[]>(schema: TObject<P>, keys: K): TObject<Omit<P, K[number]>>;
125
- declare function tComposite<const E extends readonly TObject<Record<string, TSchema>>[]>(schemas: E, opts?: ObjectOpts): TSchema<UnionToIntersection<Static<E[number]>>>;
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 TSchema>(schema: E) => E;
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 TSchema>(schema: E) => E;
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.7",
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
  },