@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
@@ -36928,8 +36928,8 @@ function rawSha1 (b) {
36928
36928
 
36929
36929
  const chunker = bf(3);
36930
36930
 
36931
- const NO_ENCRYPT = process.env?.NO_ENCRYPT;
36932
- // typeof process !== 'undefined' ? process.env.NO_ENCRYPT : import.meta && import.meta.env.VITE_NO_ENCRYPT
36931
+ const NO_ENCRYPT = typeof process !== 'undefined' && !!process.env?.NO_ENCRYPT;
36932
+ // ? process.env.NO_ENCRYPT : import.meta && import.meta.env.VITE_NO_ENCRYPT
36933
36933
 
36934
36934
  class Valet {
36935
36935
  idb = null
@@ -37225,7 +37225,10 @@ class TransactionBlockstore {
37225
37225
  inflightTransactions = new Set()
37226
37226
 
37227
37227
  constructor (name, encryptionKey) {
37228
- this.valet = new Valet(name, encryptionKey);
37228
+ if (name) {
37229
+ this.valet = new Valet(name, encryptionKey);
37230
+ }
37231
+ this.remoteBlockFunction = null;
37229
37232
  }
37230
37233
 
37231
37234
  /**
@@ -37258,6 +37261,7 @@ class TransactionBlockstore {
37258
37261
  async committedGet (key) {
37259
37262
  const old = this.committedBlocks.get(key);
37260
37263
  if (old) return old
37264
+ if (!this.valet) throw new Error('Missing block: ' + key)
37261
37265
  const got = await this.valet.getBlock(key);
37262
37266
  // console.log('committedGet: ' + key)
37263
37267
  this.committedBlocks.set(key, got);
@@ -37269,9 +37273,9 @@ class TransactionBlockstore {
37269
37273
  }
37270
37274
 
37271
37275
  async networkGet (key) {
37272
- if (this.valet.remoteBlockFunction) {
37276
+ if (this.remoteBlockFunction) {
37273
37277
  // todo why is this on valet?
37274
- const value = await husher(key, async () => await this.valet.remoteBlockFunction(key));
37278
+ const value = await husher(key, async () => await this.remoteBlockFunction(key));
37275
37279
  if (value) {
37276
37280
  // console.log('networkGot: ' + key, value.length)
37277
37281
  doTransaction('networkGot: ' + key, this, async innerBlockstore => {
@@ -37349,7 +37353,7 @@ class TransactionBlockstore {
37349
37353
  cids.add(stringCid);
37350
37354
  }
37351
37355
  }
37352
- if (cids.size > 0) {
37356
+ if (cids.size > 0 && this.valet) {
37353
37357
  // console.log(innerBlockstore.label, 'committing', cids.size, 'blocks')
37354
37358
  await this.valet.writeTransaction(innerBlockstore, cids);
37355
37359
  }
@@ -38025,11 +38029,13 @@ class Fireproof {
38025
38029
  * @static
38026
38030
  * @returns {Fireproof} - a new Fireproof instance
38027
38031
  */
38028
- static storage = (name = 'global') => {
38029
- const instanceKey = browserExports(32).toString('hex'); // pass null to disable encryption
38030
- // pick a random key from const validatedKeys
38031
- // const instanceKey = validatedKeys[Math.floor(Math.random() * validatedKeys.length)]
38032
- return new Fireproof(new TransactionBlockstore(name, instanceKey), [], { name })
38032
+ static storage = (name = null) => {
38033
+ if (name) {
38034
+ const instanceKey = browserExports(32).toString('hex'); // pass null to disable encryption
38035
+ return new Fireproof(new TransactionBlockstore(name, instanceKey), [], { name })
38036
+ } else {
38037
+ return new Fireproof(new TransactionBlockstore(), [])
38038
+ }
38033
38039
  }
38034
38040
 
38035
38041
  constructor (blocks, clock, config, authCtx = {}) {
@@ -38053,7 +38059,7 @@ class Fireproof {
38053
38059
  return {
38054
38060
  clock: this.clockToJSON(),
38055
38061
  name: this.name,
38056
- key: this.blocks.valet.getKeyMaterial(),
38062
+ key: this.blocks.valet?.getKeyMaterial(),
38057
38063
  indexes: [...this.indexes.values()].map(index => index.toJSON())
38058
38064
  }
38059
38065
  }
@@ -38071,7 +38077,7 @@ class Fireproof {
38071
38077
  hydrate ({ clock, name, key }) {
38072
38078
  this.name = name;
38073
38079
  this.clock = clock;
38074
- this.blocks.valet.setKeyMaterial(key);
38080
+ this.blocks.valet?.setKeyMaterial(key);
38075
38081
  this.indexBlocks = null;
38076
38082
  }
38077
38083
 
@@ -38312,8 +38318,7 @@ class Fireproof {
38312
38318
  }
38313
38319
 
38314
38320
  setRemoteBlockReader (remoteBlockReaderFn) {
38315
- // console.log('registering remote block reader')
38316
- this.blocks.valet.remoteBlockFunction = remoteBlockReaderFn;
38321
+ this.blocks.remoteBlockFunction = remoteBlockReaderFn;
38317
38322
  }
38318
38323
  }
38319
38324
 
@@ -38536,7 +38541,7 @@ class DbIndex {
38536
38541
  constructor (database, mapFn, clock, opts = {}) {
38537
38542
  this.database = database;
38538
38543
  if (!database.indexBlocks) {
38539
- database.indexBlocks = new TransactionBlockstore(database.name + '.indexes', database.blocks.valet.getKeyMaterial());
38544
+ database.indexBlocks = new TransactionBlockstore(database?.name + '.indexes', database.blocks.valet?.getKeyMaterial());
38540
38545
  }
38541
38546
  /**
38542
38547
  * The map function to apply to each entry in the database.