New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@balena/odata-to-abstract-sql

Package Overview
Dependencies
Maintainers
3
Versions
234
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@balena/odata-to-abstract-sql - npm Package Compare versions

Comparing version 6.1.1-build-renovate-balena-abstract-sql-compiler-9-x-2381205fb1b472e851fb57b6cd4e75ef78b33224-1 to 6.2.0-build-fisehara-optimize-computed-fields-0d5403fcdefe3e7820218bc2445696e0cddc7c8e-1

262

CHANGELOG.md

@@ -7,264 +7,6 @@ # Change Log

## 6.1.1 - 2023-08-16
## 6.2.0 - 2023-10-17
* Optimize Duplications of `ComputedField` queries [Harald Fischer]
<details>
<summary> Update dependency @balena/abstract-sql-compiler to v9 [Self-hosted Renovate Bot] </summary>
> ### abstract-sql-compiler-9.0.3 - 2023-08-09
>
>
> <details>
> <summary> Update @balena/sbvr-types to 6.0.0 [Otávio Jacobi] </summary>
>
>> #### sbvr-types-6.0.0 - 2023-08-09
>>
>> * Change contents to snake_case [Otávio Jacobi]
>>
>> #### sbvr-types-5.2.0 - 2023-08-08
>>
>> * Expose WebResource as WebResourceType [Otávio Jacobi]
>>
>> #### sbvr-types-5.1.0 - 2023-08-03
>>
>> * Adds WebResource type [Otávio Jacobi]
>>
>
> </details>
>
>
> ### abstract-sql-compiler-9.0.2 - 2023-05-16
>
>
> <details>
> <summary> Update @balena/sbvr-types to 5.0.0 [Pagan Gazzard] </summary>
>
>> #### sbvr-types-5.0.0 - 2023-05-16
>>
>> * Switch from `export =` to `export default` [Pagan Gazzard]
>>
>> #### sbvr-types-4.0.2 - 2023-05-03
>>
>> * Improve typings [Pagan Gazzard]
>>
>> #### sbvr-types-4.0.1 - 2023-05-02
>>
>> * boolean: Avoid unnecessary array creation to reduce GCs [Thodoris Greasidis]
>>
>
> </details>
>
>
> ### abstract-sql-compiler-9.0.1 - 2023-05-15
>
> * Fix TS errors for the latest sbvrTypes [Thodoris Greasidis]
>
> ### abstract-sql-compiler-9.0.0 - 2023-05-02
>
> * Drop `require-npm4-to-publish` as `engines` used [fisehara]
>
> <details>
> <summary> Update @balena/odata-to-abstract-sql to 6.x [Pagan Gazzard] </summary>
>
>> #### odata-to-abstract-sql-6.0.1 - 2023-04-27
>>
>>
>> <details>
>> <summary> Update dependencies [Pagan Gazzard] </summary>
>>
>>> ##### odata-parser-3.0.0 - 2023-04-26
>>>
>>> * Use optional chaining operator [Pagan Gazzard]
>>> * Set minimum supported nodejs version to 16.13.0 [Pagan Gazzard]
>>>
>>> ##### odata-parser-2.5.0 - 2023-04-26
>>>
>>> * Update to peggy 3 and make us of the repetition operator [Pagan Gazzard]
>>>
>>> ##### sbvr-types-4.0.0 - 2023-04-26
>>>
>>> * Add test cases for Objects in JSON validate [fisehara]
>>> * Drop `require-npm4-to-publish` devDependency [fisehara]
>>> * Set minimum supported nodejs version to 16.13.0 and tsconfig to es2021 [Pagan Gazzard]
>>> * Switch `JSON` to use `JSON` db type instead of `TEXT` [Pagan Gazzard]
>>> * Switch `Boolean` to use `BOOLEAN` db type instead of `INTEGER` [Pagan Gazzard]
>>> * Assert that JSON input typeof is object [Josh Bowling]
>>>
>>
>> </details>
>>
>>
>> #### odata-to-abstract-sql-6.0.0 - 2023-04-26
>>
>> * Set minimum supported nodejs version to 16.13.0 and tsconfig to es2021 [Pagan Gazzard]
>> * Switch `AggregateJSON` to use the newer `ReferencedField` format [Pagan Gazzard]
>>
>> #### odata-to-abstract-sql-5.9.6 - 2023-04-25
>>
>> * Collapse `AliasedFunction` into `FunctionMatch` [Pagan Gazzard]
>>
>> #### odata-to-abstract-sql-5.9.5 - 2023-04-25
>>
>>
>> <details>
>> <summary> Improve typings [Pagan Gazzard] </summary>
>>
>>> ##### abstract-sql-compiler-8.4.1 - 2023-04-25
>>>
>>> * Add much finer grained typings for abstract-sql-optimizer [Pagan Gazzard]
>>>
>>
>> </details>
>>
>>
>> #### odata-to-abstract-sql-5.9.4 - 2023-04-24
>>
>>
>> <details>
>> <summary> Update dependencies [Pagan Gazzard] </summary>
>>
>>> ##### abstract-sql-compiler-8.4.0 - 2023-04-24
>>>
>>> * Add support for using field type nodes with an AggregateJSON node [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.13 - 2023-04-24
>>>
>>> * Deprecate `AliasableFromTypeNodes` type as it's redundant [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.12 - 2023-04-17
>>>
>>> * Revert tightening of `OrderBy` to only field nodes [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.11 - 2023-04-13
>>>
>>> * Do not allow ON clauses for CROSS JOIN as it is invalid [Pagan Gazzard]
>>> * Stop accepting `ExtractJSONPathAsText`/`ToJSON` as unknown node types [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.10 - 2023-04-13
>>>
>>> * Fix DateNode/AnyNode typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.9 - 2023-04-13
>>>
>>>
>>> <details>
>>> <summary> Update dependencies [Pagan Gazzard] </summary>
>>>
>>>> ###### sbvr-types-3.5.0 - 2023-03-21
>>>>
>>>> * Add Big Serial type [Josh Bowling]
>>>>
>>>> ###### sbvr-types-3.4.19 - 2022-12-08
>>>>
>>>> * Flowzone: Allow external contributions [Josh Bowling]
>>>>
>>>
>>> </details>
>>>
>>>
>>> ##### abstract-sql-compiler-8.3.8 - 2023-04-12
>>>
>>> * Improve typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.7 - 2023-04-12
>>>
>>> * Remove typing for non-existent JSON node [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.6 - 2023-04-12
>>>
>>> * Tighten the `isXValue` function typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.5 - 2023-04-12
>>>
>>> * Correctly treat `Value` nodes as rewritten to `Text` by the optimizer [Pagan Gazzard]
>>> * Add EmbeddedTextNode typing [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.4 - 2023-04-12
>>>
>>> * Enforce the first argument of ExtractJSONPathAsText is a JSON type node [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.3 - 2023-04-12
>>>
>>> * Improve node typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.2 - 2023-04-12
>>>
>>> * Add more node typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.1 - 2023-04-12
>>>
>>> * Add more node typings [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.3.0 - 2023-04-11
>>>
>>> * Support boolean nodes in a ValuesNode [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.2.0 - 2023-04-11
>>>
>>> * Add `Between` node type [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.1.0 - 2023-04-11
>>>
>>> * Add `BitwiseAnd`/`BitwiseShiftRight` node types [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.0.2 - 2023-04-06
>>>
>>> * Add `NotInNode` type [Pagan Gazzard]
>>> * Add `IsDistinctFromNode`/`IsNotDistinctFromNode` types [Pagan Gazzard]
>>> * Add `CharacterLengthNode` type [Pagan Gazzard]
>>>
>>> ##### abstract-sql-compiler-8.0.1 - 2023-04-06
>>>
>>> * Adds Cast node type to tree parsing [Otávio Jacobi]
>>>
>>> ##### odata-parser-2.4.6 - 2023-02-24
>>>
>>> * Improve typings [Pagan Gazzard]
>>>
>>> ##### odata-parser-2.4.5 - 2023-02-23
>>>
>>> * Use const/let as appropriate [Pagan Gazzard]
>>>
>>> ##### odata-parser-2.4.4 - 2023-02-23
>>>
>>> * Use shorthand object notation [Pagan Gazzard]
>>>
>>> ##### odata-parser-2.4.3 - 2023-02-23
>>>
>>> * Update dependencies [Pagan Gazzard]
>>>
>>
>> </details>
>>
>>
>
> </details>
>
> * Remove support for the legacy AggregateJSON format of `[tableName, fieldName]` [Pagan Gazzard]
> * Remove support for the legacy boolean format of `true|false` [Pagan Gazzard]
> * Set minimum supported nodejs version to 16.13.0 and tsconfig to es2021 [Pagan Gazzard]
> * Remove support for the legacy alias format of `[node, alias]` [Pagan Gazzard]
> * Remove support for the legacy table format of `tableName` [Pagan Gazzard]
> * Remove support for the legacy null formats of `null` and `'Null'` [Pagan Gazzard]
> * Reflect the usage of BOOLEAN db type [Pagan Gazzard]
>
> <details>
> <summary> Update @balena/sbvr-types to 4.x [Pagan Gazzard] </summary>
>
>> #### sbvr-types-4.0.0 - 2023-04-26
>>
>> * Add test cases for Objects in JSON validate [fisehara]
>> * Drop `require-npm4-to-publish` devDependency [fisehara]
>> * Set minimum supported nodejs version to 16.13.0 and tsconfig to es2021 [Pagan Gazzard]
>> * Switch `JSON` to use `JSON` db type instead of `TEXT` [Pagan Gazzard]
>> * Switch `Boolean` to use `BOOLEAN` db type instead of `INTEGER` [Pagan Gazzard]
>> * Assert that JSON input typeof is object [Josh Bowling]
>>
>
> </details>
>
>
</details>
## 6.1.0 - 2023-08-16

@@ -271,0 +13,0 @@

3

out/odata-to-abstract-sql.d.ts

@@ -63,2 +63,3 @@ import * as memoize from 'memoizee';

private checkAlias;
private alreadyComputedFields;
constructor(clientModel: RequiredAbstractSqlModelSubset, methods?: Dictionary<ResourceFunction>, { minimizeAliases }?: {

@@ -86,3 +87,3 @@ minimizeAliases?: boolean | undefined;

AddSelectFields(path: any, query: Query, resource: Resource): void;
AliasSelectField(resource: Resource, fieldName: string, computed?: AbstractSqlQuery, alias?: string): ReferencedFieldNode | AliasNode<ReferencedFieldNode> | AliasNode<AbstractSqlQuery>;
AliasSelectField(resource: Resource, fieldName: string, computed?: AbstractSqlQuery, alias?: string, alwaysCompileComputed?: boolean): ReferencedFieldNode | AliasNode<ReferencedFieldNode> | AliasNode<AbstractSqlQuery>;
ReferencedField(resource: Resource, resourceField: string): ReferencedFieldNode;

@@ -89,0 +90,0 @@ BooleanMatch(match: any, optional: true): BooleanTypeNodes | undefined;

@@ -121,5 +121,6 @@ "use strict";

exports.isBindReference = isBindReference;
const isDynamicResource = (resource) => {
const isDynamicResource = (resource, alreadyComputedFieldsLookup) => {
return (resource.definition != null ||
resource.fields.some((f) => f.computed != null));
resource.fields.some((f) => f.computed != null &&
!alreadyComputedFieldsLookup[resource.name + f.fieldName]));
};

@@ -141,2 +142,3 @@ const addBodyKey = (resourceName, fieldName, bind, bodyKeys, extraBodyVars) => {

this.bindVarsLength = 0;
this.alreadyComputedFields = {};
const MAX_ALIAS_LENGTH = 63;

@@ -311,3 +313,5 @@ const shortAliases = generateShortAliases(clientModel);

query.extras.push(['Fields', bindVars.map((b) => b[0])]);
if ((hasQueryOpts || isDynamicResource(resource) || pathKeyWhere != null) &&
if ((hasQueryOpts ||
isDynamicResource(resource, this.alreadyComputedFields) ||
pathKeyWhere != null) &&
(method === 'POST' || method === 'PUT-INSERT')) {

@@ -326,3 +330,5 @@ const subQuery = new Query();

'Select',
(resource.modifyFields ?? resource.fields).map((field) => {
(resource.modifyFields ?? resource.fields)
.filter((field) => field.computed == null)
.map((field) => {
const alias = field.fieldName;

@@ -425,3 +431,4 @@ const bindVar = bindVars?.find((v) => v[0] === alias);

}
if ((hasQueryOpts || isDynamicResource(resource)) &&
if ((hasQueryOpts ||
isDynamicResource(resource, this.alreadyComputedFields)) &&
(method === 'PUT' ||

@@ -665,4 +672,6 @@ method === 'PATCH' ||

}
AliasSelectField(resource, fieldName, computed, alias = fieldName) {
if (computed) {
AliasSelectField(resource, fieldName, computed, alias = fieldName, alwaysCompileComputed = false) {
const key = resource.name + fieldName;
if (computed &&
(!this.alreadyComputedFields[key] || alwaysCompileComputed)) {
if (resource.tableAlias != null &&

@@ -672,2 +681,3 @@ resource.tableAlias !== resource.name) {

}
this.alreadyComputedFields[key] = true;
return ['Alias', computed, alias];

@@ -1173,2 +1183,3 @@ }

this.extraBindVars = [];
this.alreadyComputedFields = {};
}

@@ -1219,3 +1230,3 @@ putReset() {

['Field', '*'],
...computedFields.map((field) => this.AliasSelectField(resource, (0, exports.sqlNameToODataName)(field.fieldName), field.computed, field.fieldName)),
...computedFields.map((field) => this.AliasSelectField(resource, (0, exports.sqlNameToODataName)(field.fieldName), field.computed, field.fieldName, true)),
];

@@ -1222,0 +1233,0 @@ computedFieldQuery.fromResource(this, {

{
"name": "@balena/odata-to-abstract-sql",
"version": "6.1.1-build-renovate-balena-abstract-sql-compiler-9-x-2381205fb1b472e851fb57b6cd4e75ef78b33224-1",
"version": "6.2.0-build-fisehara-optimize-computed-fields-0d5403fcdefe3e7820218bc2445696e0cddc7c8e-1",
"description": "A consumer of the OData parser, written in OMeta",

@@ -18,3 +18,3 @@ "main": "out/odata-to-abstract-sql.js",

"dependencies": {
"@balena/abstract-sql-compiler": "^9.0.0",
"@balena/abstract-sql-compiler": "^8.4.1",
"@balena/odata-parser": "^3.0.0",

@@ -57,4 +57,4 @@ "@types/lodash": "^4.14.194",

"versionist": {
"publishedAt": "2023-08-16T15:47:32.693Z"
"publishedAt": "2023-10-17T09:06:48.180Z"
}
}

@@ -120,2 +120,4 @@ import * as _ from 'lodash';

type AlreadyComputedFieldsLookup = { [key: string]: boolean };
export type ResourceFunction = (

@@ -302,6 +304,13 @@ this: OData2AbstractSQL,

const isDynamicResource = (resource: Resource): boolean => {
const isDynamicResource = (
resource: Resource,
alreadyComputedFieldsLookup: AlreadyComputedFieldsLookup,
): boolean => {
return (
resource.definition != null ||
resource.fields.some((f) => f.computed != null)
resource.fields.some(
(f) =>
f.computed != null &&
!alreadyComputedFieldsLookup[resource.name + f.fieldName],
)
);

@@ -332,2 +341,3 @@ };

private checkAlias: (alias: string) => string;
private alreadyComputedFields: AlreadyComputedFieldsLookup = {};

@@ -549,3 +559,5 @@ constructor(

if (
(hasQueryOpts || isDynamicResource(resource) || pathKeyWhere != null) &&
(hasQueryOpts ||
isDynamicResource(resource, this.alreadyComputedFields) ||
pathKeyWhere != null) &&
(method === 'POST' || method === 'PUT-INSERT')

@@ -569,4 +581,5 @@ ) {

'Select',
(resource.modifyFields ?? resource.fields).map(
(field): AliasNode<CastNode> => {
(resource.modifyFields ?? resource.fields)
.filter((field) => field.computed == null)
.map((field): AliasNode<CastNode> => {
const alias = field.fieldName;

@@ -581,4 +594,3 @@ const bindVar = bindVars?.find((v) => v[0] === alias);

return ['Alias', ['Cast', value, field.dataType], alias];
},
),
}),
],

@@ -696,3 +708,4 @@ ],

if (
(hasQueryOpts || isDynamicResource(resource)) &&
(hasQueryOpts ||
isDynamicResource(resource, this.alreadyComputedFields)) &&
(method === 'PUT' ||

@@ -1001,2 +1014,3 @@ method === 'PATCH' ||

alias: string = fieldName,
alwaysCompileComputed: boolean = false,
):

@@ -1006,3 +1020,7 @@ | ReferencedFieldNode

| AliasNode<AbstractSqlQuery> {
if (computed) {
const key = resource.name + fieldName;
if (
computed &&
(!this.alreadyComputedFields[key] || alwaysCompileComputed)
) {
if (

@@ -1018,2 +1036,3 @@ resource.tableAlias != null &&

}
this.alreadyComputedFields[key] = true;
return ['Alias', computed, alias];

@@ -1647,2 +1666,3 @@ }

this.extraBindVars = [] as unknown as ODataBinds;
this.alreadyComputedFields = {};
}

@@ -1711,2 +1731,3 @@

field.fieldName,
true,
),

@@ -1713,0 +1734,0 @@ ),

@@ -108,2 +108,16 @@ import * as _ from 'lodash';

clientModel.tables['copilot'].fields.push({
fieldName: 'is blocked',
dataType: 'Boolean',
// The cast is needed because AbstractSqlQuery cannot express a constant value.
computed: ['Boolean', false],
});
clientModel.tables['copilot'].fields.push({
fieldName: 'rank',
dataType: 'Text',
// The cast is needed because AbstractSqlQuery cannot express a constant value.
computed: ['Text', 'Junior'],
});
const odataNameToSqlName = (odataName) =>

@@ -364,1 +378,11 @@ odataName.replace(/__/g, '-').replace(/_/g, ' ');

export let $count = [['Alias', ['Count', '*'], '$count']];
export let copilotFields = [
['Alias', ['ReferencedField', 'copilot', 'created at'], 'created_at'],
['Alias', ['ReferencedField', 'copilot', 'modified at'], 'modified_at'],
['ReferencedField', 'copilot', 'id'],
['ReferencedField', 'copilot', 'person'],
['ReferencedField', 'copilot', 'assists-pilot'],
['Alias', ['ReferencedField', 'copilot', 'is blocked'], 'is_blocked'],
['ReferencedField', 'copilot', 'rank'],
];

@@ -1450,1 +1450,95 @@ import { expect } from 'chai';

});
test(`/copilot?$select=id,rank&$filter=rank eq 'major'`, (result) =>
it(`should get and filter copilot on computed field rank`, () => {
expect(result).to.be.a.query.to.deep.equal([
'SelectQuery',
[
'Select',
[
['ReferencedField', 'copilot', 'id'],
['ReferencedField', 'copilot', 'rank'],
],
],
[
'From',
[
'Alias',
[
'SelectQuery',
[
'Select',
[
['Field', '*'],
['Alias', ['Boolean', false], 'is blocked'],
['Alias', ['Text', 'Junior'], 'rank'],
],
],
['From', ['Table', 'copilot']],
],
'copilot',
],
],
[
'Where',
[
'IsNotDistinctFrom',
['ReferencedField', 'copilot', 'rank'],
['Bind', 0],
],
],
]);
}));
test(
`/copilot?$select=id,rank&$filter=rank eq 'major'`,
'PATCH',
{ assists__pilot: 1 },
(result) =>
it(`should PATCH copilot based on filtered computed field rank`, () => {
expect(result).to.be.a.query.to.deep.equal([
'UpdateQuery',
['From', ['Table', 'copilot']],
[
'Where',
[
'In',
['ReferencedField', 'copilot', 'id'],
[
'SelectQuery',
['Select', [['ReferencedField', 'copilot', 'id']]],
[
'From',
[
'Alias',
[
'SelectQuery',
[
'Select',
[
['Field', '*'],
['Alias', ['Boolean', false], 'is blocked'],
['Alias', ['Text', 'Junior'], 'rank'],
],
],
['From', ['Table', 'copilot']],
],
'copilot',
],
],
[
'Where',
[
'IsNotDistinctFrom',
['ReferencedField', 'copilot', 'rank'],
['Bind', 0],
],
],
],
],
],
['Fields', ['assists-pilot']],
['Values', [['Bind', 'copilot', 'assists__pilot']]],
]);
}),
);

@@ -155,1 +155,79 @@ import { expect } from 'chai';

])));
test('/copilot?$select=*', (result) =>
it('should select * from copilot', () =>
expect(result).to.be.a.query.to.deep.equal([
'SelectQuery',
[
'Select',
[
['Alias', ['ReferencedField', 'copilot', 'created at'], 'created_at'],
[
'Alias',
['ReferencedField', 'copilot', 'modified at'],
'modified_at',
],
['ReferencedField', 'copilot', 'id'],
['ReferencedField', 'copilot', 'pilot'],
[
'Alias',
['ReferencedField', 'copilot', 'assists-pilot'],
'assists__pilot',
],
['Alias', ['ReferencedField', 'copilot', 'is blocked'], 'is_blocked'],
['ReferencedField', 'copilot', 'rank'],
],
],
[
'From',
[
'Alias',
[
'SelectQuery',
[
'Select',
[
['Field', '*'],
['Alias', ['Boolean', false], 'is blocked'],
['Alias', ['Text', 'Junior'], 'rank'],
],
],
['From', ['Table', 'copilot']],
],
'copilot',
],
],
])));
test('/copilot?$select=id,is_blocked,rank', (result) =>
it('should select * from copilot', () =>
expect(result).to.be.a.query.to.deep.equal([
'SelectQuery',
[
'Select',
[
['ReferencedField', 'copilot', 'id'],
['Alias', ['ReferencedField', 'copilot', 'is blocked'], 'is_blocked'],
['ReferencedField', 'copilot', 'rank'],
],
],
[
'From',
[
'Alias',
[
'SelectQuery',
[
'Select',
[
['Field', '*'],
['Alias', ['Boolean', false], 'is blocked'],
['Alias', ['Text', 'Junior'], 'rank'],
],
],
['From', ['Table', 'copilot']],
],
'copilot',
],
],
])));

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc