Socket
Socket
Sign inDemoInstall

@helenejs/data

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

@helenejs/data - npm Package Compare versions

Comparing version 1.3.0-alpha.25 to 1.3.3

lib/op-queue.d.ts

137

lib/collection.js

@@ -19,2 +19,3 @@ "use strict";

const _get_candidates_1 = require("./_get-candidates");
const op_queue_1 = require("./op-queue");
exports.CollectionEvent = {

@@ -232,11 +233,13 @@ READY: 'ready',

async insert(newDoc) {
if (Array.isArray(newDoc)) {
throw new Error('insert cannot be called with an array');
}
const preparedDoc = await this.prepareDocumentForInsertion(newDoc);
this._insertInCache(preparedDoc);
const docs = (0, isArray_1.default)(preparedDoc) ? preparedDoc : [preparedDoc];
await this.persistence.persistNewState(docs);
await Promise.all(docs.map(doc => this.afterInsert(doc)));
return (0, model_1.deepCopy)(preparedDoc);
return (0, op_queue_1.queueOperation)(async () => {
if (Array.isArray(newDoc)) {
throw new Error('insert cannot be called with an array');
}
const preparedDoc = await this.prepareDocumentForInsertion(newDoc);
this._insertInCache(preparedDoc);
const docs = (0, isArray_1.default)(preparedDoc) ? preparedDoc : [preparedDoc];
await this.persistence.persistNewState(docs);
await Promise.all(docs.map(doc => this.afterInsert(doc)));
return (0, model_1.deepCopy)(preparedDoc);
});
}

@@ -364,45 +367,47 @@ /**

}
// Perform the update
let modifiedDoc, createdAt;
const modifications = [];
const candidates = await this.getCandidates(query);
for (i = 0; i < candidates.length; i += 1) {
if ((0, model_1.match)(candidates[i], query) && (multi || numReplaced === 0)) {
numReplaced += 1;
if (this.timestampData) {
createdAt = candidates[i].createdAt;
return (0, op_queue_1.queueOperation)(async () => {
// Perform the update
let modifiedDoc, createdAt;
const modifications = [];
const candidates = await this.getCandidates(query);
for (i = 0; i < candidates.length; i += 1) {
if ((0, model_1.match)(candidates[i], query) && (multi || numReplaced === 0)) {
numReplaced += 1;
if (this.timestampData) {
createdAt = candidates[i].createdAt;
}
modifiedDoc = (0, model_1.modify)(candidates[i], updateQuery);
modifiedDoc = await this.beforeUpdate(modifiedDoc, candidates[i]);
if (this.timestampData) {
modifiedDoc.createdAt = createdAt;
modifiedDoc.updatedAt = new Date();
}
await this.afterUpdate(modifiedDoc, candidates[i]);
modifications.push({
oldDoc: candidates[i],
newDoc: modifiedDoc,
});
}
modifiedDoc = (0, model_1.modify)(candidates[i], updateQuery);
modifiedDoc = await this.beforeUpdate(modifiedDoc, candidates[i]);
if (this.timestampData) {
modifiedDoc.createdAt = createdAt;
modifiedDoc.updatedAt = new Date();
}
await this.afterUpdate(modifiedDoc, candidates[i]);
modifications.push({
oldDoc: candidates[i],
newDoc: modifiedDoc,
});
}
}
// Change the docs in memory
this.updateIndexes(modifications);
// Update the datafile
const updatedDocs = (0, utils_1.pluck)(modifications, 'newDoc');
await this.persistence.persistNewState(updatedDocs);
if (options?.returnUpdatedDocs) {
const updatedDocsDC = [];
updatedDocs.forEach(doc => updatedDocsDC.push((0, model_1.deepCopy)(doc)));
return {
acknowledged: true,
modifiedCount: numReplaced,
updatedDocs: updatedDocsDC,
};
}
else {
return {
acknowledged: true,
modifiedCount: numReplaced,
};
}
// Change the docs in memory
this.updateIndexes(modifications);
// Update the datafile
const updatedDocs = (0, utils_1.pluck)(modifications, 'newDoc');
await this.persistence.persistNewState(updatedDocs);
if (options?.returnUpdatedDocs) {
const updatedDocsDC = [];
updatedDocs.forEach(doc => updatedDocsDC.push((0, model_1.deepCopy)(doc)));
return {
acknowledged: true,
modifiedCount: numReplaced,
updatedDocs: updatedDocsDC,
};
}
else {
return {
acknowledged: true,
modifiedCount: numReplaced,
};
}
});
}

@@ -422,18 +427,20 @@ async updateOne(query, updateQuery, options) {

async remove(query, options) {
let numRemoved = 0;
const self = this;
const removedDocs = [];
const multi = Boolean(options?.multi);
const candidates = await this.getCandidates(query, true);
for (const candidate of candidates) {
if ((0, model_1.match)(candidate, query) && (multi || numRemoved === 0)) {
await this.beforeRemove(candidate);
numRemoved += 1;
removedDocs.push({ $$deleted: true, _id: candidate._id });
self.removeFromIndexes(candidate);
return (0, op_queue_1.queueOperation)(async () => {
let numRemoved = 0;
const self = this;
const removedDocs = [];
const multi = Boolean(options?.multi);
const candidates = await this.getCandidates(query, true);
for (const candidate of candidates) {
if ((0, model_1.match)(candidate, query) && (multi || numRemoved === 0)) {
await this.beforeRemove(candidate);
numRemoved += 1;
removedDocs.push({ $$deleted: true, _id: candidate._id });
self.removeFromIndexes(candidate);
}
}
}
await self.persistence.persistNewState(removedDocs);
await Promise.all(candidates.map(doc => self.afterRemove(doc)));
return numRemoved;
await self.persistence.persistNewState(removedDocs);
await Promise.all(candidates.map(doc => self.afterRemove(doc)));
return numRemoved;
});
}

@@ -440,0 +447,0 @@ async deleteOne(query) {

{
"name": "@helenejs/data",
"version": "1.3.0-alpha.25",
"version": "1.3.3",
"description": "Real-time Web Apps for Node.js",

@@ -50,3 +50,3 @@ "main": "lib/index.js",

},
"gitHead": "c16682f26329a2a7080102501dfe03e4bcf988f5"
"gitHead": "67c5217013332d81e1472c6fdad055a5a3806bec"
}

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