@fireproof/core 0.5.6 → 0.5.8
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 +18 -0
- package/dist/src/fireproof.d.ts +149 -108
- package/dist/src/fireproof.js +2771 -581
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +2771 -582
- package/dist/src/fireproof.mjs.map +1 -1
- package/package.json +4 -2
- package/src/blockstore.js +32 -16
- package/src/clock.js +42 -10
- package/src/database.js +52 -13
- package/src/db-index.js +14 -3
- package/src/fireproof.js +2 -40
- package/src/listener.js +1 -1
- package/src/prolly.js +90 -53
- package/src/sync.js +201 -0
- package/src/valet.js +32 -6
package/README.md
CHANGED
@@ -27,6 +27,24 @@ const doc = await fireproof.get(ok.id)
|
|
27
27
|
|
28
28
|
🤫 I like to drop a `window.fireproof = fireproof` in there as a development aid.
|
29
29
|
|
30
|
+
### ChatGPT Quick Start
|
31
|
+
|
32
|
+
Paste this to GPT 4 or 3.5 to enable it to write apps using Fireproof:
|
33
|
+
|
34
|
+
```
|
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);
|
36
|
+
```
|
37
|
+
|
38
|
+
In the same prompt, describe the app you want to build. Here are some examples that worked for us:
|
39
|
+
|
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 <ul>. ([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.
|
45
|
+
|
46
|
+
Please share your successes with us here or on [Twitter.](https://twitter.com/FireproofStorge)
|
47
|
+
|
30
48
|
### Status
|
31
49
|
|
32
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)
|
package/dist/src/fireproof.d.ts
CHANGED
@@ -1,101 +1,6 @@
|
|
1
1
|
import * as multiformats from 'multiformats';
|
2
2
|
import { CID } from 'multiformats';
|
3
3
|
|
4
|
-
/**
|
5
|
-
* Represents an DbIndex for a Fireproof database.
|
6
|
-
*
|
7
|
-
* @class DbIndex
|
8
|
-
* @classdesc An DbIndex can be used to order and filter the documents in a Fireproof database.
|
9
|
-
*
|
10
|
-
* @param {Database} database - The Fireproof database instance to DbIndex.
|
11
|
-
* @param {Function} mapFn - The map function to apply to each entry in the database.
|
12
|
-
*
|
13
|
-
*/
|
14
|
-
declare class DbIndex {
|
15
|
-
static registerWithDatabase(inIndex: any, database: any): void;
|
16
|
-
static fromJSON(database: any, { code, clock, name }: {
|
17
|
-
code: any;
|
18
|
-
clock: any;
|
19
|
-
name: any;
|
20
|
-
}): DbIndex;
|
21
|
-
constructor(database: any, name: any, mapFn: any, clock?: any, opts?: {});
|
22
|
-
database: any;
|
23
|
-
mapFnString: any;
|
24
|
-
mapFn: any;
|
25
|
-
name: any;
|
26
|
-
indexById: {
|
27
|
-
root: any;
|
28
|
-
cid: any;
|
29
|
-
};
|
30
|
-
indexByKey: {
|
31
|
-
root: any;
|
32
|
-
cid: any;
|
33
|
-
};
|
34
|
-
dbHead: any;
|
35
|
-
instanceId: string;
|
36
|
-
updateIndexPromise: Promise<any>;
|
37
|
-
makeName(): any;
|
38
|
-
toJSON(): {
|
39
|
-
name: any;
|
40
|
-
code: any;
|
41
|
-
clock: {
|
42
|
-
db: any;
|
43
|
-
byId: any;
|
44
|
-
byKey: any;
|
45
|
-
};
|
46
|
-
};
|
47
|
-
/**
|
48
|
-
* JSDoc for Query type.
|
49
|
-
* @typedef {Object} DbQuery
|
50
|
-
* @property {string[]} [range] - The range to query.
|
51
|
-
* @memberof DbIndex
|
52
|
-
*/
|
53
|
-
/**
|
54
|
-
* Query object can have {range}
|
55
|
-
* @param {DbQuery} query - the query range to use
|
56
|
-
* @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
|
57
|
-
* @memberof DbIndex
|
58
|
-
* @instance
|
59
|
-
*/
|
60
|
-
query(query?: {
|
61
|
-
/**
|
62
|
-
* - The range to query.
|
63
|
-
*/
|
64
|
-
range?: string[];
|
65
|
-
}, update?: boolean): Promise<{
|
66
|
-
proof: {};
|
67
|
-
rows: Array<{
|
68
|
-
id: string;
|
69
|
-
key: string;
|
70
|
-
value: any;
|
71
|
-
}>;
|
72
|
-
}>;
|
73
|
-
/**
|
74
|
-
* Update the DbIndex with the latest changes
|
75
|
-
* @private
|
76
|
-
* @returns {Promise<void>}
|
77
|
-
*/
|
78
|
-
private updateIndex;
|
79
|
-
innerUpdateIndex(inBlocks: any): Promise<any>;
|
80
|
-
}
|
81
|
-
/**
|
82
|
-
* JDoc for the result row type.
|
83
|
-
*/
|
84
|
-
type ChangeEvent = {
|
85
|
-
/**
|
86
|
-
* - The key of the document.
|
87
|
-
*/
|
88
|
-
key: string;
|
89
|
-
/**
|
90
|
-
* - The new value of the document.
|
91
|
-
*/
|
92
|
-
value: any;
|
93
|
-
/**
|
94
|
-
* - Is the row deleted?
|
95
|
-
*/
|
96
|
-
del?: boolean;
|
97
|
-
};
|
98
|
-
|
99
4
|
/**
|
100
5
|
* @class Fireproof
|
101
6
|
* @classdesc Fireproof stores data in IndexedDB and provides a Merkle clock.
|
@@ -108,15 +13,17 @@ type ChangeEvent = {
|
|
108
13
|
* @param {object} [authCtx] - Optional authorization context object to use for any authentication checks.
|
109
14
|
*
|
110
15
|
*/
|
111
|
-
declare class Database {
|
16
|
+
declare class Database$1 {
|
112
17
|
constructor(blocks: any, clock: any, config?: {});
|
113
18
|
listeners: Set<any>;
|
19
|
+
indexes: Map<any, any>;
|
20
|
+
rootCache: any;
|
21
|
+
eventsCache: Map<any, any>;
|
114
22
|
name: any;
|
115
23
|
instanceId: string;
|
116
24
|
blocks: any;
|
117
25
|
clock: any;
|
118
26
|
config: {};
|
119
|
-
indexes: Map<any, any>;
|
120
27
|
/**
|
121
28
|
* Renders the Fireproof instance as a JSON object.
|
122
29
|
* @returns {Object} - The JSON representation of the Fireproof instance. Includes clock heads for the database and its indexes.
|
@@ -169,6 +76,7 @@ declare class Database {
|
|
169
76
|
proof: any[];
|
170
77
|
}>;
|
171
78
|
allCIDs(): Promise<any[]>;
|
79
|
+
allStoredCIDs(): Promise<any[]>;
|
172
80
|
/**
|
173
81
|
* Runs validation on the specified document using the Fireproof instance's configuration. Throws an error if the document is invalid.
|
174
82
|
*
|
@@ -264,13 +172,8 @@ declare class Database {
|
|
264
172
|
result?: undefined;
|
265
173
|
}, unknown>;
|
266
174
|
visTree(): Promise<{
|
267
|
-
cids: any;
|
268
|
-
result: any;
|
269
|
-
vis?: undefined;
|
270
|
-
} | {
|
271
175
|
vis: string;
|
272
176
|
cids: any;
|
273
|
-
result?: undefined;
|
274
177
|
}>;
|
275
178
|
visClock(): Promise<{
|
276
179
|
vis: string;
|
@@ -288,6 +191,112 @@ declare class Database {
|
|
288
191
|
setRemoteBlockReader(remoteBlockReaderFn: any): void;
|
289
192
|
}
|
290
193
|
|
194
|
+
/**
|
195
|
+
* Represents an DbIndex for a Fireproof database.
|
196
|
+
*
|
197
|
+
* @class DbIndex
|
198
|
+
* @classdesc An DbIndex can be used to order and filter the documents in a Fireproof database.
|
199
|
+
*
|
200
|
+
* @param {Database} database - The Fireproof database instance to DbIndex.
|
201
|
+
* @param {Function} mapFn - The map function to apply to each entry in the database.
|
202
|
+
*
|
203
|
+
*/
|
204
|
+
declare class DbIndex {
|
205
|
+
static registerWithDatabase(inIndex: any, database: any): void;
|
206
|
+
static fromJSON(database: any, { code, clock, name }: {
|
207
|
+
code: any;
|
208
|
+
clock: any;
|
209
|
+
name: any;
|
210
|
+
}): DbIndex;
|
211
|
+
/**
|
212
|
+
* @param {Database} database
|
213
|
+
*/
|
214
|
+
constructor(database: Database$1, name: any, mapFn: any, clock?: any, opts?: {});
|
215
|
+
database: Database$1;
|
216
|
+
mapFnString: any;
|
217
|
+
mapFn: any;
|
218
|
+
name: any;
|
219
|
+
indexById: {
|
220
|
+
root: any;
|
221
|
+
cid: any;
|
222
|
+
};
|
223
|
+
indexByKey: {
|
224
|
+
root: any;
|
225
|
+
cid: any;
|
226
|
+
};
|
227
|
+
dbHead: any;
|
228
|
+
instanceId: string;
|
229
|
+
updateIndexPromise: Promise<any>;
|
230
|
+
makeName(): any;
|
231
|
+
toJSON(): {
|
232
|
+
name: any;
|
233
|
+
code: any;
|
234
|
+
clock: {
|
235
|
+
db: any;
|
236
|
+
byId: any;
|
237
|
+
byKey: any;
|
238
|
+
};
|
239
|
+
};
|
240
|
+
visKeyTree(): Promise<{
|
241
|
+
vis: string;
|
242
|
+
cids: any;
|
243
|
+
}>;
|
244
|
+
visIdTree(): Promise<{
|
245
|
+
vis: string;
|
246
|
+
cids: any;
|
247
|
+
}>;
|
248
|
+
/**
|
249
|
+
* JSDoc for Query type.
|
250
|
+
* @typedef {Object} DbQuery
|
251
|
+
* @property {string[]} [range] - The range to query.
|
252
|
+
* @memberof DbIndex
|
253
|
+
*/
|
254
|
+
/**
|
255
|
+
* Query object can have {range}
|
256
|
+
* @param {DbQuery} query - the query range to use
|
257
|
+
* @returns {Promise<{proof: {}, rows: Array<{id: string, key: string, value: any}>}>}
|
258
|
+
* @memberof DbIndex
|
259
|
+
* @instance
|
260
|
+
*/
|
261
|
+
query(query?: {
|
262
|
+
/**
|
263
|
+
* - The range to query.
|
264
|
+
*/
|
265
|
+
range?: string[];
|
266
|
+
}, update?: boolean): Promise<{
|
267
|
+
proof: {};
|
268
|
+
rows: Array<{
|
269
|
+
id: string;
|
270
|
+
key: string;
|
271
|
+
value: any;
|
272
|
+
}>;
|
273
|
+
}>;
|
274
|
+
/**
|
275
|
+
* Update the DbIndex with the latest changes
|
276
|
+
* @private
|
277
|
+
* @returns {Promise<void>}
|
278
|
+
*/
|
279
|
+
private updateIndex;
|
280
|
+
innerUpdateIndex(inBlocks: any): Promise<any>;
|
281
|
+
}
|
282
|
+
/**
|
283
|
+
* JDoc for the result row type.
|
284
|
+
*/
|
285
|
+
type ChangeEvent = {
|
286
|
+
/**
|
287
|
+
* - The key of the document.
|
288
|
+
*/
|
289
|
+
key: string;
|
290
|
+
/**
|
291
|
+
* - The new value of the document.
|
292
|
+
*/
|
293
|
+
value: any;
|
294
|
+
/**
|
295
|
+
* - Is the row deleted?
|
296
|
+
*/
|
297
|
+
del?: boolean;
|
298
|
+
};
|
299
|
+
|
291
300
|
/**
|
292
301
|
* A Fireproof database Listener allows you to react to events in the database.
|
293
302
|
*
|
@@ -302,10 +311,10 @@ declare class Listener {
|
|
302
311
|
* @param {import('./database.js').Database} database
|
303
312
|
* @param {(_: any, emit: any) => void} routingFn
|
304
313
|
*/
|
305
|
-
constructor(database: Database, routingFn?: (_: any, emit: any) => void);
|
314
|
+
constructor(database: Database$1, routingFn?: (_: any, emit: any) => void);
|
306
315
|
subcribers: Map<any, any>;
|
307
316
|
doStopListening: any;
|
308
|
-
database: Database;
|
317
|
+
database: Database$1;
|
309
318
|
/**
|
310
319
|
* The map function to apply to each entry in the database.
|
311
320
|
* @type {Function}
|
@@ -319,7 +328,7 @@ declare class Listener {
|
|
319
328
|
* @returns {Function} A function to unsubscribe from the topic.
|
320
329
|
* @memberof Listener
|
321
330
|
* @instance
|
322
|
-
* @param {any} [since] - clock to flush from on launch
|
331
|
+
* @param {any} [since] - clock to flush from on launch, pass null for all
|
323
332
|
*/
|
324
333
|
on(topic: string, subscriber: Function, since?: any): Function;
|
325
334
|
/**
|
@@ -331,6 +340,39 @@ declare class Listener {
|
|
331
340
|
onChanges(changes: ChangeEvent[]): void;
|
332
341
|
}
|
333
342
|
|
343
|
+
/**
|
344
|
+
* @typedef {import('./database.js').Database} Database
|
345
|
+
*/
|
346
|
+
declare class Sync {
|
347
|
+
/**
|
348
|
+
* @param {import("./database.js").Database} database
|
349
|
+
* @param {string} key
|
350
|
+
*/
|
351
|
+
static makeCar(database: Database$1, key: string, skip?: any[]): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
|
352
|
+
/**
|
353
|
+
* @param {Database} database
|
354
|
+
* @param {typeof SimplePeer} [PeerClass]
|
355
|
+
* @memberof Sync
|
356
|
+
* @static
|
357
|
+
*/
|
358
|
+
constructor(database: Database, PeerClass?: any);
|
359
|
+
database: Database$1;
|
360
|
+
PeerClass: any;
|
361
|
+
pushBacklog: Promise<any>;
|
362
|
+
pushBacklogResolve: (value: any) => void;
|
363
|
+
pushBacklogReject: (reason?: any) => void;
|
364
|
+
offer(): Promise<string>;
|
365
|
+
accept(base64offer: any): Promise<string>;
|
366
|
+
connect(base64accept: any): void;
|
367
|
+
setupPeer(initiator?: boolean): Promise<string>;
|
368
|
+
peer: any;
|
369
|
+
backlog(): Promise<any>;
|
370
|
+
gotData(data: any): Promise<void>;
|
371
|
+
sendUpdate(blockstore: any): Promise<void>;
|
372
|
+
startSync(): Promise<void>;
|
373
|
+
}
|
374
|
+
type Database = Database$1;
|
375
|
+
|
334
376
|
declare class Fireproof {
|
335
377
|
/**
|
336
378
|
* @function storage
|
@@ -340,11 +382,10 @@ declare class Fireproof {
|
|
340
382
|
* @static
|
341
383
|
* @returns {Database} - a new Fireproof instance
|
342
384
|
*/
|
343
|
-
static storage: (name?: any, opts?: {}) => Database;
|
385
|
+
static storage: (name?: any, opts?: {}) => Database$1;
|
344
386
|
static fromJSON(json: any, database: any): any;
|
345
387
|
static snapshot(database: any, clock: any): any;
|
346
388
|
static zoom(database: any, clock: any): Promise<any>;
|
347
|
-
static makeCar(database: any, key: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
|
348
389
|
}
|
349
390
|
|
350
|
-
export { Database, Fireproof, DbIndex as Index, Listener };
|
391
|
+
export { Database$1 as Database, Fireproof, DbIndex as Index, Listener, Sync };
|