Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify support for MERGE as an alias for PATCH #143

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/odata-to-abstract-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
} from '@balena/odata-parser';
export type { ODataBinds, ODataQuery, SupportedMethod };

type InternalSupportedMethod = Exclude<SupportedMethod, 'MERGE'> | 'PUT-INSERT';

type RequiredAbstractSqlModelSubset = Pick<
AbstractSqlModel,
'synonyms' | 'relationships' | 'tables'
Expand Down Expand Up @@ -394,7 +396,7 @@
}
match(
path: ODataQuery,
method: SupportedMethod,
$method: SupportedMethod,
bodyKeys: string[],
bindVarsLength: number,
methods?: OData2AbstractSQL['methods'],
Expand All @@ -403,6 +405,8 @@
extraBodyVars: Dictionary<BindReference>;
extraBindVars: ODataBinds;
} {
const method: InternalSupportedMethod =
$method === 'MERGE' ? 'PATCH' : $method;
const savedMethods = this.methods;
try {
if (methods != null) {
Expand Down Expand Up @@ -435,7 +439,6 @@
tree = query.compile('SelectQuery');
break;
case 'PATCH':
case 'MERGE':
tree = query.compile('UpdateQuery');
break;
case 'POST':
Expand All @@ -457,7 +460,11 @@
this.methods = savedMethods;
}
}
PathSegment(method: string, bodyKeys: string[], path: ODataQuery): Query {
PathSegment(
method: InternalSupportedMethod,
bodyKeys: string[],
path: ODataQuery,
): Query {
if (!path.resource) {
throw new SyntaxError('Path segment must contain a resource');
}
Expand Down Expand Up @@ -539,8 +546,7 @@
method === 'PUT' ||
method === 'PUT-INSERT' ||
method === 'POST' ||
method === 'PATCH' ||
method === 'MERGE'
method === 'PATCH'
) {
const resourceMapping = this.ResourceMapping(resource, true);
bindVars = this.BindVars(
Expand Down Expand Up @@ -702,10 +708,7 @@
if (
(hasQueryOpts ||
isDynamicResource(resource, this.alreadyComputedFields)) &&
(method === 'PUT' ||
method === 'PATCH' ||
method === 'MERGE' ||
method === 'DELETE')
(method === 'PUT' || method === 'PATCH' || method === 'DELETE')
) {
// For update/delete statements we need to use a style query
const subQuery = new Query();
Expand All @@ -726,7 +729,7 @@
return query;
}
PathKey(
method: string,
method: InternalSupportedMethod,
path: ODataQuery,
resource: AliasedResource,
bodyKeys: string[],
Expand Down Expand Up @@ -834,7 +837,7 @@
});
}
BindVars(
method: string,
method: InternalSupportedMethod,
bodyKeys: string[],
resourceName: string,
match: Array<[string, [string, string]]>,
Expand Down Expand Up @@ -927,7 +930,7 @@
fieldName,
];
}
resource[resourceMappingsProp] = resourceMappings;

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
}
return resource[resourceMappingsProp]!;
}
Expand Down
Loading