MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeSchemaRecords

Function encodeSchemaRecords

packages/effect/src/encoding/Csv.ts:1002–1033  ·  view source on GitHub ↗
(
  schema: S,
  options: EncodeSchemaOptions<S> | undefined
)

Source from the content-addressed store, hash-verified

1000}
1001
1002const 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

Callers 2

encodeSchemaStringFunction · 0.85
encodeSchemaFunction · 0.85

Calls 7

schemaColumnsFunction · 0.85
encodeRecordsFunction · 0.85
toArrayCodecFunction · 0.85
rebaseIssueFunction · 0.85
toCodecFunction · 0.70
encodeFunction · 0.70
syncMethod · 0.45

Tested by

no test coverage detected