Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A more practical alternative to localStorage. db64 supports all major browsers.
E.g.
import db64 from './db64.js'
try {
// First create a database with stores
await db64.create('Games', ['Super Nintendo', 'Gameboy'])
// Assing a variable for modifying a store
const snes = db64.use('Games', 'Super Nintendo')
// Set multiple entries into Super Nintendo
await snes.setEntries({ adventure: 'Mario World', rpg: 'Zelda', fighting: 'Street Fighter II' })
// Get multiple entries from Super Nintendo
await snes.getEntries(['adventure', 'fighting']) // { adventure: 'Mario Wrold', fighting: 'Street Fighter II' }
// Delete an existing db
await db64.delete('Games')
...
Launch an example using npm run d
then navigate to ./exmaples
Just give me the builds
git clone git@github.com:julienetie/db64.git
cd db64 && npm i
npm run prepublishOnly
Install
npm i db64
Import
import db64 from 'db64.js' // ES (native)
// or
import db64 from 'db64' // ES
// or
const db64 = require('db64') // CommonJS
Create a database with stores (string, array)
await db64.create('game-consoles', ['n64', 'ps5', 'dreamcast', 'xbox-360'])
Use a store (string, string)
const n64 = db64.use('game-consoles', 'n64')
Set an entry (IDB type, IDB type) See structured clone algorithm for supported types
await n64.set(5, 'Super Mario 64')
Set multiple entries (object | array)
await n64.setEntries({fps: 'GoldenEye 007', space: 'Star Fox 64', adventure: 'Banjo-Kazooie'})
await n64.setEntries(['Wave Race 64', 'The Legend of Zelda'])
Get an entry (IDB type)
const fps = await n64.get('fps') // GoldenEye 007
Get multiple entries (object | array)
const rareware = await n64.getEntries(['fps', 'adventure', 5]) // {fps: 'GoldenEye 007', adventure: 'Banjo-Kazooie', 0: 'Super Mario 64'}
Delete an entry (IDB type | array)
await n64.delete(1) // Deletes 'The Legend of Zelda'
Delete multiple entries
await n64.delete(['adventure', 0]) // Deletes 'Banjo-Kazooie' and 'Super Mario 64'
Clear a store (string, string)
await db64.clear('game-consoles', 'n64') // All data in n64 is deleted
Delete a DB (string)
await db64.delete('game-consoles') // game-consoles is deleted
We are avoiding versioning to keep your life simple. Deleting an existing object stores in IndexedDB triggers a version change. (Whilst compaction may optimise, it doesn't ensure the removal of unwanted data)
Here's the db64 workflow:
Initialise by creating a DB with stores or multiple DBs with stores.
Use a DB.
Set, get and clear data.
Manage the lifecycle of DB deletion and re-creation:
It's important to consider step 4, if not you may leave users stuck because everything will look fine on your computer. Step 4 isn't specific to IndexedDB, it mostly applies to localStorage. It's the same for all persistent storage on all platforms. Your application is at risk of breaking if you decide to change the persistent data structure or add to the structure in the future without preemptively managing common user cases.
// An exaustive list for handeling errors for db64:
switch (e.name) {
case 'NotFoundError':
// The operation failed because the requested database object could not be found.
case 'Db64MissingStore':
/*
An anticipated NotFoundError. Manage both cases togeather.
You will likely need to re-create your dateabase here with necessary stores
and re-populate with existing data if necessary. */
break
case 'AbortError':
// A request was aborted.
break
case 'SecurityError':
// Handel security error
break
case 'DataError':
// Data provided to an operation does not meet requirements.
break
case 'TransactionInactiveError':
// A request was placed against a transaction which is currently not active, or which is finished.
break
case 'InvalidStateError':
// The object is in an invalid state.
break
case 'ConstraintError':
// A mutation operation in the transaction failed because a constraint was not satisfied.
break
case 'SyntaxError':
// The keyPath argument contains an invalid key path.
break
case 'QuotaExceededError':
// The operation failed because there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database.
break
case 'ReadOnlyError':
// The mutating operation was attempted in a read-only transaction.
break
case 'UnknownError':
// The operation failed for reasons unrelated to the database itself and not covered by any other errors.
break
}
If you do require versioning consider using idb. If you're not building a progressive web app (PWA) you probably don't need versioning.
Don't hesitate just contribute, it's a tiny library we will figure it out.
If you want to edit ./README.md
edit ./src/_readme.md
which will update ./README.md
when node create-distribution.js
is called.
This is to keep the minified size accurate.
MIT © Julien Etienne 2023
FAQs
A Practical IndexedDB API
The npm package db64 receives a total of 50 weekly downloads. As such, db64 popularity was classified as not popular.
We found that db64 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.