@fireproof/core 0.17.6 → 0.17.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/README.md +50 -179
  2. package/dist/browser/fireproof.cjs +5 -0
  3. package/dist/browser/fireproof.cjs.map +1 -1
  4. package/dist/browser/fireproof.d.cts +4 -35
  5. package/dist/browser/fireproof.d.ts +4 -35
  6. package/dist/browser/fireproof.global.js +7 -2
  7. package/dist/browser/fireproof.global.js.map +1 -1
  8. package/dist/browser/fireproof.js +5 -0
  9. package/dist/browser/fireproof.js.map +1 -1
  10. package/dist/browser/metafile-cjs.json +1 -1
  11. package/dist/browser/metafile-esm.json +1 -1
  12. package/dist/browser/metafile-iife.json +1 -1
  13. package/dist/memory/fireproof.cjs +5 -0
  14. package/dist/memory/fireproof.cjs.map +1 -1
  15. package/dist/memory/fireproof.d.cts +4 -35
  16. package/dist/memory/fireproof.d.ts +4 -35
  17. package/dist/memory/fireproof.global.js +7 -2
  18. package/dist/memory/fireproof.global.js.map +1 -1
  19. package/dist/memory/fireproof.js +5 -0
  20. package/dist/memory/fireproof.js.map +1 -1
  21. package/dist/memory/metafile-cjs.json +1 -1
  22. package/dist/memory/metafile-esm.json +1 -1
  23. package/dist/memory/metafile-iife.json +1 -1
  24. package/dist/node/fireproof.cjs +5 -0
  25. package/dist/node/fireproof.cjs.map +1 -1
  26. package/dist/node/fireproof.d.cts +4 -35
  27. package/dist/node/fireproof.d.ts +4 -35
  28. package/dist/node/fireproof.global.js +7 -2
  29. package/dist/node/fireproof.global.js.map +1 -1
  30. package/dist/node/fireproof.js +5 -0
  31. package/dist/node/fireproof.js.map +1 -1
  32. package/dist/node/metafile-cjs.json +1 -1
  33. package/dist/node/metafile-esm.json +1 -1
  34. package/dist/node/metafile-iife.json +1 -1
  35. package/package.json +2 -2
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) live database for the web
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
- Simplify your application state with a live database. Automatically update your UI based on local or remote changes, and optionally integrate with any cloud for replication and sharing.
12
+ Add collaboration to any app with Fireproof. Live queries update your UI automatically when the database changes, and realtime sync means those changes can come from local or remote writers.
13
13
 
