arktype 2.0.3 → 2.1.0

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/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  <h1 align="center">ArkType</h1>
2
+ <h3 align="center"><i>Optimized runtime validation for TypeScript syntax</i></h1>
2
3
 
3
4
  ArkType is a runtime validation library that parses optimized validators from familiar, type-safe syntax.
4
5
 
@@ -11,7 +12,7 @@ controls
11
12
  playsInline
12
13
  muted
13
14
  disablePictureInPicture
14
- src="https://github.com/user-attachments/assets/eaace5f0-310e-4fc8-9a95-1c0afc6fd110"
15
+ src="https://github.com/user-attachments/assets/69fdded6-50a9-402d-a28c-afa58db63c90"
15
16
  />
16
17
 
17
18
  ## Docs
@@ -48,114 +49,144 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
48
49
  ### ArkSponsors ⛵
49
50
 
50
51
  <table>
51
- <tr>
52
- <th>sam-goodwin</th>
53
- <th>fubhy</th>
54
- </tr>
55
- <tr>
56
- <td>
57
- <a href="https://github.com/sam-goodwin"
58
- ><img
59
- height="64px"
60
- src="https://avatars.githubusercontent.com/u/38672686"
61
- /></a>
62
- </td>
63
- <td>
64
- <a href="https://github.com/fubhy"
65
- ><img
66
- height="64px"
67
- src="https://avatars.githubusercontent.com/u/1172528"
68
- /></a>
69
- </td>
52
+ <tr>
53
+ <th>sam-goodwin</th>
54
+ <th>inspatiallabs</th>
55
+ </tr>
56
+ <tr>
57
+ <td>
58
+ <a href="https://github.com/sam-goodwin"
59
+ ><img
60
+ height="64px"
61
+ src="https://avatars.githubusercontent.com/sam-goodwin"
62
+ /></a>
63
+ </td>
64
+ <td>
65
+ <a href="https://github.com/inspatiallabs"
66
+ ><img
67
+ height="64px"
68
+ src="https://avatars.githubusercontent.com/inspatiallabs"
69
+ /></a>
70
+ </td>
70
71
  </tr>
71
72
  </table>
72
73
 
73
74
  ### Sponsors 🥰
74
75
 
75
76
  <table>
76
- <tr>
77
- <th>tmm</th>
77
+ <tr>
78
+ <th>fubhy</th>
79
+ <th>tmm</th>
78
80
  <th>mishushakov</th>
79
81
  <th>mewhhaha</th>
80
- <th>codeandcats</th>
81
- <th>drwpwrs</th>
82
- </tr>
83
- <tr>
84
- <td>
85
- <a href="https://github.com/tmm"
86
- ><img
87
- height="64px"
88
- src="https://avatars.githubusercontent.com/u/6759464"
89
- /></a>
90
- </td>
82
+ <th>codeandcats</th>
83
+ </tr>
84
+ <tr>
91
85
  <td>
92
- <a href="https://github.com/mishushakov"
93
- ><img height="64px" src="https://avatars.githubusercontent.com/u/10400064"
94
- /></a>
95
- </td>
86
+ <a href="https://github.com/fubhy"
87
+ ><img
88
+ height="64px"
89
+ src="https://avatars.githubusercontent.com/fubhy"
90
+ /></a>
91
+ </td>
96
92
  <td>
97
- <a href="https://github.com/mewhhaha"
98
- ><img
99
- height="64px"
100
- src="https://avatars.githubusercontent.com/u/3399205"
101
- /></a>
102
- </td>
103
- <td>
104
- <a href="https://github.com/codeandcats"
105
- ><img
106
- height="64px"
107
- src="https://avatars.githubusercontent.com/u/6035934"
108
- /></a>
109
- </td>
110
- <td>
111
- <a href="https://github.com/drwpwrs"
112
- ><img
113
- height="64px"
114
- src="https://avatars.githubusercontent.com/u/49917220"
115
- /></a>
116
- </td>
117
- </tr>
118
- <tr>
119
- <th>Timeraa</th>
120
- <th>Phalangers</th>
121
- <th>WilliamConnatser</th>
122
- <th>JameEnder</th>
93
+ <a href="https://github.com/tmm"
94
+ ><img
95
+ height="64px"
96
+ src="https://avatars.githubusercontent.com/tmm"
97
+ /></a>
98
+ </td>
99
+ <td>
100
+ <a href="https://github.com/mishushakov"
101
+ ><img height="64px" src="https://avatars.githubusercontent.com/mishushakov"
102
+ /></a>
103
+ </td>
104
+ <td>
105
+ <a href="https://github.com/mewhhaha"
106
+ ><img
107
+ height="64px"
108
+ src="https://avatars.githubusercontent.com/mewhhaha"
109
+ /></a>
110
+ </td>
111
+ <td>
112
+ <a href="https://github.com/codeandcats"
113
+ ><img
114
+ height="64px"
115
+ src="https://avatars.githubusercontent.com/codeandcats"
116
+ /></a>
117
+ </td>
123
118
  </tr>
