-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
97 lines (87 loc) · 2.91 KB
/
mod.ts
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
import {
bases,
codecs,
dagCBOR,
dagJOSE,
dagJSON,
dagPB,
globSourceImport,
hashes,
identity,
Multibases,
Multicodecs,
Multihashes,
} from './deps.ts'
import type { BlockCodec, MultibaseCodec, MultihashHasher } from './deps.ts'
import type { Options, IPFSHTTPClient } from "./types.d.ts";
export function create(options: Options = {}) {
// deno-lint-ignore no-explicit-any
const id: BlockCodec<any, any> = {
name: identity.name,
code: identity.code,
encode: (id) => id,
decode: (id) => id,
}
const multibaseCodecs: MultibaseCodec<string>[] = 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,
})
// deno-lint-ignore no-explicit-any
const blockCodecs: BlockCodec<any, any>[] = 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,
})
const multihashHashers: MultihashHasher[] = 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,
})
const client: IPFSHTTPClient = {
// 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 const globSource = globSourceImport