@fireproof/core 0.3.21 → 0.4.0

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.
Files changed (56) hide show
  1. package/dist/blockstore.js +242 -0
  2. package/dist/clock.js +355 -0
  3. package/dist/crypto.js +59 -0
  4. package/dist/database.js +308 -0
  5. package/dist/db-index.js +314 -0
  6. package/dist/fireproof.js +83 -0
  7. package/dist/hooks/use-fireproof.js +100 -0
  8. package/dist/listener.js +110 -0
  9. package/dist/prolly.js +316 -0
  10. package/dist/sha1.js +74 -0
  11. package/dist/src/blockstore.js +242 -0
  12. package/dist/src/clock.js +355 -0
  13. package/dist/src/crypto.js +59 -0
  14. package/dist/src/database.js +312 -0
  15. package/dist/src/db-index.js +314 -0
  16. package/dist/src/fireproof.d.ts +319 -0
  17. package/dist/src/fireproof.js +38976 -0
  18. package/dist/src/fireproof.js.map +1 -0
  19. package/dist/src/fireproof.mjs +38972 -0
  20. package/dist/src/fireproof.mjs.map +1 -0
  21. package/dist/src/index.d.ts +1 -1
  22. package/dist/src/index.js +21 -16
  23. package/dist/src/index.js.map +1 -1
  24. package/dist/src/index.mjs +21 -16
  25. package/dist/src/index.mjs.map +1 -1
  26. package/dist/src/listener.js +108 -0
  27. package/dist/src/prolly.js +319 -0
  28. package/dist/src/sha1.js +74 -0
  29. package/dist/src/utils.js +16 -0
  30. package/dist/src/valet.js +262 -0
  31. package/dist/test/block.js +57 -0
  32. package/dist/test/clock.test.js +556 -0
  33. package/dist/test/db-index.test.js +231 -0
  34. package/dist/test/fireproof.test.js +444 -0
  35. package/dist/test/fulltext.test.js +61 -0
  36. package/dist/test/helpers.js +39 -0
  37. package/dist/test/hydrator.test.js +142 -0
  38. package/dist/test/listener.test.js +103 -0
  39. package/dist/test/prolly.test.js +162 -0
  40. package/dist/test/proofs.test.js +45 -0
  41. package/dist/test/reproduce-fixture-bug.test.js +57 -0
  42. package/dist/test/valet.test.js +56 -0
  43. package/dist/utils.js +16 -0
  44. package/dist/valet.js +262 -0
  45. package/hooks/use-fireproof.js +38 -63
  46. package/package.json +13 -14
  47. package/src/blockstore.js +8 -4
  48. package/src/database.js +338 -0
  49. package/src/db-index.js +3 -3
  50. package/src/fireproof.js +65 -322
  51. package/src/listener.js +10 -8
  52. package/src/prolly.js +10 -6
  53. package/src/utils.js +16 -0
  54. package/src/valet.js +2 -2
  55. package/src/hydrator.js +0 -54
  56. package/src/index.js +0 -6
