@cr_docs_t/dts 0.32.0 → 0.34.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
@@ -61,20 +61,17 @@ export interface ParserContext {
61
61
  props.set("parentId", { type: "NodeId | null", optional: false });
62
62
  props.set("type", { type: `'${node.type}'`, optional: false });
63
63
  props.set("text", { type: "string", optional: false });
64
- // 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"]);
65
68
  if (node.fields) {
66
69
  for (const [fieldName, fieldData] of Object.entries(node.fields)) {
67
- let typeString = fieldData.multiple ? "NodeId[]" : "NodeId";
70
+ if (RESERVED.has(fieldName))
71
+ continue;
72
+ const typeString = fieldData.multiple ? "NodeId[]" : "NodeId";
68
73
  const isOptional = !fieldData.required;
69
- if (props.has(fieldName)) {
70
- // Merge types on collision
71
- const existing = props.get(fieldName);
72
- existing.type = `${existing.type} | ${typeString}`;
73
- existing.optional = existing.optional && isOptional;
74
- }
75
- else {
76
- props.set(fieldName, { type: typeString, optional: isOptional });
77
- }
74
+ props.set(fieldName, { type: typeString, optional: isOptional });
78
75
  }
79
76
  }
80
77
  props.set("childrenIds", { type: "NodeId[]", optional: false });
@@ -89,46 +86,43 @@ export interface ParserContext {
89
86
  switches += `case '${node.type}': return ${funcName}(node, ctx, parentId);\n`;
90
87
  unmarshalersOut += `function ${funcName}(node: Node, ctx: ParserContext, parentId: NodeId | null): NodeId {
91
88
  const id = v4();
89
+ const namedChildren = node.namedChildren;
92
90
  const n: Partial<${interfaceName}> = {
93
91
  id,
94
92
  parentId,
95
93
  type: '${node.type}',
96
- text: node.text,
94
+ text: namedChildren.length === 0 ? node.text : '',
95
+ startIndex: node.startIndex,
96
+ endIndex: node.endIndex
97
97
  };
98
98
  ctx.nodes.set(id, n as AstNode);
99
99
 
100
100
  `;
101
- 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.
102
106
  if (node.fields) {
103
- for (const [fieldName, fieldData] of Object.entries(node.fields)) {
104
- if (fieldData.multiple) {
105
- unmarshalersOut += `n.${fieldName} = node.childrenForFieldName('${fieldName}').map(n => unmarshalNode(n, ctx, id));\n`;
106
- fieldExtractionNodes += `...node.childrenForFieldName('${fieldName}').map(n => n.id), `;
107
- }
108
- else {
109
- if (fieldData.required) {
110
- unmarshalersOut += `n.${fieldName} = unmarshalNode(node.childForFieldName('${fieldName}')!, ctx, id);\n`;
111
- 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`;
112
112
  }
113
113
  else {
114
- unmarshalersOut += `const ${fieldName}Node = node.childForFieldName('${fieldName}');
115
- n.${fieldName} = ${fieldName}Node ? unmarshalNode(${fieldName}Node, ctx, id) : undefined;
116
- `;
117
- 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
+ }
118
120
  }
119
121
  }
122
+ unmarshalersOut += `\n`;
120
123
  }
121
124
  }
122
- if (fieldExtractionNodes.length > 0) {
123
- unmarshalersOut += `
124
- const fieldNodes = new Set([${fieldExtractionNodes}].filter(id => id !== undefined));
125
- n.childrenIds = node.namedChildren.filter(n => !fieldNodes.has(n.id)).map(n => unmarshalNode(n, ctx, id));
126
- `;
127
- }
128
- else {
129
- unmarshalersOut += `n.childrenIds = node.namedChildren.map(n => unmarshalNode(n, ctx, id));\n`;
130
- }
131
- unmarshalersOut += `return id;
125
+ unmarshalersOut += ` return id;
132
126
  }
133
127
 
134
128
  `;
@@ -140,11 +134,12 @@ export const unmarshalNode = (node: Node, ctx: ParserContext, parentId: NodeId |
140
134
  ${switches}
141
135
  default: {
142
136
  const id = v4();
137
+ const namedChildren = node.namedChildren;
143
138
  const n = {
144
139
  id,
145
140
  parentId,
146
141
  type: node.type as any,
147
- text: node.text,
142
+ text: namedChildren.length === 0 ? node.text : "",
148
143
  childrenIds: [] as NodeId[],
149
144
  };
150
145
  ctx.nodes.set(id, n as AstNode);
@@ -163,6 +158,11 @@ export const unmarshalNode = (node: Node, ctx: ParserContext, parentId: NodeId |
163
158
  const rootId = unmarshalNode(root, ctx, null);
164
159
  return {rootId, nodes: ctx.nodes};
165
160
  }
161
+
162
+ export const allChildIds = (ast: BragiAST, node: AstNode): string[] => {
163
+ return node.childrenIds;
164
+ };
165
+
166
166
  `;
167
167
  // Create a generic ASTNode type
168
168
  const concreteNodes = nodes
@@ -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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cr_docs_t/dts",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",