import { CoreSchema } from "../schema/core.js"; import { IfAny, UnpackList } from "./utils.js"; //#region src/types/schema.d.ts /** * Get all available top level Item types from a given Schema */ type ItemType = Schema[keyof Schema] | { [K in keyof Schema]: Schema[K] extends any[] ? Schema[K][number] : never }[keyof Schema]; /** * Return singular collection type */ type CollectionType = IfAny extends object ? UnpackList : never : never>; /** * Returns a list of singleton collections in the schema */ type SingletonCollections = { [Key in keyof Schema]: Schema[Key] extends any[] ? never : Key }[keyof Schema]; /** * Returns a list of regular collections in the schema */ type RegularCollections = IfAny>>; /** * Return string keys of all Primitive fields in the given schema Item */ type PrimitiveFields = { [Key in keyof Item$1]: Extract> extends never ? Key : never }[keyof Item$1]; /** * Return string keys of all Relational fields in the given schema Item */ type RelationalFields = { [Key in keyof Item$1]: Extract> extends never ? never : Key }[keyof Item$1]; /** * Remove the related Item types from relational m2o/a2o fields */ type RemoveRelationships = { [Key in keyof Item$1]: Exclude> }; /** * Merge a core collection from the schema with the builtin schema */ type MergeCoreCollection = IfAny extends infer Item ? { [Field in Exclude]: Item[Field] } & BuiltinCollection : never : BuiltinCollection>; /** * Merge custom and core schema objects */ type CompleteSchema = CoreSchema extends infer Core ? { [Collection in keyof Schema | keyof Core]: Collection extends keyof Core ? Core[Collection] : Collection extends keyof Schema ? Schema[Collection] : never } : never; /** * Merge custom schema with core schema */ type AllCollections = RegularCollections | RegularCollections>; /** * Helper to extract a collection with fallback to defaults */ type GetCollection> = CollectionName extends keyof CoreSchema ? CoreSchema[CollectionName] : CollectionName extends keyof Schema ? Schema[CollectionName] : never; /** * Helper to extract a collection name */ type GetCollectionName> = { [K in keyof FullSchema]: UnpackList extends Collection$1 ? K : never }[keyof FullSchema]; //#endregion export { AllCollections, CollectionType, CompleteSchema, GetCollection, GetCollectionName, ItemType, MergeCoreCollection, PrimitiveFields, RegularCollections, RelationalFields, RemoveRelationships, SingletonCollections }; //# sourceMappingURL=schema.d.ts.map