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

mongoose-sort-encrypted-field

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-sort-encrypted-field - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

3

lib/index.js

@@ -140,2 +140,5 @@ "use strict";

.exec();
if (noOfTotalDocuments === 0) {
return;
}
if (noOfTotalDocuments <= revaluateAllCountThreshold || noOfDocumentsWithoutSortId / noOfTotalDocuments > revaluateAllThreshold) {

@@ -142,0 +145,0 @@ await modelsQueue.removeAllJobs(groupId);

5

lib/sortIdManager.js

@@ -143,4 +143,7 @@ "use strict";

curr = add(curr, diff);
if (curr[curr.length - 1] === 0 && curr.length > diff.length) {
curr = curr.slice(0, curr.length - 1);
}
}
await this.model.updateOne({ _id: documents[i]._id }, { $set: { [this.sortFieldName]: curr.toString() } });
await this.model.updateOne({ _id: documents[i]._id }, { $set: { [this.sortFieldName]: Buffer.from(curr).reverse() } });
}

@@ -147,0 +150,0 @@ if (!this.silent) {

{
"name": "mongoose-sort-encrypted-field",
"version": "0.4.2",
"version": "0.4.3",
"description": "Mongoose plugin to enable sorting on encrypted fields",

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

@@ -33,3 +33,3 @@ const { encrypt, decrypt } = require("../utils/encryption");

encryptedUserSchema.statics.createUser = async function (data) {
encryptedUserSchema.statics.createUser = async function createUser(data) {
const user = new this(data);

@@ -36,0 +36,0 @@ const userData = await user.save();

@@ -1,6 +0,3 @@

const { getModelWithSortEncryptedFieldsPlugin } = require("../../lib/index");
const { getRedis } = require("../utils/databases");
const mongoose = require("mongoose");
const redis = getRedis();
const unencryptedUserSchema = new mongoose.Schema({

@@ -23,3 +20,3 @@ firstName: {

unencryptedUserSchema.statics.createUser = async function (data) {
unencryptedUserSchema.statics.createUser = async function createUser(data) {
const user = new this(data);

@@ -26,0 +23,0 @@ const userData = await user.save();

@@ -9,43 +9,4 @@ const assert = require("assert");

const newUsers = require("./data/newUsers.json");
const n = 0;
// const newUsers = [];//require("./data/newUsers.json");
// const n = 50;
// it(`creating new documents with ${n} random users and ${newUsers.length} predefined users`, async function () {
// for (let i = 0; i < n; i += 1) {
// const [firstName, middleName] = generateName().raw;
// const [lastName] = generateName().raw;
// newUsers.push({ firstName, middleName, lastName });
// }
// await unencryptedUserModel.deleteMany({}).exec();
// await encryptedUserModel.deleteMany({}).exec();
// for (const newUser of newUsers) {
// await unencryptedUserModel.createUser(newUser);
// await encryptedUserModel.createUser(newUser);
// }
// const encryptedUsers = await encryptedUserModel.find({}).sort({ firstName: 1 }).exec();
// for (let i = 0; i < n; i += 1) {
// await encryptedUserModel.updateOne({ _id: encryptedUsers[i]._id }, { $set: { firstNameSort: Buffer.from(new Uint8Array([i])) } })
// }
// assert.equal(await unencryptedUserModel.find({}).count().exec(), newUsers.length);
// assert.equal(await encryptedUserModel.find({}).count().exec(), newUsers.length);
// });
const n = 90;
// it("Sorting check for { firstName: 1 }", async function () {
// // console.log("Waiting for sort ID to be generated...");
// // let pendingJobsCount = -1;
// // while (pendingJobsCount !== 0) {
// // pendingJobsCount = await modelsQueue.getPendingJobsCount();
// // await new Promise((r) => setTimeout(r, 5000));
// // }
// const unencryptedUsers = await unencryptedUserModel.find({}).sort({ firstName: 1 }).exec();
// const encryptedUsers1 = await encryptedUserModel.find({}).sort({ firstNameSort: 1 }).exec();
// const encryptedUsers = await encryptedUserModel.find({}).sort({ firstNameSort: 1 }).exec();
// await Promise.all(
// unencryptedUsers.map(async (unencryptedUser, i) => {
// console.log(unencryptedUser.firstName, encryptedUsers[i].firstName);
// assert.equal(unencryptedUser.firstName, encryptedUsers[i].firstName);
// })
// );
// });
describe(`Testing sorting after creating new documents with ${n} random users and ${newUsers.length} predefined users`, async function () {

@@ -75,6 +36,6 @@ let unencryptedUserModel;

await encryptedUserModel.deleteMany({}).exec();
for (const newUser of newUsers) {
await Promise.all(newUsers.map(async (newUser) => {
await unencryptedUserModel.createUser(newUser);
await encryptedUserModel.createUser(newUser);
}
}));
assert.equal(await unencryptedUserModel.find({}).count().exec(), newUsers.length);

@@ -92,3 +53,2 @@ assert.equal(await encryptedUserModel.find({}).count().exec(), newUsers.length);

const unencryptedUsers = await unencryptedUserModel.find({}).sort({ firstName: 1 }).exec();
const encryptedUsers1 = await encryptedUserModel.find({}).sort({ firstNameSort: 1 }).exec();
const encryptedUsers = await encryptedUserModel.find({}).sort({ firstNameSort: 1 }).exec();

@@ -107,2 +67,3 @@ await Promise.all(

unencryptedUsers.map(async (unencryptedUser, i) => {
console.log(unencryptedUser.middleName, encryptedUsers[i].middleName);
assert.equal(unencryptedUser.middleName, encryptedUsers[i].middleName);

@@ -117,2 +78,3 @@ })

unencryptedUsers.map(async (unencryptedUser, i) => {
console.log(unencryptedUser.lastName, encryptedUsers[i].lastName);
assert.equal(unencryptedUser.lastName, encryptedUsers[i].lastName);

@@ -119,0 +81,0 @@ })

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