124
119
  <tr>
125
- <td>
126
- <a href="https://github.com/Timeraa"
127
- ><img
128
- height="64px"
129
- src="https://avatars.githubusercontent.com/u/29104008"
130
- /></a>
131
- </td>
132
- <td>
133
- <a href="https://github.com/Phalangers"
134
- ><img
135
- height="64px"
136
- src="https://avatars.githubusercontent.com/u/13227796"
137
- /></a>
138
- </td>
120
+ <th>drwpwrs</th>
121
+ <th>Timeraa</th>
122
+ <th>Phalangers</th>
123
+ <th>WilliamConnatser</th>
124
+ <th>JameEnder</th>
125
+ </tr>
126
+ <tr>
127
+ <td>
128
+ <a href="https://github.com/drwpwrs"
129
+ ><img
130
+ height="64px"
131
+ src="https://avatars.githubusercontent.com/drwpwrs"
132
+ /></a>
133
+ </td>
134
+ <td>
135
+ <a href="https://github.com/Timeraa"
136
+ ><img
137
+ height="64px"
138
+ src="https://avatars.githubusercontent.com/Timeraa"
139
+ /></a>
140
+ </td>
141
+ <td>
142
+ <a href="https://github.com/Phalangers"
143
+ ><img
144
+ height="64px"
145
+ src="https://avatars.githubusercontent.com/Phalangers"
146
+ /></a>
147
+ </td>
148
+ <td>
149
+ <a href="https://github.com/WilliamConnatser"
150
+ ><img
151
+ height="64px"
152
+ src="https://avatars.githubusercontent.com/WilliamConnatser"
153
+ /></a>
154
+ </td>
155
+ <td>
156
+ <a href="https://github.com/JameEnder"
157
+ ><img
158
+ height="64px"
159
+ src="https://avatars.githubusercontent.com/JameEnder"
160
+ /></a>
161
+ </td>
162
+ </tr>
163
+ <tr>
164
+ <th>tylim88</th>
165
+ <th>jahands</th>
166
+ <th></th>
167
+ <th></th>
168
+ <th></th>
169
+ </tr>
170
+ <tr>
171
+ <td>
172
+ <a href="https://github.com/tylim88"
173
+ ><img
174
+ height="64px"
175
+ src="https://avatars.githubusercontent.com/tylim88"
176
+ /></a>
177
+ </td>
178
+ <td>
179
+ <a href="https://github.com/jahands"
180
+ ><img
181
+ height="64px"
182
+ src="https://avatars.githubusercontent.com/jahands"
183
+ /></a>
184
+ </td>
139
185
  <td>
140
- <a href="https://github.com/WilliamConnatser"
141
- ><img
142
- height="64px"
143
- src="https://avatars.githubusercontent.com/u/43946230"
144
- /></a>
145
- </td>
186
+ </td>
146
187
  <td>
147
- <a href="https://github.com/JameEnder"
148
- ><img
149
- height="64px"
150
- src="https://avatars.githubusercontent.com/u/47925045"
151
- /></a>
152
188
  </td>
153
189
  <td>
154
- <a href="https://github.com/tylim88"
155
- ><img
156
- height="64px"
157
- src="https://avatars.githubusercontent.com/u/5227509"
158
- /></a>
159
190
  </td>
160
191
  </tr>
161
192
  </table>
@@ -19,9 +19,7 @@ export declare namespace distill {
19
19
  }
20
20
  }
21
21
  type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
