@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.d.ts
CHANGED
@@ -19,7 +19,7 @@ declare class Fireproof {
|
|
19
19
|
* @static
|
20
20
|
* @returns {Fireproof} - a new Fireproof instance
|
21
21
|
*/
|
22
|
-
static storage: (name?:
|
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
|
-
//
|
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
|
-
|
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.
|
37278
|
+
if (this.remoteBlockFunction) {
|
37275
37279
|
// todo why is this on valet?
|
37276
|
-
const value = await husher(key, async () => await this.
|
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 =
|
38031
|
-
|
38032
|
-
|
38033
|
-
|
38034
|
-
|
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
|
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
|
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
|
-
|
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
|
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.
|