import { type ArrayOrValue, type FactoryWithRequiredInput, type IdBatchVerifier, type PrimativeKey, type ReadMultipleKeysFunction } from '@dereekb/util'; import { type FirestoreCollectionLike } from '../collection'; import { type FirestoreQueryConstraint } from '../query/constraint'; import { type DocumentSnapshot } from '../types'; /** * Base configuration for creating a Firestore-backed {@link IdBatchVerifier}. * * @template T - The Firestore document data type * @template I - The identifier/key type (must be a primitive key) */ export type FirestoreIdBatchVerifierFactoryBaseConfig = { /** * Extracts the identifier(s) from a queried document snapshot. * Used to determine which keys from a batch already exist in Firestore. */ readKeys: ReadMultipleKeysFunction, I>; }; /** * Configuration that queries a specific document field for existence checks. * Use `'_id'` as the field value to query by document ID instead of a data field. * * @template T - The Firestore document data type * @template I - The identifier/key type */ export type FirestoreIdBatchVerifierFactoryFieldsQueryConfig = FirestoreIdBatchVerifierFactoryBaseConfig & { /** * The document field to query with an `in` filter, or `'_id'` to query by document ID. */ fieldToQuery: keyof T | '_id'; }; /** * Configuration that provides custom query constraints for existence checks. * * @template T - The Firestore document data type * @template I - The identifier/key type */ export type FirestoreIdBatchVerifierFactoryMakeQueryConfig = FirestoreIdBatchVerifierFactoryBaseConfig & { /** * Creates query constraints to find documents matching the given keys. */ makeQueryConstraints: FactoryWithRequiredInput, I[]>; }; /** * Union config type: either specify a field to query or provide custom query constraints. */ export type FirestoreIdBatchVerifierFactoryConfig = FirestoreIdBatchVerifierFactoryMakeQueryConfig | FirestoreIdBatchVerifierFactoryFieldsQueryConfig; /** * Factory that creates an {@link IdBatchVerifier} bound to a specific Firestore collection. * * @template T - The Firestore document data type * @template I - The identifier/key type */ export type FirestoreIdBatchVerifierFactory = FactoryWithRequiredInput, FirestoreCollectionLike>; /** * Creates a factory for Firestore-backed {@link IdBatchVerifier} instances. * * The verifier checks which keys from a batch do **not** already exist in a Firestore * collection, respecting Firestore's `where('in')` limit of {@link FIRESTORE_MAX_WHERE_IN_FILTER_ARGS_COUNT} * items per query. This is used for batch ID generation to ensure uniqueness. * * @template T - The Firestore document data type * @template I - The identifier/key type * @param config - Specifies how to query for existing keys (by field or custom constraints) * @returns A factory that produces verifiers bound to a specific collection * * @example * ```ts * const factory = firestoreIdBatchVerifierFactory({ * fieldToQuery: '_id', * readKeys: (snapshot) => [snapshot.id] * }); * * const verifier = factory(myCollection); * // verifier can now check batches of IDs for uniqueness * ``` */ export declare function firestoreIdBatchVerifierFactory(config: FirestoreIdBatchVerifierFactoryConfig): FirestoreIdBatchVerifierFactory;