Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@balena/odata-to-abstract-sql

Package Overview
Dependencies
Maintainers
4
Versions
226
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 5.1.0 to 5.1.1-improve-typings-4f95a8c2a53289fd7e9f1f893c94716baa4a18a6

31

CHANGELOG.md

@@ -7,4 +7,33 @@ # Change Log

## 5.1.0 - 2020-06-22
## 5.1.1 - 2020-07-10
<details>
<summary> Improve typings [Pagan Gazzard] </summary>
> ### abstract-sql-compiler-7.0.2 - 2020-07-10
>
>
> <details>
> <summary> Update dependencies [Pagan Gazzard] </summary>
>
>> #### sbvr-types-3.1.0 - 2020-06-17
>>
>> * Update dependencies [Pagan Gazzard]
>>
> </details>
>
>
> ### abstract-sql-compiler-7.0.1 - 2020-07-10
>
> * Improve `BindNode` typing [Pagan Gazzard]
>
> ### odata-parser-2.0.1 - 2020-07-10
>
> * Improve typings [Pagan Gazzard]
>
</details>
## 5.1.0 - 2020-06-19
* Allow specifying valid methods for a specific match call [Pagan Gazzard]

@@ -11,0 +40,0 @@

29

out/odata-to-abstract-sql.d.ts
import * as _ from 'lodash';
import * as memoize from 'memoizee';
import type { AbstractSqlQuery, AbstractSqlModel, AbstractSqlTable, DurationNode, AbstractSqlType, SelectNode, FromNode, WhereNode, OrderByNode, LimitNode, OffsetNode, NumberTypeNodes, FieldsNode, ValuesNode, ReferencedFieldNode, BooleanTypeNodes, UnionQueryNode, SelectQueryNode, BindNode, TableNode } from '@balena/abstract-sql-compiler';
import type { ODataBinds, ODataQuery, SupportedMethod } from '@balena/odata-parser';
import type { ODataBinds, ODataQuery, SupportedMethod, ExpandPropertyPath, ResourceOptions, OrderByOption, OrderByPropertyPath, FilterOption, BindReference } from '@balena/odata-parser';
export type { ODataBinds, ODataQuery, SupportedMethod };

@@ -23,2 +23,5 @@ export declare type ResourceNode = ['Resource', string];

}
declare type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
declare type RequiredField<T, F extends keyof T> = Overwrite<T, Required<Pick<T, F>>>;
declare type AliasedResource = RequiredField<Resource, 'tableAlias'>;
export declare type ResourceFunction = (this: OData2AbstractSQL, property: any) => BooleanTypeNodes | {

@@ -55,13 +58,13 @@ resource: Resource;

tree: AbstractSqlQuery;
extraBodyVars: _.Dictionary<any>;
extraBodyVars: _.Dictionary<BindReference>;
extraBindVars: ODataBinds;
};
PathSegment(method: string, bodyKeys: string[], path: any): Query;
PathKey(method: string, path: any, resource: Resource, referencedField: ReferencedFieldNode, bodyKeys: string[]): BooleanTypeNodes | void;
Bind(bind: any, _optional?: boolean): AbstractSqlType | undefined;
SelectFilter(filter: any, query: Query, resource: Resource): void;
OrderBy(orderby: any, query: Query, resource: Resource): void;
OrderByProperties(orderings: any[]): Array<OrderByNode[1]>;
PathSegment(method: string, bodyKeys: string[], path: ODataQuery): Query;
PathKey(method: string, path: ODataQuery, resource: Resource, referencedField: ReferencedFieldNode, bodyKeys: string[]): BooleanTypeNodes | void;
Bind(bind: BindReference, _optional?: boolean): AbstractSqlType | undefined;
SelectFilter(filter: FilterOption, query: Query, resource: Resource): void;
OrderBy(orderby: OrderByOption, query: Query, resource: Resource): void;
OrderByProperties(orderings: OrderByPropertyPath[]): Array<OrderByNode[1]>;
BindVars(method: string, bodyKeys: string[], resourceName: string, match: Array<[string, [string, string]]>): Array<[string, 'Default' | BindNode]>;
Resource(resourceName: string, parentResource?: Resource): Resource;
Resource(resourceName: string, parentResource?: Resource): AliasedResource;
FieldContainedIn(fieldName: string, resource: Resource): boolean;

@@ -102,10 +105,10 @@ ResourceMapping(resource: Resource): _.Dictionary<[string, string]>;

