@cr_docs_t/dts 0.31.0 → 0.32.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/dts/Fugue/FugueList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAa,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAGnF;;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,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,SAAS,OAAO;gBAGrB,UAAU,EAAE,uBAAuB,CAAC,CAAC,CAAC,EACtC,EAAE,EAAE,SAAS,GAAG,IAAI,EACpB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM;IAQzB;;;OAGG;IACH,OAAO,CAAC,SAAS;IAQjB,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;IAiD3C;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAajD;;;;;OAKG;IACH,gBAAgB,CAAC,Q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,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;IAiD3C;;;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;IAqD3C;;;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,6 +1,7 @@
1
1
  import { FListNode } from "./FNode.js";
2
2
  import { Operation } from "../../types/Fugue/index.js";
3
3
  import { FugueMessageSerialzier } from "../Serailizers/Fugue/index.js";
4
+ import { logger } from "../../utils/logging.js";
4
5
  /**
5
6
  * A Fugue List CRDT, with insert and delete operations
6
7
  */
@@ -204,7 +205,7 @@ export class FugueList {
204
205
  delete(index) {
205
206
  const position = this.findVisiblePosition(index);
206
207
  if (!position) {
207
- console.warn(`No element at position -> ${position}`);
208
+ logger.warn(`No element at position -> ${position}`);
208
209
  return;
209
210
  }
210
211
  this.deleteAtPosition(position);
@@ -11,7 +11,7 @@ export declare class FugueTree {
11
11
  readonly replicaID: string;
12
12
  userIdentity: string;
13
13
  pendingMsgs: Map<string, FugueMessage>;
14
- readonly batchSize = 400;
14
+ readonly batchSize = 800;
15
15
  constructor(ws: WebSocket | null, documentID: string, userIdentity: string);
16
16
  /**
17
17
  * Make msg key for pending messages map
@@ -23,7 +23,7 @@ export declare class FugueTree {
23
23
  * Propagates message or messages to replicas
24
24
  * @param msg - Message or messages to propagate to replicas
25
25
  */
26
- private propagate;
26
+ propagate(msg: FugueMessage | FugueMessage[]): Promise<void>;
27
27
  /**
28
28
  * Inserts a value at the given index and returns the corresponding FugueMessage.
29
29
  * @param index - the index to insert the value at
@@ -42,7 +42,7 @@ export declare class FugueTree {
42
42
  * @param index - the index to insert the value at
43
43
  * @param value - the value to insert
44
44
  */
45
- insert(index: number, value: string): void;
45
+ insert(index: number, value: string): FugueMessage;
46
46
  /**
47
47
  * Deletes the value at the given index and returns the corresponding FugueMessage.
48
48
  * @param index - the index to delete the value at
@@ -94,6 +94,7 @@ export declare class FugueTree {
94
94
  * @returns the visible string represented by the tree, which is the concatenation of values of non-deleted nodes in traversal order
95
95
  */
96
96
  observe(): string;
97
+ traverse(): IterableIterator<string>;
97
98
  /**
98
99
  * Serializes the tree into a Uint8Array.
99
100
  * @returns a Uint8Array representing the serialized tree.
@@ -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;AAI7F,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,SAAmB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,4BAAmC;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MAAM;IAIhB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAWjB,QAAQ;IAIR;;;OAGG;IACH,IAAI,IAAI,UAAU;IAKlB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAK5B;;;;;OAKG;IACH,SAAS,IAAI,MAAM;IAInB;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,EAAE;IAId;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,KAAK;IAI3B,QAAQ;IAIR,KAAK;CAGR"}
@@ -1,7 +1,7 @@
1
1
  import { Operation } from "../../types/FugueTree/Message.js";
2
2
  import { MessageType } from "../../types/Message.js";
3
- import { randomString } from "../../utils/index.js";
4
- import { FugueMessageSerialzier } from "../Serailizers/FugueTree/index.js";
3
+ import { chunkArray, randomString } from "../../utils/index.js";
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.
@@ -12,7 +12,7 @@ export class FugueTree {
12
12
  this.replicaID = randomString(3);
13
13
  this.pendingMsgs = new Map();
14
14
  // Tentative
15
- this.batchSize = 400;
15
+ this.batchSize = 800;
16
16
  this.ws = ws;
17
17
  this.documentID = documentID;
18
18
  this.userIdentity = userIdentity;
@@ -30,12 +30,16 @@ export class FugueTree {
30
30
  * Propagates message or messages to replicas
31
31
  * @param msg - Message or messages to propagate to replicas
32
32
  */
33
- propagate(msg) {
33
+ async propagate(msg) {
34
+ // Batch send messages in the propagate function,
35
+ // since some operations (e.g. paste or delete a large chunk of text) can generate a
36
+ // large number of messages that would be inefficient to send one by one.
34
37
  if (!this.ws)
35
38
  return;
36
- const allMsgs = Array.isArray(msg) ? msg : [msg];
37
- const serializedFugueMsg = FugueMessageSerialzier.serialize(allMsgs);
38
- this.ws.send(serializedFugueMsg);
39
+ for (const batch of chunkArray(Array.isArray(msg) ? msg : [msg], this.batchSize)) {
40
+ const bytes = Serializer.serialize(batch);
41
+ this.ws.send(bytes);
42
+ }
39
43
  }
40
44
  /**
41
45
  * Inserts a value at the given index and returns the corresponding FugueMessage.
@@ -97,30 +101,14 @@ export class FugueTree {
97
101
  */
98
102
  insertMultiple(index, values) {
99
103
  let msgs = [];
100
- let returnedMsgs = []; //we need this to return messages whether or not we're online
101
104
  for (let i = 0; i < values.length; i++) {
102
105
  const val = values[i];
103
106
  const idx = index + i;
104
107
  const msg = this.insertImpl(idx, val);
105
108
  this.tree.addNode(msg.id, val, this.tree.getByID(msg.parent), msg.side, msg.rightOrigin);
106
109
  msgs.push(msg);
107
- returnedMsgs.push(msg);
108
- // Propagate this batch
109
- if (msgs.length >= this.batchSize) {
110
- if (this.ws?.readyState === WebSocket.OPEN) {
111
- this.propagate(msgs);
112
- msgs = [];
113
- }
114
- }
115
110
  }
116
- // Propagate any remaining messages that didn't fill up the last batch
117
- if (msgs.length > 0) {
118
- if (this.ws?.readyState === WebSocket.OPEN) {
119
- this.propagate(msgs);
120
- msgs = [];
121
- }
122
- }
123
- return returnedMsgs;
111
+ return msgs;
124
112
  }
125
113
  /**
126
114
  * Inserts a value at the given index and propagates the corresponding FugueMessage to replicas.
@@ -130,7 +118,7 @@ export class FugueTree {
130
118
  insert(index, value) {
131
119
  const msg = this.insertImpl(index, value);
132
120
  this.tree.addNode(msg.id, value, this.tree.getByID(msg.parent), msg.side, msg.rightOrigin);
133
- this.propagate(msg);
121
+ return msg;
134
122
  }
135
123
  /**
136
124
  * Deletes the value at the given index and returns the corresponding FugueMessage.
@@ -163,27 +151,11 @@ export class FugueTree {
163
151
  */
164
152
  deleteMultiple(index, length) {
165
153
  let msgs = [];
166
- let returnedMsgs = [];
167
154
  for (let i = 0; i < length; i++) {
168
155
  const msg = this.deleteImpl(index);
169
156
  msgs.push(msg);
170
- returnedMsgs.push(msg);
171
- // Propagate this batch
172
- if (msgs.length >= this.batchSize) {
173
- if (this.ws?.readyState === WebSocket.OPEN) {
174
- this.propagate(msgs);
175
- msgs = [];
176
- }
177
- }
178
157
  }
179
- // Propagate any remaining messages that didn't fill up the last batch
180
- if (msgs.length > 0) {
181
- if (this.ws?.readyState === WebSocket.OPEN) {
182
- this.propagate(msgs);
183
- msgs = [];
184
- }
185
- }
186
- return returnedMsgs;
158
+ return msgs;
187
159
  }
188
160
  /**
189
161
  * Deletes the value at the given index and propagates the corresponding FugueMessage to replicas.
@@ -312,6 +284,9 @@ export class FugueTree {
312
284
  }
313
285
  return res;
314
286
  }
287
+ traverse() {
288
+ return this.tree.traverse(this.tree.root);
289
+ }
315
290
  /**
316
291
  * Serializes the tree into a Uint8Array.
317
292
  * @returns a Uint8Array representing the serialized tree.
@@ -1 +1 @@
1
- {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../../src/dts/Serailizers/FugueTree/Message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,mCAAmC,CAAC;AAGvF,iBAAS,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,2BAS1C;AAED,iBAAS,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAMzD;AAED,eAAO,MAAM,sBAAsB;;;CAGlC,CAAC"}
1
+ {"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../../src/dts/Serailizers/FugueTree/Message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,mCAAmC,CAAC;AAGvF,iBAAS,SAAS,CAAC,IAAI,EAAE,gBAAgB,EAAE,2BAU1C;AAED,iBAAS,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAMzD;AAED,eAAO,MAAM,sBAAsB;;;CAGlC,CAAC"}
@@ -8,7 +8,8 @@ function serialize(msgs) {
8
8
  const buff = new Uint8Array(enced.length + 1);
9
9
  buff[0] = MessageType.FUGUE;
10
10
  buff.set(enced, 1);
11
- return buff;
11
+ let bytes = buff;
12
+ return bytes;
12
13
  }
13
14
  function deserialize(data) {
14
15
  if (data.length === 0)
@@ -1,6 +1,6 @@
1
1
  import { FTree } from "../../FugueTree/index.js";
2
2
  declare function serialize(state: FTree): Uint8Array<ArrayBufferLike>;
3
- declare function deserialize(compressed: Uint8Array<ArrayBufferLike>): FTree;
3
+ declare function deserialize(bytes: Uint8Array<ArrayBufferLike>): FTree;
4
4
  export declare const FugueStateSerializer: {
5
5
  serialize: typeof serialize;
6
6
  deserialize: typeof deserialize;
@@ -1 +1 @@
1
- {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/dts/Serailizers/FugueTree/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEjD,iBAAS,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAAC,eAAe,CAAC,CAG5D;AAED,iBAAS,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,KAAK,CAMnE;AAED,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC"}
1
+ {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/dts/Serailizers/FugueTree/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIjD,iBAAS,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAAC,eAAe,CAAC,CAO5D;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,KAAK,CAO9D;AAED,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC"}
@@ -1,13 +1,20 @@
1
1
  import { FTree } from "../../FugueTree/index.js";
2
+ import { COMP } from "../General.js";
3
+ import Pako from "pako";
2
4
  function serialize(state) {
3
5
  // return compress(state.save())
4
- return state.save();
6
+ let bytes = state.save();
7
+ if (COMP) {
8
+ bytes = Pako.gzip(bytes);
9
+ }
10
+ return bytes;
5
11
  }
6
- function deserialize(compressed) {
7
- // const raw = decompress(compressed);
8
- const raw = compressed;
12
+ function deserialize(bytes) {
13
+ if (COMP) {
14
+ bytes = Pako.ungzip(bytes);
15
+ }
9
16
  const state = new FTree();
10
- state.load(raw);
17
+ state.load(bytes);
11
18
  return state;
12
19
  }
13
20
  export const FugueStateSerializer = {
@@ -2,9 +2,10 @@ import { BasePresenceMessage } from "../../types/Presence.js";
2
2
  import { BaseMessage } from "../../types/Message.js";
3
3
  import { BaseFugueMessage } from "../../types/index.js";
4
4
  export type Message = BaseFugueMessage[] | BasePresenceMessage[];
5
+ export declare const COMP = true;
5
6
  declare function serialize(msgs: BaseMessage | BaseMessage[]): Uint8Array;
6
7
  declare function deserialize(bytes: Uint8Array): Message;
7
- export declare const Seralizer: {
8
+ export declare const Serializer: {
8
9
  serialize: typeof serialize;
9
10
  deserialize: typeof deserialize;
10
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"General.d.ts","sourceRoot":"","sources":["../../../src/dts/Serailizers/General.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAe,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIxD,MAAM,MAAM,OAAO,GAAG,gBAAgB,EAAE,GAAG,mBAAmB,EAAE,CAAC;AAEjE,iBAAS,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,EAAE,GAAG,UAAU,CAchE;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAgB/C;AAED,eAAO,MAAM,SAAS;;;CAGrB,CAAC"}
1
+ {"version":3,"file":"General.d.ts","sourceRoot":"","sources":["../../../src/dts/Serailizers/General.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAe,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAMxD,MAAM,MAAM,OAAO,GAAG,gBAAgB,EAAE,GAAG,mBAAmB,EAAE,CAAC;AAEjE,eAAO,MAAM,IAAI,OAAO,CAAC;AAIzB,iBAAS,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,EAAE,GAAG,UAAU,CAyBhE;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAyB/C;AAED,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
@@ -1,37 +1,60 @@
1
1
  import { MessageType } from "../../types/Message.js";
2
2
  import { FugueMessageSerialzier } from "./FugueTree/Message.js";
3
3
  import { PresenceMessageSerializer } from "./Presence.js";
4
+ import Pako from "pako";
5
+ import { logger } from "../../utils/logging.js";
6
+ export const COMP = true;
7
+ const COMPRESSION_CUTOFF = 1024; // Only compress messages larger than 1KB
8
+ logger.log(`Using compression -> ${COMP}`);
4
9
  function serialize(msgs) {
5
10
  const msgArr = Array.isArray(msgs) ? msgs : [msgs];
6
11
  const type = msgArr[0].msgType;
12
+ let bytes;
7
13
  switch (type) {
8
14
  case MessageType.FUGUE:
9
- return FugueMessageSerialzier.serialize(msgArr);
15
+ bytes = FugueMessageSerialzier.serialize(msgArr);
16
+ break;
10
17
  case MessageType.PRESENCE:
11
- return PresenceMessageSerializer.serialize(msgArr);
18
+ bytes = PresenceMessageSerializer.serialize(msgArr);
19
+ break;
12
20
  default:
13
21
  // Exhastive check to make sure we handled all message types
14
22
  const _exhaustiveCheck = type;
15
23
  throw new Error(`Unsupported message type: ${type}`);
16
24
  }
25
+ if (COMP) {
26
+ // Only compress if the payload is at least the COMPRESSION_CUTOFF to avoid overhead of compression for small messages
27
+ if (bytes.length >= COMPRESSION_CUTOFF) {
28
+ bytes = Pako.gzip(bytes);
29
+ }
30
+ }
31
+ return bytes;
17
32
  }
18
33
  function deserialize(bytes) {
19
34
  if (bytes.length === 0)
20
35
  return [];
21
- // Read magic byte to determine message type
22
- const type = bytes[0];
36
+ let data = bytes;
37
+ // Check for Gzip Magic Bytes: 0x1f (31) and 0x8b (139), indicating the data is compressed with gzip
38
+ if (data.length > 2 && data[0] === 0x1f && data[1] === 0x8b) {
39
+ try {
40
+ data = Pako.ungzip(data);
41
+ }
42
+ catch (e) {
43
+ throw e;
44
+ }
45
+ }
46
+ const type = data[0];
23
47
  switch (type) {
24
48
  case MessageType.FUGUE:
25
- return FugueMessageSerialzier.deserialize(bytes);
49
+ return FugueMessageSerialzier.deserialize(data);
26
50
  case MessageType.PRESENCE:
27
- return PresenceMessageSerializer.deserialize(bytes);
51
+ return PresenceMessageSerializer.deserialize(data);
28
52
  default:
29
- // Exhastive check to make sure we handled all message types
30
53
  const _exhaustiveCheck = type;
31
54
  throw new Error(`Unsupported message type: ${type}`);
32
55
  }
33
56
  }
34
- export const Seralizer = {
57
+ export const Serializer = {
35
58
  serialize,
36
59
  deserialize,
37
60
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./dts/index.js";
2
2
  export * from "./types/index.js";
3
3
  export * from "./utils/index.js";
4
+ export * from "./utils/logging.js";
4
5
  export * from "./misc/index.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./dts/index.js";
2
2
  export * from "./types/index.js";
3
3
  export * from "./utils/index.js";
4
+ export * from "./utils/logging.js";
4
5
  export * from "./misc/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/misc/fetch/index.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IAEpB,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM,GAAG,SAAS;IAC9B,IAAI,EAAE,GAAG;gBAHT,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,MAAM,GAAG,SAAqB,EAC1C,IAAI,GAAE,GAAU;CAK9B;AAED,cAAM,KAAK;IACP,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAc;gBAExB,OAAO,GAAE,MAAW;IAWhC;;OAEG;YACW,OAAO;IAmDf,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAItD,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ7E,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ5E,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;CAGlE;AAED,eAAO,MAAM,CAAC,OAAc,CAAC;AAC7B,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/misc/fetch/index.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAS,SAAQ,KAAK;IAEpB,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM,GAAG,SAAS;IAC9B,IAAI,EAAE,GAAG;gBAHT,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,MAAM,GAAG,SAAqB,EAC1C,IAAI,GAAE,GAAU;CAK9B;AAED,cAAM,KAAK;IACP,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAc;gBAExB,OAAO,GAAE,MAAW;IAWhC;;OAEG;YACW,OAAO;IAmDf,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAItD,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ7E,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ5E,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;CAGlE;AAED,eAAO,MAAM,CAAC,OAAc,CAAC;AAC7B,eAAe,KAAK,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { logger } from "../../utils/logging.js";
1
2
  export class APIError extends Error {
2
3
  constructor(message, status, statusText = undefined, data = null) {
3
4
  super(message);
@@ -42,7 +43,7 @@ class Fetch {
42
43
  catch {
43
44
  errorData = null;
44
45
  }
45
- console.error("FetchError: ", {
46
+ logger.error("FetchError: ", {
46
47
  status: response.status,
47
48
  statusText: response.statusText,
48
49
  url: response.url,
package/dist/type-gen.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { writeFileSync, readFileSync } from "fs";
3
3
  import { dirname, join } from "path";
4
4
  import { fileURLToPath } from "url";
5
+ import { logger } from "./utils/logging.js";
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const dir = dirname(__filename);
7
8
  const INPUT_PATH = join(dir, "node-types.json"); // Adjust as needed
@@ -179,6 +180,6 @@ export const unmarshalNode = (node: Node, ctx: ParserContext, parentId: NodeId |
179
180
  ${core}
180
181
  `;
181
182
  writeFileSync(OUTPUT_PATH, output);
182
- console.log(`Successfully generated AST types at ${OUTPUT_PATH}`);
183
+ logger.log(`Successfully generated AST types at ${OUTPUT_PATH}`);
183
184
  }
184
185
  generate();
@@ -1,5 +1,6 @@
1
1
  import { FNode, FTree } from "../dts";
2
2
  export declare function randomString(length?: number): string;
3
+ export declare function chunkArray<T>(array: T[], chunkSize: number): T[][];
3
4
  /**
4
5
  * Provides a list of ndes that are in tree A that are not in tree B
5
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEtC,wBAAgB,YAAY,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAIxD;AAWD;;GAEG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,CAgBxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEtC,wBAAgB,YAAY,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAIxD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAMlE;AAUD;;GAEG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,CAexD"}
@@ -4,6 +4,13 @@ export function randomString(length = 10) {
4
4
  res[i] = String.fromCharCode(97 + Math.floor(Math.random() * 26));
5
5
  return res.join("");
6
6
  }
7
+ export function chunkArray(array, chunkSize) {
8
+ const chunks = [];
9
+ for (let i = 0; i < array.length; i += chunkSize) {
10
+ chunks.push(array.slice(i, i + chunkSize));
11
+ }
12
+ return chunks;
13
+ }
7
14
  function buildValueSet(nodes) {
8
15
  const set = new Map();
9
16
  for (const node of nodes) {
@@ -0,0 +1,9 @@
1
+ export declare const setConsole: (c: Console) => void;
2
+ export declare const logger: {
3
+ info: (...args: any[]) => void;
4
+ warn: (...args: any[]) => void;
5
+ error: (...args: any[]) => void;
6
+ debug: (...args: any[]) => void;
7
+ log: (...args: any[]) => void;
8
+ };
9
+ //# sourceMappingURL=logging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/utils/logging.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GAAI,GAAG,OAAO,SAEpC,CAAC;AAEF,eAAO,MAAM,MAAM;oBACC,GAAG,EAAE;oBACL,GAAG,EAAE;qBACJ,GAAG,EAAE;qBACL,GAAG,EAAE;mBACP,GAAG,EAAE;CACvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ let internalConsole = globalThis.console;
2
+ export const setConsole = (c) => {
3
+ internalConsole = c;
4
+ };
5
+ export const logger = {
6
+ info: (...args) => internalConsole.log(...args),
7
+ warn: (...args) => internalConsole.warn(...args),
8
+ error: (...args) => internalConsole.error(...args),
9
+ debug: (...args) => internalConsole.debug(...args),
10
+ log: (...args) => internalConsole.log(...args),
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cr_docs_t/dts",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -69,6 +69,7 @@
69
69
  "@types/jest": "^30.0.0",
70
70
  "@types/lz4js": "^0.2.2",
71
71
  "@types/node": "^24.10.1",
72
+ "@types/pako": "^2.0.4",
72
73
  "jest": "^30.2.0",
73
74
  "semantic-release": "^25.0.2",
74
75
  "ts-jest": "^29.4.6",
@@ -81,6 +82,7 @@
81
82
  "dependencies": {
82
83
  "@msgpack/msgpack": "^3.1.3",
83
84
  "lz4js": "^0.2.0",
85
+ "pako": "^2.1.0",
84
86
  "uuid": "^13.0.0",
85
87
  "web-tree-sitter": "^0.26.5",
86
88
  "zod": "^4.3.6"