import { DocumentData, Timestamp } from 'firebase-admin/firestore'; import type { google } from '@gcf/firestore-protos'; /** * Returns whether a runtime value should be treated as an **immutable Firestore value**. * * A value is considered immutable if it is one of: * - `Timestamp` — Firestore timestamp object * - `FieldValue` — sentinel values (e.g., `serverTimestamp()`, `delete()`, `increment()`) * - `GeoPoint` — geographic coordinate value * - `DocumentReference` — reference to another document * - A **vector-like** value as determined by `isVectorLikeShallow` (e.g., a typed array * or array-of-numbers representation used for embeddings) * * This predicate is useful in cloning/freezing routines to avoid deep mutation or * unnecessary copying of Firestore-native types and vector buffers. * * Notes: * - The vector check is **shallow** and delegates to `isVectorLikeShallow`. * - Containers (arrays/maps) are **not** considered immutable unless they themselves * satisfy the vector-like predicate. * * @param value - Any runtime value to test. * @returns `true` if `value` is a Firestore-native immutable or vector-like value; otherwise `false`. * * @example * isImmutableFirestoreType(Timestamp.now()); // true * isImmutableFirestoreType(FieldValue.serverTimestamp()); // true * isImmutableFirestoreType(new GeoPoint(1, 2)); // true * isImmutableFirestoreType(docRef); // true * isImmutableFirestoreType(new Float32Array([0.1, 0.2])); // true (if treated as vector-like) * isImmutableFirestoreType({ a: 1 }); // false */ export declare function isImmutableFirestoreType(value: unknown): boolean; /** * Ensures a `google.protobuf.ITimestamp` wire-protocol structure rather than an * internal `Timestamp` instance. */ export declare function toProtoTimestamp(value: google.protobuf.ITimestamp | Timestamp): google.protobuf.ITimestamp; /** * Splits and validates a Firestore field path into segments. * Mimics the behavior of Firestore Admin SDK's FieldPath.fromDotSeparatedString(). * * @param fieldPath - Dot-separated string representation of a field path. * @returns An array of field path segments. */ /** * Compatibility wrapper for mask strings coming from outside your serializer. * - First tries strict parsing. * - If that fails *and* the string contains no backticks at all, falls back to * a literal split on '.' with minimal validation (no empty segments). */ export declare function parseFieldPath(fieldPath: string): string[]; export declare function parseFieldPathStrict(fieldPath: string): string[]; export type ByteArrayLike = Uint8Array | ArrayBuffer | Buffer; /** * Returns true if the value is one of the supported byte-array inputs. * Safe in browser & Node (Buffer may be undefined in browsers). */ export declare function isByteArrayLike(v: unknown): v is ByteArrayLike; /** * Create a Buffer *view* over the provided input without copying bytes. * - Buffer: returned as-is (same object; no copy) * - Uint8Array: view over the same underlying memory, honoring offset/length * - ArrayBuffer: view over the same buffer (full range) * * If you need an independent copy, use `cloneByteArray()` instead. */ export declare function toBuffer(v: ByteArrayLike): Buffer; /** * Deeply clones the provided byte data into a new Buffer with its own memory. * The resulting Buffer shares no memory with the input. */ export declare function cloneByteArray(v: ByteArrayLike): Buffer; /** * Verifies that 'obj' is a plain JavaScript object that can be encoded as a * 'Map' in Firestore. * * @private * @internal * @param input The argument to verify. * @returns 'true' if the input can be a treated as a plain object. */ export declare function isPlainObject(input: unknown): input is DocumentData; /** * Determines whether `value` is a JavaScript object. * * @private * @internal */ export declare function isObject(value: unknown): value is { [k: string]: unknown; }; /** * Creates a `Timestamp` with nanoseconds truncated in accordance with backend persistence behaviour. */ export declare function truncatedTimestamp(value: Timestamp): Timestamp; /** A minimal duck-typed shape for Firestore vector values. */ export type VectorLike = { toArray(): number[]; }; /** * Lightweight, allocation-free check for a Firestore vector value. * * @remarks * In Node/Admin Firestore, vector fields are the only values that expose a {@link VectorLike.toArray} method. * This guard intentionally **does not** call `toArray()` to avoid extra allocations or O(n) scans—use it * before calling {@link vectorDims} on hot paths. * * @param v - Unknown value from decoded document data. * @returns `true` if `v` looks like a vector (has a callable `toArray()`), otherwise `false`. * * @example * ```ts * if (isVectorLikeShallow(value)) { * // Safe to treat as VectorLike; call vectorDims(value) to size it. * } * ``` */ export declare function isVectorLikeShallow(v: unknown): v is VectorLike; export declare function vectorDims(v: VectorLike): number; export declare function getVectorValue(v: Partial | null | undefined): number[]; export declare function peekVectorValue(v: Partial | null | undefined): readonly number[]; /** * Returns a new array with duplicate items removed while preserving the order * of the first occurrence of each element. * * If no `comparer` is provided, strict equality (`===`) is used. * * You can also provide a custom `comparer` to control how elements are considered * equal. The comparer may be: * * - **Equality-style**: `(x, y) => boolean` — return `true` when `x` and `y` should be treated as duplicates. * - **Comparator-style**: `(x, y) => number` — return `0` when `x` and `y` should be treated as duplicates * (similar to `Array.prototype.sort` comparators). * * The original array is never mutated. * * @typeParam T - The element type of the array. * @param array - The input array. If `null` or `undefined`, an empty array is returned. * @param comparer - Optional function used to determine equality between two items. * @returns A new array containing only the first occurrence of each distinct item. * * @example * // Default: dedupes primitives by strict equality * dedupeArray([1, 2, 2, 3, NaN, NaN]); // => [1, 2, 3, NaN, NaN] (since NaN !== NaN) * * @example * // Equality-style comparer: case-insensitive string dedupe * const ci = (a: string, b: string) => a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0; * dedupeArray(['A', 'a', 'b'], ci); // => ['A', 'b'] * * @example * // Comparator-style comparer: dedupe by object.id * interface Item { id: number; name: string } * const byId = (a: Item, b: Item) => a.id - b.id; // equal when result === 0 * dedupeArray([{ id:1, name:'x' }, { id:1, name:'y' }, { id:2, name:'z' }], byId); * // => [{ id:1, name:'x' }, { id:2, name:'z' }] */ export declare function dedupeArray(array: T[] | null | undefined, comparer?: (x: T, y: T) => boolean | number): T[]; /** * Returns the last element of a stack-like array **without** removing it. * * - Runs in O(1) time. * - Does not mutate the input array. * - Returns `undefined` when the array is empty. * * @typeParam T - Element type of the stack. * @param stack - The array acting as a stack (top at the end of the array). * @returns The top element, or `undefined` if `stack` is empty. * * @example * const s = [1, 2, 3]; * stackPeek(s); // 3 * s; // [1, 2, 3] (unchanged) * * @example * stackPeek([]); // undefined */ export declare function stackPeek(stack: T[]): T | undefined; //# sourceMappingURL=util.d.ts.map