/** * @db4/core - Serialization Helpers * * Utilities for serializing and deserializing documents with type preservation: * - JSON serialization with BigInt, Date, and Buffer support * - Compact binary serialization for efficient storage * - Schema-aware serialization for typed documents * * @packageDocumentation */ import type { Document, StoredDocument } from './types.js'; /** * Type markers for extended JSON serialization. * These prefixes indicate special types that need custom handling. */ export declare const TYPE_MARKERS: { /** BigInt values */ readonly BIGINT: "$bigint:"; /** Date values (ISO string) */ readonly DATE: "$date:"; /** Binary data (base64) */ readonly BINARY: "$binary:"; /** Undefined values */ readonly UNDEFINED: "$undefined"; /** Symbol values */ readonly SYMBOL: "$symbol:"; /** Regular expression */ readonly REGEXP: "$regexp:"; /** Map type */ readonly MAP: "$map:"; /** Set type */ readonly SET: "$set:"; }; /** * Options for extended JSON serialization. */ export interface SerializationOptions { /** Include undefined values as $undefined markers */ preserveUndefined?: boolean; /** Pretty print JSON output */ pretty?: boolean; /** Custom replacers for additional types */ replacers?: Array<(key: string, value: unknown) => unknown>; /** Maximum depth for nested objects (default: 100) */ maxDepth?: number; } /** * Options for extended JSON deserialization. */ export interface DeserializationOptions { /** Custom revivers for additional types */ revivers?: Array<(key: string, value: unknown) => unknown>; /** Revive dates from ISO strings */ reviveDates?: boolean; /** Revive BigInts from $bigint markers */ reviveBigInts?: boolean; } /** * Serializes a value to extended JSON, preserving special types. */ export declare function serialize(value: unknown, options?: SerializationOptions): string; /** * Deserializes extended JSON back to values with type restoration. */ export declare function deserialize(json: string, options?: DeserializationOptions): T; /** * Serializes a document for storage. */ export declare function serializeDocument(doc: Document, options?: SerializationOptions): string; /** * Deserializes a stored document. */ export declare function deserializeDocument(json: string, options?: DeserializationOptions): T; /** * Serializes a stored document with metadata. */ export declare function serializeStoredDocument(doc: StoredDocument, options?: SerializationOptions): string; /** * Deserializes a stored document with metadata. */ export declare function deserializeStoredDocument(json: string, options?: DeserializationOptions): T; /** * Encodes a value to compact binary format. */ export declare function encodeBinary(value: unknown): Uint8Array; /** * Decodes a value from compact binary format. */ export declare function decodeBinary(data: Uint8Array): unknown; /** * Converts ArrayBuffer to base64 string. */ export declare function arrayBufferToBase64(buffer: Uint8Array | ArrayBuffer): string; /** * Converts base64 string to ArrayBuffer. */ export declare function base64ToArrayBuffer(base64: string): Uint8Array; /** * Schema field type for serialization. */ export interface SerializationFieldType { type: 'string' | 'number' | 'boolean' | 'date' | 'binary' | 'bigint' | 'json' | 'array' | 'object'; elementType?: SerializationFieldType; fields?: Record; } /** * Schema definition for serialization. */ export interface SerializationSchema { fields: Record; } /** * Serializes a document according to a schema. * Optimizes serialization based on known types. */ export declare function serializeWithSchema(doc: T, schema: SerializationSchema): string; /** * Deserializes a document according to a schema. */ export declare function deserializeWithSchema(json: string, schema: SerializationSchema): T; //# sourceMappingURL=serialization.d.ts.map