@cr_docs_t/dts 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"FugueList.d.ts","sourceRoot":"","sources":["../../src/Fugue/FugueList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,YAAY,EAAa,MAAM,qBAAqB,CAAC;AAE9D;;GAEG;AACH,qBAAa,SAAS,CAAC,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAM;IAC1B,UAAU,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;IACvC,eAAe,SAAK;IACpB,EAAE,EAAE,SAAS,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,SAAS,OAAO;gBAEb,UAAU,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM;IAM5F;;;OAGG;IACH,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,oBAAoB;IAmB5B;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAqBxB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAenC;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAgD3C;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAajD;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,MAAM,GAAG,SA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K,EAAE,MAAM;IAenC;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAgD3C;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAajD;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,MAAM,GAAG,SAAS;IAejD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM;IAqBpB;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAoD3C;;;OAGG;IACH,OAAO,IAAI,MAAM;IAmBjB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAcpB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAqGnB;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE;IAW/C,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,cAAc;CAOjB"}
@@ -1,5 +1,6 @@
1
1
  import { FNode } from "./FNode.js";
2
2
  import { Operation } from "../types/Message.js";
3
+ import { FugueMessageSerialzier } from "../Serailizers/index.js";
3
4
  /**
4
5
  * A Fugue List CRDT, with insert and delete operations
5
6
  */
