-
Notifications
You must be signed in to change notification settings - Fork 1
/
ductile.coffee
53 lines (40 loc) · 1.42 KB
/
ductile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
parse = require './parse'
mixin = require './mixin'
reader = require './reader'
alias = require './alias'
mappings = require './mappings'
settings = require './settings'
template = require './template'
writer = require './writer'
queryToSearch = require './query-to-search'
wait = -> new Promise (rs) -> setTimeout (->rs()), 1000
module.exports = (url) ->
target = parse(url)
client = require('./es') target
# holds {q}
search = queryToSearch(target.query)
reader: (lsearch, operdelete, trans) ->
# merged search in order of precedence
msearch = mixin search, lsearch, {index:target.index, type:target.type}
reader(client, msearch, operdelete, trans)
wait: (wantwait) ->
_self = this
return Promise.resolve(_self) unless wantwait
dowait = -> wait().then ->
client.ping()
.then ->
_self
.catch (err) ->
# not up, try again
dowait()
dowait()
alias: ->
alias(client, {index:target.index})
settings: ->
settings(client, {index:target.index})
mappings: ->
mappings(client, {index:target.index, type:target.type})
template: ->
template(client, {name:target.index})
writer: (operdelete, trans, instream) ->
writer(client, {index:target.index, type:target.type}, operdelete, trans, instream)