@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/app_meta.ts +8 -0
- package/config/config.test.ts +10 -3
- package/config/config.ts +75 -21
- package/config/mod.ts +4 -3
- package/config/secrets.ts +72 -55
- package/cron/mod.ts +32 -0
- package/dist/app_meta.d.ts +7 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +1 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +44 -18
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +43 -18
- package/dist/config/config.js.map +1 -1
- package/dist/config/mod.d.ts +5 -4
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +2 -2
- package/dist/config/mod.js.map +1 -1
- package/dist/config/secrets.d.ts +62 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +21 -37
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +1 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/cron/mod.d.ts +31 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +23 -0
- package/dist/cron/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +129 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +187 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/internal/clients/call.d.ts +147 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +274 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +90 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +355 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +54 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +240 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +2 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/context.d.ts +1 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +1 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/encode.d.ts +2 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/index.d.ts +2 -2
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +1 -2
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/meter.d.ts +1 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/propagator.d.ts +1 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/provider.d.ts +1 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/span.d.ts +4 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +5 -0
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/otel/tracer.d.ts +1 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +11 -5
- package/dist/internal/otel/tracer.js.map +1 -1
- package/dist/internal/reqfields.d.ts +150 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +312 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +1 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/mod.d.ts +6 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +32 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +160 -16
- package/dist/internal/runtime/napi/napi.d.cts +474 -29
- package/dist/internal/runtime/shutdown.d.ts +5 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +9 -1
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +81 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +237 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +1 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/logger.d.ts +2 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/runtime.d.ts +2 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/stderr.d.ts +1 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/metrics/mod.d.ts +45 -118
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +44 -179
- package/dist/metrics/mod.js.map +1 -1
- package/dist/mod.d.ts +1 -2
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/dist/otel.d.ts +1 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/pubsub/encoding.d.ts +5 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +10 -2
- package/dist/pubsub/encoding.js.map +1 -1
- package/dist/pubsub/mod.d.ts +4 -3
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +2 -2
- package/dist/pubsub/mod.js.map +1 -1
- package/dist/pubsub/refs.d.ts +8 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +104 -10
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +98 -16
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +87 -23
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +143 -40
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +191 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +160 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +145 -4
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +155 -8
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +1 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/storage/objects/bucket.d.ts +312 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +305 -15
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +10 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +25 -1
- package/dist/storage/objects/error.js.map +1 -1
- package/dist/storage/objects/mod.d.ts +4 -3
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +20 -4
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +6 -0
- package/dist/storage/objects/refs.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +81 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +125 -37
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +4 -1
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +223 -139
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +128 -6
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +56 -22
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +62 -0
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +31 -4
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +26 -1
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +10 -0
- package/dist/storage/redis/native.js.map +1 -1
- package/dist/storage/redis/options.d.ts +1 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +2 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/reply.d.ts +34 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +40 -1
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +1 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/script.d.ts +1 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/target.d.ts +5 -3
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +39 -28
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +7 -10
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +8 -32
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +160 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +227 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/mod.d.ts +19 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +46 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +210 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/internal/clients/call.ts +389 -0
- package/internal/clients/grpc.test.ts +368 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +464 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +276 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/span.ts +6 -0
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +390 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +160 -16
- package/internal/runtime/napi/napi.d.cts +474 -29
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +273 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +0 -8
- package/otel.test.ts +13 -6
- package/package.json +67 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +10 -3
- package/pubsub/pubsub.test.ts +232 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +194 -16
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +220 -25
- package/reqctx/mod.ts +284 -0
- package/reqctx/reqctx.test.ts +193 -0
- package/scripts/postprocess-docs.test.ts +48 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +183 -8
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +649 -20
- package/storage/objects/error.ts +28 -1
- package/storage/objects/mod.ts +15 -0
- package/storage/objects/refs.ts +51 -3
- package/storage/postgres/database.integration.test.ts +275 -0
- package/storage/postgres/database.test.ts +193 -6
- package/storage/postgres/database.ts +202 -55
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +4 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +271 -21
- package/storage/redis/database.ts +77 -23
- package/storage/redis/mod.ts +38 -2
- package/storage/redis/native.ts +11 -0
- package/storage/redis/redis.test.ts +170 -10
- package/storage/redis/reply.ts +76 -1
- package/storage/redis/runtime.test.ts +15 -0
- package/storage/redis/target.ts +47 -44
- package/storage/redis/wire.ts +8 -32
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +337 -0
- package/testing/node.ts +12 -0
- package/testing/vitest.ts +13 -0
- package/tracing/mod.ts +82 -0
- package/tracing/native.test.ts +170 -0
- package/tracing/tracing.test.ts +317 -0
- package/dist/internal/otel/request_context.d.ts +0 -11
- package/dist/internal/otel/request_context.js +0 -20
- package/dist/internal/otel/request_context.js.map +0 -1
- package/dist/internal/reqtrack/mod.d.ts +0 -6
- package/dist/internal/reqtrack/mod.js +0 -28
- package/dist/internal/reqtrack/mod.js.map +0 -1
- package/dist/req_meta.d.ts +0 -47
- package/dist/req_meta.js +0 -26
- package/dist/req_meta.js.map +0 -1
- package/internal/otel/request_context.ts +0 -32
- package/internal/reqtrack/mod.ts +0 -39
- package/req_meta.ts +0 -75
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {activeCtxBytes} from '../../internal/otel/index';
|
|
2
2
|
import * as runtime from '../../internal/runtime/mod';
|
|
3
|
+
import {currentScope, testMode} from '../../internal/testing/scope';
|
|
3
4
|
import {StringLiteral} from '../../internal/utils/constraints';
|
|
4
|
-
import {unwrapErr} from './error';
|
|
5
|
+
import {InvalidArgument, unwrapErr} from './error';
|
|
5
6
|
import {
|
|
6
7
|
BucketPerms,
|
|
7
8
|
Uploader,
|
|
@@ -12,10 +13,31 @@ import {
|
|
|
12
13
|
Lister,
|
|
13
14
|
Remover,
|
|
14
15
|
PublicUrler,
|
|
16
|
+
AttrsUpdater,
|
|
17
|
+
IfMatchUploader,
|
|
18
|
+
IfMatchRemover,
|
|
15
19
|
} from './refs';
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* How often an object is expected to be read, which the cloud provider
|
|
23
|
+
* prices its storage by.
|
|
24
|
+
*
|
|
25
|
+
* - `standard`: read often. No minimum storage duration and no retrieval fee.
|
|
26
|
+
* - `infrequent`: read about once a month or less (GCS Nearline, S3
|
|
27
|
+
* Standard-IA). Billed for at least 30 days, with a fee per read.
|
|
28
|
+
* - `cold`: read about once a quarter or less (GCS Coldline, S3 Glacier
|
|
29
|
+
* Instant Retrieval; Standard-IA on Cloudflare R2). Billed for at least
|
|
30
|
+
* 90 days, with a higher fee per read.
|
|
31
|
+
*
|
|
32
|
+
* Every class can be read immediately.
|
|
33
|
+
*/
|
|
34
|
+
export type StorageClass = 'standard' | 'infrequent' | 'cold';
|
|
35
|
+
|
|
17
36
|
/**
|
|
18
37
|
* Configuration options for declaring a Bucket.
|
|
38
|
+
*
|
|
39
|
+
* Encore reads the configuration when it builds the app, so its values must
|
|
40
|
+
* be literals.
|
|
19
41
|
*/
|
|
20
42
|
export interface BucketConfig {
|
|
21
43
|
/**
|
|
@@ -29,6 +51,93 @@ export interface BucketConfig {
|
|
|
29
51
|
* Defaults to false if unset.
|
|
30
52
|
*/
|
|
31
53
|
versioned?: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The storage class of an object uploaded without one.
|
|
57
|
+
* Defaults to `"standard"`.
|
|
58
|
+
*
|
|
59
|
+
* `"auto"` lets the provider move each object between classes by how
|
|
60
|
+
* often it is read (GCS Autoclass, S3 Intelligent-Tiering). It is a
|
|
61
|
+
* bucket's class only: objects in such a bucket can't name a class, and
|
|
62
|
+
* lifecycle rules can't move them.
|
|
63
|
+
*/
|
|
64
|
+
storageClass?: StorageClass | 'auto';
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Rules that move objects to colder storage classes, or delete them, as
|
|
68
|
+
* they age. Providers apply them asynchronously, usually within a day,
|
|
69
|
+
* to the objects already in the bucket too.
|
|
70
|
+
*/
|
|
71
|
+
lifecycle?: LifecycleRule[];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Keep every object for at least this long after it was written: it
|
|
75
|
+
* can't be deleted or overwritten sooner.
|
|
76
|
+
*/
|
|
77
|
+
retention?: Retention;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether objects can be given their own retain-until time, with the
|
|
81
|
+
* `retainUntil` upload option and `extendRetention`.
|
|
82
|
+
* Defaults to false if unset.
|
|
83
|
+
*/
|
|
84
|
+
objectRetention?: boolean;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Tags that classify the bucket, for policies to read: written out as
|
|
88
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
89
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
90
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
91
|
+
*/
|
|
92
|
+
tags?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A lifecycle rule: an optional prefix and at least one action. Days are
|
|
97
|
+
* whole numbers from 1 to 36500 and count from when an object was written,
|
|
98
|
+
* or for the noncurrent fields, from when it was replaced or removed.
|
|
99
|
+
*/
|
|
100
|
+
export interface LifecycleRule {
|
|
101
|
+
/** Only objects whose names start with it. Defaults to every object. */
|
|
102
|
+
prefix?: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Move an object to `infrequent` this many days after it was written.
|
|
106
|
+
* At least 30.
|
|
107
|
+
*/
|
|
108
|
+
moveToInfrequentAfterDays?: number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Move an object to `cold` this many days after it was written. With
|
|
112
|
+
* `moveToInfrequentAfterDays`, at least 30 days after it.
|
|
113
|
+
*/
|
|
114
|
+
moveToColdAfterDays?: number;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Delete an object this many days after it was written. In a versioned
|
|
118
|
+
* bucket it becomes a noncurrent version, as `remove` does.
|
|
119
|
+
*/
|
|
120
|
+
deleteAfterDays?: number;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Versioned buckets: delete a noncurrent version this many days after it
|
|
124
|
+
* was replaced or removed.
|
|
125
|
+
*/
|
|
126
|
+
deleteNoncurrentAfterDays?: number;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Versioned buckets: never delete the newest this many noncurrent
|
|
130
|
+
* versions. On its own, delete the noncurrent versions beyond them.
|
|
131
|
+
*/
|
|
132
|
+
keepNoncurrentVersions?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A bucket's retention period.
|
|
137
|
+
*/
|
|
138
|
+
export interface Retention {
|
|
139
|
+
/** The days, from 1 to 36500, an object is kept after it was written. */
|
|
140
|
+
days: number;
|
|
32
141
|
}
|
|
33
142
|
|
|
34
143
|
/**
|
|
@@ -44,9 +153,14 @@ export class Bucket
|
|
|
44
153
|
Attrser,
|
|
45
154
|
Lister,
|
|
46
155
|
Remover,
|
|
47
|
-
PublicUrler
|
|
156
|
+
PublicUrler,
|
|
157
|
+
AttrsUpdater,
|
|
158
|
+
IfMatchUploader,
|
|
159
|
+
IfMatchRemover
|
|
48
160
|
{
|
|
49
|
-
|
|
161
|
+
private readonly bucketName: string;
|
|
162
|
+
/** The runtime's bucket: made on first use in test mode. */
|
|
163
|
+
private own?: runtime.Bucket;
|
|
50
164
|
|
|
51
165
|
/**
|
|
52
166
|
* Creates a new bucket with the given name and configuration
|
|
@@ -54,7 +168,16 @@ export class Bucket
|
|
|
54
168
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
169
|
constructor(name: string, cfg?: BucketConfig) {
|
|
56
170
|
super();
|
|
57
|
-
this.
|
|
171
|
+
this.bucketName = name;
|
|
172
|
+
if (!testMode) this.own = runtime.RT.bucket(name);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The native bucket: in a test, the test's instance of it. */
|
|
176
|
+
get impl(): runtime.Bucket {
|
|
177
|
+
return (
|
|
178
|
+
currentScope()?.bucket(this.bucketName) ??
|
|
179
|
+
(this.own ??= runtime.RT.bucket(this.bucketName))
|
|
180
|
+
);
|
|
58
181
|
}
|
|
59
182
|
|
|
60
183
|
/**
|
|
@@ -65,16 +188,70 @@ export class Bucket
|
|
|
65
188
|
return new Bucket(name, {});
|
|
66
189
|
}
|
|
67
190
|
|
|
68
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Lists the objects in the bucket, sorted by name.
|
|
193
|
+
*
|
|
194
|
+
* With a `delimiter`, the names that continue past the `prefix` with the
|
|
195
|
+
* delimiter are grouped into one entry per common prefix, with
|
|
196
|
+
* `isPrefix` set, as a directory listing does.
|
|
197
|
+
*/
|
|
198
|
+
async *list(options?: ListOptions): AsyncGenerator<ListEntry> {
|
|
69
199
|
const source = activeCtxBytes();
|
|
70
|
-
const iter = unwrapErr(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
200
|
+
const iter = unwrapErr(
|
|
201
|
+
await this.impl.list(
|
|
202
|
+
{
|
|
203
|
+
prefix: options?.prefix,
|
|
204
|
+
limit: options?.limit,
|
|
205
|
+
delimiter: options?.delimiter,
|
|
206
|
+
},
|
|
207
|
+
source,
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
try {
|
|
211
|
+
while (true) {
|
|
212
|
+
const entry = unwrapErr(await iter.next());
|
|
213
|
+
if (entry === null) {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
yield entry;
|
|
217
|
+
}
|
|
218
|
+
} finally {
|
|
219
|
+
iter.markDone();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Lists every stored version of the objects in the bucket, sorted by
|
|
225
|
+
* name and then newest first. A removed object has no `latest` version.
|
|
226
|
+
* An unversioned bucket lists one latest version per object.
|
|
227
|
+
*/
|
|
228
|
+
async *listVersions(
|
|
229
|
+
options?: ListVersionsOptions,
|
|
230
|
+
): AsyncGenerator<ObjectVersion> {
|
|
231
|
+
const source = activeCtxBytes();
|
|
232
|
+
const iter = unwrapErr(
|
|
233
|
+
await this.impl.listVersions(
|
|
234
|
+
{prefix: options?.prefix, limit: options?.limit},
|
|
235
|
+
source,
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
try {
|
|
239
|
+
while (true) {
|
|
240
|
+
const version = unwrapErr(await iter.next());
|
|
241
|
+
if (version === null) {
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
yield {
|
|
245
|
+
name: version.name,
|
|
246
|
+
version: version.version,
|
|
247
|
+
size: version.size,
|
|
248
|
+
etag: version.etag,
|
|
249
|
+
latest: version.latest,
|
|
250
|
+
lastModified: toDate(version.lastModified),
|
|
251
|
+
};
|
|
76
252
|
}
|
|
77
|
-
|
|
253
|
+
} finally {
|
|
254
|
+
iter.markDone();
|
|
78
255
|
}
|
|
79
256
|
}
|
|
80
257
|
|
|
@@ -97,7 +274,7 @@ export class Bucket
|
|
|
97
274
|
const source = activeCtxBytes();
|
|
98
275
|
const impl = this.impl.object(name);
|
|
99
276
|
const res = await impl.attrs(options, source);
|
|
100
|
-
return unwrapErr(res);
|
|
277
|
+
return toAttrs(unwrapErr(res));
|
|
101
278
|
}
|
|
102
279
|
|
|
103
280
|
/**
|
|
@@ -105,13 +282,118 @@ export class Bucket
|
|
|
105
282
|
*/
|
|
106
283
|
async upload(
|
|
107
284
|
name: string,
|
|
108
|
-
data:
|
|
285
|
+
data: Uint8Array,
|
|
286
|
+
options?: UploadOptions,
|
|
287
|
+
): Promise<ObjectAttrs> {
|
|
288
|
+
return uploadChunks(
|
|
289
|
+
this.impl.object(name),
|
|
290
|
+
slices(data),
|
|
291
|
+
uploadOptions(options),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Uploads an object to the bucket from a stream of bytes: a Web
|
|
297
|
+
* `ReadableStream`, a Node.js `Readable`, or any async iterable of
|
|
298
|
+
* `Uint8Array` chunks. The stream is read as fast as the upload takes
|
|
299
|
+
* its bytes.
|
|
300
|
+
*
|
|
301
|
+
* If the stream errors, the upload is aborted and nothing is stored.
|
|
302
|
+
*/
|
|
303
|
+
async uploadStream(
|
|
304
|
+
name: string,
|
|
305
|
+
data: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
|
|
109
306
|
options?: UploadOptions,
|
|
307
|
+
): Promise<ObjectAttrs> {
|
|
308
|
+
return uploadChunks(
|
|
309
|
+
this.impl.object(name),
|
|
310
|
+
chunks(data, STREAM_EXPECTED),
|
|
311
|
+
uploadOptions(options),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Uploads an object only if the bucket still holds the given revision of
|
|
317
|
+
* it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
|
|
318
|
+
* throws `PreconditionFailed` otherwise, also if the object no longer
|
|
319
|
+
* exists. This makes read-modify-write safe against concurrent writers.
|
|
320
|
+
* A missing revision throws `InvalidArgument`.
|
|
321
|
+
*
|
|
322
|
+
* `data` is bytes or a stream, as `upload` and `uploadStream` take.
|
|
323
|
+
*
|
|
324
|
+
* The match compares the object's contents, not its attributes:
|
|
325
|
+
* `updateAttrs` doesn't break it. Google Cloud Storage matches the
|
|
326
|
+
* revision's `version`, so a revision without one throws
|
|
327
|
+
* `InvalidArgument` there; Amazon S3 and Cloudflare R2 match its `etag`.
|
|
328
|
+
*
|
|
329
|
+
* On Amazon S3 a conditional write also needs read access to the bucket,
|
|
330
|
+
* which Encore grants to the services that call this.
|
|
331
|
+
*/
|
|
332
|
+
async uploadIfMatch(
|
|
333
|
+
name: string,
|
|
334
|
+
data: Uint8Array | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
|
|
335
|
+
revision: Revision,
|
|
336
|
+
options?: UploadIfMatchOptions,
|
|
337
|
+
): Promise<ObjectAttrs> {
|
|
338
|
+
const ifMatch = requiredRevision('uploadIfMatch', revision);
|
|
339
|
+
const body =
|
|
340
|
+
data instanceof Uint8Array ? slices(data) : chunks(data, BODY_EXPECTED);
|
|
341
|
+
return uploadChunks(this.impl.object(name), body, {
|
|
342
|
+
...uploadOptions(options),
|
|
343
|
+
preconditions: {ifMatch},
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Replaces the given attributes of an object and leaves the others as
|
|
349
|
+
* they are. An empty string clears an attribute (a cleared content type
|
|
350
|
+
* is `application/octet-stream`, as S3 keeps no object without one), and
|
|
351
|
+
* `metadata` replaces the whole map.
|
|
352
|
+
*
|
|
353
|
+
* On S3 this rewrites the object, so a versioned bucket gets a new
|
|
354
|
+
* version, and the object's age for lifecycle rules starts over.
|
|
355
|
+
*/
|
|
356
|
+
async updateAttrs(
|
|
357
|
+
name: string,
|
|
358
|
+
attrs: UpdateAttrs,
|
|
359
|
+
options?: UpdateAttrsOptions,
|
|
110
360
|
): Promise<ObjectAttrs> {
|
|
111
361
|
const source = activeCtxBytes();
|
|
112
362
|
const impl = this.impl.object(name);
|
|
113
|
-
const res = await impl.
|
|
114
|
-
|
|
363
|
+
const res = await impl.updateAttrs(
|
|
364
|
+
{
|
|
365
|
+
contentType: attrs.contentType,
|
|
366
|
+
cacheControl: attrs.cacheControl,
|
|
367
|
+
contentDisposition: attrs.contentDisposition,
|
|
368
|
+
metadata: attrs.metadata,
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
version: options?.version,
|
|
372
|
+
ifMatch: toRevision(options?.preconditions?.ifMatch),
|
|
373
|
+
},
|
|
374
|
+
source,
|
|
375
|
+
);
|
|
376
|
+
return toAttrs(unwrapErr(res));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Keeps the object until `until` at least. Retention can only be
|
|
381
|
+
* extended: a time earlier than the object's current one throws
|
|
382
|
+
* `InvalidArgument`. The bucket must be declared with `objectRetention`.
|
|
383
|
+
*/
|
|
384
|
+
async extendRetention(
|
|
385
|
+
name: string,
|
|
386
|
+
until: Date,
|
|
387
|
+
options?: ExtendRetentionOptions,
|
|
388
|
+
): Promise<ObjectAttrs> {
|
|
389
|
+
const source = activeCtxBytes();
|
|
390
|
+
const impl = this.impl.object(name);
|
|
391
|
+
const res = await impl.extendRetention(
|
|
392
|
+
until.getTime(),
|
|
393
|
+
{version: options?.version},
|
|
394
|
+
source,
|
|
395
|
+
);
|
|
396
|
+
return toAttrs(unwrapErr(res));
|
|
115
397
|
}
|
|
116
398
|
|
|
117
399
|
/**
|
|
@@ -119,6 +401,9 @@ export class Bucket
|
|
|
119
401
|
*
|
|
120
402
|
* Anyone with possession of the URL can write to the given object name
|
|
121
403
|
* without any additional auth.
|
|
404
|
+
*
|
|
405
|
+
* The URL doesn't carry the bucket's storage class: an object uploaded
|
|
406
|
+
* through it gets the provider's default class for the bucket.
|
|
122
407
|
*/
|
|
123
408
|
async signedUploadUrl(
|
|
124
409
|
name: string,
|
|
@@ -152,10 +437,45 @@ export class Bucket
|
|
|
152
437
|
async download(name: string, options?: DownloadOptions): Promise<Buffer> {
|
|
153
438
|
const source = activeCtxBytes();
|
|
154
439
|
const impl = this.impl.object(name);
|
|
155
|
-
const res = await impl.downloadAll(options, source);
|
|
440
|
+
const res = await impl.downloadAll(downloadOptions(options), source);
|
|
156
441
|
return unwrapErr(res);
|
|
157
442
|
}
|
|
158
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Downloads an object from the bucket as a Web `ReadableStream`, read
|
|
446
|
+
* from the provider as the consumer reads it. A missing object throws
|
|
447
|
+
* here, before any bytes. Cancelling the stream stops the download.
|
|
448
|
+
*
|
|
449
|
+
* In Node.js, `Readable.fromWeb` converts it to a Node.js stream.
|
|
450
|
+
*/
|
|
451
|
+
async downloadStream(
|
|
452
|
+
name: string,
|
|
453
|
+
options?: DownloadOptions,
|
|
454
|
+
): Promise<ReadableStream<Uint8Array>> {
|
|
455
|
+
const source = activeCtxBytes();
|
|
456
|
+
const impl = this.impl.object(name);
|
|
457
|
+
const stream = unwrapErr(
|
|
458
|
+
await impl.downloadStream(downloadOptions(options), source),
|
|
459
|
+
);
|
|
460
|
+
return new ReadableStream<Uint8Array>(
|
|
461
|
+
{
|
|
462
|
+
async pull(controller) {
|
|
463
|
+
const chunk = unwrapErr(await stream.next());
|
|
464
|
+
if (chunk === null) {
|
|
465
|
+
controller.close();
|
|
466
|
+
} else {
|
|
467
|
+
controller.enqueue(chunk);
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
async cancel() {
|
|
471
|
+
await stream.close();
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
// Read ahead of the consumer by nothing.
|
|
475
|
+
{highWaterMark: 0},
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
|
|
159
479
|
/**
|
|
160
480
|
* Removes an object from the bucket.
|
|
161
481
|
* Throws an error on network failure.
|
|
@@ -163,7 +483,32 @@ export class Bucket
|
|
|
163
483
|
async remove(name: string, options?: DeleteOptions): Promise<void> {
|
|
164
484
|
const source = activeCtxBytes();
|
|
165
485
|
const impl = this.impl.object(name);
|
|
166
|
-
const err = await impl.delete(options, source);
|
|
486
|
+
const err = await impl.delete({version: options?.version}, source);
|
|
487
|
+
if (err) {
|
|
488
|
+
unwrapErr(err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Removes an object only if the bucket still holds the given revision of
|
|
494
|
+
* it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
|
|
495
|
+
* throws `PreconditionFailed` otherwise, also if the object no longer
|
|
496
|
+
* exists. It compares the latest version, so there is no `version` to
|
|
497
|
+
* remove. A missing revision throws `InvalidArgument`.
|
|
498
|
+
*
|
|
499
|
+
* The match compares the object's contents, not its attributes:
|
|
500
|
+
* `updateAttrs` doesn't break it.
|
|
501
|
+
*
|
|
502
|
+
* On Amazon S3 a conditional delete also needs read access to the
|
|
503
|
+
* bucket, which Encore grants to the services that call this. Cloudflare
|
|
504
|
+
* R2 doesn't support conditional deletes: there it throws
|
|
505
|
+
* `InvalidArgument`.
|
|
506
|
+
*/
|
|
507
|
+
async removeIfMatch(name: string, revision: Revision): Promise<void> {
|
|
508
|
+
const ifMatch = requiredRevision('removeIfMatch', revision);
|
|
509
|
+
const source = activeCtxBytes();
|
|
510
|
+
const impl = this.impl.object(name);
|
|
511
|
+
const err = await impl.delete({ifMatch}, source);
|
|
167
512
|
if (err) {
|
|
168
513
|
unwrapErr(err);
|
|
169
514
|
}
|
|
@@ -183,6 +528,150 @@ export class Bucket
|
|
|
183
528
|
}
|
|
184
529
|
}
|
|
185
530
|
|
|
531
|
+
/** The most bytes handed to the native upload at a time. */
|
|
532
|
+
const CHUNK_SIZE = 64 * 1024;
|
|
533
|
+
|
|
534
|
+
const STREAM_EXPECTED =
|
|
535
|
+
'uploadStream takes a ReadableStream or an async iterable of Uint8Array chunks';
|
|
536
|
+
const BODY_EXPECTED =
|
|
537
|
+
'uploadIfMatch takes a Uint8Array, a ReadableStream or an async iterable of Uint8Array chunks';
|
|
538
|
+
|
|
539
|
+
async function uploadChunks(
|
|
540
|
+
obj: runtime.BucketObject,
|
|
541
|
+
data: AsyncIterable<Uint8Array> | Iterable<Uint8Array>,
|
|
542
|
+
options: runtime.UploadOptions | undefined,
|
|
543
|
+
): Promise<ObjectAttrs> {
|
|
544
|
+
const source = activeCtxBytes();
|
|
545
|
+
const stream = unwrapErr(obj.uploadStream(options, source));
|
|
546
|
+
try {
|
|
547
|
+
for await (const chunk of data) {
|
|
548
|
+
if (!(chunk instanceof Uint8Array)) {
|
|
549
|
+
throw new TypeError('upload data must be Uint8Array chunks');
|
|
550
|
+
}
|
|
551
|
+
for (const slice of slices(chunk)) {
|
|
552
|
+
const err = await stream.write(slice);
|
|
553
|
+
if (err) {
|
|
554
|
+
unwrapErr(err);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
} catch (err) {
|
|
559
|
+
// Nothing is stored unless the upload is finished.
|
|
560
|
+
await stream.abort();
|
|
561
|
+
throw err;
|
|
562
|
+
}
|
|
563
|
+
return toAttrs(unwrapErr(await stream.finish()));
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Views of `data`, of at most CHUNK_SIZE bytes each, as Buffers. */
|
|
567
|
+
function* slices(data: Uint8Array): Generator<Buffer> {
|
|
568
|
+
const buf = Buffer.isBuffer(data)
|
|
569
|
+
? data
|
|
570
|
+
: Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
571
|
+
for (let offset = 0; offset < buf.byteLength; offset += CHUNK_SIZE) {
|
|
572
|
+
yield buf.subarray(offset, offset + CHUNK_SIZE);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function chunks(
|
|
577
|
+
data: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
|
|
578
|
+
expected: string,
|
|
579
|
+
): AsyncIterable<Uint8Array> {
|
|
580
|
+
if (typeof (data as ReadableStream).getReader === 'function') {
|
|
581
|
+
return readStream(data as ReadableStream<Uint8Array>);
|
|
582
|
+
}
|
|
583
|
+
const iterable = data as AsyncIterable<Uint8Array>;
|
|
584
|
+
if (typeof iterable[Symbol.asyncIterator] !== 'function') {
|
|
585
|
+
throw new TypeError(expected);
|
|
586
|
+
}
|
|
587
|
+
return iterable;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
async function* readStream(
|
|
591
|
+
stream: ReadableStream<Uint8Array>,
|
|
592
|
+
): AsyncGenerator<Uint8Array> {
|
|
593
|
+
const reader = stream.getReader();
|
|
594
|
+
let done = false;
|
|
595
|
+
try {
|
|
596
|
+
while (true) {
|
|
597
|
+
const res = await reader.read();
|
|
598
|
+
if (res.done) {
|
|
599
|
+
done = true;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
yield res.value;
|
|
603
|
+
}
|
|
604
|
+
} finally {
|
|
605
|
+
// An upload that failed doesn't need the rest of the stream.
|
|
606
|
+
if (!done) {
|
|
607
|
+
await reader.cancel().catch(() => {});
|
|
608
|
+
}
|
|
609
|
+
reader.releaseLock();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function uploadOptions(
|
|
614
|
+
options: UploadOptions | undefined,
|
|
615
|
+
): runtime.UploadOptions | undefined {
|
|
616
|
+
return (
|
|
617
|
+
options && {
|
|
618
|
+
contentType: options.contentType,
|
|
619
|
+
cacheControl: options.cacheControl,
|
|
620
|
+
contentDisposition: options.contentDisposition,
|
|
621
|
+
metadata: options.metadata,
|
|
622
|
+
storageClass: options.storageClass,
|
|
623
|
+
retainUntil: options.retainUntil?.getTime(),
|
|
624
|
+
preconditions: options.preconditions && {
|
|
625
|
+
notExists: options.preconditions.notExists,
|
|
626
|
+
},
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function downloadOptions(
|
|
632
|
+
options: DownloadOptions | undefined,
|
|
633
|
+
): runtime.DownloadOptions | undefined {
|
|
634
|
+
return options && {version: options.version, range: options.range};
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
|
|
638
|
+
return rev && {etag: rev.etag, version: rev.version};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* The revision a `*IfMatch` method matches. A missing one, which the types
|
|
643
|
+
* forbid but plain JavaScript can pass, is refused: the write or delete would
|
|
644
|
+
* otherwise be unconditional.
|
|
645
|
+
*/
|
|
646
|
+
function requiredRevision(method: string, rev: Revision): runtime.Revision {
|
|
647
|
+
if (rev == null || typeof rev.etag !== 'string') {
|
|
648
|
+
throw new InvalidArgument(
|
|
649
|
+
`${method} needs the revision to match: the attributes attrs, upload or updateAttrs returned`,
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
return {etag: rev.etag, version: rev.version};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function toDate(millis: number | undefined): Date | undefined {
|
|
656
|
+
return millis === undefined ? undefined : new Date(millis);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function toAttrs(attrs: runtime.ObjectAttrs): ObjectAttrs {
|
|
660
|
+
return {
|
|
661
|
+
name: attrs.name,
|
|
662
|
+
size: attrs.size,
|
|
663
|
+
version: attrs.version,
|
|
664
|
+
etag: attrs.etag,
|
|
665
|
+
contentType: attrs.contentType,
|
|
666
|
+
cacheControl: attrs.cacheControl,
|
|
667
|
+
contentDisposition: attrs.contentDisposition,
|
|
668
|
+
metadata: attrs.metadata ?? {},
|
|
669
|
+
lastModified: toDate(attrs.lastModified),
|
|
670
|
+
storageClass: attrs.storageClass,
|
|
671
|
+
retainUntil: toDate(attrs.retainUntil),
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
|
|
186
675
|
/**
|
|
187
676
|
* Options for listing objects in a bucket.
|
|
188
677
|
*/
|
|
@@ -193,7 +682,30 @@ export interface ListOptions {
|
|
|
193
682
|
*/
|
|
194
683
|
prefix?: string;
|
|
195
684
|
|
|
196
|
-
/**
|
|
685
|
+
/**
|
|
686
|
+
* Maximum number of entries to return, common prefixes included.
|
|
687
|
+
* Defaults to no limit.
|
|
688
|
+
*/
|
|
689
|
+
limit?: number;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Group the names that continue past the prefix with this delimiter,
|
|
693
|
+
* usually `"/"`, into one entry per common prefix.
|
|
694
|
+
*/
|
|
695
|
+
delimiter?: string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Options for listing object versions in a bucket.
|
|
700
|
+
*/
|
|
701
|
+
export interface ListVersionsOptions {
|
|
702
|
+
/**
|
|
703
|
+
* Only include objects with this prefix in the listing.
|
|
704
|
+
* If unset, all objects are included.
|
|
705
|
+
*/
|
|
706
|
+
prefix?: string;
|
|
707
|
+
|
|
708
|
+
/** Maximum number of versions to return. Defaults to no limit. */
|
|
197
709
|
limit?: number;
|
|
198
710
|
}
|
|
199
711
|
|
|
@@ -272,6 +784,27 @@ export interface DownloadOptions {
|
|
|
272
784
|
range?: ByteRange;
|
|
273
785
|
}
|
|
274
786
|
|
|
787
|
+
/**
|
|
788
|
+
* One revision of an object: what `uploadIfMatch`, `removeIfMatch` and the
|
|
789
|
+
* `ifMatch` precondition of `updateAttrs` compare. `ObjectAttrs` is one, so
|
|
790
|
+
* the attributes an operation returned can be passed as they are.
|
|
791
|
+
*/
|
|
792
|
+
export interface Revision {
|
|
793
|
+
etag: string;
|
|
794
|
+
version?: string;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Conditions on the object an upload writes.
|
|
799
|
+
*/
|
|
800
|
+
export interface Preconditions {
|
|
801
|
+
/**
|
|
802
|
+
* Only write the object if it does not exist yet.
|
|
803
|
+
* Throws `PreconditionFailed` otherwise.
|
|
804
|
+
*/
|
|
805
|
+
notExists?: boolean;
|
|
806
|
+
}
|
|
807
|
+
|
|
275
808
|
/**
|
|
276
809
|
* Describes the attributes of an object stored in a bucket.
|
|
277
810
|
*/
|
|
@@ -282,15 +815,48 @@ export interface ObjectAttrs {
|
|
|
282
815
|
version?: string;
|
|
283
816
|
etag: string;
|
|
284
817
|
contentType?: string;
|
|
818
|
+
cacheControl?: string;
|
|
819
|
+
contentDisposition?: string;
|
|
820
|
+
/** Custom metadata; empty if the object has none. */
|
|
821
|
+
metadata: Record<string, string>;
|
|
822
|
+
/** When this version of the object was written. */
|
|
823
|
+
lastModified?: Date;
|
|
824
|
+
/**
|
|
825
|
+
* The object's storage class. Every object in a bucket whose class is
|
|
826
|
+
* `"auto"` reads `"auto"`. Undefined for a class Encore doesn't model,
|
|
827
|
+
* set outside Encore.
|
|
828
|
+
*/
|
|
829
|
+
storageClass?: StorageClass | 'auto';
|
|
830
|
+
/** The object's own retain-until time, if it has one. */
|
|
831
|
+
retainUntil?: Date;
|
|
285
832
|
}
|
|
286
833
|
|
|
287
834
|
/**
|
|
288
835
|
* A single entry returned when listing objects in a bucket.
|
|
289
836
|
*/
|
|
290
837
|
export interface ListEntry {
|
|
838
|
+
/** The object's name, or a common prefix, ending in the delimiter. */
|
|
291
839
|
name: string;
|
|
292
840
|
size: number;
|
|
293
841
|
etag: string;
|
|
842
|
+
/**
|
|
843
|
+
* Whether the entry is a common prefix of a listing with a delimiter,
|
|
844
|
+
* rather than an object. A prefix has size 0 and an empty etag.
|
|
845
|
+
*/
|
|
846
|
+
isPrefix: boolean;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* One stored version of an object, as `listVersions` lists it.
|
|
851
|
+
*/
|
|
852
|
+
export interface ObjectVersion {
|
|
853
|
+
name: string;
|
|
854
|
+
version?: string;
|
|
855
|
+
size: number;
|
|
856
|
+
etag: string;
|
|
857
|
+
/** Whether this is the object's current version. */
|
|
858
|
+
latest: boolean;
|
|
859
|
+
lastModified?: Date;
|
|
294
860
|
}
|
|
295
861
|
|
|
296
862
|
/**
|
|
@@ -298,11 +864,74 @@ export interface ListEntry {
|
|
|
298
864
|
*/
|
|
299
865
|
export interface UploadOptions {
|
|
300
866
|
contentType?: string;
|
|
867
|
+
|
|
868
|
+
/** The `Cache-Control` header that downloads of the object get. */
|
|
869
|
+
cacheControl?: string;
|
|
870
|
+
|
|
871
|
+
/** The `Content-Disposition` header that downloads of the object get. */
|
|
872
|
+
contentDisposition?: string;
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Custom metadata. Keys match `[a-z0-9][a-z0-9_-]*` and values are
|
|
876
|
+
* printable ASCII. Keys and values together may take 8 KiB on GCS and
|
|
877
|
+
* 2 KiB on S3.
|
|
878
|
+
*/
|
|
879
|
+
metadata?: Record<string, string>;
|
|
880
|
+
|
|
881
|
+
/** The object's storage class. Defaults to the bucket's. */
|
|
882
|
+
storageClass?: StorageClass;
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Keep the object until then: it can't be deleted or overwritten
|
|
886
|
+
* sooner. The bucket must be declared with `objectRetention`.
|
|
887
|
+
*/
|
|
888
|
+
retainUntil?: Date;
|
|
889
|
+
|
|
890
|
+
preconditions?: Preconditions;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Options for `uploadIfMatch`: those of `upload`, without preconditions.
|
|
895
|
+
*/
|
|
896
|
+
export type UploadIfMatchOptions = Omit<UploadOptions, 'preconditions'>;
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* The attributes `updateAttrs` replaces. An attribute left out stays as it
|
|
900
|
+
* is, and an empty string clears it; a cleared `contentType` is
|
|
901
|
+
* `application/octet-stream`. `metadata` replaces the whole map, so `{}`
|
|
902
|
+
* clears it.
|
|
903
|
+
*/
|
|
904
|
+
export interface UpdateAttrs {
|
|
905
|
+
contentType?: string;
|
|
906
|
+
cacheControl?: string;
|
|
907
|
+
contentDisposition?: string;
|
|
908
|
+
metadata?: Record<string, string>;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Options for updating an object's attributes.
|
|
913
|
+
*/
|
|
914
|
+
export interface UpdateAttrsOptions {
|
|
915
|
+
/** The object version to update. Defaults to the latest. */
|
|
916
|
+
version?: string;
|
|
917
|
+
|
|
301
918
|
preconditions?: {
|
|
302
|
-
|
|
919
|
+
/**
|
|
920
|
+
* Only update the object if it is still this revision.
|
|
921
|
+
* Throws `PreconditionFailed` otherwise.
|
|
922
|
+
*/
|
|
923
|
+
ifMatch?: Revision;
|
|
303
924
|
};
|
|
304
925
|
}
|
|
305
926
|
|
|
927
|
+
/**
|
|
928
|
+
* Options for extending an object's retention.
|
|
929
|
+
*/
|
|
930
|
+
export interface ExtendRetentionOptions {
|
|
931
|
+
/** The object version to retain. Defaults to the latest. */
|
|
932
|
+
version?: string;
|
|
933
|
+
}
|
|
934
|
+
|
|
306
935
|
/**
|
|
307
936
|
* Options for generating a signed upload URL.
|
|
308
937
|
*/
|