@fireproof/core 0.6.2 → 0.6.3-dev

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 CHANGED
@@ -8,9 +8,6 @@
8
8
  </h3>
9
9
 
10
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
11
  <a href="https://github.com/jchris/fireproof/actions/workflows/test.yml">
15
12
  <img src="https://github.com/jchris/fireproof/actions/workflows/test.yml/badge.svg" alt="Test" style="max-width: 100%;">
16
13
  </a>
@@ -20,6 +17,9 @@
20
17
  <a href="https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md">
21
18
  <img src="https://shields.io/badge/react-black?logo=react&style=for-the-badge%22" alt="React" style="max-width: 100%;">
22
19
  </a>
20
+ <a href="https://bundlephobia.com/package/@fireproof/core" rel="nofollow">
21
+ <img src="https://deno.bundlejs.com/?q=@fireproof/core&treeshake=[*+as+fireproofCore]&badge" alt="Bundle Size" style="max-width: 100%;">
22
+ </a>
23
23
  </p>
24
24
 
25
25
  Fireproof uses immutable data and distributed protocols to offer a new kind of database that:
@@ -125,6 +125,8 @@ const { rows, ref } = await index.query({ range: [40, 52] })
125
125
  // { key: 47, value: 'André', id: 'three-thousand' } ]
126
126
  ```
127
127
 
128
+ 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/).
129
+
128
130
  ### Realtime Updates
129
131
 
130
132
  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.
@@ -146,12 +148,16 @@ useEffect(() => database.subscribe((changes) =>
146
148
 
147
149
  ### Cryptographic Proofs
148
150
 
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.
151
+ 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.
150
152
 
151
153
  ### Automatic Replication
152
154
 
153
155
  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.
154
156
 
157
+ ### Peer-to-peer Sync
158
+
159
+ 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.
160
+
155
161
  ### Self-sovereign Identity
156
162
 
157
163
  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.
@@ -0,0 +1,4 @@
1
+ import crypto from 'crypto-browserify';
2
+ export function randomBytes(n) {
3
+ return crypto.randomBytes(n);
4
+ }
@@ -2,7 +2,6 @@
2
2
  import { visMerkleClock, visMerkleTree, vis, put, get, getAll, eventsSince } from './prolly.js';
3
3
  import { doTransaction, TransactionBlockstore } from './blockstore.js';
4
4
  import charwise from 'charwise';
5
- import { localSet } from './utils.js';
6
5
  import { CID } from 'multiformats';
7
6
  // TypeScript Types
8
7
  // eslint-disable-next-line no-unused-vars
@@ -31,7 +30,7 @@ export class Database {
31
30
  this.name = name;
32
31
  this.instanceId = `fp.${this.name}.${Math.random().toString(36).substring(2, 7)}`;
33
32
  this.blocks = new TransactionBlockstore(name, config.key);
34
- this.indexBlocks = new TransactionBlockstore(name + '.indexes', config.key);
33
+ this.indexBlocks = new TransactionBlockstore(name ? name + '.indexes' : null, config.key);
35
34
  this.clock = clock;
36
35
  this.config = config;
37
36
  }
@@ -71,7 +70,7 @@ export class Database {
71
70
  }
72
71
  maybeSaveClock() {
73
72
  if (this.name && this.blocks.valet) {
74
- localSet('fp.' + this.name, JSON.stringify(this));
73
+ this.blocks.valet.saveHeader(JSON.stringify(this));
75
74
  }
76
75
  }
77
76
  index(name) {
@@ -292,6 +291,7 @@ export class Database {
292
291
  console.error('failed', event);
293
292
  throw new Error('failed to put at storage layer');
294
293
  }
294
+ // await new Promise(resolve => setTimeout(resolve, 10)) // makes concurrent tests work
295
295
  this.applyClock(prevClock, result.head);
296
296
  await this.notifyListeners([decodedEvent]); // this type is odd
297
297
  return {
@@ -1,9 +1,33 @@
1
1
  import * as multiformats from 'multiformats';
2
2
  import { Link, CID } from 'multiformats';
3
3
  import * as multiformats_cid from 'multiformats/cid';
4
+ import * as idb from 'idb';
4
5
 
5
6
  type AnyLink = Link<unknown, number, number, 1|0>
6
7
 
8
+ declare class Loader {
9
+ constructor(name: any, keyId: any, config?: {
10
+ dataDir: any;
11
+ headerKeyPrefix: string;
12
+ });
13
+ name: any;
14
+ keyId: any;
15
+ config: {
16
+ dataDir: any;
17
+ headerKeyPrefix: string;
18
+ };
19
+ isBrowser: boolean;
20
+ withDB: (dbWorkFun: any) => Promise<any>;
21
+ idb: idb.IDBPDatabase<unknown>;
22
+ writeCars(cars: any): Promise<void>;
23
+ writeCarsIDB(cars: any): Promise<any>;
24
+ readCar(carCid: any): Promise<any>;
25
+ readCarIDB(carCid: any): Promise<any>;
26
+ getHeader(): any;
27
+ saveHeader(stringValue: any): Promise<void>;
28
+ headerFilename(): any;
29
+ }
30
+
7
31
  declare class Valet {
8
32
  constructor(name: string, keyMaterial: any);
9
33
  idb: any;
@@ -22,6 +46,8 @@ declare class Valet {
22
46
  * @type {null|function(string, Uint8Array):Promise<void>}
23
47
  */
24
48
  uploadFunction: null | ((arg0: string, arg1: Uint8Array) => Promise<void>);
49
+ loader: Loader;
50
+ saveHeader(header: any): Promise<void>;
25
51
  getKeyMaterial(): any;
26
52
  setKeyMaterial(km: any): void;
27
53
  /**
@@ -32,7 +58,6 @@ declare class Valet {
32
58
  * @memberof Valet
33
59
  */
34
60
  writeTransaction(innerBlockstore: InnerBlockstore, cids: Set<string>): Promise<void>;
35
- withDB: (dbWorkFun: any) => Promise<any>;
36
61
  /**
37
62
  * Iterate over all blocks in the store.
38
63
  *
@@ -55,7 +80,6 @@ declare class Valet {
55
80
  * @param {*} value
56
81
  */
57
82
  parkCar(carCid: string, value: any, cids: any): Promise<void>;
58
- writeCars(cars: any): Promise<any>;
59
83
  remoteBlockFunction: any;
60
84
  getCarReader(carCid: any): Promise<{
61
85
  root: any;