|
1 | | -import type { AbortOptions } from '@libp2p/interfaces' |
2 | 1 | import type { ProgressEvent, ProgressOptions } from 'progress-events' |
3 | 2 | import type { CID } from 'multiformats/cid' |
4 | 3 | import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap' |
5 | | -import type { AwaitIterable, Await } from './index.js' |
6 | 4 | import type { Blockstore } from 'interface-blockstore' |
7 | 5 |
|
8 | 6 | export interface Pair { |
9 | 7 | cid: CID |
10 | 8 | block: Uint8Array |
11 | 9 | } |
12 | 10 |
|
| 11 | +export type HasBlockProgressEvents = |
| 12 | + ProgressEvent<'blocks:put:duplicate', CID> | |
| 13 | + ProgressEvent<'blocks:put:bitswap:notify', CID> | |
| 14 | + ProgressEvent<'blocks:put:blockstore:put', CID> | |
| 15 | + BitswapNotifyProgressEvents |
| 16 | + |
13 | 17 | export type PutBlockProgressEvents = |
14 | 18 | ProgressEvent<'blocks:put:duplicate', CID> | |
15 | 19 | ProgressEvent<'blocks:put:bitswap:notify', CID> | |
@@ -43,121 +47,10 @@ export type DeleteBlockProgressEvents = |
43 | 47 | export type DeleteManyBlocksProgressEvents = |
44 | 48 | ProgressEvent<'blocks:delete-many:blockstore:delete-many'> |
45 | 49 |
|
46 | | -export interface Blocks extends Blockstore { |
47 | | - /** |
48 | | - * Check for the existence of a value for the passed key |
49 | | - * |
50 | | - * @example |
51 | | - * ```js |
52 | | - * const exists = await store.has(CID('bafyfoo')) |
53 | | - * |
54 | | - * if (exists) { |
55 | | - * console.log('it is there') |
56 | | - * } else { |
57 | | - * console.log('it is not there') |
58 | | - * } |
59 | | - *``` |
60 | | - */ |
61 | | - has: (key: CID, options?: AbortOptions) => Await<boolean> |
62 | | - |
63 | | - /** |
64 | | - * Store the passed block under the passed CID |
65 | | - * |
66 | | - * @example |
67 | | - * |
68 | | - * ```js |
69 | | - * await store.put(CID('bafyfoo'), new Uint8Array([0, 1, 2, 3])) |
70 | | - * ``` |
71 | | - */ |
72 | | - put: (key: CID, val: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>) => Await<void> |
73 | | - |
74 | | - /** |
75 | | - * Store the given key/value pairs |
76 | | - * |
77 | | - * @example |
78 | | - * ```js |
79 | | - * const source = [{ cid: CID('bafyfoo'), block: new Uint8Array([0, 1, 2, 3]) }] |
80 | | - * |
81 | | - * for await (const { key, value } of store.putMany(source)) { |
82 | | - * console.info(`put content for key ${key}`) |
83 | | - * } |
84 | | - * ``` |
85 | | - */ |
86 | | - putMany: ( |
87 | | - source: AwaitIterable<Pair>, |
88 | | - options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> |
89 | | - ) => AwaitIterable<Pair> |
90 | | - |
91 | | - /** |
92 | | - * Retrieve the value stored under the given key |
93 | | - * |
94 | | - * @example |
95 | | - * ```js |
96 | | - * const value = await store.get(CID('bafyfoo')) |
97 | | - * console.log('got content: %s', value.toString('utf8')) |
98 | | - * // => got content: datastore |
99 | | - * ``` |
100 | | - */ |
101 | | - get: (key: CID, options?: AbortOptions & ProgressOptions<GetBlockProgressEvents>) => Await<Uint8Array> |
102 | | - |
103 | | - /** |
104 | | - * Retrieve values for the passed keys |
105 | | - * |
106 | | - * @example |
107 | | - * ```js |
108 | | - * for await (const value of store.getMany([CID('bafyfoo')])) { |
109 | | - * console.log('got content:', new TextDecoder('utf8').decode(value)) |
110 | | - * // => got content: datastore |
111 | | - * } |
112 | | - * ``` |
113 | | - */ |
114 | | - getMany: ( |
115 | | - source: AwaitIterable<CID>, |
116 | | - options?: AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> |
117 | | - ) => AwaitIterable<Uint8Array> |
118 | | - |
119 | | - /** |
120 | | - * Retrieve all blocks in the blockstore |
121 | | - * |
122 | | - * @example |
123 | | - * ```js |
124 | | - * for await (const value of store.getAll()) { |
125 | | - * console.log('got content:', new TextDecoder('utf8').decode(value)) |
126 | | - * // => got content: datastore |
127 | | - * } |
128 | | - * ``` |
129 | | - */ |
130 | | - getAll: ( |
131 | | - options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> |
132 | | - ) => AwaitIterable<Pair> |
133 | | - |
134 | | - /** |
135 | | - * Remove the record for the passed key |
136 | | - * |
137 | | - * @example |
138 | | - * |
139 | | - * ```js |
140 | | - * await store.delete(CID('bafyfoo')) |
141 | | - * console.log('deleted awesome content :(') |
142 | | - * ``` |
143 | | - */ |
144 | | - delete: (key: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>) => Await<void> |
| 50 | +export interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>, |
| 51 | +ProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>, |
| 52 | +ProgressOptions<GetBlockProgressEvents>, ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>, |
| 53 | +ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents> |
| 54 | +> { |
145 | 55 |
|
146 | | - /** |
147 | | - * Remove values for the passed keys |
148 | | - * |
149 | | - * @example |
150 | | - * |
151 | | - * ```js |
152 | | - * const source = [CID('bafyfoo')] |
153 | | - * |
154 | | - * for await (const key of store.deleteMany(source)) { |
155 | | - * console.log(`deleted content with key ${key}`) |
156 | | - * } |
157 | | - * ``` |
158 | | - */ |
159 | | - deleteMany: ( |
160 | | - source: AwaitIterable<CID>, |
161 | | - options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> |
162 | | - ) => AwaitIterable<CID> |
163 | 56 | } |
0 commit comments