@helia/utils 0.3.3-5ff6998 → 0.3.3-9de08ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +4 -15
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/pins.d.ts +3 -3
- package/dist/src/pins.d.ts.map +1 -1
- package/dist/src/pins.js +9 -8
- package/dist/src/pins.js.map +1 -1
- package/dist/src/utils/dag-walkers.d.ts +28 -0
- package/dist/src/utils/dag-walkers.d.ts.map +1 -0
- package/dist/src/utils/dag-walkers.js +171 -0
- package/dist/src/utils/dag-walkers.js.map +1 -0
- package/dist/src/utils/default-hashers.d.ts +3 -0
- package/dist/src/utils/default-hashers.d.ts.map +1 -0
- package/dist/src/utils/default-hashers.js +15 -0
- package/dist/src/utils/default-hashers.js.map +1 -0
- package/dist/src/utils/networked-storage.d.ts +2 -3
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js +6 -16
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +13 -26
- package/src/pins.ts +12 -9
- package/src/utils/dag-walkers.ts +198 -0
- package/src/utils/default-hashers.ts +18 -0
- package/src/utils/networked-storage.ts +8 -21
- package/dist/src/utils/get-codec.d.ts +0 -4
- package/dist/src/utils/get-codec.d.ts.map +0 -1
- package/dist/src/utils/get-codec.js +0 -38
- package/dist/src/utils/get-codec.js.map +0 -1
- package/dist/src/utils/get-hasher.d.ts +0 -4
- package/dist/src/utils/get-hasher.d.ts.map +0 -1
- package/dist/src/utils/get-hasher.js +0 -32
- package/dist/src/utils/get-hasher.js.map +0 -1
- package/dist/src/utils/is-promise.d.ts +0 -2
- package/dist/src/utils/is-promise.d.ts.map +0 -1
- package/dist/src/utils/is-promise.js +0 -4
- package/dist/src/utils/is-promise.js.map +0 -1
- package/src/utils/get-codec.ts +0 -47
- package/src/utils/get-hasher.ts +0 -40
- package/src/utils/is-promise.ts +0 -3
package/src/utils/get-codec.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/* eslint max-depth: ["error", 7] */
|
|
2
|
-
|
|
3
|
-
import { UnknownCodecError } from '@helia/interface'
|
|
4
|
-
import * as dagCbor from '@ipld/dag-cbor'
|
|
5
|
-
import * as dagJson from '@ipld/dag-json'
|
|
6
|
-
import * as dagPb from '@ipld/dag-pb'
|
|
7
|
-
import * as json from 'multiformats/codecs/json'
|
|
8
|
-
import * as raw from 'multiformats/codecs/raw'
|
|
9
|
-
import { isPromise } from './is-promise.js'
|
|
10
|
-
import type { Await } from '@helia/interface'
|
|
11
|
-
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
12
|
-
|
|
13
|
-
export function getCodec <T = any, Code extends number = any> (initialCodecs: Array<BlockCodec<any, any>> = [], loadCodec?: (code: number) => Await<BlockCodec<any, any>>): (code: Code) => Await<BlockCodec<Code, T>> {
|
|
14
|
-
const codecs: Record<number, BlockCodec<any, any>> = {
|
|
15
|
-
[dagPb.code]: dagPb,
|
|
16
|
-
[raw.code]: raw,
|
|
17
|
-
[dagCbor.code]: dagCbor,
|
|
18
|
-
[dagJson.code]: dagJson,
|
|
19
|
-
[json.code]: json
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
initialCodecs.forEach(codec => {
|
|
23
|
-
codecs[codec.code] = codec
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
return async (code) => {
|
|
27
|
-
let codec = codecs[code]
|
|
28
|
-
|
|
29
|
-
if (codec == null && loadCodec != null) {
|
|
30
|
-
const res = loadCodec(code)
|
|
31
|
-
|
|
32
|
-
if (isPromise(res)) {
|
|
33
|
-
codec = await res
|
|
34
|
-
} else {
|
|
35
|
-
codec = res
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
codecs[codec.code] = codec
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (codec != null) {
|
|
42
|
-
return codec
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
throw new UnknownCodecError(`Could not load codec for ${code}`)
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/utils/get-hasher.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { UnknownHashAlgorithmError } from '@helia/interface'
|
|
2
|
-
import { identity } from 'multiformats/hashes/identity'
|
|
3
|
-
import { sha256, sha512 } from 'multiformats/hashes/sha2'
|
|
4
|
-
import { isPromise } from './is-promise.js'
|
|
5
|
-
import type { Await } from '@helia/interface'
|
|
6
|
-
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
7
|
-
|
|
8
|
-
export function getHasher (initialHashers: MultihashHasher[] = [], loadHasher?: (code: number) => Await<MultihashHasher>): (code: number) => Await<MultihashHasher> {
|
|
9
|
-
const hashers: Record<number, MultihashHasher> = {
|
|
10
|
-
[sha256.code]: sha256,
|
|
11
|
-
[sha512.code]: sha512,
|
|
12
|
-
[identity.code]: identity
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
initialHashers.forEach(hasher => {
|
|
16
|
-
hashers[hasher.code] = hasher
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
return async (code) => {
|
|
20
|
-
let hasher = hashers[code]
|
|
21
|
-
|
|
22
|
-
if (hasher == null && loadHasher != null) {
|
|
23
|
-
const res = loadHasher(code)
|
|
24
|
-
|
|
25
|
-
if (isPromise(res)) {
|
|
26
|
-
hasher = await res
|
|
27
|
-
} else {
|
|
28
|
-
hasher = res
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
hashers[hasher.code] = hasher
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (hasher != null) {
|
|
35
|
-
return hasher
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
throw new UnknownHashAlgorithmError(`No hasher configured for multihash code 0x${code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`)
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/utils/is-promise.ts
DELETED