mongoose-sort-encrypted-field
Advanced tools
Comparing version 0.2.19 to 0.2.20
@@ -6,5 +6,5 @@ "use strict"; | ||
const Redis = require("ioredis"); | ||
const defaultRedisKeyPrefix = "mongoose-sort-encrypted-field"; | ||
const { REDIS_QUEUE_CLIENT_OPTIONS } = require("./constants"); | ||
const { updateSortFieldsForDocument, generateSortIdForAllDocuments } = require("./utils"); | ||
const defaultRedisKeyPrefix = "mongoose-sort-encrypted-field"; | ||
let modelsQueue; | ||
@@ -11,0 +11,0 @@ class ModelsQueue { |
@@ -12,2 +12,28 @@ "use strict"; | ||
} | ||
function getAverageSortId(predecessorSortId, successorSortId, noOfCharsToIncreaseOnSaturation) { | ||
if (!predecessorSortId) { | ||
predecessorSortId = "".padEnd(successorSortId.length, "\0"); | ||
} | ||
if (!successorSortId) { | ||
successorSortId = "".padEnd(predecessorSortId.length, "\uffff"); | ||
} | ||
let predecessorNumber; | ||
let successorNumber; | ||
if (predecessorSortId.length === successorSortId.length) { | ||
predecessorNumber = new Base2N(predecessorSortId, 16); | ||
successorNumber = new Base2N(successorSortId, 16); | ||
const averageNumber = predecessorNumber.average(successorNumber); | ||
if (averageNumber.toString() !== predecessorNumber.toString()) { | ||
return averageNumber.toString(); | ||
} | ||
predecessorNumber = new Base2N(predecessorSortId.padEnd(averageNumber.length + noOfCharsToIncreaseOnSaturation, "\0"), 16); | ||
successorNumber = new Base2N(successorSortId.padEnd(averageNumber.length + noOfCharsToIncreaseOnSaturation, "\0"), 16); | ||
return predecessorNumber.average(successorNumber).toString(); | ||
} | ||
const bigger = predecessorSortId.length > successorSortId.length ? predecessorSortId : successorSortId; | ||
const smaller = successorSortId.length > predecessorSortId.length ? predecessorSortId : successorSortId; | ||
const biggerNumber = new Base2N(bigger, 16); | ||
const smallerNumber = new Base2N(smaller.padEnd(bigger.length, "\0"), 16); | ||
return biggerNumber.average(smallerNumber).toString(); | ||
} | ||
async function generateSortIdUsingBinarySearch(model, fieldName, fieldValue, sortFieldName) { | ||
@@ -71,30 +97,4 @@ const { ignoreCases, noOfCharsForSortId, noOfCharsToIncreaseOnSaturation } = model.schema.options.sortEncryptedFieldsOptions; | ||
} | ||
function getAverageSortId(predecessorSortId, successorSortId, noOfCharsToIncreaseOnSaturation) { | ||
if (!predecessorSortId) { | ||
predecessorSortId = "".padEnd(successorSortId.length, "\0"); | ||
} | ||
if (!successorSortId) { | ||
successorSortId = "".padEnd(predecessorSortId.length, "\uffff"); | ||
} | ||
let predecessorNumber; | ||
let successorNumber; | ||
if (predecessorSortId.length === successorSortId.length) { | ||
predecessorNumber = new Base2N(predecessorSortId, 16); | ||
successorNumber = new Base2N(successorSortId, 16); | ||
const averageNumber = predecessorNumber.average(successorNumber); | ||
if (averageNumber.toString() !== predecessorNumber.toString()) { | ||
return averageNumber.toString(); | ||
} | ||
predecessorNumber = new Base2N(predecessorSortId.padEnd(averageNumber.length + noOfCharsToIncreaseOnSaturation, "\0"), 16); | ||
successorNumber = new Base2N(successorSortId.padEnd(averageNumber.length + noOfCharsToIncreaseOnSaturation, "\0"), 16); | ||
return predecessorNumber.average(successorNumber).toString(); | ||
} | ||
const bigger = predecessorSortId.length > successorSortId.length ? predecessorSortId : successorSortId; | ||
const smaller = successorSortId.length > predecessorSortId.length ? predecessorSortId : successorSortId; | ||
const biggerNumber = new Base2N(bigger, 16); | ||
const smallerNumber = new Base2N(smaller.padEnd(bigger.length, "\0"), 16); | ||
return biggerNumber.average(smallerNumber).toString(); | ||
} | ||
async function updateSortFieldsForDocument({ objectId, model, fieldName, fieldValue, sortFieldName }) { | ||
const { silent, noOfCharsToIncreaseOnSaturation } = model.schema.options.sortEncryptedFieldsOptions; | ||
const { silent } = model.schema.options.sortEncryptedFieldsOptions; | ||
if (!silent) { | ||
@@ -101,0 +101,0 @@ console.time(`mongoose-sort-encrypted-field -> updateSortFieldsForDocument() -> objectId: ${objectId}, fieldName: ${fieldName}, sortFieldName: ${sortFieldName}, timeTaken: `); |
{ | ||
"name": "mongoose-sort-encrypted-field", | ||
"version": "0.2.19", | ||
"version": "0.2.20", | ||
"description": "Mongoose plugin to enable sorting on encrypted fields", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26797