This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.js
148 lines (133 loc) · 5.1 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* eslint-env browser */
import { Multibases } from 'ipfs-core-utils/multibases'
import { Multicodecs } from 'ipfs-core-utils/multicodecs'
import { Multihashes } from 'ipfs-core-utils/multihashes'
import * as dagPB from '@ipld/dag-pb'
import * as dagCBOR from '@ipld/dag-cbor'
import * as dagJSON from '@ipld/dag-json'
import * as dagJOSE from 'dag-jose'
import { identity } from 'multiformats/hashes/identity'
import { bases, hashes, codecs } from 'multiformats/basics'
import { createBitswap } from './bitswap/index.js'
import { createBlock } from './block/index.js'
import { createBootstrap } from './bootstrap/index.js'
import { createConfig } from './config/index.js'
import { createDag } from './dag/index.js'
import { createDht } from './dht/index.js'
import { createDiag } from './diag/index.js'
import { createFiles } from './files/index.js'
import { createKey } from './key/index.js'
import { createLog } from './log/index.js'
import { createName } from './name/index.js'
import { createObject } from './object/index.js'
import { createPin } from './pin/index.js'
import { createPubsub } from './pubsub/index.js'
import { createRefs } from './refs/index.js'
import { createRepo } from './repo/index.js'
import { createStats } from './stats/index.js'
import { createSwarm } from './swarm/index.js'
import { createAdd } from './add.js'
import { createAddAll } from './add-all.js'
import { createCat } from './cat.js'
import { createCommands } from './commands.js'
import { createDns } from './dns.js'
import { createGetEndpointConfig } from './get-endpoint-config.js'
import { createGet } from './get.js'
import { createId } from './id.js'
import { createIsOnline } from './is-online.js'
import { createLs } from './ls.js'
import { createMount } from './mount.js'
import { createPing } from './ping.js'
import { createResolve } from './resolve.js'
import { createStart } from './start.js'
import { createStop } from './stop.js'
import { createVersion } from './version.js'
import globSourceImport from 'ipfs-utils/src/files/glob-source.js'
/**
* @typedef {import('./types').EndpointConfig} EndpointConfig
* @typedef {import('./types').Options} Options
* @typedef {import('multiformats/codecs/interface').BlockCodec<any, any>} BlockCodec
* @typedef {import('multiformats/hashes/interface').MultihashHasher} MultihashHasher
* @typedef {import('multiformats/bases/interface').MultibaseCodec<any>} MultibaseCodec
* @typedef {import('./types').IPFSHTTPClient} IPFSHTTPClient
*/
/**
* @param {Options} options
*/
export function create (options = {}) {
/**
* @type {BlockCodec}
*/
const id = {
name: identity.name,
code: identity.code,
encode: (id) => id,
decode: (id) => id
}
/** @type {MultibaseCodec[]} */
const multibaseCodecs = Object.values(bases);
(options.ipld && options.ipld.bases ? options.ipld.bases : []).forEach(base => multibaseCodecs.push(base))
const multibases = new Multibases({
bases: multibaseCodecs,
loadBase: options.ipld && options.ipld.loadBase
})
/** @type {BlockCodec[]} */
const blockCodecs = Object.values(codecs);
[dagPB, dagCBOR, dagJSON, dagJOSE, id].concat((options.ipld && options.ipld.codecs) || []).forEach(codec => blockCodecs.push(codec))
const multicodecs = new Multicodecs({
codecs: blockCodecs,
loadCodec: options.ipld && options.ipld.loadCodec
})
/** @type {MultihashHasher[]} */
const multihashHashers = Object.values(hashes);
(options.ipld && options.ipld.hashers ? options.ipld.hashers : []).forEach(hasher => multihashHashers.push(hasher))
const multihashes = new Multihashes({
hashers: multihashHashers,
loadHasher: options.ipld && options.ipld.loadHasher
})
/** @type {IPFSHTTPClient} */
const client = {
add: createAdd(options),
addAll: createAddAll(options),
bitswap: createBitswap(options),
block: createBlock(options),
bootstrap: createBootstrap(options),
cat: createCat(options),
commands: createCommands(options),
config: createConfig(options),
dag: createDag(multicodecs, options),
dht: createDht(options),
diag: createDiag(options),
dns: createDns(options),
files: createFiles(options),
get: createGet(options),
getEndpointConfig: createGetEndpointConfig(options),
id: createId(options),
isOnline: createIsOnline(options),
key: createKey(options),
log: createLog(options),
ls: createLs(options),
mount: createMount(options),
name: createName(options),
object: createObject(multicodecs, options),
pin: createPin(options),
ping: createPing(options),
pubsub: createPubsub(options),
refs: createRefs(options),
repo: createRepo(options),
resolve: createResolve(options),
start: createStart(options),
stats: createStats(options),
stop: createStop(options),
swarm: createSwarm(options),
version: createVersion(options),
bases: multibases,
codecs: multicodecs,
hashers: multihashes
}
return client
}
export { CID } from 'multiformats/cid'
export { Multiaddr as multiaddr } from 'multiaddr'
export { default as urlSource } from 'ipfs-utils/src/files/url-source.js'
export const globSource = globSourceImport