@@ -39,6 +39,7 @@ export abstract class BaseRange<
3939 readonly compiledActual : string =
4040 this . boundOperandKind === "value" ? `data`
4141 : this . boundOperandKind === "length" ? `data.length`
42+ : this . boundOperandKind === "size" ? `data.size`
4243 : `data.valueOf()`
4344 readonly comparator : RelativeComparator = compileComparator (
4445 this . kind ,
@@ -166,19 +167,22 @@ const negatedComparators = {
166167export const boundKindPairsByLower : BoundKindPairsByLower = {
167168 min : "max" ,
168169 minLength : "maxLength" ,
169- after : "before"
170+ after : "before" ,
171+ minSize : "maxSize"
170172}
171173
172174type BoundKindPairsByLower = {
173175 min : "max"
174176 minLength : "maxLength"
175177 after : "before"
178+ minSize : "maxSize"
176179}
177180
178181type BoundKindPairsByUpper = {
179182 max : "min"
180183 maxLength : "minLength"
181184 before : "after"
185+ maxSize : "minSize"
182186}
183187
184188export type pairedRangeKind < kind extends RangeKind > =
@@ -198,12 +202,27 @@ export type NumericallyBoundable = string | number | array
198202export type Boundable = NumericallyBoundable | Date
199203
200204export const parseExclusiveKey : keySchemaDefinitions <
201- Declaration < "min" | "max" >
205+ Declaration < "min" | "max" | "minSize" | "maxSize" >
202206> [ "exclusive" ] = {
203207 // omit key with value false since it is the default
204208 parse : ( flag : boolean ) => flag || undefined
205209}
206210
211+ export type SizeBoundKind = "minSize" | "maxSize"
212+
213+ export const writeInvalidSizeBoundMessage = (
214+ kind : SizeBoundKind ,
215+ limit : number
216+ ) : string => `${ kind } bound must be a non-negative integer (was ${ limit } )`
217+
218+ export const createSizeRuleParser =
219+ ( kind : SizeBoundKind ) =>
220+ ( limit : number ) : number => {
221+ if ( ! Number . isSafeInteger ( limit ) || limit < 0 )
222+ throwParseError ( writeInvalidSizeBoundMessage ( kind , limit ) )
223+ return limit
224+ }
225+
207226export const createLengthSchemaNormalizer =
208227 < kind extends "minLength" | "maxLength" > ( kind : kind ) =>
209228 ( schema : NodeSchema < kind > ) : NormalizedSchema < kind > => {
@@ -276,6 +295,8 @@ type OperandKindsByBoundKind = satisfy<
276295 maxLength : "length"
277296 after : "date"
278297 before : "date"
298+ minSize : "size"
299+ maxSize : "size"
279300 }
280301>
281302
@@ -285,7 +306,9 @@ const operandKindsByBoundKind: OperandKindsByBoundKind = {
285306 minLength : "length" ,
286307 maxLength : "length" ,
287308 after : "date" ,
288- before : "date"
309+ before : "date" ,
310+ minSize : "size" ,
311+ maxSize : "size"
289312} as const
290313
291314export const compileComparator = (
@@ -296,7 +319,7 @@ export const compileComparator = (
296319 exclusive ? "" : "="
297320 } ` as const
298321
299- export type BoundOperandKind = "value" | "length" | "date"
322+ export type BoundOperandKind = "value" | "length" | "date" | "size"
300323
301324export type LengthBoundableData = string | array
302325
@@ -308,7 +331,7 @@ export const dateLimitToString = (limit: LimitSchemaValue): string =>
308331export const writeUnboundableMessage = < root extends string > (
309332 root : root
310333) : writeUnboundableMessage < root > =>
311- `Bounded expression ${ root } must be exactly one of number, string, Array, or Date `
334+ `Bounded expression ${ root } must be exactly one of number, string, Array, Date, or File `
312335
313336export type writeUnboundableMessage < root extends string > =
314- `Bounded expression ${root } must be exactly one of number, string, Array, or Date `
337+ `Bounded expression ${root } must be exactly one of number, string, Array, Date, or File `
0 commit comments