arktype 2.0.0-dev.1 → 2.0.0-dev.11
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/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/module.d.ts +12 -0
- package/out/module.js +3 -0
- package/out/parser/definition.d.ts +14 -14
- package/out/parser/definition.js +10 -13
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +44 -18
- package/out/parser/objectLiteral.js +57 -51
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +16 -13
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/shared.d.ts +14 -28
- package/out/parser/string/reduce/shared.js +4 -3
- package/out/parser/string/reduce/static.d.ts +27 -24
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/string/shift/operand/enclosed.js +14 -14
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +8 -12
- package/out/parser/string/shift/operand/unenclosed.d.ts +16 -21
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +45 -56
- package/out/parser/string/shift/operator/divisor.d.ts +1 -3
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/scanner.d.ts +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/scope.d.ts +44 -119
- package/out/scope.js +39 -209
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/package.json +12 -10
- package/__tests__/array.test.ts +0 -272
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/badDefinitionType.test.ts +0 -51
- package/__tests__/basis.test.ts +0 -46
- package/__tests__/bounds.test.ts +0 -388
- package/__tests__/cast.test.ts +0 -32
- package/__tests__/completions.test.ts +0 -46
- package/__tests__/config.test.ts +0 -168
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -123
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -90
- package/__tests__/enclosed.test.ts +0 -93
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -138
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -294
- package/__tests__/group.test.ts +0 -72
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -113
- package/__tests__/instanceof.test.ts +0 -102
- package/__tests__/intersection.test.ts +0 -104
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/keyTraversal.test.ts +0 -73
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.test.ts +0 -34
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/narrow.test.ts +0 -102
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -300
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/regex.test.ts +0 -58
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -140
- package/__tests__/string.test.ts +0 -48
- package/__tests__/submodule.test.ts +0 -99
- package/__tests__/this.test.ts +0 -57
- package/__tests__/thunk.test.ts +0 -80
- package/__tests__/traverse.test.ts +0 -119
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/typeMethods.test.ts +0 -69
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -120
- package/__tests__/union.test.ts +0 -147
- package/ark.ts +0 -91
- package/main.ts +0 -18
- package/match.ts +0 -116
- package/out/ark.d.ts.map +0 -1
- package/out/ark.js.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/main.js.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/match.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/shared.d.ts +0 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/type.js.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/definition.ts +0 -159
- package/parser/generic.ts +0 -68
- package/parser/objectLiteral.ts +0 -197
- package/parser/semantic/bounds.ts +0 -61
- package/parser/semantic/divisor.ts +0 -13
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -144
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -152
- package/parser/string/reduce/dynamic.ts +0 -196
- package/parser/string/reduce/shared.ts +0 -101
- package/parser/string/reduce/static.ts +0 -298
- package/parser/string/shift/operand/date.ts +0 -54
- package/parser/string/shift/operand/enclosed.ts +0 -118
- package/parser/string/shift/operand/genericArgs.ts +0 -127
- package/parser/string/shift/operand/operand.ts +0 -48
- package/parser/string/shift/operand/unenclosed.ts +0 -268
- package/parser/string/shift/operator/bounds.ts +0 -264
- package/parser/string/shift/operator/divisor.ts +0 -36
- package/parser/string/shift/operator/operator.ts +0 -82
- package/parser/string/shift/scanner.ts +0 -209
- package/parser/string/string.ts +0 -90
- package/parser/tuple.ts +0 -474
- package/scope.ts +0 -574
- package/type.ts +0 -347
- package/util.ts +0 -36
package/parser/shared.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import type { extend } from "@arktype/util"
|
|
2
|
-
import type { validateDefinition } from "./definition.js"
|
|
3
|
-
import { Scanner } from "./string/shift/scanner.js"
|
|
4
|
-
|
|
5
|
-
type parsedKey<result extends KeyParseResult> = result
|
|
6
|
-
|
|
7
|
-
type OptionalTuple<value> = readonly [value, "?"]
|
|
8
|
-
|
|
9
|
-
type KeyParseResult<kind extends ParsedKeyKind = ParsedKeyKind> = {
|
|
10
|
-
kind: kind
|
|
11
|
-
innerKey: string | symbol
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type ValueParseResult<kind extends ParsedValueKind = ParsedValueKind> = {
|
|
15
|
-
kind: kind
|
|
16
|
-
innerValue: unknown
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type EntryParseResult<kind extends ParsedKeyKind = ParsedKeyKind> =
|
|
20
|
-
extend<
|
|
21
|
-
KeyParseResult<kind>,
|
|
22
|
-
{
|
|
23
|
-
innerValue: unknown
|
|
24
|
-
}
|
|
25
|
-
>
|
|
26
|
-
|
|
27
|
-
type ParsedValueKind = "required" | "optional"
|
|
28
|
-
|
|
29
|
-
type ParsedKeyKind = "required" | "optional" | "indexed" | "spread"
|
|
30
|
-
|
|
31
|
-
type parsedEntry<result extends EntryParseResult> = result
|
|
32
|
-
|
|
33
|
-
export type OptionalValue<value> =
|
|
34
|
-
| OptionalStringDefinition<value & string>
|
|
35
|
-
| OptionalTuple<value>
|
|
36
|
-
|
|
37
|
-
export type OptionalStringDefinition<name extends string = string> = `${name}?`
|
|
38
|
-
|
|
39
|
-
export type IndexedKey<def extends string = string> = `[${def}]`
|
|
40
|
-
|
|
41
|
-
export type validateObjectValue<def, $, args> = def extends OptionalTuple<
|
|
42
|
-
infer value
|
|
43
|
-
>
|
|
44
|
-
? readonly [validateObjectValueString<value, $, args>, "?"]
|
|
45
|
-
: validateObjectValueString<def, $, args>
|
|
46
|
-
|
|
47
|
-
type validateObjectValueString<def, $, args> =
|
|
48
|
-
def extends OptionalStringDefinition<infer innerValue>
|
|
49
|
-
? `${validateDefinition<innerValue, $, args>}?`
|
|
50
|
-
: validateDefinition<def, $, args>
|
|
51
|
-
|
|
52
|
-
type DefinitionEntry = readonly [string | symbol, unknown]
|
|
53
|
-
|
|
54
|
-
const getInnerValue = (value: unknown): ValueParseResult => {
|
|
55
|
-
if (typeof value === "string") {
|
|
56
|
-
if (value[value.length - 1] === "?") {
|
|
57
|
-
return {
|
|
58
|
-
kind: "optional",
|
|
59
|
-
innerValue: value.slice(0, -1)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} else if (Array.isArray(value)) {
|
|
63
|
-
if (value.length === 2 && value[1] === "?") {
|
|
64
|
-
return {
|
|
65
|
-
kind: "optional",
|
|
66
|
-
innerValue: getInnerValue(value[0]).innerValue
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
kind: "required",
|
|
72
|
-
innerValue: value
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// these methods are also used in tuple parsing, however the keys of a tuple will always be 0, 1,
|
|
77
|
-
// 2, etc and never be `...`, meaning `"spread"` as a kind will never occur in tuples
|
|
78
|
-
|
|
79
|
-
export const parseEntry = ([key, value]: DefinitionEntry): EntryParseResult => {
|
|
80
|
-
const keyParseResult: KeyParseResult =
|
|
81
|
-
typeof key === "string" && key.at(-1) === "?"
|
|
82
|
-
? key.at(-2) === Scanner.escapeToken
|
|
83
|
-
? { innerKey: `${key.slice(0, -2)}?`, kind: "required" }
|
|
84
|
-
: { innerKey: key.slice(0, -1), kind: "optional" }
|
|
85
|
-
: key === "..."
|
|
86
|
-
? { innerKey: "...", kind: "spread" }
|
|
87
|
-
: key === "\\..."
|
|
88
|
-
? { innerKey: "...", kind: "required" }
|
|
89
|
-
: { innerKey: key, kind: "required" }
|
|
90
|
-
const valueParseResult = getInnerValue(value)
|
|
91
|
-
return {
|
|
92
|
-
innerKey: keyParseResult.innerKey,
|
|
93
|
-
innerValue: valueParseResult.innerValue,
|
|
94
|
-
kind:
|
|
95
|
-
keyParseResult.kind === "indexed"
|
|
96
|
-
? "indexed"
|
|
97
|
-
: valueParseResult.kind === "optional"
|
|
98
|
-
? "optional"
|
|
99
|
-
: keyParseResult.kind
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type parseEntry<
|
|
104
|
-
keyDef extends PropertyKey,
|
|
105
|
-
valueDef
|
|
106
|
-
> = parseKey<keyDef> extends infer keyParseResult extends KeyParseResult
|
|
107
|
-
? valueDef extends OptionalValue<infer innerValue>
|
|
108
|
-
? parsedEntry<{
|
|
109
|
-
kind: "optional"
|
|
110
|
-
innerKey: keyParseResult["innerKey"]
|
|
111
|
-
innerValue: innerValue extends OptionalStringDefinition<
|
|
112
|
-
infer innerStringValue
|
|
113
|
-
>
|
|
114
|
-
? innerStringValue
|
|
115
|
-
: innerValue
|
|
116
|
-
}>
|
|
117
|
-
: parsedEntry<{
|
|
118
|
-
kind: keyParseResult["kind"]
|
|
119
|
-
innerKey: keyParseResult["innerKey"]
|
|
120
|
-
innerValue: valueDef
|
|
121
|
-
}>
|
|
122
|
-
: never
|
|
123
|
-
|
|
124
|
-
type parseKey<k> = k extends OptionalStringDefinition<infer inner>
|
|
125
|
-
? inner extends `${infer baseName}${Scanner.EscapeToken}`
|
|
126
|
-
? parsedKey<{
|
|
127
|
-
kind: "required"
|
|
128
|
-
innerKey: OptionalStringDefinition<baseName>
|
|
129
|
-
}>
|
|
130
|
-
: parsedKey<{
|
|
131
|
-
kind: "optional"
|
|
132
|
-
innerKey: inner
|
|
133
|
-
}>
|
|
134
|
-
: k extends "..."
|
|
135
|
-
? parsedKey<{ kind: "spread"; innerKey: "..." }>
|
|
136
|
-
: k extends "\\..."
|
|
137
|
-
? parsedKey<{ kind: "required"; innerKey: "..." }>
|
|
138
|
-
: k extends IndexedKey<infer def>
|
|
139
|
-
? parsedKey<{
|
|
140
|
-
kind: "indexed"
|
|
141
|
-
innerKey: def
|
|
142
|
-
}>
|
|
143
|
-
: k extends `${Scanner.EscapeToken}${infer escapedIndexKey extends
|
|
144
|
-
IndexedKey}`
|
|
145
|
-
? parsedKey<{
|
|
146
|
-
kind: "required"
|
|
147
|
-
innerKey: escapedIndexKey
|
|
148
|
-
}>
|
|
149
|
-
: parsedKey<{
|
|
150
|
-
kind: "required"
|
|
151
|
-
innerKey: k & (string | symbol)
|
|
152
|
-
}>
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import type { TypeNode } from "@arktype/schema"
|
|
2
|
-
import {
|
|
3
|
-
isKeyOf,
|
|
4
|
-
throwInternalError,
|
|
5
|
-
throwParseError,
|
|
6
|
-
type requireKeys
|
|
7
|
-
} from "@arktype/util"
|
|
8
|
-
import type { ParseContext } from "../../../scope.js"
|
|
9
|
-
import { parseOperand } from "../shift/operand/operand.js"
|
|
10
|
-
import { parseOperator } from "../shift/operator/operator.js"
|
|
11
|
-
import { Scanner } from "../shift/scanner.js"
|
|
12
|
-
import { parseUntilFinalizer } from "../string.js"
|
|
13
|
-
import {
|
|
14
|
-
invertedComparators,
|
|
15
|
-
minComparators,
|
|
16
|
-
writeMultipleLeftBoundsMessage,
|
|
17
|
-
writeOpenRangeMessage,
|
|
18
|
-
writeUnclosedGroupMessage,
|
|
19
|
-
writeUnmatchedGroupCloseMessage,
|
|
20
|
-
writeUnpairableComparatorMessage,
|
|
21
|
-
type Comparator,
|
|
22
|
-
type LimitLiteral,
|
|
23
|
-
type OpenLeftBound,
|
|
24
|
-
type StringifiablePrefixOperator
|
|
25
|
-
} from "./shared.js"
|
|
26
|
-
|
|
27
|
-
type BranchState = {
|
|
28
|
-
prefixes: StringifiablePrefixOperator[]
|
|
29
|
-
leftBound?: OpenLeftBound
|
|
30
|
-
"&"?: TypeNode
|
|
31
|
-
"|"?: TypeNode
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">
|
|
35
|
-
|
|
36
|
-
export class DynamicState {
|
|
37
|
-
readonly scanner: Scanner
|
|
38
|
-
root: TypeNode | undefined
|
|
39
|
-
branches: BranchState = {
|
|
40
|
-
prefixes: []
|
|
41
|
-
}
|
|
42
|
-
finalizer: Scanner.FinalizingLookahead | undefined
|
|
43
|
-
groups: BranchState[] = []
|
|
44
|
-
|
|
45
|
-
constructor(
|
|
46
|
-
def: string,
|
|
47
|
-
public readonly ctx: ParseContext
|
|
48
|
-
) {
|
|
49
|
-
this.scanner = new Scanner(def)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
error(message: string) {
|
|
53
|
-
return throwParseError(message)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
hasRoot(): this is DynamicStateWithRoot {
|
|
57
|
-
return this.root !== undefined
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
unsetRoot(): this["root"] {
|
|
61
|
-
const value = this.root
|
|
62
|
-
this.root = undefined
|
|
63
|
-
return value
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
constrainRoot(...args: Parameters<TypeNode["constrain"]>) {
|
|
67
|
-
this.root = this.root!.constrain(...args)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
setRoot(root: TypeNode) {
|
|
71
|
-
this.root = root
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
finalize(finalizer: Scanner.FinalizingLookahead) {
|
|
75
|
-
if (this.groups.length) {
|
|
76
|
-
return this.error(writeUnclosedGroupMessage(")"))
|
|
77
|
-
}
|
|
78
|
-
this.finalizeBranches()
|
|
79
|
-
this.finalizer = finalizer
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
reduceLeftBound(limit: LimitLiteral, comparator: Comparator) {
|
|
83
|
-
const invertedComparator = invertedComparators[comparator]
|
|
84
|
-
if (!isKeyOf(invertedComparator, minComparators)) {
|
|
85
|
-
return this.error(writeUnpairableComparatorMessage(comparator))
|
|
86
|
-
}
|
|
87
|
-
if (this.branches.leftBound) {
|
|
88
|
-
return this.error(
|
|
89
|
-
writeMultipleLeftBoundsMessage(
|
|
90
|
-
this.branches.leftBound.limit,
|
|
91
|
-
this.branches.leftBound.comparator,
|
|
92
|
-
limit,
|
|
93
|
-
invertedComparator
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
this.branches.leftBound = {
|
|
98
|
-
comparator: invertedComparator,
|
|
99
|
-
limit
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
finalizeBranches() {
|
|
104
|
-
this.assertRangeUnset()
|
|
105
|
-
if (this.branches["|"]) {
|
|
106
|
-
this.pushRootToBranch("|")
|
|
107
|
-
this.root = this.branches["|"]
|
|
108
|
-
} else if (this.branches["&"]) {
|
|
109
|
-
this.pushRootToBranch("&")
|
|
110
|
-
this.root = this.branches["&"]
|
|
111
|
-
} else {
|
|
112
|
-
this.applyPrefixes()
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
finalizeGroup() {
|
|
117
|
-
this.finalizeBranches()
|
|
118
|
-
const topBranchState = this.groups.pop()
|
|
119
|
-
if (!topBranchState) {
|
|
120
|
-
return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned))
|
|
121
|
-
}
|
|
122
|
-
this.branches = topBranchState
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
addPrefix(prefix: StringifiablePrefixOperator) {
|
|
126
|
-
this.branches.prefixes.push(prefix)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
applyPrefixes() {
|
|
130
|
-
while (this.branches.prefixes.length) {
|
|
131
|
-
const lastPrefix = this.branches.prefixes.pop()!
|
|
132
|
-
this.root =
|
|
133
|
-
lastPrefix === "keyof"
|
|
134
|
-
? this.root!.keyof()
|
|
135
|
-
: throwInternalError(`Unexpected prefix '${lastPrefix}'`)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
pushRootToBranch(token: "|" | "&") {
|
|
140
|
-
this.assertRangeUnset()
|
|
141
|
-
this.applyPrefixes()
|
|
142
|
-
const root = this.root!
|
|
143
|
-
this.branches["&"] = this.branches["&"]?.and(root) ?? root
|
|
144
|
-
if (token === "|") {
|
|
145
|
-
this.branches["|"] =
|
|
146
|
-
this.branches["|"]?.or(this.branches["&"]) ?? this.branches["&"]
|
|
147
|
-
delete this.branches["&"]
|
|
148
|
-
}
|
|
149
|
-
this.root = undefined
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
parseUntilFinalizer() {
|
|
153
|
-
return parseUntilFinalizer(
|
|
154
|
-
new DynamicState(this.scanner.unscanned, this.ctx)
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
parseOperator(this: DynamicStateWithRoot) {
|
|
159
|
-
return parseOperator(this)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
parseOperand() {
|
|
163
|
-
return parseOperand(this)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private assertRangeUnset() {
|
|
167
|
-
if (this.branches.leftBound) {
|
|
168
|
-
return this.error(
|
|
169
|
-
writeOpenRangeMessage(
|
|
170
|
-
this.branches.leftBound.limit,
|
|
171
|
-
this.branches.leftBound.comparator
|
|
172
|
-
)
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
reduceGroupOpen() {
|
|
178
|
-
this.groups.push(this.branches)
|
|
179
|
-
this.branches = {
|
|
180
|
-
prefixes: []
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
previousOperator() {
|
|
185
|
-
return (
|
|
186
|
-
this.branches.leftBound?.comparator ??
|
|
187
|
-
this.branches.prefixes.at(-1) ??
|
|
188
|
-
(this.branches["&"] ? "&" : this.branches["|"] ? "|" : undefined)
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
shiftedByOne() {
|
|
193
|
-
this.scanner.shift()
|
|
194
|
-
return this
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { DateLiteral } from "@arktype/schema"
|
|
2
|
-
|
|
3
|
-
export type StringifiablePrefixOperator = "keyof"
|
|
4
|
-
|
|
5
|
-
export const minComparators = {
|
|
6
|
-
">": true,
|
|
7
|
-
">=": true
|
|
8
|
-
} as const
|
|
9
|
-
|
|
10
|
-
export type MinComparator = keyof typeof minComparators
|
|
11
|
-
|
|
12
|
-
export const maxComparators = {
|
|
13
|
-
"<": true,
|
|
14
|
-
"<=": true
|
|
15
|
-
} as const
|
|
16
|
-
|
|
17
|
-
export type MaxComparator = keyof typeof maxComparators
|
|
18
|
-
|
|
19
|
-
export const comparators = {
|
|
20
|
-
...minComparators,
|
|
21
|
-
...maxComparators,
|
|
22
|
-
"==": true
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type Comparator = keyof typeof comparators
|
|
26
|
-
|
|
27
|
-
export const invertedComparators = {
|
|
28
|
-
"<": ">",
|
|
29
|
-
">": "<",
|
|
30
|
-
"<=": ">=",
|
|
31
|
-
">=": "<=",
|
|
32
|
-
"==": "=="
|
|
33
|
-
} as const satisfies Record<Comparator, Comparator>
|
|
34
|
-
|
|
35
|
-
export type InvertedComparators = typeof invertedComparators
|
|
36
|
-
|
|
37
|
-
export type LimitLiteral = number | DateLiteral
|
|
38
|
-
|
|
39
|
-
export type OpenLeftBound = { limit: LimitLiteral; comparator: MinComparator }
|
|
40
|
-
|
|
41
|
-
export const writeUnmatchedGroupCloseMessage = <unscanned extends string>(
|
|
42
|
-
unscanned: unscanned
|
|
43
|
-
): writeUnmatchedGroupCloseMessage<unscanned> =>
|
|
44
|
-
`Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`) as any}`
|
|
45
|
-
|
|
46
|
-
export type writeUnmatchedGroupCloseMessage<unscanned extends string> =
|
|
47
|
-
`Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`
|
|
48
|
-
|
|
49
|
-
export const writeUnclosedGroupMessage = <missingChar extends string>(
|
|
50
|
-
missingChar: missingChar
|
|
51
|
-
): writeUnclosedGroupMessage<missingChar> => `Missing ${missingChar}`
|
|
52
|
-
|
|
53
|
-
export type writeUnclosedGroupMessage<missingChar extends string> =
|
|
54
|
-
`Missing ${missingChar}`
|
|
55
|
-
|
|
56
|
-
export const writeOpenRangeMessage = <
|
|
57
|
-
min extends LimitLiteral,
|
|
58
|
-
comparator extends MinComparator
|
|
59
|
-
>(
|
|
60
|
-
min: min,
|
|
61
|
-
comparator: comparator
|
|
62
|
-
): writeOpenRangeMessage<min, comparator> =>
|
|
63
|
-
`Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`
|
|
64
|
-
|
|
65
|
-
export type writeOpenRangeMessage<
|
|
66
|
-
min extends LimitLiteral,
|
|
67
|
-
comparator extends MinComparator
|
|
68
|
-
> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`
|
|
69
|
-
|
|
70
|
-
export type writeUnpairableComparatorMessage<comparator extends Comparator> =
|
|
71
|
-
`Left-bounded expressions must specify their limits using < or <= (was ${comparator})`
|
|
72
|
-
|
|
73
|
-
export const writeUnpairableComparatorMessage = <comparator extends Comparator>(
|
|
74
|
-
comparator: comparator
|
|
75
|
-
): writeUnpairableComparatorMessage<comparator> =>
|
|
76
|
-
`Left-bounded expressions must specify their limits using < or <= (was ${comparator})`
|
|
77
|
-
|
|
78
|
-
export const writeMultipleLeftBoundsMessage = <
|
|
79
|
-
openLimit extends LimitLiteral,
|
|
80
|
-
openComparator extends MinComparator,
|
|
81
|
-
limit extends LimitLiteral,
|
|
82
|
-
comparator extends MinComparator
|
|
83
|
-
>(
|
|
84
|
-
openLimit: openLimit,
|
|
85
|
-
openComparator: openComparator,
|
|
86
|
-
limit: limit,
|
|
87
|
-
comparator: comparator
|
|
88
|
-
): writeMultipleLeftBoundsMessage<
|
|
89
|
-
openLimit,
|
|
90
|
-
openComparator,
|
|
91
|
-
limit,
|
|
92
|
-
comparator
|
|
93
|
-
> =>
|
|
94
|
-
`An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`
|
|
95
|
-
|
|
96
|
-
export type writeMultipleLeftBoundsMessage<
|
|
97
|
-
openLimit extends LimitLiteral,
|
|
98
|
-
openComparator extends MinComparator,
|
|
99
|
-
limit extends LimitLiteral,
|
|
100
|
-
comparator extends MinComparator
|
|
101
|
-
> = `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[comparator]})`
|