From 5a6d8dc230f3528491b435a082efaa61c199fd3c Mon Sep 17 00:00:00 2001 From: Lord No Name Date: Sun, 11 Aug 2024 18:54:32 +0100 Subject: [PATCH] Add files via upload --- node_modules/@adiwajshing/keyed-db/LICENSE | 21 +++++ node_modules/@adiwajshing/keyed-db/README.md | 85 +++++++++++++++++++ .../@adiwajshing/keyed-db/package.json | 34 ++++++++ 3 files changed, 140 insertions(+) create mode 100644 node_modules/@adiwajshing/keyed-db/LICENSE create mode 100644 node_modules/@adiwajshing/keyed-db/README.md create mode 100644 node_modules/@adiwajshing/keyed-db/package.json diff --git a/node_modules/@adiwajshing/keyed-db/LICENSE b/node_modules/@adiwajshing/keyed-db/LICENSE new file mode 100644 index 0000000..0d2d983 --- /dev/null +++ b/node_modules/@adiwajshing/keyed-db/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Adhiraj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/@adiwajshing/keyed-db/README.md b/node_modules/@adiwajshing/keyed-db/README.md new file mode 100644 index 0000000..4497bbe --- /dev/null +++ b/node_modules/@adiwajshing/keyed-db/README.md @@ -0,0 +1,85 @@ +# Keyed DB + +A light-weight node library to manage a sorted & indexed collection with pagination support. +All done using Binary Search. Based off my swift code for [Queenfisher](https://github.com/adiwajshing/Queenfisher) + +## Install + +`npm i github:adiwajshing/keyed-db` + +## Running Tests + +`npm test` + +## Functions + +``` ts + +db = new KeyedDB (t => t.uniqueNumberKeyProperty, t => t.optionalUniqueIDProperty) +// compare with a custom function +db = new KeyedDB ({ + key: t => t.someProperty, + compare: (t1, t2) => someComputation(t1, t2) // return -1 if t1 < t2, 0 if t1=t2 & 1 if t1 > t2 +}, t => t.optionalUniqueIDProperty) + +db.insert (value) // insert value in DB +db.upsert (value) // upserts value +db.insertIfAbsent (value) // only inserts if not already present in DB +db.delete (value) // delete value +db.deleteById (value.optionalUniqueIDProperty) // delete value by referencing the ID +// update the key of a value, +// will automatically place object after key change +db.updateKey (value, value => value.uniqueKeyProperty = newValue) +db.paginated (someCursor, 20) // get X results after the given cursor (null for the first X results) + +``` + +## Usage + +``` ts +import KeyedDB from '@adiwajshing/keyed-db' + +// Let's use the db to sort & maintain a list of chats +// Chats must be accessed quickly via the chatID (the person you're chatting with) +// Chats must be sorted by recency +type Chat = { + timestamp: Date + chatID: string +} + +// first argument -- sorting property, second argument -- ID property +const db = new KeyedDB(value => value.timestamp.getTime()*-1, value => value.chatID) + +for (let i = 0; i < 1000;i++) { + // insert data + db.insert ( + { + timestamp: new Date( new Date().getTime() - Math.random()*10000 ), + chatID: `person ${i}` + } + ) +} +console.log (db.all()) // return internal sorted array +console.log (db.paginated(null, 20)) // return first 20 chats +console.log (db.paginated(null, 20, null, 'before')) // return last 20 chats +console.log (db.paginated(null, 20, chat => chat.chatID.includes('something'))) // return first 20 chats where the chatID contains 'something' + +const someDate = new Date().getTime() +const cursorPaginated = db.paginated(someDate, 20) +console.log (cursorPaginated) // return 20 chats after the specified date + +db.delete (cursorPaginated[0]) // delete paginated chats + +// update chat timestamp +db.updateKey(cursorPaginated[1], value => value.timestamp = new Date().getTime()) + +``` + +## Time Complexity + +| Operation | Time Complexity | +|----------------|-----------------| +| db.insert() | O(logN) | +| db.delete() | O(logN) | +| db.get() | O(1) | +| db.updateKey() | O(logN) | \ No newline at end of file diff --git a/node_modules/@adiwajshing/keyed-db/package.json b/node_modules/@adiwajshing/keyed-db/package.json new file mode 100644 index 0000000..82a2225 --- /dev/null +++ b/node_modules/@adiwajshing/keyed-db/package.json @@ -0,0 +1,34 @@ +{ + "name": "@adiwajshing/keyed-db", + "version": "0.2.4", + "description": "Lightweight library to store an in-memory DB", + "homepage": "https://github.com/adiwajshing/keyed-db", + "main": "lib/KeyedDB.js", + "types": "lib/KeyedDB.d.ts", + "keywords": [ + "db", + "key" + ], + "scripts": { + "prepack": "npm run build", + "test": "mocha --timeout 60000 -r ts-node/register src/Tests.ts", + "build": "tsc" + }, + "author": "Adhiraj Singh", + "license": "MIT", + "repository": { + "url": "git@github.com:adiwajshing/keyed-db.git" + }, + "files": [ + "lib/*" + ], + "dependencies": {}, + "devDependencies": { + "@types/mocha": "5.2.7", + "@types/node": "^14.0.14", + "assert": "^2.0.0", + "mocha": "^8.0.1", + "ts-node-dev": "^1.0.0-pre.61", + "typescript": "^4.0.0" + } +}