json-joy
Version:
Collection of libraries for building collaborative editing apps.
71 lines (70 loc) • 2.77 kB
TypeScript
import { Model } from '../../model';
import { Log } from '../Log';
import { Patch } from '../../../json-crdt-patch';
import type * as types from './types';
import type { CborDecoder } from '@jsonjoy.com/json-pack/lib/cbor/CborDecoder';
import type { JsonDecoder } from '@jsonjoy.com/json-pack/lib/json/JsonDecoder';
import type { Decoder as SidecarDecoder } from '../../codec/sidecar/binary/Decoder';
import type { Decoder as StructuralDecoderCompact } from '../../codec/structural/compact/Decoder';
import type { Decoder as StructuralDecoderVerbose } from '../../codec/structural/verbose/Decoder';
import type { decode as decodeCompact } from '../../../json-crdt-patch/codec/compact/decode';
import type { decode as decodeVerbose } from '../../../json-crdt-patch/codec/verbose/decode';
export interface LogDecoderOpts {
jsonDecoder?: JsonDecoder;
cborDecoder?: CborDecoder;
structuralCompactDecoder?: StructuralDecoderCompact;
structuralVerboseDecoder?: StructuralDecoderVerbose;
sidecarDecoder?: SidecarDecoder;
patchCompactDecoder?: typeof decodeCompact;
patchVerboseDecoder?: typeof decodeVerbose;
}
export declare class LogDecoder {
protected readonly opts: LogDecoderOpts;
constructor(opts?: LogDecoderOpts);
decode(blob: Uint8Array, params?: DecodeParams): DecodeResult;
decodeNdjsonComponents(blob: Uint8Array): types.LogComponentsWithFrontier;
decodeSeqCborComponents(blob: Uint8Array): types.LogComponentsWithFrontier;
deserialize(components: types.LogComponentsWithFrontier, params?: DeserializeParams): DecodeResult;
deserializeHistory(components: types.LogComponentsWithFrontier): Log;
deserializeModel(serialized: unknown): Model;
deserializePatch(serialized: unknown): Patch;
}
export interface DeserializeParams {
/**
* Whether to return decoded `view` of the end state of the log as a POJO in
* the {@link DecodeResult}.
*/
view?: boolean;
/**
* Whether to return decoded frontier of the log in the {@link DecodeResult}.
*/
frontier?: boolean;
/**
* Whether to return the full history of the log in the {@link DecodeResult}.
*/
history?: boolean;
}
export interface DecodeParams extends DeserializeParams {
/**
* The format of the input binary blob, whether it is NDJSON or CBOR-Sequence
* format.
*/
format?: 'ndjson' | 'seq.cbor';
}
/**
* Decoding result of a log binary blob.
*/
export interface DecodeResult {
/**
* Plain POJO view of the end state of the log.
*/
view?: unknown;
/**
* Final state of the log, the end state of the document.
*/
frontier?: Log;
/**
* The full history of the log, from the start to the end state.
*/
history?: Log;
}