@balena/abstract-sql-compiler 10.2.3-build-renovate-major-22-node-d6c0f904df738bdfb51aa65395e2b146a26000e6-1 → 10.2.3-build-tests-0edb21cc4ee30ead2a6eeb290623f3a0adc7a0fe-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.
@@ -1,16 +1,31 @@
1
1
  - commits:
2
- - subject: Update dependency @types/node to v22
3
- hash: d6c0f904df738bdfb51aa65395e2b146a26000e6
4
- body: |
5
- Update @types/node from 20.17.19 to 22.13.1
2
+ - subject: "Tests: convert test/abstract-sql/case-when-else.js to typescript"
3
+ hash: 0edb21cc4ee30ead2a6eeb290623f3a0adc7a0fe
4
+ body: ""
5
+ footer:
6
+ Change-type: patch
7
+ change-type: patch
8
+ author: Pagan Gazzard
9
+ nested: []
10
+ - subject: "Tests: convert test/abstract-sql/test.js to typescript"
11
+ hash: 43c24e87e4af08c8dd803a1cc4dfcb8bead301e9
12
+ body: ""
6
13
  footer:
7
14
  Change-type: patch
8
15
  change-type: patch
9
- author: balena-renovate[bot]
16
+ author: Pagan Gazzard
17
+ nested: []
18
+ - subject: "Tests: simplify handling of variadic test helper functions"
19
+ hash: f07fa0857b22c99c019cb1d3ea04a9b6fa7449e7
20
+ body: ""
21
+ footer:
22
+ Change-type: patch
23
+ change-type: patch
24
+ author: Pagan Gazzard
10
25
  nested: []
11
26
  version: 10.2.3
12
27
  title: ""
13
- date: 2025-02-14T17:44:43.552Z
28
+ date: 2025-03-18T21:29:49.750Z
14
29
  - commits:
15
30
  - subject: Clarify the `['Bind', string, string]` form of `BindNode` is legacy
16
31
  hash: aa72d3c77c2b6dae37d517ca149a27ea7e5a9bc1
package/CHANGELOG.md CHANGED
@@ -4,9 +4,11 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
- ## 10.2.3 - 2025-02-14
7
+ ## 10.2.3 - 2025-03-18
8
8
 
9
- * Update dependency @types/node to v22 [balena-renovate[bot]]
9
+ * Tests: convert test/abstract-sql/case-when-else.js to typescript [Pagan Gazzard]
10
+ * Tests: convert test/abstract-sql/test.js to typescript [Pagan Gazzard]
11
+ * Tests: simplify handling of variadic test helper functions [Pagan Gazzard]
10
12
 
11
13
  ## 10.2.2 - 2025-02-14
12
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/abstract-sql-compiler",
3
- "version": "10.2.3-build-renovate-major-22-node-d6c0f904df738bdfb51aa65395e2b146a26000e6-1",
3
+ "version": "10.2.3-build-tests-0edb21cc4ee30ead2a6eeb290623f3a0adc7a0fe-1",
4
4
  "description": "A translator for abstract sql into sql.",
5
5
  "type": "commonjs",
6
6
  "main": "out/AbstractSQLCompiler.js",
@@ -32,7 +32,7 @@
32
32
  "@types/common-tags": "^1.8.4",
33
33
  "@types/lodash": "^4.17.10",
34
34
  "@types/mocha": "^10.0.8",
35
- "@types/node": "^22.0.0",
35
+ "@types/node": "^20.16.10",
36
36
  "chai": "^4.3.7",
37
37
  "common-tags": "^1.8.2",
38
38
  "husky": "^9.1.6",
@@ -64,6 +64,6 @@
64
64
  "npm": ">=10.7.0"
65
65
  },
66
66
  "versionist": {
67
- "publishedAt": "2025-02-14T17:44:43.935Z"
67
+ "publishedAt": "2025-03-18T21:29:50.127Z"
68
68
  }
