All files / json-crdt-repo/src/__tests__/e2e codecs.ts

33.33% Statements 9/27
0% Branches 0/5
0% Functions 0/2
28% Lines 7/25

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 612x 2x 2x 2x 2x             2x                                                                                     2x            
import {Writer} from '@jsonjoy.com/buffers/lib/Writer';
import {Codecs} from '@jsonjoy.com/json-pack/lib/codecs/Codecs';
import {RpcCodecs} from '@jsonjoy.com/rpc-codec/lib/RpcCodecs';
import {RpcMessageCodecs} from '@jsonjoy.com/rpc-codec/lib/RpcMessageCodecs';
import {RpcCodec} from '@jsonjoy.com/rpc-codec/lib/RpcCodec';
 
export interface SetupCodecsOpts {
  skipJson2?: boolean;
  onlyCommon?: boolean;
}
 
export const setupCodecs = (opts: SetupCodecsOpts = {}) => {
  const codecs = new RpcCodecs(new Codecs(new Writer() as any), new RpcMessageCodecs());
  const {binary, compact, jsonRpc2} = codecs.msg;
  const {json, cbor, msgpack} = codecs.val;
  const list: RpcCodec<any>[] = [
    new RpcCodec(compact, json, json),
    new RpcCodec(compact, cbor, cbor),
    new RpcCodec(binary, cbor, cbor),
  ];
  if (!opts.onlyCommon) {
    list.push(new RpcCodec(compact, msgpack, msgpack));
    list.push(new RpcCodec(compact, json, cbor));
    // list.push(new RpcCodec(compact, json, msgpack));
    // list.push(new RpcCodec(compact, cbor, json));
    // list.push(new RpcCodec(compact, cbor, msgpack));
    // list.push(new RpcCodec(compact, msgpack, json));
    // list.push(new RpcCodec(compact, msgpack, cbor));
    list.push(new RpcCodec(binary, msgpack, msgpack));
    list.push(new RpcCodec(binary, json, json));
    // list.push(new RpcCodec(binary, json, cbor));
    // list.push(new RpcCodec(binary, json, msgpack));
    // list.push(new RpcCodec(binary, cbor, json));
    // list.push(new RpcCodec(binary, cbor, msgpack));
    // list.push(new RpcCodec(binary, msgpack, json));
    // list.push(new RpcCodec(binary, msgpack, cbor));
    if (!opts.skipJson2) {
      list.push(new RpcCodec(jsonRpc2, json, json));
      list.push(new RpcCodec(jsonRpc2, cbor, cbor));
      list.push(new RpcCodec(jsonRpc2, msgpack, msgpack));
      // list.push(new RpcCodec(jsonRpc2, json, cbor));
      // list.push(new RpcCodec(jsonRpc2, json, msgpack));
      // list.push(new RpcCodec(jsonRpc2, cbor, json));
      // list.push(new RpcCodec(jsonRpc2, cbor, msgpack));
      // list.push(new RpcCodec(jsonRpc2, msgpack, json));
      // list.push(new RpcCodec(jsonRpc2, msgpack, cbor));
    }
  }
  return {
    codecs,
    list,
  };
};
 
export const cborCodec = () => {
  const codecs = new RpcCodecs(new Codecs(new Writer() as any), new RpcMessageCodecs());
  const {binary} = codecs.msg;
  const {cbor} = codecs.val;
  return new RpcCodec(binary, cbor, cbor);
};