( columns: Record<string, any>, refinements: Record<string, any>, conditions: Conditions, )
| 12 | } |
| 13 | |
| 14 | function handleColumns( |
| 15 | columns: Record<string, any>, |
| 16 | refinements: Record<string, any>, |
| 17 | conditions: Conditions, |
| 18 | ): v.GenericSchema { |
| 19 | const columnSchemas: Record<string, v.GenericSchema> = {}; |
| 20 | |
| 21 | for (const [key, selected] of Object.entries(columns)) { |
| 22 | if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === 'object') { |
| 23 | const columns = isTable(selected) || isView(selected) ? getColumns(selected) : selected; |
| 24 | columnSchemas[key] = handleColumns(columns, refinements[key] ?? {}, conditions); |
| 25 | continue; |
| 26 | } |
| 27 | |
| 28 | const refinement = refinements[key]; |
| 29 | if (refinement !== undefined && typeof refinement !== 'function') { |
| 30 | columnSchemas[key] = refinement; |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | const column = is(selected, Column) ? selected : undefined; |
| 35 | const schema = column ? columnToSchema(column) : v.any(); |
| 36 | const refined = typeof refinement === 'function' ? refinement(schema) : schema; |
| 37 | |
| 38 | if (conditions.never(column)) { |
| 39 | continue; |
| 40 | } else { |
| 41 | columnSchemas[key] = refined; |
| 42 | } |
| 43 | |
| 44 | if (column) { |
| 45 | if (conditions.nullable(column)) { |
| 46 | columnSchemas[key] = v.nullable(columnSchemas[key]!); |
| 47 | } |
| 48 | |
| 49 | if (conditions.optional(column)) { |
| 50 | columnSchemas[key] = v.optional(columnSchemas[key]!); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return v.object(columnSchemas) as any; |
| 56 | } |
| 57 | |
| 58 | export const createSelectSchema: CreateSelectSchema = ( |
| 59 | entity: Table | View | PgEnum<[string, ...string[]]>, |
no test coverage detected