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

mvom

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mvom - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

shared/typedefs/ResultsObject.js

3

.mvomrc.json

@@ -6,4 +6,5 @@ {

"entry": "^0.1.0",
"find": "^0.1.0",
"find": "^0.2.0",
"findById": "^0.1.0",
"findByIds": "^0.1.0",
"getServerInfo": "^0.1.0",

@@ -10,0 +11,0 @@ "save": "^0.1.0"

# CHANGELOG.md
## 0.3.2
###### _2019-05-13_
- Add new `findByIds` static model method which finds a list of documents by id. ReedMattos
- Add new `findAndCount` static model method which returns both the documents matching the query as well as the count of
all documents matching the query irrespective of skip and limit. @ReedMattos
## 0.3.1

@@ -3,0 +9,0 @@ ###### _2018-12-21_

@@ -71,9 +71,10 @@ 'use strict';

/**
* Find a document by its id
* @function findById
* Find multiple documents by their ids
* @function findByIds
* @memberof Model
* @static
* @async
* @param {string} id - Document identifier
* @returns {Promise.<Model>} Model instance
* @param {string[]} ids - Array of document identifiers
* @returns {Promise.<Model[]>} Array of model instances
* @throws {InvalidParameterError} An invalid parameter was passed to the function
* @throws {ConnectionManagerError} (indirect) An error occurred in connection manager communications

@@ -84,2 +85,19 @@ * @throws {DbServerError} (indirect) An error occurred on the database server

/**
* Find documents via query, returning them along with a count
* @function findAndCount
* @memberof Model
* @static
* @async
* @param {Object} [selectionCriteria = {}] - Selection criteria object
* @param {Object} [options = {}]
* @param {number} [options.skip = 0] - Skip this number of items in the result set
* @param {number} [options.limit = null] - Limit the result set to this number of items
* @param {Array} [options.sort = []] - Array of field/direction nested arrays defining sort criteria. ex: [[foo, 1], [bar, -1]] where value of 1 indicates ascending and -1 indicates descending
* @returns {Promise.<ResultsObject>} Query results object
* @throws {ConnectionManagerError} (indirect) An error occurred in connection manager communications
* @throws {DbServerError} (indirect) An error occurred on the database server
*/
/* static methods */

@@ -195,2 +213,15 @@

/**
* Find a document by its id
* @function findById
* @memberof Model
* @static
* @async
* @param {string} id - Document identifier
* @returns {Promise.<Model>} Model instance
* @throws {ConnectionManagerError} (indirect) An error occurred in connection manager communications
* @throws {DbServerError} (indirect) An error occurred on the database server
*/
/**
* Find documents via query

@@ -243,4 +274,10 @@ * @function find

Model.find = (selectionCriteria = {}, options = {}) => {
Model.find = async (selectionCriteria = {}, options = {}) => {
const query = new _Query2.default(Model, selectionCriteria, options);
const { documents } = await query.exec();
return documents;
};
Model.findAndCount = (selectionCriteria = {}, options = {}) => {
const query = new _Query2.default(Model, selectionCriteria, options);
return query.exec();

@@ -259,2 +296,18 @@ };

Model.findByIds = async ids => {
if (ids == null) {
throw new _InvalidParameter2.default({ parameterName: 'ids' });
}
// this will cast ids to an array in the event only a single id is passed in
const idsArray = [].concat(ids);
const data = await Model.connection.executeDbFeature('findByIds', {
filename: Model.file,
ids: idsArray
});
// returns an array of newly instantiated Models
// there may be empty strings in the array if a particular document couldn't be found or contained corrupt data
return data.result.map(dbResultItem => dbResultItem ? Model.makeModelFromDbResult(dbResultItem) : null);
};
Model.makeModelFromDbResult = ({ record = [], _id = null, __v = null } = {}) => {

@@ -261,0 +314,0 @@ const model = new Model({}, { _id, __v });

{
"name": "mvom",
"author": "STORIS",
"version": "0.3.1",
"version": "0.3.2",
"description": "Multivalue Object Mapper",

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

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

* @async
* @returns {Model[]} Array of model instances
* @returns {Promise.<ResultsObject>} Query results object
* @throws {ConnectionManagerError} (indirect) An error occurred in connection manager communications

@@ -274,3 +274,6 @@ * @throws {DbServerError} (indirect) An error occurred on the database server

return data.result.map(dbResultItem => this._Model.makeModelFromDbResult(dbResultItem));
return {
count: data.count,
documents: data.documents.map(dbResultItem => this._Model.makeModelFromDbResult(dbResultItem))
};
};

@@ -277,0 +280,0 @@

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