@@ -186,7 +186,7 @@ second parameter, with one of the following values:
186186If an object with the given key is not found, ` null ` is returned.
187187
188188``` javascript
189- const entry = await blobs .get (' some-key' , { type: ' json' })
189+ const entry = await store .get (' some-key' , { type: ' json' })
190190
191191console .log (entry)
192192```
@@ -209,7 +209,7 @@ second parameter, with one of the following values:
209209If an object with the given key is not found, ` null ` is returned.
210210
211211``` javascript
212- const blob = await blobs .getWithMetadata (' some-key' , { type: ' json' })
212+ const blob = await store .getWithMetadata (' some-key' , { type: ' json' })
213213
214214console .log (blob .data , blob .etag , blob .metadata )
215215```
@@ -223,7 +223,7 @@ const cachedETag = getFromMockCache('my-key')
223223
224224// Get entry from the blob store only if its ETag is different from the one you
225225// have locally, which means the entry has changed since you last obtained it
226- const { data , etag , fresh } = await blobs .getWithMetadata (' some-key' , { etag: cachedETag })
226+ const { data , etag , fresh } = await store .getWithMetadata (' some-key' , { etag: cachedETag })
227227
228228if (fresh) {
229229 // `data` is `null` because the local blob is fresh
@@ -240,7 +240,7 @@ Creates an object with the given key and value.
240240If an entry with the given key already exists, its value is overwritten.
241241
242242``` javascript
243- await blobs .set (' some-key' , ' This is a string value' )
243+ await store .set (' some-key' , ' This is a string value' )
244244```
245245
246246### ` setJSON(key: string, value: any, { metadata?: object }): Promise<void> `
@@ -250,7 +250,7 @@ Convenience method for creating a JSON-serialized object with the given key.
250250If an entry with the given key already exists, its value is overwritten.
251251
252252``` javascript
253- await blobs .setJSON (' some-key' , {
253+ await store .setJSON (' some-key' , {
254254 foo: ' bar' ,
255255})
256256```
@@ -260,9 +260,86 @@ await blobs.setJSON('some-key', {
260260Deletes an object with the given key, if one exists.
261261
262262``` javascript
263- await blobs .delete (' my-key' )
263+ await store .delete (' my-key' )
264264```
265265
266+ ### ` list(options?: { cursor?: string, directories?: boolean, paginate?: boolean. prefix?: string }): Promise<{ blobs: BlobResult[], directories: string[] }> `
267+
268+ Returns a list of blobs in a given store.
269+
270+ ``` javascript
271+ const { blobs } = await store .list ()
272+
273+ // [ { etag: 'etag1', key: 'some-key' }, { etag: 'etag2', key: 'another-key' } ]
274+ console .log (blobs)
275+ ```
276+
277+ To filter down the entries that should be returned, an optional ` prefix ` parameter can be supplied. When used, only the
278+ entries whose key starts with that prefix are returned.
279+
280+ ``` javascript
281+ const { blobs } = await store .list ({ prefix: ' some' })
282+
283+ // [ { etag: 'etag1', key: 'some-key' } ]
284+ console .log (blobs)
285+ ```
286+
287+ Optionally, you can choose to group blobs together under a common prefix and then browse them hierarchically when
288+ listing a store, just like grouping files in a directory. To do this, use the ` / ` character in your keys to group them
289+ into directories.
290+
291+ Take the following list of keys as an example:
292+
293+ ```
294+ cats/garfield.jpg
295+ cats/tom.jpg
296+ mice/jerry.jpg
297+ mice/mickey.jpg
298+ pink-panther.jpg
299+ ```
300+
301+ By default, calling ` store.list() ` will return all five keys.
302+
303+ ``` javascript
304+ const { blobs } = await store .list ()
305+
306+ // [
307+ // { etag: "etag1", key: "cats/garfield.jpg" },
308+ // { etag: "etag2", key: "cats/tom.jpg" },
309+ // { etag: "etag3", key: "mice/jerry.jpg" },
310+ // { etag: "etag4", key: "mice/mickey.jpg" },
311+ // { etag: "etag5", key: "pink-panther.jpg" },
312+ // ]
313+ console .log (blobs)
314+ ```
315+
316+ But if you want to list entries hierarchically, use the ` directories ` parameter.
317+
318+ ``` javascript
319+ const { blobs , directories } = await store .list ({ directories: true })
320+
321+ // [ { etag: "etag1", key: "pink-panther.jpg" } ]
322+ console .log (blobs)
323+
324+ // [ "cats", "mice" ]
325+ console .log (directories)
326+ ```
327+
328+ To drill down into a directory and get a list of its items, you can use the directory name as the ` prefix ` value.
329+
330+ ``` javascript
331+ const { blobs , directories } = await store .list ({ directories: true , prefix: ' cats/' })
332+
333+ // [ { etag: "etag1", key: "cats/garfield.jpg" }, { etag: "etag2", key: "cats/tom.jpg" } ]
334+ console .log (blobs)
335+
336+ // [ ]
337+ console .log (directories)
338+ ```
339+
340+ Note that we're only interested in entries under the ` cats ` directory, which is why we're using a trailing slash.
341+ Without it, other keys like ` catsuit ` would also match.
342+
266343## Contributing
267344
268345Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or
0 commit comments