muschema
Version:
Schemas for mudb
26 lines (25 loc) • 1.13 kB
TypeScript
import { MuWriteStream, MuReadStream } from 'mustreams';
import { MuSchema } from './schema';
export interface _TypeDataPair<SubTypes extends {
[type: string]: MuSchema<any>;
}> {
type: keyof SubTypes;
data: SubTypes[keyof SubTypes]['identity'];
}
export declare class MuUnion<SubTypes extends {
[type: string]: MuSchema<any>;
}> implements MuSchema<_TypeDataPair<SubTypes>> {
private _types;
readonly identity: _TypeDataPair<SubTypes>;
readonly muType: string;
readonly muData: SubTypes;
readonly json: object;
constructor(schemaSpec: SubTypes, identityType?: keyof SubTypes);
alloc(): _TypeDataPair<SubTypes>;
free(data: _TypeDataPair<SubTypes>): void;
equal(x: _TypeDataPair<SubTypes>, y: _TypeDataPair<SubTypes>): boolean;
clone(data: _TypeDataPair<SubTypes>): _TypeDataPair<SubTypes>;
copy(source: _TypeDataPair<SubTypes>, target: _TypeDataPair<SubTypes>): void;
diff(base: _TypeDataPair<SubTypes>, target: _TypeDataPair<SubTypes>, stream: MuWriteStream): boolean;
patch(base: _TypeDataPair<SubTypes>, stream: MuReadStream): _TypeDataPair<SubTypes>;
}