@oh-my-pi/omptype 17.2.6
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 +8 -0
- package/README.md +60 -0
- package/dist/types/ark.d.ts +26 -0
- package/dist/types/compile.d.ts +5 -0
- package/dist/types/errors.d.ts +63 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/infer.d.ts +49 -0
- package/dist/types/interp.d.ts +24 -0
- package/dist/types/ir.d.ts +115 -0
- package/dist/types/json-schema.d.ts +8 -0
- package/dist/types/type.d.ts +100 -0
- package/dist/types/typebox.d.ts +184 -0
- package/dist/types/zod.d.ts +100 -0
- package/package.json +56 -0
- package/src/ark.ts +30 -0
- package/src/compile.ts +415 -0
- package/src/errors.ts +136 -0
- package/src/index.ts +13 -0
- package/src/infer.ts +160 -0
- package/src/interp.ts +282 -0
- package/src/ir.ts +480 -0
- package/src/json-schema.ts +172 -0
- package/src/type.ts +329 -0
- package/src/typebox.ts +487 -0
- package/src/zod.ts +339 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { type NarrowContext, type Type as OmpType } from "./type.js";
|
|
2
|
+
export interface Meta {
|
|
3
|
+
title?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
default?: unknown;
|
|
6
|
+
examples?: unknown[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface StringOpts extends Meta {
|
|
10
|
+
minLength?: number;
|
|
11
|
+
maxLength?: number;
|
|
12
|
+
pattern?: string;
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface NumberOpts extends Meta {
|
|
16
|
+
minimum?: number;
|
|
17
|
+
maximum?: number;
|
|
18
|
+
exclusiveMinimum?: number;
|
|
19
|
+
exclusiveMaximum?: number;
|
|
20
|
+
multipleOf?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ArrayOpts extends Meta {
|
|
23
|
+
minItems?: number;
|
|
24
|
+
maxItems?: number;
|
|
25
|
+
uniqueItems?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ObjectOpts extends Meta {
|
|
28
|
+
additionalProperties?: boolean | TSchema;
|
|
29
|
+
}
|
|
30
|
+
declare const OPTIONAL_INNER: unique symbol;
|
|
31
|
+
declare const OBJECT_INFO: unique symbol;
|
|
32
|
+
export interface TypeBoxValidationFailure {
|
|
33
|
+
message: string;
|
|
34
|
+
}
|
|
35
|
+
export type TypeBoxSafeParseResult<T> = {
|
|
36
|
+
success: true;
|
|
37
|
+
data: T;
|
|
38
|
+
} | {
|
|
39
|
+
success: false;
|
|
40
|
+
error: TypeBoxValidationFailure;
|
|
41
|
+
};
|
|
42
|
+
interface LegacyTypeBoxCompat<T> {
|
|
43
|
+
/** TypeBox compatibility validator used by legacy extension loaders. */
|
|
44
|
+
__validator(data: unknown): T | TypeBoxValidationFailure;
|
|
45
|
+
/** Zod-style compatibility parser used by legacy extensions. */
|
|
46
|
+
safeParse(input: unknown): TypeBoxSafeParseResult<T>;
|
|
47
|
+
}
|
|
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<{
|
|
61
|
+
-readonly [K in keyof E]: Static<E[K]>;
|
|
62
|
+
}>;
|
|
63
|
+
export type TOptional<E extends TSchema> = TSchema<Static<E> | undefined> & {
|
|
64
|
+
readonly [OPTIONAL_INNER]: E;
|
|
65
|
+
};
|
|
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>> = {
|
|
74
|
+
[K in keyof P]-?: P[K] extends {
|
|
75
|
+
readonly [OPTIONAL_INNER]: TSchema;
|
|
76
|
+
} ? K : never;
|
|
77
|
+
}[keyof P];
|
|
78
|
+
type RequiredKeys<P extends Record<string, TSchema>> = Exclude<keyof P, OptionalKeys<P>>;
|
|
79
|
+
type ObjectStatic<P extends Record<string, TSchema>> = {
|
|
80
|
+
[K in RequiredKeys<P>]: Static<P[K]>;
|
|
81
|
+
} & {
|
|
82
|
+
[K in OptionalKeys<P>]?: Exclude<Static<P[K]>, undefined>;
|
|
83
|
+
};
|
|
84
|
+
export type TObject<P extends Record<string, TSchema> = Record<string, TSchema>> = TSchema<ObjectStatic<P>>;
|
|
85
|
+
type RequiredProps<P extends Record<string, TSchema>> = {
|
|
86
|
+
[K in keyof P]: P[K] extends TOptional<infer E> ? E : P[K];
|
|
87
|
+
};
|
|
88
|
+
interface RuntimeType<T> extends OmpType<T> {
|
|
89
|
+
[OPTIONAL_INNER]?: TSchema;
|
|
90
|
+
[OBJECT_INFO]?: ObjectInfo;
|
|
91
|
+
describe(description: string): RuntimeType<T>;
|
|
92
|
+
default(value: T | (() => T)): RuntimeType<T>;
|
|
93
|
+
or<R>(schema: OmpType<R>): RuntimeType<T | R>;
|
|
94
|
+
and<R>(schema: OmpType<R>): RuntimeType<T & R>;
|
|
95
|
+
array(): RuntimeType<T[]>;
|
|
96
|
+
atLeastLength(bound: number): RuntimeType<T>;
|
|
97
|
+
atMostLength(bound: number): RuntimeType<T>;
|
|
98
|
+
atLeast(bound: number): RuntimeType<T>;
|
|
99
|
+
atMost(bound: number): RuntimeType<T>;
|
|
100
|
+
narrow<N extends T>(predicate: (value: T, ctx: NarrowContext) => value is N): RuntimeType<N>;
|
|
101
|
+
narrow(predicate: (value: T, ctx: NarrowContext) => boolean): RuntimeType<T>;
|
|
102
|
+
}
|
|
103
|
+
type CompatRuntime<T> = RuntimeType<T> & LegacyTypeBoxCompat<T>;
|
|
104
|
+
type ObjectInfo = {
|
|
105
|
+
props: Record<string, TSchema>;
|
|
106
|
+
additionalProperties?: boolean | TSchema;
|
|
107
|
+
};
|
|
108
|
+
declare function tString(opts?: StringOpts): TString;
|
|
109
|
+
declare function tLiteral<const V extends string | number | boolean | null>(value: V, opts?: Meta): TLiteral<V>;
|
|
110
|
+
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]>>>;
|
|
113
|
+
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]>>>;
|
|
126
|
+
declare function tUnsafe<T = unknown>(_jsonSchema?: Record<string, unknown>): TUnsafe<T>;
|
|
127
|
+
export declare const Type: {
|
|
128
|
+
readonly String: typeof tString;
|
|
129
|
+
readonly Number: (opts?: NumberOpts) => TNumber;
|
|
130
|
+
readonly Integer: (opts?: NumberOpts) => TNumber;
|
|
131
|
+
readonly Boolean: (opts?: Meta) => CompatRuntime<boolean>;
|
|
132
|
+
readonly Null: (opts?: Meta) => CompatRuntime<null>;
|
|
133
|
+
readonly Any: (opts?: Meta) => CompatRuntime<unknown>;
|
|
134
|
+
readonly Unknown: (opts?: Meta) => CompatRuntime<unknown>;
|
|
135
|
+
readonly Never: typeof tNever;
|
|
136
|
+
readonly Literal: typeof tLiteral;
|
|
137
|
+
readonly Union: typeof tUnion;
|
|
138
|
+
readonly Intersect: typeof tIntersect;
|
|
139
|
+
readonly Enum: typeof tEnum;
|
|
140
|
+
readonly Array: typeof tArray;
|
|
141
|
+
readonly Tuple: typeof tTuple;
|
|
142
|
+
readonly Object: typeof tObject;
|
|
143
|
+
readonly Record: typeof tRecord;
|
|
144
|
+
readonly Optional: typeof tOptional;
|
|
145
|
+
readonly Nullable: typeof tNullable;
|
|
146
|
+
readonly Readonly: <E extends TSchema>(schema: E) => E;
|
|
147
|
+
readonly Partial: typeof tPartial;
|
|
148
|
+
readonly Required: typeof tRequired;
|
|
149
|
+
readonly Pick: typeof tPick;
|
|
150
|
+
readonly Omit: typeof tOmit;
|
|
151
|
+
readonly Composite: typeof tComposite;
|
|
152
|
+
readonly Unsafe: typeof tUnsafe;
|
|
153
|
+
};
|
|
154
|
+
export type TypeBuilder = typeof Type;
|
|
155
|
+
declare const _default: {
|
|
156
|
+
Type: {
|
|
157
|
+
readonly String: typeof tString;
|
|
158
|
+
readonly Number: (opts?: NumberOpts) => TNumber;
|
|
159
|
+
readonly Integer: (opts?: NumberOpts) => TNumber;
|
|
160
|
+
readonly Boolean: (opts?: Meta) => CompatRuntime<boolean>;
|
|
161
|
+
readonly Null: (opts?: Meta) => CompatRuntime<null>;
|
|
162
|
+
readonly Any: (opts?: Meta) => CompatRuntime<unknown>;
|
|
163
|
+
readonly Unknown: (opts?: Meta) => CompatRuntime<unknown>;
|
|
164
|
+
readonly Never: typeof tNever;
|
|
165
|
+
readonly Literal: typeof tLiteral;
|
|
166
|
+
readonly Union: typeof tUnion;
|
|
167
|
+
readonly Intersect: typeof tIntersect;
|
|
168
|
+
readonly Enum: typeof tEnum;
|
|
169
|
+
readonly Array: typeof tArray;
|
|
170
|
+
readonly Tuple: typeof tTuple;
|
|
171
|
+
readonly Object: typeof tObject;
|
|
172
|
+
readonly Record: typeof tRecord;
|
|
173
|
+
readonly Optional: typeof tOptional;
|
|
174
|
+
readonly Nullable: typeof tNullable;
|
|
175
|
+
readonly Readonly: <E extends TSchema>(schema: E) => E;
|
|
176
|
+
readonly Partial: typeof tPartial;
|
|
177
|
+
readonly Required: typeof tRequired;
|
|
178
|
+
readonly Pick: typeof tPick;
|
|
179
|
+
readonly Omit: typeof tOmit;
|
|
180
|
+
readonly Composite: typeof tComposite;
|
|
181
|
+
readonly Unsafe: typeof tUnsafe;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
export default _default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Type } from "./type.js";
|
|
2
|
+
interface OptionalSchemaMarker {
|
|
3
|
+
readonly _optional: true;
|
|
4
|
+
}
|
|
5
|
+
interface RefineOptions {
|
|
6
|
+
message?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ZodLikeIssue {
|
|
10
|
+
path: PropertyKey[];
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
export type ZodLikeSafeParseResult<Out> = {
|
|
14
|
+
success: true;
|
|
15
|
+
data: Out;
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: {
|
|
19
|
+
message: string;
|
|
20
|
+
issues: ZodLikeIssue[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** A callable omptype schema carrying the Zod-v4-style fluent surface. */
|
|
24
|
+
export interface ZodLikeSchema<out Out> extends Type<Out> {
|
|
25
|
+
readonly _output: Out;
|
|
26
|
+
/** @internal Used while composing object property IR. */
|
|
27
|
+
readonly isOptional: boolean;
|
|
28
|
+
parse(value: unknown): Out;
|
|
29
|
+
safeParse(value: unknown): ZodLikeSafeParseResult<Out>;
|
|
30
|
+
min(bound: number): ZodLikeSchema<Out>;
|
|
31
|
+
max(bound: number): ZodLikeSchema<Out>;
|
|
32
|
+
int(): ZodLikeSchema<Out>;
|
|
33
|
+
positive(): ZodLikeSchema<Out>;
|
|
34
|
+
nonnegative(): ZodLikeSchema<Out>;
|
|
35
|
+
regex(expression: RegExp, message?: string): ZodLikeSchema<Out>;
|
|
36
|
+
url(): ZodLikeSchema<Out>;
|
|
37
|
+
optional(): ZodLikeSchema<Out | undefined> & OptionalSchemaMarker;
|
|
38
|
+
nullable(): ZodLikeSchema<Out | null>;
|
|
39
|
+
default(value: Exclude<Out, undefined> | (() => Exclude<Out, undefined>)): ZodLikeSchema<Exclude<Out, undefined>>;
|
|
40
|
+
describe(description: string): ZodLikeSchema<Out>;
|
|
41
|
+
refine(predicate: (value: Out) => unknown, messageOrOptions?: string | RefineOptions): ZodLikeSchema<Out>;
|
|
42
|
+
transform<Next>(transformer: (value: Out) => Next): ZodLikeSchema<Next>;
|
|
43
|
+
catch(fallback: Out | (() => Out)): ZodLikeSchema<Out>;
|
|
44
|
+
strict(): ZodLikeSchema<Out>;
|
|
45
|
+
passthrough(): ZodLikeSchema<Out & Record<string, unknown>>;
|
|
46
|
+
strip(): ZodLikeSchema<Out>;
|
|
47
|
+
partial(): Out extends object ? ZodLikeSchema<Partial<Out>> : ZodLikeSchema<Out>;
|
|
48
|
+
}
|
|
49
|
+
export type infer<T> = T extends {
|
|
50
|
+
readonly _output: infer Out;
|
|
51
|
+
} ? Out : never;
|
|
52
|
+
type SchemaOutput<Schema> = Schema extends {
|
|
53
|
+
readonly _output: infer Out;
|
|
54
|
+
} ? Out : never;
|
|
55
|
+
type Shape = Readonly<Record<string, ZodLikeSchema<unknown>>>;
|
|
56
|
+
type ObjectOutput<S extends Shape> = {
|
|
57
|
+
-readonly [K in keyof S as S[K] extends OptionalSchemaMarker ? never : K]: SchemaOutput<S[K]>;
|
|
58
|
+
} & {
|
|
59
|
+
-readonly [K in keyof S as S[K] extends OptionalSchemaMarker ? K : never]?: SchemaOutput<S[K]>;
|
|
60
|
+
};
|
|
61
|
+
type Simplify<T> = {
|
|
62
|
+
[K in keyof T]: T[K];
|
|
63
|
+
};
|
|
64
|
+
type UnionOutput<Schemas extends readonly ZodLikeSchema<unknown>[]> = SchemaOutput<Schemas[number]>;
|
|
65
|
+
export declare const string: () => ZodLikeSchema<string>;
|
|
66
|
+
export declare const number: () => ZodLikeSchema<number>;
|
|
67
|
+
export declare const boolean: () => ZodLikeSchema<boolean>;
|
|
68
|
+
export declare const literal: <const Value>(value: Value) => ZodLikeSchema<Value>;
|
|
69
|
+
declare const enumSchema: <const Values extends readonly [string, ...string[]]>(values: Values) => ZodLikeSchema<Values[number]>;
|
|
70
|
+
export { enumSchema as enum };
|
|
71
|
+
export declare const union: <const Schemas extends readonly [ZodLikeSchema<unknown>, ZodLikeSchema<unknown>, ...ZodLikeSchema<unknown>[]]>(schemas: Schemas) => ZodLikeSchema<UnionOutput<Schemas>>;
|
|
72
|
+
export declare const array: <Element>(element: ZodLikeSchema<Element>) => ZodLikeSchema<Element[]>;
|
|
73
|
+
export declare const object: <const S extends Shape>(shape: S) => ZodLikeSchema<Simplify<ObjectOutput<S>>>;
|
|
74
|
+
export declare const record: <Key extends string, Value>(keySchema: ZodLikeSchema<Key>, valueSchema: ZodLikeSchema<Value>) => ZodLikeSchema<Record<string, Value>>;
|
|
75
|
+
export declare const unknown: () => ZodLikeSchema<unknown>;
|
|
76
|
+
export declare const any: () => ZodLikeSchema<unknown>;
|
|
77
|
+
declare const nullSchema: () => ZodLikeSchema<null>;
|
|
78
|
+
declare const undefinedSchema: () => ZodLikeSchema<undefined>;
|
|
79
|
+
export { nullSchema as null, undefinedSchema as undefined };
|
|
80
|
+
/** Runtime `z.*` facade, merged with the `z.infer` type namespace below. */
|
|
81
|
+
export declare const z: {
|
|
82
|
+
string: typeof string;
|
|
83
|
+
number: typeof number;
|
|
84
|
+
boolean: typeof boolean;
|
|
85
|
+
literal: typeof literal;
|
|
86
|
+
enum: typeof enumSchema;
|
|
87
|
+
union: typeof union;
|
|
88
|
+
array: typeof array;
|
|
89
|
+
object: typeof object;
|
|
90
|
+
record: typeof record;
|
|
91
|
+
unknown: typeof unknown;
|
|
92
|
+
any: typeof any;
|
|
93
|
+
null: typeof nullSchema;
|
|
94
|
+
undefined: typeof undefinedSchema;
|
|
95
|
+
};
|
|
96
|
+
export declare namespace z {
|
|
97
|
+
type infer<Schema> = Schema extends {
|
|
98
|
+
readonly _output: infer Out;
|
|
99
|
+
} ? Out : never;
|
|
100
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@oh-my-pi/omptype",
|
|
4
|
+
"version": "17.2.6",
|
|
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/can1357/oh-my-pi.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": "./dist/types/index.d.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
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bun": "^1.3.14"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.3.14"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"README.md",
|
|
42
|
+
"CHANGELOG.md",
|
|
43
|
+
"dist/types"
|
|
44
|
+
],
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./dist/types/index.d.ts",
|
|
48
|
+
"import": "./src/index.ts"
|
|
49
|
+
},
|
|
50
|
+
"./*": {
|
|
51
|
+
"types": "./dist/types/*.d.ts",
|
|
52
|
+
"import": "./src/*.ts"
|
|
53
|
+
},
|
|
54
|
+
"./*.js": "./src/*.ts"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/ark.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArkType compatibility facade — `@oh-my-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 "@oh-my-pi/omptype/ark"` and nothing else changes. New code should
|
|
7
|
+
* import `@oh-my-pi/omptype` directly.
|
|
8
|
+
*
|
|
9
|
+
* Compatibility affordances beyond the plain re-export:
|
|
10
|
+
* - `ArkError` / `ArkErrors` alias `OmpError` / `OmpErrors`.
|
|
11
|
+
* - `scope()` (alias-free form only) returns `{ type }`; the `jitless` flag is
|
|
12
|
+
* obsolete — omptype always starts interpreted and JIT-compiles lazily.
|
|
13
|
+
*/
|
|
14
|
+
import { OmpError, OmpErrors, OmpTypeError } from "./errors";
|
|
15
|
+
import { type } from "./type";
|
|
16
|
+
|
|
17
|
+
export * from "./index";
|
|
18
|
+
|
|
19
|
+
export const ArkError = OmpError;
|
|
20
|
+
export type ArkError = OmpError;
|
|
21
|
+
export const ArkErrors = OmpErrors;
|
|
22
|
+
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
|
+
}
|