-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add support for arbitrary metadata #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e2bdfff
9403217
a2535c7
4677bbb
4f06edb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ console.log(await store.get('my-key')) | |
|
||
## Store API reference | ||
|
||
### `get(key: string, { type: string }): Promise<any>` | ||
### `get(key: string, { type?: string }): Promise<any>` | ||
|
||
Retrieves an object with the given key. | ||
|
||
|
@@ -191,7 +191,30 @@ const entry = await blobs.get('some-key', { type: 'json' }) | |
console.log(entry) | ||
``` | ||
|
||
### `set(key: string, value: ArrayBuffer | Blob | ReadableStream | string): Promise<void>` | ||
### `getWithMetadata(key: string, { type?: string }): Promise<{ data: any, etag: string, metadata: object }>` | ||
|
||
|
||
Retrieves an object with the given key, the [ETag value](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) | ||
for the entry, and any metadata that has been stored with the entry. | ||
|
||
Depending on the most convenient format for you to access the value, you may choose to supply a `type` property as a | ||
second parameter, with one of the following values: | ||
|
||
- `arrayBuffer`: Returns the entry as an | ||
[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) | ||
- `blob`: Returns the entry as a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | ||
- `json`: Parses the entry as JSON and returns the resulting object | ||
|
||
- `stream`: Returns the entry as a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) | ||
- `text` (default): Returns the entry as a string of plain text | ||
|
||
If an object with the given key is not found, `null` is returned. | ||
|
||
```javascript | ||
const blob = await blobs.getWithMetadata('some-key', { type: 'json' }) | ||
|
||
console.log(blob.data, blob.etag, blob.metadata) | ||
``` | ||
|
||
### `set(key: string, value: ArrayBuffer | Blob | ReadableStream | string, { metadata?: object }): Promise<void>` | ||
|
||
Creates an object with the given key and value. | ||
|
||
|
@@ -201,7 +224,7 @@ If an entry with the given key already exists, its value is overwritten. | |
await blobs.set('some-key', 'This is a string value') | ||
``` | ||
|
||
### `setJSON(key: string, value: any): Promise<void>` | ||
### `setJSON(key: string, value: any, { metadata?: object }): Promise<void>` | ||
|
||
Convenience method for creating a JSON-serialized object with the given key. | ||
|
||
|