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

@rocketbean/data-repo

v1.2.1

Published

on-File data repository, file caching, out of process memory module for nodejs

Downloads

1

Readme

data-repo

Github: https://github.com/rocketbean/data-repo/releases

npm: https://www.npmjs.com/package/@rocketbean/data-repo

data-repo is a file-based data storage, which dev's can do basic CRUD operation to a model. this lib might be useful for file caching, or tracking processes outside the node process env, e.g. on managing clusters.

start by creating an instance:

import  DataRepo, { Model } from  "@rocketbean/data-repo";
import path from "path"

var repo = await DataRepo.init({
  storage: path.join(process.cwd(), "./storage2"),
  driver: "file",
  name: "box",
  hashfrom: "boxed",
  options: {
    writeAs: "hash",
    passphrase: "context",
    reset: false,
  },
});

initialization will require parameters:

parameters prefixed with "*" is a default setting.

  • storage [string] - directory where repo and accommodated files will be saved
  • name [string] - a name for the container, this property have no effect to new or existing repo.
  • hashfrom [string] - this hash string will be used for naming containers and repo file, chaging this property after initialization will cause repo to be re-initialized and into a new set of instance.
  • driver [string]["file"] - a storage driver option. As of this release, "file" is the only available driver.
  • options [object] - associated options, to change the behavior of the repo.
    • options[writeAs] [string] - option on how the contents will be saved.
    •  *"readable" - contents will be readable as it will be parsed as JSON string
    •  "hash" - the writer will encrypt contents, with a passphrase.
    • options[passphrase] [string] - passphrase to use with the encoding
    • options[reset] [string|bool ] - passphrase to use with the encoding
    •  *false - the storage will not be refreshed or deleted.
    •  "invoke" - the storage will be reset everytime the repo is invoked.

creating a Model var repo = await DataRepo.init({ storage: path.join(process.cwd(), "./storage2"), driver: "file", name: "box", hashfrom: "boxed", options: { writeAs: "hash", passphrase: "context", reset: false, }, });

let clusterModel = await repo.createModel("cluster",
{
	session: {
		type:  "",
		unique:  true,
	},
	text: {
		type:  "",
	},
	threads: {
		type: [],
		required:  true,
	},
	logs: {
		type: [],
	},
},
{
	max:  3, // do not declare this option to set the max record to unlimited.
	strict:  true,  // set to false to allow extra property.
});

Model parameters:

  • name [string]- Model name
  • Schema [object]- a basic schema:
    • Schema[type][any] - DataType for this declaration,
    • Schema[required][bool] - marking this propeprty as required.
    • Schema[unique][bool] - marking this propeprty as required && unique.
  • Options [object] - additional options for the model:
    • Options [max] [number] - if this option is set, the records will be limited to the declared value.
    • Options [strict] [bool] - if enabled, properties that is undeclared in the schema will not be allowed.

Model CRUD Operations:

async Model.create({}) - creating a record Parameter can be Array[] or Object{}

// creating a single record
await clusterModel.create({
	session:  uuidv4(),
	threads: [],
	logs: {
		log: {
			message:  "initialized",
		},
	},
	text:  "init",
});

// Or creating multiple record
await clusterModel.create([
	{
		session:  uuidv4(),
		threads: [],
		logs: {
			log: {
				message:  "started",
			},
		},
		text:  "start",
	},
	{
		session:  uuidv4(),
		threads: [],
		logs: {
			log: {
				message:  "running",
			},
		},
		text:  "processing",
	}
]);

async Model.get(< identifier>) - getting a record

  • < identifier>[as string] - if string is declared, items will be matched with the "_id" property that is automatically created and is unique. if matched, it will always return as a single object.

  • < identifier>["*"] - returns all the records.

  • < identifier>[as object] - if type of [object] is passed, it will try to match keys and values to the record, it may return as a single object or an array for multiple results.

// fetching record using string
// this is an example value for ["\_id"]
await clusterModel.get('4d4b2c18-bc88-4c50-a599-7d0a58931634')
// fetching all records
await clusterModel.get('*')
// Or using an object
await clusterModel.get({ text:  "test3" })

async Model.update(< identifier>, < data>) - updating a record

updating using a model, if the identifier results to more than 1 record, all results will be updated

await clusterModel.update({ text:  "test" }, { text:  "test3" })

Or updating using a schema, will only update the specific record

await clust.update({ text:  "test3" })

async Model.delete(< identifier>, < data>) - deleting a record

deleting using a model, if the identifier results to more than 1 record, all results will be deleted

await clusterModel.delete({ text:  "test" })

Or deleting using a schema, will only delete the specific record

await clust.delete({ text:  "test3" })