@@ -19,7 +20,8 @@ export class FugueList {
19
20
  propagate(msg) {
20
21
  if (!this.ws)
21
22
  return;
22
- this.ws.send(JSON.stringify(msg));
23
+ const serializedFugueMsg = FugueMessageSerialzier.serialize(Array.isArray(msg) ? msg : [msg]);
24
+ this.ws.send(serializedFugueMsg);
23
25
  }
24
26
  binarySearchPosition(position) {
25
27
  let low = 0;
@@ -275,10 +277,10 @@ export class FugueList {
275
277
  const nodes = idx
276
278
  .filter((n) => n.value !== undefined)
277
279
  .sort((a, b) => this.totalOrder.compare(a.position, b.position));
278
- // Then append to resultdkjand if somehow
279
- //a value is undefined append the placeholder thorn
280
+ // Then append to result jand if somehow
281
+ // a value is undefined append empty string
280
282
  for (const n of nodes) {
281
- res += n.value || "Þ";
283
+ res += n.value || "";
282
284
  }
283
285
  }
284
286
  return res.toString();
@@ -0,0 +1,9 @@
1
+ import { FugueMessageType } from "../../types/Message.js";
2
+ declare function serialize<P>(msgs: FugueMessageType<P>[]): Uint8Array<ArrayBuffer>;
3
+ declare function deserialize<P>(data: Uint8Array): FugueMessageType<P>[];
4
+ export declare const FugueMessageSerialzier: {
5
+ serialize: typeof serialize;
6
+ deserialize: typeof deserialize;
7
+ };
8
+ export {};
9
+ //# sourceMappingURL=Message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../src/Serailizers/Fugue/Message.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,gBAAgB,EAAa,MAAM,wBAAwB,CAAC;AAErG,iBAAS,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,2BAEhD;AAED,iBAAS,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAM/D;AAmCD,eAAO,MAAM,sBAAsB;;;CAGlC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { encode, decode } from "@msgpack/msgpack";
2
+ import { Operation } from "../../types/Message.js";
3
+ function serialize(msgs) {
4
+ return encode(msgs.map((m) => toTuple(m)));
5
+ }
6
+ function deserialize(data) {
7
+ const dec = decode(data);
8
+ if (Array.isArray(dec) && Array.isArray(dec[0])) {
9
+ return dec.map((t) => fromTuple(t));
10
+ }
11
+ return [fromTuple(dec)];
12
+ }
13
+ function toTuple(msg) {
14
+ // Check if msg is of FugueJoinMessage type
15
+ switch (msg.operation) {
16
+ case Operation.JOIN:
17
+ return [msg.operation, msg.documentID, msg.state];
18
+ case Operation.INSERT:
19
+ case Operation.DELETE:
20
+ return [msg.operation, msg.documentID, msg.replicaId, msg.position, msg.data];
21
+ }
22
+ throw new Error("Unknown message type");
23
+ }
24
+ function fromTuple(tuple) {
25
+ switch (tuple[0]) {
26
+ case Operation.JOIN:
27
+ return {
28
+ operation: tuple[0],
29
+ documentID: tuple[1],
30
+ state: tuple[2],
31
+ };
32
+ case Operation.INSERT:
33
+ case Operation.DELETE:
34
+ return {
35
+ operation: tuple[0],
36
+ documentID: tuple[1],
37
+ replicaId: tuple[2],
38
+ position: tuple[3],
39
+ data: tuple[4],
40
+ };
41
+ }
42
+ throw new Error("Unknown tuple format");
43
+ }
44
+ export const FugueMessageSerialzier = {
45
+ serialize,
46
+ deserialize,
47
+ };
@@ -0,0 +1,9 @@
1
+ import { FugueState } from "../../types/Fugue.js";
2
+ declare function serialize(state: FugueState<string>): Uint8Array<ArrayBufferLike>;
3
+ declare function deserialize(compressed: Uint8Array<ArrayBufferLike>): FugueState<string>;
4
+ export declare const FugueStateSerializer: {
5
+ serialize: typeof serialize;
6
+ deserialize: typeof deserialize;
7
+ };
8
+ export {};
9
+ //# sourceMappingURL=State.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../src/Serailizers/Fugue/State.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,iBAAS,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,eAAe,CAAC,CAKzE;AAED,iBAAS,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAIhF;AAED,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { encode, decode } from "@msgpack/msgpack";
2
+ import { compress, decompress } from "lz4js";
3
+ function serialize(state) {
4
+ // const flat = state.flatMap((c) => c.map((n) => [n.position, n.value]));
5
+ const bin = encode(state);
6
+ const com = compress(bin);
7
+ return com;
8
+ }
9
+ function deserialize(compressed) {
10
+ const raw = decompress(compressed);
11
+ const state = decode(raw);
12
+ return state;
13
+ }
14
+ export const FugueStateSerializer = {
15
+ serialize,
16
+ deserialize,
17
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./Fugue/State.js";
2
+ export * from "./Fugue/Message.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Serailizers/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./Fugue/State.js";
2
+ export * from "./Fugue/Message.js";
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * from "./TotalOrder/UniquelyDenseTotalOrder.js";
4
4
  export * from "./TotalOrder/StringTotalOrder.js";
5
5
  export * from "./types/Message.js";
6
6
  export * from "./types/Fugue.js";
7
+ export * from "./Serailizers/index.js";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export * from "./TotalOrder/UniquelyDenseTotalOrder.js";
4
4
  export * from "./TotalOrder/StringTotalOrder.js";
5
5
  export * from "./types/Message.js";
6
6
  export * from "./types/Fugue.js";
7
+ export * from "./Serailizers/index.js";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FugueList.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FugueList.test.d.ts","sourceRoot":"","sources":["../../src/tests/FugueList.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { emptyFugueList } from "./mocks";
2
+ describe("Fugue List Tests", () => {
3
+ describe("Given a Fugue list ", () => {
4
+ test("Empty Fugue List has an empty string", () => {
5
+ expect(emptyFugueList.observe()).toBe('');
6
+ });
7
+ });
8
+ });
@@ -0,0 +1,3 @@
1
+ import { FugueList } from "../Fugue/FugueList";
2
+ export declare const emptyFugueList: FugueList<string>;
3
+ //# sourceMappingURL=mocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,eAAO,MAAM,cAAc,mBAAmI,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { FugueList } from "../Fugue/FugueList";
2
+ import crypto from "crypto";
3
+ import { StringTotalOrder } from "../TotalOrder/StringTotalOrder";
4
+ export const emptyFugueList = new FugueList(new StringTotalOrder(crypto.randomBytes(3).toString('hex')), null, crypto.randomBytes(24).toString('hex'));
@@ -6,13 +6,16 @@ export declare enum Operation {
6
6
  }
7
7
  export type Data = string;
8
8
  export interface FugueMessage<P> {
9
+ operation: Operation.INSERT | Operation.DELETE;
9
10
  documentID: string;
10
11
  replicaId: string;
11
- operation: Operation;
12
12
  position: P;
13
13
  data: Data | null;
14
14
  }
15
15
  export interface FugueJoinMessage<P> {
16
- state: FugueState<P>;
16
+ operation: Operation.JOIN;
17
+ documentID: string;
18
+ state: FugueState<P> | null;
17
19
  }
20
+ export type FugueMessageType<P> = FugueMessage<P> | FugueJoinMessage<P>;
18
21
  //# sourceMappingURL=Message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/types/Message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,oBAAY,SAAS;IACjB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,IAAI,IAAA;CACP;AAED,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,CAAC,CAAC;IACZ,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACxB"}
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/types/Message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,oBAAY,SAAS;IACjB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,IAAI,IAAA;CACP;AAED,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,CAAC,CAAC;IACZ,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@cr_docs_t/dts",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "type": "module",
6
7
  "types": "dist/index.d.ts",
7
8
  "scripts": {
8
9
  "build": "tsc",
9
10
  "prepublishOnly": "npm run build",
10
11
  "ci": "npm install && npm run build",
11
- "publish": "npm publish --access public"
12
+ "publish": "npm publish --access public",
13
+ "test": "jest"
12
14
  },
13
15
  "exports": {
14
16
  ".": {
@@ -56,11 +58,19 @@
56
58
  "devDependencies": {
57
59
  "@semantic-release/changelog": "^6.0.3",
58
60
  "@semantic-release/git": "^10.0.1",
61
+ "@types/jest": "^30.0.0",
62
+ "@types/lz4js": "^0.2.2",
59
63
  "@types/node": "^24.10.1",
64
+ "jest": "^30.2.0",
60
65
  "semantic-release": "^25.0.2",
66
+ "ts-jest": "^29.4.6",
61
67
  "typescript": "^5.9.3"
62
68
  },
63
69
  "files": [
64
70
  "dist"
65
- ]
71
+ ],
72
+ "dependencies": {
73
+ "@msgpack/msgpack": "^3.1.3",
74
+ "lz4js": "^0.2.0"
75
+ }
66
76
  }