@fireproof/core 0.5.6 → 0.5.7

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
@@ -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)
@@ -108,7 +108,7 @@ type ChangeEvent = {
108
108
  * @param {object} [authCtx] - Optional authorization context object to use for any authentication checks.
109
109
  *
110
110
  */
111
- declare class Database {
111
+ declare class Database$1 {
112
112
  constructor(blocks: any, clock: any, config?: {});
113
113
  listeners: Set<any>;
114
114
  name: any;
@@ -169,6 +169,7 @@ declare class Database {
169
169
  proof: any[];
170
170
  }>;
171
171
  allCIDs(): Promise<any[]>;
172
+ allStoredCIDs(): Promise<any[]>;
172
173
  /**
173
174
  * Runs validation on the specified document using the Fireproof instance's configuration. Throws an error if the document is invalid.
174
175
  *
@@ -265,7 +266,10 @@ declare class Database {
265
266
  }, unknown>;
266
267
  visTree(): Promise<{
267
268
  cids: any;
268
- result: any;
269
+ result: any; /**
270
+ // * Advances the clock to the specified event and updates the root CID
271
+ // * Will be used by replication
272
+ // */
269
273
  vis?: undefined;
270
274
  } | {
271
275
  vis: string;
@@ -302,10 +306,10 @@ declare class Listener {
302
306
  * @param {import('./database.js').Database} database
303
307
  * @param {(_: any, emit: any) => void} routingFn
304
308
  */
305
- constructor(database: Database, routingFn?: (_: any, emit: any) => void);
309
+ constructor(database: Database$1, routingFn?: (_: any, emit: any) => void);
306
310
  subcribers: Map<any, any>;
307
311
  doStopListening: any;
308
- database: Database;
312
+ database: Database$1;
309
313
  /**
310
314
  * The map function to apply to each entry in the database.
311
315
  * @type {Function}
@@ -319,7 +323,7 @@ declare class Listener {
319
323
  * @returns {Function} A function to unsubscribe from the topic.
320
324
  * @memberof Listener
321
325
  * @instance
322
- * @param {any} [since] - clock to flush from on launch
326
+ * @param {any} [since] - clock to flush from on launch, pass null for all
323
327
  */
324
328
  on(topic: string, subscriber: Function, since?: any): Function;
325
329
  /**
@@ -331,6 +335,39 @@ declare class Listener {
331
335
  onChanges(changes: ChangeEvent[]): void;
332
336
  }
333
337
 
338
+ /**
339
+ * @typedef {import('./database.js').Database} Database
340
+ */
341
+ declare class Sync {
342
+ /**
343
+ * @param {import("./database.js").Database} database
344
+ * @param {string} key
345
+ */
346
+ static makeCar(database: Database$1, key: string, skip?: any[]): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
347
+ /**
348
+ * @param {Database} database
349
+ * @param {typeof SimplePeer} [PeerClass]
350
+ * @memberof Sync
351
+ * @static
352
+ */
353
+ constructor(database: Database, PeerClass?: any);
354
+ database: Database$1;
355
+ PeerClass: any;
356
+ pushBacklog: Promise<any>;
357
+ pushBacklogResolve: (value: any) => void;
358
+ pushBacklogReject: (reason?: any) => void;
359
+ offer(): Promise<string>;
360
+ accept(base64offer: any): Promise<string>;
361
+ connect(base64accept: any): void;
362
+ setupPeer(initiator?: boolean): Promise<string>;
363
+ peer: any;
364
+ backlog(): Promise<any>;
365
+ gotData(data: any): Promise<void>;
366
+ sendUpdate(blockstore: any): Promise<void>;
367
+ startSync(): Promise<void>;
368
+ }
369
+ type Database = Database$1;
370
+
334
371
  declare class Fireproof {
335
372
  /**
336
373
  * @function storage
@@ -340,11 +377,10 @@ declare class Fireproof {
340
377
  * @static
341
378
  * @returns {Database} - a new Fireproof instance
342
379
  */
343
- static storage: (name?: any, opts?: {}) => Database;
380
+ static storage: (name?: any, opts?: {}) => Database$1;
344
381
  static fromJSON(json: any, database: any): any;
345
382
  static snapshot(database: any, clock: any): any;
346
383
  static zoom(database: any, clock: any): Promise<any>;
347
- static makeCar(database: any, key: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
348
384
  }
349
385
 
350
- export { Database, Fireproof, DbIndex as Index, Listener };
386
+ export { Database$1 as Database, Fireproof, DbIndex as Index, Listener, Sync };