@fireproof/core 0.17.6 → 0.17.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +50 -179
- package/dist/browser/fireproof.cjs +5 -0
- package/dist/browser/fireproof.cjs.map +1 -1
- package/dist/browser/fireproof.d.cts +4 -35
- package/dist/browser/fireproof.d.ts +4 -35
- package/dist/browser/fireproof.global.js +2149 -689
- package/dist/browser/fireproof.global.js.map +1 -1
- package/dist/browser/fireproof.js +5 -0
- package/dist/browser/fireproof.js.map +1 -1
- package/dist/browser/metafile-cjs.json +1 -1
- package/dist/browser/metafile-esm.json +1 -1
- package/dist/browser/metafile-iife.json +1 -1
- package/dist/memory/fireproof.cjs +5 -0
- package/dist/memory/fireproof.cjs.map +1 -1
- package/dist/memory/fireproof.d.cts +4 -35
- package/dist/memory/fireproof.d.ts +4 -35
- package/dist/memory/fireproof.global.js +2149 -689
- package/dist/memory/fireproof.global.js.map +1 -1
- package/dist/memory/fireproof.js +5 -0
- package/dist/memory/fireproof.js.map +1 -1
- package/dist/memory/metafile-cjs.json +1 -1
- package/dist/memory/metafile-esm.json +1 -1
- package/dist/memory/metafile-iife.json +1 -1
- package/dist/node/fireproof.cjs +5 -0
- package/dist/node/fireproof.cjs.map +1 -1
- package/dist/node/fireproof.d.cts +4 -35
- package/dist/node/fireproof.d.ts +4 -35
- package/dist/node/fireproof.global.js +2228 -768
- package/dist/node/fireproof.global.js.map +1 -1
- package/dist/node/fireproof.js +5 -0
- package/dist/node/fireproof.js.map +1 -1
- package/dist/node/metafile-cjs.json +1 -1
- package/dist/node/metafile-esm.json +1 -1
- package/dist/node/metafile-iife.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
|
3
|
-
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage)
|
3
|
+
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) realtime database
|
4
4
|
|
5
5
|
<p align="right">
|
6
6
|
<img src="https://img.shields.io/bundlephobia/minzip/%40fireproof%2Fcore" alt="Package size">
|
@@ -9,61 +9,37 @@
|
|
9
9
|
</a>
|
10
10
|
</p>
|
11
11
|
|
12
|
-
|
12
|
+
### No setup: write features first, access your data anywhere
|
13
13
|
|
14
|
-
Fireproof
|
14
|
+
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](https://www.npmjs.com/package/@fireproof/connect) and those changes will sync between browsers and backend functions. Apps built this way are multi-player by default.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
### Install Anywhere
|
19
|
-
|
20
|
-
Get started with just the NPM module:
|
21
|
-
|
22
|
-
```sh
|
23
|
-
npm install use-fireproof
|
24
|
-
```
|
25
|
-
|
26
|
-
or target specific builds via:
|
27
|
-
|
28
|
-
```sh
|
29
|
-
npm install @fireproof/core
|
30
|
-
```
|
16
|
+
|
17
|
+
### JavaScript quick start
|
31
18
|
|
32
|
-
The
|
19
|
+
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.
|
33
20
|
|
34
21
|
```js
|
35
|
-
import { fireproof } from '@fireproof/core
|
36
|
-
```
|
37
|
-
|
38
|
-
Add the database to any web page via HTML script tag (global is `Fireproof`):
|
22
|
+
import { fireproof } from '@fireproof/core'
|
39
23
|
|
40
|
-
|
41
|
-
<script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
|
42
|
-
```
|
43
|
-
|
44
|
-
Go ahead and write features, then [connect to any cloud backend](https://www.npmjs.com/package/@fireproof/connect) later.
|
45
|
-
|
46
|
-
### JavaScript Example
|
24
|
+
const db = fireproof('music-app')
|
47
25
|
|
48
|
-
|
49
|
-
import { fireproof } from 'use-fireproof'
|
26
|
+
await db.put({ _id: 'beyonce', name: 'Beyoncé', hitSingles: 29 })
|
50
27
|
|
51
|
-
|
52
|
-
const
|
53
|
-
|
54
|
-
|
55
|
-
age: 47
|
56
|
-
});
|
28
|
+
db.subscribe(async () => {
|
29
|
+
const topArtists = await db.query("hitSingles", { range: [30, Infinity] })
|
30
|
+
// redraw the UI with the new topArtists
|
31
|
+
})
|
57
32
|
|
58
|
-
const
|
59
|
-
|
33
|
+
const beyonceDoc = await db.get('beyonce')
|
34
|
+
beyonceDoc.hitSingles += 1
|
35
|
+
await db.put(beyonceDoc)
|
60
36
|
```
|
61
37
|
|
62
|
-
Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics)
|
38
|
+
Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics)
|
63
39
|
|
64
|
-
###
|
40
|
+
### Live data hooks for React
|
65
41
|
|
66
|
-
Fireproof
|
42
|
+
Fireproof [React hooks for live data](https://use-fireproof.com/docs/category/react-hooks) avoid boilerplate and make building collaborative apps a breeze.
|
67
43
|
|
68
44
|
```js
|
69
45
|
import { useLiveQuery, useDocument } from 'use-fireproof'
|
@@ -73,157 +49,63 @@ function App() {
|
|
73
49
|
const [newTodo, setNewTodoData, saveNewTodo] = useDocument({type: 'todo', text: '', completed: false, created: Date.now() })
|
74
50
|
```
|
75
51
|
|
76
|
-
Read the [step-by-step React tutorial](https://use-fireproof.com/docs/react-tutorial) to get started
|
52
|
+
Read the [step-by-step React tutorial](https://use-fireproof.com/docs/react-tutorial) to get started.
|
77
53
|
|
78
54
|
## Why choose Fireproof
|
79
55
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
The core features of the database are available on any platform in a compact JavaScript package and a foundational cloud storage service.
|
56
|
+
Compared to other embedded databases, Fireproof:
|
57
|
+
- is network aware, encrypted, and multi-writer safe
|
58
|
+
- is designed for real-time collaboration with CRDTs
|
59
|
+
- offers cryptographic causal integrity for all operations
|
60
|
+
- is built for the web, with a small package size and no wasm
|
87
61
|
|
88
|
-
|
89
|
-
* **File Attachments** - Share social media or manage uploads within Fireproof's [file attachment API](https://use-fireproof.com/docs/database-api/documents#put-with-files). Attachments are stored locally and in the cloud, and can be encrypted or public.
|
90
|
-
* **Live Query** - Sort and filter any database with CouchDB-style `map` functions. The `useFireproof` React hook integrates so cleanly your code doesn't even have to import `useState` or `useEffect`, instead, [`useLiveQuery`](https://use-fireproof.com/docs/react-hooks/use-live-query) makes dynamic renders easy.
|
91
|
-
* **Realtime Updates** - [Subscribe to query changes in your application](https://use-fireproof.com/docs/database-api/database#subscribing-to-changes), so your UI updates automatically. This makes vanilla JS apps super easy to build -- the `useFireproof` React hook handles this so you won't need `db.subscribe()` there.
|
92
|
-
* **Cryptographic Proofs** - Fireproof's Merkle clocks and hash trees are immutable and self-validating, making all query results into offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. This makes it a great choice for building custom document approval workflows or other situations where provenance is important.
|
62
|
+
Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access data anywhere.
|
93
63
|
|
94
|
-
|
64
|
+
[Get the latest roadmap updates on our blog](https://fireproof.storage/blog/) or join our [Discord](https://discord.gg/cCryrNHePH) to collaborate. Read the docs to learn more about the database [architecture](https://use-fireproof.com/docs/architecture).
|
95
65
|
|
96
66
|
### Use cases
|
97
67
|
|
98
|
-
Fireproof
|
99
|
-
|
100
|
-
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.
|
101
|
-
|
102
|
-
### AI Copilot Quick Start
|
103
|
-
|
104
|
-
Because Fireproof is designed to let you get started in the browser and connect to the cloud when you're ready, it's ideal for AI-assisted app development. If you are using GPT, Claude, 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).
|
105
|
-
|
106
|
-
Working with an AI assistant is a great way to get started on projects or try out new frameworks. Paste this line of code into your prompt, along with a detailed description of the app to build, and your app will be running without ever requiring a cloud.
|
107
|
-
|
108
|
-
```
|
109
|
-
Fireproof/React/Usage: import { useFireproof } from 'use-fireproof'; function App() { const { useLiveQuery, useDocument, database } = useFireproof(); const result = useLiveQuery(doc => doc.word, { limit: 10 }); const [{ count }, saveCountDocument] = useDocument({_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></>)}
|
110
|
-
```
|
68
|
+
Fireproof allows web developers to build full-stack apps. It's especially useful for:
|
111
69
|
|
112
|
-
|
70
|
+
- Rapid prototyping
|
71
|
+
- AI copilot safety
|
72
|
+
- Collaborative editing
|
73
|
+
- Personalization and configuration
|
74
|
+
- Offline and local-first apps
|
113
75
|
|
114
|
-
|
76
|
+
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.
|
115
77
|
|
116
|
-
|
78
|
+
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](https://use-fireproof.com/docs/chatgpt-quick-start).
|
117
79
|
|
118
|
-
```js
|
119
|
-
import { fireproof } from 'use-fireproof'
|
120
|
-
```
|
121
|
-
and create a database:
|
122
|
-
|
123
|
-
```js
|
124
|
-
const database = fireproof('my-app-name')
|
125
|
-
```
|
126
80
|
|
81
|
+
### Install
|
127
82
|
|
128
|
-
|
129
|
-
|
130
|
-
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.
|
131
|
-
|
132
|
-
```js
|
133
|
-
const { id } = await database.put({
|
134
|
-
_id: 'three-thousand'
|
135
|
-
name: 'André',
|
136
|
-
age: 47
|
137
|
-
});
|
138
|
-
|
139
|
-
const doc = await database.get('three-thousand')
|
140
|
-
// {
|
141
|
-
// _id : 'three-thousand'
|
142
|
-
// name : 'André',
|
143
|
-
// age : 47
|
144
|
-
// }
|
145
|
-
```
|
146
|
-
|
147
|
-
Fireproof tracks all versions so undo is easy to write, and cryptographically verifiable snapshots of the database are as easy as web links.
|
83
|
+
Get started with the React hooks:
|
148
84
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
```js
|
154
|
-
const { rows } = await database.query("age", { range: [40, 52] })
|
155
|
-
```
|
156
|
-
|
157
|
-
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.
|
158
|
-
|
159
|
-
You can specify your function as a string and Fireproof will interpret it as indexing that field on all documents. You can also pass a function for more control:
|
160
|
-
|
161
|
-
```js
|
162
|
-
const { rows } = await database.query(function (doc, map) {
|
163
|
-
map(doc.age, doc.name)
|
164
|
-
}, { range: [40, 52] })
|
85
|
+
```sh
|
86
|
+
npm install use-fireproof
|
165
87
|
```
|
166
88
|
|
89
|
+
or install the database in any JavaScript environment:
|
167
90
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
### Realtime Updates
|
172
|
-
|
173
|
-
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.
|
174
|
-
|
175
|
-
```js
|
176
|
-
const unsubscribe = database.subscribe(changes) => {
|
177
|
-
changes.forEach(change => {
|
178
|
-
console.log(change)
|
179
|
-
})
|
180
|
-
})
|
91
|
+
```sh
|
92
|
+
npm install @fireproof/core
|
181
93
|
```
|
182
94
|
|
183
|
-
|
95
|
+
The default build is optimized for browsers, to load the node build add `/node`:
|
184
96
|
|
185
97
|
```js
|
186
|
-
|
187
|
-
changes.forEach(change => console.log(change))), [])
|
98
|
+
import { fireproof } from '@fireproof/core/node'
|
188
99
|
```
|
189
100
|
|
190
|
-
|
191
|
-
|
192
|
-
### Cryptographic Proofs
|
193
|
-
|
194
|
-
Fireproof's Merkle clocks and hash trees are immutable and self-validating, and all query results are offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. If you are making a "DocuSign for _____", [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.
|
195
|
-
|
196
|
-
|
197
|
-
### Cloud Storage
|
198
|
-
|
199
|
-
When you are ready to save your data to the cloud for sharing or backup:
|
200
|
-
|
201
|
-
```js
|
202
|
-
import { connect } from 'use-fireproof'
|
101
|
+
Add the database to any web page via HTML script tag (global is `Fireproof`):
|
203
102
|
|
204
|
-
|
103
|
+
```html
|
104
|
+
<script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
|
205
105
|
```
|
206
106
|
|
207
|
-
|
208
|
-
|
209
|
-
Currently, the web3 driver only stores database data, not metadata, but that still makes it great for sharing databases via direct links.
|
210
|
-
|
211
|
-
## Coming Soon
|
212
|
-
|
213
|
-
The six-month roadmap for Fireproof includes these features to make it a complete offering for application data.
|
214
|
-
|
215
|
-
|
216
|
-
### Automatic Replication
|
217
|
-
|
218
|
-
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.
|
219
|
-
|
220
|
-
### Peer-to-peer Sync
|
221
|
-
|
222
|
-
Application instances can be connected using WebRTC or any other stream API library, like [Socket Supply](https://socketsupply.co), [libp2p](https://libp2p.io), or [PartyKit](https://partykit.io). The [first sync demo uses pure WebRTC with no signaling server](https://game.fireproof.storage), which limits its usability. There are demos with other transports coming soon.
|
223
|
-
|
224
|
-
### Self-sovereign Identity
|
107
|
+
Go ahead and write features, then [connect to any cloud backend](https://www.npmjs.com/package/@fireproof/connect) later.
|
225
108
|
|
226
|
-
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.
|
227
109
|
|
228
110
|
## Thanks 🙏
|
229
111
|
|
@@ -233,19 +115,8 @@ Thanks to Alan Shaw and Mikeal Rogers without whom this project would have never
|
|
233
115
|
|
234
116
|
## Contributing
|
235
117
|
|
236
|
-
|
237
|
-
|
238
|
-
1. Click on the "Fork" button in the top-right corner of the repository's page. This will create a copy of the repository in your account.
|
239
|
-
2. Clone the forked repository to your local machine using Git.
|
240
|
-
3. Now cd to the target directory, or load the directory in your IDE, and open up a terminal.
|
241
|
-
4. Run the command `pnpm install`. This will install all the dependencies that are listed in the `package.json` file.
|
242
|
-
5. Now change the directory to packages/fireproof using the command `cd packages/fireproof`.
|
243
|
-
6. See the `package.json` file to work with all the listed commands and try them out. You can also test your changes using `npm test`.
|
244
|
-
7. Also change directory to `examples/todomvc` and run the command `npm run dev` to load up a simple application to understand the use of Fireproof as a real-time database.
|
245
|
-
8. Keep contributing :) See [issues](https://github.com/fireproof-storage/fireproof/issues) for ideas how to get started.
|
246
|
-
|
247
|
-
Feel free to [join in the conversation on Discord. All welcome.](https://discord.gg/cCryrNHePH)
|
118
|
+
We love contributions. Feel free to [join in the conversation on Discord. All welcome.](https://discord.gg/cCryrNHePH)
|
248
119
|
|
249
120
|
# License
|
250
121
|
|
251
|
-
Dual-licensed under [MIT or Apache 2.0](https://github.com/
|
122
|
+
Dual-licensed under [MIT or Apache 2.0](https://github.com/fireproof-storage/fireproof/blob/main/LICENSE.md)
|
@@ -241,6 +241,11 @@ async function processFileset(blocks, files, publicFiles = false) {
|
|
241
241
|
t.putSync(block.cid, block.bytes);
|
242
242
|
}
|
243
243
|
files[filename] = { cid, type: file.type, size: file.size };
|
244
|
+
} else {
|
245
|
+
const { cid, type, size, car } = files[filename];
|
246
|
+
if (cid && type && size && car) {
|
247
|
+
files[filename] = { cid, type, size, car };
|
248
|
+
}
|
244
249
|
}
|
245
250
|
}
|
246
251
|
if (didPut.length) {
|