import { ARRAY } from "../../array"; import { BooleanType } from "../../boolean"; import { DateType } from "../../date"; import { IntegerType, NumberType } from "../../number"; import { DICTIONARY, KnownRecord, RECORD, RecordType } from "../../record"; import { StringType } from "../../string"; export type PrimitiveNameOf = T extends Boolean ? BooleanType : T extends Date ? DateType : T extends BigInt ? IntegerType : T extends Number ? NumberType : T extends String ? StringType : RecordType; type FieldsOf = typeof RECORD | [string, typeof RECORD] | FieldMap; type ArrayOf = U extends KnownRecord ? | [FieldMap | typeof RECORD, typeof ARRAY] | [string, typeof RECORD, typeof ARRAY] : [PrimitiveNameOf, typeof ARRAY]; type DictionaryOf = V extends KnownRecord ? | typeof RECORD | [string, typeof RECORD, typeof DICTIONARY, StringType?] | [typeof RECORD, typeof DICTIONARY, StringType?] | [FieldMap, typeof DICTIONARY, StringType?] // [model name, , , key type] : [PrimitiveNameOf, typeof DICTIONARY, StringType?]; // [type, , key type] export type TypeOf = T extends Array ? ArrayOf : T extends Record ? DictionaryOf // [type, , key type] : T extends KnownRecord ? FieldsOf : PrimitiveNameOf; export interface FieldModel { default?: T; name: string; type: TypeOf; } export type FieldDescriptor = Omit, "name">; export type FieldMap = { [P in keyof T]: FieldDescriptor; };