Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
pouchdb-sync-to-anything
Advanced tools
Use PouchDB's sequences and checkpoints to sync to something that's not CouchDB
This is a plugin that lets you use CouchDBs replication algorithm with checkpointing, resuming, etc, but provide your own function to write the documents. This can be used to sequentially write updates to a REST API,
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-sync-to-anything')
var myDb = new PouchDB('exampleDB')
myDb.syncToAnything(function (docs) {
// Sync function receives a document batch
// Should return a promise
// Example:
return $.ajax({
url: 'http://example.com/my-rest-endpoint',
data: JSON.stringify(docs),
method: 'POST'
})
}, {
sync_id: 'talkingToMyRestAPI',
batch_size: 10
})
A function which you use for writing whatever you need to write the documents to. Should return a promise. The function will be passed an array of documents that is minimum 1 document (never called empty) and maximum batch_size
documents.
sync_id
or syncId
(string) required used as a checkpoint name. Change this to something else and the replication will start over from 0.batch_size
(number) the number of documents passed in to the syncer
function.This is a partial implementation of the CouchDB replication protocol. It allows you to use PouchDB's tools to save replication checkpoints for syncing with your API. Using those checkpoints, we can start the next replication from the last good checkpoint.
Every write you make to a PouchDB/CouchDB instance has a sequence number
. This is the base for the replication protocol, we use it to read every change that was made sequentially from the database.
Using the sync_id
passed in from the user, read the last sync checkpoint (will be 0 if we never synced before with that id).
Read the changes feed from the PouchDB, limiting the number of changes to batch_size
.
Call the user provided sync function, passing in the documents from the changes batch. The sync function should return a promise that fails if the write failed.
If the sync promise resolves, write a checkpoint of the last sequence numbers from the written batch
Go back to 1
Using this works best for one way data-flows only. If you're interested in a 2-way data flow, consider syncing data from the server to a different PouchDB instance, and write changes that are to be sent to the server separately.
A document is only sent to the sync function once per sync cycle. If you create a document, hit your sync function, update the document twice, and then hit sync again, it will be passed to the sync function once in the first sync call, and once in the second sync call.
FAQs
Use PouchDB's sequences and checkpoints to sync to something that's not CouchDB
The npm package pouchdb-sync-to-anything receives a total of 50 weekly downloads. As such, pouchdb-sync-to-anything popularity was classified as not popular.
We found that pouchdb-sync-to-anything demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.