22
- type _distill<t, endpoint extends distill.Endpoint, seen> = t extends undefined ? t : [t] extends [anyOrNever | seen] ? t : unknown extends t ? unknown : t extends Brand<infer base> ? endpoint extends "in" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends InferredMorph<infer i, infer o> ? [
23
- ReturnType<t>
24
- ] extends [anyOrNever] ? t : distillIo<i, o, endpoint, seen> : t : t extends Default<infer constraint> ? _distill<constraint, endpoint, seen> : t extends array ? distillArray<t, endpoint, seen | t> : isSafelyMappable<t> extends true ? distillMappable<t, endpoint, seen | t> : t;
22
+ type _distill<t, endpoint extends distill.Endpoint, seen> = t extends undefined ? t : [t] extends [anyOrNever | seen] ? t : unknown extends t ? unknown : t extends Brand<infer base> ? endpoint extends "in" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends (...args: never) => anyOrNever ? t : t extends InferredMorph<infer i, infer o> ? distillIo<i, o, endpoint, seen> : t : t extends Default<infer constraint> ? _distill<constraint, endpoint, seen> : t extends array ? distillArray<t, endpoint, seen | t> : isSafelyMappable<t> extends true ? distillMappable<t, endpoint, seen | t> : t;
25
23
  type distillMappable<o, endpoint extends distill.Endpoint, seen> = endpoint extends "in" ? show<{
26
24
  [k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], endpoint, seen>;
27
25
  } & {
@@ -73,11 +71,11 @@ export type withDefault<t, v, undistributed = t> = t extends InferredMorph ? add
73
71
  type addDefaultToMorph<t extends InferredMorph, v> = [
74
72
  normalizeMorphDistribution<t>
75
73
  ] extends [InferredMorph<infer i, infer o>] ? (In: Default<i, v>) => o : never;
76
- type normalizeMorphDistribution<t, undistributedIn = t extends InferredMorph<infer i> ? i : never, undistributedOut extends Out = [t] extends [InferredMorph<any, infer o>] ? [
74
+ type normalizeMorphDistribution<t, undistributedIn = t extends InferredMorph<infer i> ? i : never, undistributedOut extends Out = t extends InferredMorph<any, infer o> ? [
77
75
  o
78
76
  ] extends [To<infer unwrappedOut>] ? To<unwrappedOut> : o : never> = (Extract<t, InferredMorph> extends anyOrNever ? never : Extract<t, InferredMorph> extends InferredMorph<infer i, infer o> ? [
79
77
  undistributedOut
80
- ] extends [o] ? (In: undistributedIn) => undistributedOut : [undistributedIn] extends [i] ? (In: undistributedIn) => undistributedOut : t : never) | Exclude<t, InferredMorph>;
78
+ ] extends [o] ? (In: undistributedIn) => undistributedOut : [undistributedIn] extends [i] ? (In: undistributedIn) => undistributedOut : t : never) | Exclude<t, InferredMorph> extends infer _ ? _ : never;
81
79
  export type defaultFor<t = unknown> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
82
80
  export type termOrType<t> = t | Type<t, any>;
83
81
  export type inferIntersection<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, false>>;
package/out/config.d.ts CHANGED
@@ -1,10 +1,21 @@
1
- import type { ArkSchemaRegistry } from "@ark/schema";
1
+ import type { arkKind } from "@ark/schema";
2
2
  import type { Ark } from "./keywords/keywords.ts";
3
- import type { exportScope } from "./module.ts";
4
- export { configure, type ArkConfig, type ArkSchemaRegistry } from "@ark/schema";
5
- export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
6
- ambient: exportScope<Ark>;
3
+ import { type ArkSchemaConfig } from "@ark/schema/config";
4
+ import type { anyOrNever } from "@ark/util";
5
+ export type TypeMeta = Omit<ArkEnv.meta, "onFail">;
6
+ export type TypeMetaInput = string | TypeMeta;
7
+ export type KeywordConfig = {
8
+ [k in keyof Ark.flat as parseConfigurableFlatAlias<k, Ark.flat[k]>]?: TypeMetaInput;
9
+ };
10
+ type parseConfigurableFlatAlias<k extends string, v> = [
11
+ v
12
+ ] extends [anyOrNever] ? k : v extends {
13
+ [arkKind]: "generic" | "module";
14
+ } ? never : k extends `${infer prefix}.root` ? prefix : k;
15
+ export interface ArkConfig extends ArkSchemaConfig {
16
+ keywords?: KeywordConfig;
7
17
  }