69
69
  }
@@ -1,15 +1,4 @@
1
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
2
-
3
- type TestCb = (
4
- result: { query: string },
5
- sqlEquals: (a: string, b: string) => void,
6
- ) => void;
7
- import $test from './test';
8
- const test = $test as (
9
- query: AnyTypeNodes,
10
- binds: any[][] | TestCb,
11
- cb?: TestCb,
12
- ) => void;
1
+ import test from './test';
13
2
 
14
3
  describe('AggregateJSON', () => {
15
4
  test(
@@ -46,7 +35,7 @@ describe('AggregateJSON', () => {
46
35
  (result, sqlEquals) => {
47
36
  it('should produce a valid aggregate JSON statement', () => {
48
37
  sqlEquals(
49
- result.query,
38
+ result,
50
39
  `\
51
40
  SELECT (
52
41
  SELECT COALESCE(JSON_AGG("pilot.licence".*), '[]') AS "licence"
@@ -1,21 +1,10 @@
1
1
  import { expect } from 'chai';
2
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
3
-
4
- type TestCb = (
5
- result: { query: string },
6
- sqlEquals: (a: string, b: string) => void,
7
- ) => void;
8
- import $test from './test';
9
- const test = $test as (
10
- query: AnyTypeNodes,
11
- binds: any[][] | TestCb,
12
- cb?: TestCb,
13
- ) => void;
2
+ import test from './test';
14
3
 
15
4
  describe('Count', () => {
16
5
  test(['SelectQuery', ['Select', [['Count', '*']]]], (result, sqlEquals) => {
17
6
  it('should produce a valid COUNT(*) statement', () => {
18
- sqlEquals(result.query, 'SELECT COUNT(*)');
7
+ sqlEquals(result, 'SELECT COUNT(*)');
19
8
  });
20
9
  });
21
10
  });
@@ -25,7 +14,7 @@ describe('Average', () => {
25
14
  ['SelectQuery', ['Select', [['Average', ['Number', 5]]]]],
26
15
  (result, sqlEquals) => {
27
16
  it('should produce a valid AVG(5) statement', () => {
28
- sqlEquals(result.query, 'SELECT AVG(5)');
17
+ sqlEquals(result, 'SELECT AVG(5)');
29
18
  });
30
19
  },
31
20
  );
@@ -36,7 +25,7 @@ describe('Sum', () => {
36
25
  ['SelectQuery', ['Select', [['Sum', ['Number', 5]]]]],
37
26
  (result, sqlEquals) => {
38
27
  it('should produce a valid SUM(5) statement', () => {
39
- sqlEquals(result.query, 'SELECT SUM(5)');
28
+ sqlEquals(result, 'SELECT SUM(5)');
40
29
  });
41
30
  },
42
31
  );
@@ -47,7 +36,7 @@ describe('Subtract now timestamp from now timestamp', () => {
47
36
  ['SelectQuery', ['Select', [['Subtract', ['Now'], ['Now']]]]],
48
37
  (result, sqlEquals) => {
49
38
  it('Subtract now timestamp from now timestamp', () => {
50
- sqlEquals(result.query, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
39
+ sqlEquals(result, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
51
40
  });
52
41
  },
53
42
  );
@@ -61,10 +50,7 @@ describe('Subtract Duration from now timestamp', () => {
61
50
  ],
62
51
  (result, sqlEquals) => {
63
52
  it('Subtract Duration from now timestamp', () => {
64
- sqlEquals(
65
- result.query,
66
- `SELECT CURRENT_TIMESTAMP - INTERVAL '1 0:0:0.0'`,
67
- );
53
+ sqlEquals(result, `SELECT CURRENT_TIMESTAMP - INTERVAL '1 0:0:0.0'`);
68
54
  });
69
55
  },
70
56
  );
@@ -72,18 +58,11 @@ describe('Subtract Duration from now timestamp', () => {
72
58
 
73
59
  // this is not allowed
74
60
  describe('Add now timestamp to now timestamp should fail', () => {
75
- test(
76
- ['SelectQuery', ['Select', [['Add', ['Now'], ['Now']]]]],
77
- (result, sqlEquals) => {
78
- it('Add now timestamp to now timestamp should fail', () => {
79
- expect(result).to.be.empty;
80
- expect(sqlEquals).to.be.undefined;
81
- expect(result.query).to.not.eq(
82
- 'SELECT CURRENT_TIMESTAMP + CURRENT_TIMESTAMP',
83
- );
84
- });
85
- },
86
- );
61
+ test.fail(['SelectQuery', ['Select', [['Add', ['Now'], ['Now']]]]], (err) => {
62
+ it('Add now timestamp to now timestamp should fail', () => {
63
+ expect(err).to.be.an('error');
64
+ });
65
+ });
87
66
  });
88
67
 
89
68
  describe('Add Duration to now timestamp', () => {
@@ -91,10 +70,7 @@ describe('Add Duration to now timestamp', () => {
91
70
  ['SelectQuery', ['Select', [['Add', ['Now'], ['Duration', { day: 1 }]]]]],
92
71
  (result, sqlEquals) => {
93
72
  it('Add Duration to now timestamp', () => {
94
- sqlEquals(
95
- result.query,
96
- `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`,
97
- );
73
+ sqlEquals(result, `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`);
98
74
  });
99
75
  },
100
76
  );
@@ -123,7 +99,7 @@ describe('Substract DateTrunc datefield from now timestamp', () => {
123
99
  (result, sqlEquals) => {
124
100
  it('Substract DateTrunc datefield from now timestamp', () => {
125
101
  sqlEquals(
126
- result.query,
102
+ result,
127
103
  `SELECT CURRENT_TIMESTAMP - DATE_TRUNC('milliseconds', $1)`,
128
104
  );
129
105
  });
@@ -161,7 +137,7 @@ describe('Substract DateTrunc datefield from now timestamp', () => {
161
137
  (result, sqlEquals) => {
162
138
  it('Substract DateTrunc datefield from now timestamp', () => {
163
139
  sqlEquals(
164
- result.query,
140
+ result,
165
141
  `SELECT DATE_TRUNC('milliseconds', $1) - DATE_TRUNC('milliseconds', $2)`,
166
142
  );
167
143
  });
@@ -1,16 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
3
-
4
- type TestCb = (
5
- result: { query: string },
6
- sqlEquals: (a: string, b: string) => void,
7
- ) => void;
8
- import $test from './test';
9
- const test = $test as (
10
- query: AnyTypeNodes,
11
- binds: any[][] | TestCb,
12
- cb?: TestCb,
13
- ) => void;
2
+ import test from './test';
14
3
 
15
4
  describe('Unnecessary booleans should be removed', () => {
16
5
  test(
@@ -31,7 +20,7 @@ describe('Unnecessary booleans should be removed', () => {
31
20
  (result, sqlEquals) => {
32
21
  it('should simplify `... AND true` to `...`', () => {
33
22
  sqlEquals(
34
- result.query,
23
+ result,
35
24
  stripIndent`
36
25
  SELECT 1
37
26
  FROM "table"
@@ -59,7 +48,7 @@ describe('Unnecessary booleans should be removed', () => {
59
48
  (result, sqlEquals) => {
60
49
  it('should simplify `... OR false` to `...`', () => {
61
50
  sqlEquals(
62
- result.query,
51
+ result,
63
52
  stripIndent`
64
53
  SELECT 1
65
54
  FROM "table"
@@ -86,7 +75,7 @@ describe('Unnecessary booleans should be removed', () => {
86
75
  (result, sqlEquals) => {
87
76
  it('should simplify `... AND false` to `false`', () => {
88
77
  sqlEquals(
89
- result.query,
78
+ result,
90
79
  stripIndent`
91
80
  SELECT 1
92
81
  FROM "table"
@@ -113,7 +102,7 @@ describe('Unnecessary booleans should be removed', () => {
113
102
  (result, sqlEquals) => {
114
103
  it('should simplify `... AND true` to `true`', () => {
115
104
  sqlEquals(
116
- result.query,
105
+ result,
117
106
  stripIndent`
118
107
  SELECT 1
119
108
  FROM "table"
@@ -1,25 +1,16 @@
1
+ import type { CaseNode, SelectQueryNode } from '../../src/AbstractSQLCompiler';
1
2
  import test from './test';
2
3
 
3
- const buildSelect = (withElse) => [
4
- 'SelectQuery',
5
- [
6
- 'Select',
7
- [
8
- [
9
- 'Alias',
10
- [
11
- 'Case',
12
- [
13
- 'When',
14
- ['Equals', ['Number', -2], ['Number', -2]],
15
- ['Text', 'Equal'],
16
- ],
17
- ].concat(withElse ? [['Else', ['Text', 'Not Equal']]] : []),
18
- 'equal_alias',
19
- ],
20
- ],
21
- ],
22
- ];
4
+ const buildSelect = (withElse: boolean): SelectQueryNode => {
5
+ let caseNode: CaseNode = [
6
+ 'Case',
7
+ ['When', ['Equals', ['Number', -2], ['Number', -2]], ['Text', 'Equal']],
8
+ ];
9
+ if (withElse) {
10
+ caseNode = [...caseNode, ['Else', ['Text', 'Not Equal']]];
11
+ }
12
+ return ['SelectQuery', ['Select', [['Alias', caseNode, 'equal_alias']]]];
13
+ };
23
14
 
24
15
  test(
25
16
  buildSelect(true),
@@ -30,7 +21,7 @@ test(
30
21
  (result, sqlEquals) => {
31
22
  it('should produce a valid case statement', () => {
32
23
  sqlEquals(
33
- result.query,
24
+ result,
34
25
  `\
35
26
  SELECT CASE
36
27
  WHEN -2 = -2 THEN ?
@@ -44,7 +35,7 @@ END AS "equal_alias"`,
44
35
  test(buildSelect(false), [['Text', 'Equal']], (result, sqlEquals) => {
45
36
  it('should produce a valid case statement without an else', () => {
46
37
  sqlEquals(
47
- result.query,
38
+ result,
48
39
  `\
49
40
  SELECT CASE
50
41
  WHEN -2 = -2 THEN ?
@@ -1,22 +1,11 @@
1
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
2
-
3
- type TestCb = (
4
- result: { query: string },
5
- sqlEquals: (a: string, b: string) => void,
6
- ) => void;
7
- import $test from './test';
8
- const test = $test as (
9
- query: AnyTypeNodes,
10
- binds: any[][] | TestCb,
11
- cb?: TestCb,
12
- ) => void;
1
+ import test from './test';
13
2
 
14
3
  describe('Cast', () => {
15
4
  test(
16
5
  ['SelectQuery', ['Select', [['Cast', ['Number', 1.2], 'Integer']]]],
17
6
  (result, sqlEquals) => {
18
7
  it('should produce a valid integer cast statement', () => {
19
- sqlEquals(result.query, 'SELECT CAST(1.2 AS INTEGER)');
8
+ sqlEquals(result, 'SELECT CAST(1.2 AS INTEGER)');
20
9
  });
21
10
  },
22
11
  );
@@ -29,7 +18,7 @@ describe('Cast', () => {
29
18
  [['Date', '2022-10-10T10:10:10.000Z']],
30
19
  (result, sqlEquals) => {
31
20
  it('should produce a valid date cast statement', () => {
32
- sqlEquals(result.query, `SELECT CAST($1 AS DATE)`);
21
+ sqlEquals(result, `SELECT CAST($1 AS DATE)`);
33
22
  });
34
23
  },
35
24
  );
@@ -1,22 +1,11 @@
1
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
2
-
3
- type TestCb = (
4
- result: { query: string },
5
- sqlEquals: (a: string, b: string) => void,
6
- ) => void;
7
- import $test from './test';
8
- const test = $test as (
9
- query: AnyTypeNodes,
10
- binds: any[][] | TestCb,
11
- cb?: TestCb,
12
- ) => void;
1
+ import test from './test';
13
2
 
14
3
  describe('Coalesce', () => {
15
4
  test(
16
5
  ['SelectQuery', ['Select', [['Coalesce', ['Number', 1], ['Number', 2]]]]],
17
6
  (result, sqlEquals) => {
18
7
  it('should produce a valid coalesce statement', () => {
19
- sqlEquals(result.query, 'SELECT COALESCE(1, 2)');
8
+ sqlEquals(result, 'SELECT COALESCE(1, 2)');
20
9
  });
21
10
  },
22
11
  );
@@ -28,7 +17,7 @@ describe('Coalesce', () => {
28
17
  [['Text', '1']],
29
18
  (result, sqlEquals) => {
30
19
  it('should produce a valid coalesce statement', () => {
31
- sqlEquals(result.query, 'SELECT COALESCE($1, NULL, 2)');
20
+ sqlEquals(result, 'SELECT COALESCE($1, NULL, 2)');
32
21
  });
33
22
  },
34
23
  );
@@ -1,16 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler';
3
-
4
- type TestCb = (
5
- result: { query: string },
6
- sqlEquals: (a: string, b: string) => void,
7
- ) => void;
8
- import $test from './test';
9
- const test = $test as (
10
- query: AnyTypeNodes,
11
- binds: any[][] | TestCb,
12
- cb?: TestCb,
13
- ) => void;
2
+ import test from './test';
14
3
 
15
4
  describe('Between', () => {
16
5
  test(
@@ -20,7 +9,7 @@ describe('Between', () => {
20
9
  ],
21
10
  (result, sqlEquals) => {
22
11
  it('should produce a valid Between statement', () => {
23
- sqlEquals(result.query, 'SELECT 5 BETWEEN 3 AND (8)');
12
+ sqlEquals(result, 'SELECT 5 BETWEEN 3 AND (8)');
24
13
  });
25
14
  },
26
15
  );
@@ -32,7 +21,7 @@ describe('Equals Any', () => {
32
21
  [['Bind', 0]],
33
22
  (result, sqlEquals) => {
34
23
  it('should produce a valid EqualsAny statement', () => {
35
- sqlEquals(result.query, 'SELECT 5 = ANY($1)');
24
+ sqlEquals(result, 'SELECT 5 = ANY($1)');
36
25
  });
37
26
  },
38
27
  );
@@ -56,7 +45,7 @@ describe('Comparison Operator Precedence', () => {
56
45
  ],
57
46
  (result, sqlEquals) => {
58
47
  it('should produce a valid Equals statement when the second operand is also an Equals', () => {
59
- sqlEquals(result.query, 'SELECT TRUE = (TRUE = TRUE)');
48
+ sqlEquals(result, 'SELECT TRUE = (TRUE = TRUE)');
60
49
  });
61
50
  },
62
51
  );
@@ -77,7 +66,7 @@ describe('Comparison Operator Precedence', () => {
77
66
  ],
78
67
  (result, sqlEquals) => {
79
68
  it('should produce a valid NotEquals statement when both operands are Equals comparisons', () => {
80
- sqlEquals(result.query, 'SELECT (FALSE = FALSE) != (TRUE = TRUE)');
69
+ sqlEquals(result, 'SELECT (FALSE = FALSE) != (TRUE = TRUE)');
81
70
  });
82
71
  },
83
72
  );
@@ -107,7 +96,7 @@ describe('Comparison Operator Precedence', () => {
107
96
  (result, sqlEquals) => {
108
97
  it('should produce a valid NotEquals statement when the operands are math expressions with nested parenthesis', () => {
109
98
  sqlEquals(
110
- result.query,
99
+ result,
111
100
  stripIndent`
112
101
  SELECT 1 + (2 + (3 * 4)) != 1 + 0
113
102
  `,
@@ -138,7 +127,7 @@ describe('Comparison Operator Precedence', () => {
138
127
  // Evaluating this would match the expression w/o parenthesis
139
128
  it('should produce a valid NotEquals statement when the operands are math expressions with left sided parenthesis', () => {
140
129
  sqlEquals(
141
- result.query,
130
+ result,
142
131
  stripIndent`
143
132
  SELECT (1 + 2) * 5 >= 12 + 2
144
133
  `,
@@ -169,7 +158,7 @@ describe('Comparison Operator Precedence', () => {
169
158
  // Evaluating this would give a different result than if it was w/o parenthesis
170
159
  it('should produce a valid NotEquals statement when the operands are math expressions with right sided parenthesis', () => {
171
160
  sqlEquals(
172
- result.query,
161
+ result,
173
162
  stripIndent`
174
163
  SELECT 1 + (2 * 5) >= 12 + 2
175
164
  `,
@@ -199,7 +188,7 @@ describe('Comparison Operator Precedence', () => {
199
188
  (result, sqlEquals) => {
200
189
  it('should produce a valid And statement when the operands are composite boolean expressions', () => {
201
190
  sqlEquals(
202
- result.query,
191
+ result,
203
192
  stripIndent`
204
193
  SELECT (1 > 0
205
194
  OR 1 < 0)
@@ -232,7 +221,7 @@ describe('Comparison Operator Precedence', () => {
232
221
  // Even though the parenthesis are not added around the AND, the expression is correct b/c of precedence.
233
222
  it('should produce a valid Or statement when the first operand is a composite boolean expression', () => {
234
223
  sqlEquals(
235
- result.query,
224
+ result,
236
225
  stripIndent`
237
226
  SELECT (0 > 1
238
227
  AND 0 = 1
@@ -265,7 +254,7 @@ describe('Comparison Operator Precedence', () => {
265
254
  // Even though the parenthesis are not added around the AND, the expression is correct b/c of precedence.
266
255
  it('should produce a valid Or statement when the second operand is a composite boolean expression', () => {
267
256
  sqlEquals(
268
- result.query,
257
+ result,
269
258
  stripIndent`
270
259
  SELECT (1 > 0
271
260
  OR 0 = 1
@@ -298,7 +287,7 @@ describe('Comparison Operator Precedence', () => {
298
287
  // If it was w/o parenthesis, evaluating this would give a different result
299
288
  it('should produce a valid And statement when the first operand is an Or boolean expressions', () => {
300
289
  sqlEquals(
301
- result.query,
290
+ result,
302
291
  stripIndent`
303
292
  SELECT (1 > 0
304
293
  OR 0 = 1)
@@ -331,7 +320,7 @@ describe('Comparison Operator Precedence', () => {
331
320
  // If it was w/o parenthesis, evaluating this would give a different result
332
321
  it('should produce a valid And statement when the second operand is an Or boolean expressions', () => {
333
322
  sqlEquals(
334
- result.query,
323
+ result,
335
324
  stripIndent`
336
325
  SELECT 0 > 1
337
326
  AND (0 = 1
@@ -360,7 +349,7 @@ describe('Comparison Operator Precedence', () => {
360
349
  (result, sqlEquals) => {
361
350
  it('should produce a valid Between statement when the operands are math expressions', () => {
362
351
  sqlEquals(
363
- result.query,
352
+ result,
364
353
  stripIndent`
365
354
  SELECT 1 + 0 BETWEEN 1 + 0 AND (1 + 0)
366
355
  `,