( ast: SchemaAST.AST, options: Pick<EncodeOptions, "columns" | "headers"> | undefined )
| 979 | // array schemas encode by position. Other schemas, including records with |
| 980 | // index signatures, need explicit columns. |
| 981 | const 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 | |
| 1002 | const encodeSchemaRecords = <S extends Schema.Constraint, IE, Done>( |
| 1003 | schema: S, |
no test coverage detected