@balena/abstract-sql-compiler 10.6.3-build-tests-update-66ee93652310d4add5b0c8c09843dc052d796f5e-1 → 11.0.0-build-11-x-9f16483079cd561a9fdaa741cd830c2c5eb2065a-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 (61) hide show
  1. package/.versionbot/CHANGELOG.yml +57 -2
  2. package/CHANGELOG.md +8 -2
  3. package/out/AbstractSQLCompiler.d.ts +15 -16
  4. package/out/AbstractSQLCompiler.js +50 -62
  5. package/out/AbstractSQLCompiler.js.map +1 -1
  6. package/out/AbstractSQLOptimiser.d.ts +1 -1
  7. package/out/AbstractSQLOptimiser.js +9 -54
  8. package/out/AbstractSQLOptimiser.js.map +1 -1
  9. package/out/AbstractSQLRules2SQL.d.ts +2 -2
  10. package/out/AbstractSQLRules2SQL.js +206 -224
  11. package/out/AbstractSQLRules2SQL.js.map +1 -1
  12. package/out/AbstractSQLSchemaOptimiser.d.ts +5 -3
  13. package/out/AbstractSQLSchemaOptimiser.js +14 -21
  14. package/out/AbstractSQLSchemaOptimiser.js.map +1 -1
  15. package/out/referenced-fields.d.ts +1 -1
  16. package/out/referenced-fields.js +17 -24
  17. package/out/referenced-fields.js.map +1 -1
  18. package/package.json +4 -4
  19. package/src/AbstractSQLCompiler.ts +28 -30
  20. package/src/AbstractSQLOptimiser.ts +11 -27
  21. package/src/AbstractSQLRules2SQL.ts +4 -3
  22. package/src/AbstractSQLSchemaOptimiser.ts +7 -6
  23. package/src/referenced-fields.ts +4 -4
  24. package/test/abstract-sql/aggregate-json.ts +1 -1
  25. package/test/abstract-sql/aggregate.ts +25 -10
  26. package/test/abstract-sql/and-or-boolean-optimisations.ts +1 -1
  27. package/test/abstract-sql/case-when-else.ts +5 -2
  28. package/test/abstract-sql/cast.ts +1 -1
  29. package/test/abstract-sql/coalesce.ts +1 -1
  30. package/test/abstract-sql/comparisons.ts +1 -1
  31. package/test/abstract-sql/dates.ts +10 -4
  32. package/test/abstract-sql/duration.ts +1 -1
  33. package/test/abstract-sql/empty-query-optimisations.ts +2 -2
  34. package/test/abstract-sql/functions_wrapper.ts +1 -1
  35. package/test/abstract-sql/get-referenced-fields.ts +1 -1
  36. package/test/abstract-sql/get-rule-referenced-fields.ts +1 -1
  37. package/test/abstract-sql/insert-query.ts +1 -1
  38. package/test/abstract-sql/is-distinct.ts +1 -1
  39. package/test/abstract-sql/joins.ts +1 -1
  40. package/test/abstract-sql/json.ts +1 -1
  41. package/test/abstract-sql/math.ts +1 -1
  42. package/test/abstract-sql/nested-in-optimisations.ts +1 -1
  43. package/test/abstract-sql/not-not-optimisations.ts +1 -1
  44. package/test/abstract-sql/schema-checks.ts +1 -1
  45. package/test/abstract-sql/schema-informative-reference.ts +1 -1
  46. package/test/abstract-sql/schema-rule-optimization.ts +1 -1
  47. package/test/abstract-sql/schema-rule-to-check.ts +1 -1
  48. package/test/abstract-sql/schema-views.ts +37 -2
  49. package/test/abstract-sql/test.ts +1 -1
  50. package/test/abstract-sql/text.ts +1 -1
  51. package/test/odata/expand.ts +3 -3
  52. package/test/odata/filterby.ts +8 -4
  53. package/test/odata/orderby.ts +2 -2
  54. package/test/odata/paging.ts +2 -2
  55. package/test/odata/resource_parsing.ts +5 -5
  56. package/test/odata/select.ts +2 -2
  57. package/test/odata/stress.ts +2 -2
  58. package/test/odata/test.ts +24 -20
  59. package/test/sbvr/pilots.ts +3 -3
  60. package/test/sbvr/reference-type.ts +3 -3
  61. package/test/sbvr/test.ts +12 -10
@@ -6,24 +6,28 @@ export const enum Engines {
6
6
  /* eslint-enable @typescript-eslint/no-shadow */
7
7
  }