18
+ export declare const configure: <config extends ArkConfig>(config: config) => config;
8
19
  declare global {
9
20
  export interface ArkEnv {
10
21
  $(): Ark;
@@ -23,3 +34,4 @@ export declare namespace ArkAmbient {
23
34
  type meta = ArkEnv.meta;
24
35
  type prototypes = ArkEnv.prototypes;
25
36
  }
37
+ export {};
package/out/config.js CHANGED
@@ -1 +1,3 @@
1
- export { configure } from "@ark/schema";
1
+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports
2
+ import { configureSchema } from "@ark/schema/config";
3
+ export const configure = configureSchema;
package/out/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
1
+ export { ArkError, ArkErrors, type ArkSchemaConfig, type ArkSchemaScopeConfig, type JsonSchema } from "@ark/schema";
2
2
  export { Hkt, inferred } from "@ark/util";
3
3
  export type { distill } from "./attributes.ts";
4
4
  export * from "./config.ts";
5
5
  export { Generic } from "./generic.ts";
6
- export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
6
+ export { ark, declare, define, generic, keywords, match, type, type Ark } from "./keywords/keywords.ts";
7
7
  export { Module, type BoundModule, type Submodule } from "./module.ts";
8
8
  export { scope, type Scope } from "./scope.ts";
9
9
  export { Type } from "./type.ts";
package/out/index.js CHANGED
@@ -2,7 +2,7 @@ export { ArkError, ArkErrors } from "@ark/schema";
2
2
  export { Hkt, inferred } from "@ark/util";
3
3
  export * from "./config.js";
4
4
  export { Generic } from "./generic.js";
5
- export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
5
+ export { ark, declare, define, generic, keywords, match, type } from "./keywords/keywords.js";
6
6
  export { Module } from "./module.js";
7
7
  export { scope } from "./scope.js";
8
8
  export { Type } from "./type.js";
@@ -16,4 +16,6 @@ export const arkArray = Scope.module({
16
16
  readonly: "root",
17
17
  index: intrinsic.nonNegativeIntegerString,
18
18
  liftFrom
19
+ }, {
20
+ name: "Array"
19
21
  });
@@ -35,4 +35,6 @@ export const arkFormData = Scope.module({
35
35
  },
36
36
  declaredOut: parsed
37
37
  })
38
+ }, {
39
+ name: "FormData"
38
40
  });
@@ -11,4 +11,6 @@ export const TypedArray = Scope.module({
11
11
  Float64: ["instanceof", Float64Array],
12
12
  BigInt64: ["instanceof", BigInt64Array],
13
13
  BigUint64: ["instanceof", BigUint64Array]
14
+ }, {
15
+ name: "TypedArray"
14
16
  });
@@ -1,8 +1,10 @@
1
- import type { ArkErrors, arkKind } from "@ark/schema";
1
+ import type { ArkErrors, arkKind, flatResolutionsOf } from "@ark/schema";
2
2
  import type { Brand, inferred } from "@ark/util";
3
3
  import type { distill, InferredMorph, Out, To } from "../attributes.ts";
4
4
  import type { GenericParser } from "../generic.ts";
5
+ import type { MatchParser } from "../match.ts";
5
6
  import type { BaseType } from "../methods/base.ts";
7
+ import type { instantiateType } from "../methods/instantiate.ts";
6
8
  import type { BoundModule, Module } from "../module.ts";
7
9
  import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
8
10
  import { type bindThis, type Scope } from "../scope.ts";
@@ -23,6 +25,7 @@ export declare namespace Ark {
23
25
  object: object.submodule;
24
26
  unknown: unknown.submodule;
25
27
  }
28
+ type flat = flatResolutionsOf<Ark>;
26
29
  interface typeAttachments extends arkTsKeywords.$ {
27
30
  arrayIndex: arkPrototypes.$["Array"]["index"];
28
31
  Key: arkBuiltins.$["Key"];
@@ -41,9 +44,6 @@ export declare namespace type {
41
44
  [inferred]?: to;
42
45
  }
43
46
  type errors = ArkErrors;
44
- /** @ts-ignore cast variance */
45
- interface Any<out t = any> extends BaseType<t, any> {
46
- }
47
47
  type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
48
48
  namespace infer {
49
49
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
@@ -53,9 +53,14 @@ export declare namespace type {
53
53
  }
54
54
  }
55
55
  type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
56
+ type instantiate<def, $ = {}, args = bindThis<def>> = instantiateType<inferDefinition<def, $, args>, $>;
56
57
  type brand<t, id> = t extends InferredMorph<infer i, infer o> ? o["introspectable"] extends true ? (In: i) => To<Brand<o["t"], id>> : (In: i) => Out<Brand<o["t"], id>> : Brand<t, id>;
58
+ /** @ts-ignore cast variance */
59
+ interface Any<out t = any> extends BaseType<t, any> {
60
+ }
57
61
  }
58
62
  export type type<t = unknown, $ = {}> = Type<t, $>;
63
+ export declare const match: MatchParser<{}>;
59
64
  export declare const generic: GenericParser<{}>;
60
65
  export declare const schema: SchemaParser<{}>;
61
66
  export declare const define: DefinitionParser<{}>;
