Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Types] R2Objects stricter type #315

Closed
DaniFoldi opened this issue Jan 25, 2023 · 0 comments · Fixed by #472
Closed

[Types] R2Objects stricter type #315

DaniFoldi opened this issue Jan 25, 2023 · 0 comments · Fixed by #472
Labels
types Related to @cloudflare/workers-types

Comments

@DaniFoldi
Copy link
Contributor

Hi 👋

When listing objects in R2, a value of type R2Objects is returned.

Similarly, in KV KVNamespaceListResult is returned, which a union type where the cursor and list_complete keys are strictly combined to provide either the result of a complete list or an incomplete list - which are the only possible outcomes.

Currently, R2Objects has this type:

declare interface R2Objects {
  objects: R2Object[];
  truncated: boolean;
  cursor?: string;
  delimitedPrefixes: string[];
}

Which I believe could be changed to

declare type R2Objects = {
  objects: R2Object[];
  delimitedPrefixes: string[];
} & (
  | {truncated: true; cursor: string}
  | {truncated: false}
)
@mrbbot mrbbot added the types Related to @cloudflare/workers-types label Jan 25, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Feb 9, 2023
@mrbbot mrbbot moved this from Untriaged to Backlog in workers-sdk Feb 13, 2023
mrbbot added a commit that referenced this issue Mar 23, 2023
When listing R2 objects, a `cursor` is only returned when `truncated`
is `true`. This change encodes this constraint in TypeScript, similar
to `KVNamespaceListResult`.

Closes #315
@github-project-automation github-project-automation bot moved this from Backlog to Done in workers-sdk Mar 28, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
types Related to @cloudflare/workers-types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants