import type { M } from "ts-algebra"; import type { JSONSchema } from "../definitions"; import type { And, DoesExtend, Not, Tail } from "../type-utils"; import type { ParseSchema, ParseSchemaOptions } from "./index"; export type ArrayOrTupleSchema = JSONSchema & Readonly<{ type: "array"; }>; export type ArraySchema = Omit & Readonly<{ type: "array"; items: JSONSchema; }>; export type TupleSchema = JSONSchema & Readonly<{ type: "array"; items: readonly JSONSchema[]; }>; export type ParseArrayOrTupleSchema = ARRAY_OR_TUPLE_SCHEMA extends ArraySchema ? M.$Array> : ARRAY_OR_TUPLE_SCHEMA extends TupleSchema ? M.$Union, ARRAY_OR_TUPLE_SCHEMA, OPTIONS>> : M.$Array; type ParseTupleItems = ITEM_SCHEMAS extends readonly [ infer ITEM_SCHEMAS_HEAD, ...infer ITEM_SCHEMAS_TAIL ] ? ITEM_SCHEMAS_HEAD extends JSONSchema ? ITEM_SCHEMAS_TAIL extends readonly JSONSchema[] ? [ ParseSchema, ...ParseTupleItems ] : never : never : []; type ApplyMinMaxAndAdditionalItems = ApplyAdditionalItems ? ROOT_SCHEMA["minItems"] : 0, ROOT_SCHEMA extends Readonly<{ maxItems: number; }> ? ROOT_SCHEMA["maxItems"] : undefined>, ROOT_SCHEMA extends Readonly<{ additionalItems: JSONSchema; }> ? ROOT_SCHEMA["additionalItems"] : true, OPTIONS>; type ApplyMinMax = And>, DoesExtend> extends true ? RECURSED_PARSED_ITEM_SCHEMAS extends [ ...infer RECURSED_PARSED_ITEM_SCHEMAS_BODY, unknown ] ? ApplyMinMax : RESULT | M.$Tuple, HAS_ENCOUNTERED_MIN extends true ? true : DoesExtend, HAS_ENCOUNTERED_MAX extends true ? true : DoesExtend, INITIAL_PARSED_ITEM_SCHEMAS> : never : { result: MAX extends undefined ? RESULT | M.$Tuple : HAS_ENCOUNTERED_MAX extends true ? RESULT | M.$Tuple : MAX extends RECURSED_PARSED_ITEM_SCHEMAS["length"] ? M.$Tuple : IsLongerThan, MAX> extends true ? never : RESULT | M.$Tuple; hasEncounteredMin: DoesExtend; hasEncounteredMax: HAS_ENCOUNTERED_MAX extends true ? true : MAX extends RECURSED_PARSED_ITEM_SCHEMAS["length"] ? true : IsLongerThan, MAX>; completeTuple: INITIAL_PARSED_ITEM_SCHEMAS; }; type IsLongerThan = LENGTH extends undefined ? false : TUPLE["length"] extends LENGTH ? true : TUPLE extends [any, ...infer TUPLE_TAIL] ? IsLongerThan : RESULT; type ApplyAdditionalItems = APPLY_MIN_MAX_RESULT extends { hasEncounteredMax: true; } ? APPLY_MIN_MAX_RESULT extends { hasEncounteredMin: true; } ? APPLY_MIN_MAX_RESULT["result"] : M.Never : ADDITIONAL_ITEMS_SCHEMA extends false ? APPLY_MIN_MAX_RESULT extends { hasEncounteredMin: true; } ? APPLY_MIN_MAX_RESULT["result"] : M.Never : ADDITIONAL_ITEMS_SCHEMA extends true ? APPLY_MIN_MAX_RESULT extends { hasEncounteredMin: true; } ? APPLY_MIN_MAX_RESULT["result"] | M.$Tuple : M.$Tuple : APPLY_MIN_MAX_RESULT extends { hasEncounteredMin: true; } ? APPLY_MIN_MAX_RESULT["result"] | M.$Tuple> : M.$Tuple>; export {};