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

iter-db

v0.0.5

Published

Database, based on singly linked list and iterators

Downloads

6

Readme

iter-db

Database, based on singly linked list and iterators Contains:

  • im-memory database class with iterators support
  • iterator for iterating elements one-by-one
  • class of shell, thats implements periodical autosave data as json, loading from file and messaging

see also packages:

  • list-db-server //implementation of server, thats runs from command line
  • list-db-connector //implementation of connector with functional api

IterDb

It is in-memory database thats may contents elems and iterator

import { IterDb } form "list-db"
//Example of usage
const db: IterDb<any> = (new IterDb()) //empty db
const id = db.push(12) //id = 0 - index of new elem
db.push("John Konor") //id = 1 ...
db.push([false, true, false])
db.push({ i: 43, val: { name: "\"[Jona<ta>n\"]", vals: [12, 13] } })
db.push(999) //id = 4

const json = db.serializeToJson() //serialization of db content
db.parseFromJson(json) //deserialization and reinitialization

const iterId = db.regIter() //register new iterator from start, and gets it's id
let iter = db.getIter(iterId) //get iter by ID
iter.read() // = 12 . Iterator now on 0-th elem and its readed
iter.next().read() // = "John Konnor" . Iterator now on 1-st element and its readed
Array.isArray(iter.next().read()) // true. Iterator now on 2-nd  element and its readed
let iter = db.getIter(iterId) // get iterator again. It has save its position
iter.next().next().read() // = 999 . Iterator now on 4-th  element and its readed

IterDbShell

class of shell, thats implements periodical autosave data as json, loading from file and messaging Use it as template for server-making based on db

import { IterDb, IterDbShell } form "list-db"
import * as path from "path"
import * as fs from "fs"

const db = new IterDb()
const filepath = path
    .resolve((module as unknown as { path: string }).path, "..", "..", "test.json")

const shell = new IterDbShell(db, {
    token: "7gx1827b", //Auth token
    filepath: filepath, //file to load and store data
    unref: true, //is unref imterval-timer thats rewrite file 
    //(without unref script will not stop running)
    fileDelay: 1000 //delay of rewriting file in milliseconds
})

//message handling. See full list of messages in next paragraph
const msg = new IterDbMessage({
    authToken: "7gx1827b",
    set: { v: 216318729 }
})
shell.handleMessage(msg)
const response = msg.getResponse() //{id: 0} - id of new elem

All request message types

//file IterDb.listReq
//also contains superstruct declaration
type ReqIterBody = { //request data
    authToken: string;
    req: {
        iter: string;
        req: {
            batchNew: number;
        } | {
            oneNew: true;
        } | {
            again: true;
        };
    };
} | { //set new event
    authToken: string;
    set?: any;
} | { //request of new iterator
    authToken: string;
    reg: true;
}

All response message types

//file IterDb.listResp
//also contains superstruct declaration
type IterResp = { //error responses
    error: "Invalid auth data" | "Iter is not exists" | "Invalid format of request" | "Unexcepted error";
    details?: any;
} | { //response on iter request
    iter: string;
} | { //response on set new event
    id: number;
} | { //response on batch request vals
    vals: {
        id: number;
        val?: any;
    }[];
} | { //response on request one item 
    //(if requested new item and all items are readed, will returns null)
    val: {
        id: number,
        val: any
    } | null
}

Index file overview

export { arr, IterDb as ListDb } from "./IterDb"
export { IterDbMessage as ListDbMessage } from "./IterDbMessage"
export { IterIter as ListIter } from "./IterIter"
export { IterDbShellConfig, IterDbShell } from "./IterDbShell"
export * as iterReq from "./IterReq"
export * as iterResp from "./IterResp"

License

MIT

Author

Anatoly Starodubtsev [email protected]