8
8
 
9
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
10
- import type { Binding, SqlResult } from './AbstractSQLRules2SQL';
11
- import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL';
12
- export { Binding, SqlResult } from './AbstractSQLRules2SQL';
9
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
10
+ import type { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
11
+ import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL.js';
12
+ export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
13
13
  import type { SbvrType } from '@balena/sbvr-types';
14
- import sbvrTypes from '@balena/sbvr-types';
15
- import { optimizeSchema, generateRuleSlug } from './AbstractSQLSchemaOptimiser';
14
+ import $sbvrTypes from '@balena/sbvr-types';
15
+ const { default: sbvrTypes } = $sbvrTypes;
16
+ import {
17
+ optimizeSchema,
18
+ generateRuleSlug,
19
+ } from './AbstractSQLSchemaOptimiser.js';
16
20
  import type {
17
21
  ReferencedFields,
18
22
  RuleReferencedFields,
19
23
  ModifiedFields,
20
- } from './referenced-fields';
24
+ } from './referenced-fields.js';
21
25
  import {
22
26
  getReferencedFields,
23
27
  getRuleReferencedFields,
24
28
  getModifiedFields,
25
29
  insertAffectedIdsBinds,
26
- } from './referenced-fields';
30
+ } from './referenced-fields.js';
27
31
 
28
32
  export type { ReferencedFields, RuleReferencedFields, ModifiedFields };
29
33
 
@@ -234,14 +238,7 @@ export type CaseNode =
234
238
  | ['Case', ...WhenNode[]]
235
239
  | ['Case', ...WhenNode[], ElseNode];
236
240
 
237
- /**
238
- * @deprecated This gets converted to the `['Bind', [string, string]]` form during compilation
239
- */
240
- type BackCompatBindNode = ['Bind', string, string];
241
- export type BindNode =
242
- | ['Bind', number | string]
243
- | ['Bind', [string, string]]
244
- | BackCompatBindNode;
241
+ export type BindNode = ['Bind', number | string] | ['Bind', [string, string]];
245
242
  export type CastNode = ['Cast', AnyTypeNodes, string];
246
243
  export type CoalesceNode = [
247
244
  'Coalesce',
@@ -380,11 +377,6 @@ export type FromTypeNodes =
380
377
  | FromTypeNode[keyof FromTypeNode]
381
378
  | AliasNode<FromTypeNode[keyof FromTypeNode]>;
382
379
 
383
- /**
384
- * @deprecated `FromTypeNodes` already includes aliased versions
385
- */
386
- export type AliasableFromTypeNodes = FromTypeNodes;
387
-
388
380
  export type SelectNode = ['Select', AnyTypeNodes[]];
389
381
  export type FromNode = ['From', FromTypeNodes];
390
382
  export type InnerJoinNode = ['Join', FromTypeNodes, OnNode?];
@@ -494,6 +486,7 @@ export interface AbstractSqlTable {
494
486
  primitive: false | string;
495
487
  triggers?: Trigger[];
496
488
  checks?: Check[];
489
+ viewDefinition?: Omit<Definition, 'binds'>;
497
490
  definition?: Definition;
498
491
  modifyFields?: AbstractSqlTable['fields'];
499
492
  modifyName?: AbstractSqlTable['name'];
@@ -754,7 +747,9 @@ const compileSchema = (
754
747
  engine: Engines,
755
748
  ifNotExists: boolean,
756
749
  ): SqlModel => {
757
- abstractSqlModel = optimizeSchema(abstractSqlModel, false);
750
+ abstractSqlModel = optimizeSchema(abstractSqlModel, {
751
+ createCheckConstraints: false,
752
+ });
758
753
 
759
754
  let ifNotExistsStr = '';
760
755
  let orReplaceStr = '';
@@ -815,21 +810,24 @@ $$;`);
815
810
  if (typeof table === 'string') {
816
811
  return;
817
812
  }
818
- const { definition } = table;
819
- if (definition != null) {
813
+ const { definition, viewDefinition } = table;
814
+ if (viewDefinition != null && definition != null) {
815
+ throw new Error('Cannot have both a definition and a viewDefinition');
816
+ }
817
+ if (definition != null || viewDefinition != null) {
820
818
  if (table.fields.some(({ computed }) => computed != null)) {
821
819
  throw new Error(
822
820
  `Using computed fields alongside a custom table definition is unsupported, found for table resourceName: '${table.resourceName}', name: '${table.name}'`,
823
821
  );
824
822
  }
825
- if (definition.binds != null && definition.binds.length > 0) {
826
- // If there are any binds then it's a dynamic definition and cannot become a view
827
- return;
828
- }
829
- let definitionAbstractSql = definition.abstractSql;
823
+ }
824
+ if (viewDefinition != null) {
825
+ let definitionAbstractSql = viewDefinition.abstractSql;
830
826
  // If there are any resource nodes then it's a dynamic definition and cannot become a view
831
827
  if (abstractSqlContainsNode(definitionAbstractSql, isResourceNode)) {
832
- return;
828
+ throw new Error(
829
+ `Cannot create a view from a dynamic viewDefinition, found for table resourceName: '${table.resourceName}', name: '${table.name}'`,
830
+ );
833
831
  }
834
832
  if (isTableNode(definitionAbstractSql)) {
835
833
  // If the definition is a table node we need to wrap it in a select query for the view creation
@@ -70,7 +70,6 @@ import type {
70
70
  ReferencedFieldNode,
71
71
  ReplaceNode,
72
72
  StrictBooleanTypeNodes,
73
- StrictDateTypeNodes,
74
73
  StrictNumberTypeNodes,
75
74
  StrictTextTypeNodes,
76
75
  RightJoinNode,
@@ -104,9 +103,9 @@ import type {
104
103
  EscapeForLikeNode,
105
104
  EqualsAnyNode,
106
105
  NotInNode,
107
- } from './AbstractSQLCompiler';
108
- import { isFieldTypeNode } from './AbstractSQLCompiler';
109
- import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL';
106
+ } from './AbstractSQLCompiler.js';
107
+ import { isFieldTypeNode } from './AbstractSQLCompiler.js';
108
+ import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL.js';
110
109
 
111
110
  const {
112
111
  isAbstractSqlQuery,
@@ -297,9 +296,7 @@ const BooleanValue = MatchValue<BooleanTypeNodes>(
297
296
  isBooleanValue as typeof AbstractSQLRules2SQL.isBooleanValue,
298
297
  );
299
298
 
300
- const isDateValue = (type: unknown): type is 'Now' | StrictDateTypeNodes[0] => {
301
- return type === 'Now' || AbstractSQLRules2SQL.isDateValue(type);
302
- };
299
+ const { isDateValue } = AbstractSQLRules2SQL;
303
300
  const DateValue = MatchValue(isDateValue);
304
301
 
305
302
  const { isJSONValue } = AbstractSQLRules2SQL;
@@ -1219,21 +1216,13 @@ const typeRules = {
1219
1216
  ];
1220
1217
  },
1221
1218
  ),
1222
- Bind: tryMatches<BindNode>(
1223
- Helper<OptimisationMatchFn<BindNode>>((args) => {
1224
- if (args.length !== 2) {
1225
- return false;
1226
- }
1227
- return ['Bind', args] as BindNode;
1228
- }),
1229
- (args) => {
1230
- if (noBinds) {
1231
- throw new SyntaxError('Cannot use a bind whilst they are disabled');
1232
- }
1233
- checkArgs('Bind', args, 1);
1234
- return ['Bind', ...args] as BindNode;
1235
- },
1236
- ),
1219
+ Bind: (args) => {
1220
+ if (noBinds) {
1221
+ throw new SyntaxError('Cannot use a bind whilst they are disabled');
1222
+ }
1223
+ checkArgs('Bind', args, 1);
1224
+ return ['Bind', ...args] as BindNode;
1225
+ },
1237
1226
  Text,
1238
1227
  Value: Text,
1239
1228
  Date: matchArgs('Date', identity),
@@ -1531,11 +1520,6 @@ const typeRules = {
1531
1520
  EscapeForLike: matchArgs<EscapeForLikeNode>('EscapeForLike', TextValue),
1532
1521
 
1533
1522
  // Virtual functions
1534
- Now: rewriteMatch(
1535
- 'Now',
1536
- [],
1537
- Helper<MatchFn<CurrentTimestampNode>>(() => ['CurrentTimestamp']),
1538
- ),
1539
1523
  Contains: rewriteMatch(
1540
1524
  'Contains',
1541
1525
  [TextValue, TextValue],
@@ -1,4 +1,5 @@
1
- import sbvrTypes from '@balena/sbvr-types';
1
+ import $sbvrTypes from '@balena/sbvr-types';
2
+ const { default: sbvrTypes } = $sbvrTypes;
2
3
  import type {
3
4
  AbstractSqlQuery,
4
5
  AbstractSqlType,
@@ -17,8 +18,8 @@ import type {
17
18
  StrictDurationTypeNodes,
18
19
  StrictTextArrayTypeNodes,
19
20
  StrictJSONTypeNodes,
20
- } from './AbstractSQLCompiler';
21
- import { Engines, isFieldTypeNode } from './AbstractSQLCompiler';
21
+ } from './AbstractSQLCompiler.js';
22
+ import { Engines, isFieldTypeNode } from './AbstractSQLCompiler.js';
22
23
 
23
24
  export type Binding =
24
25
  | [string, any]
@@ -4,17 +4,18 @@ export const enum Engines {
4
4
  websql = 'websql',
5
5
  }
6
6
 
7
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
8
- export { Binding, SqlResult } from './AbstractSQLRules2SQL';
9
- import sbvrTypes from '@balena/sbvr-types';
7
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
8
+ export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
9
+ import $sbvrTypes from '@balena/sbvr-types';
10
+ const { default: sbvrTypes } = $sbvrTypes;
10
11
  import type {
11
12
  AbstractSqlModel,
12
13
  AbstractSqlQuery,
13
14
  AbstractSqlType,
14
15
  BooleanTypeNodes,
15
16
  WhereNode,
16
- } from './AbstractSQLCompiler';
17
- import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler';
17
+ } from './AbstractSQLCompiler.js';
18
+ import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler.js';
18
19
 
19
20
  const countFroms = (n: AbstractSqlType[]) => {
20
21
  let count = 0;
@@ -43,7 +44,7 @@ export const generateRuleSlug = (
43
44
 
44
45
  export const optimizeSchema = (
45
46
  abstractSqlModel: AbstractSqlModel,
46
- createCheckConstraints = true,
47
+ { createCheckConstraints = true } = {},
47
48
  ): AbstractSqlModel => {
48
49
  abstractSqlModel.rules = abstractSqlModel.rules
49
50
  .map((rule): AbstractSqlQuery | undefined => {
@@ -48,7 +48,7 @@ import type {
48
48
  ToJSONNode,
49
49
  UnionQueryNode,
50
50
  WhereNode,
51
- } from './AbstractSQLCompiler';
51
+ } from './AbstractSQLCompiler.js';
52
52
  import {
53
53
  isAliasNode,
54
54
  isFromNode,
@@ -56,9 +56,9 @@ import {
56
56
  isSelectQueryNode,
57
57
  isTableNode,
58
58
  isWhereNode,
59
- } from './AbstractSQLCompiler';
60
- import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
61
- import { isAbstractSqlQuery } from './AbstractSQLRules2SQL';
59
+ } from './AbstractSQLCompiler.js';
60
+ import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
61
+ import { isAbstractSqlQuery } from './AbstractSQLRules2SQL.js';
62
62
 
63
63
  export interface ReferencedFields {
64
64
  [alias: string]: string[];
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('AggregateJSON', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Count', () => {
5
5
  test(['SelectQuery', ['Select', [['Count', '*']]]], (result, sqlEquals) => {
@@ -33,7 +33,10 @@ describe('Sum', () => {
33
33
 
34
34
  describe('Subtract now timestamp from now timestamp', () => {
35
35
  test(
36
- ['SelectQuery', ['Select', [['Subtract', ['Now'], ['Now']]]]],
36
+ [
37
+ 'SelectQuery',
38
+ ['Select', [['Subtract', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
39
+ ],
37
40
  (result, sqlEquals) => {
38
41
  it('Subtract now timestamp from now timestamp', () => {
39
42
  sqlEquals(result, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
@@ -46,7 +49,10 @@ describe('Subtract Duration from now timestamp', () => {
46
49
  test(
47
50
  [
48
51
  'SelectQuery',
49
- ['Select', [['Subtract', ['Now'], ['Duration', { day: 1 }]]]],
52
+ [
53
+ 'Select',
54
+ [['Subtract', ['CurrentTimestamp'], ['Duration', { day: 1 }]]],
55
+ ],
50
56
  ],
51
57
  (result, sqlEquals) => {
52
58
  it('Subtract Duration from now timestamp', () => {
@@ -58,16 +64,25 @@ describe('Subtract Duration from now timestamp', () => {
58
64
 
59
65
  // this is not allowed
60
66
  describe('Add now timestamp to now timestamp should fail', () => {
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
- });
67
+ test.fail(
68
+ [
69
+ 'SelectQuery',
70
+ ['Select', [['Add', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
71
+ ],
72
+ (err) => {
73
+ it('Add now timestamp to now timestamp should fail', () => {
74
+ expect(err).to.be.an('error');
75
+ });
76
+ },
77
+ );
66
78
  });
67
79
 
68
80
  describe('Add Duration to now timestamp', () => {
69
81
  test(
70
- ['SelectQuery', ['Select', [['Add', ['Now'], ['Duration', { day: 1 }]]]]],
82
+ [
83
+ 'SelectQuery',
84
+ ['Select', [['Add', ['CurrentTimestamp'], ['Duration', { day: 1 }]]]],
85
+ ],
71
86
  (result, sqlEquals) => {
72
87
  it('Add Duration to now timestamp', () => {
73
88
  sqlEquals(result, `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`);
@@ -85,7 +100,7 @@ describe('Substract DateTrunc datefield from now timestamp', () => {
85
100
  [
86
101
  [
87
102
  'Subtract',
88
- ['Now'],
103
+ ['CurrentTimestamp'],
89
104
  [
90
105
  'DateTrunc',
91
106
  ['EmbeddedText', 'milliseconds'],
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Unnecessary booleans should be removed', () => {
5
5
  test(
@@ -1,5 +1,8 @@
1
- import type { CaseNode, SelectQueryNode } from '../../src/AbstractSQLCompiler';
2
- import test from './test';
1
+ import type {
2
+ CaseNode,
3
+ SelectQueryNode,
4
+ } from '../../out/AbstractSQLCompiler.js';
5
+ import test from './test.js';
3
6
 
4
7
  const buildSelect = (withElse: boolean): SelectQueryNode => {
5
8
  let caseNode: CaseNode = [
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Cast', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Coalesce', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Between', () => {
5
5
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Year', () => {
4
4
  test(
@@ -359,7 +359,13 @@ describe('SubtractDateDate', () => {
359
359
  'SelectQuery',
360
360
  [
361
361
  'Select',
362
- [['Multiply', ['SubtractDateDate', ['Now'], ['Now']], ['Number', 4]]],
362
+ [
363
+ [
364
+ 'Multiply',
365
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
366
+ ['Number', 4],
367
+ ],
368
+ ],
363
369
  ],
364
370
  ],
365
371
  (result, sqlEquals) => {
@@ -377,7 +383,7 @@ describe('SubtractDateDate', () => {
377
383
  [
378
384
  [
379
385
  'Multiply',
380
- ['SubtractDateDate', ['Now'], ['Now']],
386
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
381
387
  ['Subtract', ['Number', 4], ['Number', 5]],
382
388
  ],
383
389
  ],
@@ -403,7 +409,7 @@ describe('SubtractDateDate', () => {
403
409
  'SubtractDateDate',
404
410
  [
405
411
  'AddDateDuration',
406
- ['Now'],
412
+ ['CurrentTimestamp'],
407
413
  [
408
414
  'Duration',
409
415
  {
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Totalseconds', () => {
4
4
  test(
@@ -1,7 +1,7 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import type { SelectQueryNode } from '../../src/AbstractSQLCompiler';
2
+ import type { SelectQueryNode } from '../../out/AbstractSQLCompiler.js';
3
3
 
4
- import test from './test';
4
+ import test from './test.js';
5
5
 
6
6
  describe('Empty queries should be optimized', () => {
7
7
  const emptyQuery: SelectQueryNode = [
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Date trunc function on ReferencedField for milliseconds', () => {
5
5
  test(
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../src/AbstractSQLCompiler';
2
+ import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
3
3
 
4
4
  describe('getReferencedFields', () => {
5
5
  it('should work with selected fields', () => {
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'chai';
2
- import * as AbstractSqlCompiler from '../../src/AbstractSQLCompiler';
2
+ import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
3
3
 
4
4
  describe('getRuleReferencedFields', () => {
5
5
  it('should work with single table NOT EXISTS', () => {
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Insert boolean value', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('IsDistinctFrom', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  const joinTest = (
5
5
  joinType: 'Join' | 'RightJoin' | 'LeftJoin' | 'FullJoin',
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('ExtractJSONPathAsText', () => {
4
4
  test(
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Add', () => {
4
4
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('Nested OR EQUALs should create a single IN statement', () => {
5
5
  test(
@@ -1,5 +1,5 @@
1
1
  import { stripIndent } from 'common-tags';
2
- import test from './test';
2
+ import test from './test.js';
3
3
 
4
4
  describe('NOT(NOT(...)) should cancel each other out', () => {
5
5
  test(['Not', ['Not', ['Boolean', true]]], [], (result, sqlEquals) => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  it('an empty abstractSql model should produce an empty schema', () => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  describe('generate informative reference schema', () => {
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  const generateSchema = (
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
4
  const generateSchema = (
@@ -1,7 +1,7 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
  import { expect } from 'chai';
3
3
 
4
- it('a table with a static definition should produce a view', () => {
4
+ it('a table with a static definition should not produce a view', () => {
5
5
  expect(
6
6
  AbstractSQLCompiler.postgres.compileSchema({
7
7
  synonyms: {},
@@ -30,6 +30,41 @@ it('a table with a static definition should produce a view', () => {
30
30
  .to.have.property('createSchema')
31
31
  .that.deep.equals([
32
32
  `\
33
+ CREATE TABLE IF NOT EXISTS "test" (
34
+ "id" INTEGER NULL PRIMARY KEY
35
+ );`,
36
+ ]);
37
+ });
38
+
39
+ it('a table with a view definition should produce a view', () => {
40
+ expect(
41
+ AbstractSQLCompiler.postgres.compileSchema({
42
+ synonyms: {},
43
+ relationships: {},
44
+ tables: {
45
+ test: {
46
+ name: 'test',
47
+ resourceName: 'test',
48
+ idField: 'id',
49
+ fields: [
50
+ {
51
+ fieldName: 'id',
52
+ dataType: 'Integer',
53
+ index: 'PRIMARY KEY',
54
+ },
55
+ ],
56
+ indexes: [],
57
+ primitive: false,
58
+ viewDefinition: { abstractSql: ['Table', 'other table'] },
59
+ },
60
+ },
61
+ rules: [],
62
+ lfInfo: { rules: {} },
63
+ }),
64
+ )
65
+ .to.have.property('createSchema')
66
+ .that.deep.equals([
67
+ `\
33
68
  CREATE OR REPLACE VIEW "test" AS (
34
69
  SELECT *
35
70
  FROM "other table"
@@ -1,4 +1,4 @@
1
- import * as AbstractSQLCompiler from '../..';
1
+ import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
2
2
 
3
3
  import { expect } from 'chai';
4
4
  import _ from 'lodash';
@@ -1,4 +1,4 @@
1
- import test from './test';
1
+ import test from './test.js';
2
2
 
3
3
  describe('Concatenate', () => {
4
4
  test(
@@ -1,12 +1,12 @@
1
- import type { ExpectationFailFn, ExpectationSuccessFn } from './test';
2
- import test from './test';
1
+ import type { ExpectationFailFn, ExpectationSuccessFn } from './test.js';
2
+ import test from './test.js';
3
3
  import {
4
4
  pilotFields,
5
5
  aliasFields,
6
6
  aliasLicenceFields,
7
7
  aliasPlaneFields,
8
8
  aliasPilotCanFlyPlaneFields,
9
- } from './fields';
9
+ } from './fields.js';
10
10
  import _ from 'lodash';
11
11
 
12
12
  type TestFn = (
@@ -4,16 +4,20 @@
4
4
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
5
5
  */
6
6
  import { expect } from 'chai';
7
- import type { ExpectationSuccessFn } from './test';
8
- import test, { clientModel } from './test';
7
+ import type { ExpectationSuccessFn } from './test.js';
8
+ import test, { clientModel } from './test.js';
9
9
  import _ from 'lodash';
10
10
  import { odataNameToSqlName } from '@balena/odata-to-abstract-sql';
11
- import { pilotFields, teamFields, aliasPilotCanFlyPlaneFields } from './fields';
11
+ import {
12
+ pilotFields,
13
+ teamFields,
14
+ aliasPilotCanFlyPlaneFields,
15
+ } from './fields.js';
12
16
  import type {
13
17
  Binding,
14
18
  DurationNode,
15
19
  SqlResult,
16
- } from '../../src/AbstractSQLCompiler';
20
+ } from '../../out/AbstractSQLCompiler.js';
17
21
 
18
22
  const pilotFieldsStr = pilotFields.join(', ');
19
23
  const aliasPilotCanFlyPlaneFieldsStr = aliasPilotCanFlyPlaneFields.join(', ');