// tracing: off import { pipe } from "@effect-ts/core/Function" import * as S from "../_schema.js" import * as Arbitrary from "../Arbitrary.js" import * as Encoder from "../Encoder.js" import * as Guard from "../Guard.js" import * as Th from "../These.js" import { chunk } from "./chunk.js" import type { DefaultSchema } from "./withDefaults.js" import { withDefaults } from "./withDefaults.js" export const arrayIdentifier = S.makeAnnotation<{ self: S.SchemaUPI }>() export function array( self: S.Schema ): DefaultSchema< unknown, readonly ParsedShape[], readonly ParsedShape[], readonly Encoded[], { self: Api } > { const guardSelf = Guard.for(self) const arbitrarySelf = Arbitrary.for(self) const encodeSelf = Encoder.for(self) const fromChunk = pipe( S.identity( (u): u is readonly ParsedShape[] => Array.isArray(u) && u.every(guardSelf) ), S.parser((u: Chunk) => Th.succeed(u.toArray as readonly ParsedShape[])), S.encoder((u): Chunk => Chunk.fromIterable(u)), S.arbitrary(_ => _.array(arbitrarySelf(_))) ) return pipe( chunk(self)[">>>"](fromChunk), S.mapParserError(_ => ((_ as any).errors as Chunk).unsafeHead.error), S.constructor((_: readonly ParsedShape[]) => Th.succeed(_)), S.encoder(u => u.map(encodeSelf)), S.mapApi(() => ({ self: self.Api })), withDefaults, S.annotate(arrayIdentifier, { self }) ) }