@balena/abstract-sql-compiler 10.5.0-build-joshbwlng-date-trunc-456a4a82262ae24000cf4427451b6ef107b876b3-1 → 11.0.0-build-11-x-db9cd30f6ec498e5293df9e060f5531cd960b1cc-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 +28 -7
  2. package/CHANGELOG.md +4 -2
  3. package/out/AbstractSQLCompiler.d.ts +6 -5
  4. package/out/AbstractSQLCompiler.js +45 -57
  5. package/out/AbstractSQLCompiler.js.map +1 -1
  6. package/out/AbstractSQLOptimiser.d.ts +1 -1
  7. package/out/AbstractSQLOptimiser.js +8 -56
  8. package/out/AbstractSQLOptimiser.js.map +1 -1
  9. package/out/AbstractSQLRules2SQL.d.ts +2 -2
  10. package/out/AbstractSQLRules2SQL.js +206 -229
  11. package/out/AbstractSQLRules2SQL.js.map +1 -1
  12. package/out/AbstractSQLSchemaOptimiser.d.ts +2 -2
  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 +22 -18
  20. package/src/AbstractSQLOptimiser.ts +6 -22
  21. package/src/AbstractSQLRules2SQL.ts +6 -11
  22. package/src/AbstractSQLSchemaOptimiser.ts +6 -5
  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 -27
  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
 
@@ -174,9 +178,7 @@ export type NumberTypeNodes = StrictNumberTypeNodes | UnknownTypeNodes;
174
178
 
175
179
  export type FieldNode = ['Field', string];
176
180
  export type ReferencedFieldNode = ['ReferencedField', string, string];
177
- export type DateTruncNode =
178
- | ['DateTrunc', TextTypeNodes, DateTypeNodes]
179
- | ['DateTrunc', TextTypeNodes, DateTypeNodes, TextTypeNodes];
181
+ export type DateTruncNode = ['DateTrunc', TextTypeNodes, DateTypeNodes];
180
182
  export type ToDateNode = ['ToDate', DateTypeNodes];
181
183
  export type ToTimeNode = ['ToTime', DateTypeNodes];
182
184
  export type CurrentTimestampNode = ['CurrentTimestamp'];
