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

rest-client-sdk

Package Overview
Dependencies
Maintainers
4
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-client-sdk - npm Package Compare versions

Comparing version 6.3.0 to 6.4.0

4

CHANGELOG.md
# Changelog
## 6.4.0
- allow unitOfWork deactivation on find\* calls
## 6.3.0

@@ -4,0 +8,0 @@

@@ -12,2 +12,3 @@ import URI from 'urijs';

constructor(sdk: RestClientSdk<SdkMetadata>, metadata: ClassMetadata);
withUnitOfWork(enabled: boolean): this;
getDefaultParameters(): Record<string, unknown>;

@@ -75,3 +76,8 @@ getPathBase(pathParameters: Record<string, unknown>): string;

private _getEntityIdentifier;
/**
* TODO convert this to javascript private method (`#`) once https://github.com/microsoft/TypeScript/issues/37677 is resolved
*/
private _activateUnitOfWork;
private _throwIfUnitOfWorkIsDisabled;
}
export default AbstractClient;

2

package.json
{
"name": "rest-client-sdk",
"version": "6.3.0",
"version": "6.4.0",
"description": "Rest Client SDK for API",

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

@@ -164,2 +164,21 @@ # Mapado Rest Client JS SDK [![Build Status](https://travis-ci.org/mapado/rest-client-js-sdk.svg?branch=master)](https://travis-ci.org/mapado/rest-client-js-sdk)

##### Deactivating the UnitOfWork for some calls
You can deactivate unit of work for some calls to avoid registering objects you don't want:
```js
const productRepo = sdk.getRepository('products');
// imagine a call with a backend returning all product fields
productRepo.find(1, { fields: ALL_PROPERTIES }); // will register the product with all it's properties.
// then for some reason, we make a call that will return only the id, and no properties
// you do not want this entity to be registered
productRepo.withUnitOfWork(false).find(1, { fields: ONLY_ID });
```
The `withUnitOfWork` can only be used for find\* calls. See [#94](https://github.com/mapado/rest-client-js-sdk/issues/94) for more informations.
> You can not activate the unit of work if it has not been enabled globally.
### Make calls

@@ -166,0 +185,0 @@

@@ -24,2 +24,4 @@ import URI from 'urijs';

#isUnitOfWorkEnabled: boolean;
constructor(sdk: RestClientSdk<SdkMetadata>, metadata: ClassMetadata) {

@@ -30,4 +32,11 @@ this.sdk = sdk;

this.metadata = metadata;
this.#isUnitOfWorkEnabled = true;
}
withUnitOfWork(enabled: boolean): this {
this.#isUnitOfWorkEnabled = enabled;
return this;
}
getDefaultParameters(): Record<string, unknown> {

@@ -135,2 +144,4 @@ return {};

): Promise<D['entity']> {
this._throwIfUnitOfWorkIsDisabled();
const url = new URI(this.getPathBase(pathParameters));

@@ -173,2 +184,4 @@ url.addSearch(queryParam);

): Promise<D['entity']> {
this._throwIfUnitOfWorkIsDisabled();
const url = new URI(this.getEntityURI(entity));

@@ -213,2 +226,4 @@ url.addSearch(queryParam);

delete(entity: D['entity'], requestParams = {}): Promise<Response> {
this._throwIfUnitOfWorkIsDisabled();
const url = this.getEntityURI(entity);

@@ -263,5 +278,7 @@ const identifier = this._getEntityIdentifier(entity);

// then we register the re-normalized item
if (identifier !== null) {
if (this.#isUnitOfWorkEnabled && identifier !== null) {
this.sdk.unitOfWork.registerClean(identifier, normalizedItem);
}
this._activateUnitOfWork();
}

@@ -289,3 +306,3 @@

if (identifier !== null) {
if (this.#isUnitOfWorkEnabled && identifier !== null) {
this.sdk.unitOfWork.registerClean(

@@ -297,2 +314,4 @@ identifier,

this._activateUnitOfWork();
return item as D['entity'];

@@ -505,2 +524,17 @@ });

}
/**
* TODO convert this to javascript private method (`#`) once https://github.com/microsoft/TypeScript/issues/37677 is resolved
*/
private _activateUnitOfWork(): void {
this.#isUnitOfWorkEnabled = true;
}
private _throwIfUnitOfWorkIsDisabled(): void {
if (!this.#isUnitOfWorkEnabled) {
throw new Error(
'UnitOfWork can be deactivated only on find* methods (for now). If you think this should be authorized, please report in https://git.io/JkYTO'
);
}
}
}

@@ -507,0 +541,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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