arktype 2.1.7 → 2.1.9

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/out/generic.d.ts CHANGED
@@ -14,83 +14,43 @@ export type extractParams<s extends ParameterString> = s extends ParameterString
14
14
  export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
15
15
  export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
16
16
  export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
17
- <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
17
+ <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r extends infer _ ? _ : never;
18
18
  } : params["length"] extends 2 ? {
19
19
  <const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
20
20
  type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
21
21
  type.validate<b, args$> & validateGenericArg<b, params[1], args$>
22
- ]): r;
22
+ ]): r extends infer _ ? _ : never;
23
23
  } : params["length"] extends 3 ? {
24
24
  <const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
25
- type.validate<a, args$>,
26
- type.validate<b, args$>,
27
- type.validate<c, args$>
28
- ] & [
29
- validateGenericArg<a, params[0], args$>,
30
- validateGenericArg<b, params[1], args$>,
31
- validateGenericArg<c, params[2], args$>
32
- ]): r;
25
+ type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
26
+ type.validate<b, args$> & validateGenericArg<b, params[1], args$>,
27
+ type.validate<c, args$> & validateGenericArg<c, params[2], args$>
28
+ ]): r extends infer _ ? _ : never;
33
29
  } : params["length"] extends 4 ? {
34
30
  <const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
35
- type.validate<a, args$>,
36
- type.validate<b, args$>,
37
- type.validate<c, args$>,
38
- type.validate<d, args$>
39
- ] & [
40
- validateGenericArg<a, params[0], args$>,
41
- validateGenericArg<b, params[1], args$>,
42
- validateGenericArg<c, params[2], args$>,
43
- validateGenericArg<d, params[3], args$>
44
- ]): r;
45
- } : params["length"] extends 4 ? {
46
- <const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
47
- type.validate<a, args$>,
48
- type.validate<b, args$>,
49
- type.validate<c, args$>,
50
- type.validate<d, args$>,
51
- type.validate<e, args$>
52
- ] & [
53
- validateGenericArg<a, params[0], args$>,
54
- validateGenericArg<b, params[1], args$>,
55
- validateGenericArg<c, params[2], args$>,
56
- validateGenericArg<d, params[3], args$>,
57
- validateGenericArg<e, params[4], args$>
58
- ]): r;
31
+ type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
32
+ type.validate<b, args$> & validateGenericArg<b, params[1], args$>,
33
+ type.validate<c, args$> & validateGenericArg<c, params[2], args$>,
34
+ type.validate<d, args$> & validateGenericArg<d, params[3], args$>
35
+ ]): r extends infer _ ? _ : never;
59
36
  } : params["length"] extends 5 ? {
60
- <const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
61
- type.validate<a, args$>,
62
- type.validate<b, args$>,
63
- type.validate<c, args$>,
64
- type.validate<d, args$>,
65
- type.validate<e, args$>,
66
- type.validate<f, args$>
67
- ] & [
68
- validateGenericArg<a, params[0], args$>,
69
- validateGenericArg<b, params[1], args$>,
70
- validateGenericArg<c, params[2], args$>,
71
- validateGenericArg<d, params[3], args$>,
72
- validateGenericArg<e, params[4], args$>,
73
- validateGenericArg<f, params[5], args$>
74
- ]): r;
37
+ <const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
38
+ type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
39
+ type.validate<b, args$> & validateGenericArg<b, params[1], args$>,
40
+ type.validate<c, args$> & validateGenericArg<c, params[2], args$>,
41
+ type.validate<d, args$> & validateGenericArg<d, params[3], args$>,
42
+ type.validate<e, args$> & validateGenericArg<e, params[4], args$>
43
+ ]): r extends infer _ ? _ : never;
75
44
  } : params["length"] extends 6 ? {
76
- <const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
77
- type.validate<a, args$>,
78
- type.validate<b, args$>,
79
- type.validate<c, args$>,
80
- type.validate<d, args$>,
81
- type.validate<e, args$>,
82
- type.validate<f, args$>,
83
- type.validate<g, args$>
84
- ] & [
85
- validateGenericArg<a, params[0], args$>,
86
- validateGenericArg<b, params[1], args$>,
87
- validateGenericArg<c, params[2], args$>,
88
- validateGenericArg<d, params[3], args$>,
89
- validateGenericArg<e, params[4], args$>,
90
- validateGenericArg<f, params[5], args$>,
91
- validateGenericArg<g, params[6], args$>
92
- ]): r;
93
- } : (error: ErrorMessage<`You may not define more than 7 positional generic parameters`>) => never;
45
+ <const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
46
+ type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
47
+ type.validate<b, args$> & validateGenericArg<b, params[1], args$>,
48
+ type.validate<c, args$> & validateGenericArg<c, params[2], args$>,
49
+ type.validate<d, args$> & validateGenericArg<d, params[3], args$>,
50
+ type.validate<e, args$> & validateGenericArg<e, params[4], args$>,
51
+ type.validate<f, args$> & validateGenericArg<f, params[5], args$>
52
+ ]): r extends infer _ ? _ : never;
53
+ } : (error: ErrorMessage<`You may not define more than 6 positional generic parameters`>) => never;
94
54
  type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
