@fireproof/core 0.6.1 β 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.
- package/README.md +85 -83
- package/package.json +2 -4
package/README.md
CHANGED
@@ -1,79 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
Fireproof is optimized to make building React apps fast and fun, with reliable results.
|
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.
|
31
|
+
|
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)
|
10
33
|
|
11
|
-
## React hooks API
|
12
34
|
|
13
|
-
|
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):
|
14
37
|
|
15
38
|
```js
|
16
|
-
|
17
|
-
|
18
|
-
export default App = () => {
|
19
|
-
const { database, useLiveQuery } = useFireproof()
|
20
|
-
const todoList = useLiveQuery((doc) => doc.date).docs
|
21
|
-
const [newTodo, setNewTodo] = useState('')
|
22
|
-
|
23
|
-
return (
|
24
|
-
<div>
|
25
|
-
<input type="text" onChange={(e) => setNewTodo(e.target.value)} />
|
26
|
-
<button onClick={() => database.put({text: newTodo, date: Date.now(), completed: false})}>Save</button>
|
27
|
-
<ul>
|
28
|
-
{todoList.map((todo) => (
|
29
|
-
<li key={todo._id}>
|
30
|
-
<input
|
31
|
-
type="checkbox"
|
32
|
-
checked={todo.completed}
|
33
|
-
onChange={() => database.put({...todo, completed: !todo.completed})} />
|
34
|
-
{todo.text}
|
35
|
-
</li>
|
36
|
-
))}
|
37
|
-
</div>
|
38
|
-
)
|
39
|
-
}
|
39
|
+
const completedTodos = useLiveQuery((doc) => doc.completed, { key: true })
|
40
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.
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
* **Realtime** - data is updated as soon as it is available, with no polling or refreshes required.
|
45
|
-
* **Distributed** - data is stored in a distributed network, so it is always available.
|
46
|
-
* **Sync** - users can collaborate on data subsets, with changes synced across devices or via the cloud.
|
47
|
-
* **Proofs** - cryptographic verification makes results verifiable and lowers operating costs
|
48
|
-
|
49
|
-
### Architecture
|
43
|
+
## AI Assistant Quick Start
|
50
44
|
|
51
|
-
|
52
|
-
* Immutable content-addressed data ensures that data is always consistent, accurate, and verified
|
53
|
-
* Encrypted at rest and in transit, with optional clear-text database publishing for content management use cases.
|
54
|
-
* Open source, so you can inspect the code and make sure that it meets your security and privacy requirements.
|
55
|
-
|
56
|
-
Learn more about the [concepts](https://fireproof.storage/posts/from-mlops-to-point-of-sale:-merkle-proofs-and-data-locality/) and [architecture](https://fireproof.storage/documentation/how-the-database-engine-works/) behind Fireproof, or look in the `examples/` directory for projects using the database, or see [examples on CodePen](https://codepen.io/jchrisa/pen/GRYJJEM).
|
57
|
-
|
58
|
-
## ChatGPT / Bard Quick Start
|
59
|
-
|
60
|
-
Paste this to GPT 4, 3.5, or Bard to enable it to write React 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:
|
61
46
|
|
62
47
|
```
|
63
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></>)}
|
64
49
|
```
|
65
50
|
|
66
|
-
|
51
|
+
Here are some examples that worked for us:
|
67
52
|
|
68
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 <ul>. ([Running copy here.](https://codepen.io/jchrisa/pen/zYmogWO))
|
69
|
-
* 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.
|
70
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.
|
71
|
-
* Build
|
72
|
-
* 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.
|
73
|
-
|
74
|
-
Please share your successes with us here or on [Twitter.](https://twitter.com/FireproofStorge)
|
75
|
-
|
76
|
-
#### Advanced AI Docs
|
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.
|
77
56
|
|
78
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.
|
79
58
|
|
@@ -81,18 +60,27 @@ You can enhance the AI's understanding by adding the core APIs. Use this if you
|
|
81
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);
|
82
61
|
```
|
83
62
|
|
84
|
-
|
63
|
+
Please share your successes with us here or on [Twitter.](https://twitter.com/FireproofStorge)
|
64
|
+
|
65
|
+
# Database Features
|
85
66
|
|
86
|
-
|
67
|
+
The core features of the database are available on any platform in a compact JavaScript package and a foundational cloud storage service.
|
87
68
|
|
88
|
-
|
89
|
-
[
|
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.
|
90
75
|
|
91
|
-
|
76
|
+
|
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).
|
78
|
+
|
79
|
+
## API Usage
|
92
80
|
|
93
81
|
### Encrypted Documents
|
94
82
|
|
95
|
-
A simple put, get
|
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.
|
96
84
|
|
97
85
|
```js
|
98
86
|
const { id, ref } = await database.put({
|
@@ -100,7 +88,9 @@ const { id, ref } = await database.put({
|
|
100
88
|
name: 'AndrΓ©',
|
101
89
|
age: 47
|
102
90
|
});
|
103
|
-
|
91
|
+
|
92
|
+
// mvcc is optional
|
93
|
+
const doc = await database.get('three-thousand', { mvcc: true })
|
104
94
|
// {
|
105
95
|
// _id : 'three-thousand'
|
106
96
|
// _clock : CID(bafy84...agfw7)
|
@@ -109,16 +99,25 @@ const doc = await database.get('three-thousand', { mvcc : true }) // mvcc is opt
|
|
109
99
|
// }
|
110
100
|
```
|
111
101
|
|
112
|
-
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.
|
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.
|
113
103
|
|
114
104
|
### Live Query
|
115
105
|
|
116
|
-
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.
|
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.
|
117
107
|
|
118
|
-
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.
|
119
109
|
|
120
110
|
```js
|
121
|
-
const index = new Index(database,
|
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) {
|
122
121
|
map(doc.age, doc.name)
|
123
122
|
})
|
124
123
|
const { rows, ref } = await index.query({ range: [40, 52] })
|
@@ -128,35 +127,38 @@ const { rows, ref } = await index.query({ range: [40, 52] })
|
|
128
127
|
|
129
128
|
### Realtime Updates
|
130
129
|
|
131
|
-
Subscribe to query changes in your application, so your UI updates automatically. Use the supplied React hooks,
|
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.
|
132
131
|
|
133
132
|
```js
|
134
|
-
const
|
135
|
-
|
136
|
-
|
137
|
-
}
|
138
|
-
})
|
139
|
-
listener.on('member', (id) => {
|
140
|
-
const doc = await db.get(id)
|
141
|
-
alert(`Member update ${doc.name}`)
|
133
|
+
const unsubscribe = database.subscribe(changes) => {
|
134
|
+
changes.forEach(change => {
|
135
|
+
console.log(change)
|
136
|
+
})
|
142
137
|
})
|
143
138
|
```
|
144
139
|
|
145
|
-
|
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.)
|
146
141
|
|
147
|
-
|
142
|
+
```js
|
143
|
+
useEffect(() => database.subscribe((changes) =>
|
144
|
+
changes.forEach(change => console.log(change))), [])
|
145
|
+
```
|
146
|
+
|
147
|
+
### Cryptographic Proofs
|
148
|
+
|
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.
|
148
150
|
|
149
151
|
### Automatic Replication
|
150
152
|
|
151
|
-
Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.storage](https://web3.storage), and made available over
|
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.
|
152
154
|
|
153
|
-
###
|
155
|
+
### Self-sovereign Identity
|
154
156
|
|
155
|
-
|
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.
|
156
158
|
|
157
159
|
## Thanks π
|
158
160
|
|
159
|
-
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
|
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.
|
160
162
|
|
161
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).
|
162
164
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fireproof/core",
|
3
|
-
"version": "0.6.
|
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
|
}
|