import type { TypesaurusCore as Core } from "./core.js"; import { TypesaurusShared as Shared } from "./shared.js"; import type { TypesaurusUtils as Utils } from "./utils.js"; export declare const groups: TypesaurusGroups.Function; export declare namespace TypesaurusGroups { interface Function { >(db: DB): DB extends Core.DB ? Groups : never; } interface Group extends Core.CollectionAPI { /** The group type */ type: "group"; /** The group name */ name: string; /** * The function narrows the type to shared group type. Unlike regular * group, shared group lacks methods which type-safety depends on * knowing the full type of the model: `set`, `upset`, and `as`. The `ref` * is also limited. * * When models don't match, it resolves `unknown`. */ as: Shared.GroupAs; } /** * The type flattens the schema and generates groups from nested and * root collections. */ type Groups = /** * {@link ConstructGroups} here plays a role of merger, each level of nesting * returns respective collections and the type creates an object from those, * inferring the Model (`PostComment | UpdateComment`). */ ConstructGroups, GroupsLevel2, GroupsLevel3, GroupsLevel4, GroupsLevel5, GroupsLevel6, GroupsLevel7, GroupsLevel8, GroupsLevel9, GroupsLevel10>; /** * The type merges extracted collections into groups. */ type ConstructGroups = Schema1 | Schema2 | Schema3 | Schema4 | Schema5 | Schema6 | Schema7 | Schema8 | Schema9 | Schema10 extends infer Schema ? { [Key in Utils.UnionKeys]: Group ? Def : never>; } : never; type GroupsLevel1 = { [Name in Utils.UnionKeys as Schema[Name] extends Core.NestedPlainCollection | Core.PlainCollection ? CustomName extends string ? CustomName : Name : never]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? Core.CollectionDef : Schema[Name] extends Core.PlainCollection ? Core.CollectionDef : never : never; }; type GroupsLevel2 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel1> : never : never; }[keyof Schema]; type GroupsLevel3 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel2> : never : never; }[keyof Schema]; type GroupsLevel4 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel3> : never : never; }[keyof Schema]; type GroupsLevel5 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel4> : never : never; }[keyof Schema]; type GroupsLevel6 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel5> : never : never; }[keyof Schema]; type GroupsLevel7 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel6> : never : never; }[keyof Schema]; type GroupsLevel8 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel7> : never : never; }[keyof Schema]; type GroupsLevel9 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel8> : never : never; }[keyof Schema]; type GroupsLevel10 = { [Name in keyof Schema]: Name extends string ? Schema[Name] extends Core.NestedPlainCollection ? GroupsLevel9> : never : never; }[keyof Schema]; }