14
- Fireproof is an embedded JavaScript document database designed to streamline app development. Data resides locally, with optional encrypted cloud storage and real-time sync and collaboration. Features like live queries, database branches and snapshots, and file attachments make Fireproof ideal for browser-based apps big or small.
14
+ The database can be embedded in your browser, server, or edge function, and syncs using any cloud, with [connectors for popular backend services like AWS, Netlify, and PartyKit.](https://www.npmjs.com/package/@fireproof/connect)
15
15
 
16
- Fireproof works in the browser, server, edge function, and any other JavaScript environment, with [connectors for popular backend services like AWS, Netlify, and PartyKit.]()
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 Example
31
18
 
32
- The default build is optimized for browsers, to load the node build add `/node`:
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/node'
36
- ```
22
+ import { fireproof } from '@fireproof/core'
37
23
 
38
- Add the database to any web page via HTML script tag (global is `Fireproof`):
24
+ const db = fireproof('music-app')
39
25
 
40
- ```html
41
- <script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
42
- ```
26
+ await db.put({ _id: 'beyonce', name: 'Beyoncé', hitSingles: 29 })
43
27
 
44
- Go ahead and write features, then [connect to any cloud backend](https://www.npmjs.com/package/@fireproof/connect) later.
45
-
46
- ### JavaScript Example
47
-
48
- ```js
49
- import { fireproof } from 'use-fireproof'
50
-
51
- const db = fireproof('my-app-name')
52
- const { id } = await db.put({
53
- _id: 'three-thousand'
54
- name: 'André',
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 doc = await db.get(id)
59
- const result = await db.query("age", { range: [40, 52] })
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) You can [find a real-world JavaScript app here.](https://github.com/mlc-ai/web-stable-diffusion/pull/52) Fireproof has been tested in many JavaScript environments. Read more about [bundler support](https://use-fireproof.com/docs/bundling).
38
+ Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics)
63
39
 
64
- ### React Example
40
+ ### Live React Hooks
65
41
 
66
- Fireproof has React hooks so you can avoid boilerplate and write expressive code. Instead of dealing with React contexts and reducers, simple hooks make your JSON documents feel like `setState()` objects.
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, or [check out this code sandbox example](https://codesandbox.io/s/fireproof-react-antd-twelve-nk63z6?file=/src/App.tsx) to see how easy it is to build a basic app.
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
- Fireproof has a unique take on distributed data integrity, rooted in immutable data and cryptographically verifiable protocols. This allows you to add live data to any app without complex configuration or installation (it's just an npm module) and if you decide to connect to the cloud you can easily choose storage providers or connect to your own S3 bucket. End-to-end encryption allows you to manage keys separately from data, defining custom security policies, so you can get started writing app features today, and connect to any environment when you are ready. This infrastructure independence makes Fireproof great for brownfield and greenfield projects alike.
81
-
82
- [Read more about the thinking behind Fireproof on our blog.](https://fireproof.storage/blog/) The community is active on [Discord](https://discord.gg/cCryrNHePH) and [X](https://twitter.com/FireproofStorge), among other places.
83
-
84
- ### Database Features
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
85
61
 
86
- The core features of the database are available on any platform in a compact JavaScript package and a foundational cloud storage service.
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.
87
63
 
88
- * **JSON Documents** - Encrypted changes are persisted locally and to any connected storage. Store any JSON object using a familiar document database API.
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.
93
-
94
- Learn more about the [architecture](https://use-fireproof.com/docs/architecture) behind Fireproof.
64
+ [Get the latest 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 is optimized to make [building React and other front-end 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 data collection, [Fireproof is also great](https://fireproof.storage/posts/great-opportunites-to-use-fireproof/) for gaming, [generative AI](https://github.com/fireproof-storage/fireproof/discussions/11), social media, collaborative world-building, and rapidly implementing [executive decision support tools](https://epiphany.fireproof.storage) that can stand up to blockchain levels of scrutiny.
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.
68
+ Fireproof allows web developers to build full-stack apps. It's especially useful for:
107
69
 
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
- ```
70
+ - Rapid prototyping
71
+ - AI copilot safety
72
+ - Collaborative editing
73
+ - Personalization and configuration
74
+ - Offline and local-first apps
111
75
 
112
- For example prompts and inspiration [check out the illustrated version of this technique with links to saved chats](https://use-fireproof.com/docs/chatgpt-quick-start) that are ready to go.
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.
113
77
 
114
- ## API Usage
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).
115
79
 
116
- Import from the package like this:
117
80
 
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
- ```
81
+ ### Install
126
82
 
83
+ Get started with the React hooks:
127
84
 
128
- ### JSON Documents
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.
148
-
149
-
150
- ### Flexible Query
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
- The same mechanism that powers the built-in indexes can all be used to connect secondary [vector indexers](https://github.com/tantaraio/voy) or fulltext indexes to Fireproof. [Follow this tutorial to connect a secondary index](https://fireproof.storage/documentation/external-indexers/).
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
- 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.)
95
+ The default build is optimized for browsers, to load the node build add `/node`:
184
96
 
185
97
  ```js
186
- useEffect(() => database.subscribe((changes) =>
187
- changes.forEach(change => console.log(change))), [])
98
+ import { fireproof } from '@fireproof/core/node'
188
99
  ```
189
100
 
190
- The React [useLiveQuery](https://use-fireproof.com/docs/react-hooks/use-live-query) hook automatically refreshes query results for you, but under the hood, it's just calling `index.query()` and calling `setState()` when the results change. You can use the same technique to build your live query UIs with any framework.
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
- const connection = await connect.web3(db, 'my-account-email@example.com')
103
+ ```html
104
+ <script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
205
105
  ```
206
106
 
207
- You can tie any app to your app developer storage account, or allow users to create personal storage accounts (at no cost to you).
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
- To contribute please follow these steps for local setup and installation of the project
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/jchris/fireproof/blob/main/LICENSE.md)
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) {