New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

aolog

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aolog - npm Package Compare versions

Comparing version 1.0.4 to 1.1.1

99

index.js

@@ -63,3 +63,9 @@ 'use strict'

var Ref = function (pointsto, hash, filters) {
var Ref = function (pointsto, hash, filters, count) {
if (typeof count === 'undefined') {
count = pointsto.count
} else {
count = count
}
return {

@@ -69,2 +75,3 @@ type: 'Ref',

ref: pointsto,
count: count,
hash: hash,

@@ -127,2 +134,3 @@ append: function (el, cb) {

elements: elements || [],
count: elements.length,
append: function (el, cb) {

@@ -173,57 +181,18 @@ if (this.elements.length === BUCKET_SIZE) {

var self = this
var filters = {}
// bucket of refs?
if (this.elements[0] &&
typeof this.elements[0].filter === 'function') {
async.series(_.map(self.elements, function (element, idx) {
var name = zeropad(idx)
filters[name] = serialize_filters(self.elements[idx].filters)
return function (done) {
element.persist(function (err, persisted) {
if (err) return done(err)
done(null, {
Name: name,
Hash: persisted.Hash,
Size: persisted.Size
})
})
}
}), function (err, links) {
if (err) return cb(err)
var obj = {
Data: JSON.stringify({
type: 'Bucket',
filters: filters
}),
Links: links
}
var buf = new Buffer(JSON.stringify(obj))
ipfs.object.put(buf, 'json', function (err, put) {
if (err) return cb(err)
ipfs.object.stat(put.Hash, function (err, stat) {
if (err) return cb(err)
cb(null, {Hash: put.Hash,
Size: stat.CumulativeSize})
})
})
})
} else {
var obj = {Data:
JSON.stringify({
type: 'Bucket',
data: this
}),
Links: []}
var buf = new Buffer(JSON.stringify(obj))
ipfs.object.put(buf, 'json', function (err, put) {
var buf = new Buffer(JSON.stringify({
Data: JSON.stringify({
type: 'Bucket',
data: this
}),
Links: []
}))
ipfs.object.put(buf, 'json', function (err, put) {
if (err) return cb(err)
ipfs.object.stat(put.Hash, function (err, stat) {
if (err) return cb(err)
ipfs.object.stat(put.Hash, function (err, stat) {
if (err) return cb(err)
cb(null, {Hash: put.Hash,
Size: stat.CumulativeSize})
})
cb(null, {Hash: put.Hash,
Size: stat.CumulativeSize})
})
}
})
}

@@ -237,2 +206,5 @@ }

refs: refs,
count: _.reduce(refs, function (a, b) {
return a + b.count;
}, 0),
append: function (el, cb) {

@@ -272,5 +244,7 @@ if (this.refs.length === BUCKET_SIZE) {

var filters = {}
var counts = {}
async.series(_.map(self.refs, function (ref, idx) {
var name = zeropad(idx)
filters[name] = serialize_filters(self.refs[idx].filters)
counts[name] = self.refs[idx].count
return function (done) {

@@ -292,2 +266,3 @@ ref.persist(function (err, persisted) {

type: self.type,
counts: counts,
filters: filters

@@ -318,2 +293,3 @@ }),

head: head,
count: head.count + rest.count + tail.count,
append: function (el, cb) {

@@ -355,4 +331,6 @@ tail.append(el, function (err, newtail) {

var filters = {}
var counts = {}
async.series(_.map(['head', 'rest', 'tail'], function (part) {
filters[part] = serialize_filters(self[part].filters)
counts[part] = self[part].count
return function (done) {

@@ -374,3 +352,4 @@ self[part].persist(function (err, persisted) {

type: 'Finger',
filters: filters
filters: filters,
counts: counts
}),

@@ -493,3 +472,4 @@ Links: links

link.Hash,
deserialize_filters(object.filters[zeropad(idx)]))
deserialize_filters(object.filters[zeropad(idx)]),
object.counts[zeropad(idx)])
})))

@@ -503,9 +483,12 @@ } else if (object.type === 'Finger') {

linkmap.head,
deserialize_filters(object.filters.head)),
deserialize_filters(object.filters.head),
object.counts.head),
new Ref(null,
linkmap.rest,
deserialize_filters(object.filters.rest)),
deserialize_filters(object.filters.rest),
object.counts.rest),
new Ref(null,
linkmap.tail,
deserialize_filters(object.filters.tail))))
deserialize_filters(object.filters.tail),
object.counts.tail)))
}

@@ -512,0 +495,0 @@ })

{
"name": "aolog",
"version": "1.0.4",
"version": "1.1.1",
"description": "Append only log",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,3 +14,3 @@ 'use strict'

if (!count--) return next(1)
var add = fn(i++)
var add = fn(i++, log)
log.append(add, function (err, res) {

@@ -416,2 +416,17 @@ if (err) throw err

describe('count', function () {
var SIZE = BUCKET_SIZE * 10
it('should have the correct count always', function (done) {
add_many(aolog.empty(), SIZE,
function (i, current) {
assert.equal(i, current.count)
return i
},
function (err, res) {
if (err) throw err
done()
})
})
})
describe('persistance', function () {

@@ -637,2 +652,31 @@ describe('persist bucket', function () {

describe('persist count', function () {
var SIZE = BUCKET_SIZE * 10
var log, plog, nlog
before(function (done) {
add_many(aolog.empty(), SIZE, function (i) { return { is: "i = " + i } },
function (err, res) {
if (err) throw err
log = res
done()
})
})
before(function (done) {
log.persist(function (err, persisted) {
if (err) throw err
aolog.restore(persisted.Hash, function (err, res) {
if (err) throw err
nlog = res
done()
})
})
})
it('should have persisted count', function () {
assert.equal(log.count, nlog.count)
})
})
describe('persist, restore, add, persist', function () {

@@ -639,0 +683,0 @@

Sorry, the diff of this file is too big to display

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