( o: dict, pointer: string, ctx: ReadContext )
| 924 | ] |
| 925 | |
| 926 | const readArray = ( |
| 927 | o: dict, |
| 928 | pointer: string, |
| 929 | ctx: ReadContext |
| 930 | ): RootSchema[] => { |
| 931 | const constraints: RootSchema[] = [] |
| 932 | if ( |
| 933 | o.prefixItems !== undefined && |
| 934 | isArray(o.items) && |
| 935 | !ctx.dialectBefore2020 |
| 936 | ) { |
| 937 | return throwParseError( |
| 938 | writeInvalidKeywordMessage( |
| 939 | `${pointer}/items`, |
| 940 | "a schema beside prefixItems", |
| 941 | o.items |
| 942 | ) |
| 943 | ) |
| 944 | } |
| 945 | // draft-07 and 2019-09 list a tuple's elements as items, followed by |
| 946 | // additionalItems, and ignore 2020-12's prefixItems |
| 947 | const elementsKey = isArray(o.items) ? "items" : "prefixItems" |
| 948 | const restKey = elementsKey === "items" ? "additionalItems" : "items" |
| 949 | const [elements, rest] = withChildValue(ctx, () => [ |
| 950 | elementsKey === "prefixItems" && ctx.dialectBefore2020 ? |
| 951 | [] |
| 952 | : readEach( |
| 953 | (o[elementsKey] ?? []) as array, |
| 954 | `${pointer}/${elementsKey}`, |
| 955 | ctx |
| 956 | ), |
| 957 | read(o[restKey] ?? true, `${pointer}/${restKey}`, ctx) |
| 958 | ]) |
| 959 | if (elements.length === 0 && rest.isNever()) |
| 960 | constraints.push({ exactLength: 0 }) |
| 961 | else if (elements.length || !rest.isUnknown()) { |
| 962 | constraints.push({ |
| 963 | sequence: |
| 964 | rest.isNever() ? |
| 965 | { optionals: elements } |
| 966 | : { optionals: elements, variadic: rest } |
| 967 | }) |
| 968 | } |
| 969 | if (o.minItems !== undefined) |
| 970 | constraints.push({ minLength: o.minItems as number }) |
| 971 | if (o.maxItems !== undefined) |
| 972 | constraints.push({ maxLength: o.maxItems as number }) |
| 973 | if (o.uniqueItems === true) { |
| 974 | constraints.push({ |
| 975 | predicate: [ |
| 976 | opaque( |
| 977 | ["uniqueItems"], |
| 978 | "an array of unique items", |
| 979 | hasUniqueItems, |
| 980 | "`uniqueItems` keyword" |
| 981 | ) |
| 982 | ] |
| 983 | }) |
no test coverage detected