@fireproof/core 0.5.2 → 0.5.4

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.2",
3
+ "version": "0.5.4",
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/db-index.js CHANGED
@@ -244,7 +244,8 @@ export class DbIndex {
244
244
  let removeByIdIndexEntries = []
245
245
  await loadIndex(blocks, this.indexById, idIndexOpts)
246
246
  await loadIndex(blocks, this.indexByKey, dbIndexOpts)
247
- if (this.dbHead) {
247
+ // console.log('head', this.dbHead, this.indexById)
248
+ if (this.indexById.root) {
248
249
  const oldChangeEntries = await this.indexById.root.getMany(result.rows.map(({ key }) => key))
249
250
  oldIndexEntries = oldChangeEntries.result.map((key) => ({ key, del: true }))
250
251
  removeByIdIndexEntries = oldIndexEntries.map(({ key }) => ({ key: key[1], del: true }))
@@ -292,13 +293,18 @@ async function bulkIndex (blocks, inIndex, indexEntries, opts) {
292
293
  inIndex.root = await load({ cid, get: getBlock, ...dbIndexOpts })
293
294
  }
294
295
  const { root, blocks: newBlocks } = await inIndex.root.bulk(indexEntries)
295
- returnRootBlock = await root.block
296
- returnNode = root
297
- for await (const block of newBlocks) {
298
- 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 }
299
307
  }
300
- await putBlock(returnRootBlock.cid, returnRootBlock.bytes)
301
- return { root: returnNode, cid: returnRootBlock.cid }
302
308
  }
303
309
 
304
310
  async function loadIndex (blocks, index, indexOpts) {
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') {