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

Function schemaColumns

packages/effect/src/encoding/Csv.ts:981–1000  ·  view source on GitHub ↗
(
  ast: SchemaAST.AST,
  options: Pick<EncodeOptions, "columns" | "headers"> | undefined
)

Source from the content-addressed store, hash-verified

979// array schemas encode by position. Other schemas, including records with
980// index signatures, need explicit columns.
981const schemaColumns = (
982 ast: SchemaAST.AST,
983 options: Pick<EncodeOptions, "columns" | "headers"> | undefined
984): ReadonlyArray<string> | undefined => {
985 if (options?.columns !== undefined) {
986 checkCells(ast, options.columns)
987 return options.columns
988 }
989 if (SchemaAST.isObjects(ast) && ast.indexSignatures.length === 0) {
990 const columns = ast.propertySignatures.flatMap((ps) => typeof ps.name === "string" ? [ps.name] : [])
991 checkCells(ast, columns)
992 return columns
993 }
994 if (SchemaAST.isArrays(ast)) {
995 if (options?.headers === true) throw new Error("Csv: headers for tuple or array schemas require columns")
996 checkCells(ast, undefined)
997 return undefined
998 }
999 throw new Error(`Csv: columns are required to encode ${ast._tag} schemas`)
1000}
1001
1002const encodeSchemaRecords = <S extends Schema.Constraint, IE, Done>(
1003 schema: S,

Callers 1

encodeSchemaRecordsFunction · 0.85

Calls 1

checkCellsFunction · 0.85

Tested by

no test coverage detected