( schema: S, options: EncodeSchemaOptions<S> | undefined )
| 1000 | } |
| 1001 | |
| 1002 | const encodeSchemaRecords = <S extends Schema.Constraint, IE, Done>( |
| 1003 | schema: S, |
| 1004 | options: EncodeSchemaOptions<S> | undefined |
| 1005 | ): Channel.Channel< |
| 1006 | Arr.NonEmptyReadonlyArray<string>, |
| 1007 | IE | Schema.SchemaError, |
| 1008 | Done, |
| 1009 | Arr.NonEmptyReadonlyArray<S["Type"]>, |
| 1010 | IE, |
| 1011 | Done, |
| 1012 | S["EncodingServices"] |
| 1013 | > => { |
| 1014 | const codec = toCodec(schema, options?.disableCodecs) |
| 1015 | const columns = schemaColumns(SchemaAST.toEncoded(codec.ast), options) |
| 1016 | const writer = encodeRecords<S["Encoded"], IE | Schema.SchemaError, Done>({ ...options, columns }) |
| 1017 | const encode = Schema.encodeEffect(toArrayCodec(codec)) |
| 1018 | const firstRecord = options?.headers === true ? 2 : 1 |
| 1019 | const values = Channel.fromTransform(( |
| 1020 | upstream: Pull.Pull<Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done>, |
| 1021 | _scope |
| 1022 | ) => |
| 1023 | Effect.sync(() => { |
| 1024 | let record = firstRecord |
| 1025 | return Effect.flatMap(upstream, (chunk) => { |
| 1026 | const first = record |
| 1027 | record += chunk.length |
| 1028 | return Effect.mapError(encode(chunk), (error) => rebaseIssue(error, (index) => first + index)) |
| 1029 | }) |
| 1030 | }) |
| 1031 | ) |
| 1032 | return Channel.pipeTo(values, writer) |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * Creates a channel that encodes values with a schema and writes them as CSV |
no test coverage detected