arktype 2.1.16 → 2.1.18

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2024 ArkType
1
+ Copyright 2025 ArkType
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
@@ -9,7 +9,7 @@ export type RegexLiteral<source extends string = string> = `/${source}/`;
9
9
  export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
10
10
  export type LimitLiteral = number | DateLiteral;
11
11
  export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
12
- export type distill<t, endpoint extends distill.Endpoint> = finalizeDistillation<t, _distill<t, endpoint, never>>;
12
+ export type distill<t, endpoint extends distill.Endpoint> = finalizeDistillation<t, _distill<t, endpoint>>;
13
13
  export declare namespace distill {
14
14
  type Endpoint = "in" | "out" | "out.introspectable";
15
15
  type In<t> = distill<t, "in">;
@@ -19,33 +19,33 @@ 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 (...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;
23
- type distillMappable<o, endpoint extends distill.Endpoint, seen> = endpoint extends "in" ? show<{
24
- [k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], endpoint, seen>;
22
+ type _distill<t, endpoint extends distill.Endpoint> = t extends undefined ? t : [t] extends [anyOrNever] ? 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> : t : t extends Default<infer constraint> ? _distill<constraint, endpoint> : t extends array ? distillArray<t, endpoint> : isSafelyMappable<t> extends true ? distillMappable<t, endpoint> : t;
23
+ type distillMappable<o, endpoint extends distill.Endpoint> = endpoint extends "in" ? show<{
24
+ [k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], endpoint>;
25
25
  } & {
26
- [k in inferredDefaultKeyOf<o>]?: _distill<o[k], endpoint, seen>;
26
+ [k in inferredDefaultKeyOf<o>]?: _distill<o[k], endpoint>;
27
27
  }> : {
28
- [k in keyof o]: _distill<o[k], endpoint, seen>;
28
+ [k in keyof o]: _distill<o[k], endpoint>;
29
29
  };
30
- type distillIo<i, o extends Out, endpoint extends distill.Endpoint, seen> = endpoint extends "out" ? _distill<o["t"], endpoint, seen> : endpoint extends "in" ? _distill<i, endpoint, seen> : o extends To<infer validatedOut> ? _distill<validatedOut, endpoint, seen> : unknown;
30
+ type distillIo<i, o extends Out, endpoint extends distill.Endpoint> = endpoint extends "out" ? _distill<o["t"], endpoint> : endpoint extends "in" ? _distill<i, endpoint> : o extends To<infer validatedOut> ? _distill<validatedOut, endpoint> : unknown;
31
31
  type unwrapInput<t> = t extends InferredMorph<infer i> ? t extends anyOrNever ? t : i : t;
32
32
  type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? unwrapInput<o[k]> extends Default<infer t> ? [
33
33
  t
34
34
  ] extends [anyOrNever] ? never : k : never : never : never;
35
- type distillArray<t extends array, endpoint extends distill.Endpoint, seen> = t[number][] extends t ? alignReadonly<_distill<t[number], endpoint, seen>[], t> : distillNonArraykeys<t, alignReadonly<distillArrayFromPrefix<[...t], endpoint, seen, []>, t>, endpoint, seen>;
35
+ type distillArray<t extends array, endpoint extends distill.Endpoint> = t[number][] extends t ? alignReadonly<_distill<t[number], endpoint>[], t> : distillNonArraykeys<t, alignReadonly<distillArrayFromPrefix<[...t], endpoint, []>, t>, endpoint>;
36
36
  type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
37
- type distillNonArraykeys<originalArray extends array, distilledArray, endpoint extends distill.Endpoint, seen> = keyof originalArray extends keyof distilledArray ? distilledArray : distilledArray & _distill<{
37
+ type distillNonArraykeys<originalArray extends array, distilledArray, endpoint extends distill.Endpoint> = keyof originalArray extends keyof distilledArray ? distilledArray : distilledArray & _distill<{
38
38
  [k in keyof originalArray as k extends keyof distilledArray ? never : k]: originalArray[k];
39
- }, endpoint, seen>;
40
- type distillArrayFromPrefix<t extends array, endpoint extends distill.Endpoint, seen, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArrayFromPrefix<tail, endpoint, seen, [
39
+ }, endpoint>;
40
+ type distillArrayFromPrefix<t extends array, endpoint extends distill.Endpoint, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArrayFromPrefix<tail, endpoint, [
41
41
  ...prefix,
42
- _distill<head, endpoint, seen>
43
- ]> : [...prefix, ...distillArrayFromPostfix<t, endpoint, seen, []>];
44
- type distillArrayFromPostfix<t extends array, endpoint extends distill.Endpoint, seen, postfix extends array> = t extends readonly [...infer init, infer last] ? distillArrayFromPostfix<init, endpoint, seen, [
45
- _distill<last, endpoint, seen>,
42
+ _distill<head, endpoint>
43
+ ]> : [...prefix, ...distillArrayFromPostfix<t, endpoint, []>];
44
+ type distillArrayFromPostfix<t extends array, endpoint extends distill.Endpoint, postfix extends array> = t extends readonly [...infer init, infer last] ? distillArrayFromPostfix<init, endpoint, [
45
+ _distill<last, endpoint>,
46
46
  ...postfix
47
47
  ]> : [...{
48
- [i in keyof t]: _distill<t[i], endpoint, seen>;
48
+ [i in keyof t]: _distill<t[i], endpoint>;
49
49
  }, ...postfix];
50
50
  type BuiltinTerminalObjectKind = Exclude<arkPrototypes.NonDegenerateName, "Array" | "Function">;
51
51
  /** Objects we don't want to expand during inference like Date or Promise */
package/out/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- export { ArkError, ArkErrors, type ArkSchemaConfig, type ArkSchemaScopeConfig, type JsonSchema } from "@ark/schema";
2
- export { Hkt, inferred } from "@ark/util";
3
- export type { distill } from "./attributes.ts";
1
+ export { ArkError, ArkErrors, Traversal, TraversalError, type ArkSchemaConfig, type ArkSchemaScopeConfig, type JsonSchema } from "@ark/schema";
2
+ export { Hkt, inferred, ParseError } from "@ark/util";
3
+ export type { distill, Out } from "./attributes.ts";
4
4
  export * from "./config.ts";
5
5
  export { Generic } from "./generic.ts";
6
6
  export { ark, declare, define, generic, keywords, match, type, type Ark } from "./keywords/keywords.ts";
7
+ export type { BaseType } from "./methods/base.ts";
7
8
  export { Module, type BoundModule, type Submodule } from "./module.ts";
8
- export { scope, type Scope } from "./scope.ts";
9
+ export type { inferDefinition, validateDefinition } from "./parser/definition.ts";
10
+ export { scope, type bindThis, type Scope } from "./scope.ts";
9
11
  export { Type } from "./type.ts";
package/out/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { ArkError, ArkErrors } from "@ark/schema";
2
- export { Hkt, inferred } from "@ark/util";
1
+ export { ArkError, ArkErrors, Traversal, TraversalError } from "@ark/schema";
2
+ export { Hkt, inferred, ParseError } from "@ark/util";
3
3
  export * from "./config.js";
4
4
  export { Generic } from "./generic.js";
5
5
  export { ark, declare, define, generic, keywords, match, type } from "./keywords/keywords.js";
@@ -3,6 +3,7 @@ import { Hkt, type Key } from "@ark/util";
3
3
  import type { Module, Submodule } from "../module.ts";
4
4
  declare class MergeHkt extends Hkt<[base: object, props: object]> {
5
5
  body: util.merge<this[0], this[1]>;
6
+ description: string;
6
7
  }
7
8
  declare const Merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], MergeHkt>;
8
9
  export declare const arkBuiltins: arkBuiltins;
@@ -2,6 +2,7 @@ import { genericNode, intrinsic } from "@ark/schema";
2
2
  import { Hkt } from "@ark/util";
3
3
  import { Scope } from "../scope.js";
4
4
  class MergeHkt extends Hkt {
5
+ description = 'merge an object\'s properties onto another like `Merge(User, { isAdmin: "true" })`';
5
6
  }
6
7
  const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
7
8
  export const arkBuiltins = Scope.module({
@@ -44,6 +44,8 @@ export declare namespace type {
44
44
  [inferred]?: to;
45
45
  }
46
46
  type errors = ArkErrors;
47
+ type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
48
+ type instantiate<def, $ = {}, args = bindThis<def>> = instantiateType<inferDefinition<def, $, args>, $>;
47
49
  type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
48
50
  namespace infer {
49
51
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
@@ -52,11 +54,9 @@ export declare namespace type {
52
54
  type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
53
55
  }
54
56
  }
55
- type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
56
- type instantiate<def, $ = {}, args = bindThis<def>> = instantiateType<inferDefinition<def, $, args>, $>;
57
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
58
  /** @ts-ignore cast variance */
59
- interface Any<out t = any> extends BaseType<t, any> {
59
+ interface Any<out t = any, $ = any> extends BaseType<t, $> {
60
60
  }
61
61
  }
62
62
  export type type<t = unknown, $ = {}> = Type<t, $>;
@@ -63,26 +63,32 @@ declare class RecordHkt extends Hkt<[Key, unknown]> {
63
63
  declare const Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], RecordHkt>;
64
64
  declare class PickHkt extends Hkt<[object, Key]> {
65
65
  body: pick<this[0], this[1] & keyof this[0]>;
66
+ description: string;
66
67
  }
67
68
  declare const Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], PickHkt>;
68
69
  declare class OmitHkt extends Hkt<[object, Key]> {
69
70
  body: omit<this[0], this[1] & keyof this[0]>;
71
+ description: string;
70
72
  }
71
73
  declare const Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], OmitHkt>;
72
74
  declare class PartialHkt extends Hkt<[object]> {
73
75
  body: show<Partial<this[0]>>;
76
+ description: string;
74
77
  }
75
78
  declare const Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], PartialHkt>;
76
79
  declare class RequiredHkt extends Hkt<[object]> {
77
80
  body: show<Required<this[0]>>;
81
+ description: string;
78
82
  }
79
83
  declare const Required: import("@ark/schema").GenericRoot<readonly [["T", object]], RequiredHkt>;
80
84
  declare class ExcludeHkt extends Hkt<[unknown, unknown]> {
81
85
  body: Exclude<this[0], this[1]>;
86
+ description: string;
82
87
  }
83
88
  declare const Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExcludeHkt>;
84
89
  declare class ExtractHkt extends Hkt<[unknown, unknown]> {
85
90
  body: Extract<this[0], this[1]>;
91
+ description: string;
86
92
  }
87
93
  declare const Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
88
94
  export declare const arkTsGenerics: arkTsGenerics.module;
@@ -38,7 +38,7 @@ export const object = Scope.module({
38
38
  name: "object"
39
39
  });
40
40
  class RecordHkt extends Hkt {
41
- description = "a generic type that instantiates an object from a single index signature and corresponding value type";
41
+ description = 'instantiate an object from an index signature and corresponding value type like `Record("string", "number")`';
42
42
  }
43
43
  const Record = genericNode(["K", intrinsic.key], "V")(args => ({
44
44
  domain: "object",
@@ -48,21 +48,27 @@ const Record = genericNode(["K", intrinsic.key], "V")(args => ({
48
48
  }
49
49
  }), RecordHkt);
50
50
  class PickHkt extends Hkt {
51
+ description = 'pick a set of properties from an object like `Pick(User, "name | age")`';
51
52
  }
52
53
  const Pick = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.pick(args.K), PickHkt);
53
54
  class OmitHkt extends Hkt {
55
+ description = 'omit a set of properties from an object like `Omit(User, "age")`';
54
56
  }
55
57
  const Omit = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.omit(args.K), OmitHkt);
56
58
  class PartialHkt extends Hkt {
59
+ description = "make all named properties of an object optional like `Partial(User)`";
57
60
  }
58
61
  const Partial = genericNode(["T", intrinsic.object])(args => args.T.partial(), PartialHkt);
59
62
  class RequiredHkt extends Hkt {
63
+ description = "make all named properties of an object required like `Required(User)`";
60
64
  }
61
65
  const Required = genericNode(["T", intrinsic.object])(args => args.T.required(), RequiredHkt);
62
66
  class ExcludeHkt extends Hkt {
67
+ description = 'exclude branches of a union like `Exclude("boolean", "true")`';
63
68
  }
64
69
  const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt);
65
70
  class ExtractHkt extends Hkt {
71
+ description = 'extract branches of a union like `Extract("0 | false | 1", "number")`';
66
72
  }
67
73
  const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
68
74
  export const arkTsGenerics = Scope.module({
package/out/match.d.ts CHANGED
@@ -73,16 +73,26 @@ type maybeLiftToKey<t, ctx extends MatchParserContext> = ctx["key"] extends Prop
73
73
  type _finalizeCaseArg<t, ctx extends MatchParserContext, endpoint extends "in" | "out"> = [
74
74
  distill<t, "in">,
75
75
  distill<t, endpoint>
76
- ] extends [infer i, infer result] ? i extends ctx["input"] ? result : Extract<ctx["input"], i> extends never ? result : Extract<ctx["input"], result> : never;
76
+ ] extends [infer i, infer result] ? [
77
+ i
78
+ ] extends [ctx["input"]] ? result : Extract<ctx["input"], i> extends never ? result : Extract<ctx["input"], result> : never;
77
79
  type CaseParser<ctx extends MatchParserContext> = <const def, ret>(def: type.validate<def, ctx["$"]>, resolve: (In: inferCaseArg<def, ctx, "out">) => ret) => ChainableMatchParser<addCasesToContext<ctx, [(In: inferCaseArg<def, ctx, "in">) => ret]>>;
78
80
  type validateKey<key extends Key, ctx extends MatchParserContext> = ctx["key"] extends Key ? ErrorMessage<doubleAtMessage> : ctx["cases"]["length"] extends 0 ? keyof ctx["input"] extends never ? key : conform<key, keyof ctx["input"]> : ErrorMessage<chainedAtMessage>;
79
81
  interface StringsParser<ctx extends MatchParserContext> {
80
82
  <const cases>(def: cases extends validateStringCases<cases, ctx> ? cases : validateStringCases<cases, ctx>): addCasesToParser<cases, ctx, "string">;
81
83
  }
82
- type validateStringCases<cases, ctx extends MatchParserContext> = {
83
- [k in keyof cases | stringValue<ctx> | "default"]?: k extends "default" ? DefaultCase<ctx> : k extends stringValue<ctx> ? (In: _finalizeCaseArg<maybeLiftToKey<k, ctx>, ctx, "out">) => unknown : ErrorType<`${k & string} must be a possible string value`>;
84
+ type validateStringCases<cases, ctx extends MatchParserContext> = unknown extends ctx["input"] ? {
85
+ [k in keyof cases]?: k extends "default" ? DefaultCase<ctx> : (In: _finalizeCaseArg<maybeLiftToKey<k, ctx>, ctx, "out">) => unknown;
86
+ } & {
87
+ default?: DefaultCase<ctx>;
88
+ } : {
89
+ [k in keyof cases]?: k extends "default" ? DefaultCase<ctx> : k extends stringValue<ctx> ? (In: _finalizeCaseArg<maybeLiftToKey<k, ctx>, ctx, "out">) => unknown : ErrorType<`${k & string} must be a possible string value`>;
90
+ } & {
91
+ [k in stringValue<ctx>]?: unknown;
92
+ } & {
93
+ default?: DefaultCase<ctx>;
84
94
  };
85
- type stringValue<ctx extends MatchParserContext> = ctx["key"] extends keyof ctx["input"] ? ctx["input"][ctx["key"]] extends string ? ctx["input"][ctx["key"]] : never : ctx["input"] extends string ? ctx["input"] : never;
95
+ type stringValue<ctx extends MatchParserContext> = ctx["input"] extends string ? ctx["input"] : ctx["key"] extends keyof ctx["input"] ? ctx["input"][ctx["key"]] extends infer s extends string ? s : never : never;
86
96
  interface AtParser<ctx extends MatchParserContext> {
87
97
  <const key extends string>(key: validateKey<key, ctx>): ChainableMatchParser<ctx.atKey<ctx, key>>;
88
98
  <const key extends string, const cases, ctxAtKey extends MatchParserContext = ctx.atKey<ctx, key>>(key: validateKey<key, ctx>, cases: cases extends validateCases<cases, ctxAtKey> ? cases : errorCases<cases, ctxAtKey>): addCasesToParser<cases, ctxAtKey, "def">;
@@ -62,19 +62,19 @@ export interface Inferred<out t = unknown, $ = {}> {
62
62
  * 🥸 inference-only property that will be `undefined` at runtime
63
63
  *
64
64
  * @example
65
- * const unmorphed = type("string")
65
+ * const Unmorphed = type("string")
66
66
  * // with no morphs, we can introspect the input and output as a single Type
67
- * type UnmorphedOut = typeof unmorphed.inferIntrospectableOut // string
67
+ * type UnmorphedOut = typeof Unmorphed.inferIntrospectableOut // string
68
68
  *
69
- * const morphed = type("string").pipe(s => s.length)
69
+ * const Morphed = type("string").pipe(s => s.length)
70
70
  * // with a standard user-defined morph, TypeScript can infer a
71
71
  * // return type from your function, but we have no way to
72
72
  * // know the shape at runtime
73
- * type MorphOut = typeof morphed.inferIntrospectableOut // unknown
73
+ * type MorphOut = typeof Morphed.inferIntrospectableOut // unknown
74
74
  *
75
- * const validated = type("string").pipe(s => s.length).to("number")
75
+ * const Validated = type("string").pipe(s => s.length).to("number")
76
76
  * // morphs with validated output, including all morph keywords, are introspectable
77
- * type ValidatedMorphOut = typeof validated.inferIntrospectableOut
77
+ * type ValidatedMorphOut = typeof Validated.inferIntrospectableOut
78
78
  */
79
79
  inferIntrospectableOut: distill.introspectable.Out<t>;
80
80
  /**
@@ -113,8 +113,8 @@ export interface Inferred<out t = unknown, $ = {}> {
113
113
  * ✅ works best for primitive values
114
114
  *
115
115
  * @example
116
- * const n = type("0 < number <= 100")
117
- * console.log(n.description) // positive and at most 100
116
+ * const N = type("0 < number <= 100")
117
+ * console.log(N.description) // positive and at most 100
118
118
  */
119
119
  description: string;
120
120
  /**
@@ -123,8 +123,8 @@ export interface Inferred<out t = unknown, $ = {}> {
123
123
  * ✅ works well for both primitives and structures
124
124
  *
125
125
  * @example
126
- * const loc = type({ coords: ["number", "number"] })
127
- * console.log(loc.expression) // { coords: [number, number] }
126
+ * const Loc = type({ coords: ["number", "number"] })
127
+ * console.log(Loc.expression) // { coords: [number, number] }
128
128
  */
129
129
  expression: string;
130
130
  /**
@@ -133,11 +133,11 @@ export interface Inferred<out t = unknown, $ = {}> {
133
133
  * ✅ sugar to avoid checking for {@link type.errors} if they are unrecoverable
134
134
  *
135
135
  * @example
136
- * const criticalPayload = type({
136
+ * const CriticalPayload = type({
137
137
  * superImportantValue: "string"
138
138
  * })
139
139
  * // throws TraversalError: superImportantValue must be a string (was missing)
140
- * const data = criticalPayload.assert({ irrelevantValue: "whoops" })
140
+ * const data = CriticalPayload.assert({ irrelevantValue: "whoops" })
141
141
  * console.log(data.superImportantValue) // valid output can be accessed directly
142
142
  *
143
143
  * @throws {TraversalError}
@@ -149,9 +149,9 @@ export interface Inferred<out t = unknown, $ = {}> {
149
149
  * ✅ good for stuff like filtering that doesn't benefit from detailed errors
150
150
  *
151
151
  * @example
152
- * const numeric = type("number | bigint")
152
+ * const Numeric = type("number | bigint")
153
153
  * // [0, 2n]
154
- * const numerics = [0, "one", 2n].filter(numeric.allows)
154
+ * const numerics = [0, "one", 2n].filter(Numeric.allows)
155
155
  */
156
156
  allows(data: unknown): data is this["inferIn"];
157
157
  /**
@@ -160,20 +160,20 @@ export interface Inferred<out t = unknown, $ = {}> {
160
160
  * ⚠️ does not affect error messages within properties of an object
161
161
  *
162
162
  * @example
163
- * const notOdd = type("number % 2").configure({ description: "not odd" })
163
+ * const NotOdd = type("number % 2").configure({ description: "not odd" })
164
164
  * // all constraints at the root are affected
165
- * const odd = notOdd(3) // must be not odd (was 3)
166
- * const nonNumber = notOdd("two") // must be not odd (was "two")
165
+ * const odd = NotOdd(3) // must be not odd (was 3)
166
+ * const nonNumber = NotOdd("two") // must be not odd (was "two")
167
167
  *
168
- * const notOddBox = type({
168
+ * const NotOddBox = type({
169
169
  * // we should have referenced notOdd or added meta here
170
170
  * notOdd: "number % 2",
171
171
  * // but instead chained from the root object
172
172
  * }).configure({ description: "not odd" })
173
173
  * // error message at path notOdd is not affected
174
- * const oddProp = notOddBox({ notOdd: 3 }) // notOdd must be even (was 3)
174
+ * const oddProp = NotOddBox({ notOdd: 3 }) // notOdd must be even (was 3)
175
175
  * // error message at root is affected, leading to a misleading description
176
- * const nonObject = notOddBox(null) // must be not odd (was null)
176
+ * const nonObject = NotOddBox(null) // must be not odd (was null)
177
177
  */
178
178
  configure: NodeSelector.SelectableFn<TypeMeta.MappableInput, this>;
179
179
  /**
@@ -183,10 +183,10 @@ export interface Inferred<out t = unknown, $ = {}> {
183
183
  * ⚠️ does not affect error messages within properties of an object
184
184
  *
185
185
  * @example
186
- * const aToZ = type(/^a.*z$/).describe("a string like 'a...z'")
187
- * const good = aToZ("alcatraz") // "alcatraz"
186
+ * const AToZ = type(/^a.*z$/).describe("a string like 'a...z'")
187
+ * const good = AToZ("alcatraz") // "alcatraz"
188
188
  * // ArkErrors: must be a string like 'a...z' (was "albatross")
189
- * const badPattern = aToZ("albatross")
189
+ * const badPattern = AToZ("albatross")
190
190
  */
191
191
  describe: NodeSelector.SelectableFn<string, this>;
192
192
  /**
@@ -209,9 +209,9 @@ export interface Inferred<out t = unknown, $ = {}> {
209
209
  * #### alias for {@link assert} with typed input
210
210
  *
211
211
  * @example
212
- * const t = type({ foo: "string" });
212
+ * const T = type({ foo: "string" });
213
213
  * // TypeScript: foo must be a string (was 5)
214
- * const data = t.from({ foo: 5 });
214
+ * const data = T.from({ foo: 5 });
215
215
  */
216
216
  from(literal: this["inferIn"]): this["infer"];
217
217
  /**
@@ -221,13 +221,13 @@ export interface Inferred<out t = unknown, $ = {}> {
221
221
  * ✅ good for generating JSON Schema or other non-transforming formats
222
222
  *
223
223
  * @example
224
- * const createUser = type({
224
+ * const User = type({
225
225
  * age: "string.numeric.parse"
226
226
  * })
227
227
  * // { age: 25 } (age parsed to a number)
228
- * const out = createUser({ age: "25" })
228
+ * const out = User({ age: "25" })
229
229
  * // { age: "25" } (age is still a string)
230
- * const inOut = createUser.in({ age: "25" })
230
+ * const inOut = User.in({ age: "25" })
231
231
  */
232
232
  get in(): instantiateType<this["inferIn"], $>;
233
233
  /**
@@ -238,15 +238,15 @@ export interface Inferred<out t = unknown, $ = {}> {
238
238
  * were defined with an explicit output validator via `.to(outputDef)` or `.pipe(morph, outputType)`
239
239
  *
240
240
  * @example
241
- * const userMorph = type("string[]").pipe(a => a.join(","))
241
+ * const join = type("string[]").pipe(a => a.join(","))
242
242
  *
243
- * const t = type({
243
+ * const T = type({
244
244
  * // all keywords have introspectable output
245
245
  * keyword: "string.numeric.parse",
246
- * // TypeScript knows this returns a boolean, but we can't introspect that at runtime
247
- * unvalidated: userMorph,
246
+ * // TypeScript knows this returns a string, but we can't introspect that at runtime
247
+ * unvalidated: join,
248
248
  * // if needed, it can be made introspectable with an output validator
249
- * validated: userMorph.to("string")
249
+ * validated: join.to("string")
250
250
  * })
251
251
  *
252
252
  * // Type<{ keyword: number; unvalidated: unknown; validated: string }>
@@ -259,11 +259,11 @@ export interface Inferred<out t = unknown, $ = {}> {
259
259
  * 🥸 inference-only function that does nothing runtime
260
260
  *
261
261
  * @example
262
- * const palindrome = type("string")
262
+ * const Palindrome = type("string")
263
263
  * .narrow(s => s === [...s].reverse().join(""))
264
264
  * .brand("palindrome")
265
265
  * // Brand<string, "palindrome">
266
- * const out = palindrome.assert("racecar")
266
+ * const out = Palindrome.assert("racecar")
267
267
  */
268
268
  brand<const name extends string, r = instantiateType<type.brand<t, name>, $>>(name: name): r extends infer _ ? _ : never;
269
269
  /**
@@ -271,7 +271,7 @@ export interface Inferred<out t = unknown, $ = {}> {
271
271
  *
272
272
  * @example
273
273
  * // Type<{ rebmun: number }[]>
274
- * const t = type({ rebmun: "number" }).array();
274
+ * const T = type({ rebmun: "number" }).array();
275
275
  */
276
276
  array(): ArrayType<t[], $>;
277
277
  /**
@@ -280,9 +280,9 @@ export interface Inferred<out t = unknown, $ = {}> {
280
280
  * ⚠️ unlike most other methods, this creates a definition rather than a Type (read why)
281
281
  *
282
282
  * @example
283
- * const prop = type({ foo: "number" })
283
+ * const Prop = type({ foo: "number" })
284
284
  * // Type<{ bar?: { foo: number } }>
285
- * const obj = type({ bar: prop.optional() })
285
+ * const Obj = type({ bar: Prop.optional() })
286
286
  */
287
287
  optional(): [this, "?"];
288
288
  /**
@@ -294,10 +294,10 @@ export interface Inferred<out t = unknown, $ = {}> {
294
294
  *
295
295
  * @example
296
296
  * // Type<{ count: Default<number, 0> }>
297
- * const state = type({ count: type.number.default(0) })
298
- * const prop = type({ nested: "boolean" })
299
- * const forObj = type({
300
- * key: nested.default(() => ({ nested: false }))
297
+ * const State = type({ count: type.number.default(0) })
298
+ * const Prop = type({ nested: "boolean" })
299
+ * const ForObj = type({
300
+ * key: Prop.default(() => ({ nested: false }))
301
301
  * })
302
302
  */
303
303
  default<const value extends defaultFor<this["inferIn"]>>(value: value): [this, "=", value];
@@ -312,7 +312,7 @@ export interface Inferred<out t = unknown, $ = {}> {
312
312
  * const stringifyUser = type({ name: "string" }).pipe(user => JSON.stringify(user))
313
313
  * const stringifySafe = stringifyUser.filter(user => user.name !== "Bobby Tables")
314
314
  * // Type<(In: `${string}Z`) => To<Date>>
315
- * const withPredicate = type("string.date.parse").filter((s): s is `${string}Z` =>
315
+ * const WithPredicate = type("string.date.parse").filter((s): s is `${string}Z` =>
316
316
  * s.endsWith("Z")
317
317
  * )
318
318
  */
@@ -327,13 +327,13 @@ export interface Inferred<out t = unknown, $ = {}> {
327
327
  * 🥸 {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates | Type predicates} can be used as casts
328
328
  *
329
329
  * @example
330
- * const palindrome = type("string").narrow(s => s === [...s].reverse().join(""))
330
+ * const Palindrome = type("string").narrow(s => s === [...s].reverse().join(""))
331
331
  *
332
- * const palindromicEmail = type("string.date.parse").narrow((date, ctx) =>
332
+ * const PalindromicEmail = type("string.date.parse").narrow((date, ctx) =>
333
333
  * date.getFullYear() === 2025 || ctx.mustBe("the current year")
334
334
  * )
335
335
  * // Type<`${string}.tsx`>
336
- * const withPredicate = type("string").narrow((s): s is `${string}.tsx` => /\.tsx?$/.test(s))
336
+ * const WithPredicate = type("string").narrow((s): s is `${string}.tsx` => /\.tsx?$/.test(s))
337
337
  */
338
338
  narrow<narrowed extends this["infer"] = never, r = instantiateType<[
339
339
  narrowed
@@ -342,7 +342,7 @@ export interface Inferred<out t = unknown, $ = {}> {
342
342
  * #### pipe output through arbitrary transformations or other Types
343
343
  *
344
344
  * @example
345
- * const user = type({ name: "string" })
345
+ * const User = type({ name: "string" })
346
346
  *
347
347
  * // parse a string and validate that the result as a user
348
348
  * const parseUser = type("string").pipe(s => JSON.parse(s), user)
@@ -378,7 +378,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
378
378
  *
379
379
  * @example
380
380
  * // Type<`LEEEEEEEE${string}ROY`>
381
- * const leeroy = type(/^LE{8,}ROY$/).as<`LEEEEEEEE${string}ROY`>()
381
+ * const Leeroy = type(/^LE{8,}ROY$/).as<`LEEEEEEEE${string}ROY`>()
382
382
  */
383
383
  as<castTo = unset>(...args: validateChainedAsArgs<castTo>): instantiateType<castTo, $>;
384
384
  /**
@@ -386,9 +386,9 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
386
386
  *
387
387
  * @example
388
388
  * // Type<{ foo: number; bar: string }>
389
- * const t = type({ foo: "number" }).and({ bar: "string" })
389
+ * const T = type({ foo: "number" }).and({ bar: "string" })
390
390
  * // ParseError: Intersection at foo of number and string results in an unsatisfiable type
391
- * const bad = type({ foo: "number" }).and({ foo: "string" })
391
+ * const Bad = type({ foo: "number" }).and({ foo: "string" })
392
392
  */
393
393
  and<const def, r = instantiateType<inferIntersection<t, type.infer<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
394
394
  /**
@@ -398,7 +398,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
398
398
  *
399
399
  * @example
400
400
  * // Type<string | { box: string }>
401
- * const t = type("string").or({ box: "string" })
401
+ * const T = type("string").or({ box: "string" })
402
402
  */
403
403
  or<const def, r = instantiateType<t | type.infer<def, $>, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
404
404
  /**
@@ -406,10 +406,10 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
406
406
  *
407
407
  * @example
408
408
  * // Type<{ foo: number; bar: string }>
409
- * const t = type({ foo: "number" }).intersect({ bar: "string" })
410
- * const bad = type("number > 10").intersect("number < 5")
409
+ * const T = type({ foo: "number" }).intersect({ bar: "string" })
410
+ * const Bad = type("number > 10").intersect("number < 5")
411
411
  * // logs "Intersection of > 10 and < 5 results in an unsatisfiable type"
412
- * if (bad instanceof Disjoint) console.log(`${bad.summary}`)
412
+ * if (Bad instanceof Disjoint) console.log(`${bad.summary}`)
413
413
  */
414
414
  intersect<const def, r = instantiateType<inferIntersection<t, type.infer<def, $>>, $>>(def: type.validate<def, $>): r extends infer _ ? _ | Disjoint : never;
415
415
  /**
@@ -419,14 +419,14 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
419
419
  * ✅ ignores associated {@link meta}, which does not affect the set of allowed values
420
420
  *
421
421
  * @example
422
- * const divisibleBy6 = type.number.divisibleBy(6).moreThan(0)
422
+ * const DivisibleBy6 = type.number.divisibleBy(6).moreThan(0)
423
423
  * // false (left side must also be positive)
424
- * divisibleBy6.equals("number % 6")
424
+ * DivisibleBy6.equals("number % 6")
425
425
  * // false (right side has an additional <100 constraint)
426
- * console.log(divisibleBy6.equals("0 < (number % 6) < 100"))
427
- * const thirdTry = type("(number % 2) > 0").divisibleBy(3)
426
+ * console.log(DivisibleBy6.equals("0 < (number % 6) < 100"))
427
+ * const ThirdTry = type("(number % 2) > 0").divisibleBy(3)
428
428
  * // true (types are normalized and reduced)
429
- * console.log(divisibleBy6.equals(thirdTry))
429
+ * console.log(DivisibleBy6.equals(ThirdTry))
430
430
  */
431
431
  equals<const def>(def: type.validate<def, $>): boolean;
432
432
  /**
@@ -435,9 +435,9 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
435
435
  * ✅ ignores associated {@link meta}, which does not affect the set of allowed values
436
436
  *
437
437
  * @example
438
- * const n = type.raw(`${Math.random()}`)
438
+ * const N = type.raw(`${Math.random()}`)
439
439
  * // Type<0.5> | undefined
440
- * const ez = n.ifEquals("0.5")
440
+ * const Ez = N.ifEquals("0.5")
441
441
  */
442
442
  ifEquals<const def, r = type.instantiate<def, $>>(def: type.validate<def, $>): r extends infer _ ? _ | undefined : never;
443
443
  /**
@@ -458,8 +458,8 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
458
458
  * ✅ ignores associated {@link meta}, which does not affect the set of allowed values
459
459
  *
460
460
  * @example
461
- * const n = type(Math.random() > 0.5 ? "true" : "0") // Type<0 | true>
462
- * const ez = n.ifExtends("boolean") // Type<true> | undefined
461
+ * const N = type(Math.random() > 0.5 ? "true" : "0") // Type<0 | true>
462
+ * const Ez = N.ifExtends("boolean") // Type<true> | undefined
463
463
  */
464
464
  ifExtends<const def, r = type.instantiate<def, $>>(other: type.validate<def, $>): r extends infer _ ? _ | undefined : never;
465
465
  /**
@@ -472,8 +472,8 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
472
472
  * type("string | number").overlaps("1") // true (1)
473
473
  * type("number > 0").overlaps("number < 0") // false (no values exist)
474
474
  *
475
- * const noAt = type("string").narrow(s => !s.includes("@"))
476
- * noAt.overlaps("string.email") // true (no values exist, but not provable)
475
+ * const NoAt = type("string").narrow(s => !s.includes("@"))
476
+ * NoAt.overlaps("string.email") // true (no values exist, but not provable)
477
477
  */
478
478
  overlaps<const def>(r: type.validate<def, $>): boolean;
479
479
  /**
@@ -481,7 +481,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
481
481
  *
482
482
  * @example
483
483
  * // Type<true | 0 | 2>
484
- * const t = type("boolean | 0 | 'one' | 2 | bigint").extract("number | 0n | true")
484
+ * const T = type("boolean | 0 | 'one' | 2 | bigint").extract("number | 0n | true")
485
485
  */
486
486
  extract<const def, r = instantiateType<t extends type.infer<def, $> ? t : never, $>>(r: type.validate<def, $>): r extends infer _ extends r ? _ : never;
487
487
  /**
@@ -490,7 +490,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
490
490
  * @example
491
491
  *
492
492
  * // Type<false | 'one' | bigint>
493
- * const t = type("boolean | 0 | 'one' | 2 | bigint").exclude("number | 0n | true")
493
+ * const T = type("boolean | 0 | 'one' | 2 | bigint").exclude("number | 0n | true")
494
494
  */
495
495
  exclude<const def, r = instantiateType<t extends type.infer<def, $> ? never : t, $>>(r: type.validate<def, $>): r extends infer _ ? _ : never;
496
496
  /**
package/out/type.d.ts CHANGED
@@ -16,7 +16,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
16
16
  /**
17
17
  * Create a {@link Type} from your definition.
18
18
  *
19
- * @example const person = type({ name: "string" })
19
+ * @example const Person = type({ name: "string" })
20
20
  */
21
21
  <const def, r = type.instantiate<def, $>>(def: type.validate<def, $>): r extends infer _ ? _ : never;
22
22
  /**
@@ -29,7 +29,7 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
29
29
  * parameter names specified in the previous argument in addition to aliases
30
30
  * from its {@link Scope}.
31
31
  *
32
- * @example const boxOf = type("<t extends string | number>", { contents: "t" })
32
+ * @example const BoxOf = type("<t extends string | number>", { contents: "t" })
33
33
  */
34
34
  <const params extends ParameterString, const def, r = Generic<parseValidGenericParams<params, $>, def, $>>(params: validateParameterString<params, $>, def: type.validate<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): r extends infer _ ? _ : never;
35
35
  /**
@@ -77,8 +77,8 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
77
77
  /**
78
78
  * Create a {@link Type} that is satisfied only by a value strictly equal (`===`) to one of the arguments passed to this function.
79
79
  * @example const enum = type.enumerated('foo', 'bar', obj) // obj is a by-reference object
80
- * @example const tupleForm = type(['===', 'foo', 'bar', obj])
81
- * @example const argsForm = type('===', 'foo', 'bar', obj)
80
+ * @example const TupleForm = type(['===', 'foo', 'bar', obj])
81
+ * @example const ArgsForm = type('===', 'foo', 'bar', obj)
82
82
  */
83
83
  enumerated: EnumeratedTypeParser<$>;
84
84
  /**
@@ -95,12 +95,12 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
95
95
  instanceOf: InstanceOfTypeParser<$>;
96
96
  /**
97
97
  * Create a {@link Type} from a union of definitions
98
- * @example const t = type.or("string", "number")
98
+ * @example const T = type.or("string", "number")
99
99
  */
100
100
  or: NaryUnionParser<$>;
101
101
  /**
102
102
  * Create a {@link Type} from an intersection of definitions
103
- * @example const t = type.and({ a: "1" }, { b: "2" })
103
+ * @example const T = type.and({ a: "1" }, { b: "2" })
104
104
  */
105
105
  and: NaryIntersectionParser<$>;
106
106
  /**
@@ -108,14 +108,14 @@ export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
108
108
  * definitions having precedence for overlapping keys
109
109
  * @example
110
110
  * // Type<{ a: "3", b: "2", c: "4" }>
111
- * const t = type.merge({ a: "1", b: "2" }, { a: "3", c: "4" })
111
+ * const T = type.merge({ a: "1", b: "2" }, { a: "3", c: "4" })
112
112
  */
113
113
  merge: NaryMergeParser<$>;
114
114
  /**
115
115
  * Create a {@link Type} from a set of morphs (including Types)
116
116
  * @example
117
117
  * // Type<(In: string) => To<object>>
118
- * const t = type.pipe(type.string, s => JSON.parse(s), type.object)
118
+ * const T = type.pipe(type.string, s => JSON.parse(s), type.object)
119
119
  */
120
120
  pipe: NaryPipeParser<$>;
121
121
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.1.16",
4
+ "version": "2.1.18",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -34,8 +34,8 @@
34
34
  "out"
35
35
  ],
36
36
  "dependencies": {
37
- "@ark/util": "0.45.6",
38
- "@ark/schema": "0.45.6"
37
+ "@ark/util": "0.45.8",
38
+ "@ark/schema": "0.45.8"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"