@balena/abstract-sql-compiler 11.0.0-build-11-x-b2280608fff69d9959999c79db6245c4ad561bbc-1 → 11.0.0-build-11-x-7511b8ebe5a9461f20add0ed97d0670ed3b5a479-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.
Files changed (53) hide show
  1. package/package.json +5 -2
  2. package/.github/workflows/flowzone.yml +0 -21
  3. package/.husky/pre-commit +0 -2
  4. package/.versionbot/CHANGELOG.yml +0 -10729
  5. package/CHANGELOG.md +0 -3515
  6. package/repo.yml +0 -12
  7. package/src/abstract-sql-compiler.ts +0 -1138
  8. package/src/abstract-sql-optimizer.ts +0 -1632
  9. package/src/abstract-sql-rules-to-sql.ts +0 -1730
  10. package/src/abstract-sql-schema-optimizer.ts +0 -172
  11. package/src/referenced-fields.ts +0 -600
  12. package/test/abstract-sql/aggregate-json.ts +0 -49
  13. package/test/abstract-sql/aggregate.ts +0 -161
  14. package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
  15. package/test/abstract-sql/case-when-else.ts +0 -48
  16. package/test/abstract-sql/cast.ts +0 -25
  17. package/test/abstract-sql/coalesce.ts +0 -24
  18. package/test/abstract-sql/comparisons.ts +0 -360
  19. package/test/abstract-sql/dates.ts +0 -512
  20. package/test/abstract-sql/duration.ts +0 -56
  21. package/test/abstract-sql/empty-query-optimisations.ts +0 -54
  22. package/test/abstract-sql/functions-wrapper.ts +0 -70
  23. package/test/abstract-sql/get-referenced-fields.ts +0 -674
  24. package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
  25. package/test/abstract-sql/insert-query.ts +0 -22
  26. package/test/abstract-sql/is-distinct.ts +0 -102
  27. package/test/abstract-sql/joins.ts +0 -84
  28. package/test/abstract-sql/json.ts +0 -58
  29. package/test/abstract-sql/math.ts +0 -467
  30. package/test/abstract-sql/nested-in-optimisations.ts +0 -200
  31. package/test/abstract-sql/not-not-optimisations.ts +0 -15
  32. package/test/abstract-sql/schema-checks.ts +0 -168
  33. package/test/abstract-sql/schema-informative-reference.ts +0 -420
  34. package/test/abstract-sql/schema-rule-optimization.ts +0 -120
  35. package/test/abstract-sql/schema-rule-to-check.ts +0 -393
  36. package/test/abstract-sql/schema-views.ts +0 -73
  37. package/test/abstract-sql/test.ts +0 -192
  38. package/test/abstract-sql/text.ts +0 -168
  39. package/test/model.sbvr +0 -60
  40. package/test/odata/expand.ts +0 -674
  41. package/test/odata/fields.ts +0 -59
  42. package/test/odata/filterby.ts +0 -1517
  43. package/test/odata/orderby.ts +0 -96
  44. package/test/odata/paging.ts +0 -48
  45. package/test/odata/resource-parsing.ts +0 -568
  46. package/test/odata/select.ts +0 -119
  47. package/test/odata/stress.ts +0 -93
  48. package/test/odata/test.ts +0 -297
  49. package/test/sbvr/pilots.ts +0 -1097
  50. package/test/sbvr/reference-type.ts +0 -211
  51. package/test/sbvr/test.ts +0 -101
  52. package/tsconfig.build.json +0 -6
  53. package/tsconfig.json +0 -25
