@fireproof/core 0.5.3 → 0.5.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Cloudless database for apps, the browser, and IPFS",
5
5
  "main": "dist/src/fireproof.js",
6
6
  "module": "dist/src/fireproof.mjs",
package/src/database.js CHANGED
@@ -3,12 +3,14 @@ import { visMerkleClock, visMerkleTree, vis, put, get, getAll, eventsSince } fro
3
3
  import { doTransaction } from './blockstore.js'
4
4
  import charwise from 'charwise'
5
5
  import { localSet } from './utils.js'
6
+ import { CID } from 'multiformats'
6
7
 
7
8
  // TypeScript Types
8
9
  // eslint-disable-next-line no-unused-vars
9
10
  // import { CID } from 'multiformats/dist/types/src/cid.js'
10
11
  // eslint-disable-next-line no-unused-vars
11
12
  class Proof {}
13
+ export const parseCID = cid => (typeof cid === 'string' ? CID.parse(cid) : cid)
12
14
 
13
15
  /**
14
16
  * @class Fireproof
package/src/db-index.js CHANGED
@@ -244,7 +244,7 @@ export class DbIndex {
244
244
  let removeByIdIndexEntries = []
245
245
  await loadIndex(blocks, this.indexById, idIndexOpts)
246
246
  await loadIndex(blocks, this.indexByKey, dbIndexOpts)
247
- console.log('head', this.dbHead, this.indexById)
247
+ // console.log('head', this.dbHead, this.indexById)
248
248
  if (this.indexById.root) {
249
249
  const oldChangeEntries = await this.indexById.root.getMany(result.rows.map(({ key }) => key))
250
250
  oldIndexEntries = oldChangeEntries.result.map((key) => ({ key, del: true }))
@@ -293,13 +293,18 @@ async function bulkIndex (blocks, inIndex, indexEntries, opts) {
293
293
  inIndex.root = await load({ cid, get: getBlock, ...dbIndexOpts })
294
294
  }
295
295
  const { root, blocks: newBlocks } = await inIndex.root.bulk(indexEntries)
296
- returnRootBlock = await root.block
297
- returnNode = root
298
- for await (const block of newBlocks) {
299
- await putBlock(block.cid, block.bytes)
296
+ if (root) {
297
+ returnRootBlock = await root.block
298
+ returnNode = root
299
+ for await (const block of newBlocks) {
300
+ await putBlock(block.cid, block.bytes)
301
+ }
302
+ await putBlock(returnRootBlock.cid, returnRootBlock.bytes)
303
+ return { root: returnNode, cid: returnRootBlock.cid }
304
+ } else {
305
+ // throw new Error('test for index after delete')
306
+ return { root: null, cid: null }
300
307
  }
301
- await putBlock(returnRootBlock.cid, returnRootBlock.bytes)
302
- return { root: returnNode, cid: returnRootBlock.cid }
303
308
  }
304
309
 
305
310
  async function loadIndex (blocks, index, indexOpts) {
package/src/fireproof.js CHANGED
@@ -1,17 +1,14 @@
1
1
  import randomBytes from 'randombytes'
2
2
 
3
- import { Database } from './database.js'
3
+ import { Database, parseCID } from './database.js'
4
4
  import { Listener } from './listener.js'
5
5
  import { DbIndex as Index } from './db-index.js'
6
- import { CID } from 'multiformats'
7
6
  import { TransactionBlockstore } from './blockstore.js'
8
7
  import { localGet } from './utils.js'
9
8
  import { blocksToCarBlock, blocksToEncryptedCarBlock } from './valet.js'
10
9
 
11
10
  export { Index, Listener, Database }
12
11
 
13
- const parseCID = cid => (typeof cid === 'string' ? CID.parse(cid) : cid)
14
-
15
12
  export class Fireproof {
16
13
  /**
17
14
  * @function storage
@@ -95,7 +92,7 @@ export class Fireproof {
95
92
  const allCIDs = await database.allCIDs()
96
93
  const blocks = database.blocks
97
94
 
98
- const rootCid = CID.parse(allCIDs[allCIDs.length - 1])
95
+ const rootCid = parseCID(allCIDs[allCIDs.length - 1])
99
96
  if (typeof key === 'undefined') {
100
97
  key = blocks.valet?.getKeyMaterial()
101
98
  }
@@ -113,7 +110,9 @@ export class Fireproof {
113
110
  allCIDs.map(async c => {
114
111
  const b = await blocks.get(c)
115
112
  // console.log('block', b)
116
- if (typeof b.cid === 'string') { b.cid = CID.parse(b.cid) }
113
+ if (typeof b.cid === 'string') {
114
+ b.cid = parseCID(b.cid)
115
+ }
117
116
  // if (b.bytes.constructor.name === 'Buffer') console.log('conver vbuff')
118
117
  return b
119
118
  })
package/src/listener.js CHANGED
@@ -41,9 +41,9 @@ export class Listener {
41
41
  * @returns {Function} A function to unsubscribe from the topic.
42
42
  * @memberof Listener
43
43
  * @instance
44
- * @param {any} since
44
+ * @param {any} [since] - clock to flush from on launch
45
45
  */
46
- on (topic, subscriber, since) {
46
+ on (topic, subscriber, since = undefined) {
47
47
  const listOfTopicSubscribers = getTopicList(this.subcribers, topic)
48
48
  listOfTopicSubscribers.push(subscriber)
49
49
  if (typeof since !== 'undefined') {