Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@synonymdev/feeds

Package Overview
Dependencies
Maintainers
10
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@synonymdev/feeds - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

68

index.js

@@ -9,3 +9,2 @@ const os = require('os')

const Hyperdrive = require('hyperdrive')
const deepEqual = require('deep-equal')

@@ -26,2 +25,3 @@ const DEFAULT_PATH = path.join(os.homedir(), '.slashtags-feeds')

this.header = header
this.drives = []
}

@@ -33,2 +33,8 @@

async close () {
// close the drives (one at a time)
for (let i = 0; i < this.drives.length; i += 1) {
await this.drives[i].hyperdrive.close()
}
this.drives = []
await this.corestore.close()

@@ -62,3 +68,4 @@ return this.swarm.destroy()

await this._ensureHeader(drive)
const headerContent = Buffer.from(JSON.stringify(this.header))
await this.ensureFile(feedID, Feeds.HEADER_PATH, headerContent)

@@ -71,23 +78,15 @@ return {

async _ensureHeader (drive) {
const batch = drive.batch()
const existing = await batch.get(Feeds.HEADER_PATH).then((buf) => {
return buf && JSON.parse(buf.toString())
})
const skip = existing && deepEqual(existing, this.header)
if (skip) return batch.flush()
_drive (feedID) {
const drive = this.drives.find((d) => d.feedID === feedID)
if (drive) {
return drive.hyperdrive
}
await batch.put(
Feeds.HEADER_PATH,
Buffer.from(JSON.stringify(this.header))
)
await batch.flush()
}
_drive (feedID) {
// don't have this one yet, make it
const namespace = this.corestore.namespace(feedID)
const encryptionKey = hash(namespace._namespace)
const drive = new Hyperdrive(namespace, { encryptionKey })
const hyperdrive = new Hyperdrive(namespace, { encryptionKey })
this.drives.push({ feedID, hyperdrive })
return drive
return hyperdrive
}

@@ -123,2 +122,33 @@

/**
* Deletes an old file that is not needed any more
* @param {} feedID
* @param {*} key
*/
async deleteFile (feedID, key) {
const drive = await this._drive(feedID)
await drive.del(key)
}
/**
* Ensures a file exists and writes it if missing or out of date
* Returns true if the file was missing and needed to be written
* @param {string} feedID
* @param {string} key
* @param {SerializableItem} value
*/
async ensureFile (feedID, key, data) {
const drive = await this._drive(feedID)
const batch = drive.batch()
const existing = await batch.get(key)
if (existing && existing.equals(data)) {
await batch.flush()
return false
}
await batch.put(key, data)
await batch.flush()
return true
}
/**
* Delete the feed from storage

@@ -125,0 +155,0 @@ * @param {string} feedID

{
"name": "@synonymdev/feeds",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"scripts": {

@@ -10,6 +10,4 @@ "test": "standard --fix && node test/all.js"

"corestore": "^6.0.1-alpha.19",
"deep-equal": "^2.0.5",
"hyperdrive": "github:Nazeh/hyperdrive-next#pass-options",
"hyperswarm": "^4.2.0",
"just-compare": "^2.2.2",
"sodium-universal": "^3.1.0"

@@ -22,2 +20,2 @@ },

}
}
}

@@ -40,3 +40,3 @@ const Feeds = require('../index.js')

feed.key.toString('hex'),
'3ea919d3dd3fc7ba82d24df6a04ca972dcac66a2470e6fbea2008437072214a1'
'b5fd1f1df9204f61ab6f5741a1471f14ee1541c833f2233258e4ee3f59a65dbe'
)

@@ -50,3 +50,3 @@ t.is(

feed2.key.toString('hex'),
'c09510a75f0296cc935b9dc3d39bda113d5d9552751722e5ce4e3d2326446173'
'7843365d5054795fd61238f8fd1d6c534ca7abd17913705911b3a074ce45171d'
)

@@ -53,0 +53,0 @@ t.is(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc