/** * @db4/core - Shared Type Guards * * High-performance type guards with WeakMap caching for hot paths. * These utilities are shared across all @db4 packages and the icetype submodule. * * Performance optimizations: * 1. Fast-path rejection of primitives and arrays * 2. WeakMap caching for repeated validation of the same objects * 3. Set-based O(1) lookups for valid value checking * * @packageDocumentation */ import type { Document, DocumentMeta, StoredDocument, BatchMetadata, DocumentBatch, QueryFilter, SortSpec, QueryOptions, FieldDefinition, FieldModifier, FilterOperator, SortDirection, PrimitiveType } from './types.js'; /** * Type guard for Document (id-based). * A valid document must have an 'id' property of type string. * * @param value - Value to check * @returns true if value is a Document */ export declare function isDocument(value: unknown): value is Document; /** * Type guard for DocumentMeta. * * @param value - Value to check * @returns true if value is a DocumentMeta */ export declare function isDocumentMeta(value: unknown): value is DocumentMeta; /** * Type guard for StoredDocument (id + _meta based). * * @param value - Value to check * @returns true if value is a StoredDocument */ export declare function isStoredDocument(value: unknown): value is StoredDocument; /** * IceType Document interface ($id and $type based). */ export interface IceTypeDocument { $id: string; $type: string; [key: string]: unknown; } /** * IceType StoredDocument interface (with $version, $createdAt, $updatedAt). */ export interface IceTypeStoredDocument extends IceTypeDocument { $version: number; $createdAt: number; $updatedAt: number; } /** * IceType CDC operation types. */ export type CDCOperation = 'INSERT' | 'UPDATE' | 'DELETE'; /** * IceType CDC log entry. */ export interface CDCLogEntry { sequenceId: number; operation: CDCOperation; collection: string; documentId: string; timestamp: number; shardId: string; beforeState?: IceTypeStoredDocument; afterState?: IceTypeStoredDocument; changedFields?: string[]; transactionId?: string; synced: boolean; } /** * Type guard for IceType Document ($id/$type based). * Uses WeakMap caching for hot path performance. * * @param value - Value to check * @returns true if value is an IceType Document */ export declare function isIceTypeDocument(value: unknown): value is IceTypeDocument; /** * Type guard for IceType StoredDocument ($id/$type + metadata fields). * Uses WeakMap caching for hot path performance. * * @param value - Value to check * @returns true if value is an IceType StoredDocument */ export declare function isIceTypeStoredDocument(value: unknown): value is IceTypeStoredDocument; /** * Type guard for CDC operation. * * @param value - Value to check * @returns true if value is a valid CDC operation */ export declare function isCDCOperation(value: unknown): value is CDCOperation; /** * Type guard for CDCLogEntry. * Uses WeakMap caching for hot path performance. * * @param value - Value to check * @returns true if value is a CDCLogEntry */ export declare function isCDCEntry(value: unknown): value is CDCLogEntry; /** * Type guard for BatchMetadata. * * @param value - Value to check * @returns true if value is a BatchMetadata */ export declare function isBatchMetadata(value: unknown): value is BatchMetadata; /** * Type guard for DocumentBatch. * * @param value - Value to check * @returns true if value is a DocumentBatch */ export declare function isDocumentBatch(value: unknown): value is DocumentBatch; /** * Type guard for FilterOperator. * * @param value - Value to check * @returns true if value is a valid FilterOperator */ export declare function isFilterOperator(value: unknown): value is FilterOperator; /** * Type guard for QueryFilter. * * @param value - Value to check * @returns true if value is a QueryFilter */ export declare function isQueryFilter(value: unknown): value is QueryFilter; /** * Type guard for SortDirection. * * @param value - Value to check * @returns true if value is a valid SortDirection */ export declare function isSortDirection(value: unknown): value is SortDirection; /** * Type guard for SortSpec. * * @param value - Value to check * @returns true if value is a SortSpec */ export declare function isSortSpec(value: unknown): value is SortSpec; /** * Type guard for QueryOptions. * * @param value - Value to check * @returns true if value is a QueryOptions */ export declare function isQueryOptions(value: unknown): value is QueryOptions; /** * Type guard for FieldModifier. * * @param value - Value to check * @returns true if value is a valid FieldModifier */ export declare function isFieldModifier(value: unknown): value is FieldModifier; /** * Type guard for PrimitiveType. * * @param value - Value to check * @returns true if value is a valid PrimitiveType */ export declare function isPrimitiveType(value: unknown): value is PrimitiveType; /** * Type guard for FieldDefinition. * * @param value - Value to check * @returns true if value is a FieldDefinition */ export declare function isFieldDefinition(value: unknown): value is FieldDefinition; /** * Type guard for Error objects. * Also works as a base check for custom error types. * * @param value - Value to check * @returns true if value is an Error */ export declare function isError(value: unknown): value is Error; /** * Creates a type guard for a specific error class. * Useful for creating type guards for custom error types. * * @param ErrorClass - The error class to check for * @returns A type guard function for the specified error class * * @example * ```typescript * class MyError extends Error {} * const isMyError = createErrorTypeGuard(MyError); * if (isMyError(error)) { * // error is typed as MyError * } * ``` */ export declare function createErrorTypeGuard(ErrorClass: new (...args: unknown[]) => T): (value: unknown) => value is T; /** * Clears the type guard cache. * * Note: WeakMaps automatically garbage collect when keys are no longer referenced. * This function is provided for API completeness and testing purposes. * In practice, manual clearing is rarely needed. * * Implementation note: WeakMaps don't have a clear() method, and we cannot * reassign module-level constants. This function is effectively a no-op but * is preserved for API compatibility. */ export declare function clearTypeGuardCache(): void; /** * Gets the cache key constants for testing purposes. * Not intended for production use. */ export declare const _cacheKeys: { readonly DOCUMENT: "doc"; readonly DOCUMENT_META: "meta"; readonly STORED_DOCUMENT: "stored"; readonly ICETYPE_DOCUMENT: "ice_doc"; readonly ICETYPE_STORED_DOCUMENT: "ice_stored"; readonly CDC_ENTRY: "cdc"; readonly BATCH_METADATA: "batch_meta"; readonly DOCUMENT_BATCH: "doc_batch"; readonly QUERY_FILTER: "q_filter"; readonly SORT_SPEC: "sort"; readonly QUERY_OPTIONS: "q_opts"; readonly FIELD_DEFINITION: "field_def"; readonly ERROR: "error"; }; /** * Type guard for non-null objects. * Useful as a base check before more specific type guards. * * @param value - Value to check * @returns true if value is a non-null, non-array object */ export declare function isObject(value: unknown): value is Record; /** * Type guard for arrays. * * @param value - Value to check * @returns true if value is an array */ export declare function isArray(value: unknown): value is unknown[]; /** * Type guard for strings. * * @param value - Value to check * @returns true if value is a string */ export declare function isString(value: unknown): value is string; /** * Type guard for numbers. * * @param value - Value to check * @returns true if value is a number */ export declare function isNumber(value: unknown): value is number; /** * Type guard for booleans. * * @param value - Value to check * @returns true if value is a boolean */ export declare function isBoolean(value: unknown): value is boolean; /** * Type guard for null. * * @param value - Value to check * @returns true if value is null */ export declare function isNull(value: unknown): value is null; /** * Type guard for undefined. * * @param value - Value to check * @returns true if value is undefined */ export declare function isUndefined(value: unknown): value is undefined; /** * Type guard for null or undefined. * * @param value - Value to check * @returns true if value is null or undefined */ export declare function isNullish(value: unknown): value is null | undefined; /** * Type guard for non-null and non-undefined values. * * @param value - Value to check * @returns true if value is not null or undefined */ export declare function isDefined(value: T | null | undefined): value is T; /** * Type guard for functions. * * @param value - Value to check * @returns true if value is a function */ export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown; //# sourceMappingURL=type-guards.d.ts.map