UNPKG

from-schema

Version:

Infer TypeScript types from JSON schemas

21 lines (19 loc) 1.35 kB
import { SchemaBase } from '../generic'; import { FromPostgresPropertySchemas } from './FromPostgresPropertySchemas'; import { PostgresColumnModel } from './PostgresColumnModel'; import { RequiredPropOf } from './RequiredPropOf'; export type PostgresRecordModelWithoutRequired = SchemaBase & { readonly properties: Record<string, PostgresColumnModel>; readonly minProperties?: number; readonly maxProperties?: number; readonly default?: Record<string, unknown>; readonly examples?: Record<string, unknown>[]; readonly additionalProperties?: false | PostgresColumnModel; }; export type PostgresRecordModelWithRequired = PostgresRecordModelWithoutRequired & { readonly required: readonly string[]; }; export type PostgresRecordModel = PostgresRecordModelWithoutRequired | PostgresRecordModelWithRequired; export type OnlyRequiredPostgres<T extends PostgresRecordModel> = T extends PostgresRecordModelWithRequired ? Required<Pick<FromPostgresPropertySchemas<T>, RequiredPropOf<T>>> : Record<string, never>; export type OnlyOptionalPostgres<T extends PostgresRecordModel> = T extends PostgresRecordModelWithRequired ? Partial<Omit<FromPostgresPropertySchemas<T>, RequiredPropOf<T>>> : Record<string, never>; export type FromPostgresRecordModel<S extends PostgresRecordModel> = OnlyRequiredPostgres<S> & OnlyOptionalPostgres<S>;