@cr_docs_t/dts 0.35.0 → 0.35.1
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.
- package/dist/dts/FugueTree/FTree.d.ts +0 -1
- package/dist/dts/FugueTree/FTree.d.ts.map +1 -1
- package/dist/dts/FugueTree/FTree.js +3 -3
- package/dist/dts/FugueTree/FugueTree.d.ts +4 -1
- package/dist/dts/FugueTree/FugueTree.d.ts.map +1 -1
- package/dist/dts/FugueTree/FugueTree.js +9 -5
- package/dist/tests/unit/AST.test.d.ts +2 -0
- package/dist/tests/unit/AST.test.d.ts.map +1 -0
- package/dist/tests/unit/AST.test.js +111 -0
- package/dist/tests/unit/FTree.test.d.ts +2 -0
- package/dist/tests/unit/FTree.test.d.ts.map +1 -0
- package/dist/tests/unit/FTree.test.js +447 -0
- package/dist/tests/unit/FugueTree.test.d.ts.map +1 -0
- package/dist/tests/unit/FugueTree.test.js +416 -0
- package/dist/tests/unit/mocks/BragiAST-mocks.d.ts +2 -0
- package/dist/tests/unit/mocks/BragiAST-mocks.d.ts.map +1 -0
- package/dist/tests/unit/mocks/BragiAST-mocks.js +1 -0
- package/dist/tests/unit/mocks/FTree-mocks.d.ts +20 -0
- package/dist/tests/unit/mocks/FTree-mocks.d.ts.map +1 -0
- package/dist/tests/unit/mocks/FTree-mocks.js +36 -0
- package/dist/tests/unit/mocks/FugueTree-mocks.d.ts +24 -0
- package/dist/tests/unit/mocks/FugueTree-mocks.d.ts.map +1 -0
- package/dist/tests/unit/mocks/FugueTree-mocks.js +52 -0
- package/dist/tests/utils.d.ts +9 -0
- package/dist/tests/utils.d.ts.map +1 -0
- package/dist/tests/utils.js +47 -0
- package/dist/treesitter/index.d.ts +1 -0
- package/dist/treesitter/index.d.ts.map +1 -1
- package/dist/treesitter/index.js +1 -0
- package/dist/treesitter/utils.d.ts +9 -0
- package/dist/treesitter/utils.d.ts.map +1 -0
- package/dist/treesitter/utils.js +84 -0
- package/dist/wasm/tree-sitter-latex.wasm +0 -0
- package/dist/wasm/web-tree-sitter.wasm +0 -0
- package/package.json +16 -4
- package/dist/tests/FugueList.test.d.ts +0 -2
- package/dist/tests/FugueList.test.d.ts.map +0 -1
- package/dist/tests/FugueList.test.js +0 -8
- package/dist/tests/FugueTree.test.d.ts.map +0 -1
- package/dist/tests/FugueTree.test.js +0 -8
- package/dist/tests/mocks.d.ts +0 -4
- package/dist/tests/mocks.d.ts.map +0 -1
- package/dist/tests/mocks.js +0 -4
- /package/dist/tests/{FugueTree.test.d.ts → unit/FugueTree.test.d.ts} +0 -0
|
@@ -70,7 +70,6 @@ export declare class FTree {
|
|
|
70
70
|
*/
|
|
71
71
|
addNode(id: ID, value: string, parent: FNode, side: NodeSide, rightOriginID?: ID | null): void;
|
|
72
72
|
/**
|
|
73
|
-
* TODO: Maybe change the children types to linked list to make insertions more efficient, since we expect many insertions at the end of the siblings.
|
|
74
73
|
* Inserts a node into the correct position among its parent node's children arrays based on the
|
|
75
74
|
* node's rightOrigin and sender ID, and the existing order of its rightOrigin among its siblings.
|
|
76
75
|
* @param node - The node to insert into its siblings
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FTree.d.ts","sourceRoot":"","sources":["../../../src/dts/FugueTree/FTree.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,EAAE,GAAG;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,EAAE,CAAC;IACP,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,EAAE,KAAK,EAAE,CAAC;IACtB,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,IAAI,EAAE,KAAK,GAAG,KAAK;IAMtC;;;;;OAKG;IACH,iBAAiB,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI;IAoB5C;;;OAGG;IACF,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAiChD;;;;;OAKG;IACH,IAAI,IAAI,UAAU;IAqBlB;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,UAAU;IA0EzB,QAAQ;IAIR,KAAK;CASR"}
|
|
@@ -74,7 +74,6 @@ export class FTree {
|
|
|
74
74
|
this.updateSize(node, 1);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* TODO: Maybe change the children types to linked list to make insertions more efficient, since we expect many insertions at the end of the siblings.
|
|
78
77
|
* Inserts a node into the correct position among its parent node's children arrays based on the
|
|
79
78
|
* node's rightOrigin and sender ID, and the existing order of its rightOrigin among its siblings.
|
|
80
79
|
* @param node - The node to insert into its siblings
|
|
@@ -91,9 +90,10 @@ export class FTree {
|
|
|
91
90
|
let i = 0;
|
|
92
91
|
for (; i < right.length; i++) {
|
|
93
92
|
const sib = right[i];
|
|
94
|
-
const isLessThanSib = this.isLess(
|
|
93
|
+
const isLessThanSib = this.isLess(sib.rightOrigin ?? null, node.rightOrigin ?? null);
|
|
95
94
|
const isEqualRightOrigin = node.rightOrigin === sib.rightOrigin;
|
|
96
|
-
const
|
|
95
|
+
const senderCmp = node.id.sender.localeCompare(sib.id.sender);
|
|
96
|
+
const isGreaterSender = senderCmp > 0 || (senderCmp === 0 && node.id.counter > sib.id.counter);
|
|
97
97
|
if (!(isLessThanSib || (isEqualRightOrigin && isGreaterSender)))
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
@@ -12,7 +12,9 @@ export declare class FugueTree {
|
|
|
12
12
|
userIdentity: string;
|
|
13
13
|
pendingMsgs: Map<string, FugueMessage>;
|
|
14
14
|
readonly batchSize = 800;
|
|
15
|
-
|
|
15
|
+
private lastIndex;
|
|
16
|
+
private lastNode;
|
|
17
|
+
constructor(ws: WebSocket | null, documentID: string, userIdentity: string, replicaID?: string);
|
|
16
18
|
/**
|
|
17
19
|
* Make msg key for pending messages map
|
|
18
20
|
* @param msg - the message to make key for
|
|
@@ -124,6 +126,7 @@ export declare class FugueTree {
|
|
|
124
126
|
* @returns the index of the given node in the visible string
|
|
125
127
|
*/
|
|
126
128
|
getVisibleIndex(node: FNode): number;
|
|
129
|
+
nextNonDescendant(node: FNode): FNode | null;
|
|
127
130
|
getState(): FTree;
|
|
128
131
|
clear(): void;
|
|
129
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FugueTree.d.ts","sourceRoot":"","sources":["../../../src/dts/FugueTree/FugueTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,kCAAkC,CAAC;AAK7F,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,IAAI,CAAQ;IACpB,EAAE,EAAE,SAAS,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"FugueTree.d.ts","sourceRoot":"","sources":["../../../src/dts/FugueTree/FugueTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,kCAAkC,CAAC;AAK7F,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,IAAI,CAAQ;IACpB,EAAE,EAAE,SAAS,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,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,CAAC,EAAE,EAAE,EAAE;IAId;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,KAAK;IAI3B,iBAAiB,CAAC,IAAI,EAAE,KAAK;IAI7B,QAAQ;IAIR,KAAK;CAIR"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { Operation } from "../../types/FugueTree/Message.js";
|
|
2
2
|
import { MessageType } from "../../types/Message.js";
|
|
3
|
-
import { chunkArray
|
|
3
|
+
import { chunkArray } from "../../utils/index.js";
|
|
4
4
|
import { Serializer } from "../Serailizers/General.js";
|
|
5
5
|
import { FTree } from "./FTree.js";
|
|
6
6
|
/**
|
|
7
7
|
* A Fugue Tree CRDT, with insert and delete operations.
|
|
8
8
|
*/
|
|
9
9
|
export class FugueTree {
|
|
10
|
-
constructor(ws, documentID, userIdentity) {
|
|
10
|
+
constructor(ws, documentID, userIdentity, replicaID) {
|
|
11
11
|
this.counter = 0;
|
|
12
|
-
this.replicaID = randomString(3);
|
|
13
12
|
this.pendingMsgs = new Map();
|
|
14
13
|
// Tentative
|
|
15
14
|
this.batchSize = 800;
|
|
15
|
+
this.lastIndex = -1;
|
|
16
|
+
this.lastNode = undefined;
|
|
16
17
|
this.ws = ws;
|
|
17
18
|
this.documentID = documentID;
|
|
18
19
|
this.userIdentity = userIdentity;
|
|
19
20
|
this.tree = new FTree();
|
|
21
|
+
this.replicaID = replicaID ?? crypto.randomUUID();
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Make msg key for pending messages map
|
|
@@ -49,8 +51,6 @@ export class FugueTree {
|
|
|
49
51
|
*/
|
|
50
52
|
insertImpl(index, value) {
|
|
51
53
|
const id = { sender: this.replicaID, counter: this.counter };
|
|
52
|
-
// PERF: optimize by caching the last accessed node and its index,
|
|
53
|
-
// so that if the next insert is nearby, we can start from there instead of the root
|
|
54
54
|
this.counter++;
|
|
55
55
|
const leftOrigin = index === 0 ? this.tree.root : this.tree.getByIndex(this.tree.root, index - 1);
|
|
56
56
|
let msg;
|
|
@@ -329,10 +329,14 @@ export class FugueTree {
|
|
|
329
329
|
getVisibleIndex(node) {
|
|
330
330
|
return this.tree.getVisibleIndex(node);
|
|
331
331
|
}
|
|
332
|
+
nextNonDescendant(node) {
|
|
333
|
+
return this.tree.nextNonDescendant(node);
|
|
334
|
+
}
|
|
332
335
|
getState() {
|
|
333
336
|
return this.tree;
|
|
334
337
|
}
|
|
335
338
|
clear() {
|
|
339
|
+
this.counter = 0;
|
|
336
340
|
return this.tree.clear();
|
|
337
341
|
}
|
|
338
342
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AST.test.d.ts","sourceRoot":"","sources":["../../../src/tests/unit/AST.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { parseCST } from "../../treesitter/types/AST";
|
|
2
|
+
import { getParser } from "./mocks/BragiAST-mocks.js";
|
|
3
|
+
import { breadthFirstAstTraversalFunc, postorderAstTraversalFunc, preoderAstTraversalFunc, } from "../../treesitter/index.js";
|
|
4
|
+
describe("AST Codegen and Parsing", () => {
|
|
5
|
+
let parser;
|
|
6
|
+
let tree = null;
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
parser = await getParser();
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
if (tree) {
|
|
12
|
+
tree.delete();
|
|
13
|
+
tree = null;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
afterAll(() => {
|
|
17
|
+
if (parser) {
|
|
18
|
+
parser.delete();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
describe("parseCST", () => {
|
|
22
|
+
it("should parse a simple LaTeX document into a flat node map", () => {
|
|
23
|
+
const code = `
|
|
24
|
+
\\documentclass{article}
|
|
25
|
+
\\begin{document}
|
|
26
|
+
Hello, World!
|
|
27
|
+
\\end{document}
|
|
28
|
+
`;
|
|
29
|
+
tree = parser.parse(code);
|
|
30
|
+
if (!tree || !tree.rootNode) {
|
|
31
|
+
throw new Error("Parser failed to return a valid tree");
|
|
32
|
+
}
|
|
33
|
+
const ast = parseCST(tree.rootNode);
|
|
34
|
+
expect(ast.rootId).toBeDefined();
|
|
35
|
+
expect(ast.nodes.has(ast.rootId)).toBe(true);
|
|
36
|
+
const root = ast.nodes.get(ast.rootId);
|
|
37
|
+
expect(root?.type).toBe("source_file");
|
|
38
|
+
expect(root?.childrenIds.length).toBeGreaterThan(0);
|
|
39
|
+
root?.childrenIds.forEach((id) => {
|
|
40
|
+
expect(ast.nodes.has(id)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it("should correctly wire parent-child relationships", () => {
|
|
44
|
+
const code = `\\begin{enumerate} \\item test \\end{enumerate}`;
|
|
45
|
+
tree = parser.parse(code);
|
|
46
|
+
if (!tree?.rootNode)
|
|
47
|
+
return;
|
|
48
|
+
const ast = parseCST(tree.rootNode);
|
|
49
|
+
const nodes = Array.from(ast.nodes.values());
|
|
50
|
+
const itemNode = nodes.find((n) => n.type === "enum_item");
|
|
51
|
+
const parentNode = nodes.find((n) => n.id === itemNode?.parentId);
|
|
52
|
+
expect(itemNode).toBeDefined();
|
|
53
|
+
expect(parentNode).toBeDefined();
|
|
54
|
+
expect(parentNode?.type).toBe("generic_environment");
|
|
55
|
+
});
|
|
56
|
+
it("should capture text content for leaf nodes", () => {
|
|
57
|
+
const code = `SpecificTextContent`;
|
|
58
|
+
tree = parser.parse(code);
|
|
59
|
+
if (!tree?.rootNode)
|
|
60
|
+
return;
|
|
61
|
+
const ast = parseCST(tree.rootNode);
|
|
62
|
+
const textNode = Array.from(ast.nodes.values()).find((n) => n.text.includes("SpecificTextContent"));
|
|
63
|
+
expect(textNode).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
it("should throw an error if no root node is provided", () => {
|
|
66
|
+
expect(() => parseCST(null)).toThrow("No root node provided");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("Node Metadata", () => {
|
|
70
|
+
it("should ensure every node in the map has a valid type and text field", () => {
|
|
71
|
+
const code = `\\section{Title}`;
|
|
72
|
+
tree = parser.parse(code);
|
|
73
|
+
if (!tree?.rootNode)
|
|
74
|
+
return;
|
|
75
|
+
const ast = parseCST(tree.rootNode);
|
|
76
|
+
ast.nodes.forEach((node) => {
|
|
77
|
+
expect(typeof node.type).toBe("string");
|
|
78
|
+
expect(typeof node.text).toBe("string");
|
|
79
|
+
expect(node.id).toBeDefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe("AST Traversal", () => {
|
|
84
|
+
let ast;
|
|
85
|
+
beforeAll(() => {
|
|
86
|
+
const code = `\\section{A} Text \\textbf{B}`;
|
|
87
|
+
tree = parser.parse(code);
|
|
88
|
+
if (!tree?.rootNode)
|
|
89
|
+
throw new Error("Parse failed");
|
|
90
|
+
ast = parseCST(tree.rootNode);
|
|
91
|
+
});
|
|
92
|
+
it("should be traversable in Pre-order (Root -> L -> R)", () => {
|
|
93
|
+
const visited = [];
|
|
94
|
+
preoderAstTraversalFunc(ast, (node) => visited.push(node.type));
|
|
95
|
+
expect(visited[0]).toBe("source_file");
|
|
96
|
+
expect(visited.length).toBe(ast.nodes.size);
|
|
97
|
+
});
|
|
98
|
+
it("should be traversable in Post-order (Left -> Right -> Root)", () => {
|
|
99
|
+
const visited = [];
|
|
100
|
+
postorderAstTraversalFunc(ast, (node) => visited.push(node.type));
|
|
101
|
+
expect(visited[visited.length - 1]).toBe("source_file");
|
|
102
|
+
expect(visited.length).toBe(ast.nodes.size);
|
|
103
|
+
});
|
|
104
|
+
it("should be traversable in Breadth-First (Level Order)", () => {
|
|
105
|
+
const visited = [];
|
|
106
|
+
breadthFirstAstTraversalFunc(ast, (node) => visited.push(node.type));
|
|
107
|
+
expect(visited[0]).toBe("source_file");
|
|
108
|
+
expect(visited.length).toBe(ast.nodes.size);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FTree.test.d.ts","sourceRoot":"","sources":["../../../src/tests/unit/FTree.test.ts"],"names":[],"mappings":""}
|