-
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
Conversation
✅ Deploy Preview for blobs-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -0,0 +1,70 @@ | |||
import { Client, ClientOptions, getClientOptions } from './client.ts' |
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.
Methods on this file haven't changed. They were just moved from store.ts
.
This happened in its own commit, so reviewing each commit individually might help.
- `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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the same error that you get when parsing an invalid Response
will be thrown. I can add a note to the docs.
@@ -191,6 +191,29 @@ const entry = await blobs.get('some-key', { type: 'json' }) | |||
console.log(entry) | |||
``` | |||
|
|||
### `getWithMetadata(key: string, { type?: string }): Promise<{ data: any, etag: string, metadata: object }>` |
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.
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.
Looks good. Do you think it would be possible to also implement getMetadata
, which uses a HEAD
request and returns just the metadata?
I think so, although maybe not for the beta since it'll require some work in nfserver. |
It could be a nice addition at some point, to cheaply check metadata before requesting potentially large objects |
Adds support for arbitrary metadata, supplied by users, to be stored alongside entries.
To write an entry with metadata, one can supply the
metadata
option to theset()
method:To read an entry and also retrieve its metadata, a new
getWithMetadata()
method has been added:Needs https://github.com/netlify/netlify-server/pull/3111.
Part of https://github.com/netlify/pillar-runtime/issues/751.