@cr_docs_t/dts 0.31.0 → 0.33.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.
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
@@ -60,20 +61,17 @@ export interface ParserContext {
60
61
  props.set("parentId", { type: "NodeId | null", optional: false });
61
62
  props.set("type", { type: `'${node.type}'`, optional: false });
62
63
  props.set("text", { type: "string", optional: false });
63
- // Map Fields
64
+ props.set("startIndex", { type: "number", optional: false });
65
+ props.set("endIndex", { type: "number", optional: false });
66
+ // Map Fields skipping any field whose name collides with a reserved base property
67
+ const RESERVED = new Set(["id", "parentId", "type", "text", "childrenIds", "startIndex", "endIndex"]);
64
68
  if (node.fields) {
65
69
  for (const [fieldName, fieldData] of Object.entries(node.fields)) {
66
- let typeString = fieldData.multiple ? "NodeId[]" : "NodeId";
70
+ if (RESERVED.has(fieldName))
71
+ continue;
72
+ const typeString = fieldData.multiple ? "NodeId[]" : "NodeId";
67
73
  const isOptional = !fieldData.required;
68
- if (props.has(fieldName)) {
69
- // Merge types on collision
70
- const existing = props.get(fieldName);
71
- existing.type = `${existing.type} | ${typeString}`;
72
- existing.optional = existing.optional && isOptional;
73
- }
74
- else {
75
- props.set(fieldName, { type: typeString, optional: isOptional });
76
- }
74
+ props.set(fieldName, { type: typeString, optional: isOptional });
77
75
  }
78
76
  }
79
77
  props.set("childrenIds", { type: "NodeId[]", optional: false });
@@ -88,46 +86,43 @@ export interface ParserContext {
88
86
  switches += `case '${node.type}': return ${funcName}(node, ctx, parentId);\n`;
89
87
  unmarshalersOut += `function ${funcName}(node: Node, ctx: ParserContext, parentId: NodeId | null): NodeId {
90
88
  const id = v4();
89
+ const namedChildren = node.namedChildren;
91
90
  const n: Partial<${interfaceName}> = {
92
91
  id,
93
92
  parentId,
94
93
  type: '${node.type}',
95
- text: node.text,
94
+ text: namedChildren.length === 0 ? node.text : '',
95
+ startIndex: node.startIndex,
96
+ endIndex: node.endIndex
96
97
  };
97
98
  ctx.nodes.set(id, n as AstNode);
98
99
 
99
100
  `;
100
- let fieldExtractionNodes = "";
101
+ // Unmarshal all namedChildren once into childrenIds.
102
+ unmarshalersOut += ` n.childrenIds = namedChildren.map(child => unmarshalNode(child, ctx, id));
103
+
104
+ `;
105
+ // Assign field properties by index-lookup into the already-built childrenIds.
101
106
  if (node.fields) {
102
- for (const [fieldName, fieldData] of Object.entries(node.fields)) {
103
- if (fieldData.multiple) {
104
- unmarshalersOut += `n.${fieldName} = node.childrenForFieldName('${fieldName}').map(n => unmarshalNode(n, ctx, id));\n`;
105
- fieldExtractionNodes += `...node.childrenForFieldName('${fieldName}').map(n => n.id), `;
106
- }
107
- else {
108
- if (fieldData.required) {
109
- unmarshalersOut += `n.${fieldName} = unmarshalNode(node.childForFieldName('${fieldName}')!, ctx, id);\n`;
110
- fieldExtractionNodes += `node.childForFieldName('${fieldName}')!.id, `;
107
+ const nonReservedFields = Object.entries(node.fields).filter(([fieldName]) => !RESERVED.has(fieldName));
108
+ if (nonReservedFields.length > 0) {
109
+ for (const [fieldName, fieldData] of nonReservedFields) {
110
+ if (fieldData.multiple) {
111
+ unmarshalersOut += ` n.${fieldName} = node.childrenForFieldName('${fieldName}').map(child => n.childrenIds![node.namedChildren.indexOf(child)]).filter((id) => id !== undefined);\n`;
111
112
  }
112
113
  else {
113
- unmarshalersOut += `const ${fieldName}Node = node.childForFieldName('${fieldName}');
114
- n.${fieldName} = ${fieldName}Node ? unmarshalNode(${fieldName}Node, ctx, id) : undefined;
115
- `;
116
- fieldExtractionNodes += `${fieldName}Node ? ${fieldName}Node.id : undefined, `;
114
+ if (fieldData.required) {
115
+ unmarshalersOut += ` { const _fc = node.childForFieldName('${fieldName}'); n.${fieldName} = _fc ? n.childrenIds![namedChildren.indexOf(_fc)] : undefined; }\n`;
116
+ }
117
+ else {
118
+ unmarshalersOut += ` { const _fc = node.childForFieldName('${fieldName}'); n.${fieldName} = _fc ? n.childrenIds![namedChildren.indexOf(_fc)] : undefined; }\n`;
119
+ }
117
120
  }
118
121
  }
122
+ unmarshalersOut += `\n`;
119
123
  }
120
124
  }
121
- if (fieldExtractionNodes.length > 0) {
122
- unmarshalersOut += `
123
- const fieldNodes = new Set([${fieldExtractionNodes}].filter(id => id !== undefined));
124
- n.childrenIds = node.namedChildren.filter(n => !fieldNodes.has(n.id)).map(n => unmarshalNode(n, ctx, id));
125
- `;
126
- }
127
- else {
128
- unmarshalersOut += `n.childrenIds = node.namedChildren.map(n => unmarshalNode(n, ctx, id));\n`;
129
- }
130
- unmarshalersOut += `return id;
125
+ unmarshalersOut += ` return id;
131
126
  }
132
127
 
133
128
  `;
@@ -139,11 +134,12 @@ export const unmarshalNode = (node: Node, ctx: ParserContext, parentId: NodeId |
139
134
  ${switches}
140
135
  default: {
141
136
  const id = v4();
137
+ const namedChildren = node.namedChildren;
142
138
  const n = {
143
139
  id,
144
140
  parentId,
145
141
  type: node.type as any,
146
- text: node.text,
142
+ text: namedChildren.length === 0 ? node.text : "",
147
143
  childrenIds: [] as NodeId[],
148
144
  };
149
145
  ctx.nodes.set(id, n as AstNode);
@@ -162,6 +158,11 @@ export const unmarshalNode = (node: Node, ctx: ParserContext, parentId: NodeId |
162
158
  const rootId = unmarshalNode(root, ctx, null);
163
159
  return {rootId, nodes: ctx.nodes};
164
160
  }
161
+
162
+ export const allChildIds = (ast: BragiAST, node: AstNode): string[] => {
163
+ return node.childrenIds;
164
+ };
165
+
165
166
  `;
166
167
  // Create a generic ASTNode type
167
168
  const concreteNodes = nodes
@@ -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,7 +1,7 @@
1
1
  import { BaseMessage, MessageType } from "./Message.js";
2
2
  export declare enum PresenceMessageType {
3
3
  CURSOR = 0,
4
- SELECTION = 1
4
+ UPDATE = 1
5
5
  }
6
6
  export interface BasePresenceMessage<T extends PresenceMessageType = PresenceMessageType> extends BaseMessage<MessageType.PRESENCE> {
7
7
  type: T;
@@ -9,6 +9,8 @@ export interface BasePresenceMessage<T extends PresenceMessageType = PresenceMes
9
9
  export interface PresenceCursorMessage extends BasePresenceMessage<PresenceMessageType.CURSOR> {
10
10
  pos: number;
11
11
  }
12
- export type PresenceMessage = PresenceCursorMessage;
12
+ export interface PresenceUpdateMessage extends BasePresenceMessage<PresenceMessageType.UPDATE> {
13
+ }
14
+ export type PresenceMessage = PresenceCursorMessage | PresenceUpdateMessage;
13
15
  export declare const makePresenceMsg: <T extends PresenceMessage>(msg: Omit<T, "msgType">) => BasePresenceMessage;
14
16
  //# sourceMappingURL=Presence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Presence.d.ts","sourceRoot":"","sources":["../../src/types/Presence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExD,oBAAY,mBAAmB;IAC3B,MAAM,IAAA;IACN,SAAS,IAAA;CACZ;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CACpF,SAAQ,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,CAAC;IAC1F,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,eAAe,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,KAAG,mBAKpF,CAAC"}
1
+ {"version":3,"file":"Presence.d.ts","sourceRoot":"","sources":["../../src/types/Presence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExD,oBAAY,mBAAmB;IAC3B,MAAM,IAAA;IACN,MAAM,IAAA;CACT;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CACpF,SAAQ,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,CAAC;IAC1F,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,CAAC;CAAG;AAEjG,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG,qBAAqB,CAAC;AAE5E,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,eAAe,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,KAAG,mBAKpF,CAAC"}
@@ -2,7 +2,7 @@ import { MessageType } from "./Message.js";
2
2
  export var PresenceMessageType;
3
3
  (function (PresenceMessageType) {
4
4
  PresenceMessageType[PresenceMessageType["CURSOR"] = 0] = "CURSOR";
5
- PresenceMessageType[PresenceMessageType["SELECTION"] = 1] = "SELECTION";
5
+ PresenceMessageType[PresenceMessageType["UPDATE"] = 1] = "UPDATE";
6
6
  })(PresenceMessageType || (PresenceMessageType = {}));
7
7
  export const makePresenceMsg = (msg) => {
8
8
  return {
@@ -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.33.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"