File
Blob: src/workerd/api/r2-api.capnp
| 1 | # Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | # Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | # https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | @0xfb0dc52eec08c4d2; |
| 6 | |
| 7 | using Cxx = import "/capnp/c++.capnp"; |
| 8 | using Json = import "/capnp/compat/json.capnp"; |
| 9 | |
| 10 | $Cxx.namespace("workerd::api::public_beta"); |
| 11 | $Cxx.allowCancellation; |
| 12 | |
| 13 | const versionPublicBeta :UInt32 = 1; |
| 14 | |
| 15 | struct R2BindingRequest { |
| 16 | version @0 :UInt32; |
| 17 | payload :union $Json.flatten() $Json.discriminator(name="method") { |
| 18 | head @1 :R2HeadRequest $Json.flatten(); |
| 19 | get @2 :R2GetRequest $Json.flatten(); |
| 20 | put @3 :R2PutRequest $Json.flatten(); |
| 21 | list @4 :R2ListRequest $Json.flatten(); |
| 22 | delete @5 :R2DeleteRequest $Json.flatten(); |
| 23 | createBucket @6 :R2CreateBucketRequest $Json.flatten(); |
| 24 | listBucket @7 :R2ListBucketRequest $Json.flatten(); |
| 25 | deleteBucket @8 :R2DeleteBucketRequest $Json.flatten(); |
| 26 | createMultipartUpload @9 :R2CreateMultipartUploadRequest $Json.flatten(); |
| 27 | uploadPart @10 :R2UploadPartRequest $Json.flatten(); |
| 28 | completeMultipartUpload @11 :R2CompleteMultipartUploadRequest $Json.flatten(); |
| 29 | abortMultipartUpload @12 :R2AbortMultipartUploadRequest $Json.flatten(); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | struct Record { |
| 34 | k @0 :Text; |
| 35 | v @1 :Text; |
| 36 | } |
| 37 | |
| 38 | struct R2Range { |
| 39 | offset @0 :UInt64 = 0xffffffffffffffff; |
| 40 | length @1 :UInt64 = 0xffffffffffffffff; |
| 41 | suffix @2 :UInt64 = 0xffffffffffffffff; |
| 42 | } |
| 43 | |
| 44 | struct R2Etag { |
| 45 | value @0 :Text; |
| 46 | type :union $Json.flatten() $Json.discriminator(name="type") { |
| 47 | strong @1 :Void; |
| 48 | weak @2 :Void; |
| 49 | wildcard @3 :Void; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | struct R2Conditional { |
| 54 | etagMatches @0 :List(R2Etag); |
| 55 | etagDoesNotMatch @1 :List(R2Etag); |
| 56 | uploadedBefore @2 :UInt64 = 0xffffffffffffffff; |
| 57 | uploadedAfter @3 :UInt64 = 0xffffffffffffffff; |
| 58 | secondsGranularity @4 :Bool; |
| 59 | # Should uploadedBefore / uploadedAfter be evaluated against the seconds granularity of the upload |
| 60 | # timestamp. |
| 61 | } |
| 62 | |
| 63 | struct R2SSECOptions { |
| 64 | key @0 :Text; |
| 65 | } |
| 66 | |
| 67 | struct R2Checksums { |
| 68 | # The JSON name of these fields must comform to the representation of the ChecksumAlgorithm in |
| 69 | # the R2 gateway worker. |
| 70 | md5 @0 :Data $Json.hex $Json.name("0"); |
| 71 | sha1 @1 :Data $Json.hex $Json.name("1"); |
| 72 | sha256 @2 :Data $Json.hex $Json.name("2"); |
| 73 | sha384 @3 :Data $Json.hex $Json.name("3"); |
| 74 | sha512 @4 :Data $Json.hex $Json.name("4"); |
| 75 | } |
| 76 | |
| 77 | struct R2PublishedPart { |
| 78 | etag @0 :Text; |
| 79 | part @1 :UInt32; |
| 80 | } |
| 81 | |
| 82 | struct R2HttpFields { |
| 83 | contentType @0 :Text; |
| 84 | contentLanguage @1 :Text; |
| 85 | contentDisposition @2 :Text; |
| 86 | contentEncoding @3 :Text; |
| 87 | cacheControl @4 :Text; |
| 88 | cacheExpiry @5 :UInt64 = 0xffffffffffffffff; |
| 89 | } |
| 90 | |
| 91 | struct R2HeadRequest { |
| 92 | object @0 :Text; |
| 93 | } |
| 94 | |
| 95 | struct R2GetRequest { |
| 96 | object @0 :Text; |
| 97 | range @1 :R2Range; |
| 98 | rangeHeader @3 :Text; |
| 99 | onlyIf @2 :R2Conditional; |
| 100 | ssec @4 :R2SSECOptions; |
| 101 | } |
| 102 | |
| 103 | struct R2PutRequest { |
| 104 | object @0 :Text; |
| 105 | customFields @1 :List(Record); |
| 106 | httpFields @2 :R2HttpFields; |
| 107 | onlyIf @3 :R2Conditional; |
| 108 | md5 @4 :Data $Json.base64; |
| 109 | sha1 @5 :Data $Json.hex; |
| 110 | sha256 @6 :Data $Json.hex; |
| 111 | sha384 @7 :Data $Json.hex; |
| 112 | sha512 @8 :Data $Json.hex; |
| 113 | storageClass @9 :Text; |
| 114 | ssec @10 :R2SSECOptions; |
| 115 | } |
| 116 | |
| 117 | struct R2CreateMultipartUploadRequest { |
| 118 | object @0 :Text; |
| 119 | customFields @1 :List(Record); |
| 120 | httpFields @2 :R2HttpFields; |
| 121 | storageClass @3 :Text; |
| 122 | ssec @4 :R2SSECOptions; |
| 123 | } |
| 124 | |
| 125 | struct R2UploadPartRequest { |
| 126 | object @0 :Text; |
| 127 | uploadId @1 :Text; |
| 128 | partNumber @2 :UInt32; |
| 129 | ssec @3 :R2SSECOptions; |
| 130 | } |
| 131 | |
| 132 | struct R2CompleteMultipartUploadRequest { |
| 133 | object @0 :Text; |
| 134 | uploadId @1 :Text; |
| 135 | parts @2 :List(R2PublishedPart); |
| 136 | } |
| 137 | |
| 138 | struct R2AbortMultipartUploadRequest { |
| 139 | object @0 :Text; |
| 140 | uploadId @1 :Text; |
| 141 | } |
| 142 | |
| 143 | struct R2ListRequest { |
| 144 | limit @0 :UInt32 = 0xffffffff; |
| 145 | |
| 146 | prefix @1 :Text; |
| 147 | cursor @2 :Text; |
| 148 | delimiter @3 :Text; |
| 149 | startAfter @4 :Text; |
| 150 | |
| 151 | include @5 :List(UInt16); |
| 152 | # Additional fields to include in the response that might not normally be rendered. |
| 153 | # The values are all IncludeField but we can't actually have that here because otherwise |
| 154 | # capnp's builtin JSON encoder will print the enum name instead of the value. |
| 155 | |
| 156 | newRuntime @6 :Bool; |
| 157 | # We used to send the include but not honor it. Newer versions of the runtime will send this to |
| 158 | # indicate we're sending a version of the `include` that can be honored. Before that the R2 worker |
| 159 | # should assume include always means http & custom metadata should be returned. This is a |
| 160 | # transitionary field just to avoid coupling needing to simultaneously release the Worker & |
| 161 | # runtime and can be removed after the release cut for the week of July 4, 2022. |
| 162 | |
| 163 | enum IncludeField @0xc02f1c58744671f1 { |
| 164 | http @0; |
| 165 | custom @1; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | struct R2DeleteRequest { |
| 170 | union { |
| 171 | object @0 :Text; |
| 172 | objects @1 :List(Text); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | struct R2CreateBucketRequest { |
| 177 | bucket @0 :Text; |
| 178 | } |
| 179 | |
| 180 | struct R2ListBucketRequest { |
| 181 | limit @0 :UInt32 = 0xffffffff; |
| 182 | |
| 183 | prefix @1 :Text; |
| 184 | cursor @2 :Text; |
| 185 | } |
| 186 | |
| 187 | struct R2DeleteBucketRequest { |
| 188 | bucket @0 :Text; |
| 189 | } |
| 190 | |
| 191 | struct R2ErrorResponse { |
| 192 | version @0 :UInt32; |
| 193 | v4code @1 :UInt32; |
| 194 | # Bindings use the same error code space as the V4 API. |
| 195 | message @2 :Text; |
| 196 | } |
| 197 | |
| 198 | struct R2SSECResponse { |
| 199 | algorithm @0 :Text; |
| 200 | keyMd5 @1 :Text; |
| 201 | } |
| 202 | |
| 203 | struct R2HeadResponse { |
| 204 | name @0 :Text; |
| 205 | # The name of the object. |
| 206 | |
| 207 | version @1 :Text; |
| 208 | # The version ID of the object. |
| 209 | |
| 210 | size @2 :UInt64; |
| 211 | # The total size of the object in bytes. |
| 212 | |
| 213 | etag @3 :Text; |
| 214 | # The ETag the object has currently. |
| 215 | |
| 216 | uploadedMillisecondsSinceEpoch @4 :UInt64 $Json.name("uploaded"); |
| 217 | # The timestamp of when the object was uploaded. |
| 218 | |
| 219 | httpFields @5 :R2HttpFields; |
| 220 | # The HTTP headers that we were asked to associate with this object on upload. |
| 221 | |
| 222 | customFields @6 :List(Record); |
| 223 | # Arbitrary key-value pairs that we were asked to associate with this object on upload. |
| 224 | # Since cap'n'proto doesn't really have a natural key-value type, we emulate it with an exploded |
| 225 | # list of the entries of the map. |
| 226 | |
| 227 | range @7 :R2Range; |
| 228 | # If set, an echo of the range that was requested. |
| 229 | |
| 230 | checksums @8 :R2Checksums; |
| 231 | # If set, the available checksums for this object |
| 232 | |
| 233 | storageClass @9 :Text; |
| 234 | # The storage class of the object. Standard or Infrequent Access. |
| 235 | # Provided on object creation to specify which storage tier R2 should use for this object. |
| 236 | |
| 237 | ssec @10 :R2SSECResponse; |
| 238 | # The algorithm/key hash used for encryption(if the user used SSE-C) |
| 239 | } |
| 240 | |
| 241 | using R2GetResponse = R2HeadResponse; |
| 242 | |
| 243 | using R2PutResponse = R2HeadResponse; |
| 244 | |
| 245 | struct R2CreateMultipartUploadResponse { |
| 246 | uploadId @0 :Text; |
| 247 | # The unique identifier of this object, required for subsequent operations on |
| 248 | # this multipart upload. |
| 249 | ssec @1 :R2SSECResponse; |
| 250 | # The algorithm/key hash used for encryption(if the user used SSE-C) |
| 251 | } |
| 252 | |
| 253 | struct R2UploadPartResponse { |
| 254 | etag @0 :Text; |
| 255 | # The ETag the of the uploaded part. |
| 256 | # This ETag is required in order to complete the multipart upload. |
| 257 | } |
| 258 | |
| 259 | using R2CompleteMultipartUploadResponse = R2PutResponse; |
| 260 | |
| 261 | struct R2AbortMultipartUploadResponse {} |
| 262 | |
| 263 | struct R2ListResponse { |
| 264 | objects @0 :List(R2HeadResponse); |
| 265 | truncated @1 :Bool; |
| 266 | cursor @2 :Text; |
| 267 | delimitedPrefixes @3 :List(Text); |
| 268 | } |
| 269 | |
| 270 | struct R2DeleteResponse {} |
| 271 | |
| 272 | struct R2CreateBucketResponse {} |
| 273 | struct R2ListBucketResponse { |
| 274 | buckets @0 :List(Bucket); |
| 275 | truncated @1 :Bool; |
| 276 | cursor @2 :Text; |
| 277 | |
| 278 | struct Bucket { |
| 279 | name @0 :Text; |
| 280 | createdMillisecondsSinceEpoch @1 :UInt64 $Json.name("created"); |
| 281 | } |
| 282 | } |
| 283 | struct R2DeleteBucketResponse {} |