DurationMatch(match: DurationNode[1]): AbstractSqlType | undefined;
Expands(resource: Resource, query: Query, expands: any): void;
AddQueryOptions(resource: Resource, path: any, query: Query): void;
Expands(resource: Resource, query: Query, expands: ExpandPropertyPath[]): void;
AddQueryOptions(resource: Resource, path: ResourceOptions, query: Query): void;
NavigateResources(resource: Resource, navigation: string): {
resource: Resource;
resource: AliasedResource;
where: BooleanTypeNodes;
};
AddExtraFroms(query: Query, parentResource: Resource, match: any): void;
AddNavigation(query: Query, resource: Resource, extraResource: string): Resource;
AddNavigation(query: Query, resource: Resource, extraResource: string): AliasedResource;
reset(): void;

@@ -112,0 +115,0 @@ putReset(): void;

@@ -31,2 +31,5 @@ "use strict";

const containsQueryOption = (opts) => {
if (opts == null) {
return false;
}
for (const key in opts) {

@@ -218,2 +221,3 @@ if (key[0] === '$') {

PathSegment(method, bodyKeys, path) {
var _a;
if (!path.resource) {

@@ -235,3 +239,3 @@ throw new SyntaxError('Path segment must contain a resource');

let addPathKey = true;
if (hasQueryOpts && path.options.$expand) {
if (hasQueryOpts && ((_a = path.options) === null || _a === void 0 ? void 0 : _a.$expand)) {
this.Expands(resource, query, path.options.$expand.properties);

@@ -462,3 +466,2 @@ }

}
resource = { ...resource };
let tableAlias;

@@ -479,4 +482,6 @@ if (parentResource) {

}
resource.tableAlias = this.checkAlias(tableAlias);
return resource;
return {
...resource,
tableAlias: this.checkAlias(tableAlias),
};
}

@@ -952,5 +957,3 @@ FieldContainedIn(fieldName, resource) {

}
if (expand.options) {
this.AddQueryOptions(expandResource, expand, nestedExpandQuery);
}
this.AddQueryOptions(expandResource, expand, nestedExpandQuery);
this.defaultResource = defaultResource;

@@ -977,2 +980,5 @@ nestedExpandQuery.where.push(navigation.where);

AddQueryOptions(resource, path, query) {
if (!path.options) {
return;
}
if (path.options.$filter) {

@@ -979,0 +985,0 @@ this.SelectFilter(path.options.$filter, query, resource);

{
"name": "@balena/odata-to-abstract-sql",
"version": "5.1.0",
"version": "5.1.1-improve-typings-4f95a8c2a53289fd7e9f1f893c94716baa4a18a6",
"description": "A consumer of the OData parser, written in OMeta",

@@ -20,8 +20,8 @@ "main": "out/odata-to-abstract-sql.js",

"dependencies": {
"@balena/abstract-sql-compiler": "^7.0.0",
"@balena/odata-parser": "^2.0.0",
"@types/lodash": "^4.14.155",
"@balena/abstract-sql-compiler": "^7.0.2",
"@balena/odata-parser": "^2.0.1",
"@types/lodash": "^4.14.157",
"@types/memoizee": "^0.4.4",
"@types/randomstring": "^1.1.6",
"lodash": "^4.17.15",
"lodash": "^4.17.19",
"memoizee": "^0.4.14",

@@ -42,3 +42,3 @@ "randomstring": "^1.1.5"

"require-npm4-to-publish": "^1.0.0",
"typescript": "^3.9.5"
"typescript": "^3.9.6"
},

@@ -45,0 +45,0 @@ "husky": {

@@ -35,2 +35,8 @@ import * as _ from 'lodash';

SupportedMethod,
ExpandPropertyPath,
ResourceOptions,
OrderByOption,
OrderByPropertyPath,
FilterOption,
BindReference,
} from '@balena/odata-parser';

@@ -59,2 +65,5 @@ export type { ODataBinds, ODataQuery, SupportedMethod };

}
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
type RequiredField<T, F extends keyof T> = Overwrite<T, Required<Pick<T, F>>>;
type AliasedResource = RequiredField<Resource, 'tableAlias'>;

@@ -99,3 +108,6 @@ export type ResourceFunction = (

const containsQueryOption = (opts: object): boolean => {
const containsQueryOption = (opts?: object): boolean => {
if (opts == null) {
return false;
}
for (const key in opts) {

@@ -214,5 +226,5 @@ if (key[0] === '$') {

export class OData2AbstractSQL {
private extraBodyVars: _.Dictionary<any> = {};
private extraBodyVars: _.Dictionary<BindReference> = {};
public extraBindVars: ODataBinds = [];
private resourceAliases: _.Dictionary<Resource> = {};
private resourceAliases: _.Dictionary<AliasedResource> = {};
public defaultResource: Resource | undefined;

@@ -284,3 +296,3 @@ public bindVarsLength: number = 0;

tree: AbstractSqlQuery;
extraBodyVars: _.Dictionary<any>;
extraBodyVars: _.Dictionary<BindReference>;
extraBindVars: ODataBinds;

@@ -341,3 +353,3 @@ } {

}
PathSegment(method: string, bodyKeys: string[], path: any): Query {
PathSegment(method: string, bodyKeys: string[], path: ODataQuery): Query {
if (!path.resource) {

@@ -371,3 +383,3 @@ throw new SyntaxError('Path segment must contain a resource');

if (hasQueryOpts && path.options.$expand) {
if (hasQueryOpts && path.options?.$expand) {
this.Expands(resource, query, path.options.$expand.properties);

@@ -571,3 +583,3 @@ }

method: string,
path: any,
path: ODataQuery,
resource: Resource,

@@ -598,3 +610,3 @@ referencedField: ReferencedFieldNode,

}
Bind(bind: any, _optional?: boolean): AbstractSqlType | undefined {
Bind(bind: BindReference, _optional?: boolean): AbstractSqlType | undefined {
if (bind != null && bind.bind != null) {

@@ -604,3 +616,3 @@ return ['Bind', bind.bind];

}
SelectFilter(filter: any, query: Query, resource: Resource) {
SelectFilter(filter: FilterOption, query: Query, resource: Resource) {
this.AddExtraFroms(query, resource, filter);

@@ -610,3 +622,3 @@ const where = this.BooleanMatch(filter);

}
OrderBy(orderby: any, query: Query, resource: Resource) {
OrderBy(orderby: OrderByOption, query: Query, resource: Resource) {
this.AddExtraFroms(query, resource, orderby.properties);

@@ -618,3 +630,3 @@ query.extras.push([

}
OrderByProperties(orderings: any[]): Array<OrderByNode[1]> {
OrderByProperties(orderings: OrderByPropertyPath[]): Array<OrderByNode[1]> {
return orderings.map((ordering) => {

@@ -648,3 +660,3 @@ const field = this.ReferencedProperty(ordering);

}
Resource(resourceName: string, parentResource?: Resource): Resource {
Resource(resourceName: string, parentResource?: Resource): AliasedResource {
const resourceAlias = this.resourceAliases[resourceName];

@@ -654,3 +666,3 @@ if (resourceAlias) {

}
let resource: Resource;
let resource: AbstractSqlTable;
if (parentResource) {

@@ -670,3 +682,2 @@ const relationshipMapping = this.ResolveRelationship(

}
resource = { ...resource };
let tableAlias;

@@ -687,4 +698,6 @@ if (parentResource) {

}
resource.tableAlias = this.checkAlias(tableAlias);
return resource;
return {
...resource,
tableAlias: this.checkAlias(tableAlias),
};
}

@@ -1191,3 +1204,7 @@ FieldContainedIn(fieldName: string, resource: Resource): boolean {

}
Expands(resource: Resource, query: Query, expands: any): void {
Expands(
resource: Resource,
query: Query,
expands: ExpandPropertyPath[],
): void {
const defaultResource = this.defaultResource;

@@ -1218,5 +1235,3 @@ for (const expand of expands) {

}
if (expand.options) {
this.AddQueryOptions(expandResource, expand, nestedExpandQuery);
}
this.AddQueryOptions(expandResource, expand, nestedExpandQuery);

@@ -1245,3 +1260,10 @@ this.defaultResource = defaultResource;

}
AddQueryOptions(resource: Resource, path: any, query: Query): void {
AddQueryOptions(
resource: Resource,
path: ResourceOptions,
query: Query,
): void {
if (!path.options) {
return;
}
if (path.options.$filter) {

@@ -1268,3 +1290,3 @@ this.SelectFilter(path.options.$filter, query, resource);

navigation: string,
): { resource: Resource; where: BooleanTypeNodes } {
): { resource: AliasedResource; where: BooleanTypeNodes } {
const relationshipMapping = this.ResolveRelationship(resource, navigation);

@@ -1326,3 +1348,3 @@ const linkedResource = this.Resource(navigation, resource);

extraResource: string,
): Resource {
): AliasedResource {
const navigation = this.NavigateResources(resource, extraResource);

@@ -1329,0 +1351,0 @@ if (

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