import { type DateRange, type DateRangeInput } from '@dereekb/date'; import { type StringKeyPropertyKeys } from '@dereekb/util'; import { type RootFirestoreModelIdentity } from '../collection/collection'; import { type DocumentReference, type FieldPathOrStringPath, type FieldPathOrStringPathOf } from '../types'; import { type FirestoreQueryConstraint, type OrderByDirection } from './constraint'; /** * Creates constraints to query all child documents under a specific parent document reference. * * This function is designed to be used with a CollectionGroup query to filter results to only * include documents that are descendants of the specified parent. It's useful for hierarchical data * structures where you need to retrieve all documents of a certain type that belong to a specific parent. * * @template P - The parent document data type * @param parentRef - The parent document reference * @returns Array of query constraints to filter by parent document * * @example * // Get all 'comments' documents under a specific 'post' * const postRef = doc(firestore, 'posts', postId); * const query = collectionGroup(firestore, 'comments') * .where(...allChildDocumentsUnderParent(postRef)); */ export declare function allChildDocumentsUnderParent

(parentRef: DocumentReference

): FirestoreQueryConstraint[]; /** * Creates constraints to query all child documents under a specific parent path. * * Similar to allChildDocumentsUnderParent but takes a string path instead of a document reference. * This is useful when you have the path to a parent document but don't need to create a reference. * Uses a range query on document IDs to efficiently filter for descendants. * * @param parentPath - The full path to the parent document (e.g., 'users/123') * @returns Array of query constraints to filter by parent path * * @example * // Get all 'comments' under a specific post without creating a reference * const query = collectionGroup(firestore, 'comments') * .where(...allChildDocumentsUnderParentPath('posts/abc123')); */ export declare function allChildDocumentsUnderParentPath(parentPath: string): FirestoreQueryConstraint[]; /** * Creates constraints to query documents that have a field value starting with a specific prefix. * * Unlike allChildDocumentsUnderParent, this function filters on a field value rather than * the document path. This is useful when you're storing hierarchical references in a field * rather than relying on the document path itself. * * For example, if documents have a 'parentPath' field that contains a string path, you can * filter to find all documents where that field starts with a specific value. * * @template T - The document data type * @param orderByFieldPath - The field path to filter on * @param parentValue - The string value prefix to match * @param sortDirection - Optional direction to sort results (default: 'asc') * @returns Array of query constraints to filter by field value prefix * * @example * // Find all documents where the 'parentPath' field starts with 'organizations/org123/' * const query = collectionGroup(firestore, 'tasks') * .where(...allChildDocumentsUnderRelativePath('parentPath', 'organizations/org123/')); */ export declare function allChildDocumentsUnderRelativePath(orderByFieldPath: StringKeyPropertyKeys, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function allChildDocumentsUnderRelativePath(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates constraints to find documents where a field contains a reference to a specific model type. * * This utility searches for string values that start with a specific model collection type prefix. * It's useful when you're storing references to other models as strings in the format * 'collectionType/id'. * * @template T - The document data type * @param orderByFieldPath - The field containing model references * @param value - The root model identity containing the collection type to search for * @param sortDirection - Optional direction to sort results (default: 'asc') * @returns Array of query constraints to filter by model type * * @example * // Find all documents where the 'reference' field contains a reference to a 'users' model * const query = collection(firestore, 'documents') * .where(...whereStringHasRootIdentityModelKey('reference', { collectionType: 'users' })); */ export declare function whereStringHasRootIdentityModelKey(orderByFieldPath: FieldPathOrStringPathOf | FieldPathOrStringPath, value: RootFirestoreModelIdentity, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates constraints to find documents where a string field starts with a specific prefix. * * This utility creates a range query that efficiently finds all documents where a string * field starts with the specified prefix. This is more efficient than using a LIKE query * since it can utilize Firestore's indexes. * * @template T - The document data type * @param orderByFieldPath - The string field to search * @param parentValue - The prefix to match at the start of the field * @param sortDirection - Optional direction to sort results (default: 'asc') * @returns Array of query constraints to filter by string prefix * * @example * // Find all documents where the 'email' field starts with 'admin@' * const query = collection(firestore, 'users') * .where(...whereStringValueHasPrefix('email', 'admin@')); */ export declare function whereStringValueHasPrefix(orderByFieldPath: StringKeyPropertyKeys, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereStringValueHasPrefix(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates constraints to filter documents by a date field within a specific date range. * * This function creates constraints to find documents where a date field falls within * a specified range. It automatically orders the results by the date field and applies * appropriate filters for the start and end dates. * * @template T - The document data type * @param field - The date field to filter on (stored as ISO string in Firestore) * @param dateRange - The date range to filter by (start and/or end date) * @param sortDirection - Optional direction to sort results (default: 'asc') * @returns Array of query constraints to filter by date range * * @example * // Find documents created in the last 7 days * const lastWeek = { startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) }; * const query = collection(firestore, 'documents') * .where(...filterWithDateRange('createdAt', lastWeek)); */ export declare function filterWithDateRange(field: StringKeyPropertyKeys, dateRange: Partial, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function filterWithDateRange(field: FieldPathOrStringPath, dateRange: Partial, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates constraints to filter documents by a date field within a range specified by flexible input. * * This function accepts various forms of date range inputs (start/end dates, relative ranges, * predefined periods) and converts them to appropriate query constraints. It's more flexible * than filterWithDateRange because it accepts different input formats. * * @template T - The document data type * @param field - The date field to filter on (stored as ISO string in Firestore) * @param rangeInput - Flexible specification of a date range * @param sortDirection - Optional direction to sort results (default: 'asc') * @returns Array of query constraints to filter by date range * * @example * // Find documents from January 2023 * const query = collection(firestore, 'documents') * .where(...whereDateIsInRange('createdAt', { month: 0, year: 2023 })); */ export declare function whereDateIsInRange(field: StringKeyPropertyKeys, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsInRange(field: FieldPathOrStringPath, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates constraints to filter documents where a date field falls within a half-open range `[start, end)`. * * The start date is inclusive and the end date is exclusive. Results are sorted by the * date field in ascending order by default. * * @param field - The date field to filter on (stored as ISO string in Firestore) * @param range - Date range with `start` (inclusive) and `end` (exclusive) boundaries * @param sortDirection - Direction to sort results (default: 'asc') * @returns Array of query constraints for the date range filter and sort */ export declare function whereDateIsBetween(field: StringKeyPropertyKeys, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsBetween(field: FieldPathOrStringPath, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates a constraint to filter documents where a date field is greater than or equal to a specified date. * * This function creates a simple comparison constraint that finds documents where a date field * is on or after a specific date. If no date is provided, it defaults to the current date and time. * * @template T - The document data type * @param field - The date field to filter on (stored as ISO string in Firestore) * @param date - The minimum date to include (default: current date/time) * @returns A query constraint to filter for dates on or after the specified date * * @example * // Find documents created today or in the future * const query = collection(firestore, 'documents') * .where(whereDateIsOnOrAfter('createdAt')); * * // Find documents created on or after a specific date * const startOfYear = new Date(2023, 0, 1); * const query = collection(firestore, 'documents') * .where(whereDateIsOnOrAfter('createdAt', startOfYear)); */ export declare function whereDateIsOnOrAfter(field: StringKeyPropertyKeys, date?: Date): FirestoreQueryConstraint; export declare function whereDateIsOnOrAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint; /** * Creates constraints to filter documents by dates on or after a specified date, with sorting. * * This function combines a date comparison constraint with a sort order, returning an array of * constraints that can be applied to a query. It finds documents where a date field is on or * after a specific date, and sorts the results by that same date field. * * @template T - The document data type * @param field - The date field to filter and sort on (stored as ISO string in Firestore) * @param date - The minimum date to include (default: current date/time) * @param sortDirection - Direction to sort results (default: 'asc') * @returns Array of query constraints for filtering and sorting * * @example * // Find documents created today or in the future, sorted newest first * const query = collection(firestore, 'documents') * .where(...whereDateIsOnOrAfterWithSort('createdAt', new Date(), 'desc')); */ export declare function whereDateIsOnOrAfterWithSort(field: StringKeyPropertyKeys, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsOnOrAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates a constraint to filter documents where a date field is less than or equal to a specified date. * * If no date is provided, defaults to the current date and time (`new Date()`). * * @param field - The date field to filter on (stored as ISO string in Firestore) * @param date - The maximum date to include (default: current date/time) * @returns A query constraint for dates on or before the specified date */ export declare function whereDateIsOnOrBefore(field: StringKeyPropertyKeys, date?: Date): FirestoreQueryConstraint; export declare function whereDateIsOnOrBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint; /** * Creates constraints to filter documents where a date field is on or before a specified date, with sorting. * * Combines a `<=` date comparison with an `orderBy` on the same field. * Sorts in descending order by default (most recent first). * If no date is provided, defaults to the current date and time. * * @param field - The date field to filter and sort on (stored as ISO string in Firestore) * @param date - The maximum date to include (default: current date/time) * @param sortDirection - Direction to sort results (default: 'desc') * @returns Array of query constraints for filtering and sorting */ export declare function whereDateIsOnOrBeforeWithSort(field: StringKeyPropertyKeys, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsOnOrBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates a constraint to filter documents where a date field is strictly after a specified date. * * Uses a `>` comparison (exclusive). If no date is provided, defaults to the current date and time. * * @param field - The date field to filter on (stored as ISO string in Firestore) * @param date - The exclusive lower bound date (default: current date/time) * @returns A query constraint for dates strictly after the specified date */ export declare function whereDateIsAfter(field: StringKeyPropertyKeys, date?: Date): FirestoreQueryConstraint; export declare function whereDateIsAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint; /** * Creates constraints to filter documents where a date field is strictly after a specified date, with sorting. * * Combines a `>` date comparison with an `orderBy` on the same field. * Sorts in ascending order by default. If no date is provided, defaults to the current date and time. * * @param field - The date field to filter and sort on (stored as ISO string in Firestore) * @param date - The exclusive lower bound date (default: current date/time) * @param sortDirection - Direction to sort results (default: 'asc') * @returns Array of query constraints for filtering and sorting */ export declare function whereDateIsAfterWithSort(field: StringKeyPropertyKeys, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; /** * Creates a constraint to filter documents where a date field is strictly before a specified date. * * Uses a `<` comparison (exclusive). If no date is provided, defaults to the current date and time. * * @param field - The date field to filter on (stored as ISO string in Firestore) * @param date - The exclusive upper bound date (default: current date/time) * @returns A query constraint for dates strictly before the specified date */ export declare function whereDateIsBefore(field: StringKeyPropertyKeys, date?: Date): FirestoreQueryConstraint; export declare function whereDateIsBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint; /** * Creates constraints to filter documents where a date field is strictly before a specified date, with sorting. * * Combines a `<` date comparison with an `orderBy` on the same field. * Sorts in descending order by default (most recent first). * If no date is provided, defaults to the current date and time. * * @param field - The date field to filter and sort on (stored as ISO string in Firestore) * @param date - The exclusive upper bound date (default: current date/time) * @param sortDirection - Direction to sort results (default: 'desc') * @returns Array of query constraints for filtering and sorting */ export declare function whereDateIsBeforeWithSort(field: StringKeyPropertyKeys, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[]; export declare function whereDateIsBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];