@fireproof/core 0.6.0 β†’ 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +90 -83
  2. package/package.json +2 -4
package/README.md CHANGED
@@ -1,81 +1,86 @@
1
- # πŸ”₯ Fireproof
2
-
3
- Fireproof is a realtime database for today's interactive applications. It uses immutable data and distributed protocols
4
- to offer a new kind of database that:
1
+ <p align="center" >
2
+ <a href="https://fireproof.storage/">
3
+ <img src="https://fireproof.storage/static/img/logo-animated-black.svg" alt="Fireproof logo" width="200">
4
+ </a>
5
+ </p>
6
+ <h3 align="center">
7
+ Cloudless database for React apps
8
+ </h3>
9
+
10
+ <p align="center">
11
+ <a href="https://bundlephobia.com/package/@fireproof/core" rel="nofollow">
12
+ <img src="https://deno.bundlejs.com/?q=@fireproof/core&treeshake=[*+as+fireproofCore]&badge" alt="Bundle Size" style="max-width: 100%;">
13
+ </a>
14
+ <a href="https://github.com/jchris/fireproof/actions/workflows/test.yml">
15
+ <img src="https://github.com/jchris/fireproof/actions/workflows/test.yml/badge.svg" alt="Test" style="max-width: 100%;">
16
+ </a>
17
+ <a href="https://standardjs.com" rel="nofollow">
18
+ <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide" style="max-width: 100%;">
19
+ </a>
20
+ <a href="https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md">
21
+ <img src="https://shields.io/badge/react-black?logo=react&style=for-the-badge%22" alt="React" style="max-width: 100%;">
22
+ </a>
23
+ </p>
24
+
25
+ Fireproof uses immutable data and distributed protocols to offer a new kind of database that:
5
26
  - can be embedded in any page or app, with a flexible data ownership model
6
27
  - can be hosted on any cloud
7
28
  - uses cryptographically verifiable protocols (what plants crave)
8
29
 
