@balena/abstract-sql-compiler
Advanced tools
Comparing version 9.0.7 to 9.0.8-build-renovate-major--balenalint-326d8aacb8142a51d4b8f57c1b994772bec8c411-1
@@ -7,5 +7,9 @@ # Change Log | ||
## 9.0.7 - 2024-03-21 | ||
## 9.0.8 - 2024-03-26 | ||
* Update dependency @balena/lint to v8 [Thodoris Greasidis] | ||
## 9.0.7 - 2024-03-22 | ||
<details> | ||
@@ -12,0 +16,0 @@ <summary> Update dependency @balena/odata-parser to v3 [Self-hosted Renovate Bot] </summary> |
@@ -6,6 +6,6 @@ export declare const enum Engines { | ||
} | ||
import { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
import type { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
export { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
import * as _ from 'lodash'; | ||
import { ReferencedFields, RuleReferencedFields, ModifiedFields } from './referenced-fields'; | ||
import type { ReferencedFields, RuleReferencedFields, ModifiedFields } from './referenced-fields'; | ||
export type { ReferencedFields, RuleReferencedFields, ModifiedFields }; | ||
@@ -12,0 +12,0 @@ export type NullNode = ['Null']; |
@@ -289,3 +289,3 @@ "use strict"; | ||
if (dependency !== resourceName && | ||
schemaDependencyMap.hasOwnProperty(dependency)) { | ||
Object.prototype.hasOwnProperty.call(schemaDependencyMap, dependency)) { | ||
unsolvedDependency = true; | ||
@@ -292,0 +292,0 @@ break; |
@@ -1,2 +0,2 @@ | ||
import { AbstractSqlQuery } from './AbstractSQLCompiler'; | ||
import type { AbstractSqlQuery } from './AbstractSQLCompiler'; | ||
export declare const AbstractSQLOptimiser: (abstractSQL: AbstractSqlQuery, $noBinds?: boolean) => AbstractSqlQuery; |
@@ -213,3 +213,3 @@ "use strict"; | ||
return arg; | ||
default: | ||
default: { | ||
const [type, ...rest] = arg; | ||
@@ -229,2 +229,3 @@ switch (type) { | ||
} | ||
} | ||
} | ||
@@ -591,3 +592,3 @@ }; | ||
switch (type) { | ||
case 'When': | ||
case 'When': { | ||
checkArgs('When', rest, 2); | ||
@@ -597,2 +598,3 @@ const matches = BooleanValue(getAbstractSqlQuery(rest, 0)); | ||
return ['When', matches, resultValue]; | ||
} | ||
case 'Else': | ||
@@ -971,3 +973,3 @@ if (index !== args.length - 1) { | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -994,2 +996,3 @@ throw new SyntaxError(`'InsertQuery' can only accept one '${type}'`); | ||
break; | ||
} | ||
case 'From': | ||
@@ -1039,3 +1042,3 @@ tables.push(typeRules[type](rest)); | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1049,2 +1052,3 @@ throw new SyntaxError(`'UpdateQuery' can only accept one '${type}'`); | ||
break; | ||
} | ||
case 'From': | ||
@@ -1157,3 +1161,3 @@ tables.push(typeRules[type](rest)); | ||
break; | ||
case 'UpsertQuery': | ||
case 'UpsertQuery': { | ||
checkArgs('UpsertQuery', rest, 2); | ||
@@ -1172,2 +1176,3 @@ const insertQuery = getAbstractSqlQuery(rest, 0); | ||
break; | ||
} | ||
default: | ||
@@ -1174,0 +1179,0 @@ abstractSQL = AnyValue(abstractSQL); |
@@ -1,2 +0,3 @@ | ||
import { AbstractSqlQuery, AbstractSqlType, Engines, InsertQueryNode, SelectQueryNode, UnionQueryNode, UpdateQueryNode, DeleteQueryNode, UpsertQueryNode } from './AbstractSQLCompiler'; | ||
import type { AbstractSqlQuery, AbstractSqlType, InsertQueryNode, SelectQueryNode, UnionQueryNode, UpdateQueryNode, DeleteQueryNode, UpsertQueryNode } from './AbstractSQLCompiler'; | ||
import { Engines } from './AbstractSQLCompiler'; | ||
export type Binding = [string, any] | ['Bind', number | string | [string, string]]; | ||
@@ -3,0 +4,0 @@ export interface SqlResult { |
@@ -54,6 +54,7 @@ "use strict"; | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return '(' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -298,6 +299,7 @@ throw new Error(`Invalid "UnknownValue" type: ${type}`); | ||
switch (type) { | ||
case 'On': | ||
case 'On': { | ||
(0, exports.checkArgs)('On', rest, 1); | ||
const ruleBody = BooleanValue((0, exports.getAbstractSqlQuery)(rest, 0), NestedIndent(indent)); | ||
return sqlJoinType + from + ' ON ' + ruleBody; | ||
} | ||
default: | ||
@@ -477,3 +479,3 @@ throw new SyntaxError(`'${joinType}' clause does not support '${type}' clause`); | ||
return 'DEFAULT'; | ||
default: | ||
default: { | ||
const [type, ...rest] = arg; | ||
@@ -493,2 +495,3 @@ switch (type) { | ||
} | ||
} | ||
} | ||
@@ -509,7 +512,8 @@ }; | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedindent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedindent); | ||
return '(' + nestedindent + query + indent + ')'; | ||
case 'Table': | ||
} | ||
case 'Table': { | ||
(0, exports.checkArgs)('Table', rest, 1); | ||
@@ -521,2 +525,3 @@ const [table] = rest; | ||
return escapeField(table); | ||
} | ||
default: | ||
@@ -529,6 +534,7 @@ throw new SyntaxError(`From does not support ${type}`); | ||
switch (type) { | ||
case 'Alias': | ||
case 'Alias': { | ||
(0, exports.checkArgs)('Alias', rest, 2); | ||
const field = matchFn((0, exports.getAbstractSqlQuery)(rest, 0), indent); | ||
return `${field} AS "${rest[1]}"`; | ||
} | ||
default: | ||
@@ -1073,3 +1079,3 @@ return matchFn(args, indent); | ||
switch (type) { | ||
case 'When': | ||
case 'When': { | ||
(0, exports.checkArgs)('When', rest, 2); | ||
@@ -1079,2 +1085,3 @@ const matches = BooleanValue((0, exports.getAbstractSqlQuery)(rest, 0), NestedIndent(nestedIndent)); | ||
return 'WHEN ' + matches + ' THEN ' + resultValue; | ||
} | ||
case 'Else': | ||
@@ -1172,6 +1179,7 @@ if (index !== args.length - 1) { | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return 'EXISTS (' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -1187,6 +1195,7 @@ return AnyValue(arg, indent) + ' IS NOT NULL'; | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return 'NOT EXISTS (' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -1241,3 +1250,3 @@ return AnyValue(arg, indent) + ' IS NULL'; | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1259,2 +1268,3 @@ throw new SyntaxError(`'InsertQuery' can only accept one '${type}'`); | ||
break; | ||
} | ||
case 'From': | ||
@@ -1304,3 +1314,3 @@ tables.push(typeRules[type](rest, indent)); | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1314,2 +1324,3 @@ throw new SyntaxError(`'UpdateQuery' can only accept one '${type}'`); | ||
break; | ||
} | ||
case 'From': | ||
@@ -1404,6 +1415,7 @@ tables.push(typeRules[type](rest, indent)); | ||
case 'UpdateQuery': | ||
case 'DeleteQuery': | ||
case 'DeleteQuery': { | ||
const query = typeRules[type](rest, indent); | ||
return toSqlResult(query); | ||
case 'UpsertQuery': | ||
} | ||
case 'UpsertQuery': { | ||
(0, exports.checkArgs)('UpsertQuery', rest, 2); | ||
@@ -1423,3 +1435,4 @@ const insertQuery = (0, exports.getAbstractSqlQuery)(rest, 0); | ||
return [insert, update]; | ||
default: | ||
} | ||
default: { | ||
const value = AnyValue(abstractSQL, indent); | ||
@@ -1433,2 +1446,3 @@ if (noBinds) { | ||
}; | ||
} | ||
} | ||
@@ -1435,0 +1449,0 @@ } |
@@ -7,3 +7,3 @@ export declare const enum Engines { | ||
export { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
import { AbstractSqlModel } from './AbstractSQLCompiler'; | ||
import type { AbstractSqlModel } from './AbstractSQLCompiler'; | ||
export declare const optimizeSchema: (abstractSqlModel: AbstractSqlModel, createCheckConstraints?: boolean) => AbstractSqlModel; |
@@ -1,2 +0,2 @@ | ||
import { AbstractSqlQuery, EngineInstance, LfRuleInfo } from './AbstractSQLCompiler'; | ||
import type { AbstractSqlQuery, EngineInstance, LfRuleInfo } from './AbstractSQLCompiler'; | ||
export interface ReferencedFields { | ||
@@ -3,0 +3,0 @@ [alias: string]: string[]; |
@@ -242,7 +242,8 @@ "use strict"; | ||
case 'ToJSON': | ||
case 'Where': | ||
case 'Where': { | ||
const unaryOperation = abstractSql; | ||
assertAbstractSqlIsNotLegacy(unaryOperation[1]); | ||
return countTableSelects(unaryOperation[1], table); | ||
case 'Count': | ||
} | ||
case 'Count': { | ||
const countNode = abstractSql; | ||
@@ -253,2 +254,3 @@ if (countNode[1] !== '*') { | ||
return 0; | ||
} | ||
case 'AddDateDuration': | ||
@@ -268,3 +270,3 @@ case 'AddDateNumber': | ||
case 'SubtractDateDuration': | ||
case 'SubtractDateNumber': | ||
case 'SubtractDateNumber': { | ||
const binaryOperation = abstractSql; | ||
@@ -277,6 +279,7 @@ const leftOperand = binaryOperation[1]; | ||
countTableSelects(rightOperand, table)); | ||
} | ||
case 'FullJoin': | ||
case 'Join': | ||
case 'LeftJoin': | ||
case 'RightJoin': | ||
case 'RightJoin': { | ||
const joinNode = abstractSql; | ||
@@ -289,2 +292,3 @@ assertAbstractSqlIsNotLegacy(joinNode[1]); | ||
return sum + countTableSelects(joinNode[1], table); | ||
} | ||
case 'And': | ||
@@ -294,3 +298,3 @@ case 'Or': | ||
case 'TextArray': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const selectQueryNode = abstractSql; | ||
@@ -302,4 +306,5 @@ for (const arg of selectQueryNode.slice(1)) { | ||
return sum; | ||
} | ||
case 'In': | ||
case 'NotIn': | ||
case 'NotIn': { | ||
const inNode = abstractSql; | ||
@@ -311,3 +316,4 @@ for (const arg of inNode.slice(2)) { | ||
return sum; | ||
case 'Select': | ||
} | ||
case 'Select': { | ||
const selectNode = abstractSql; | ||
@@ -319,2 +325,3 @@ for (const arg of selectNode[1]) { | ||
return sum; | ||
} | ||
case 'Boolean': | ||
@@ -331,3 +338,3 @@ case 'Date': | ||
return 0; | ||
case 'Table': | ||
case 'Table': { | ||
const tableNode = abstractSql; | ||
@@ -340,2 +347,3 @@ if (tableNode[1] === table) { | ||
} | ||
} | ||
default: | ||
@@ -342,0 +350,0 @@ throw new Error(`unknown abstract sql type: ${abstractSql[0]}`); |
{ | ||
"name": "@balena/abstract-sql-compiler", | ||
"version": "9.0.7", | ||
"version": "9.0.8-build-renovate-major--balenalint-326d8aacb8142a51d4b8f57c1b994772bec8c411-1", | ||
"description": "A translator for abstract sql into sql.", | ||
@@ -24,3 +24,3 @@ "main": "out/AbstractSQLCompiler.js", | ||
"@balena/lf-to-abstract-sql": "^5.0.0", | ||
"@balena/lint": "^6.2.2", | ||
"@balena/lint": "^8.0.0", | ||
"@balena/odata-parser": "^3.0.0", | ||
@@ -65,4 +65,4 @@ "@balena/odata-to-abstract-sql": "^6.0.1", | ||
"versionist": { | ||
"publishedAt": "2024-03-21T16:45:06.297Z" | ||
"publishedAt": "2024-03-26T09:05:34.993Z" | ||
} | ||
} |
export const enum Engines { | ||
/* eslint-disable @typescript-eslint/no-shadow -- this is fine since we only assign plain string values to the enum items */ | ||
postgres = 'postgres', | ||
mysql = 'mysql', | ||
websql = 'websql', | ||
/* eslint-enable @typescript-eslint/no-shadow */ | ||
} | ||
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser'; | ||
import { | ||
AbstractSQLRules2SQL, | ||
Binding, | ||
SqlResult, | ||
} from './AbstractSQLRules2SQL'; | ||
import type { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL'; | ||
export { Binding, SqlResult } from './AbstractSQLRules2SQL'; | ||
@@ -18,2 +17,7 @@ import type { SbvrType } from '@balena/sbvr-types'; | ||
import { optimizeSchema } from './AbstractSQLSchemaOptimiser'; | ||
import type { | ||
ReferencedFields, | ||
RuleReferencedFields, | ||
ModifiedFields, | ||
} from './referenced-fields'; | ||
import { | ||
@@ -23,5 +27,2 @@ getReferencedFields, | ||
getModifiedFields, | ||
ReferencedFields, | ||
RuleReferencedFields, | ||
ModifiedFields, | ||
insertAffectedIdsBinds, | ||
@@ -333,3 +334,3 @@ } from './referenced-fields'; | ||
'UnionQuery', | ||
// tslint:disable-next-line:array-type typescript fails on a circular reference when `Array<T>` form | ||
// eslint-disable-next-line @typescript-eslint/array-type -- Typescript fails on a circular reference when prettier changes this to an `Array<T>` form | ||
...(UnionQueryNode | SelectQueryNode)[], | ||
@@ -958,3 +959,3 @@ ]; | ||
dependency !== resourceName && | ||
schemaDependencyMap.hasOwnProperty(dependency) | ||
Object.prototype.hasOwnProperty.call(schemaDependencyMap, dependency) | ||
) { | ||
@@ -961,0 +962,0 @@ unsolvedDependency = true; |
import * as _ from 'lodash'; | ||
import { Dictionary } from 'lodash'; | ||
import { | ||
import type { Dictionary } from 'lodash'; | ||
import type { | ||
AbstractSqlQuery, | ||
@@ -427,3 +427,3 @@ AbstractSqlType, | ||
return arg; | ||
default: | ||
default: { | ||
const [type, ...rest] = arg; | ||
@@ -449,2 +449,3 @@ switch (type) { | ||
} | ||
} | ||
} | ||
@@ -506,2 +507,3 @@ }; | ||
} | ||
// eslint-disable-next-line no-fallthrough | ||
default: | ||
@@ -712,5 +714,7 @@ throw new SyntaxError( | ||
Cast: matchArgs<CastNode>('Cast', AnyValue, _.identity), | ||
// eslint-disable-next-line id-denylist | ||
Number: NumberMatch('Number'), | ||
Real: NumberMatch('Real'), | ||
Integer: NumberMatch('Integer'), | ||
// eslint-disable-next-line id-denylist | ||
Boolean: matchArgs<BooleanNode>('Boolean', _.identity), | ||
@@ -923,3 +927,3 @@ EmbeddedText: matchArgs('EmbeddedText', _.identity), | ||
switch (type) { | ||
case 'When': | ||
case 'When': { | ||
checkArgs('When', rest, 2); | ||
@@ -929,2 +933,3 @@ const matches = BooleanValue(getAbstractSqlQuery(rest, 0)); | ||
return ['When', matches, resultValue]; | ||
} | ||
case 'Else': | ||
@@ -1355,3 +1360,3 @@ if (index !== args.length - 1) { | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1382,2 +1387,3 @@ throw new SyntaxError( | ||
break; | ||
} | ||
case 'From': | ||
@@ -1436,3 +1442,3 @@ tables.push(typeRules[type](rest)); | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1448,2 +1454,3 @@ throw new SyntaxError( | ||
break; | ||
} | ||
case 'From': | ||
@@ -1609,3 +1616,3 @@ tables.push(typeRules[type](rest)); | ||
break; | ||
case 'UpsertQuery': | ||
case 'UpsertQuery': { | ||
checkArgs('UpsertQuery', rest, 2); | ||
@@ -1628,2 +1635,3 @@ const insertQuery = getAbstractSqlQuery(rest, 0); | ||
break; | ||
} | ||
default: | ||
@@ -1630,0 +1638,0 @@ abstractSQL = AnyValue(abstractSQL) as AbstractSqlQuery; |
@@ -5,7 +5,6 @@ import * as _ from 'lodash'; | ||
import { Dictionary } from 'lodash'; | ||
import { | ||
import type { Dictionary } from 'lodash'; | ||
import type { | ||
AbstractSqlQuery, | ||
AbstractSqlType, | ||
Engines, | ||
InsertQueryNode, | ||
@@ -27,2 +26,3 @@ SelectQueryNode, | ||
} from './AbstractSQLCompiler'; | ||
import { Engines } from './AbstractSQLCompiler'; | ||
@@ -95,6 +95,7 @@ export type Binding = | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return '(' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -367,3 +368,3 @@ throw new Error(`Invalid "UnknownValue" type: ${type}`); | ||
switch (type) { | ||
case 'On': | ||
case 'On': { | ||
checkArgs('On', rest, 1); | ||
@@ -375,2 +376,3 @@ const ruleBody = BooleanValue( | ||
return sqlJoinType + from + ' ON ' + ruleBody; | ||
} | ||
default: | ||
@@ -561,3 +563,3 @@ throw new SyntaxError( | ||
return 'DEFAULT'; | ||
default: | ||
default: { | ||
const [type, ...rest] = arg; | ||
@@ -577,2 +579,3 @@ switch (type) { | ||
} | ||
} | ||
} | ||
@@ -594,7 +597,8 @@ }; | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedindent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedindent); | ||
return '(' + nestedindent + query + indent + ')'; | ||
case 'Table': | ||
} | ||
case 'Table': { | ||
checkArgs('Table', rest, 1); | ||
@@ -606,2 +610,3 @@ const [table] = rest; | ||
return escapeField(table); | ||
} | ||
default: | ||
@@ -619,6 +624,7 @@ throw new SyntaxError(`From does not support ${type}`); | ||
switch (type) { | ||
case 'Alias': | ||
case 'Alias': { | ||
checkArgs('Alias', rest, 2); | ||
const field = matchFn(getAbstractSqlQuery(rest, 0), indent); | ||
return `${field} AS "${rest[1]}"`; | ||
} | ||
default: | ||
@@ -892,5 +898,7 @@ return matchFn(args, indent); | ||
}, | ||
// eslint-disable-next-line id-denylist | ||
Number: NumberMatch('Number'), | ||
Real: NumberMatch('Real'), | ||
Integer: NumberMatch('Integer'), | ||
// eslint-disable-next-line id-denylist | ||
Boolean: (args) => { | ||
@@ -1208,3 +1216,3 @@ checkArgs('Boolean', args, 1); | ||
switch (type) { | ||
case 'When': | ||
case 'When': { | ||
checkArgs('When', rest, 2); | ||
@@ -1220,2 +1228,3 @@ const matches = BooleanValue( | ||
return 'WHEN ' + matches + ' THEN ' + resultValue; | ||
} | ||
case 'Else': | ||
@@ -1325,6 +1334,7 @@ if (index !== args.length - 1) { | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return 'EXISTS (' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -1340,6 +1350,7 @@ return AnyValue(arg, indent) + ' IS NOT NULL'; | ||
case 'SelectQuery': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const nestedIndent = NestedIndent(indent); | ||
const query = typeRules[type](rest, nestedIndent); | ||
return 'NOT EXISTS (' + nestedIndent + query + indent + ')'; | ||
} | ||
default: | ||
@@ -1400,3 +1411,3 @@ return AnyValue(arg, indent) + ' IS NULL'; | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1420,2 +1431,3 @@ throw new SyntaxError( | ||
break; | ||
} | ||
case 'From': | ||
@@ -1471,3 +1483,3 @@ tables.push(typeRules[type](rest, indent)); | ||
break; | ||
case 'Values': | ||
case 'Values': { | ||
if (values.length !== 0) { | ||
@@ -1483,2 +1495,3 @@ throw new SyntaxError( | ||
break; | ||
} | ||
case 'From': | ||
@@ -1626,6 +1639,7 @@ tables.push(typeRules[type](rest, indent)); | ||
case 'UpdateQuery': | ||
case 'DeleteQuery': | ||
case 'DeleteQuery': { | ||
const query = typeRules[type](rest, indent); | ||
return toSqlResult(query); | ||
case 'UpsertQuery': | ||
} | ||
case 'UpsertQuery': { | ||
checkArgs('UpsertQuery', rest, 2); | ||
@@ -1650,3 +1664,4 @@ const insertQuery = getAbstractSqlQuery(rest, 0); | ||
return [insert, update] as [string, string] | [SqlResult, SqlResult]; | ||
default: | ||
} | ||
default: { | ||
const value = AnyValue(abstractSQL, indent); | ||
@@ -1660,3 +1675,4 @@ if (noBinds) { | ||
}; | ||
} | ||
} | ||
} |
@@ -11,3 +11,3 @@ export const enum Engines { | ||
import * as _ from 'lodash'; | ||
import { | ||
import type { | ||
AbstractSqlModel, | ||
@@ -18,5 +18,4 @@ AbstractSqlQuery, | ||
WhereNode, | ||
isFromNode, | ||
isSelectQueryNode, | ||
} from './AbstractSQLCompiler'; | ||
import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler'; | ||
@@ -23,0 +22,0 @@ const countFroms = (n: AbstractSqlType[]) => { |
import * as _ from 'lodash'; | ||
import { | ||
import type { | ||
AbstractSqlQuery, | ||
@@ -29,10 +29,4 @@ AbstractSqlType, | ||
InNode, | ||
isAliasNode, | ||
IsDistinctFromNode, | ||
isFromNode, | ||
IsNotDistinctFromNode, | ||
isSelectNode, | ||
isSelectQueryNode, | ||
isTableNode, | ||
isWhereNode, | ||
LeftJoinNode, | ||
@@ -60,2 +54,10 @@ LessThanNode, | ||
} from './AbstractSQLCompiler'; | ||
import { | ||
isAliasNode, | ||
isFromNode, | ||
isSelectNode, | ||
isSelectQueryNode, | ||
isTableNode, | ||
isWhereNode, | ||
} from './AbstractSQLCompiler'; | ||
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser'; | ||
@@ -219,3 +221,3 @@ import { isAbstractSqlQuery } from './AbstractSQLRules2SQL'; | ||
} | ||
// Fallthrough | ||
// eslint-disable-next-line no-fallthrough -- Fallthrough | ||
case 'Where': | ||
@@ -380,3 +382,3 @@ case 'And': | ||
case 'ToJSON': | ||
case 'Where': | ||
case 'Where': { | ||
const unaryOperation = abstractSql as | ||
@@ -400,5 +402,5 @@ | AliasNode<FromTypeNodes> | ||
return countTableSelects(unaryOperation[1], table); | ||
} | ||
// `COUNT` is an unary function but we only support the `COUNT(*)` form | ||
case 'Count': | ||
case 'Count': { | ||
const countNode = abstractSql as CountNode; | ||
@@ -410,3 +412,3 @@ if (countNode[1] !== '*') { | ||
return 0; | ||
} | ||
// Binary nodes | ||
@@ -427,3 +429,3 @@ case 'AddDateDuration': | ||
case 'SubtractDateDuration': | ||
case 'SubtractDateNumber': | ||
case 'SubtractDateNumber': { | ||
const binaryOperation = abstractSql as | ||
@@ -454,3 +456,3 @@ | AddDateDurationNode | ||
); | ||
} | ||
// Binary nodes with optional `ON` second argument | ||
@@ -460,3 +462,3 @@ case 'FullJoin': | ||
case 'LeftJoin': | ||
case 'RightJoin': | ||
case 'RightJoin': { | ||
const joinNode = abstractSql as | ||
@@ -474,3 +476,3 @@ | FullJoinNode | ||
return sum + countTableSelects(joinNode[1], table); | ||
} | ||
// n-ary nodes | ||
@@ -481,3 +483,3 @@ case 'And': | ||
case 'TextArray': | ||
case 'UnionQuery': | ||
case 'UnionQuery': { | ||
const selectQueryNode = abstractSql as | ||
@@ -495,6 +497,6 @@ | AndNode | ||
return sum; | ||
} | ||
// n-ary nodes but the slice starts at the third argument | ||
case 'In': | ||
case 'NotIn': | ||
case 'NotIn': { | ||
const inNode = abstractSql as InNode | NotInNode; | ||
@@ -507,5 +509,5 @@ for (const arg of inNode.slice(2)) { | ||
return sum; | ||
} | ||
// n-ary-like node | ||
case 'Select': | ||
case 'Select': { | ||
const selectNode = abstractSql as SelectNode; | ||
@@ -518,3 +520,3 @@ for (const arg of selectNode[1]) { | ||
return sum; | ||
} | ||
// Uninteresting atomic nodes | ||
@@ -534,3 +536,3 @@ case 'Boolean': | ||
// The atomic node we're looking for: a table selection | ||
case 'Table': | ||
case 'Table': { | ||
const tableNode = abstractSql as TableNode; | ||
@@ -543,3 +545,3 @@ | ||
} | ||
} | ||
default: | ||
@@ -546,0 +548,0 @@ throw new Error(`unknown abstract sql type: ${abstractSql[0]}`); |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
import { expect } from 'chai'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
const test = require('./test'); | ||
import test from './test'; | ||
@@ -3,0 +3,0 @@ const buildSelect = (withElse) => [ |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes, SelectQueryNode } from '../../src/AbstractSQLCompiler'; | ||
import type { | ||
AnyTypeNodes, | ||
SelectQueryNode, | ||
} from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +11,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +15,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as (( | ||
import $test from './test'; | ||
const test = $test as (( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
import { stripIndent } from 'common-tags'; | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -8,4 +8,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -12,0 +12,0 @@ binds: any[][] | TestCb, |
@@ -151,3 +151,3 @@ import * as AbstractSQLCompiler from '../..'; | ||
, -- It is necessary that each test has an id that is greater than 0. | ||
CONSTRAINT "test$qEORqfvLM2D8/gu0ZEVfvrnt19+uBo55ipVGKTdmu0k=\" CHECK (0 < "id" | ||
CONSTRAINT "test$qEORqfvLM2D8/gu0ZEVfvrnt19+uBo55ipVGKTdmu0k=" CHECK (0 < "id" | ||
AND "id" IS NOT NULL) | ||
@@ -154,0 +154,0 @@ );`, |
@@ -1,5 +0,5 @@ | ||
const AbstractSQLCompiler = require('../..'); | ||
import * as AbstractSQLCompiler from '../..'; | ||
const { expect } = require('chai'); | ||
const _ = require('lodash'); | ||
import { expect } from 'chai'; | ||
import * as _ from 'lodash'; | ||
@@ -82,2 +82,3 @@ const bindingsTest = function (actualBindings, expectedBindings) { | ||
bound.skip = runExpectation.bind(null, describe.skip, engine); | ||
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive | ||
bound.only = runExpectation.bind(null, describe.only, engine); | ||
@@ -87,5 +88,7 @@ return bound; | ||
module.exports = bindRunExpectation('postgres'); | ||
module.exports.postgres = bindRunExpectation('postgres'); | ||
module.exports.mysql = bindRunExpectation('mysql'); | ||
module.exports.websql = bindRunExpectation('websql'); | ||
const testFn = bindRunExpectation('postgres'); | ||
testFn.postgres = bindRunExpectation('postgres'); | ||
testFn.mysql = bindRunExpectation('mysql'); | ||
testFn.websql = bindRunExpectation('websql'); | ||
export default testFn; |
@@ -1,2 +0,2 @@ | ||
import { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
import type { AnyTypeNodes } from '../../src/AbstractSQLCompiler'; | ||
@@ -7,4 +7,4 @@ type TestCb = ( | ||
) => void; | ||
// tslint:disable-next-line no-var-requires | ||
const test = require('./test') as ( | ||
import $test from './test'; | ||
const test = $test as ( | ||
query: AnyTypeNodes, | ||
@@ -11,0 +11,0 @@ binds: any[][] | TestCb, |
@@ -1,3 +0,3 @@ | ||
const test = require('./test'); | ||
const { | ||
import test from './test'; | ||
import { | ||
pilotFields, | ||
@@ -8,4 +8,4 @@ aliasFields, | ||
aliasPilotCanFlyPlaneFields, | ||
} = require('./fields'); | ||
const _ = require('lodash'); | ||
} from './fields'; | ||
import * as _ from 'lodash'; | ||
@@ -77,3 +77,3 @@ const postgresAgg = (field) => 'COALESCE(JSON_AGG(' + field + "), '[]')"; | ||
for (let url of [ | ||
for (const url of [ | ||
'/pilot?$expand=can_fly__plane/plane', | ||
@@ -129,3 +129,3 @@ '/pilot?$expand=can_fly__plane($expand=plane)', | ||
for (let url of [ | ||
for (const url of [ | ||
'/pilot?$expand=can_fly__plane/plane,licence', | ||
@@ -194,3 +194,3 @@ '/pilot?$expand=can_fly__plane($expand=plane),licence', | ||
for (let url of [ | ||
for (const url of [ | ||
'/pilot?$select=id&$expand=can_fly__plane/plane', | ||
@@ -242,3 +242,3 @@ '/pilot?$select=id&$expand=can_fly__plane($expand=plane)', | ||
for (let url of [ | ||
for (const url of [ | ||
'/pilot?$select=id,licence&$expand=can_fly__plane/plane,licence', | ||
@@ -245,0 +245,0 @@ '/pilot?$select=id,licence&$expand=can_fly__plane($expand=plane),licence', |
@@ -6,12 +6,7 @@ /* | ||
*/ | ||
const { expect } = require('chai'); | ||
const test = require('./test'); | ||
const { clientModel } = test; | ||
const _ = require('lodash'); | ||
const { odataNameToSqlName } = require('@balena/odata-to-abstract-sql'); | ||
const { | ||
pilotFields, | ||
teamFields, | ||
aliasPilotCanFlyPlaneFields, | ||
} = require('./fields'); | ||
import { expect } from 'chai'; | ||
import test, { clientModel } from './test'; | ||
import * as _ from 'lodash'; | ||
import { odataNameToSqlName } from '@balena/odata-to-abstract-sql'; | ||
import { pilotFields, teamFields, aliasPilotCanFlyPlaneFields } from './fields'; | ||
@@ -111,3 +106,3 @@ const pilotFieldsStr = pilotFields.join(', '); | ||
let previousResource = resource; | ||
for (let resourceName of fieldParts.slice(0, -1)) { | ||
for (const resourceName of fieldParts.slice(0, -1)) { | ||
const sqlName = odataNameToSqlName(resourceName); | ||
@@ -339,4 +334,4 @@ const sqlNameParts = sqlName.split('-'); | ||
}; | ||
default: | ||
if (methodMaps.hasOwnProperty(method)) { | ||
default: { | ||
if (Object.prototype.hasOwnProperty.call(methodMaps, method)) { | ||
method = methodMaps[method]; | ||
@@ -349,3 +344,3 @@ } | ||
} | ||
var sql = method + '(' + args.map((arg) => arg.sql).join(', ') + ')'; | ||
const sql = method + '(' + args.map((arg) => arg.sql).join(', ') + ')'; | ||
return { | ||
@@ -356,2 +351,3 @@ sql, | ||
}; | ||
} | ||
} | ||
@@ -358,0 +354,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
const test = require('./test'); | ||
const { pilotFields } = require('./fields'); | ||
import test from './test'; | ||
import { pilotFields } from './fields'; | ||
const pilotFieldsStr = pilotFields.join(', '); | ||
@@ -4,0 +4,0 @@ |
@@ -1,3 +0,3 @@ | ||
const test = require('./test'); | ||
const { pilotFields } = require('./fields'); | ||
import test from './test'; | ||
import { pilotFields } from './fields'; | ||
const pilotFieldsStr = pilotFields.join(', '); | ||
@@ -4,0 +4,0 @@ |
@@ -1,5 +0,5 @@ | ||
const { expect } = require('chai'); | ||
const test = require('./test'); | ||
const ODataParser = require('@balena/odata-parser'); | ||
let { | ||
import { expect } from 'chai'; | ||
import test from './test'; | ||
import * as ODataParser from '@balena/odata-parser'; | ||
import { | ||
pilotFields, | ||
@@ -11,3 +11,3 @@ teamFields, | ||
aliasLicenceFields, | ||
} = require('./fields'); | ||
} from './fields'; | ||
const aliasPilotFields = aliasFields( | ||
@@ -14,0 +14,0 @@ 'plane.pilot-can fly-plane.pilot', |
@@ -1,3 +0,3 @@ | ||
const test = require('./test'); | ||
const { pilotFields } = require('./fields'); | ||
import test from './test'; | ||
import { pilotFields } from './fields'; | ||
const pilotFieldsStr = pilotFields.join(', '); | ||
@@ -4,0 +4,0 @@ |
@@ -1,4 +0,4 @@ | ||
const test = require('./test'); | ||
const _ = require('lodash'); | ||
const { pilotFields } = require('./fields'); | ||
import test from './test'; | ||
import * as _ from 'lodash'; | ||
import { pilotFields } from './fields'; | ||
const pilotFieldsStr = pilotFields.join(', '); | ||
@@ -5,0 +5,0 @@ |
@@ -1,12 +0,13 @@ | ||
const fs = require('fs'); | ||
const ODataParser = require('@balena/odata-parser'); | ||
const { OData2AbstractSQL } = require('@balena/odata-to-abstract-sql'); | ||
import * as fs from 'node:fs'; | ||
import * as ODataParser from '@balena/odata-parser'; | ||
import { OData2AbstractSQL } from '@balena/odata-to-abstract-sql'; | ||
const sbvrModel = fs.readFileSync(require.resolve('../model.sbvr'), 'utf8'); | ||
const AbstractSQLCompiler = require('../..'); | ||
import * as AbstractSQLCompiler from '../..'; | ||
const { expect } = require('chai'); | ||
const _ = require('lodash'); | ||
import { expect } from 'chai'; | ||
import * as _ from 'lodash'; | ||
const generateClientModel = function (input) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const sbvrTypes = require('@balena/sbvr-types').default; | ||
@@ -18,2 +19,3 @@ const typeVocab = fs.readFileSync( | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const SBVRParser = require('@balena/sbvr-parser').SBVRParser.createInstance(); | ||
@@ -25,2 +27,3 @@ SBVRParser.enableReusingMemoizations(SBVRParser._sideEffectingRules); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const LF2AbstractSQL = require('@balena/lf-to-abstract-sql'); | ||
@@ -34,3 +37,3 @@ const LF2AbstractSQLTranslator = LF2AbstractSQL.createTranslator(sbvrTypes); | ||
const clientModel = generateClientModel(sbvrModel); | ||
export const clientModel = generateClientModel(sbvrModel); | ||
const odata2AbstractSQL = new OData2AbstractSQL(clientModel); | ||
@@ -131,2 +134,3 @@ | ||
bound.skip = runExpectation.bind(null, describe.skip, engine); | ||
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive | ||
bound.only = runExpectation.bind(null, describe.only, engine); | ||
@@ -136,6 +140,7 @@ return bound; | ||
module.exports = bindRunExpectation('postgres'); | ||
module.exports.clientModel = clientModel; | ||
module.exports.postgres = bindRunExpectation('postgres'); | ||
module.exports.mysql = bindRunExpectation('mysql'); | ||
module.exports.websql = bindRunExpectation('websql'); | ||
const testFn = bindRunExpectation('postgres'); | ||
testFn.postgres = bindRunExpectation('postgres'); | ||
testFn.mysql = bindRunExpectation('mysql'); | ||
testFn.websql = bindRunExpectation('websql'); | ||
export default testFn; |
@@ -1,5 +0,7 @@ | ||
const typeVocab = require('fs').readFileSync( | ||
import * as fs from 'node:fs'; | ||
const typeVocab = fs.readFileSync( | ||
require.resolve('@balena/sbvr-types/Type.sbvr'), | ||
); | ||
const test = require('./test')(typeVocab); | ||
import { getTestHelpers } from './test'; | ||
const test = getTestHelpers(typeVocab); | ||
@@ -6,0 +8,0 @@ const modifiedAtTrigger = (tableName) => `\ |
@@ -1,4 +0,8 @@ | ||
const typeVocab = require('fs').readFileSync( | ||
import * as fs from 'node:fs'; | ||
import { getTestHelpers } from './test'; | ||
const typeVocab = fs.readFileSync( | ||
require.resolve('@balena/sbvr-types/Type.sbvr'), | ||
); | ||
const modifiedAtTrigger = (tableName) => `\ | ||
@@ -25,3 +29,3 @@ DO | ||
beforeEach(() => { | ||
test = require('./test')(typeVocab); | ||
test = getTestHelpers(typeVocab); | ||
}); | ||
@@ -28,0 +32,0 @@ |
@@ -1,14 +0,16 @@ | ||
const _ = require('lodash'); | ||
const sbvrTypes = require('@balena/sbvr-types').default; | ||
import * as _ from 'lodash'; | ||
import sbvrTypes from '@balena/sbvr-types'; | ||
const { expect } = require('chai'); | ||
const AbstractSQLCompiler = require('../..'); | ||
import { expect } from 'chai'; | ||
import * as AbstractSQLCompiler from '../..'; | ||
module.exports = function (builtInVocab) { | ||
export function getTestHelpers(builtInVocab) { | ||
if (builtInVocab == null) { | ||
builtInVocab = false; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const SBVRParser = require('@balena/sbvr-parser').SBVRParser.createInstance(); | ||
SBVRParser.enableReusingMemoizations(SBVRParser._sideEffectingRules); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const LF2AbstractSQL = require('@balena/lf-to-abstract-sql'); | ||
@@ -77,7 +79,9 @@ const LF2AbstractSQLTranslator = LF2AbstractSQL.createTranslator(sbvrTypes); | ||
ret.skip = runSchema.bind(null, it.skip); | ||
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive | ||
ret.only = runSchema.bind(null, it.only); | ||
ret.rule = runRule.bind(null, it); | ||
ret.rule.skip = runRule.bind(null, it.skip); | ||
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive | ||
ret.rule.only = runRule.bind(null, it.only); | ||
return ret; | ||
}; | ||
} |
@@ -7,2 +7,7 @@ { | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"test/**/*", | ||
".eslintrc.js" | ||
], | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
842303
71
17836
1
2