@@ -1,345 +0,0 @@
1
- import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../out/abstract-sql-compiler.js';
3
-
4
- describe('getRuleReferencedFields', () => {
5
- it('should work with single table NOT EXISTS', () => {
6
- expect(
7
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
8
- 'Not',
9
- [
10
- 'Exists',
11
- [
12
- 'SelectQuery',
13
- ['Select', []],
14
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
15
- [
16
- 'Where',
17
- [
18
- 'Not',
19
- [
20
- 'And',
21
- [
22
- 'LessThan',
23
- ['Integer', 0],
24
- ['ReferencedField', 'test.0', 'id'],
25
- ],
26
- ['Exists', ['ReferencedField', 'test.0', 'id']],
27
- ],
28
- ],
29
- ],
30
- ],
31
- ],
32
- ]),
33
- ).to.deep.equal({
34
- test: {
35
- create: ['id'],
36
- update: ['id'],
37
- delete: [],
38
- },
39
- });
40
- });
41
- it('should work with single table COUNT(*) = 0', () => {
42
- expect(
43
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
44
- 'Equals',
45
- [
46
- 'SelectQuery',
47
- ['Select', [['Count', '*']]],
48
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
49
- [
50
- 'Where',
51
- [
52
- 'Not',
53
- [
54
- 'And',
55
- [
56
- 'LessThan',
57
- ['Integer', 0],
58
- ['ReferencedField', 'test.0', 'id'],
59
- ],
60
- ['Exists', ['ReferencedField', 'test.0', 'id']],
61
- ],
62
- ],
63
- ],
64
- ],
65
- ['Number', 0],
66
- ]),
67
- ).to.deep.equal({
68
- test: {
69
- create: ['id'],
70
- update: ['id'],
71
- delete: [],
72
- },
73
- });
74
- });
75
-
76
- it('should work with multi table SELECT NOT EXISTS', () => {
77
- expect(
78
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
79
- 'Not',
80
- [
81
- 'Exists',
82
- [
83
- 'SelectQuery',
84
- ['Select', []],
85
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
86
- ['From', ['Alias', ['Table', 'test'], 'test.1']],
87
- [
88
- 'Where',
89
- [
90
- 'Not',
91
- [
92
- 'And',
93
- [
94
- 'LessThan',
95
- ['ReferencedField', 'test.1', 'id'],
96
- ['ReferencedField', 'test.0', 'id'],
97
- ],
98
- ['Exists', ['ReferencedField', 'test.0', 'id']],
99
- ],
100
- ],
101
- ],
102
- ],
103
- ],
104
- ]),
105
- ).to.deep.equal({
106
- test: {
107
- create: ['id'],
108
- update: ['id'],
109
- delete: [],
110
- },
111
- });
112
- });
113
-
114
- it('should work with single table SELECT EXISTS', () => {
115
- expect(
116
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
117
- 'Exists',
118
- [
119
- 'SelectQuery',
120
- ['Select', []],
121
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
122
- [
123
- 'Where',
124
- [
125
- 'Not',
126
- [
127
- 'And',
128
- [
129
- 'LessThan',
130
- ['Integer', 0],
131
- ['ReferencedField', 'test.0', 'id'],
132
- ],
133
- ['Exists', ['ReferencedField', 'test.0', 'id']],
134
- ],
135
- ],
136
- ],
137
- ],
138
- ]),
139
- ).to.deep.equal({
140
- test: {
141
- create: [],
142
- update: ['id'],
143
- delete: ['id'],
144
- },
145
- });
146
- });
147
-
148
- it('should work with single table SELECT EXISTS for `Field`s', () => {
149
- expect(
150
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
151
- 'Exists',
152
- [
153
- 'SelectQuery',
154
- ['Select', []],
155
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
156
- [
157
- 'Where',
158
- [
159
- 'Not',
160
- [
161
- 'And',
162
- ['LessThan', ['Integer', 0], ['Field', 'id']],
163
- ['Exists', ['Field', 'id']],
164
- ],
165
- ],
166
- ],
167
- ],
168
- ]),
169
- ).to.deep.equal({
170
- test: {
171
- create: [],
172
- update: ['id'],
173
- delete: ['id'],
174
- },
175
- });
176
- });
177
-
178
- it('should work with single table SELECT NOT EXISTS for COUNT(*)', () => {
179
- expect(
180
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
181
- 'NotExists',
182
- [
183
- 'SelectQuery',
184
- ['Select', [['Count', '*']]],
185
- ['From', ['Table', 'test']],
186
- ],
187
- ]),
188
- ).to.deep.equal({
189
- test: {
190
- create: [''],
191
- update: [''],
192
- delete: [],
193
- },
194
- });
195
- });
196
-
197
- it('should work with nested NOT EXISTS', () => {
198
- expect(
199
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
200
- 'Not',
201
- [
202
- 'Exists',
203
- [
204
- 'SelectQuery',
205
- ['Select', []],
206
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
207
- [
208
- 'Where',
209
- [
210
- 'Not',
211
- [
212
- 'Exists',
213
- [
214
- 'SelectQuery',
215
- ['Select', []],
216
- ['From', ['Alias', ['Table', 'test2'], 'test2.0']],
217
- [
218
- 'Where',
219
- [
220
- 'Equals',
221
- ['ReferencedField', 'test.0', 'id'],
222
- ['ReferencedField', 'test2.0', 'test'],
223
- ],
224
- ],
225
- ],
226
- ],
227
- ],
228
- ],
229
- ],
230
- ],
231
- ]),
232
- ).to.deep.equal({
233
- test: {
234
- create: ['id'],
235
- update: ['id'],
236
- delete: [],
237
- },
238
- test2: {
239
- create: [],
240
- update: ['test'],
241
- delete: ['test'],
242
- },
243
- });
244
- });
245
-
246
- it('should work with multiple FROMs for `Field`s', () => {
247
- expect(
248
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
249
- 'Not',
250
- [
251
- 'Exists',
252
- [
253
- 'SelectQuery',
254
- ['Select', []],
255
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
256
- ['From', ['Alias', ['Table', 'test2'], 'test2.0']],
257
- ['Where', ['Equals', ['Field', 'id'], ['Field', 'test']]],
258
- ],
259
- ],
260
- ]),
261
- ).to.deep.equal({
262
- test: {
263
- // We assume any unreferenced field can come from any of the scoped tables
264
- create: ['id', 'test'],
265
- update: ['id', 'test'],
266
- delete: [],
267
- },
268
- test2: {
269
- create: ['id', 'test'],
270
- update: ['id', 'test'],
271
- delete: [],
272
- },
273
- });
274
- });
275
-
276
- it('should work with nested NOT EXISTS', () => {
277
- expect(
278
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
279
- 'Not',
280
- [
281
- 'Exists',
282
- [
283
- 'SelectQuery',
284
- ['Select', []],
285
- ['From', ['Alias', ['Table', 'test'], 'test.0']],
286
- [
287
- 'Where',
288
- [
289
- 'Not',
290
- [
291
- 'Exists',
292
- [
293
- 'SelectQuery',
294
- ['Select', [['Count', '*']]],
295
- ['From', ['Alias', ['Table', 'test2'], 'test2.0']],
296
- [
297
- 'Where',
298
- [
299
- 'Equals',
300
- ['ReferencedField', 'test.0', 'id'],
301
- ['ReferencedField', 'test2.0', 'test'],
302
- ],
303
- ],
304
- ],
305
- ],
306
- ],
307
- ],
308
- ],
309
- ],
310
- ]),
311
- ).to.deep.equal({
312
- test: {
313
- create: ['id'],
314
- update: ['id'],
315
- delete: [],
316
- },
317
- test2: {
318
- create: [],
319
- update: ['', 'test'],
320
- delete: ['', 'test'],
321
- },
322
- });
323
- });
324
-
325
- it('HAVING clauses should not be subject to the operation typecheck optimization', () => {
326
- expect(
327
- AbstractSqlCompiler.postgres.getRuleReferencedFields([
328
- 'NotExists',
329
- [
330
- 'SelectQuery',
331
- ['Select', []],
332
- ['From', ['Table', 'test']],
333
- ['GroupBy', [['ReferencedField', 'test', 'field']]],
334
- ['Having', ['GreaterThanOrEqual', ['Count', '*'], ['Number', 2]]],
335
- ],
336
- ]),
337
- ).to.deep.equal({
338
- test: {
339
- create: ['field', ''],
340
- update: ['field', ''],
341
- delete: [''],
342
- },
343
- });
344
- });
345
- });
@@ -1,22 +0,0 @@
1
- import test from './test.js';
2
-
3
- describe('Insert boolean value', () => {
4
- test(
5
- [
6
- 'InsertQuery',
7
- ['From', ['Table', 'test']],
8
- ['Fields', ['foo']],
9
- ['Values', [['Boolean', true]]],
10
- ],
11
- (result, sqlEquals) => {
12
- it('should produce a valid insert boolean statement', () => {
13
- sqlEquals(
14
- result,
15
- `\
16
- INSERT INTO "test" ("foo")
17
- VALUES (TRUE)`,
18
- );
19
- });
20
- },
21
- );
22
- });
@@ -1,102 +0,0 @@
1
- import test from './test.js';
2
-
3
- describe('IsDistinctFrom', () => {
4
- test(
5
- [
6
- 'SelectQuery',
7
- ['Select', [['IsDistinctFrom', ['Field', 'a'], ['Field', 'b']]]],
8
- ],
9
- (result, sqlEquals) => {
10
- it('should produce a valid is distinct from statement', () => {
11
- sqlEquals(
12
- result,
13
- 'SELECT NOT("a" IS NOT NULL AND "b" IS NOT NULL AND "a" = "b" OR "a" IS NULL AND "b" IS NULL)',
14
- );
15
- });
16
- },
17
- );
18
- test(
19
- [
20
- 'SelectQuery',
21
- ['Select', [['IsDistinctFrom', ['Number', 1], ['Number', 2]]]],
22
- ],
23
- (result, sqlEquals) => {
24
- it('should optimize down to a !=', () => {
25
- sqlEquals(result, 'SELECT 1 != 2');
26
- });
27
- },
28
- );
29
- test(
30
- [
31
- 'SelectQuery',
32
- ['Select', [['IsDistinctFrom', ['Field', 'a'], ['Text', '2']]]],
33
- ],
34
- [['Text', '2']],
35
- (result, sqlEquals) => {
36
- it('should produce a valid is distinct from statement', () => {
37
- sqlEquals(result, 'SELECT NOT("a" IS NOT NULL AND "a" = $1)');
38
- });
39
- },
40
- );
41
-
42
- test(
43
- ['SelectQuery', ['Select', [['IsDistinctFrom', ['Field', 'a'], ['Null']]]]],
44
- (result, sqlEquals) => {
45
- it('should produce an is not null statement', () => {
46
- sqlEquals(result, 'SELECT "a" IS NOT NULL');
47
- });
48
- },
49
- );
50
- });
51
-
52
- describe('IsNotDistinctFrom', () => {
53
- test(
54
- [
55
- 'SelectQuery',
56
- ['Select', [['IsNotDistinctFrom', ['Field', 'a'], ['Field', 'b']]]],
57
- ],
58
- (result, sqlEquals) => {
59
- it('should produce a valid is not distinct from statement', () => {
60
- sqlEquals(
61
- result,
62
- 'SELECT "a" IS NOT NULL AND "b" IS NOT NULL AND "a" = "b" OR "a" IS NULL AND "b" IS NULL',
63
- );
64
- });
65
- },
66
- );
67
- test(
68
- [
69
- 'SelectQuery',
70
- ['Select', [['IsNotDistinctFrom', ['Number', 1], ['Number', 2]]]],
71
- ],
72
- (result, sqlEquals) => {
73
- it('should optimize down to an =', () => {
74
- sqlEquals(result, 'SELECT 1 = 2');
75
- });
76
- },
77
- );
78
- test(
79
- [
80
- 'SelectQuery',
81
- ['Select', [['IsNotDistinctFrom', ['Field', 'a'], ['Text', '2']]]],
82
- ],
83
- [['Text', '2']],
84
- (result, sqlEquals) => {
85
- it('should produce a valid is not distinct from statement', () => {
86
- sqlEquals(result, 'SELECT "a" IS NOT NULL AND "a" = $1');
87
- });
88
- },
89
- );
90
-
91
- test(
92
- [
93
- 'SelectQuery',
94
- ['Select', [['IsNotDistinctFrom', ['Field', 'a'], ['Null']]]],
95
- ],
96
- (result, sqlEquals) => {
97
- it('should produce a valid is not distinct from statement', () => {
98
- sqlEquals(result, 'SELECT "a" IS NULL');
99
- });
100
- },
101
- );
102
- });
@@ -1,84 +0,0 @@
1
- import { stripIndent } from 'common-tags';
2
- import test from './test.js';
3
-
4
- const joinTest = (
5
- joinType: 'Join' | 'RightJoin' | 'LeftJoin' | 'FullJoin',
6
- sqlJoinType: string,
7
- ) => {
8
- describe(joinType, () => {
9
- test(
10
- [
11
- 'SelectQuery',
12
- [
13
- 'Select',
14
- [
15
- ['ReferencedField', 'table', 'field1'],
16
- ['ReferencedField', 'table2', 'field2'],
17
- ],
18
- ],
19
- ['From', ['Table', 'table']],
20
- [
21
- joinType,
22
- ['Table', 'table2'],
23
- [
24
- 'On',
25
- [
26
- 'Equals',
27
- ['ReferencedField', 'table', 'field1'],
28
- ['ReferencedField', 'table2', 'field2'],
29
- ],
30
- ],
31
- ],
32
- ],
33
- (result, sqlEquals) => {
34
- it('should produce a valid join statement', () => {
35
- sqlEquals(
36
- result,
37
- stripIndent`
38
- SELECT "table"."field1", "table2"."field2"
39
- FROM "table"
40
- ${sqlJoinType} "table2" ON "table"."field1" = "table2"."field2"
41
- `,
42
- );
43
- });
44
- },
45
- );
46
- });
47
- };
48
-
49
- joinTest('Join', 'JOIN');
50
-
51
- joinTest('RightJoin', 'RIGHT JOIN');
52
-
53
- joinTest('LeftJoin', 'LEFT JOIN');
54
-
55
- joinTest('FullJoin', 'FULL JOIN');
56
-
57
- describe('CrossJoin', () => {
58
- test(
59
- [
60
- 'SelectQuery',
61
- [
62
- 'Select',
63
- [
64
- ['ReferencedField', 'table', 'field1'],
65
- ['ReferencedField', 'table2', 'field2'],
66
- ],
67
- ],
68
- ['From', ['Table', 'table']],
69
- ['CrossJoin', ['Table', 'table2']],
70
- ],
71
- (result, sqlEquals) => {
72
- it('should produce a valid join statement', () => {
73
- sqlEquals(
74
- result,
75
- stripIndent`
76
- SELECT "table"."field1", "table2"."field2"
77
- FROM "table"
78
- CROSS JOIN "table2"
79
- `,
80
- );
81
- });
82
- },
83
- );
84
- });
@@ -1,58 +0,0 @@
1
- import test from './test.js';
2
-
3
- describe('ExtractJSONPathAsText', () => {
4
- test(
5
- [
6
- 'SelectQuery',
7
- [
8
- 'Select',
9
- [
10
- [
11
- 'ExtractJSONPathAsText',
12
- ['ReferencedField', 'foo', 'bar'],
13
- ['TextArray'],
14
- ],
15
- ],
16
- ],
17
- ],
18
- (result, sqlEquals) => {
19
- it('should produce a valid select with given empty text array', () => {
20
- sqlEquals(result, `SELECT "foo"."bar" #>> CAST(ARRAY[] as TEXT[])`);
21
- });
22
- },
23
- );
24
- test(
25
- [
26
- 'SelectQuery',
27
- [
28
- 'Select',
29
- [
30
- [
31
- 'ExtractJSONPathAsText',
32
- ['ReferencedField', 'foo', 'bar'],
33
- ['TextArray', ['EmbeddedText', 'buz'], ['EmbeddedText', 'baz']],
34
- ],
35
- ],
36
- ],
37
- ],
38
- (result, sqlEquals) => {
39
- it('should produce a valid select with given populated text array', () => {
40
- sqlEquals(result, `SELECT "foo"."bar" #>> ARRAY['buz', 'baz']`);
41
- });
42
- },
43
- );
44
- });
45
-
46
- describe('ToJSON', () => {
47
- test(
48
- [
49
- 'SelectQuery',
50
- ['Select', [['ToJSON', ['ReferencedField', 'foo', 'bar']]]],
51
- ],
52
- (result, sqlEquals) => {
53
- it('should produce a valid to_json select statement', () => {
54
- sqlEquals(result, 'SELECT TO_JSON("foo"."bar")');
55
- });
56
- },
57
- );
58
- });