@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,674 +0,0 @@
1
- import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../out/abstract-sql-compiler.js';
3
-
4
- describe('getReferencedFields', () => {
5
- it('should work with selected fields', () => {
6
- expect(
7
- AbstractSqlCompiler.postgres.getReferencedFields([
8
- 'SelectQuery',
9
- [
10
- 'Select',
11
- [
12
- ['ReferencedField', 'table', 'field1'],
13
- ['ReferencedField', 'table', 'field2'],
14
- ],
15
- ],
16
- ['From', ['Table', 'table']],
17
- ]),
18
- ).to.deep.equal({ table: ['field1', 'field2'] });
19
- });
20
-
21
- it('should work with filtered fields', () => {
22
- expect(
23
- AbstractSqlCompiler.postgres.getReferencedFields([
24
- 'SelectQuery',
25
- ['Select', []],
26
- ['From', ['Table', 'table']],
27
- [
28
- 'Where',
29
- [
30
- 'Equals',
31
- ['ReferencedField', 'table', 'field1'],
32
- ['ReferencedField', 'table', 'field2'],
33
- ],
34
- ],
35
- ]),
36
- ).to.deep.equal({ table: ['field1', 'field2'] });
37
- });
38
-
39
- it('should work with selected fields from an aliased table', () => {
40
- expect(
41
- AbstractSqlCompiler.postgres.getReferencedFields([
42
- 'SelectQuery',
43
- [
44
- 'Select',
45
- [
46
- ['ReferencedField', 'atable', 'field1'],
47
- ['ReferencedField', 'atable', 'field2'],
48
- ],
49
- ],
50
- ['From', ['Alias', ['Table', 'table'], 'atable']],
51
- ]),
52
- ).to.deep.equal({
53
- table: ['field1', 'field2'],
54
- });
55
- });
56
-
57
- it('should work with filtered fields from an aliased table', () => {
58
- expect(
59
- AbstractSqlCompiler.postgres.getReferencedFields([
60
- 'SelectQuery',
61
- ['Select', []],
62
- ['From', ['Alias', ['Table', 'table'], 'atable']],
63
- [
64
- 'Where',
65
- [
66
- 'Equals',
67
- ['ReferencedField', 'atable', 'field1'],
68
- ['ReferencedField', 'atable', 'field2'],
69
- ],
70
- ],
71
- ]),
72
- ).to.deep.equal({
73
- table: ['field1', 'field2'],
74
- });
75
- });
76
-
77
- it('should work with selected fields from multiple tables', () => {
78
- expect(
79
- AbstractSqlCompiler.postgres.getReferencedFields([
80
- 'SelectQuery',
81
- [
82
- 'Select',
83
- [
84
- ['ReferencedField', 'table', 'field1'],
85
- ['ReferencedField', 'table2', 'field2'],
86
- ],
87
- ],
88
- ['From', ['Table', 'table']],
89
- ['From', ['Table', 'table2']],
90
- ]),
91
- ).to.deep.equal({ table: ['field1'], table2: ['field2'] });
92
- });
93
-
94
- it('should work with filtered fields', () => {
95
- expect(
96
- AbstractSqlCompiler.postgres.getReferencedFields([
97
- 'SelectQuery',
98
- ['Select', []],
99
- ['From', ['Table', 'table']],
100
- ['From', ['Table', 'table2']],
101
- [
102
- 'Where',
103
- [
104
- 'Equals',
105
- ['ReferencedField', 'table', 'field1'],
106
- ['ReferencedField', 'table2', 'field2'],
107
- ],
108
- ],
109
- ]),
110
- ).to.deep.equal({ table: ['field1'], table2: ['field2'] });
111
- });
112
-
113
- it('should work with selected fields from multiple aliased tables', () => {
114
- expect(
115
- AbstractSqlCompiler.postgres.getReferencedFields([
116
- 'SelectQuery',
117
- [
118
- 'Select',
119
- [
120
- ['ReferencedField', 'atable', 'field1'],
121
- ['ReferencedField', 'atable2', 'field2'],
122
- ],
123
- ],
124
- ['From', ['Alias', ['Table', 'table'], 'atable']],
125
- ['From', ['Alias', ['Table', 'table2'], 'atable2']],
126
- ]),
127
- ).to.deep.equal({
128
- table: ['field1'],
129
- table2: ['field2'],
130
- });
131
- });
132
-
133
- it('should work with filtered fields from multiple aliased tables', () => {
134
- expect(
135
- AbstractSqlCompiler.postgres.getReferencedFields([
136
- 'SelectQuery',
137
- ['Select', []],
138
- ['From', ['Alias', ['Table', 'table'], 'atable']],
139
- ['From', ['Alias', ['Table', 'table2'], 'atable2']],
140
- [
141
- 'Where',
142
- [
143
- 'Equals',
144
- ['ReferencedField', 'atable', 'field1'],
145
- ['ReferencedField', 'atable2', 'field2'],
146
- ],
147
- ],
148
- ]),
149
- ).to.deep.equal({
150
- table: ['field1'],
151
- table2: ['field2'],
152
- });
153
- });
154
-
155
- it('should work with selected fields from a table with multiple aliases', () => {
156
- expect(
157
- AbstractSqlCompiler.postgres.getReferencedFields([
158
- 'SelectQuery',
159
- [
160
- 'Select',
161
- [
162
- ['ReferencedField', 'atable', 'field1'],
163
- ['ReferencedField', 'atable2', 'field2'],
164
- ],
165
- ],
166
- ['From', ['Alias', ['Table', 'table'], 'atable']],
167
- ['From', ['Alias', ['Table', 'table'], 'atable2']],
168
- ]),
169
- ).to.deep.equal({
170
- table: ['field1', 'field2'],
171
- });
172
- });
173
-
174
- it('should work with filtered fields from multiple aliased tables', () => {
175
- expect(
176
- AbstractSqlCompiler.postgres.getReferencedFields([
177
- 'SelectQuery',
178
- ['Select', []],
179
- ['From', ['Alias', ['Table', 'table'], 'atable']],
180
- ['From', ['Alias', ['Table', 'table'], 'atable2']],
181
- [
182
- 'Where',
183
- [
184
- 'Equals',
185
- ['ReferencedField', 'atable', 'field1'],
186
- ['ReferencedField', 'atable2', 'field2'],
187
- ],
188
- ],
189
- ]),
190
- ).to.deep.equal({
191
- table: ['field1', 'field2'],
192
- });
193
- });
194
-
195
- it('should work with selected and filtered fields', () => {
196
- expect(
197
- AbstractSqlCompiler.postgres.getReferencedFields([
198
- 'SelectQuery',
199
- [
200
- 'Select',
201
- [
202
- ['ReferencedField', 'table', 'field1'],
203
- ['ReferencedField', 'table', 'field2'],
204
- ],
205
- ],
206
- ['From', ['Table', 'table']],
207
- [
208
- 'Where',
209
- [
210
- 'Equals',
211
- ['ReferencedField', 'table', 'field3'],
212
- ['ReferencedField', 'table', 'field4'],
213
- ],
214
- ],
215
- ]),
216
- ).to.deep.equal({ table: ['field1', 'field2', 'field3', 'field4'] });
217
- });
218
-
219
- it('should work with the same field selected multiple times', () => {
220
- expect(
221
- AbstractSqlCompiler.postgres.getReferencedFields([
222
- 'SelectQuery',
223
- [
224
- 'Select',
225
- [
226
- ['ReferencedField', 'table', 'field1'],
227
- ['ReferencedField', 'table', 'field1'],
228
- ],
229
- ],
230
- ['From', ['Table', 'table']],
231
- ]),
232
- ).to.deep.equal({ table: ['field1'] });
233
- });
234
-
235
- it('should work with the same field filtered multiple times', () => {
236
- expect(
237
- AbstractSqlCompiler.postgres.getReferencedFields([
238
- 'SelectQuery',
239
- ['Select', []],
240
- ['From', ['Table', 'table']],
241
- [
242
- 'Where',
243
- [
244
- 'Equals',
245
- ['ReferencedField', 'table', 'field1'],
246
- ['ReferencedField', 'table', 'field1'],
247
- ],
248
- ],
249
- ]),
250
- ).to.deep.equal({ table: ['field1'] });
251
- });
252
-
253
- it('should work with select queries in the select', () => {
254
- expect(
255
- AbstractSqlCompiler.postgres.getReferencedFields([
256
- 'SelectQuery',
257
- [
258
- 'Select',
259
- [
260
- ['ReferencedField', 'table', 'field1'],
261
- ['ReferencedField', 'table', 'field2'],
262
- [
263
- 'Alias',
264
- [
265
- 'SelectQuery',
266
- ['Select', []],
267
- ['From', ['Table', 'table']],
268
- [
269
- 'Where',
270
- [
271
- 'Equals',
272
- ['ReferencedField', 'table', 'field5'],
273
- ['ReferencedField', 'table', 'field6'],
274
- ],
275
- ],
276
- ],
277
- 'afield',
278
- ],
279
- ],
280
- ],
281
- ['From', ['Table', 'table']],
282
- [
283
- 'Where',
284
- [
285
- 'Equals',
286
- ['ReferencedField', 'table', 'field3'],
287
- ['ReferencedField', 'table', 'field4'],
288
- ],
289
- ],
290
- ]),
291
- ).to.deep.equal({
292
- table: ['field1', 'field2', 'field5', 'field6', 'field3', 'field4'],
293
- });
294
- });
295
-
296
- it('should work with select queries in the from', () => {
297
- expect(
298
- AbstractSqlCompiler.postgres.getReferencedFields([
299
- 'SelectQuery',
300
- ['Select', [['ReferencedField', 'table', 'field1']]],
301
- ['From', ['Table', 'table']],
302
- [
303
- 'From',
304
- [
305
- 'Alias',
306
- [
307
- 'SelectQuery',
308
- ['Select', [['ReferencedField', 'table2', 'field2']]],
309
- ['From', ['Table', 'table2']],
310
- [
311
- 'Where',
312
- [
313
- 'Equals',
314
- ['ReferencedField', 'table', 'field3'],
315
- ['ReferencedField', 'table2', 'field4'],
316
- ],
317
- ],
318
- ],
319
- 'atable2',
320
- ],
321
- ],
322
- ]),
323
- ).to.deep.equal({
324
- table: ['field1', 'field3'],
325
- table2: ['field2', 'field4'],
326
- });
327
- });
328
-
329
- it('should work with select queries in the from', () => {
330
- expect(
331
- AbstractSqlCompiler.postgres.getReferencedFields([
332
- 'SelectQuery',
333
- [
334
- 'Select',
335
- [
336
- ['ReferencedField', 'table', 'field1'],
337
- ['ReferencedField', 'atable2', 'afield2'],
338
- ],
339
- ],
340
- ['From', ['Table', 'table']],
341
- [
342
- 'From',
343
- [
344
- 'Alias',
345
- [
346
- 'SelectQuery',
347
- [
348
- 'Select',
349
- [['Alias', ['ReferencedField', 'table2', 'field2'], 'afield2']],
350
- ],
351
- ['From', ['Table', 'table2']],
352
- [
353
- 'Where',
354
- [
355
- 'Equals',
356
- ['ReferencedField', 'table', 'field3'],
357
- ['ReferencedField', 'table2', 'field4'],
358
- ],
359
- ],
360
- ],
361
- 'atable2',
362
- ],
363
- ],
364
- ]),
365
- ).to.deep.equal({
366
- table: ['field1', 'field3'],
367
- table2: ['field2', 'field4'],
368
- });
369
- });
370
-
371
- it('should work with select queries in the select and from', () => {
372
- expect(
373
- AbstractSqlCompiler.postgres.getReferencedFields([
374
- 'SelectQuery',
375
- [
376
- 'Select',
377
- [
378
- ['ReferencedField', 'table', 'field1'],
379
- ['ReferencedField', 'atable2', 'afield2'],
380
- [
381
- 'Alias',
382
- [
383
- 'SelectQuery',
384
- ['Select', [['ReferencedField', 'table3', 'field5']]],
385
- ['From', ['Table', 'table3']],
386
- [
387
- 'Where',
388
- [
389
- 'Equals',
390
- ['ReferencedField', 'table', 'field6'],
391
- ['ReferencedField', 'table3', 'field7'],
392
- ],
393
- ],
394
- ],
395
- 'afield',
396
- ],
397
- ],
398
- ],
399
- ['From', ['Table', 'table']],
400
- [
401
- 'From',
402
- [
403
- 'Alias',
404
- [
405
- 'SelectQuery',
406
- [
407
- 'Select',
408
- [['Alias', ['ReferencedField', 'table2', 'field2'], 'afield2']],
409
- ],
410
- ['From', ['Table', 'table2']],
411
- [
412
- 'Where',
413
- [
414
- 'Equals',
415
- ['ReferencedField', 'table', 'field3'],
416
- ['ReferencedField', 'table2', 'field4'],
417
- ],
418
- ],
419
- ],
420
- 'atable2',
421
- ],
422
- ],
423
- ]),
424
- ).to.deep.equal({
425
- table: ['field1', 'field6', 'field3'],
426
- table2: ['field2', 'field4'],
427
- table3: ['field5', 'field7'],
428
- });
429
- });
430
-
431
- it('should work with nested select queries in the from', () => {
432
- expect(
433
- AbstractSqlCompiler.postgres.getReferencedFields([
434
- 'SelectQuery',
435
- [
436
- 'Select',
437
- [
438
- ['ReferencedField', 'table', 'field1'],
439
- ['ReferencedField', 'aatable2', 'aafield2'],
440
- ],
441
- ],
442
- ['From', ['Table', 'table']],
443
- [
444
- 'From',
445
- [
446
- 'Alias',
447
- [
448
- 'SelectQuery',
449
- [
450
- 'Select',
451
- [
452
- [
453
- 'Alias',
454
- ['ReferencedField', 'atable2', 'afield2'],
455
- 'aafield2',
456
- ],
457
- ],
458
- ],
459
- [
460
- 'From',
461
- [
462
- 'Alias',
463
- [
464
- 'SelectQuery',
465
- [
466
- 'Select',
467
- [
468
- [
469
- 'Alias',
470
- ['ReferencedField', 'table2', 'field2'],
471
- 'afield2',
472
- ],
473
- [
474
- 'Alias',
475
- ['ReferencedField', 'table', 'field5'],
476
- 'afield5',
477
- ],
478
- [
479
- 'Alias',
480
- ['ReferencedField', 'table3', 'field6'],
481
- 'afield6',
482
- ],
483
- ],
484
- ],
485
- ['From', ['Table', 'table3']],
486
- [
487
- 'Where',
488
- [
489
- 'Equals',
490
- ['ReferencedField', 'table2', 'field7'],
491
- ['ReferencedField', 'table3', 'field8'],
492
- ],
493
- ],
494
- ],
495
- 'atable2',
496
- ],
497
- ],
498
- ['From', ['Table', 'table2']],
499
- [
500
- 'Where',
501
- [
502
- 'Equals',
503
- ['ReferencedField', 'table', 'field3'],
504
- ['ReferencedField', 'table2', 'field4'],
505
- ],
506
- ],
507
- ],
508
- 'aatable2',
509
- ],
510
- ],
511
- ]),
512
- ).to.deep.equal({
513
- table: ['field1', 'field5', 'field3'],
514
- table2: ['field2', 'field7', 'field4'],
515
- table3: ['field6', 'field8'],
516
- });
517
- });
518
-
519
- it('should work with nested select queries in the select', () => {
520
- expect(
521
- AbstractSqlCompiler.postgres.getReferencedFields([
522
- 'SelectQuery',
523
- [
524
- 'Select',
525
- [
526
- ['ReferencedField', 'table', 'field1'],
527
- [
528
- 'Alias',
529
- [
530
- 'SelectQuery',
531
- [
532
- 'Select',
533
- [
534
- [
535
- 'Alias',
536
- [
537
- 'SelectQuery',
538
- [
539
- 'Select',
540
- [
541
- [
542
- 'Alias',
543
- ['ReferencedField', 'table2', 'field2'],
544
- 'afield2',
545
- ],
546
- [
547
- 'Alias',
548
- ['ReferencedField', 'table', 'field5'],
549
- 'afield5',
550
- ],
551
- [
552
- 'Alias',
553
- ['ReferencedField', 'table3', 'field6'],
554
- 'afield6',
555
- ],
556
- ],
557
- ],
558
- ['From', ['Table', 'table3']],
559
- [
560
- 'Where',
561
- [
562
- 'Equals',
563
- ['ReferencedField', 'table2', 'field7'],
564
- ['ReferencedField', 'table3', 'field8'],
565
- ],
566
- ],
567
- ],
568
- 'aafield2',
569
- ],
570
- ],
571
- ],
572
- ['From', ['Table', 'table2']],
573
- [
574
- 'Where',
575
- [
576
- 'Equals',
577
- ['ReferencedField', 'table', 'field3'],
578
- ['ReferencedField', 'table2', 'field4'],
579
- ],
580
- ],
581
- ],
582
- 'aafield2',
583
- ],
584
- ],
585
- ],
586
- ['From', ['Table', 'table']],
587
- ]),
588
- ).to.deep.equal({
589
- table: ['field1', 'field5', 'field3'],
590
- table2: ['field2', 'field7', 'field4'],
591
- table3: ['field6', 'field8'],
592
- });
593
- });
594
-
595
- it('should work with from select query with select query in its select', () => {
596
- expect(
597
- AbstractSqlCompiler.postgres.getReferencedFields([
598
- 'SelectQuery',
599
- [
600
- 'Select',
601
- [
602
- ['ReferencedField', 'table', 'field1'],
603
- ['ReferencedField', 'aatable2', 'aafield2'],
604
- ],
605
- ],
606
- ['From', ['Table', 'table']],
607
- [
608
- 'From',
609
- [
610
- 'Alias',
611
- [
612
- 'SelectQuery',
613
- [
614
- 'Select',
615
- [
616
- [
617
- 'Alias',
618
- [
619
- 'SelectQuery',
620
- [
621
- 'Select',
622
- [
623
- [
624
- 'Alias',
625
- ['ReferencedField', 'table2', 'field2'],
626
- 'afield2',
627
- ],
628
- [
629
- 'Alias',
630
- ['ReferencedField', 'table', 'field5'],
631
- 'afield5',
632
- ],
633
- [
634
- 'Alias',
635
- ['ReferencedField', 'table3', 'field6'],
636
- 'afield6',
637
- ],
638
- ],
639
- ],
640
- ['From', ['Table', 'table3']],
641
- [
642
- 'Where',
643
- [
644
- 'Equals',
645
- ['ReferencedField', 'table2', 'field7'],
646
- ['ReferencedField', 'table3', 'field8'],
647
- ],
648
- ],
649
- ],
650
- 'atable2',
651
- ],
652
- ],
653
- ],
654
- ['From', ['Table', 'table2']],
655
- [
656
- 'Where',
657
- [
658
- 'Equals',
659
- ['ReferencedField', 'table', 'field3'],
660
- ['ReferencedField', 'table2', 'field4'],
661
- ],
662
- ],
663
- ],
664
- 'aatable2',
665
- ],
666
- ],
667
- ]),
668
- ).to.deep.equal({
669
- table: ['field1', 'field5', 'field3'],
670
- table2: ['field2', 'field7', 'field4'],
671
- table3: ['field6', 'field8'],
672
- });
673
- });
674
- });