1
+ export type RequiredCreateOptions = {
2
+ cid : CID ;
3
+ } ;
4
+ /**
5
+ * @template {unknown} T - Logical type of the data encoded in the block
6
+ * @template {number} Code - multicodec code corresponding to codec used to encode the block
7
+ * @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
8
+ * @param {object } options
9
+ * @param {T } options.value
10
+ * @param {API.BlockEncoder<Code, T> } options.codec
11
+ * @param {API.MultihashHasher<Alg> } options.hasher
12
+ * @returns {Promise<API.BlockView<T, Code, Alg>> }
13
+ */
14
+ export function encode < T extends unknown , Code extends number , Alg extends number > ( { value, codec, hasher } : {
15
+ value : T ;
16
+ codec : API . BlockEncoder < Code , T > ;
17
+ hasher : API . MultihashHasher < Alg > ;
18
+ } ) : Promise < API . BlockView < T , Code , Alg , 1 > > ;
19
+ /**
20
+ * @template {unknown} T - Logical type of the data encoded in the block
21
+ * @template {number} Code - multicodec code corresponding to codec used to encode the block
22
+ * @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
23
+ * @param {object } options
24
+ * @param {API.ByteView<T> } options.bytes
25
+ * @param {API.BlockDecoder<Code, T> } options.codec
26
+ * @param {API.MultihashHasher<Alg> } options.hasher
27
+ * @returns {Promise<API.BlockView<T, Code, Alg>> }
28
+ */
29
+ export function decode < T extends unknown , Code extends number , Alg extends number > ( { bytes, codec, hasher } : {
30
+ bytes : API . ByteView < T > ;
31
+ codec : API . BlockDecoder < Code , T > ;
32
+ hasher : API . MultihashHasher < Alg > ;
33
+ } ) : Promise < API . BlockView < T , Code , Alg , 1 > > ;
34
+ /**
35
+ * @template {unknown} T - Logical type of the data encoded in the block
36
+ * @template {number} Code - multicodec code corresponding to codec used to encode the block
37
+ * @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
38
+ * @template {API.Version} V - CID version
39
+ * @param {object } options
40
+ * @param {API.Link<T, Code, Alg, V> } options.cid
41
+ * @param {API.ByteView<T> } options.bytes
42
+ * @param {API.BlockDecoder<Code, T> } options.codec
43
+ * @param {API.MultihashHasher<Alg> } options.hasher
44
+ * @returns {Promise<API.BlockView<T, Code, Alg, V>> }
45
+ */
46
+ export function create < T extends unknown , Code extends number , Alg extends number , V extends API . Version > ( { bytes, cid, hasher, codec } : {
47
+ cid : API . Link < T , Code , Alg , V > ;
48
+ bytes : API . ByteView < T > ;
49
+ codec : API . BlockDecoder < Code , T > ;
50
+ hasher : API . MultihashHasher < Alg > ;
51
+ } ) : Promise < API . BlockView < T , Code , Alg , V > > ;
52
+ /**
53
+ * @typedef {object } RequiredCreateOptions
54
+ * @property {CID } options.cid
55
+ */
56
+ /**
57
+ * @template {unknown} T - Logical type of the data encoded in the block
58
+ * @template {number} Code - multicodec code corresponding to codec used to encode the block
59
+ * @template {number} Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
60
+ * @template {API.Version} V - CID version
61
+ * @param {{ cid: API.Link<T, Code, Alg, V>, value:T, codec?: API.BlockDecoder<Code, T>, bytes: API.ByteView<T> }|{cid:API.Link<T, Code, Alg, V>, bytes:API.ByteView<T>, value?:void, codec:API.BlockDecoder<Code, T>} } options
62
+ * @returns {API.BlockView<T, Code, Alg, V> }
63
+ */
64
+ export function createUnsafe < T extends unknown , Code extends number , Alg extends number , V extends API . Version > ( { bytes, cid, value : maybeValue , codec } : {
65
+ cid : API . Link < T , Code , Alg , V > ;
66
+ value : T ;
67
+ codec ?: API . BlockDecoder < Code , T > | undefined ;
68
+ bytes : API . ByteView < T > ;
69
+ } | {
70
+ cid : API . Link < T , Code , Alg , V > ;
71
+ bytes : API . ByteView < T > ;
72
+ value ?: void | undefined ;
73
+ codec : API . BlockDecoder < Code , T > ;
74
+ } ) : API . BlockView < T , Code , Alg , V > ;
75
+ /**
76
+ * @template {unknown} T - Logical type of the data encoded in the block
77
+ * @template {number} C - multicodec code corresponding to codec used to encode the block
78
+ * @template {number} A - multicodec code corresponding to the hashing algorithm used in CID creation.
79
+ * @template {API.Version} V - CID version
80
+ * @implements {API.BlockView<T, C, A, V>}
81
+ */
82
+ export class Block < T extends unknown , C extends number , A extends number , V extends API . Version > implements API . BlockView < T , C , A , V > {
83
+ /**
84
+ * @param {object } options
85
+ * @param {CID<T, C, A, V> } options.cid
86
+ * @param {API.ByteView<T> } options.bytes
87
+ * @param {T } options.value
88
+ */
89
+ constructor ( { cid, bytes, value } : {
90
+ cid : CID < T , C , A , V > ;
91
+ bytes : API . ByteView < T > ;
92
+ value : T ;
93
+ } ) ;
94
+ cid : CID < T , C , A , V > ;
95
+ bytes : API . ByteView < T > ;
96
+ value : T ;
97
+ asBlock : Block < T , C , A , V > ;
98
+ links ( ) : Iterable < [ string , CID < any , number , number , API . Version > ] > ;
99
+ tree ( ) : Iterable < string > ;
100
+ /**
101
+ *
102
+ * @param {string } [path]
103
+ * @returns {API.BlockCursorView<unknown> }
104
+ */
105
+ get ( path ?: string | undefined ) : API . BlockCursorView < unknown > ;
106
+ }
107
+ import * as API from "./interface.js" ;
108
+ import { CID } from "./index.js" ;
109
+ //# sourceMappingURL=block.d.ts.map
0 commit comments