CodeForPhilly / jawn

'Git for Tabular Data'
http://datjawn.com
BSD 3-Clause "New" or "Revised" License
44 stars 9 forks source link

Story: Diff two feeds #29

Open flyingzumwalt opened 8 years ago

flyingzumwalt commented 8 years ago

This is a Work in Progress

If I run jawn.diff(feedOneId, feedTwoId) I should get a stream of json objects representing actions (add/update/delete).

If I apply all of the actions in that stream to the database/repository represented by feedOne, its contents should then match feedTwo.

Running a diff

Checkout a feed, run a diff and print the results of the diff.

var jawn = require('jawn');
var through = require('through2').obj;

var checkout = jawn.checkout(feedOneId);
checkout.on('end', function () {
  jawn.diff(feedOneId, feedTwoId).pipe(process.stdout)
});

The output should look roughly like this: (see 2015 dat beta for real examples)

{ action: "add", key: 9812349878, values: {...} }
{ action: "delete", key: 23421341234 }

Applying a diff using (hypothetical) jawn.applyActionStream function

var jawn = require('jawn');
var through = require('through2').obj;

var checkout = jawn.checkout(feedOneId);
var applyActions =  jawn.applyActionStream

checkout.on('end', function () {
  jawn.diff(feedOneId, feedTwoId).pipe(applyActions)
})

applyActions.on('end', function () {
  // the current contents of the repo should match the contents of feedTwo
  t.same('', jawn.diff(jawn.current, feedTwoId))
})