|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -const callbackify = require('callbackify') |
4 |
| -const errCode = require('err-code') |
5 |
| -const { collectify } = require('../lib/converters') |
6 |
| - |
7 |
| -module.exports = config => { |
8 |
| - const get = require('./get')(config) |
9 |
| - const findPeer = require('./find-peer')(config) |
10 |
| - |
11 |
| - return { |
12 |
| - get: callbackify.variadic(async (key, options) => { |
13 |
| - for await (const value of get(key, options)) { |
14 |
| - return value |
15 |
| - } |
16 |
| - throw errCode(new Error('value not found'), 'ERR_TYPE_5_NOT_FOUND') |
17 |
| - }), |
18 |
| - put: callbackify.variadic(collectify(require('./put')(config))), |
19 |
| - findProvs: callbackify.variadic(collectify(require('./find-provs')(config))), |
20 |
| - findPeer: callbackify.variadic(async (peerId, options) => { |
21 |
| - for await (const peerInfo of findPeer(peerId, options)) { |
22 |
| - return peerInfo |
23 |
| - } |
24 |
| - throw errCode(new Error('final peer not found'), 'ERR_TYPE_2_NOT_FOUND') |
25 |
| - }), |
26 |
| - provide: callbackify.variadic(collectify(require('./provide')(config))), |
27 |
| - // find closest peerId to given peerId |
28 |
| - query: callbackify.variadic(collectify(require('./query')(config))) |
29 |
| - } |
30 |
| -} |
| 3 | +module.exports = config => ({ |
| 4 | + get: require('./get')(config), |
| 5 | + put: require('./put')(config), |
| 6 | + findProvs: require('./find-provs')(config), |
| 7 | + findPeer: require('./find-peer')(config), |
| 8 | + provide: require('./provide')(config), |
| 9 | + // find closest peerId to given peerId |
| 10 | + query: require('./query')(config) |
| 11 | +}) |
0 commit comments