|
6 | 6 | type NodeSchema |
7 | 7 | } from "@ark/schema" |
8 | 8 | import { isKeyOf, throwParseError, type KeySet, type Scanner } from "@ark/util" |
9 | | -import type { DateLiteral } from "../../../attributes.ts" |
| 9 | +import type { DateLiteral, LimitLiteral } from "../../../attributes.ts" |
10 | 10 | import type { InferredAst } from "../../ast/infer.ts" |
11 | 11 | import type { astToString } from "../../ast/utils.ts" |
12 | 12 | import type { RootedRuntimeState, RuntimeState } from "../../reduce/dynamic.ts" |
@@ -60,10 +60,7 @@ export type parseBound< |
60 | 60 | > |
61 | 61 | ) ? |
62 | 62 | s["root"] extends ( |
63 | | - InferredAst< |
64 | | - Date | number, |
65 | | - `${infer limit extends number | DateLiteral}` |
66 | | - > |
| 63 | + InferredAst<Date | number, `${infer limit extends LimitLiteral}`> |
67 | 64 | ) ? |
68 | 65 | s.reduceLeftBound<s, limit, comparator, nextUnscanned> |
69 | 66 | : parseRightBound<s.scanTo<s, nextUnscanned>, comparator, $, args> |
@@ -103,7 +100,7 @@ export const writeIncompatibleRangeMessage = ( |
103 | 100 |
|
104 | 101 | export const getBoundKinds = ( |
105 | 102 | comparator: Comparator, |
106 | | - limit: number | DateLiteral, |
| 103 | + limit: LimitLiteral, |
107 | 104 | root: BaseRoot, |
108 | 105 | boundKind: BoundExpressionKind |
109 | 106 | ): BoundKind[] => { |
@@ -140,6 +137,18 @@ export const getBoundKinds = ( |
140 | 137 | : ["before"] |
141 | 138 | ) |
142 | 139 | } |
| 140 | + if (root.extends($ark.intrinsic.File)) { |
| 141 | + if (typeof limit !== "number") { |
| 142 | + return throwParseError( |
| 143 | + writeInvalidLimitMessage(comparator, limit, boundKind) |
| 144 | + ) |
| 145 | + } |
| 146 | + return ( |
| 147 | + comparator === "==" ? ["minSize", "maxSize"] |
| 148 | + : comparator[0] === ">" ? ["minSize"] |
| 149 | + : ["maxSize"] |
| 150 | + ) |
| 151 | + } |
143 | 152 | return throwParseError(writeUnboundableMessage(root.expression)) |
144 | 153 | } |
145 | 154 |
|
@@ -181,7 +190,7 @@ export const parseRightBound = ( |
181 | 190 |
|
182 | 191 | const boundKinds = getBoundKinds( |
183 | 192 | comparator, |
184 | | - typeof limit === "number" ? limit : (limitToken as DateLiteral), |
| 193 | + limit instanceof Date ? (limitToken as DateLiteral) : limit, |
185 | 194 | previousRoot, |
186 | 195 | "right" |
187 | 196 | ) |
@@ -217,7 +226,7 @@ export type parseRightBound< |
217 | 226 | > = |
218 | 227 | parseOperand<s, $, args> extends infer nextState extends StaticState ? |
219 | 228 | nextState["root"] extends ( |
220 | | - InferredAst<unknown, `${infer limit extends number | DateLiteral}`> |
| 229 | + InferredAst<unknown, `${infer limit extends LimitLiteral}`> |
221 | 230 | ) ? |
222 | 231 | s["branches"]["leftBound"] extends {} ? |
223 | 232 | comparator extends MaxComparator ? |
|
0 commit comments