/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IFluidHandle } from "@fluidframework/core-interfaces"; import type { IFluidHandleContext, IFluidHandleInternal } from "@fluidframework/core-interfaces/internal"; import { type ISerializedHandle } from "@fluidframework/runtime-utils/internal"; import { type ISharedObjectHandle } from "./handle.js"; /** * @legacy @beta */ export interface IFluidSerializer { /** * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object * where any embedded IFluidHandles have been replaced with a serializable form. * * The original `input` object is not mutated. This method will shallowly clones all objects in the path from * the root to any replaced handles. (If no handles are found, returns the original object.) */ encode(value: unknown, bind: IFluidHandle): unknown; /** * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form. * * The original `input` object is not mutated. This method will shallowly clone all objects in the path from * the root to any replaced handles. (If no handles are found, returns the original object.) * * The decoded handles are implicitly bound to the handle context of this serializer. */ decode(input: unknown): unknown; /** * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent. */ stringify(value: unknown, bind: IFluidHandle): string; /** * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid * handles will be realized as part of the parse */ parse(value: string): unknown; } /** * Data Store serializer implementation * @internal */ export declare class FluidSerializer implements IFluidSerializer { private readonly context; private readonly root; constructor(context: IFluidHandleContext); get IFluidSerializer(): IFluidSerializer; /** * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form. * * The original `input` object is not mutated. This method will shallowly clone all objects in the path from * the root to any replaced handles. (If no handles are found, returns the original object.) * * Any unbound handles encountered are bound to the provided IFluidHandle. */ encode(input: unknown, bind: IFluidHandleInternal): unknown; /** * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form. * * The original `input` object is not mutated. This method will shallowly clone all objects in the path from * the root to any replaced handles. (If no handles are found, returns the original object.) * * The decoded handles are implicitly bound to the handle context of this serializer. */ decode(input: unknown): unknown; /** * Serializes the input object into a JSON string. * Any IFluidHandles in the object will be replaced with their serialized form before stringify, * being bound to the given bind context in the process. */ stringify(input: unknown, bind: IFluidHandle): string; /** * Parses the serialized data - context must match the context with which the JSON was stringified */ parse(input: string): unknown; /** * If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle. * Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'. */ protected encodeValue(value: unknown, bind?: ISharedObjectHandle): unknown; /** * If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle. * Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'. */ protected decodeValue(value: unknown): unknown; /** * Invoked for non-null objects to recursively replace references to IFluidHandles. * Clones as-needed to avoid mutating the `input` object. If no IFluidHandles are present, * returns the original `input`. */ private recursivelyReplace; /** * Encodes the given IFluidHandle into a JSON-serializable form, * also binding it to another node to ensure it attaches at the right time. * @param handle - The IFluidHandle to serialize. * @param bind - The binding context for the handle (the handle will become attached whenever this context is attached). * @returns The serialized handle. */ protected bindAndEncodeHandle(handle: IFluidHandleInternal, bind: ISharedObjectHandle): ISerializedHandle; } //# sourceMappingURL=serializer.d.ts.map