/** * Utility functions for Loro Mirror core */ import { Container, ContainerID, ContainerType, LoroDoc } from "loro-crdt"; import { EqualityStrategy, SchemaType, TransformDefinition } from "../schema/index.js"; import { Change, InferContainerOptions } from "./mirror.js"; /** * Schema type with transform property. */ export type SchemaWithTransform = SchemaType & { transform: TransformDefinition; }; /** * Check if a schema has a transform. * Distinguishes between the .transform() builder method (function) and an actual * TransformDefinition object (with decode/encode functions). */ export declare function hasTransform(schema: SchemaType | undefined): schema is SchemaWithTransform; /** * Get the transform from a schema, or undefined if none exists. */ export declare function getTransform(schema: SchemaType | undefined): TransformDefinition | undefined; /** * Get the effective equality strategy for a transform. * Default: "reference-equality" */ export declare function getEqualityStrategy(schema: SchemaType | undefined, strategyIfNotTransformable: EqualityStrategy): EqualityStrategy; /** * Apply decode transform to a CRDT value. * Null/undefined pass through as-is - transform is only called for real values. */ export declare function applyDecode(schema: SchemaType | undefined, crdtValue: unknown): unknown; /** * Recursively decode JSON values using schema transforms. * Mutates in-place. Used for snapshot initialization where toJSON() skips decode. */ export declare function decodeNestedJsonValues(json: unknown, schema: SchemaType | undefined): unknown; /** * Apply encode transform to a domain value. * Null/undefined pass through as-is - transform is only called for real values. */ export declare function applyEncode(schema: SchemaType | undefined, domainValue: unknown): unknown; /** * Check if two domain values are equal according to the schema's equality strategy. * * Reference equality is always checked first (performance optimization). * If refs match, returns true (no change). * If refs differ, behavior depends on isEqual setting. */ export declare function valuesEqual(schema: SchemaType | undefined, oldValue: unknown, newValue: unknown, strategyIfNotTransformable: EqualityStrategy): boolean; export declare function defineCidProperty(target: unknown, cid: ContainerID): void; /** * Check if a value is an object */ export declare function isObject(value: unknown): value is Record; /** * Recursively removes undefined values from an object. * This treats undefined values as non-existent fields. * Preserves non-enumerable properties like $cid. * Returns the original object if no undefined values are found. * Protects against prototype pollution by skipping unsafe keys. */ export declare function stripUndefined(value: T): T; /** * Performs a deep equality check between two values */ export declare function deepEqual(a: unknown, b: unknown): boolean; /** * Get a value from a nested object using a path array */ export declare function getPathValue(obj: Record, path: string[]): unknown; /** * Set a value in a nested object using a path array * Note: This modifies the object directly (intended for use with Immer) */ export declare function setPathValue(obj: Record, path: string[], value: unknown): void; type ContainerValue = { cid: string; value: unknown; }; export declare function valueIsContainer(value: unknown): value is ContainerValue; export declare function valueIsContainerOfType(value: unknown, containerType: string): value is ContainerValue; export declare function containerIdToContainerType(containerId: ContainerID): ContainerType | undefined; export declare function getRootContainerByType(doc: LoroDoc, key: string, type: ContainerType): Container; export declare function insertChildToMap(containerId: ContainerID | "", key: string, value: unknown, inferOptions?: InferContainerOptions): Change; export declare function tryUpdateToContainer(change: Change, toUpdate: boolean, schema: SchemaType | undefined, inferOptions?: InferContainerOptions): Change; export declare function schemaToContainerType(schema: SchemaType): ContainerType | undefined; export declare function tryInferContainerType(value: unknown, defaults?: InferContainerOptions): ContainerType | undefined; export declare function applySchemaToInferOptions(schema: SchemaType | undefined, base: InferContainerOptions | undefined): InferContainerOptions | undefined; export declare function isValueOfContainerType(containerType: ContainerType, value: unknown): boolean; export declare function inferContainerTypeFromValue(value: unknown, defaults?: InferContainerOptions): "loro-map" | "loro-list" | "loro-text" | "loro-movable-list" | undefined; export type ObjectLike = Record; export type ArrayLike = Array; export declare function isObjectLike(value: unknown): value is ObjectLike; export declare function isArrayLike(value: unknown): value is ArrayLike; export declare function isStringLike(value: unknown): value is string; export declare function isStateAndSchemaOfType(values: { oldState: unknown; newState: unknown; schema: SchemaType | undefined; }, stateGuard: (value: unknown) => value is S, schemaGuard: (schema: SchemaType) => schema is T): values is { oldState: S; newState: S; schema: T | undefined; }; export declare function isTreeID(id: unknown): boolean; /** * Stringify a value safely, handling non-JSON-serializable types. * Handles BigInt, Date, RegExp, functions, and custom objects. */ export declare function safeStringify(value: unknown, indent?: number): string; export {}; //# sourceMappingURL=utils.d.ts.map