UNPKG

679 Btext/coffeescriptView Raw
1through2 = require 'through2'
2mixin = require './mixin'
3
4
5toBulk = -> through2.obj (doc, enc, callback) ->
6 this.push template:doc
7 callback()
8
9
10jsonStream = -> through2.obj (chunk, enc, callback) ->
11 this.push(JSON.stringify(chunk) + "\n")
12 callback()
13
14
15module.exports = (client, _opts) ->
16
17 opts = mixin _opts
18
19 instream = toBulk()
20 sink = instream.write.bind instream
21
22 exec = ->
23 client.indices.getTemplate(opts).then (v) ->
24 {_name:name, _template:template} for name, template of v
25
26 exec().then (docs) ->
27 docs.forEach sink
28 .catch (err) ->
29 stream.emit 'error', err
30
31 stream = instream.pipe jsonStream()