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

@janiscommerce/api-save

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@janiscommerce/api-save - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

5

CHANGELOG.md

@@ -10,2 +10,7 @@ # Changelog

## [2.0.0] - 2019-07-18
### Changed
- Browse APIs paths changed. Now MS_PATH env var is taken into account.
- Now relationships configurations receive a `modelClass` instead of a `model`
## [1.1.2] - 2019-07-02

@@ -12,0 +17,0 @@ ### Fixed

2

lib/api-save-data.js

@@ -22,3 +22,3 @@ 'use strict';

this.controller = apiSaveValidator.validateController();
this.model = apiSaveValidator.validateModel();
}

@@ -25,0 +25,0 @@

@@ -16,7 +16,7 @@ 'use strict';

if(this.apiInstance.dataToSave.id) {
const updateResult = await this.apiInstance.controller.update(dataToSave, { id: this.apiInstance.dataToSave.id });
const updateResult = await this.apiInstance.model.update(dataToSave, { id: this.apiInstance.dataToSave.id });
return !updateResult ? updateResult : this.apiInstance.dataToSave.id;
}
return this.apiInstance.controller.insert(dataToSave);
return this.apiInstance.model.insert(dataToSave);
}

@@ -23,0 +23,0 @@

@@ -35,7 +35,8 @@ 'use strict';

const { controller } = relationshipParameters;
const { modelClass: ModelClass } = relationshipParameters;
const relationshipsToSave = this._formatRelationshipsToInsert(relationship, relationshipParameters);
return controller.multiInsert(relationshipsToSave);
const model = new ModelClass();
return model.multiInsert(relationshipsToSave);
}

@@ -45,5 +46,6 @@

const { controller, mainIdentifierField } = relationshipParameters;
const { modelClass: ModelClass, mainIdentifierField } = relationshipParameters;
const currentRelationships = controller.get({
const model = new ModelClass();
const currentRelationships = model.get({
[mainIdentifierField]: this.mainId

@@ -56,4 +58,4 @@ });

const removePromise = removeData.length ? controller.multiRemove(removeData) : Promise.resolve();
const insertPromise = insertData.length ? controller.multiInsert(insertData) : Promise.resolve();
const removePromise = removeData.length ? model.multiRemove(removeData) : Promise.resolve();
const insertPromise = insertData.length ? model.multiInsert(insertData) : Promise.resolve();

@@ -60,0 +62,0 @@ return Promise.all([removePromise, insertPromise]);

'use strict';
const { Controller } = require('@janiscommerce/model-controller');
const { struct } = require('superstruct');
const path = require('path');

@@ -33,10 +33,10 @@ const ApiSaveError = require('./api-save-error');

} catch(e) {
const path = e.path.join('.');
throw new ApiSaveError(`${e.message} in ${path}`, ApiSaveError.codes.INVALID_REQUEST_DATA);
const errorParh = e.path.join('.');
throw new ApiSaveError(`${e.message} in ${errorParh}`, ApiSaveError.codes.INVALID_REQUEST_DATA);
}
}
validateController() {
validateModel() {
try {
return Controller.getInstance(this.apiInstance.entity);
return this._getModelInstance();
} catch(e) {

@@ -47,4 +47,11 @@ throw new ApiSaveError(e.message, ApiSaveError.codes.INVALID_ENTITY);

/* istanbul ignore next */
_getModelInstance() {
// eslint-disable-next-line global-require, import/no-dynamic-require
const Model = require(path.join(process.cwd(), process.env.MS_PATH, 'models', this.apiInstance.entity));
return new Model();
}
}
module.exports = ApiSaveValidator;
{
"name": "@janiscommerce/api-save",
"version": "1.1.2",
"version": "2.0.0",
"description": "A package to handle JANIS Views Save APIs",

@@ -21,6 +21,6 @@ "main": "index.js",

"devDependencies": {
"husky": "^2.4.1",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.17.3",
"husky": "^2.7.0",
"mocha": "^5.2.0",

@@ -37,7 +37,7 @@ "nyc": "^13.1.0",

"dependencies": {
"@janiscommerce/api-view": "^1.2.0",
"@janiscommerce/model-controller": "^1.4.0",
"lodash": "^4.17.11",
"@janiscommerce/api-view": "^1.3.0",
"@janiscommerce/model": "^1.1.1",
"lodash": "^4.17.14",
"superstruct": "^0.6.1"
}
}
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