npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quantum-sequence

v0.10.1

Published

Map and Set implementations which uses tachyon-drive as storage backend

Downloads

106

Readme

quantum-sequence

quantum-sequence is a package that provides Map and Set implementations which use tachyon-drive drivers as a storage backend. This allows for fast and efficient storage and retrieval of key-value pairs and sets of data.

Map and Set implementations which uses tachyon-drive drivers as storage backend

Installation

To install quantum-sequence, run:

npm install quantum-sequence

Usage

To use quantum-sequence, you can create a new QuantumMap, QuantumKeySet or QuantumSet instance with a tachyon-drive storage driver, and then use the provided methods to interact with the data.

import {QuantumMap} from 'quantum-sequence';

// Create a new TachyonDrive instance and serializer setup
const mapDataSchema = zod.map(zod.string(), zod.number());
const bufferSerializer: IPersistSerializer<Map<string, Data>, Buffer> = {
	serialize: (data: Map<string, number>) => Buffer.from(JSON.stringify(Array.from(data))),
	deserialize: (buffer: Buffer) => new Map(JSON.parse(buffer.toString())),
	validator: (data: Map<string, number>) => mapDataSchema.safeParse(data).success,
};
const driver = new MemoryStorageDriver('QuantumMapDriver', bufferSerializer, null); // MemoryStorageDriver as example driver

// Create a new QuantumMap instance with a tachyon-drive storage driver
// ⚠️Warning⚠️: if using non-primitive types as keys, you must get actual value first from keys() method before call "delete" or "has" methods as hydrate will replace the object reference (manually or via updates) and the reference will be lost.
const map = new QuantumMap<string, number>(driver);

await map.init(); // hydrates last data from store

// Set a key-value pair in the map
await map.set('foo', 42);

// Get the value for a key
await map.get('foo'); // 42

// Check if a key exists in the map
await map.has('foo'); // true

// Delete a key-value pair from the map
await map.delete('foo');

// Get the size of the map
await map.size(); // 0
import {QuantumKeySet} from 'quantum-sequence';

// Create a new TachyonDrive instance and serializer setup
const setDataSchema = zod.set(zod.object({key: zod.string(), value: zod.string()}));
const bufferSerializer: IPersistSerializer<Set<Data>, Buffer> = {
	serialize: (data: Set<Data>) => Buffer.from(JSON.stringify(Array.from(data))),
	deserialize: (buffer: Buffer) => new Set(zod.array(dataSchema).parse(JSON.parse(buffer.toString()))),
	validator: (data: Set<Data>) => setDataSchema.safeParse(data).success,
};
const driver = new MemoryStorageDriver('QuantumKeySet', bufferSerializer, null); // MemoryStorageDriver as example driver

// Create a new QuantumKeySet instance with a tachyon-drive storage driver
type Data = {key: string; value: string};
const set = new QuantumKeySet<Data, 'key'>('key', driver);

await set.init(); // hydrates last data from store

// Add a new item to the set
await set.set('foo', {key: 'foo', value: 'bar'});

// Get an item from the set
await set.get('foo'); // {key: 'foo', value: 'bar'}

// Delete an item from the set
await set.delete('foo');

// Get the size of the set
await set.size(); // 0
import {QuantumSet} from 'quantum-sequence';

// Create a new TachyonDrive instance and serializer setup
const setDataSchema = zod.set(zod.string());
const bufferSerializer: IPersistSerializer<Set<Data>, Buffer> = {
	name: 'BufferSerializer',
	serialize: (data: Set<Data>) => Buffer.from(JSON.stringify(Array.from(data))),
	deserialize: (buffer: Buffer) => new Set(zod.array(dataSchema).parse(JSON.parse(buffer.toString()))),
	validator: (data: Set<Data>) => setDataSchema.safeParse(data).success,
};
const driver = new MemoryStorageDriver('QuantumSetDriver', bufferSerializer, null); // MemoryStorageDriver as example driver

// Create a new QuantumSet instance with a tachyon-drive storage driver
// ⚠️Warning⚠️: if using non-primitive types, you must get actual value first from values() method before call "delete" or "has" methods as hydrate will replace the object reference (manually or via updates) and the reference will be lost.
const set = new QuantumSet<string>(driver);

await set.init(); // hydrates last data from store

// Add a new item to the set
await set.add('foo');

// Check if an item exists in the set
await set.has('foo'); // true

// Delete an item from the set
await set.delete('foo');

// Get the size of the set
await set.size(); // 0