/** * @module snapshot.field * * Provides pre-built Firestore field mapping configurations for converting between application model types and * their Firestore-stored representations. Each field converter is a factory function that returns a * {@link FirestoreModelFieldMapFunctionsConfig}, which plugs into the snapshot converter system * (see {@link snapshotConverterFunctions} in `snapshot.ts`). * * ## Pattern * * Every field type has a required variant (e.g., `firestoreString()`) and an optional variant * (e.g., `optionalFirestoreString()`). Required variants provide a default value when the field * is missing from Firestore; optional variants return `null`/`undefined`. * * ## Storage Optimization * * Optional fields support `dontStoreIf` / `dontStoreValueIf` to skip storing values that match a * condition (e.g., don't store `false` booleans or empty arrays). This reduces Firestore document * size and read costs. The value is still returned correctly on read via `defaultReadValue`. * * ## Available Field Types * * - **Primitives**: `firestoreString`, `firestoreNumber`, `firestoreBoolean`, `firestoreEnum` * - **Dates**: `firestoreDate` (ISO8601), `firestoreDateNumber` (unix seconds) * - **Arrays**: `firestoreArray`, `firestoreUniqueArray`, `firestoreEnumArray`, `firestoreEncodedArray` * - **Maps**: `firestoreMap`, `firestoreEncodedObjectMap`, `firestoreArrayMap` * - **Objects**: `firestoreSubObject`, `firestoreObjectArray` * - **Specialized**: `firestoreUID`, `firestoreLatLngString`, `firestoreWebsiteLink`, * `firestoreDateCellRange`, `firestoreBitwiseSet`, `firestoreUnitedStatesAddress` */ import { type WebsiteLink, type GrantedRole, type WebsiteFileLink } from '@dereekb/model'; import { type DateCellRange, type DateCellSchedule } from '@dereekb/date'; import { type ModelFieldMapFunctionsConfig, type GetterOrValue, type Maybe, type ModelFieldMapConvertFunction, type PrimativeKey, type ReadKeyFunction, type ModelFieldMapFunctionsWithDefaultsConfig, type FilterUniqueStringsTransformConfig, type MapFunction, type FilterKeyValueTuplesInput, type ModelKey, type ToModelMapFunctionsInput, type ModelMapFunctionsRef, type LatLngPrecision, type LatLngString, type TimezoneString, type PrimativeKeyStringDencoderFunction, type PrimativeKeyDencoderFunction, type UnitedStatesAddress, type ZoomLevel, type FilterUniqueFunction, type BitwiseEncodedSet, type BitwiseObjectDencoder, type SortCompareFunctionRef, type TransformNumberFunctionConfigInput, type TransformStringFunctionConfigInput, type DecisionFunction, type ISO8601DateString, type FilterFunction } from '@dereekb/util'; import { type FirestoreModelData } from './snapshot.type'; /** * Base configuration for Firestore field mapping. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export interface BaseFirestoreFieldConfig { /** * Function to convert from Firestore data (D) to model value (V) */ fromData: ModelFieldMapConvertFunction; /** * Function to convert from model value (V) to Firestore data (D) */ toData: ModelFieldMapConvertFunction; /** * Optional default value to use before saving if the value is null/undefined */ defaultBeforeSave?: GetterOrValue; } /** * Default value for firestoreField(). */ export interface FirestoreFieldDefault { /** * Default value to retrieve when a null/undefined value is encountered. * * Input objects that are passed without a Getter are transformed into an ObjectCopyFactory, so copies are already returned. */ default: GetterOrValue; } /** * Default Data value for firestoreField(). */ export interface FirestoreFieldDefaultData { /** * Default value to apply when a null/undefined value is encountered. * * Input objects that are passed without a Getter are transformed into an ObjectCopyFactory, so copies are already returned. */ defaultData: GetterOrValue; } /** * Configuration for Firestore field with a default value for the model. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export interface FirestoreFieldConfigWithDefault extends BaseFirestoreFieldConfig, FirestoreFieldDefault { } /** * Configuration for Firestore field with a default value for the Firestore data. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export interface FirestoreFieldConfigWithDefaultData extends BaseFirestoreFieldConfig, FirestoreFieldDefaultData { } /** * Configuration for Firestore field that can have either a default value for the model * or a default value for the Firestore data. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type FirestoreFieldConfig = FirestoreFieldConfigWithDefault | FirestoreFieldConfigWithDefaultData; /** * The standard field mapping config type used by all Firestore field converters. * * The read side accepts `Maybe` (nullable) because Firestore documents are schemaless — any field * can be missing or null. This design ensures the system gracefully handles incomplete documents. * * @template V - Value type in the application model * @template D - Data type in Firestore */ export type FirestoreModelFieldMapFunctionsConfig = ModelFieldMapFunctionsWithDefaultsConfig>; /** * Creates a Firestore field mapping configuration. * * This is the low-level building block that all other field converters (e.g., {@link firestoreString}, * {@link firestoreDate}) delegate to. It generates `from`/`to` mapping functions that handle defaults * and conversions in both directions. * * Use the higher-level field converters for common types; use this directly only when you need a * custom conversion not covered by the built-in converters. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) * @param config - Configuration for the Firestore field * @returns A configured mapping between model and Firestore data * * @example * ```ts * // Custom field that stores a Set as a comma-separated string * const tagsField = firestoreField, string>({ * default: () => new Set(), * fromData: (csv) => new Set(csv.split(',')), * toData: (set) => [...set].join(',') * }); * ``` */ export declare function firestoreField(config: FirestoreFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * A pre-built passthrough field mapping that stores and reads values unchanged. * * Defaults to `null` when the field is missing. Used internally by {@link firestorePassThroughField} * and as a fallback for {@link optionalFirestoreField} when no config is provided. */ export declare const FIRESTORE_PASSTHROUGH_FIELD: FirestoreModelFieldMapFunctionsConfig; /** * Creates a pass-through field mapping configuration that doesn't transform the data. * * This is useful when the model field and Firestore field are the same type and * no transformation is needed in either direction. * * @template T - Type for both the model field and Firestore field * @returns A field mapping configuration that passes values through unchanged */ export declare function firestorePassThroughField(): ModelFieldMapFunctionsConfig; /** * Configuration for optional Firestore fields with conditional storage. * * Enables storage optimization by skipping fields that match a "don't store" condition. * This reduces Firestore document size and cost. The field is still read correctly because * `defaultReadValue` provides the expected value when the field is absent from the document. * * The optimization flow: * 1. On write: if the value matches `dontStoreValueIf` (pre-transform) or `dontStoreIf` (post-transform), store `null` instead * 2. On read: if the stored value is `null`/`undefined`, return `defaultReadValue` (if configured) before transforming * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore */ export interface OptionalFirestoreFieldConfig { /** * Removes the value from the object if the decision returns true. * * This check occurs **before** the value is transformed to Firestore data format. * Can be a specific value (compared with `===`) or a decision function. */ readonly dontStoreValueIf?: V | DecisionFunction; /** * Removes the value from the object if the decision returns true. * * This check occurs **after** the value is transformed to Firestore data format. * Can be a specific value (compared with `===`) or a decision function. */ readonly dontStoreIf?: D | DecisionFunction; /** * Default data value to return when the field is missing from the Firestore document. * * Pairs with `dontStoreIf`/`dontStoreValueIf` to enable storage optimization: don't store the value, * but return this default on read so the application sees the expected value. * * If using a getter, the getter is invoked each time to ensure fresh copies. */ readonly defaultReadValue?: GetterOrValue; } /** * Configuration for optional Firestore fields with the same type for model and Firestore. * * @template T - Type for both the model field and Firestore field */ export interface OptionalOneTypeFirestoreFieldConfig extends OptionalFirestoreFieldConfig { /** * Defaults the dontStoreIfValue value to this value. * * This is ignored if defaultReadValue is not set or if dontStoreIf is provided. */ readonly dontStoreDefaultReadValue?: boolean; } /** * Configuration for optional Firestore fields with different types and transformations. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore */ export interface OptionalFirestoreFieldConfigWithTwoTypeTransform extends OptionalFirestoreFieldConfig { /** * (Optional) Function to transform the data after it is read from Firestore. * * Only transforms non-null/undefined values from the database. * * Overrides transformData. */ readonly transformFromData?: MapFunction; /** * (Optional) Transform function that is only used before the data is stored to Firestore. * * Is allowed to return null to clear the stored value. * * Overrides transformData. */ readonly transformToData?: MapFunction; } /** * Configuration for optional Firestore fields with single type and transformation function. * * @template T - Type for both the model field and Firestore field */ export interface OptionalFirestoreFieldConfigWithOneTypeTransform extends OptionalFirestoreFieldConfigWithTwoTypeTransform, OptionalOneTypeFirestoreFieldConfig { /** * (Optional) Function to transform the data before it is stored and after it is read. * * This is used as the default for transformToData, and transformToData. */ readonly transformData?: MapFunction; } /** * Creates a field mapping configuration for optional Firestore fields. * * Optional fields store `null` in Firestore when absent and return `null`/`undefined` to the application. * Supports conditional storage via `dontStoreIf`/`dontStoreValueIf` to reduce document size. * * When no config is provided, returns a passthrough field that stores/reads values unchanged. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore * @param config - Configuration for the optional Firestore field * @returns A field mapping configuration for optional values * * @example * ```ts * // Optional boolean that isn't stored when false (saves document space) * const isAdminField = optionalFirestoreField({ * dontStoreIf: false, * defaultReadValue: false * }); * * // Optional date with transformation * const deletedAtField = optionalFirestoreField({ * transformFromData: toJsDate, * transformToData: toISODateString * }); * ``` */ export declare function optionalFirestoreField(config?: OptionalFirestoreFieldConfigWithTwoTypeTransform): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Creates a field mapping configuration for optional Firestore fields with same type. * * Handles transformation and conditional storage of values of the same type. * * @template T - Type for both the model field and Firestore field * @param config - Configuration for the optional Firestore field * @returns A field mapping configuration for optional values */ export declare function optionalFirestoreField(config?: OptionalFirestoreFieldConfigWithOneTypeTransform): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore field with default model value but without conversion functions. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type MapConfiguredFirestoreFieldConfigWithDefault = Omit, 'fromData' | 'toData'>; /** * Configuration for a Firestore field with default data value but without conversion functions. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type MapConfiguredFirestoreFieldConfigWithDefaultData = Omit, 'fromData' | 'toData'>; /** * Configuration for a Firestore field with default values but without conversion functions. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type MapConfiguredFirestoreFieldConfig = MapConfiguredFirestoreFieldConfigWithDefault | MapConfiguredFirestoreFieldConfigWithDefaultData; /** * Configuration for a Firestore field with optional default model value but without conversion functions. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type DefaultMapConfiguredFirestoreFieldConfig = Omit, 'fromData' | 'toData' | 'default'> & Partial, 'default'>>; /** * Configuration for an optional Firestore field without conversion functions or defaults. * * @template V - Value type for the field in the model * @template D - Data type for the field in Firestore (defaults to unknown) */ export type OptionalMapConfiguredFirestoreFieldConfig = Omit, 'fromData' | 'toData' | 'defaultBeforeSave'>; /** * Configuration for a Firestore string field with optional transformation. * * @template S - String type for the field (defaults to string) */ export interface FirestoreStringConfig extends DefaultMapConfiguredFirestoreFieldConfig { /** * Optional transformation to apply to the string value */ readonly transform?: TransformStringFunctionConfigInput; } /** * Default value for required Firestore string fields when the field is missing from the document. */ export declare const DEFAULT_FIRESTORE_STRING_FIELD_VALUE = ""; /** * Creates a field mapping configuration for Firestore string fields. * * Defaults to empty string `''` when the field is missing. Supports optional string * transformation (e.g., lowercase, trim) applied on both read and write. * * @template S - String type for the field (defaults to string) * @param config - Configuration for the string field * @returns A field mapping configuration for string values * * @example * ```ts * // Simple string field with default * const nameField = firestoreString({ default: 'unnamed' }); * * // String field with lowercase transformation * const emailField = firestoreString({ transform: 'lowercase' }); * ``` */ export declare function firestoreString(config?: FirestoreStringConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore string field with transformation. * * @template S - String type for the field (defaults to string) */ export type OptionalFirestoreString = OptionalOneTypeFirestoreFieldConfig & Pick, 'transform'>; /** * Creates a field mapping configuration for optional Firestore string fields. * * @template S - String type for the field (defaults to string) * @param config - Configuration for the optional string field * @returns A field mapping configuration for optional string values */ export declare function optionalFirestoreString(config?: OptionalFirestoreString): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore enum field. * * @template S - Enum type (string or number) */ export type FirestoreEnumConfig = MapConfiguredFirestoreFieldConfigWithDefault; /** * Creates a field mapping configuration for Firestore enum fields. * * @template S - Enum type (string or number) * @param config - Configuration for the enum field * @returns A field mapping configuration for enum values */ export declare function firestoreEnum(config: FirestoreEnumConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore enum field. * * @template S - Enum type (string or number) */ export type OptionalFirestoreEnumConfig = OptionalOneTypeFirestoreFieldConfig; /** * Creates a field mapping configuration for optional Firestore enum fields. * * @template S - Enum type (string or number) * @param config - Configuration for the optional enum field * @returns A field mapping configuration for optional enum values */ export declare function optionalFirestoreEnum(config?: OptionalFirestoreEnumConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Creates a field mapping configuration for Firestore UID fields. * * @returns A field mapping configuration for Firebase Auth user IDs */ export declare function firestoreUID(): FirestoreModelFieldMapFunctionsConfig; /** * Creates a field mapping configuration for optional Firestore UID fields. * * @returns A field mapping configuration for optional Firebase Auth user IDs */ export declare function optionalFirestoreUID(): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Pre-built field mapping for Firestore model key strings. Defaults to empty string. */ export declare const firestoreModelKeyString: FirestoreModelFieldMapFunctionsConfig; /** * Pre-built field mapping for Firestore model ID strings. Defaults to empty string. */ export declare const firestoreModelIdString: FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore date field. * * @template Date - JavaScript Date object type * @template string - ISO8601 date string format in Firestore */ export type FirestoreDateFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & { /** * Whether to save the default date as the current timestamp */ readonly saveDefaultAsNow?: boolean; }; /** * Creates a field mapping configuration for Firestore date fields. * * Handles conversion between JavaScript Date objects and ISO8601 strings stored in Firestore. * Defaults to `new Date()` when the field is missing. Use `saveDefaultAsNow` to automatically * store the current timestamp when a new document is created. * * @param config - Configuration for the date field * @returns A field mapping configuration for Date values * * @example * ```ts * // Date field that auto-saves current time on creation * const createdAtField = firestoreDate({ saveDefaultAsNow: true }); * * // Date field with a fixed default * const startDateField = firestoreDate({ default: new Date('2020-01-01') }); * ``` */ export declare function firestoreDate(config?: FirestoreDateFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore date field. * * @template Date - JavaScript Date object type * @template ISO8601DateString - ISO8601 date string format in Firestore */ export type OptionalFirestoreDateFieldConfig = OptionalFirestoreFieldConfig; /** * Creates a field mapping configuration for optional Firestore date fields. * * Handles conversion between JavaScript Date objects and ISO8601 strings stored in Firestore. * * @param config - Configuration for the optional date field * @returns A field mapping configuration for optional Date values */ export declare function optionalFirestoreDate(config?: OptionalFirestoreDateFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore date field that is stored as a number. */ export type FirestoreDateNumberFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & { /** * Whether to save the default date as the current timestamp */ readonly saveDefaultAsNow?: boolean; /** * Converts a Date object to a number. */ readonly fromDate: (input: Date) => number; /** * Converts a number to a Date object. */ readonly toDate: (input: number) => Date; }; /** * Creates a field mapping configuration for Firestore date fields stored as numbers. * * Handles conversion between JavaScript Date objects and numeric representations * using the provided `fromDate`/`toDate` conversion functions. * * @param config - Configuration including custom Date-to-number conversion functions * @returns A field mapping configuration for Date values stored as numbers */ export declare function firestoreDateNumber(config: FirestoreDateNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore date field. * * @template Date - JavaScript Date object type * @template ISO8601DateString - ISO8601 date string format in Firestore */ export type OptionalFirestoreDateNumberFieldConfig = OptionalFirestoreFieldConfig & Pick; /** * Creates a field mapping configuration for optional Firestore date field that is stored as a number. * * @param config - Configuration for the optional date field * @returns A field mapping configuration for optional Date values */ export declare function optionalFirestoreDateNumber(config: OptionalFirestoreDateNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; export type FirestoreUnixDateTimeSecondsNumberFieldConfig = Omit; /** * Creates a field mapping configuration for Firestore Date fields that are stored as a UnixDateTimeSecondsNumber. * * @param config - Configuration for the date field * @returns A field mapping configuration for Date values */ export declare function firestoreUnixDateTimeSecondsNumber(config: FirestoreUnixDateTimeSecondsNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig; export type OptionalFirestoreUnixDateTimeSecondsNumberFieldConfig = Omit; /** * Creates a field mapping configuration for optional Firestore Date fields that are stored as a UnixDateTimeSecondsNumber. * * @param config - Configuration for the optional date field * @returns A field mapping configuration for optional Date values */ export declare function optionalFirestoreUnixDateTimeSecondsNumber(config?: OptionalFirestoreUnixDateTimeSecondsNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore boolean field. */ export type FirestoreBooleanFieldConfig = MapConfiguredFirestoreFieldConfigWithDefault; /** * Creates a field mapping configuration for Firestore boolean fields. * * @param config - Configuration for the boolean field * @returns A field mapping configuration for boolean values */ export declare function firestoreBoolean(config: FirestoreBooleanFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore boolean field. */ export type OptionalFirestoreBooleanFieldConfig = OptionalOneTypeFirestoreFieldConfig; /** * Creates a field mapping configuration for optional Firestore boolean fields. * * @param config - Configuration for the optional boolean field * @returns A field mapping configuration for optional boolean values */ export declare function optionalFirestoreBoolean(config?: OptionalFirestoreBooleanFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore number field with optional transformation. * * @template N - Number type for the field (defaults to number) */ export interface FirestoreNumberConfig extends MapConfiguredFirestoreFieldConfigWithDefault { /** * Whether to save the default value if no value is provided */ readonly saveDefault?: Maybe; /** * Optional transformation to apply to the number value */ readonly transform?: TransformNumberFunctionConfigInput; } /** * Creates a field mapping configuration for Firestore number fields. * * @template N - Number type for the field (defaults to number) * @param config - Configuration for the number field * @returns A field mapping configuration for number values */ export declare function firestoreNumber(config: FirestoreNumberConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore number field with transformation. * * @template N - Number type for the field (defaults to number) */ export type OptionalFirestoreNumberFieldConfig = OptionalOneTypeFirestoreFieldConfig & Pick, 'transform'>; /** * Creates a field mapping configuration for optional Firestore number fields. * * @template N - Number type for the field (defaults to number) * @param config - Configuration for the optional number field * @returns A field mapping configuration for optional number values */ export declare function optionalFirestoreNumber(config?: OptionalFirestoreNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore array field with optional sorting. * * @template T - Type of elements in the array */ export type FirestoreArrayFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & Partial> & Partial>; /** * Creates a field mapping configuration for Firestore array fields. * * Defaults to an empty array when the field is missing. Supports optional sorting * via `sortWith` which is applied on both read and write. * * @template T - Type of elements in the array * @param config - Configuration for the array field * @returns A field mapping configuration for array values * * @example * ```ts * // Array of strings sorted alphabetically * const tagsField = firestoreArray({ * sortWith: (a, b) => a.localeCompare(b) * }); * ``` */ export declare function firestoreArray(config: FirestoreArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for an optional Firestore array field with filtering and sorting options. * * @template T - Type of elements in the array */ export type OptionalFirestoreArrayFieldConfig = Omit, 'dontStoreIf' | 'dontStoreIfValue' | 'transformFromData' | 'transformToData'> & Pick, 'sortWith'> & { /** * Filters the function uniquely. If true uses the unique function. */ readonly filterUnique?: T extends PrimativeKey ? FilterUniqueFunction | true : never; /** * Removes the value from the object if the decision returns true. */ readonly dontStoreIf?: DecisionFunction; /** * The array is not stored if it is empty. * * Defaults to false. */ readonly dontStoreIfEmpty?: boolean; }; /** * Creates a field mapping configuration for optional Firestore array fields. * * Supports unique filtering and conditional storage based on array content. * * @template T - Type of elements in the array * @param config - Configuration for the optional array field * @returns A field mapping configuration for optional array values */ export declare function optionalFirestoreArray(config?: OptionalFirestoreArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig, Maybe>; /** * Configuration for a Firestore array field with unique filtering. * * @template T - Type of elements in the array * @template K - Key type for filtering uniqueness (defaults to T if it's a primative key) */ export type FirestoreUniqueArrayFieldConfig = FirestoreArrayFieldConfig & Partial> & { /** * Function to filter array elements for uniqueness */ readonly filterUnique: FilterUniqueFunction | true; }; /** * Creates a field mapping configuration for Firestore array fields with unique filtering. * * @template T - Type of elements in the array * @template K - Key type for filtering uniqueness * @param config - Configuration for the unique array field * @returns A field mapping configuration for unique array values */ export declare function firestoreUniqueArray(config: FirestoreUniqueArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field with unique filtering based on a key function. * * @template T - Type of elements in the array * @template K - Type of the key used for uniqueness (defaults to PrimativeKey) */ export type FirestoreUniqueKeyedArrayFieldConfig = FirestoreArrayFieldConfig & { /** * Function to extract the key from an array element for uniqueness checking */ readonly readKey: ReadKeyFunction; }; /** * Creates a field mapping configuration for Firestore array fields with unique filtering based on a key function. * * @template T - Type of elements in the array * @template K - Type of the key used for uniqueness * @param config - Configuration for the keyed unique array field * @returns A field mapping configuration for keyed unique array values */ export declare function firestoreUniqueKeyedArray(config: FirestoreUniqueKeyedArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field of enum values. * * @template S - Enum type (string or number) */ export type FirestoreEnumArrayFieldConfig = Omit, 'filterUnique'>; /** * Creates a field mapping configuration for Firestore array fields of unique enum values. * * @template S - Enum type (string or number) * @param config - Configuration for the enum array field * @returns A field mapping configuration for enum array values */ export declare function firestoreEnumArray(config?: FirestoreEnumArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field of unique string values. * * @template S - String type (defaults to string) */ export type FirestoreUniqueStringArrayFieldConfig = Omit, 'filterUnique'> & FilterUniqueStringsTransformConfig; /** * Creates a field mapping configuration for Firestore array fields of unique string values. * * @template S - String type (defaults to string) * @param config - Configuration for the unique string array field * @returns A field mapping configuration for unique string array values */ export declare function firestoreUniqueStringArray(config?: FirestoreUniqueStringArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Pre-built field mapping for arrays of unique Firestore model key strings. */ export declare const firestoreModelKeyArrayField: FirestoreModelFieldMapFunctionsConfig; /** * Pre-built field mapping for arrays of unique Firestore model ID strings. * Alias for {@link firestoreModelKeyArrayField}. */ export declare const firestoreModelIdArrayField: FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field of unique number values. * * @template S - Number type (defaults to number) */ export type FirestoreUniqueNumberArrayFieldConfig = Omit, 'filterUnique'>; /** * Creates a field mapping configuration for Firestore array fields of unique number values. * * @template S - Number type (defaults to number) * @param config - Configuration for the unique number array field * @returns A field mapping configuration for unique number array values */ export declare function firestoreUniqueNumberArray(config?: FirestoreUniqueNumberArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field with custom encoding/decoding of values. * * @template T - Type of elements in the model array * @template E - Type of encoded elements in Firestore (string or number) */ export type FirestoreEncodedArrayFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & Partial> & { /** * Conversion functions for encoding/decoding array elements */ readonly convert: { /** * Function to convert from Firestore data to model value */ fromData: MapFunction; /** * Function to convert from model value to Firestore data */ toData: MapFunction; }; }; /** * Creates a field mapping configuration for Firestore array fields with custom encoding. * * Encodes model values to string or number representations for storage, and decodes them on read. * Useful when the model type is richer than what should be stored directly in Firestore. * * @template T - Type of elements in the model array * @template E - Type of encoded elements in Firestore (string or number) * @param config - Configuration for the encoded array field * @returns A field mapping configuration for encoded array values */ export declare function firestoreEncodedArray(config: FirestoreEncodedArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field with primative key encoding/decoding. * * @template D - Type of decoded elements in the model array * @template E - Type of encoded elements in Firestore */ export type FirestoreDencoderArrayFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & { /** * Function that handles both encoding and decoding of array elements */ readonly dencoder: PrimativeKeyDencoderFunction; }; /** * Creates a field mapping configuration for Firestore array fields using a dencoder (encode/decode) function. * * The dencoder is a single function that handles both encoding (model → Firestore) and decoding * (Firestore → model) directions, leveraging {@link PrimativeKeyDencoderFunction}. * * @template D - Type of decoded elements in the model array * @template E - Type of encoded elements in Firestore * @param config - Configuration for the decoder array field * @returns A field mapping configuration for encoded primative key array values */ export declare function firestoreDencoderArray(config: FirestoreDencoderArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore array field that encodes primative keys to a string representation. * * @template D - Type of decoded elements in the model array * @template E - Type of encoded elements (intermediate representation) * @template S - String type for storage in Firestore */ export type FirestoreDencoderStringArrayFieldConfig = DefaultMapConfiguredFirestoreFieldConfig & { /** * Function that handles both encoding and decoding of array elements to/from string */ readonly dencoder: PrimativeKeyStringDencoderFunction; }; /** * Creates a field mapping configuration for Firestore array fields that encode primative keys to a string representation. * * An array that is stored as an encoded string using a PrimativeKeyDencoderString configuration. * * @template D - Type of decoded elements in the model array * @template E - Type of encoded elements (intermediate representation) * @template S - String type for storage in Firestore * @param config - Configuration for the string decoder array field * @returns A field mapping configuration for string-encoded primative key array values */ export declare function firestoreDencoderStringArray(config: FirestoreDencoderStringArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * A Firestore map type. Firestore/JSON maps only support string keys. * * @template T - Value type in the map * @template K - Key type (must extend string) */ export type FirestoreMapFieldType = Record; /** * Configuration for a {@link firestoreMap} field. */ export type FirestoreMapFieldConfig = DefaultMapConfiguredFirestoreFieldConfig, FirestoreMapFieldType> & Partial>> & { /** * Optional filter to apply when saving to data. * * By default will filter all null/undefined values from maps. */ readonly mapFilter?: FilterKeyValueTuplesInput>; /** * Optional map function to apply to each input value before saving. */ readonly mapFieldValues?: MapFunction, Maybe>; }; /** * Creates a field mapping configuration for Firestore map-type (key-value object) fields. * * By default, removes all null/undefined keys from the object before saving to Firestore. * Defaults to an empty object `{}` when the field is missing. * * @template T - Value type in the map * @template K - Key type (must be string, as Firestore maps only have string keys) * @param config - Configuration for the map field * @returns A field mapping configuration for map values * * @example * ```ts * // Map of user preferences * const prefsField = firestoreMap({ * mapFilter: KeyValueTypleValueFilter.EMPTY * }); * ``` */ export declare function firestoreMap(config?: FirestoreMapFieldConfig): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * FirestoreField configuration for a map of granted roles, keyed by model keys. * * Filters out models with no/null roles by default. * * @returns A field mapping configuration for a map of granted roles keyed by FirestoreModelKey */ export declare function firestoreModelKeyGrantedRoleMap(): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * FirestoreField configuration for a map of granted roles, keyed by model ids. * * Filters out models with no/null roles by default. */ export declare const firestoreModelIdGrantedRoleMap: () => FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * A Firestore map type where values are encoded from type `T` to type `E` for storage. */ export type FirestoreEncodedObjectMapFieldValueType = Record; export type FirestoreEncodedObjectMapFieldConfig = DefaultMapConfiguredFirestoreFieldConfig, FirestoreMapFieldType> & Partial>> & { /** * Optional filter to apply when saving to data. * * By default will filter all null/undefined values from maps. */ readonly mapFilter?: FilterKeyValueTuplesInput>; /** * Encoder to map a value to the encoded/stored value. */ readonly encoder: MapFunction; /** * Encoder to map an encoded/stored value to a value. */ readonly decoder: MapFunction; }; /** * Creates a field mapping configuration for Firestore map fields with encoded values. * * Each value in the map is encoded/decoded using the provided `encoder`/`decoder` functions. * By default, removes all empty/null keys from the map before saving. * * @template T - Decoded value type in the model * @template E - Encoded value type in Firestore * @template S - Key type (string, defaults to string) * @param config - Configuration including encoder/decoder functions * @returns A field mapping configuration for encoded map values */ export declare function firestoreEncodedObjectMap(config: FirestoreEncodedObjectMapFieldConfig): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; export type FirestoreDencoderMapFieldValueType = FirestoreEncodedObjectMapFieldValueType; export type FirestoreDencoderMapFieldConfig = Omit, 'encoder' | 'decoder'> & { /** * Dencoder to use for the input values. */ readonly dencoder: PrimativeKeyStringDencoderFunction; }; /** * Creates a field mapping configuration for Firestore map fields using a dencoder function. * * Similar to {@link firestoreEncodedObjectMap} but uses a single dencoder function for both * encoding and decoding directions. By default, removes all empty/null keys from the map before saving. * * @template D - Decoded primative key type * @template E - Encoded primative key type * @template S - Key type for the map (string, defaults to string) * @param config - Configuration including the dencoder function * @returns A field mapping configuration for dencoder-mapped values */ export declare function firestoreDencoderMap(config: FirestoreDencoderMapFieldConfig): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * FirestoreField configuration for a map of encoded granted roles, keyed by model keys. * * Filters out models with empty/no roles by default. * * @param dencoder - The dencoder function used to encode and decode the role values * @returns A field mapping configuration for an encoded granted role map keyed by FirestoreModelKey */ export declare function firestoreModelKeyEncodedGrantedRoleMap(dencoder: PrimativeKeyStringDencoderFunction): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * A Firestore map where each value is an array of `T`. */ export type FirestoreArrayMapFieldType = FirestoreMapFieldType; export type FirestoreArrayMapFieldConfig = FirestoreMapFieldConfig; /** * Creates a field mapping configuration for Firestore map fields where each value is an array. * * Defaults to filtering empty arrays and null/undefined elements from each array before saving. * * @template T - Element type in the array values * @template K - Key type for the map (string) * @param config - Configuration for the array map field * @returns A field mapping configuration for map values with array entries */ export declare function firestoreArrayMap(config?: FirestoreArrayMapFieldConfig): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * FirestoreField configuration for a map of granted roles, keyed by models keys. * * Filters empty roles/arrays by default. * * @returns A field mapping configuration for a map of granted role arrays keyed by FirestoreModelKey */ export declare function firestoreModelKeyGrantedRoleArrayMap(): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * FirestoreField configuration for a map of granted roles, keyed by models ids. * * Filters empty roles/arrays by default. */ export declare const firestoreModelIdGrantedRoleArrayMap: () => FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>; /** * firestoreObjectArray configuration */ export type FirestoreObjectArrayFieldConfig> = DefaultMapConfiguredFirestoreFieldConfig & (FirestoreObjectArrayFieldConfigObjectFieldInput | FirestoreObjectArrayFieldConfigFirestoreFieldInput) & Partial> & { /** * Filters the objects array uniquely. */ readonly filterUnique?: FilterUniqueFunction; /** * Arbitrary filter to apply to the array. Is run after the filterUnique function is run. */ readonly filter?: FilterFunction; }; export type FirestoreObjectArrayFieldConfigObjectFieldInput> = { /** * The field to use for conversion. */ readonly objectField: ToModelMapFunctionsInput; }; export type FirestoreObjectArrayFieldConfigFirestoreFieldInput> = { /** * FirestoreModelFieldMapFunctionsConfig to use for conversion. */ readonly firestoreField: FirestoreModelFieldMapFunctionsConfig; }; /** * Converts a {@link FirestoreModelFieldMapFunctionsConfig} into a {@link ModelMapFunctionsRef}. * * Used internally by {@link firestoreObjectArray} to adapt field configs into the map functions * format needed for array element conversion. * * @param config - The FirestoreModelFieldMapFunctionsConfig to convert * @returns A ModelMapFunctionsRef wrapping the derived map functions */ export declare function firestoreFieldConfigToModelMapFunctionsRef>(config: FirestoreModelFieldMapFunctionsConfig): ModelMapFunctionsRef; /** * Creates a field mapping configuration for Firestore arrays of complex objects. * * Each element in the array is converted using its own set of field converters (via `objectField` * or `firestoreField`), enabling type-safe conversion of embedded document arrays. * Supports optional unique filtering and sorting. * * On write, null/undefined values are filtered from each object to match Firestore semantics. * * @template T - The element model type * @template O - The element Firestore data type (defaults to FirestoreModelData) * @param config - Configuration including element conversions and optional filtering/sorting * @returns A field mapping configuration for object array values * * @example * ```ts * // Array of embedded item objects * const itemsField = firestoreObjectArray({ * objectField: notificationItemFields, * sortWith: sortAscendingIndexNumberRefFunction() * }); * ``` */ export declare function firestoreObjectArray>(config: FirestoreObjectArrayFieldConfig): FirestoreModelFieldMapFunctionsConfig; /** * firestoreSubObjectField configuration */ export type FirestoreSubObjectFieldConfig> = DefaultMapConfiguredFirestoreFieldConfig & { /** * Whether or not to save the default object. Is ignored if defaultBeforeSave is set. * * Is false by default. */ readonly saveDefaultObject?: boolean; /** * The fields to use for conversion. */ readonly objectField: ToModelMapFunctionsInput; }; export type FirestoreSubObjectFieldMapFunctionsConfig> = FirestoreModelFieldMapFunctionsConfig & ModelMapFunctionsRef; /** * Creates a field mapping configuration for nested Firestore object fields. * * Maps a nested object using its own set of field converters, enabling recursive type-safe * conversion of embedded documents. The `objectField` defines the conversion rules for * the nested object's fields using the same converter patterns. * * @template T - The nested model type * @template O - The nested Firestore data type (defaults to FirestoreModelData) * @param config - Configuration including nested field conversions * @returns A field mapping configuration with both field config and map functions * * @example * ```ts * // Nested address object with its own converters * const addressField = firestoreSubObject
({ * objectField: { * street: firestoreString(), * city: firestoreString(), * zip: firestoreString() * } * }); * ``` */ export declare function firestoreSubObject>(config: FirestoreSubObjectFieldConfig): FirestoreSubObjectFieldMapFunctionsConfig; export interface FirestoreLatLngStringConfig extends DefaultMapConfiguredFirestoreFieldConfig { precision?: LatLngPrecision; } /** * Creates a field mapping configuration for Firestore latitude/longitude string fields. * * Stores lat/lng as a single string rather than a lat/lng object or value pair. This is preferred * because Firestore cannot efficiently sort/search lat and lng together, making indexing on separate * fields useless. As a single string field, it integrates with the {@link LatLngStringRef} interface * and can be mapped using `latLngDataPointFunction()`. * * Applies validation and optional precision rounding on both read and write. * * @param config - Optional precision and default value configuration * @returns A field mapping configuration for LatLngString values */ export declare function firestoreLatLngString(config?: FirestoreLatLngStringConfig): FirestoreModelFieldMapFunctionsConfig<`${number},${number}`, `${number},${number}`>; export type FirestoreTimezoneStringConfig = DefaultMapConfiguredFirestoreFieldConfig; /** * Default configuration for a TimezoneString. * * The value defaults to UTC. * * @param config - Optional configuration for the timezone string field, including default value and pre-save default. * @returns A configured Firestore field that stores a TimezoneString value. */ export declare function firestoreTimezoneString(config?: FirestoreTimezoneStringConfig): FirestoreModelFieldMapFunctionsConfig; export declare const DEFAULT_WEBSITE_LINK: WebsiteLink; export declare const assignWebsiteLinkFunction: import("@dereekb/util").AssignValuesToPOJOFunction; export declare const firestoreWebsiteLinkAssignFn: MapFunction; /** * Creates a field mapping configuration for Firestore website link fields. * * @returns A field mapping configuration for website link values */ export declare function firestoreWebsiteLink(): FirestoreModelFieldMapFunctionsConfig; /** * Creates a field mapping configuration for Firestore arrays of WebsiteLink values. * * @returns A field mapping configuration for WebsiteLink array values */ export declare function firestoreWebsiteLinkArray(): FirestoreModelFieldMapFunctionsConfig; export declare const DEFAULT_FIRESTORE_WEBSITE_FILE_LINK_VALUE: WebsiteFileLink; export declare const assignWebsiteFileLinkFunction: import("@dereekb/util").AssignValuesToPOJOFunction; export declare const firestoreWebsiteFileLinkAssignFn: MapFunction; /** * Creates a field mapping configuration for Firestore website file link fields. * * @returns A field mapping configuration for website file link values */ export declare function firestoreWebsiteFileLink(): FirestoreModelFieldMapFunctionsConfig; /** * Stores the array of WebsiteFileLink values as an array of objects. * * @returns A field mapping configuration for WebsiteFileLink array values stored as objects */ export declare function firestoreWebsiteFileLinkObjectArray(): FirestoreModelFieldMapFunctionsConfig; /** * Stores the array of WebsiteFileLink values as an array of EncodedWebsiteFileLink values. * * @returns A field mapping configuration for WebsiteFileLink array values stored in encoded form */ export declare function firestoreWebsiteFileLinkEncodedArray(): FirestoreModelFieldMapFunctionsConfig; export declare const DEFAULT_DATE_CELL_RANGE_VALUE: DateCellRange; export declare const assignDateCellRangeFunction: import("@dereekb/util").AssignValuesToPOJOFunction; export declare const firestoreDateCellRangeAssignFn: MapFunction; /** * Creates a field mapping configuration for Firestore date cell range fields. * * @returns A field mapping configuration for date cell range values */ export declare function firestoreDateCellRange(): FirestoreModelFieldMapFunctionsConfig; /** * Creates a field mapping configuration for Firestore arrays of DateCellRange values. * * @param sort - Whether to sort the array by index number; defaults to true * @returns A field mapping configuration for DateCellRange array values */ export declare function firestoreDateCellRangeArray(sort?: boolean): FirestoreModelFieldMapFunctionsConfig; export declare const DEFAULT_FIRESTORE_DATE_CELL_SCHEDULE_VALUE: DateCellSchedule; export declare const assignDateCellScheduleFunction: import("@dereekb/util").AssignValuesToPOJOFunction; export declare const firestoreDateCellScheduleAssignFn: MapFunction; /** * Creates a field mapping configuration for Firestore date cell schedule fields. * * @returns A field mapping configuration for date cell schedule values */ export declare function firestoreDateCellSchedule(): FirestoreModelFieldMapFunctionsConfig; export declare const DEFAULT_FIRESTORE_UNITED_STATES_ADDRESS_VALUE: UnitedStatesAddress; /** * Function to assign values to a UnitedStatesAddress object while filtering specific keys and empty values. */ export declare const assignUnitedStatesAddressFunction: import("@dereekb/util").AssignValuesToPOJOFunction; /** * Function to assign values from an input UnitedStatesAddress to a default UnitedStatesAddress. * * @param input - The source UnitedStatesAddress to copy values from * @returns A new UnitedStatesAddress with values assigned from the input */ export declare const firestoreUnitedStatesAddressAssignFn: MapFunction; /** * Creates a field mapping configuration for Firestore United States address fields. * * @returns A field mapping configuration for United States address values */ export declare function firestoreUnitedStatesAddress(): FirestoreModelFieldMapFunctionsConfig; /** * Creates a field mapping configuration for optional Firestore United States address fields. * * @returns A field mapping configuration for optional United States address values */ export declare function optionalFirestoreUnitedStatesAddress(): FirestoreModelFieldMapFunctionsConfig, Maybe>; export declare const MIN_FIRESTORE_MAP_ZOOM_LEVEL_VALUE: ZoomLevel; export declare const MAX_FIRESTORE_MAP_ZOOM_LEVEL_VALUE: ZoomLevel; /** * Field mapping configuration for Firestore map zoom level fields. * * Convenience function for firestoreNumber() for storing an integer ZoomLevel value. */ export declare const firestoreMapZoomLevel: FirestoreModelFieldMapFunctionsConfig; /** * Configuration for a Firestore field that stores a set of numbers as a bitwise-encoded value. * * @template D - Type of number elements in the set (defaults to number) */ export interface FirestoreBitwiseSetConfig extends DefaultMapConfiguredFirestoreFieldConfig, BitwiseEncodedSet> { /** * Maximum index value to support in the bitwise encoding */ readonly maxIndex?: number; } /** * Creates a field mapping configuration for Firestore fields that store sets of numbers as bitwise-encoded values. * * @template D - Type of number elements in the set (defaults to number) * @param config - Configuration for the bitwise set field * @returns A field mapping configuration for bitwise-encoded set values */ export declare function firestoreBitwiseSet(config: FirestoreBitwiseSetConfig): FirestoreModelFieldMapFunctionsConfig, number>; /** * Configuration for a Firestore field that maps objects with bitwise-encoded set values. * * @template D - Type of number elements in the sets (defaults to number) * @template K - Type of keys in the object (string) */ export interface FirestoreBitwiseSetMapConfig extends Omit, BitwiseEncodedSet, K>, 'encoder' | 'decoder'> { /** * Maximum index value to support in the bitwise encoding */ readonly maxIndex?: number; } /** * Creates a field mapping configuration for Firestore fields that map objects with bitwise-encoded set values. * * @template D - Type of number elements in the sets (defaults to number) * @template K - Type of keys in the object (string) * @param config - Configuration for the bitwise set map field * @returns A field mapping configuration for object maps with bitwise-encoded set values */ export declare function firestoreBitwiseSetMap(config: FirestoreBitwiseSetMapConfig): FirestoreModelFieldMapFunctionsConfig, K>, FirestoreMapFieldType>; /** * Configuration for a Firestore field that maps objects with bitwise-encoded object values. * * @template T - Type of object values in the map * @template K - Type of keys in the object (string) */ export interface FirestoreBitwiseObjectMapConfig extends Omit, 'encoder' | 'decoder'> { /** * Function that handles both encoding and decoding of object values to/from bitwise values */ readonly dencoder: BitwiseObjectDencoder; } /** * Creates a field mapping configuration for Firestore fields that map objects with bitwise-encoded object values. * * @template T - Type of object values in the map * @template K - Type of keys in the object (string) * @param config - Configuration for the bitwise object map field * @returns A field mapping configuration for object maps with bitwise-encoded object values */ export declare function firestoreBitwiseObjectMap(config: FirestoreBitwiseObjectMapConfig): FirestoreModelFieldMapFunctionsConfig, FirestoreMapFieldType>;