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

@sap_oss/odata-library

Package Overview
Dependencies
Maintainers
11
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap_oss/odata-library - npm Package Compare versions

Comparing version 0.9.11 to 0.9.12

5

CHANGELOG.md
# Changelog
# 0.9.12
* f5edbb3 - [FEATURE] PUT method for OData 3.0 and newer - Norbert Volf
* 58bb17b - [FIX] Parse PropertyPath with Navigation Property - Norbert Volf
# 0.9.11

@@ -4,0 +9,0 @@

24

doc/ACTIVE_OPERATIONS.md

@@ -53,4 +53,12 @@ # Create entity

Use EntitySet.merge to update properties of an entity. The object
passed as parameter of the EntitySet.merge method should contain
OData protocol versions 1.0 and 2.0 define "MERGE" HTTP method to update
existing entity. Newer versions of OData protocol define "PATCH"
HTTP method to update existing entity. EntitySet supports both HTTP
methods. The EntitySet does not check current version of the OData
protocol version. You can try use *patch* for OData 2.0 also. You
are limited by server implementation only. EntitySet.patch and
EntitySet.merge are synonyms.
Use merge or patch to update properties of an entity. The object
passed as parameter of the merge or patch method should contains
entries of the entity's key properties and entries of properties,

@@ -62,3 +70,3 @@ which are supposed to be updated.

