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

@jimpick/use-fireproof

v0.19.118-jim2

Published

Fireproof live database, JavaScript API and React hooks

Downloads

115

Readme

Fireproof realtime database

No setup: write features first, access your data anywhere

Add collaboration to any app with Fireproof. Access data from JavaScript servers and edge functions. Use live queries to update your UI automatically when the database changes. Connect realtime sync and those changes will sync between browsers and backend functions. Apps built this way are multi-player by default.

JavaScript quick start

The document database API will feel familiar. Queries use dynamic indexes, and the database can refresh your UI, as seen in the db.subscribe call below, as well as the React liveQuery hook.

import { fireproof } from "@jimpick/fireproof-core";

const db = fireproof("music-app");

await db.put({ _id: "beyonce", name: "Beyoncé", hitSingles: 29 });

db.subscribe(async () => {
  const topArtists = await db.query("hitSingles", { range: [30, Infinity] });
  // redraw the UI with the new topArtists
});

const beyonceDoc = await db.get("beyonce");
beyonceDoc.hitSingles += 1;
await db.put(beyonceDoc);

Jump to the docs site for JavaScript API basics.

Live data hooks for React

Fireproof React hooks for live data avoid boilerplate and make building collaborative apps a breeze.

import { useLiveQuery, useDocument } from 'use-fireproof'

function App() {
  const completedTodos = useLiveQuery('completed', { limit: 10 })
  const [newTodo, setNewTodoData, saveNewTodo] = useDocument({type: 'todo', text: '', completed: false, created: Date.now() })

Read the step-by-step React tutorial to get started.

Why choose Fireproof

Compared to other embedded databases, Fireproof:

  • is network aware, encrypted, and multi-writer safe
  • is designed for real-time collaboration with CRDTs
  • offers cryptographic causal integrity for all operations
  • is built for the web, with a small package size and no wasm

Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access data anywhere.

Get the latest roadmap updates on our blog or join our Discord to collaborate. Read the docs to learn more about the database architecture.

Use cases

Fireproof allows web developers to build full-stack apps. It's especially useful for:

  • Rapid prototyping
  • AI copilot safety
  • Collaborative editing
  • Personalization and configuration
  • Offline and local-first apps

With Fireproof, you build first and sync via your cloud of choice when you are ready, so it's as easy to add to existing apps as it is to build something new. Drop Fireproof in your page with a script tag and start sharing interactive data.

Fireproof is a great fit for code sandboxes and online IDEs, as you can get started without any configuration. This also makes it easy for AI to write Fireproof apps.

Install

Get started with the React hooks:

npm install use-fireproof

or install the database in any JavaScript environment:

npm install @jimpick/fireproof-core

The default build is optimized for browsers, to load the node build add /node:

import { fireproof } from "@jimpick/fireproof-core/node";

Add the database to any web page via HTML script tag (global is Fireproof):

<script src="https://cdn.jsdelivr.net/npm/@jimpick/fireproof-core/dist/browser/fireproof.global.js"></script>

Go ahead and write features, then connect to any cloud backend later.

Debug

to control the log output you an either use the FP_DEBUG environment variable or set the debug level in your code:

FP_DEBUG='*' node myapp.js
logger.setDebug(...moduleNameList or '*')

if you are in the browser you can use the following code to set the debug level:

this[Symbol.for("FP_ENV")].set("FP_DEBUG", "*");
// vitest pass env
globalThis[Symbol.for("FP_PRESET_ENV")] = {
  FP_DEBUG: "*",
};

Log Formatting

It's possible to change the logformat by setting FP_FORMAT to:

  • jsonice makes the log output in multiline json
  • yaml makes the log output in yaml
  • json makes the log output in singleline json (default)

KeyBag

If you add extractKey with the value _deprecated_internal_api to the FP_STORAGE_URL url you can bypass the security check to extract the key material. This is the default configuration, but there is a warning emitted if you use this feature, and roadmap plans for more secure key management.

Deno

Fireproof is compatible with Deno. To runit in Deno you need to add the following flags:

Currently the tests are not run with deno -- TODO

It might be that using our provided deno.json is somekind of odd --- TODO is to add fireproof to jsr and deno.land

deno run --config node_modules/@jimpick/fireproof-core/deno.json --allow-read --allow-write --allow-env --unstable-sloppy-imports ./node-test.ts

Thanks 🙏

Fireproof is a synthesis of work done by people in the web community over the years. I couldn't even begin to name all the folks who made pivotal contributions. Without npm, React, and VS Code all this would have taken so much longer. Thanks to everyone who supported me getting into database development via Apache CouchDB, one of the original document databases. The distinguishing work on immutable data-structures comes from the years of consideration IPFS, IPLD, and the Filecoin APIs have enjoyed.

Thanks to Alan Shaw and Mikeal Rogers without whom this project would have never got started. The core Merkle hash-tree clock is based on Alan's Pail, and you can see the repository history goes all the way back to work begun as a branch of that repo. Mikeal wrote the prolly trees implementation.

Contributing

We love contributions. Feel free to join in the conversation on Discord. All welcome.

License

Dual-licensed under MIT or Apache 2.0