@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.
- package/dist/blockstore.js +242 -0
- package/dist/clock.js +355 -0
- package/dist/crypto.js +59 -0
- package/dist/database.js +308 -0
- package/dist/db-index.js +314 -0
- package/dist/fireproof.js +83 -0
- package/dist/hooks/use-fireproof.js +100 -0
- package/dist/listener.js +110 -0
- package/dist/prolly.js +316 -0
- package/dist/sha1.js +74 -0
- package/dist/src/blockstore.js +242 -0
- package/dist/src/clock.js +355 -0
- package/dist/src/crypto.js +59 -0
- package/dist/src/database.js +312 -0
- package/dist/src/db-index.js +314 -0
- package/dist/src/fireproof.d.ts +319 -0
- package/dist/src/fireproof.js +38976 -0
- package/dist/src/fireproof.js.map +1 -0
- package/dist/src/fireproof.mjs +38972 -0
- package/dist/src/fireproof.mjs.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +21 -16
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +21 -16
- package/dist/src/index.mjs.map +1 -1
- package/dist/src/listener.js +108 -0
- package/dist/src/prolly.js +319 -0
- package/dist/src/sha1.js +74 -0
- package/dist/src/utils.js +16 -0
- package/dist/src/valet.js +262 -0
- package/dist/test/block.js +57 -0
- package/dist/test/clock.test.js +556 -0
- package/dist/test/db-index.test.js +231 -0
- package/dist/test/fireproof.test.js +444 -0
- package/dist/test/fulltext.test.js +61 -0
- package/dist/test/helpers.js +39 -0
- package/dist/test/hydrator.test.js +142 -0
- package/dist/test/listener.test.js +103 -0
- package/dist/test/prolly.test.js +162 -0
- package/dist/test/proofs.test.js +45 -0
- package/dist/test/reproduce-fixture-bug.test.js +57 -0
- package/dist/test/valet.test.js +56 -0
- package/dist/utils.js +16 -0
- package/dist/valet.js +262 -0
- package/hooks/use-fireproof.js +38 -63
- package/package.json +13 -14
- package/src/blockstore.js +8 -4
- package/src/database.js +338 -0
- package/src/db-index.js +3 -3
- package/src/fireproof.js +65 -322
- package/src/listener.js +10 -8
- package/src/prolly.js +10 -6
- package/src/utils.js +16 -0
- package/src/valet.js +2 -2
- package/src/hydrator.js +0 -54
- package/src/index.js +0 -6
package/dist/src/index.mjs
CHANGED
@@ -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
|
-
//
|
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
|
-
|
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.
|
37276
|
+
if (this.remoteBlockFunction) {
|
37273
37277
|
// todo why is this on valet?
|
37274
|
-
const value = await husher(key, async () => await this.
|
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 =
|
38029
|
-
|
38030
|
-
|
38031
|
-
|
38032
|
-
|
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
|
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
|
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
|
-
|
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
|
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.
|