-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(addendum): allow arbitrary data to be stored alongside the rest …
…of the document
- Loading branch information
1 parent
6fc4cf0
commit 8fdb82c
Showing
8 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
// Select the codec used for functionality which requires | ||
// encoding/decoding data before being sent to elasticsearch. | ||
|
||
// JSON codec | ||
const json = { | ||
encode: (value) => JSON.stringify(value), | ||
decode: (text) => JSON.parse(text) | ||
}; | ||
|
||
// msgpack codec | ||
// const msgpack = require("msgpack-lite"); | ||
|
||
module.exports = json; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module.exports.Document = require('./Document'); | ||
module.exports.codec = require('./codec'); | ||
module.exports.createDocumentMapperStream = require('./DocumentMapperStream'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const Document = require('../../Document'); | ||
module.exports.tests = {}; | ||
|
||
const fixture = { | ||
wikipedia: { slug: 'Wikipedia', population: 100 }, | ||
custom: { example: [ 'Example' ] } | ||
}; | ||
|
||
module.exports.tests.getAddendum = function(test) { | ||
test('getAddendum', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.equal(doc.getAddendum('wikipedia'), undefined, 'getter works'); | ||
doc.addendum = fixture; | ||
t.equal(doc.getAddendum('wikipedia'), fixture.wikipedia, 'getter works'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.tests.setAddendum = function(test) { | ||
test('setAddendum', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.equal(doc.setAddendum('wikipedia',fixture.wikipedia), doc, 'chainable'); | ||
t.equal(doc.addendum.wikipedia, fixture.wikipedia, 'setter works'); | ||
t.end(); | ||
}); | ||
test('setAddendum - validate namespace', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.throws( doc.setAddendum.bind(doc,1,fixture), null, 'invalid type' ); | ||
t.throws( doc.setAddendum.bind(doc,'',fixture), null, 'invalid length' ); | ||
t.throws( doc.setAddendum.bind(doc,' ',fixture), null, 'invalid length' ); | ||
t.throws( doc.setAddendum.bind(doc,null,fixture), null, 'invalid length' ); | ||
t.equal(doc.getAddendum('test'), undefined, 'property not set'); | ||
t.end(); | ||
}); | ||
test('setAddendum - validate val', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.throws( doc.setAddendum.bind(doc,'wikipedia',1), null, 'invalid value' ); | ||
t.throws( doc.setAddendum.bind(doc,'wikipedia',''), null, 'invalid value' ); | ||
t.throws( doc.setAddendum.bind(doc,'wikipedia',' '), null, 'invalid value' ); | ||
t.throws( doc.setAddendum.bind(doc,'wikipedia',null), null, 'invalid value' ); | ||
t.throws( doc.setAddendum.bind(doc,'wikipedia','\t'), null, 'invalid value' ); | ||
t.equal(doc.getAddendum('test'), undefined, 'property not set'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.tests.hasAddendum = function(test) { | ||
test('hasAddendum', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.equal(doc.hasAddendum('wikipedia'), false, 'hasser works'); | ||
doc.addendum = fixture; | ||
t.equal(doc.hasAddendum('wikipedia'), true, 'hasser works'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.tests.delAddendum = function(test) { | ||
test('delAddendum', function(t) { | ||
var doc = new Document('mysource','mylayer','myid'); | ||
t.equal(doc.delAddendum('wikipedia'), false, 'deller works'); | ||
doc.addendum = fixture; | ||
t.equal(doc.delAddendum('wikipedia'), true, 'deller works'); | ||
t.equal(doc.addendum.wikipedia, undefined, 'deller works'); | ||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.all = function (tape, common) { | ||
|
||
function test(name, testFunction) { | ||
return tape('addendum: ' + name, testFunction); | ||
} | ||
|
||
for( var testCase in module.exports.tests ){ | ||
module.exports.tests[testCase](test, common); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters