All files / json-crdt-extensions ModelWithExt.ts

84.21% Statements 16/19
100% Branches 1/1
50% Functions 1/2
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39  40x   40x 40x     40x   40x 40x 40x 40x   40x   40x 40x   40x       1567x 1567x 1567x     40x                    
import type * as clock from '../json-crdt-patch/clock';
import * as ext from './ext';
import type {NodeBuilder} from '../json-crdt-patch';
import {Extensions} from '../json-crdt/extensions/Extensions';
import {Model} from '../json-crdt/model';
import type {SchemaToJsonNode} from '../json-crdt/schema/types';
 
const extensions = new Extensions();
 
extensions.register(ext.cnt);
extensions.register(ext.mval);
extensions.register(ext.peritext);
extensions.register(ext.quill);
 
export {ext};
 
export class ModelWithExt {
  public static readonly ext = ext;
 
  public static readonly create = <S extends NodeBuilder>(
    schema?: S,
    sidOrClock: clock.ClockVector | number = Model.sid(),
  ): Model<SchemaToJsonNode<S>> => {
    const model = Model.create(schema, sidOrClock);
    model.ext = extensions;
    return model;
  };
 
  public static readonly load = <S extends NodeBuilder>(
    data: Uint8Array,
    sid?: number,
    schema?: S,
  ): Model<SchemaToJsonNode<S>> => {
    const model = Model.load(data, sid, schema);
    model.ext = extensions;
    return model;
  };
}