import { Collection } from "./collections/Collection.js"; import { Field } from "./fields/Field.js"; export type FieldRuleReference = { field: "this" | string; collectionRef?: string; }; export type Operators = "<" | "<=" | "==" | ">" | ">=" | "!=" | "array-contains" | "array-contains-any" | "in" | "not-in" | "is"; export type RuleCondition = [FieldRuleReference | string, Operators, FieldRuleReference | string]; export type Rule = { type: "and" | "or" | "not"; conditions: (Rule | RuleCondition | string | undefined | null)[]; }; export type RuleStringConditions = { type: "and" | "or" | "not"; conditions: (RuleStringConditions | string | undefined | null)[]; }; export type BuildResult = (string | BuildResult)[]; export type CollectionType>, COLLECTIONS extends Collection[], T = Collection> = { fields: InferFields; f: InferFields; collections: CollectionObjectType; c: CollectionObjectType; }; /** * Expands a given type by resolving its structure one level deep. * * TypeScript often leaves generics unevaluated in error messages, making it * difficult to see the full structure of a type. Wrapping a type with `Expand` * forces TypeScript to compute and display the expanded shape of the type, * improving readability in error messages and tooltips. * * @template T - The type to expand. * @returns A new type where all properties of `T` are resolved to their original values. * * @example * type OriginalType = { ABC: string; DEF: number; }; * type ExpandedType = Expand; * // ExpandedType will resolve to: { ABC: string; DEF: number; } */ type Expand = T extends infer O ? { [K in keyof O]: O[K]; } : never; export type InferFields>> = Expand<{ [K in keyof FIELDS]: FIELDS[K] extends ValidationFunction ? (DATA extends Record> ? InferFields : DATA) : never; }>; export type ConvertToOptional> = { [K in keyof FIELDS]-?: undefined extends FIELDS[K] ? FIELDS[K] : FIELDS[K]; }; export type CollectionArray = Collection[]; export type CollectionObjectType = { [K in T[number] as K["name"]]: CollectionType; }; export type RequiredValidationFunction = (resourcePath: string, field: Field, currentFieldName?: string) => RuleStringConditions; export type OptionalValidationFunction = { isOptional: true; func: RequiredValidationFunction; }; export type ValidationFunction = RequiredValidationFunction | OptionalValidationFunction; export {};