@@ -4,14 +4,6 @@ import { arkPrototypes } from "./constructors.js";
4
4
  import { number } from "./number.js";
5
5
  import { string } from "./string.js";
6
6
  import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.js";
7
- $arkTypeRegistry.typeAttachments = {
8
- ...arkTsKeywords,
9
- arrayIndex: arkPrototypes.Array.index,
10
- Key: arkBuiltins.Key,
11
- Record: arkTsGenerics.Record,
12
- Array: arkPrototypes.Array.root,
13
- Date: arkPrototypes.Date
14
- };
15
7
  export const ark = scope({
16
8
  ...arkTsKeywords,
17
9
  ...arkTsGenerics,
@@ -21,9 +13,34 @@ export const ark = scope({
21
13
  number,
22
14
  object,
23
15
  unknown
24
- }, { prereducedAliases: true, ambient: true });
16
+ }, { prereducedAliases: true, name: "ark" });
25
17
  export const keywords = ark.export();
26
- export const type = ark.type;
18
+ Object.assign($arkTypeRegistry.ambient, keywords);
19
+ $arkTypeRegistry.typeAttachments = {
20
+ string: keywords.string.root,
21
+ number: keywords.number.root,
22
+ bigint: keywords.bigint,
23
+ boolean: keywords.boolean,
24
+ symbol: keywords.symbol,
25
+ undefined: keywords.undefined,
26
+ null: keywords.null,
27
+ object: keywords.object.root,
28
+ unknown: keywords.unknown.root,
29
+ false: keywords.false,
30
+ true: keywords.true,
31
+ never: keywords.never,
32
+ arrayIndex: keywords.Array.index,
33
+ Key: keywords.Key,
34
+ Record: keywords.Record,
35
+ Array: keywords.Array.root,
36
+ Date: keywords.Date
37
+ };
38
+ export const type = Object.assign(ark.type,
39
+ // assign attachments newly parsed in keywords
40
+ // future scopes add these directly from the
41
+ // registry when their TypeParsers are instantiated
42
+ $arkTypeRegistry.typeAttachments);
43
+ export const match = ark.match;
27
44
  export const generic = ark.generic;
28
45
  export const schema = ark.schema;
29
46
  export const define = ark.define;
@@ -44,4 +44,6 @@ export const number = Scope.module({
44
44
  NaN: ["===", Number.NaN],
45
45
  Infinity: ["===", Number.POSITIVE_INFINITY],
46
46
  NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
47
+ }, {
48
+ name: "number"
47
49
  });
@@ -244,10 +244,27 @@ export declare namespace uuid {
244
244
  v7: string;
245
245
  v8: string;
246
246
  };
247
+ namespace $ {
248
+ type flat = {};
249
+ }
247
250
  }
248
251
  export declare const string: Module<{
249
252
  root: unknown;
250
- trim: Submodule<trim.submodule>;
253
+ alpha: unknown;
254
+ alphanumeric: unknown;
255
+ base64: Submodule<{
256
+ root: unknown;
257
+ url: unknown;
258
+ }>;
259
+ capitalize: Submodule<capitalize.submodule>;
260
+ creditCard: unknown;
261
+ date: Submodule<stringDate.submodule>;
262
+ digits: unknown;
263
+ email: unknown;
264
+ integer: Submodule<stringInteger.submodule>;
265
+ ip: Submodule<ip.submodule>;
266
+ json: Submodule<stringJson.submodule>;
267
+ lower: Submodule<lower.submodule>;
251
268
  normalize: Submodule<{
252
269
  root: unknown;
253
270
  NFC: Submodule<{
@@ -267,23 +284,9 @@ export declare const string: Module<{
267
284
  preformatted: unknown;
268
285
  }>;
269
286
  }>;
270
- integer: Submodule<stringInteger.submodule>;
271
- json: Submodule<stringJson.submodule>;
272
- alpha: unknown;
273
- alphanumeric: unknown;
274
- base64: Submodule<{
275
- root: unknown;
276
- url: unknown;
277
- }>;
278
- capitalize: Submodule<capitalize.submodule>;
279
- creditCard: unknown;
280
- date: Submodule<stringDate.submodule>;
281
- digits: unknown;
282
- email: unknown;
283
- ip: Submodule<ip.submodule>;
284
- lower: Submodule<lower.submodule>;
285
287
  numeric: Submodule<stringNumeric.submodule>;
286
288
  semver: unknown;
289
+ trim: Submodule<trim.submodule>;
287
290
  upper: Submodule<upper.submodule>;
288
291
  url: Submodule<url.submodule>;
289
292
  uuid: Submodule<{