-
Notifications
You must be signed in to change notification settings - Fork 2
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if that parsing fails? do we just bubble up the SyntaxError? would it make sense to include a note about what happens? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the same error that you get when parsing an invalid |
||
- `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. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we reference the
Metadata
type in the return type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon it's ok in the docs to just say object. It's just
Record<string, unknown>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't think there's much value in using the custom type here.