@@ -19,7 +19,7 @@ declare class Fireproof {
19
19
  * @static
20
20
  * @returns {Fireproof} - a new Fireproof instance
21
21
  */
22
- static storage: (name?: string) => Fireproof;
22
+ static storage: (name?: any) => Fireproof;
23
23
  constructor(blocks: any, clock: any, config: any, authCtx?: {});
24
24
  listeners: Set<any>;
25
25
  name: any;
package/dist/src/index.js CHANGED
@@ -36930,8 +36930,8 @@ function rawSha1 (b) {
36930
36930
 
36931
36931
  const chunker = bf(3);
36932
36932
 
36933
- const NO_ENCRYPT = process.env?.NO_ENCRYPT;
36934
- // typeof process !== 'undefined' ? process.env.NO_ENCRYPT : import.meta && import.meta.env.VITE_NO_ENCRYPT
36933
+ const NO_ENCRYPT = typeof process !== 'undefined' && !!process.env?.NO_ENCRYPT;
36934
+ // ? process.env.NO_ENCRYPT : import.meta && import.meta.env.VITE_NO_ENCRYPT
36935
36935
 
36936
36936
  class Valet {
36937
36937
  idb = null
@@ -37227,7 +37227,10 @@ class TransactionBlockstore {
37227
37227
  inflightTransactions = new Set()
37228
37228
 
37229
37229
  constructor (name, encryptionKey) {
37230
- this.valet = new Valet(name, encryptionKey);
37230
+ if (name) {
37231
+ this.valet = new Valet(name, encryptionKey);
37232
+ }
37233
+ this.remoteBlockFunction = null;
37231
37234
  }
37232
37235
 
37233
37236
  /**
@@ -37260,6 +37263,7 @@ class TransactionBlockstore {
37260
37263
  async committedGet (key) {
37261
37264
  const old = this.committedBlocks.get(key);
37262
37265
  if (old) return old
37266
+ if (!this.valet) throw new Error('Missing block: ' + key)
37263
37267
  const got = await this.valet.getBlock(key);
37264
37268
  // console.log('committedGet: ' + key)
37265
37269
  this.committedBlocks.set(key, got);
@@ -37271,9 +37275,9 @@ class TransactionBlockstore {
37271
37275
  }
37272
37276
 
37273
37277
  async networkGet (key) {
37274
- if (this.valet.remoteBlockFunction) {
37278
+ if (this.remoteBlockFunction) {
37275
37279
  // todo why is this on valet?
37276
- const value = await husher(key, async () => await this.valet.remoteBlockFunction(key));
37280
+ const value = await husher(key, async () => await this.remoteBlockFunction(key));
37277
37281
  if (value) {
37278
37282
  // console.log('networkGot: ' + key, value.length)
37279
37283
  doTransaction('networkGot: ' + key, this, async innerBlockstore => {
@@ -37351,7 +37355,7 @@ class TransactionBlockstore {
37351
37355
  cids.add(stringCid);
37352
37356
  }
37353
37357
  }
37354
- if (cids.size > 0) {
37358
+ if (cids.size > 0 && this.valet) {
37355
37359
  // console.log(innerBlockstore.label, 'committing', cids.size, 'blocks')
37356
37360
  await this.valet.writeTransaction(innerBlockstore, cids);
37357
37361
  }
@@ -38027,11 +38031,13 @@ class Fireproof {
38027
38031
  * @static
38028
38032
  * @returns {Fireproof} - a new Fireproof instance
38029
38033
  */
38030
- static storage = (name = 'global') => {
38031
- const instanceKey = browserExports(32).toString('hex'); // pass null to disable encryption
38032
- // pick a random key from const validatedKeys
38033
- // const instanceKey = validatedKeys[Math.floor(Math.random() * validatedKeys.length)]
38034
- return new Fireproof(new TransactionBlockstore(name, instanceKey), [], { name })
38034
+ static storage = (name = null) => {
38035
+ if (name) {
38036
+ const instanceKey = browserExports(32).toString('hex'); // pass null to disable encryption
38037
+ return new Fireproof(new TransactionBlockstore(name, instanceKey), [], { name })
38038
+ } else {
38039
+ return new Fireproof(new TransactionBlockstore(), [])
38040
+ }
38035
38041
  }
38036
38042
 
38037
38043
  constructor (blocks, clock, config, authCtx = {}) {
@@ -38055,7 +38061,7 @@ class Fireproof {
38055
38061
  return {
38056
38062
  clock: this.clockToJSON(),
38057
38063
  name: this.name,
38058
- key: this.blocks.valet.getKeyMaterial(),
38064
+ key: this.blocks.valet?.getKeyMaterial(),
38059
38065
  indexes: [...this.indexes.values()].map(index => index.toJSON())
38060
38066
  }
38061
38067
  }
@@ -38073,7 +38079,7 @@ class Fireproof {
38073
38079
  hydrate ({ clock, name, key }) {
38074
38080
  this.name = name;
38075
38081
  this.clock = clock;
38076
- this.blocks.valet.setKeyMaterial(key);
38082
+ this.blocks.valet?.setKeyMaterial(key);
38077
38083
  this.indexBlocks = null;
38078
38084
  }
38079
38085
 
@@ -38314,8 +38320,7 @@ class Fireproof {
38314
38320
  }
38315
38321
 
38316
38322
  setRemoteBlockReader (remoteBlockReaderFn) {
38317
- // console.log('registering remote block reader')
38318
- this.blocks.valet.remoteBlockFunction = remoteBlockReaderFn;
38323
+ this.blocks.remoteBlockFunction = remoteBlockReaderFn;
38319
38324
  }
38320
38325
  }
38321
38326
 
@@ -38538,7 +38543,7 @@ class DbIndex {
38538
38543
  constructor (database, mapFn, clock, opts = {}) {
38539
38544
  this.database = database;
38540
38545
  if (!database.indexBlocks) {
38541
- database.indexBlocks = new TransactionBlockstore(database.name + '.indexes', database.blocks.valet.getKeyMaterial());
38546
+ database.indexBlocks = new TransactionBlockstore(database?.name + '.indexes', database.blocks.valet?.getKeyMaterial());
38542
38547
  }
38543
38548
  /**
38544
38549
  * The map function to apply to each entry in the database.