rethinkdb-elasticsearch-stream
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
/** | ||
@@ -20,11 +22,24 @@ * Replicate a document in Elasticsearch | ||
db, | ||
deleteTransform, | ||
document, | ||
esType, | ||
idKey, | ||
oldDocument, | ||
table, | ||
transform | ||
}) { | ||
// Transform the document if necessary | ||
const documentToSave = transform != null ? yield transform({ db, document, table }) : document; | ||
let documentToSave; | ||
// document will be null if the doc was deleted in Rethink | ||
if (document === null) { | ||
documentToSave = deleteTransform != null ? yield deleteTransform({ db, document, oldDocument, table }) | ||
// if a deleteTransform isn't provided, the default behavior is to just | ||
// delete the document from elastic search | ||
: _extends({}, oldDocument, { | ||
_delete: _._delete | ||
}); | ||
} else { | ||
documentToSave = transform != null ? yield transform({ db, document, oldDocument, table }) : document; | ||
} | ||
if (Array.isArray(documentToSave)) { | ||
@@ -31,0 +46,0 @@ return Promise.all(documentToSave.map(function (d) { |
@@ -34,3 +34,3 @@ 'use strict'; | ||
return dataStream.pipe((0, _through.obj)((() => { | ||
var _ref2 = _asyncToGenerator(function* ({ new_val: chunk }, enc, cb) { | ||
var _ref2 = _asyncToGenerator(function* ({ new_val: chunk, old_val: oldDocument }, enc, cb) { | ||
try { | ||
@@ -40,2 +40,3 @@ yield (0, _saveDocument2.default)(_extends({ | ||
document: chunk, | ||
oldDocument, | ||
table | ||
@@ -42,0 +43,0 @@ }, properties)); |
{ | ||
"name": "rethinkdb-elasticsearch-stream", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"main": "build/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/gsandf/rethinkdb-elasticsearch-stream", |
@@ -63,2 +63,21 @@ # rethinkdb-elasticsearch-stream | ||
db: 'megacorp', | ||
// (optional) Handle when a document is deleted in Rethink | ||
// This is detected when the new value for a document is null | ||
// If this is not specified, a DELETE is sent to Elasticsearch for the | ||
// id of the old value | ||
deleteTransform: async ({db, document, oldDocument, table }) => { | ||
if (await someImportantCheck()) { | ||
return oldDocument; | ||
} | ||
// this is the default behavior for a delete | ||
return { | ||
// import { _delete } from 'rethinkdb-elasticsearch-stream'; | ||
// | ||
// this is a special Symbol that tells the library that this should | ||
// be a DELETE. It can also be used in the regular transform function | ||
_delete | ||
id: oldDocument.id, | ||
} | ||
}, | ||
// (optional) Type field for Elasticsearch. This is similar to a "table" in | ||
@@ -77,5 +96,5 @@ // RethinkDB, and is the second portion of the URL path (index/db is the first). | ||
// `db` and `table` are specified for convenience | ||
transform: async ({ db, document, table }) => { | ||
transform: async ({ db, document, oldDocument, table }) => { | ||
await doSomethingImportant() | ||
return document | ||
return document; | ||
} | ||
@@ -82,0 +101,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
187064
388
128
0