@@ -495,6 +497,7 @@ export interface AbstractSqlTable {
495
497
  primitive: false | string;
496
498
  triggers?: Trigger[];
497
499
  checks?: Check[];
500
+ viewDefinition?: Omit<Definition, 'binds'>;
498
501
  definition?: Definition;
499
502
  modifyFields?: AbstractSqlTable['fields'];
500
503
  modifyName?: AbstractSqlTable['name'];
@@ -813,18 +816,19 @@ $$;`);
813
816
  if (typeof table === 'string') {
814
817
  return;
815
818
  }
816
- const { definition } = table;
817
- if (definition != null) {
819
+ const { definition, viewDefinition } = table;
820
+ if (viewDefinition != null && definition != null) {
821
+ throw new Error('Cannot have both a definition and a viewDefinition');
822
+ }
823
+ if (definition != null || viewDefinition != null) {
818
824
  if (table.fields.some(({ computed }) => computed != null)) {
819
825
  throw new Error(
820
826
  `Using computed fields alongside a custom table definition is unsupported, found for table resourceName: '${table.resourceName}', name: '${table.name}'`,
821
827
  );
822
828
  }
823
- if (definition.binds != null && definition.binds.length > 0) {
824
- // If there are any binds then it's a dynamic definition and cannot become a view
825
- return;
826
- }
827
- let definitionAbstractSql = definition.abstractSql;
829
+ }
830
+ if (viewDefinition != null) {
831
+ let definitionAbstractSql = viewDefinition.abstractSql;
828
832
  // If there are any resource nodes then it's a dynamic definition and cannot become a view
829
833
  if (containsNode(definitionAbstractSql, isResourceNode)) {
830
834
  return;
@@ -25,6 +25,7 @@ import type {
25
25
  CrossJoinNode,
26
26
  CurrentDateNode,
27
27
  CurrentTimestampNode,
28
+ DateTruncNode,
28
29
  DeleteQueryNode,
29
30
  DivideNode,
30
31
  DurationNode,
@@ -70,7 +71,6 @@ import type {
70
71
  ReferencedFieldNode,
71
72
  ReplaceNode,
72
73
  StrictBooleanTypeNodes,
73
- StrictDateTypeNodes,
74
74
  StrictNumberTypeNodes,
75
75
  StrictTextTypeNodes,
76
76
  RightJoinNode,
@@ -104,9 +104,9 @@ import type {
104
104
  EscapeForLikeNode,
105
105
  EqualsAnyNode,
106
106
  NotInNode,
107
- } from './AbstractSQLCompiler';
108
- import { isFieldTypeNode } from './AbstractSQLCompiler';
109
- import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL';
107
+ } from './AbstractSQLCompiler.js';
108
+ import { isFieldTypeNode } from './AbstractSQLCompiler.js';
109
+ import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL.js';
110
110
 
111
111
  const {
112
112
  isAbstractSqlQuery,
@@ -298,9 +298,7 @@ const BooleanValue = MatchValue<BooleanTypeNodes>(
298
298
  isBooleanValue as typeof AbstractSQLRules2SQL.isBooleanValue,
299
299
  );
300
300
 
301
- const isDateValue = (type: unknown): type is 'Now' | StrictDateTypeNodes[0] => {
302
- return type === 'Now' || AbstractSQLRules2SQL.isDateValue(type);
303
- };
301
+ const { isDateValue } = AbstractSQLRules2SQL;
304
302
  const DateValue = MatchValue(isDateValue);
305
303
 
306
304
  const { isJSONValue } = AbstractSQLRules2SQL;
@@ -886,16 +884,7 @@ const typeRules = {
886
884
  Floor: matchArgs<FloorNode>('Floor', NumericValue),
887
885
  Ceiling: matchArgs<CeilingNode>('Ceiling', NumericValue),
888
886
  ToDate: matchArgs<ToDateNode>('ToDate', DateValue),
889
- DateTrunc: (args) => {
890
- checkMinArgs('DateTrunc', args, 2);
891
- const precision = TextValue(getAbstractSqlQuery(args, 0));
892
- const date = DateValue(getAbstractSqlQuery(args, 1));
893
- const timeZone =
894
- args.length === 3 ? TextValue(getAbstractSqlQuery(args, 2)) : undefined;
895
- return timeZone
896
- ? ['DateTrunc', precision, date, timeZone]
897
- : ['DateTrunc', precision, date];
898
- },
887
+ DateTrunc: matchArgs<DateTruncNode>('DateTrunc', TextValue, DateValue),
899
888
  ToTime: matchArgs<ToTimeNode>('ToTime', DateValue),
900
889
  ExtractJSONPathAsText: (args): ExtractJSONPathAsTextNode => {
901
890
  checkMinArgs('ExtractJSONPathAsText', args, 1);
@@ -1532,11 +1521,6 @@ const typeRules = {
1532
1521
  EscapeForLike: matchArgs<EscapeForLikeNode>('EscapeForLike', TextValue),
1533
1522
 
1534
1523
  // Virtual functions
1535
- Now: rewriteMatch(
1536
- 'Now',
1537
- [],
1538
- Helper<MatchFn<CurrentTimestampNode>>(() => ['CurrentTimestamp']),
1539
- ),
1540
1524
  Contains: rewriteMatch(
1541
1525
  'Contains',
1542
1526
  [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]
@@ -1207,7 +1208,7 @@ const typeRules: Record<string, MatchFn> = {
1207
1208
  return `DATE(${date})`;
1208
1209
  },
1209
1210
  DateTrunc: (args, indent) => {
1210
- checkMinArgs('DateTrunc', args, 2);
1211
+ checkArgs('DateTrunc', args, 2);
1211
1212
  const precision = TextValue(getAbstractSqlQuery(args, 0), indent);
1212
1213
  const date = DateValue(getAbstractSqlQuery(args, 1), indent);
1213
1214
  // Postgres generated timestamps have a microseconds precision
@@ -1215,13 +1216,7 @@ const typeRules: Record<string, MatchFn> = {
1215
1216
  // js timestamps that have only milliseconds precision
1216
1217
  // thus supporting for truncating to a given precision
1217
1218
  if (engine === Engines.postgres) {
1218
- const timeZone =
1219
- args.length === 3
1220
- ? TextValue(getAbstractSqlQuery(args, 2), indent)
1221
- : undefined;
1222
- return timeZone
1223
- ? `DATE_TRUNC(${precision}, ${date}, ${timeZone})`
1224
- : `DATE_TRUNC(${precision}, ${date})`;
1219
+ return `DATE_TRUNC(${precision}, ${date})`;
1225
1220
  } else if (
1226
1221
  // not postgresql ==> no need to truncate ==> return timestamp as is (milliseconds precision)
1227
1222
  precision === "'milliseconds'" ||
@@ -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;
@@ -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(
@@ -127,29 +127,6 @@ describe('DateTrunc', () => {
127
127
  });
128
128
  },
129
129
  );
130
-
131
- test(
132
- [
133
- 'SelectQuery',
134
- [
135
- 'Select',
136
- [
137
- [
138
- 'DateTrunc',
139
- ['EmbeddedText', 'year'],
140
- ['Date', '2022-10-10'],
141
- ['EmbeddedText', 'UTC'],
142
- ],
143
- ],
144
- ],
145
- ],
146
- [['Date', '2022-10-10']],
147
- (result, sqlEquals) => {
148
- it('should produce a valid DateTrunc statement', () => {
149
- sqlEquals(result, `SELECT DATE_TRUNC('year', $1, 'UTC')`);
150
- });
151
- },
152
- );
153
130
  });
154
131
 
155
132
  describe('ToTime', () => {
@@ -359,7 +336,13 @@ describe('SubtractDateDate', () => {
359
336
  'SelectQuery',
360
337
  [
361
338
  'Select',
362
- [['Multiply', ['SubtractDateDate', ['Now'], ['Now']], ['Number', 4]]],
339
+ [
340
+ [
341
+ 'Multiply',
342
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
343
+ ['Number', 4],
344
+ ],
345
+ ],
363
346
  ],
364
347
  ],
365
348
  (result, sqlEquals) => {
@@ -377,7 +360,7 @@ describe('SubtractDateDate', () => {
377
360
  [
378
361
  [
379
362
  'Multiply',
380
- ['SubtractDateDate', ['Now'], ['Now']],
363
+ ['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
381
364
  ['Subtract', ['Number', 4], ['Number', 5]],
382
365
  ],
383
366
  ],
@@ -403,7 +386,7 @@ describe('SubtractDateDate', () => {
403
386
  'SubtractDateDate',
404
387
  [
405
388
  'AddDateDuration',
406
- ['Now'],
389
+ ['CurrentTimestamp'],
407
390
  [
408
391
  'Duration',
409
392
  {
@@ -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 = (