9
- Learn more about the [concepts and architecture behind Fireproof](https://fireproof.storage/documentation/how-the-database-engine-works/), or jump to the [quick start](#quick-start) for React and server-side examples.
10
-
11
- ## Quick Start
30
+ Fireproof is optimized to make [building React apps](https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md) fast and fun, with reliable results. Suitable for mission-critical data workloads like [LLM orchestration](https://fireproof.storage/posts/why-proofs-matter-for-ai/), supply-chain provenance, and field use of auditable data, [ Fireproof is also great](https://fireproof.storage/posts/great-opportunites-to-use-fireproof/) for social media, collaborative world-building, and rapidly implementing executive decision support tools that can stand up to blockchain levels of scrutiny.
12
31
 
13
- Look in the `examples/` directory for projects using the database, or see [examples on CodePen](https://codepen.io/jchrisa/pen/GRYJJEM). If you are adding Fireproof to an existing page, just install it and try some operations.
32
+ With Fireproof, you **build first** and connect it to your cloud of choice when you are ready, so there's nothing holding you back from adding it to your existing apps, or [writing something new.](https://hackernoon.com/get-chatgpt-to-focus-on-coding-on-the-right-apis-with-gptdoc-strings)
14
33
 
15
- ```sh
16
- npm install @fireproof/core
17
- ```
18
34
 
19
- In your `app.js` or `app.tsx` file:
35
+ ## React Quick Start
36
+ *One-line preview:* in the context of a React component render, `useLiveQuery` will automatically refresh (even on changes by remote collaborators):
20
37
 
21
38
  ```js
22
- import { Fireproof } from '@fireproof/core'
23
- const fireproof = Fireproof.storage("my-db")
24
- const ok = await fireproof.put({ hello: 'world' })
25
- const doc = await fireproof.get(ok.id)
39
+ const completedTodos = useLiveQuery((doc) => doc.completed, { key: true })
26
40
  ```
41
+ This is the README for the core database technology. [The `useFireproof` hook documentation has features and a getting started guide](https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md), like `useLiveDocument` and database setup helpers. Don't forget to star 🌟 this repo on the way over.
27
42
 
28
- 🀫 I like to drop a `window.fireproof = fireproof` in there as a development aid.
29
-
30
- ### ChatGPT Quick Start
43
+ ## AI Assistant Quick Start
31
44
 
32
- Paste this to GPT 4 or 3.5 to enable it to write apps using Fireproof:
45
+ Because Fireproof is designed around the mantra of build-first, it's ideal for AI-assisted app development as you can get an app up and running before even considering the cloud. If you are using GPT-3.5, GPT-4, or Bard, you can [easily enable the AI to write React apps using Fireproof](https://hackernoon.com/get-chatgpt-to-focus-on-coding-on-the-right-apis-with-gptdoc-strings). Paste this line of code into your prompt, along with a detailed description of the app to build:
33
46
 
34
47
  ```
35
- Fireproof/API/Usage: import { Fireproof, Listener, Index } from '@fireproof/core'; const db = fireproof.storage('app-db-name'); const ok = await db.put({ any: 'json' }); const doc = await db.get(ok.id); await db.del(doc._id); const all = await db.allDocuments(); all.rows.map(({key, value}) => value); const listener = new Listener(db); listener.on('*', updateReactStateFn); const index = new Index(db, (doc, map) => map(doc.any, {custom: Object.keys(doc)})); const result = await index.query({range : ['a', 'z']}); result.rows.map(({ key }) => key);
48
+ Fireproof/React/Usage: import { useFireproof } from '@fireproof/react'; function App() { const { useLiveQuery, useLiveDocument, database } = useFireproof(); const result = useLiveQuery(doc => doc.word, { limit: 10 }); const [{ count }, saveCountDocument] = useLiveDocument({_id: 'count', count: 0}); return (<><p>{count} changes</p><input type='text' onChange={() => saveCountDocument({count: count + 1})} onSubmit={e => database.put({word: e.target.value})} /><ul>{result.map(row => (<li key={row.id}>{row.key}</li>))}</ul></>)}
36
49
  ```
37
50
 
38
- In the same prompt, describe the app you want to build. Here are some examples that worked for us:
51
+ Here are some examples that worked for us:
39
52
 
40
- * Create a react app using Fireproof for tracking party invites. It should have a text input that creates a new document with the guest name, and an Index that lists all guests in a &lt;ul&gt;. ([Running copy here.](https://codepen.io/jchrisa/pen/zYmogWO))
41
- * Build a React app that allows you to create profiles for dogs, and browse to each profile. It should be optimized for mobile. Use Tailwind.
42
- * Build a photo grid app that with drag and drop ordering that references photos by url. Use tailwind and render all photos as squares. Keep grid arrangement in fireproof with one document for each gallery, that is: 4-16 photos arranged into a layout.
43
- * Build an app using React, Fireproof, MagicLink, and Tailwind that allows user to create one-question multiple choice polls and collect the answers.
44
- * Create a note taking app using React, Tailwind, and Fireproof that stores each note as a large text string in a Fireproof document, and uses an Index to split the text of the documents into tokens for full text search. The app has an input field to search the documents via an index query.
53
+ * Create a React app using Fireproof for tracking party invites. It should have a text input that creates a new document with the guest name, and an Index that lists all guests in a &lt;ul&gt;. ([Running copy here.](https://codepen.io/jchrisa/pen/zYmogWO))
54
+ * Build a photo grid app with drag-and-drop ordering that references photos by URL. Use tailwind and render all photos as squares. Keep grid arrangement in Fireproof with one document for each gallery, that is 4-16 photos arranged into a layout.
55
+ * Build a React app that allows users to create a list of their favorite movies, and then share that list with friends. Use Fireproof to store the list of movies, and to store the list of friends. Use MagicLink to authenticate users. Use Tailwind to make it look good.
56
+
57
+ You can enhance the AI's understanding by adding the core APIs. Use this if you aren't using React, or you are adding additional features to your app and you need to go deeper than the React hooks.
58
+
59
+ ```
60
+ Fireproof/API/Usage: import { Fireproof, Index } from '@fireproof/core'; const db = fireproof.storage('app-db-name'); const ok = await db.put({ any: 'json' }); const doc = await db.get(ok.id); await db.del(doc._id); const all = await db.allDocuments(); all.rows.map(({key, value}) => value); useEffect(()=> db.subscribe(updateReactStateFn), []); const index = new Index(db, (doc, map) => map(doc.any, {custom: Object.keys(doc)})); const result = await index.query({range : ['a', 'z']}); result.rows.map(({ key }) => key);
61
+ ```
45
62
 
46
63
  Please share your successes with us here or on [Twitter.](https://twitter.com/FireproofStorge)
47
64
 
48
- ### Status
65
+ # Database Features
49
66
 
50
- Fireproof is alpha software, ready for you to evaluate for your future applications. For now, [check out our React TodoMVC implementation running in browser-local mode.](https://main--lucky-naiad-5aa507.netlify.app/) It demonstrates document persistence, index queries, and event subscriptions, and uses the [`useFireproof()` React hook.](https://github.com/fireproof-storage/fireproof/blob/main/packages/fireproof/hooks/use-fireproof.tsx)
67
+ The core features of the database are available on any platform in a compact JavaScript package and a foundational cloud storage service.
51
68
 
52
- [![Test](https://github.com/jchris/fireproof/actions/workflows/test.yml/badge.svg)](https://github.com/jchris/fireproof/actions/workflows/test.yml)
53
- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
69
+ * **Local** - always encrypted, data automatically collocates with your users, for faster and more reliable apps.
70
+ * **Immutable** - [cutting-edge git-like data structures](https://fireproof.storage/posts/from-mlops-to-point-of-sale:-merkle-proofs-and-data-locality/) allow Fireproof to combine cryptographic verification with append-only storage, automatically converging on a verified state.
71
+ * **Distributed** - immutable data can be stored on the Fireproof service, your cloud, and the distributed IPFS network, so it is always available.
72
+ * **Realtime** - use the Fireproof service or APIs like WebRTC, libp2p, PartyKit, or SocketSupply to push changes to connected peers. React hook APIs like `useLiveQuery` are designed for automatic UI refresh.
73
+ * **Verifiable** - [cryptographic proofs make results verifiable](https://fireproof.storage/posts/why-proofs-matter-for-ai/), sync fast, and storage cheap.
74
+ * **[Cloudless](https://www.oreilly.com/radar/the-paradigm-shift-to-cloudless-computing/)** - data can be hosted on any cloud, on the IPFS network, or both. UCAN integration allows for flexible data ownership models.
54
75
 
55
- ## Usage
56
76
 
57
- ```js
58
- import { Fireproof } from 'fireproof';
59
-
60
- async function main() {
61
- const database = Fireproof.storage('my-db');
62
- const ok = await database.put({
63
- name: 'alice',
64
- age: 42
65
- });
66
-
67
- const doc = await database.get(ok.id);
68
- console.log(doc.name); // 'alice'
69
- }
70
-
71
- main();
72
- ```
77
+ Learn more about the [architecture](https://fireproof.storage/documentation/how-the-database-engine-works/) behind Fireproof, or see [examples on CodePen](https://codepen.io/jchrisa/pen/GRYJJEM).
73
78
 
74
- ## Features
79
+ ## API Usage
75
80
 
76
- ### Document Store
81
+ ### Encrypted Documents
77
82
 
78
- A simple put, get, and delete interface for keeping track of all your JSON documents. Once your data is in Fireproof you can access it from any app or website. Fireproof document store uses MVCC versioning and Merkle clocks so you can always recover the version you are looking for.
83
+ A simple put, get and delete interface for keeping track of all your JSON documents. Once your data is in Fireproof you can access it from any app or website. Fireproof document store uses MVCC versioning and Merkle clocks so you can always recover the version you are looking for.
79
84
 
80
85
  ```js
81
86
  const { id, ref } = await database.put({
@@ -83,7 +88,9 @@ const { id, ref } = await database.put({
83
88
  name: 'AndrΓ©',
84
89
  age: 47
85
90
  });
86
- const doc = await database.get('three-thousand', {mvcc : true}) // mvcc is optional
91
+
92
+ // mvcc is optional
93
+ const doc = await database.get('three-thousand', { mvcc: true })
87
94
  // {
88
95
  // _id : 'three-thousand'
89
96
  // _clock : CID(bafy84...agfw7)
@@ -92,14 +99,25 @@ const doc = await database.get('three-thousand', {mvcc : true}) // mvcc is optio
92
99
  // }
93
100
  ```
94
101
 
95
- The `_clock` allows you to query a stable snapshot of that version of the database. Fireproof uses immutable data structures under the hood, so you can always rollback to old data. Files can be embedded anywhere in your document using IPFS links like `{"/":"bafybeih3e3zdiehbqfpxzpppxrb6kaaw4xkbqzyr2f5pwr5refq2te2ape"}`, with API sugar coming soon.
102
+ As you can see in the return value above, the `_clock` allows you to query a stable snapshot of that version of the database. Fireproof uses immutable data structures under the hood, so you can always rollback to old data. Files can be embedded anywhere in your document using IPFS links like `{"/": "bafybeih3e3zdiehbqfpxzpppxrb6kaaw4xkbqzyr2f5pwr5refq2te2ape"}`, with API sugar coming soon.
103
+
104
+ ### Live Query
96
105
 
97
- ### Flexible Indexes
106
+ Fireproof provides a live query interface that allows you to subscribe to changes in your data. This means that your UI will automatically update whenever there is a change to your data. See the [useFireproof React hooks documentation](https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md) for the easiest way to use this feature.
98
107
 
99
- Fireproof indexes are defined by custom JavaScript functions that you write, allowing you to easily index and search your data in the way that works best for your application. Easily handle data variety and schema drift by normalizing any data to the desired index.
108
+ Fireproof indexes are defined by custom JavaScript functions that you write, allowing you to easily index and search your data in the way that works best for your application. Easily handle data variety and schema drift by normalizing any data to the desired index. The index function defines the sort order. You can use the index to query for a range of values or to find exact matches. This baseline functionality is all you need to build many kinds of complex queries.
100
109
 
101
110
  ```js
102
- const index = new Index(database, function (doc, map) {
111
+ const index = new Index(database, "byAge", (doc) => doc.age)
112
+ const { rows, proof } = await index.query({ range: [40, 52] })
113
+ ```
114
+
115
+ You can ignore the proof or use it to optimize hydration of your client side components. The `rows` are the results of the query. You can use `database.subscribe(myAppQueryFn)` to get notified of changes and re-issue your query. The React [useLiveQuery](https://fireproof.storage/documentation/usefireproof-hook-for-react/) hook does this for you automatically.
116
+
117
+ If you need more control over the results, you can use the optional second argument to your map function to specify both keys and values for the index:
118
+
119
+ ```js
120
+ const index = new Index(database, "namesByAge", function (doc, map) {
103
121
  map(doc.age, doc.name)
104
122
  })
105
123
  const { rows, ref } = await index.query({ range: [40, 52] })
@@ -109,49 +127,38 @@ const { rows, ref } = await index.query({ range: [40, 52] })
109
127
 
110
128
  ### Realtime Updates
111
129
 
112
- Subscribe to query changes in your application, so your UI updates automatically. Use the supplied React hooks, our Redux connector, or simple function calls to be notified of relevant changes.
130
+ Subscribe to query changes in your application, so your UI updates automatically. Use the supplied React hooks, or simple function calls to be notified of relevant changes.
113
131
 
114
132
  ```js
115
- const listener = new Listener(database, function(doc, emit) {
116
- if (doc.type == 'member') {
117
- emit('member')
118
- }
119
- })
120
- listener.on('member', (id) => {
121
- const doc = await db.get(id)
122
- alert(`Member update ${doc.name}`)
133
+ const unsubscribe = database.subscribe(changes) => {
134
+ changes.forEach(change => {
135
+ console.log(change)
136
+ })
123
137
  })
124
138
  ```
125
139
 
126
- ### Self-sovereign Identity
127
-
128
- Fireproof is so easy to integrate with any site or app because you can get started right away, and set up an account later. By default users write to their own database copy, so you can get pretty far before you even have to think about API keys. [Authorization is via non-extractable keypair](https://ucan.xyz), like TouchID / FaceID.
129
-
130
- ### Automatic Replication
140
+ Return the `unsubscribe` function from `useEffect` and React will handle it for you. (In the code below, we use the arrow function's implicit return to connect the unsubscribe function to the `useEffect` hook. This prevents extra subscriptions from building up on each render.)
131
141
 
132
- Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.storage](https://web3.storage), and made available over [IPFS] and on a global content delivery network. All you need to do to sync state is send a link to the latest database head, and Fireproof will take care of the rest. [Learn how to enable replication.](#status)
142
+ ```js
143
+ useEffect(() => database.subscribe((changes) =>
144
+ changes.forEach(change => console.log(change))), [])
145
+ ```
133
146
 
134
147
  ### Cryptographic Proofs
135
148
 
136
- The [UCAN protocol](https://ucan.xyz) verifiably links Fireproof updates to authorized agents via cryptographic proof chains. These proofs are portable like bearer tokens, but because invocations are signed by end-user device keys, UCAN proofs don't need to be hidden to be secure, allowing for delegation of service capabilities across devices and parties. Additionally, Fireproof's Merkle clocks and hash trees are immutable and self-validating, making merging changes safe and efficient. Fireproof makes cryptographic proofs available for all of its operations, making it an ideal verifiable document database for smart contracts and other applications running in trustless environments. [Proof chains provide performance benefits as well](https://purrfect-tracker-45c.notion.site/Data-Routing-23c37b269b4c4c3dacb60d0077113bcb), by allowing recipients to skip costly I/O operations and instead cryptographically verify that changes contain all of the required context.
137
-
138
- ## Limitations πŸ’£
139
-
140
- ### Security
141
-
142
- Until encryption support is enabled, all data written to Fireproof is public. There are no big hurdles for this feature but it's not ready yet.
149
+ Fireproof's Merkle clocks and hash trees are immutable and self-validating, making merging changes safe and efficient. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. [Proofs make Fireproof the ideal verifiable document database](https://fireproof.storage/posts/from-mlops-to-point-of-sale:-merkle-proofs-and-data-locality/) for smart contracts and other applications where unique, verifiable, and trustworthy data is required. [Proof chains provide performance benefits as well](https://purrfect-tracker-45c.notion.site/Data-Routing-23c37b269b4c4c3dacb60d0077113bcb), by allowing recipients to skip costly I/O operations and instead cryptographically verify that changes contain all of the required context.
143
150
 
144
- ### Replication
151
+ ### Automatic Replication
145
152
 
146
- Currently Fireproof writes transactions and proofs to [CAR files](https://ipld.io/specs/transport/car/carv2/) which are well suited for peer and cloud replication. They are stored in IndexedDB locally, with cloud replication coming very soon.
153
+ Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.storage](https://web3.storage), and made available over IPFS and on a global content delivery network. All you need to do to sync state is send a link to the latest database head, and Fireproof will take care of the rest.
147
154
 
148
- ### Pre-beta Software
155
+ ### Self-sovereign Identity
149
156
 
150
- While the underlying data structures and libraries Fireproof uses are trusted with billions of dollars worth of data, Fireproof started in February of 2023. Results may vary.
157
+ Fireproof is so easy to integrate with any site or app because you can get started right away, and set up an account later. By default users write to their own database copy, so you can get pretty far before you even have to think about API keys. [Authorization is via non-extractable keypair](https://ucan.xyz), like TouchID / FaceID.
151
158
 
152
159
  ## Thanks πŸ™
153
160
 
154
- 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 datastructures comes from the years of consideration [IPFS](https://ipfs.tech), [IPLD](https://ipld.io), and the [Filecoin APIs](https://docs.filecoin.io) have enjoyed.
161
+ 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](https://ipfs.tech), [IPLD](https://ipld.io), and the [Filecoin APIs](https://docs.filecoin.io) have enjoyed.
155
162
 
156
163
  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](https://github.com/alanshaw/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](https://github.com/mikeal/prolly-trees).
157
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Live data for React, accelerated by proofs, powered by IPFS",
5
5
  "main": "dist/src/fireproof.js",
6
6
  "module": "dist/src/fireproof.mjs",
@@ -74,6 +74,7 @@
74
74
  "rollup-plugin-esbuild": "^5.0.0",
75
75
  "rollup-plugin-node-builtins": "^2.1.2",
76
76
  "rollup-plugin-polyfill-node": "^0.12.0",
77
+ "rollup-plugin-visualizer": "^5.9.0",
77
78
  "standard": "^17.0.0",
78
79
  "typescript": "^5.0.2",
79
80
  "webpack": "^5.78.0",
@@ -119,8 +120,5 @@
119
120
  "dist",
120
121
  "hooks",
121
122
  "README.md"
122
- ],
123
- "workspaces": [
124
- "examples/todomvc"
125
123
  ]
126
124
  }