@comprehend/telemetry-node 0.1.2 → 0.1.3

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,8 +1,7 @@
1
1
  {
2
2
  "permissions": {
3
3
  "allow": [
4
- "Bash(npm test:*)",
5
- "Bash(grep:*)"
4
+ "Bash(npm test:*)"
6
5
  ],
7
6
  "deny": []
8
7
  }
@@ -3,6 +3,7 @@
3
3
  <component name="NewModuleRootManager">
4
4
  <content url="file://$MODULE_DIR$">
5
5
  <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/dist" />
6
7
  <excludeFolder url="file://$MODULE_DIR$/temp" />
7
8
  <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
9
  </content>
@@ -23,6 +23,7 @@ function analyzeSQL(sql) {
23
23
  let skippingValues = false;
24
24
  let lookingForCommaOrEnd = false;
25
25
  let valuesDepth = 0;
26
+ let skippedWhitespace = [];
26
27
  for (let token of tokenizeSQL(sql)) {
27
28
  switch (token.type) {
28
29
  case "whitespace":
@@ -136,23 +137,31 @@ function analyzeSQL(sql) {
136
137
  switch (token.type) {
137
138
  case "comment":
138
139
  case "whitespace":
139
- // Skip whitespace/comments while looking for comma or end
140
+ // Collect whitespace/comments while looking for comma or end
141
+ skippedWhitespace.push(token);
140
142
  break;
141
143
  case "punct":
142
144
  if (token.value === ",") {
143
- // More tuples coming, continue skipping
145
+ // More tuples coming, clear skipped whitespace and continue skipping
146
+ skippedWhitespace = [];
144
147
  lookingForCommaOrEnd = false;
145
148
  skippingValues = true;
146
149
  }
147
150
  else {
148
151
  // Not a comma, so VALUES clause is done
152
+ // Add back the skipped whitespace, then the current token
153
+ presentableTokens.push(...skippedWhitespace);
149
154
  presentableTokens.push(token);
155
+ skippedWhitespace = [];
150
156
  lookingForCommaOrEnd = false;
151
157
  }
152
158
  break;
153
159
  default:
154
160
  // VALUES clause is done, resume normal processing
161
+ // Add back the skipped whitespace, then the current token
162
+ presentableTokens.push(...skippedWhitespace);
155
163
  presentableTokens.push(token);
164
+ skippedWhitespace = [];
156
165
  lookingForCommaOrEnd = false;
157
166
  break;
158
167
  }
@@ -482,4 +482,16 @@ describe('SQL Analyzer - bulk INSERT VALUES cardinality reduction', () => {
482
482
  expect(result.presentableQuery).toEqual(`INSERT INTO comments (text, author) VALUES
483
483
  (...)`);
484
484
  });
485
+ it('preserves whitespace before ON CONFLICT after VALUES clause', () => {
486
+ const sql = `INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com') ON CONFLICT (email) DO NOTHING`;
487
+ const result = (0, sql_analyzer_1.analyzeSQL)(sql);
488
+ expect(result.tableOperations).toEqual({ users: ['INSERT'] });
489
+ expect(result.presentableQuery).toEqual(`INSERT INTO users (name, email) VALUES (...) ON CONFLICT (email) DO NOTHING`);
490
+ });
491
+ it('preserves whitespace before ON CONFLICT with multiple VALUES tuples', () => {
492
+ const sql = `INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'), ('Bob', 'bob@example.com') ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name`;
493
+ const result = (0, sql_analyzer_1.analyzeSQL)(sql);
494
+ expect(result.tableOperations).toEqual({ users: ['INSERT'] });
495
+ expect(result.presentableQuery).toEqual(`INSERT INTO users (name, email) VALUES (...) ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name`);
496
+ });
485
497
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comprehend/telemetry-node",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Integration of comprehend.dev with OpenTelemetry in Node.js and similar environemnts.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -580,4 +580,20 @@ describe('SQL Analyzer - bulk INSERT VALUES cardinality reduction', () => {
580
580
  expect(result.presentableQuery).toEqual(`INSERT INTO comments (text, author) VALUES
581
581
  (...)`);
582
582
  });
583
+
584
+ it('preserves whitespace before ON CONFLICT after VALUES clause', () => {
585
+ const sql = `INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com') ON CONFLICT (email) DO NOTHING`;
586
+ const result = analyzeSQL(sql);
587
+
588
+ expect(result.tableOperations).toEqual({ users: ['INSERT'] });
589
+ expect(result.presentableQuery).toEqual(`INSERT INTO users (name, email) VALUES (...) ON CONFLICT (email) DO NOTHING`);
590
+ });
591
+
592
+ it('preserves whitespace before ON CONFLICT with multiple VALUES tuples', () => {
593
+ const sql = `INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'), ('Bob', 'bob@example.com') ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name`;
594
+ const result = analyzeSQL(sql);
595
+
596
+ expect(result.tableOperations).toEqual({ users: ['INSERT'] });
597
+ expect(result.presentableQuery).toEqual(`INSERT INTO users (name, email) VALUES (...) ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name`);
598
+ });
583
599
  });
@@ -28,6 +28,7 @@ export function analyzeSQL(sql: string): SQLAnalysisResult {
28
28
  let skippingValues = false;
29
29
  let lookingForCommaOrEnd = false;
30
30
  let valuesDepth = 0;
31
+ let skippedWhitespace: Token[] = [];
31
32
  for (let token of tokenizeSQL(sql)) {
32
33
  switch (token.type) {
33
34
  case "whitespace":
@@ -140,22 +141,30 @@ export function analyzeSQL(sql: string): SQLAnalysisResult {
140
141
  switch (token.type) {
141
142
  case "comment":
142
143
  case "whitespace":
143
- // Skip whitespace/comments while looking for comma or end
144
+ // Collect whitespace/comments while looking for comma or end
145
+ skippedWhitespace.push(token);
144
146
  break;
145
147
  case "punct":
146
148
  if (token.value === ",") {
147
- // More tuples coming, continue skipping
149
+ // More tuples coming, clear skipped whitespace and continue skipping
150
+ skippedWhitespace = [];
148
151
  lookingForCommaOrEnd = false;
149
152
  skippingValues = true;
150
153
  } else {
151
154
  // Not a comma, so VALUES clause is done
155
+ // Add back the skipped whitespace, then the current token
156
+ presentableTokens.push(...skippedWhitespace);
152
157
  presentableTokens.push(token);
158
+ skippedWhitespace = [];
153
159
  lookingForCommaOrEnd = false;
154
160
  }
155
161
  break;
156
162
  default:
157
163
  // VALUES clause is done, resume normal processing
164
+ // Add back the skipped whitespace, then the current token
165
+ presentableTokens.push(...skippedWhitespace);
158
166
  presentableTokens.push(token);
167
+ skippedWhitespace = [];
159
168
  lookingForCommaOrEnd = false;
160
169
  break;
161
170
  }