-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.js
More file actions
27 lines (26 loc) · 748 Bytes
/
copy.js
File metadata and controls
27 lines (26 loc) · 748 Bytes
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
import { crocks, R } from './deps.js';
const { Async } = crocks;
const { compose, prop, last } = R;
const FINISHED = '__FINISHED__';
const lastId = compose(prop('id'), last);
const isOk = (result) => result.ok ? Async.of(result) : Async.Rejected('Error Copying Data');
const checkFinished = (limit) => (xs) => xs.length === limit ? lastId(xs) : FINISHED;
/**
* @param {Async} list
* @param {Async} bulk
*/
export default function (list, bulk) {
/**
* @param {Number} limit
* @param {string} startkey
*/
return function (limit, startkey) {
return Async.of({ limit, startkey })
.chain(list)
.map(prop('docs'))
.chain(bulk)
.chain(isOk)
.map(prop('results'))
.map(checkFinished(limit));
};
}