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

@adiwajshing/keyed-db

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adiwajshing/keyed-db - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

12

lib/KeyedDB.d.ts

@@ -49,3 +49,13 @@ import { IKeyedDB, Identifiable, Comparable, PaginationMode } from "./Types";

all(): T[];
updateKey(value: T, update: (value: T) => void): void;
/**
* Updates a value specified by the ID
* and adjusts its position in the DB after an update if required
* @param id
* @param update
*/
update(id: string, update: (value: T) => void): 1 | 2;
/**
* @deprecated see `update`
*/
updateKey(value: T, update: (value: T) => void): 1 | 2;
filter(predicate: (value: T, index: number) => boolean): KeyedDB<T, K>;

@@ -52,0 +62,0 @@ /**

@@ -121,6 +121,31 @@ "use strict";

}
/**
* Updates a value specified by the ID
* and adjusts its position in the DB after an update if required
* @param id
* @param update
*/
update(id, update) {
const value = this.get(id);
if (value) {
const idx = this.firstIndex(value);
if (idx >= 0 && idx < this.array.length && this.idGetter(this.array[idx]) === id) {
const oldKey = this.key.key(value);
update(value);
const newKey = this.key.key(value);
if (newKey !== oldKey) {
delete this.dict[id];
this.array.splice(idx, 1);
this._insertSingle(value);
return 2;
}
return 1;
}
}
}
/**
* @deprecated see `update`
*/
updateKey(value, update) {
this.delete(value);
update(value);
this.insert(value);
return this.update(this.idGetter(value), update);
}

@@ -218,5 +243,6 @@ filter(predicate) {

firstIndex(value) {
return BinarySearch_1.default(this.array, v => this.key.compare(this.key.key(value), this.key.key(v)));
const valueKey = this.key.key(value);
return BinarySearch_1.default(this.array, v => this.key.compare(valueKey, this.key.key(v)));
}
}
exports.default = KeyedDB;

2

package.json
{
"name": "@adiwajshing/keyed-db",
"version": "0.2.3",
"version": "0.2.4",
"description": "Lightweight library to store an in-memory DB",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/adiwajshing/keyed-db",

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