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.
Files changed (221) hide show
  1. package/out/api.d.ts +6 -0
  2. package/out/api.js +5 -0
  3. package/out/ark.d.ts +15 -39
  4. package/out/ark.js +9 -18
  5. package/out/config.d.ts +1 -0
  6. package/out/config.js +2 -0
  7. package/out/generic.d.ts +21 -0
  8. package/out/generic.js +24 -0
  9. package/out/main.d.ts +6 -7
  10. package/out/main.js +4 -3
  11. package/out/match.d.ts +57 -34
  12. package/out/match.js +51 -17
  13. package/out/module.d.ts +12 -0
  14. package/out/module.js +3 -0
  15. package/out/parser/definition.d.ts +14 -14
  16. package/out/parser/definition.js +10 -13
  17. package/out/parser/generic.d.ts +5 -7
  18. package/out/parser/generic.js +7 -11
  19. package/out/parser/objectLiteral.d.ts +44 -18
  20. package/out/parser/objectLiteral.js +57 -51
  21. package/out/parser/semantic/bounds.d.ts +10 -8
  22. package/out/parser/semantic/bounds.js +0 -1
  23. package/out/parser/semantic/divisor.d.ts +5 -7
  24. package/out/parser/semantic/divisor.js +0 -1
  25. package/out/parser/semantic/infer.d.ts +24 -0
  26. package/out/parser/semantic/infer.js +1 -0
  27. package/out/parser/semantic/utils.d.ts +3 -7
  28. package/out/parser/semantic/utils.js +0 -1
  29. package/out/parser/semantic/validate.d.ts +16 -13
  30. package/out/parser/semantic/validate.js +1 -1
  31. package/out/parser/string/reduce/dynamic.d.ts +13 -13
  32. package/out/parser/string/reduce/dynamic.js +31 -26
  33. package/out/parser/string/reduce/shared.d.ts +14 -28
  34. package/out/parser/string/reduce/shared.js +4 -3
  35. package/out/parser/string/reduce/static.d.ts +27 -24
  36. package/out/parser/string/reduce/static.js +0 -1
  37. package/out/parser/string/shift/operand/date.d.ts +2 -2
  38. package/out/parser/string/shift/operand/date.js +4 -7
  39. package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
  40. package/out/parser/string/shift/operand/enclosed.js +14 -14
  41. package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
  42. package/out/parser/string/shift/operand/genericArgs.js +6 -10
  43. package/out/parser/string/shift/operand/operand.d.ts +3 -4
  44. package/out/parser/string/shift/operand/operand.js +8 -12
  45. package/out/parser/string/shift/operand/unenclosed.d.ts +16 -21
  46. package/out/parser/string/shift/operand/unenclosed.js +24 -36
  47. package/out/parser/string/shift/operator/bounds.d.ts +8 -12
  48. package/out/parser/string/shift/operator/bounds.js +45 -56
  49. package/out/parser/string/shift/operator/divisor.d.ts +1 -3
  50. package/out/parser/string/shift/operator/divisor.js +1 -3
  51. package/out/parser/string/shift/operator/operator.d.ts +1 -2
  52. package/out/parser/string/shift/operator/operator.js +12 -19
  53. package/out/parser/string/shift/scanner.d.ts +2 -2
  54. package/out/parser/string/shift/scanner.js +14 -16
  55. package/out/parser/string/string.d.ts +8 -6
  56. package/out/parser/string/string.js +1 -3
  57. package/out/parser/tuple.d.ts +102 -43
  58. package/out/parser/tuple.js +119 -87
  59. package/out/scope.d.ts +44 -119
  60. package/out/scope.js +39 -209
  61. package/out/type.d.ts +43 -64
  62. package/out/type.js +30 -131
  63. package/package.json +12 -10
  64. package/__tests__/array.test.ts +0 -272
  65. package/__tests__/astUtils.test.ts +0 -17
  66. package/__tests__/badDefinitionType.test.ts +0 -51
  67. package/__tests__/basis.test.ts +0 -46
  68. package/__tests__/bounds.test.ts +0 -388
  69. package/__tests__/cast.test.ts +0 -32
  70. package/__tests__/completions.test.ts +0 -46
  71. package/__tests__/config.test.ts +0 -168
  72. package/__tests__/cyclic.test.ts +0 -144
  73. package/__tests__/dateLiteral.test.ts +0 -32
  74. package/__tests__/declared.test.ts +0 -123
  75. package/__tests__/discrimination.test.ts +0 -74
  76. package/__tests__/divisor.test.ts +0 -90
  77. package/__tests__/enclosed.test.ts +0 -93
  78. package/__tests__/examples.test.ts +0 -56
  79. package/__tests__/expressions.test.ts +0 -138
  80. package/__tests__/generateBenchData.ts +0 -89
  81. package/__tests__/generated/cyclic.ts +0 -3058
  82. package/__tests__/generic.test.ts +0 -294
  83. package/__tests__/group.test.ts +0 -72
  84. package/__tests__/hkt.test.ts +0 -22
  85. package/__tests__/imports.test.ts +0 -113
  86. package/__tests__/instanceof.test.ts +0 -102
  87. package/__tests__/intersection.test.ts +0 -104
  88. package/__tests__/jsdoc.test.ts +0 -64
  89. package/__tests__/keyTraversal.test.ts +0 -73
  90. package/__tests__/keyof.test.ts +0 -134
  91. package/__tests__/keywords.test.ts +0 -188
  92. package/__tests__/literal.test.ts +0 -51
  93. package/__tests__/match.test.ts +0 -34
  94. package/__tests__/methods.bench.ts +0 -22
  95. package/__tests__/morph.test.ts +0 -409
  96. package/__tests__/narrow.test.ts +0 -102
  97. package/__tests__/nodeDefinitions.test.ts +0 -190
  98. package/__tests__/object.bench.ts +0 -28
  99. package/__tests__/objectLiteral.test.ts +0 -300
  100. package/__tests__/operand.bench.ts +0 -45
  101. package/__tests__/operator.bench.ts +0 -130
  102. package/__tests__/regex.test.ts +0 -58
  103. package/__tests__/scope.bench.ts +0 -39
  104. package/__tests__/scope.test.ts +0 -140
  105. package/__tests__/string.test.ts +0 -48
  106. package/__tests__/submodule.test.ts +0 -99
  107. package/__tests__/this.test.ts +0 -57
  108. package/__tests__/thunk.test.ts +0 -80
  109. package/__tests__/traverse.test.ts +0 -119
  110. package/__tests__/tsGenerics.test.ts +0 -12
  111. package/__tests__/typeMethods.test.ts +0 -69
  112. package/__tests__/typeReference.test.ts +0 -39
  113. package/__tests__/unenclosed.test.ts +0 -120
  114. package/__tests__/union.test.ts +0 -147
  115. package/ark.ts +0 -91
  116. package/main.ts +0 -18
  117. package/match.ts +0 -116
  118. package/out/ark.d.ts.map +0 -1
  119. package/out/ark.js.map +0 -1
  120. package/out/arkConfig.d.ts +0 -2
  121. package/out/arkConfig.d.ts.map +0 -1
  122. package/out/arkConfig.js +0 -10
  123. package/out/arkConfig.js.map +0 -1
  124. package/out/main.d.ts.map +0 -1
  125. package/out/main.js.map +0 -1
  126. package/out/match.d.ts.map +0 -1
  127. package/out/match.js.map +0 -1
  128. package/out/parser/definition.d.ts.map +0 -1
  129. package/out/parser/definition.js.map +0 -1
  130. package/out/parser/generic.d.ts.map +0 -1
  131. package/out/parser/generic.js.map +0 -1
  132. package/out/parser/objectLiteral.d.ts.map +0 -1
  133. package/out/parser/objectLiteral.js.map +0 -1
  134. package/out/parser/semantic/bounds.d.ts.map +0 -1
  135. package/out/parser/semantic/bounds.js.map +0 -1
  136. package/out/parser/semantic/divisor.d.ts.map +0 -1
  137. package/out/parser/semantic/divisor.js.map +0 -1
  138. package/out/parser/semantic/intersections.d.ts +0 -14
  139. package/out/parser/semantic/intersections.d.ts.map +0 -1
  140. package/out/parser/semantic/intersections.js +0 -2
  141. package/out/parser/semantic/intersections.js.map +0 -1
  142. package/out/parser/semantic/semantic.d.ts +0 -33
  143. package/out/parser/semantic/semantic.d.ts.map +0 -1
  144. package/out/parser/semantic/semantic.js +0 -2
  145. package/out/parser/semantic/semantic.js.map +0 -1
  146. package/out/parser/semantic/utils.d.ts.map +0 -1
  147. package/out/parser/semantic/utils.js.map +0 -1
  148. package/out/parser/semantic/validate.d.ts.map +0 -1
  149. package/out/parser/semantic/validate.js.map +0 -1
  150. package/out/parser/shared.d.ts +0 -54
  151. package/out/parser/shared.d.ts.map +0 -1
  152. package/out/parser/shared.js +0 -47
  153. package/out/parser/shared.js.map +0 -1
  154. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  155. package/out/parser/string/reduce/dynamic.js.map +0 -1
  156. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  157. package/out/parser/string/reduce/shared.js.map +0 -1
  158. package/out/parser/string/reduce/static.d.ts.map +0 -1
  159. package/out/parser/string/reduce/static.js.map +0 -1
  160. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  161. package/out/parser/string/shift/operand/date.js.map +0 -1
  162. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  163. package/out/parser/string/shift/operand/enclosed.js.map +0 -1
  164. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  165. package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
  166. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  167. package/out/parser/string/shift/operand/operand.js.map +0 -1
  168. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  169. package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
  170. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  171. package/out/parser/string/shift/operator/bounds.js.map +0 -1
  172. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  173. package/out/parser/string/shift/operator/divisor.js.map +0 -1
  174. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  175. package/out/parser/string/shift/operator/operator.js.map +0 -1
  176. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  177. package/out/parser/string/shift/scanner.js.map +0 -1
  178. package/out/parser/string/string.d.ts.map +0 -1
  179. package/out/parser/string/string.js.map +0 -1
  180. package/out/parser/tuple.d.ts.map +0 -1
  181. package/out/parser/tuple.js.map +0 -1
  182. package/out/scope.d.ts.map +0 -1
  183. package/out/scope.js.map +0 -1
  184. package/out/test.d.ts +0 -2
  185. package/out/test.d.ts.map +0 -1
  186. package/out/test.js +0 -7
  187. package/out/test.js.map +0 -1
  188. package/out/tsconfig.build.tsbuildinfo +0 -1
  189. package/out/type.d.ts.map +0 -1
  190. package/out/type.js.map +0 -1
  191. package/out/util.d.ts +0 -19
  192. package/out/util.d.ts.map +0 -1
  193. package/out/util.js +0 -7
  194. package/out/util.js.map +0 -1
  195. package/parser/definition.ts +0 -159
  196. package/parser/generic.ts +0 -68
  197. package/parser/objectLiteral.ts +0 -197
  198. package/parser/semantic/bounds.ts +0 -61
  199. package/parser/semantic/divisor.ts +0 -13
  200. package/parser/semantic/intersections.ts +0 -46
  201. package/parser/semantic/semantic.ts +0 -144
  202. package/parser/semantic/utils.ts +0 -26
  203. package/parser/semantic/validate.ts +0 -109
  204. package/parser/shared.ts +0 -152
  205. package/parser/string/reduce/dynamic.ts +0 -196
  206. package/parser/string/reduce/shared.ts +0 -101
  207. package/parser/string/reduce/static.ts +0 -298
  208. package/parser/string/shift/operand/date.ts +0 -54
  209. package/parser/string/shift/operand/enclosed.ts +0 -118
  210. package/parser/string/shift/operand/genericArgs.ts +0 -127
  211. package/parser/string/shift/operand/operand.ts +0 -48
  212. package/parser/string/shift/operand/unenclosed.ts +0 -268
  213. package/parser/string/shift/operator/bounds.ts +0 -264
  214. package/parser/string/shift/operator/divisor.ts +0 -36
  215. package/parser/string/shift/operator/operator.ts +0 -82
  216. package/parser/string/shift/scanner.ts +0 -209
  217. package/parser/string/string.ts +0 -90
  218. package/parser/tuple.ts +0 -474
  219. package/scope.ts +0 -574
  220. package/type.ts +0 -347
  221. 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]})`