95
55
  def
96
56
  ] extends [Hkt] ? Hkt.apply<def, {
@@ -252,6 +252,7 @@ export declare const string: Module<{
252
252
  root: unknown;
253
253
  alpha: unknown;
254
254
  alphanumeric: unknown;
255
+ hex: unknown;
255
256
  base64: Submodule<{
256
257
  root: unknown;
257
258
  url: unknown;
@@ -308,6 +309,7 @@ export declare namespace string {
308
309
  root: string;
309
310
  alpha: string;
310
311
  alphanumeric: string;
312
+ hex: string;
311
313
  base64: base64.submodule;
312
314
  capitalize: capitalize.submodule;
313
315
  creditCard: string;
@@ -25,6 +25,7 @@ export const stringInteger = Scope.module({
25
25
  }, {
26
26
  name: "string.integer"
27
27
  });
28
+ const hex = regexStringNode(/^[0-9a-fA-F]+$/, "hex characters only");
28
29
  const base64 = Scope.module({
29
30
  root: regexStringNode(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, "base64-encoded"),
30
31
  url: regexStringNode(/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==|%3D%3D)?|[A-Za-z0-9_-]{3}(?:=|%3D)?)?$/, "base64url-encoded")
@@ -418,6 +419,7 @@ export const string = Scope.module({
418
419
  root: intrinsic.string,
419
420
  alpha: regexStringNode(/^[A-Za-z]*$/, "only letters"),
420
421
  alphanumeric: regexStringNode(/^[A-Za-z\d]*$/, "only letters and digits 0-9"),
422
+ hex,
421
423
  base64,
422
424
  capitalize,
423
425
  creditCard,
@@ -135,11 +135,11 @@ export interface Inferred<out t = unknown, $ = {}> {
135
135
  * const criticalPayload = type({
136
136
  * superImportantValue: "string"
137
137
  * })
138
- * // throws AggregateError: superImportantValue must be a string (was missing)
138
+ * // throws TraversalError: superImportantValue must be a string (was missing)
139
139
  * const data = criticalPayload.assert({ irrelevantValue: "whoops" })
140
140
  * console.log(data.superImportantValue) // valid output can be accessed directly
141
141
  *
142
- * @throws {AggregateError}
142
+ * @throws {TraversalError}
143
143
  */
144
144
  assert(data: unknown): this["infer"];
145
145
  /**
@@ -1,5 +1,5 @@
1
1
  import type { arkKeyOf, array } from "@ark/util";
2
- import type { distill, inferIntersection, LimitLiteral, withDefault } from "../../attributes.ts";
2
+ import type { distill, inferIntersection, inferPipe, LimitLiteral, withDefault } from "../../attributes.ts";
3
3
  import type { type } from "../../keywords/keywords.ts";
4
4
  import type { inferDefinition } from "../definition.ts";
5
5
  import type { Comparator } from "../reduce/shared.ts";
@@ -18,7 +18,7 @@ export type InferredAst<t = unknown, def extends string = string> = [
18
18
  "inferred",
19
19
  def
20
20
  ];
21
- export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? inferGenericInstantiation<g, argAsts, $, args> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
21
+ export type inferExpression<ast, $, args> = ast extends array ? ast extends InferredAst<infer resolution> ? resolution : ast extends DefAst<infer def> ? inferDefinition<def, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? inferGenericInstantiation<g, argAsts, $, args> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "|>" ? inferPipe<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? withDefault<inferExpression<ast[0], $, args>, defaultValue> : never : ast[1] extends "#" ? type.brand<inferExpression<ast[0], $, args>, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression<ast[2], $, args> : inferExpression<ast[0], $, args> : ast[1] extends "%" ? inferExpression<ast[0], $, args> : ast[1] extends "?" ? inferExpression<ast[0], $, args> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
22
22
  export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
23
23
  export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
24
24
  export type PostfixExpression<operator extends ArkTypeScanner.PostfixToken = ArkTypeScanner.PostfixToken, operand = unknown> = readonly [operand, operator];
@@ -1,7 +1,7 @@
1
1
  import type { arkKind, PrivateDeclaration, writeMissingSubmoduleAccessMessage } from "@ark/schema";
2
2
  import type { anyOrNever, BigintLiteral, Completion, ErrorMessage, NumberLiteral, writeMalformedNumericLiteralMessage } from "@ark/util";
3
3
  import type { Generic } from "../../generic.ts";
4
- import type { Comparator } from "../reduce/shared.ts";
4
+ import type { BranchOperator, Comparator } from "../reduce/shared.ts";
5
5
  import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
6
6
  import type { UnitLiteral } from "../shift/operator/default.ts";
7
7
  import type { parseString } from "../string.ts";
@@ -12,7 +12,7 @@ import type { GenericInstantiationAst, validateGenericInstantiation } from "./ge
12
12
  import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
13
13
  import type { validateKeyof } from "./keyof.ts";
14
14
  import type { astToString } from "./utils.ts";
15
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
+ export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<"[]" | "?", infer operand> ? validateAst<operand, $, args> : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends BranchOperator ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericInstantiation<g, argAsts, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
16
16
  ast: ast;
17
17
  };
18
18
  type writeUnexpectedExpressionMessage<expression extends string> = `Failed to parse the expression resulting from ${expression}`;
@@ -2,12 +2,13 @@ import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
3
  import type { LimitLiteral } from "../../attributes.ts";
4
4
  import type { ArkTypeScanner } from "../shift/scanner.ts";
5
- import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
5
+ import { type BranchOperator, type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
6
6
  type BranchState = {
7
7
  prefixes: StringifiablePrefixOperator[];
8
8
  leftBound: OpenLeftBound | null;
9
9
  intersection: BaseRoot | null;
10
10
  union: BaseRoot | null;
11
+ pipe: BaseRoot | null;
11
12
  };
12
13
  export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
13
14
  export declare class DynamicState {
@@ -29,7 +30,7 @@ export declare class DynamicState {
29
30
  finalizeGroup(): void;
30
31
  addPrefix(prefix: StringifiablePrefixOperator): void;
31
32
  applyPrefixes(): void;
32
- pushRootToBranch(token: "|" | "&"): void;
33
+ pushRootToBranch(token: BranchOperator): void;
33
34
  parseUntilFinalizer(): DynamicStateWithRoot;
34
35
  parseOperator(this: DynamicStateWithRoot): void;
35
36
  parseOperand(): void;
@@ -10,7 +10,8 @@ export class DynamicState {
10
10
  prefixes: [],
11
11
  leftBound: null,
12
12
  intersection: null,
13
- union: null
13
+ union: null,
14
+ pipe: null
14
15
  };
15
16
  finalizer;
16
17
  groups = [];
@@ -57,16 +58,22 @@ export class DynamicState {
57
58
  }
58
59
  finalizeBranches() {
59
60
  this.assertRangeUnset();
61
+ if (this.branches.pipe) {
62
+ this.pushRootToBranch("|>");
63
+ this.root = this.branches.pipe;
64
+ return;
65
+ }
60
66
  if (this.branches.union) {
61
67
  this.pushRootToBranch("|");
62
68
  this.root = this.branches.union;
69
+ return;
63
70
  }
64
- else if (this.branches.intersection) {
71
+ if (this.branches.intersection) {
65
72
  this.pushRootToBranch("&");
66
73
  this.root = this.branches.intersection;
74
+ return;
67
75
  }
68
- else
69
- this.applyPrefixes();
76
+ this.applyPrefixes();
70
77
  }
71
78
  finalizeGroup() {
72
79
  this.finalizeBranches();
@@ -91,15 +98,21 @@ export class DynamicState {
91
98
  this.assertRangeUnset();
92
99
  this.applyPrefixes();
93
100
  const root = this.root;
101
+ this.root = undefined;
94
102
  this.branches.intersection =
95
103
  this.branches.intersection?.rawAnd(root) ?? root;
96
- if (token === "|") {
97
- this.branches.union =
98
- this.branches.union?.rawOr(this.branches.intersection) ??
99
- this.branches.intersection;
100
- this.branches.intersection = null;
101
- }
102
- this.root = undefined;
104
+ if (token === "&")
105
+ return;
106
+ this.branches.union =
107
+ this.branches.union?.rawOr(this.branches.intersection) ??
108
+ this.branches.intersection;
109
+ this.branches.intersection = null;
110
+ if (token === "|")
111
+ return;
112
+ this.branches.pipe =
113
+ this.branches.pipe?.rawPipeOnce(this.branches.union) ??
114
+ this.branches.union;
115
+ this.branches.union = null;
103
116
  }
104
117
  parseUntilFinalizer() {
105
118
  return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx));
@@ -121,7 +134,8 @@ export class DynamicState {
121
134
  prefixes: [],
122
135
  leftBound: null,
123
136
  union: null,
124
- intersection: null
137
+ intersection: null,
138
+ pipe: null
125
139
  };
126
140
  }
127
141
  previousOperator() {
@@ -129,7 +143,8 @@ export class DynamicState {
129
143
  this.branches.prefixes.at(-1) ??
130
144
  (this.branches.intersection ? "&"
131
145
  : this.branches.union ? "|"
132
- : undefined));
146
+ : this.branches.pipe ? "|>"
147
+ : undefined));
133
148
  }
134
149
  shiftedByOne() {
135
150
  this.scanner.shift();
@@ -26,6 +26,7 @@ export type InvertedComparators = {
26
26
  ">=": "<=";
27
27
  "==": "==";
28
28
  };
29
+ export type BranchOperator = "&" | "|" | "|>";
29
30
  export type OpenLeftBound = {
30
31
  limit: LimitLiteral;
31
32
  comparator: MinComparator;
@@ -1,7 +1,7 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
2
  import type { LimitLiteral } from "../../attributes.ts";
3
3
  import type { ArkTypeScanner } from "../shift/scanner.ts";
4
- import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
4
+ import type { BranchOperator, Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
5
5
  export type StaticState = {
6
6
  root: unknown;
7
7
  branches: BranchState;
@@ -14,6 +14,7 @@ type BranchState = {
14
14
  prefixes: StringifiablePrefixOperator[];
15
15
  leftBound: OpenLeftBound | undefined;
16
16
  intersection: unknown;
17
+ pipe: unknown;
17
18
  union: unknown;
18
19
  };
19
20
  export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
@@ -46,6 +47,7 @@ export declare namespace state {
46
47
  prefixes: [];
47
48
  leftBound: undefined;
48
49
  intersection: undefined;
50
+ pipe: undefined;
49
51
  union: undefined;
50
52
  }>;
51
53
  type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
@@ -63,6 +65,7 @@ export declare namespace state {
63
65
  prefixes: [...s["branches"]["prefixes"], prefix];
64
66
  leftBound: s["branches"]["leftBound"];
65
67
  intersection: s["branches"]["intersection"];
68
+ pipe: s["branches"]["pipe"];
66
69
  union: s["branches"]["union"];
67
70
  };
68
71
  groups: s["groups"];
@@ -70,13 +73,14 @@ export declare namespace state {
70
73
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
71
74
  unscanned: unscanned;
72
75
  }>;
73
- type reduceBranch<s extends StaticState, token extends "|" | "&", unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
76
+ type reduceBranch<s extends StaticState, token extends BranchOperator, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
74
77
  root: undefined;
75
78
  branches: {
76
79
  prefixes: [];
77
80
  leftBound: undefined;
78
81
  intersection: token extends "&" ? mergeToIntersection<s> : undefined;
79
- union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"];
82
+ union: token extends "|" ? mergeToUnion<s> : token extends "|>" ? undefined : s["branches"]["union"];
83
+ pipe: token extends "|>" ? mergeToPipe<s> : s["branches"]["pipe"];
80
84
  };
81
85
  groups: s["groups"];
82
86
  finalizer: s["finalizer"];
@@ -92,6 +96,7 @@ export declare namespace state {
92
96
  comparator: InvertedComparators[comparator];
93
97
  };
94
98
  intersection: s["branches"]["intersection"];
99
+ pipe: s["branches"]["pipe"];
95
100
  union: s["branches"]["union"];
96
101
  };
97
102
  groups: s["groups"];
@@ -105,6 +110,7 @@ export declare namespace state {
105
110
  prefixes: s["branches"]["prefixes"];
106
111
  leftBound: undefined;
107
112
  intersection: s["branches"]["intersection"];
113
+ pipe: s["branches"]["pipe"];
108
114
  union: s["branches"]["union"];
109
115
  };
110
116
  groups: s["groups"];
@@ -118,6 +124,7 @@ export declare namespace state {
118
124
  prefixes: s["branches"]["prefixes"];
119
125
  leftBound: undefined;
120
126
  intersection: s["branches"]["intersection"];
127
+ pipe: s["branches"]["pipe"];
121
128
  union: s["branches"]["union"];
122
129
  };
123
130
  groups: s["groups"];
@@ -125,8 +132,9 @@ export declare namespace state {
125
132
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
126
133
  unscanned: unscanned;
127
134
  }>;
128
- type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
129
135
  type mergeToIntersection<s extends StaticState> = s["branches"]["intersection"] extends undefined ? mergePrefixes<s> : [s["branches"]["intersection"], "&", mergePrefixes<s>];
136
+ type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
137
+ type mergeToPipe<s extends StaticState> = s["branches"]["pipe"] extends undefined ? mergeToUnion<s> : [s["branches"]["pipe"], "|>", mergeToUnion<s>];
130
138
  type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [
131
139
  head,
132
140
  mergePrefixes<s, tail>
@@ -138,7 +146,7 @@ export declare namespace state {
138
146
  type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
139
147
  groups: stack;
140
148
  branches: top;
141
- root: mergeToUnion<s>;
149
+ root: mergeToPipe<s>;
142
150
  finalizer: s["finalizer"];
143
151
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
144
152
  unscanned: unscanned;
@@ -152,7 +160,7 @@ export declare namespace state {
152
160
  unscanned: unscanned;
153
161
  }>;
154
162
  type finalize<s extends StaticState, finalizer extends ArkTypeScanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
155
- root: mergeToUnion<s>;
163
+ root: mergeToPipe<s>;
156
164
  groups: s["groups"];
157
165
  branches: initialBranches;
158
166
  finalizer: finalizer;
@@ -6,7 +6,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
6
  import { parseBrand } from "./brand.ts";
7
7
  import { parseDivisor } from "./divisor.ts";
8
8
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
9
- export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : ArkTypeScanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & ArkTypeScanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
+ export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" ? unscanned extends ArkTypeScanner.shift<">", infer nextUnscanned> ? state.reduceBranch<s, "|>", nextUnscanned> : state.reduceBranch<s, lookahead, unscanned> : lookahead extends "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : ArkTypeScanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & ArkTypeScanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
10
10
  export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
11
11
  export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
12
12
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
@@ -10,15 +10,19 @@ export const parseOperator = (s) => {
10
10
  s.scanner.shift() === "]" ?
11
11
  s.setRoot(s.root.array())
12
12
  : s.error(incompleteArrayTokenMessage)
13
- : lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
14
- : lookahead === ")" ? s.finalizeGroup()
15
- : ArkTypeScanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
16
- s.finalize(lookahead)
17
- : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
18
- : lookahead === "%" ? parseDivisor(s)
19
- : lookahead === "#" ? parseBrand(s)
20
- : lookahead in whitespaceChars ? parseOperator(s)
21
- : s.error(writeUnexpectedCharacterMessage(lookahead)));
13
+ : lookahead === "|" ?
14
+ s.scanner.lookahead === ">" ?
15
+ s.shiftedByOne().pushRootToBranch("|>")
16
+ : s.pushRootToBranch(lookahead)
17
+ : lookahead === "&" ? s.pushRootToBranch(lookahead)
18
+ : lookahead === ")" ? s.finalizeGroup()
19
+ : ArkTypeScanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
20
+ s.finalize(lookahead)
21
+ : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
22
+ : lookahead === "%" ? parseDivisor(s)
23
+ : lookahead === "#" ? parseBrand(s)
24
+ : lookahead in whitespaceChars ? parseOperator(s)
25
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
22
26
  };
23
27
  export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
24
28
  export const incompleteArrayTokenMessage = `Missing expected ']'`;
@@ -30,8 +30,7 @@ export type TupleExpression = IndexZeroExpression | IndexOneExpression;
30
30
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
31
31
  export type ArgTwoOperator = Exclude<IndexOneOperator, "?" | "=">;
32
32
  export declare const parseMorphTuple: IndexOneParser<"=>">;
33
- export declare const parseToTuple: IndexOneParser<"|>">;
34
- export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>" | "|>", value: unknown) => string;
33
+ export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
35
34
  export type parseTo<inDef, outDef, $, args> = inferPipe<inferDefinition<inDef, $, args>, inferDefinition<outDef, $, args>>;
36
35
  export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
37
36
  export declare const parseNarrowTuple: IndexOneParser<":">;
@@ -43,22 +42,22 @@ declare const postfixParsers: {
43
42
  };
44
43
  export type TuplePostfixOperator = keyof typeof postfixParsers;
45
44
  declare const infixParsers: {
46
- "=": IndexOneParser<"=">;
47
- "|": IndexOneParser<"|">;
48
45
  "&": IndexOneParser<"&">;
46
+ "|": IndexOneParser<"|">;
47
+ "|>": IndexOneParser<"|>">;
48
+ "=": IndexOneParser<"=">;
49
49
  ":": IndexOneParser<":">;
50
50
  "=>": IndexOneParser<"=>">;
51
- "|>": IndexOneParser<"|>">;
52
51
  "@": IndexOneParser<"@">;
53
52
  };
54
53
  export type TupleInfixOperator = keyof typeof infixParsers;
55
54
  declare const indexOneParsers: {
56
- "=": IndexOneParser<"=">;
57
- "|": IndexOneParser<"|">;
58
55
  "&": IndexOneParser<"&">;
56
+ "|": IndexOneParser<"|">;
57
+ "|>": IndexOneParser<"|>">;
58
+ "=": IndexOneParser<"=">;
59
59
  ":": IndexOneParser<":">;
60
60
  "=>": IndexOneParser<"=>">;
61
- "|>": IndexOneParser<"|>">;
62
61
  "@": IndexOneParser<"@">;
63
62
  "?": IndexOneParser<"?">;
64
63
  "[]": IndexOneParser<"[]">;
@@ -1,4 +1,4 @@
1
- import { Disjoint, intersectNodesRoot } from "@ark/schema";
1
+ import { Disjoint, intersectNodesRoot, pipeNodesRoot } from "@ark/schema";
2
2
  import { objectKindOrDomainOf, throwParseError } from "@ark/util";
3
3
  import { shallowDefaultableMessage, shallowOptionalMessage } from "./ast/validate.js";
4
4
  import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
@@ -13,7 +13,9 @@ const parseBranchTuple = (def, ctx) => {
13
13
  const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
14
14
  if (def[1] === "|")
15
15
  return ctx.$.node("union", { branches: [l, r] });
16
- const result = intersectNodesRoot(l, r, ctx.$);
16
+ const result = def[1] === "&" ?
17
+ intersectNodesRoot(l, r, ctx.$)
18
+ : pipeNodesRoot(l, r, ctx.$);
17
19
  if (result instanceof Disjoint)
18
20
  return result.throw();
19
21
  return result;
@@ -25,11 +27,6 @@ export const parseMorphTuple = (def, ctx) => {
25
27
  }
26
28
  return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
27
29
  };
28
- export const parseToTuple = (def, ctx) => {
29
- const node = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
30
- const outputValidator = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
31
- return node.to(outputValidator);
32
- };
33
30
  export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
34
31
  export const parseNarrowTuple = (def, ctx) => {
35
32
  if (typeof def[2] !== "function") {
@@ -48,7 +45,7 @@ const infixParsers = defineIndexOneParsers({
48
45
  "&": parseBranchTuple,
49
46
  ":": parseNarrowTuple,
50
47
  "=>": parseMorphTuple,
51
- "|>": parseToTuple,
48
+ "|>": parseBranchTuple,
52
49
  "@": parseAttributeTuple,
53
50
  // since object and tuple literals parse there via `parseProperty`,
54
51
  // they must be shallow if parsed directly as a tuple expression
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "Optimized runtime validation for TypeScript syntax",
4
- "version": "2.1.7",
4
+ "version": "2.1.9",
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.44.2",
38
- "@ark/schema": "0.44.2"
37
+ "@ark/util": "0.44.4",
38
+ "@ark/schema": "0.44.4"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"