return service .C_PaymentRequest
.merge({
.patch({
"PaymentRequest": "861",

@@ -73,5 +81,5 @@ "DraftUUID": "0894ef30-1ccd-1ed8-bdde-86bb77adbb96",

Merge could be callaed with two parameter. First parameter contains
key and second parameter contains object with properties for changes.
It is useful for chaining.
merge and patch could be called with two parameter also. First parameter
contains key and second parameter contains object with properties
to change. It is useful for chaining.

@@ -94,5 +102,5 @@ ```javascript

# Update entity (entire resource)
# Replace entity (entire resource)
Use EntitySet.put to update an entity by replacing its content.
Use EntitySet.put to replace an entity by replacing its content.
The entity content is replaced by a new content from object

@@ -99,0 +107,0 @@ passed as parameter of the EntitySet.put method.

@@ -479,3 +479,4 @@ "use strict";

/**
* Wrapper around MERGE function. All parameters are passed to superagent
* Wrapper around MERGE function. All parameters are passed to superagent. MERGE request
* is supported by OData protocol 2.0 and older.
*

@@ -496,2 +497,19 @@ * @param {String} inputUrl relative path in the service

/**
* Create PATCH request. Patch updates the entity. It is supported by OData protocol
* version 3.0 and newer.
*
* @param {String} inputUrl relative path in the service
* @param {Object} headers object which contains headers used for the GET request
* @param {Object} payload data which is converted to the JSON string and passed as body of MERGE request in batch
*
* @returns {Promise} promise which done when PATCH request has finished
*
* @public
* @memberof Agent
*/
patch(...args) {
return this.sendRequest("PATCH", ...args);
}
/**
* Wrapper around DELETE function. All parameters are passed to superagent method

@@ -498,0 +516,0 @@ *

@@ -53,2 +53,36 @@ "use strict";

/**
* Create request in batch with payload
*
* @param {String} httpMethod name of the HTTP method
* @param {String} inputUrl relative path in the service
* @param {Object} headers object which contains headers used for the GET request
* @param {Object} payload data which is converted to the JSON string and passed as body of POST request
* @param {batch/ChangeSet} changeSet which contains newly created request
*
* @returns {batch/Request} instance of batch Request
*
* @private
* @memberof Agent
*/
addRequestWithPayload(httpMethod, inputUrl, headers, payload, changeSet) {
return this.addRequest(
httpMethod,
inputUrl,
_.assign(
{
"sap-contextid-accept": "header",
Accept: "application/json",
DataServiceVersion: "2.0",
MaxDataServiceVersion: "2.0",
"Content-Type": "application/json",
"sap-message-scope": "BusinessObject",
},
headers
),
payload,
changeSet
);
}
/**
* Try to find passed changeSet in the current batch. If changeSet is not

@@ -208,26 +242,11 @@ * defined and the batch contains only one batch. Use it.

*
* @public
* @memberof Agent
*/
post(inputUrl, headers, payload, changeSet) {
return this.addRequest(
"POST",
inputUrl,
_.assign(
{
"sap-contextid-accept": "header",
Accept: "application/json",
DataServiceVersion: "2.0",
MaxDataServiceVersion: "2.0",
"Content-Type": "application/json",
"sap-message-scope": "BusinessObject",
},
headers
),
payload,
changeSet
);
post(...args) {
return this.addRequestWithPayload("POST", ...args);
}
/**
* Create PUT request in batch
* Create PUT request in batch. The PUT request replaces entity by OData protocol
*

@@ -241,26 +260,12 @@ * @param {String} inputUrl relative path in the service

*
* @public
* @memberof Agent
*/
put(inputUrl, headers, payload, changeSet) {
return this.addRequest(
"PUT",
inputUrl,
_.assign(
{
"sap-contextid-accept": "header",
Accept: "application/json",
DataServiceVersion: "2.0",
MaxDataServiceVersion: "2.0",
"Content-Type": "application/json",
"sap-message-scope": "BusinessObject",
},
headers
),
payload,
changeSet
);
put(...args) {
return this.addRequestWithPayload("PUT", ...args);
}
/**
* Create MERGE request in batch
* Create MERGE request in batch. MERGE updates the entity.
* It is supported by OData protocol 1.0 and 2.0
*

@@ -274,25 +279,28 @@ * @param {String} inputUrl relative path in the service

*
* @public
* @memberof Agent
*/
merge(inputUrl, headers, payload, changeSet) {
return this.addRequest(
"MERGE",
inputUrl,
_.assign(
{
"sap-contextid-accept": "header",
Accept: "application/json",
DataServiceVersion: "2.0",
MaxDataServiceVersion: "2.0",
"Content-Type": "application/json",
"sap-message-scope": "BusinessObject",
},
headers
),
payload,
changeSet
);
merge(...args) {
return this.addRequestWithPayload("MERGE", ...args);
}
/**
* Create PATCH request in batch. Patch updates the entity.
* It is supported by OData protocol version 3.0 and later.
*
* @param {String} inputUrl relative path in the service
* @param {Object} headers object which contains headers used for the GET request
* @param {Object} payload data which is converted to the JSON string and passed as body of MERGE request in batch
* @param {batch/ChangeSet} changeSet which contains newly created request
*
* @returns {batch/Request} instance of batch Request
*
* @public
* @memberof Agent
*/
patch(...args) {
return this.addRequestWithPayload("PATCH", ...args);
}
/**
* Create DELETE request in batch

@@ -299,0 +307,0 @@ *

@@ -236,2 +236,18 @@ "use strict";

/**
* Send request to update an entity by HTTP MERGE method (update for
* OData protocol version 1.0-2.0)
*
* @param {Object} body map of key properties and new data for the entity
* @param {Object} [propertiesToChange] map of new data for the entity
*
* @return {Promise} returned promise is resolved when request is finished
* Promise is resolved with response object which doesn't contain body
*
* @memberof QueryableResource
*/
merge(...args) {
return this.processUpdateCall("merge", ...args);
}
/**
* Send request to update an entity by HTTP MERGE method

@@ -247,3 +263,21 @@ *

*/
merge() {
patch(...args) {
return this.processUpdateCall("patch", ...args);
}
/**
* Send request to update entity via MERGE or PATCH method. The method
* unify code for patch and merge methods.
*
* @param {String} methodName name of method from agent "merge" or "patch"
* @param {Object} body map of key properties and new data for the entity
* @param {Object} [propertiesToChange] map of new data for the entity
*
* @return {Promise} returned promise is resolved when request is finished
* Promise is resolved with response object which doesn't contain body
*
* @private
* @memberof QueryableResource
*/
processUpdateCall(methodName, ...args) {
let keyProperties;

@@ -257,6 +291,6 @@ let keyPredicate;

if (arguments.length === 0 || arguments.length > 2) {
throw new Error("Invalid body parameter for merge.");
} else if (arguments.length === 1) {
entity = _.assign({}, arguments[0], this.defaultRequest._keyValue);
if (args.length === 0 || args.length > 2) {
throw new Error(`Invalid body parameter for ${methodName}.`);
} else if (args.length === 1) {
entity = _.assign({}, args[0], this.defaultRequest._keyValue);
keyProperties = this.keyProperties(entity);

@@ -269,6 +303,6 @@ keyPredicate = this.keyPredicate(keyProperties);

} else {
keyProperties = this.keyProperties(arguments[0]);
keyProperties = this.keyProperties(args[0]);
keyPredicate = this.keyPredicate(keyProperties);
// note: following assignment allows to change also properties which are part of the key
propertiesToChange = arguments[1];
propertiesToChange = args[1];
}

@@ -282,3 +316,3 @@

this.defaultRequest.header("Accept", "application/json");
return defaultBatch.merge(
return defaultBatch[methodName](
path,

@@ -292,3 +326,3 @@ this.defaultRequest._headers,

this.header("Content-type", "application/json");
return this.agent.merge(
return this.agent[methodName](
path,

@@ -295,0 +329,0 @@ this.defaultRequest._headers,

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

* @param {EntityType} [entityType] target entity type
* @param {CsdlSchema} [schema] parent schema
* @memberof SideEffectsType
*/
constructor(annotation, entityType) {
constructor(annotation, entityType, schema) {
Object.defineProperty(this, "annotation", {

@@ -36,13 +37,30 @@ get: () => annotation,

definePropertyCollection(this, "SourceEntities", (p) =>
SideEffectsType._.definePropertyCollection(this, "SourceEntities", (p) =>
entityType.getNavigationProperty(p)
);
definePropertyCollection(this, "SourceProperties", (p) =>
SideEffectsType._.definePropertyCollection(this, "SourceProperties", (p) =>
entityType.getProperty(p)
);
definePropertyCollection(this, "TargetEntities", (p) =>
SideEffectsType._.definePropertyCollection(this, "TargetEntities", (p) =>
entityType.getNavigationProperty(p)
);
definePropertyCollection(this, "TargetProperties", (p) =>
entityType.getProperty(p)
SideEffectsType._.definePropertyCollection(
this,
"TargetProperties",
(p) => {
let propertyName;
let navigationPropertyName;
let foundProperty;
let isNavigationProperty = _.isString(p) && p.split("/").length === 2;
if (isNavigationProperty) {
[navigationPropertyName, propertyName] = p.split("/");
foundProperty = entityType
.getNavigationProperty(navigationPropertyName)
.getTarget(schema)
.entityType.getProperty(propertyName);
} else {
foundProperty = entityType.getProperty(p);
}
return foundProperty;
}
);

@@ -52,2 +70,6 @@ }

SideEffectsType._ = {
definePropertyCollection: definePropertyCollection,
};
module.exports = SideEffectsType;

@@ -71,7 +71,7 @@ "use strict";

function createEntityTypeCommonExtension(entityType) {
function createEntityTypeCommonExtension(entityType, schema) {
return {
sideEffects: entityType.annotations
.filter((a) => a.term === "Common.SideEffects")
.map((a) => new SideEffectsType(a, entityType)),
.map((a) => new SideEffectsType(a, entityType, schema)),
};

@@ -117,3 +117,3 @@ }

entityType.sap.common = createEntityTypeCommonExtension(entityType);
entityType.sap.common = createEntityTypeCommonExtension(entityType, schema);
entityType.sap.ui = createEntityTypeUIExtension(entityType);

@@ -134,2 +134,6 @@

EntityTypeExtender._ = {
createEntityTypeCommonExtension: createEntityTypeCommonExtension,
};
module.exports = EntityTypeExtender;
{
"name": "@sap_oss/odata-library",
"version": "0.9.11",
"version": "0.9.12",
"description": "OData client for testing Netweawer OData services.",

@@ -5,0 +5,0 @@ "main": "index.js",

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