@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.16
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 +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
|
@@ -19,129 +19,126 @@ import {
|
|
|
19
19
|
} from './refs';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Storage tier indicating how frequently an object is accessed, used by cloud
|
|
23
|
+
* providers to price storage and retrieval:
|
|
24
24
|
*
|
|
25
|
-
* - `standard`:
|
|
26
|
-
* - `infrequent`:
|
|
27
|
-
* Standard-IA)
|
|
28
|
-
* - `cold`:
|
|
29
|
-
* Instant Retrieval; Standard-IA on Cloudflare R2)
|
|
30
|
-
*
|
|
25
|
+
* - `standard`: frequent access; no minimum storage duration or retrieval fee.
|
|
26
|
+
* - `infrequent`: accessed roughly once a month or less (GCS Nearline, S3
|
|
27
|
+
* Standard-IA); billed for at least 30 days with a per-read retrieval fee.
|
|
28
|
+
* - `cold`: accessed roughly once a quarter or less (GCS Coldline, S3 Glacier
|
|
29
|
+
* Instant Retrieval; Standard-IA on Cloudflare R2); billed for at least 90
|
|
30
|
+
* days with a higher per-read retrieval fee.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
32
|
+
* Objects in every class remain immediately readable.
|
|
33
33
|
*/
|
|
34
34
|
export type StorageClass = 'standard' | 'infrequent' | 'cold';
|
|
35
35
|
|
|
36
36
|
/**
|
|
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.
|
|
37
|
+
* Configuration options for declaring a {@link Bucket}. Values must be
|
|
38
|
+
* literals so Encore can inspect them at build time.
|
|
41
39
|
*/
|
|
42
40
|
export interface BucketConfig {
|
|
43
41
|
/**
|
|
44
|
-
* Whether
|
|
45
|
-
*
|
|
42
|
+
* Whether objects in the bucket are publicly accessible via CDN.
|
|
43
|
+
* Defaults to `false`.
|
|
46
44
|
*/
|
|
47
45
|
public?: boolean;
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
|
-
* Whether
|
|
51
|
-
* Defaults to false
|
|
48
|
+
* Whether object versioning is enabled on the bucket.
|
|
49
|
+
* Defaults to `false`.
|
|
52
50
|
*/
|
|
53
51
|
versioned?: boolean;
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
|
-
*
|
|
57
|
-
* Defaults to `"standard"`.
|
|
54
|
+
* Default storage class for newly uploaded objects. Defaults to `"standard"`.
|
|
58
55
|
*
|
|
59
|
-
* `"auto"`
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
56
|
+
* Setting `"auto"` delegates class transitions to the provider based on
|
|
57
|
+
* access patterns (GCS Autoclass, S3 Intelligent-Tiering). When `"auto"` is
|
|
58
|
+
* set, individual uploads cannot override `storageClass` and lifecycle rules
|
|
59
|
+
* cannot transition storage classes.
|
|
63
60
|
*/
|
|
64
61
|
storageClass?: StorageClass | 'auto';
|
|
65
62
|
|
|
66
63
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
64
|
+
* Lifecycle rules that automatically transition objects to colder storage
|
|
65
|
+
* classes or delete them as they age. Providers evaluate rules
|
|
66
|
+
* asynchronously (typically within a day), including for existing objects.
|
|
70
67
|
*/
|
|
71
68
|
lifecycle?: LifecycleRule[];
|
|
72
69
|
|
|
73
70
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
71
|
+
* Minimum retention period applied to every object in the bucket; objects
|
|
72
|
+
* cannot be deleted or overwritten before this period elapses.
|
|
76
73
|
*/
|
|
77
74
|
retention?: Retention;
|
|
78
75
|
|
|
79
76
|
/**
|
|
80
|
-
* Whether objects can
|
|
81
|
-
*
|
|
82
|
-
* Defaults to false if unset.
|
|
77
|
+
* Whether individual objects can specify their own `retainUntil` timestamp
|
|
78
|
+
* via upload options and {@link Bucket.extendRetention}. Defaults to `false`.
|
|
83
79
|
*/
|
|
84
80
|
objectRetention?: boolean;
|
|
85
81
|
|
|
86
82
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
83
|
+
* Static string-literal tags that classify the bucket for policy checks
|
|
84
|
+
* (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
|
|
85
|
+
* digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
|
|
86
|
+
* and cannot start with the reserved prefix `encore`. At most 32 tags.
|
|
91
87
|
*/
|
|
92
88
|
tags?: Record<string, string>;
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
/**
|
|
96
|
-
* A lifecycle rule
|
|
97
|
-
* whole numbers from 1 to 36500
|
|
98
|
-
*
|
|
92
|
+
* A lifecycle rule with an optional key prefix and at least one action. Day
|
|
93
|
+
* counts are whole numbers from 1 to 36500 measured from creation time (or
|
|
94
|
+
* from replacement/deletion time for noncurrent version rules).
|
|
99
95
|
*/
|
|
100
96
|
export interface LifecycleRule {
|
|
101
|
-
/**
|
|
97
|
+
/** Restrict the rule to objects whose names start with this prefix. Defaults to all objects. */
|
|
102
98
|
prefix?: string;
|
|
103
99
|
|
|
104
100
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
101
|
+
* Transition objects to `infrequent` storage this many days after creation.
|
|
102
|
+
* Must be at least 30.
|
|
107
103
|
*/
|
|
108
104
|
moveToInfrequentAfterDays?: number;
|
|
109
105
|
|
|
110
106
|
/**
|
|
111
|
-
*
|
|
112
|
-
* `moveToInfrequentAfterDays`, at least 30 days
|
|
107
|
+
* Transition objects to `cold` storage this many days after creation. When
|
|
108
|
+
* combined with `moveToInfrequentAfterDays`, must be at least 30 days later.
|
|
113
109
|
*/
|
|
114
110
|
moveToColdAfterDays?: number;
|
|
115
111
|
|
|
116
112
|
/**
|
|
117
|
-
* Delete
|
|
118
|
-
*
|
|
113
|
+
* Delete objects this many days after creation. In versioned buckets, the
|
|
114
|
+
* object becomes a noncurrent version (just like {@link Bucket.remove}).
|
|
119
115
|
*/
|
|
120
116
|
deleteAfterDays?: number;
|
|
121
117
|
|
|
122
118
|
/**
|
|
123
|
-
* Versioned buckets: delete
|
|
124
|
-
*
|
|
119
|
+
* Versioned buckets only: delete noncurrent versions this many days after
|
|
120
|
+
* they were replaced or removed.
|
|
125
121
|
*/
|
|
126
122
|
deleteNoncurrentAfterDays?: number;
|
|
127
123
|
|
|
128
124
|
/**
|
|
129
|
-
* Versioned buckets:
|
|
130
|
-
* versions
|
|
125
|
+
* Versioned buckets only: retain at least this many of the newest noncurrent
|
|
126
|
+
* versions (deleting older noncurrent versions beyond this count when used
|
|
127
|
+
* on its own).
|
|
131
128
|
*/
|
|
132
129
|
keepNoncurrentVersions?: number;
|
|
133
130
|
}
|
|
134
131
|
|
|
135
132
|
/**
|
|
136
|
-
*
|
|
133
|
+
* Bucket-level retention period.
|
|
137
134
|
*/
|
|
138
135
|
export interface Retention {
|
|
139
|
-
/**
|
|
136
|
+
/** Number of days (1 to 36500) to retain each object after creation. */
|
|
140
137
|
days: number;
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
/**
|
|
144
|
-
*
|
|
141
|
+
* Declares an Object Storage bucket infrastructure resource.
|
|
145
142
|
*/
|
|
146
143
|
export class Bucket
|
|
147
144
|
extends BucketPerms
|
|
@@ -159,11 +156,11 @@ export class Bucket
|
|
|
159
156
|
IfMatchRemover
|
|
160
157
|
{
|
|
161
158
|
private readonly bucketName: string;
|
|
162
|
-
/**
|
|
159
|
+
/** Native runtime bucket, initialized lazily in test mode. */
|
|
163
160
|
private own?: runtime.Bucket;
|
|
164
161
|
|
|
165
162
|
/**
|
|
166
|
-
*
|
|
163
|
+
* Declares a new bucket with the given name and configuration.
|
|
167
164
|
*/
|
|
168
165
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
169
166
|
constructor(name: string, cfg?: BucketConfig) {
|
|
@@ -172,8 +169,7 @@ export class Bucket
|
|
|
172
169
|
if (!testMode) this.own = runtime.RT.bucket(name);
|
|
173
170
|
}
|
|
174
171
|
|
|
175
|
-
/**
|
|
176
|
-
* @internal */
|
|
172
|
+
/** Native bucket handle (resolves to the current test's instance in test mode). @internal */
|
|
177
173
|
get impl(): runtime.Bucket {
|
|
178
174
|
return (
|
|
179
175
|
currentScope()?.bucket(this.bucketName) ??
|
|
@@ -182,19 +178,19 @@ export class Bucket
|
|
|
182
178
|
}
|
|
183
179
|
|
|
184
180
|
/**
|
|
185
|
-
*
|
|
186
|
-
* To
|
|
181
|
+
* References an existing bucket by name.
|
|
182
|
+
* To declare a new bucket, use `new Bucket(...)` instead.
|
|
187
183
|
*/
|
|
188
184
|
static named<name extends string>(name: StringLiteral<name>): Bucket {
|
|
189
185
|
return new Bucket(name, {});
|
|
190
186
|
}
|
|
191
187
|
|
|
192
188
|
/**
|
|
193
|
-
* Lists
|
|
189
|
+
* Lists objects in the bucket in lexicographical order by name.
|
|
194
190
|
*
|
|
195
|
-
*
|
|
196
|
-
* delimiter are grouped into
|
|
197
|
-
*
|
|
191
|
+
* When `delimiter` is set, keys sharing a common prefix past `options.prefix`
|
|
192
|
+
* up to the delimiter are grouped into a single entry with `isPrefix: true`
|
|
193
|
+
* (similar to a directory listing).
|
|
198
194
|
*/
|
|
199
195
|
async *list(options?: ListOptions): AsyncGenerator<ListEntry> {
|
|
200
196
|
const source = activeCtxBytes();
|
|
@@ -228,9 +224,9 @@ export class Bucket
|
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
/**
|
|
231
|
-
* Lists
|
|
232
|
-
*
|
|
233
|
-
*
|
|
227
|
+
* Lists all stored object versions in the bucket, sorted by name and then
|
|
228
|
+
* newest first. Deleted objects have no `latest` version. In unversioned
|
|
229
|
+
* buckets, yields one `latest` version per object.
|
|
234
230
|
*/
|
|
235
231
|
async *listVersions(
|
|
236
232
|
options?: ListVersionsOptions,
|
|
@@ -275,7 +271,7 @@ export class Bucket
|
|
|
275
271
|
|
|
276
272
|
/**
|
|
277
273
|
* Returns the object's attributes.
|
|
278
|
-
* Throws
|
|
274
|
+
* Throws `ObjectNotFound` if the object does not exist.
|
|
279
275
|
*/
|
|
280
276
|
async attrs(name: string, options?: AttrsOptions): Promise<ObjectAttrs> {
|
|
281
277
|
const source = activeCtxBytes();
|
|
@@ -300,10 +296,9 @@ export class Bucket
|
|
|
300
296
|
}
|
|
301
297
|
|
|
302
298
|
/**
|
|
303
|
-
* Uploads an object
|
|
304
|
-
* `
|
|
305
|
-
*
|
|
306
|
-
* its bytes.
|
|
299
|
+
* Uploads an object from a byte stream — a Web `ReadableStream`, Node.js
|
|
300
|
+
* `Readable`, or any async iterable of `Uint8Array` chunks — pulling chunks
|
|
301
|
+
* as the upload consumes them.
|
|
307
302
|
*
|
|
308
303
|
* If the stream errors, the upload is aborted and nothing is stored.
|
|
309
304
|
*/
|
|
@@ -320,21 +315,19 @@ export class Bucket
|
|
|
320
315
|
}
|
|
321
316
|
|
|
322
317
|
/**
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
* concurrent writers. A missing revision throws `InvalidArgument`.
|
|
328
|
-
*
|
|
329
|
-
* `data` is bytes or a stream, as `upload` and `uploadStream` take.
|
|
318
|
+
* Conditionally uploads an object only if the bucket still holds `revision`
|
|
319
|
+
* (returned by `download`, `attrs`, `upload`, `updateAttrs`, or `list`),
|
|
320
|
+
* throwing `PreconditionFailed` if the object changed or was deleted. Throws
|
|
321
|
+
* `InvalidArgument` if `revision` is missing.
|
|
330
322
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* `InvalidArgument`
|
|
323
|
+
* `data` may be a `Uint8Array` or a stream (as in {@link upload} and
|
|
324
|
+
* {@link uploadStream}). Comparisons check object contents rather than
|
|
325
|
+
* metadata, so {@link updateAttrs} does not invalidate a match. GCS matches
|
|
326
|
+
* on `revision.version` (throwing `InvalidArgument` if absent), while S3 and
|
|
327
|
+
* Cloudflare R2 match on `revision.etag`.
|
|
335
328
|
*
|
|
336
|
-
* On
|
|
337
|
-
*
|
|
329
|
+
* On AWS S3, conditional writes also require read permission, which Encore
|
|
330
|
+
* grants automatically to calling services.
|
|
338
331
|
*/
|
|
339
332
|
async uploadIfMatch(
|
|
340
333
|
name: string,
|
|
@@ -352,13 +345,13 @@ export class Bucket
|
|
|
352
345
|
}
|
|
353
346
|
|
|
354
347
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* `metadata`
|
|
348
|
+
* Updates the specified attributes of an object while leaving omitted
|
|
349
|
+
* attributes unchanged. Pass an empty string to clear an attribute (clearing
|
|
350
|
+
* `contentType` resets it to `application/octet-stream`), and pass a new
|
|
351
|
+
* `metadata` object to replace the entire metadata map (`{}` clears it).
|
|
359
352
|
*
|
|
360
|
-
* On S3
|
|
361
|
-
*
|
|
353
|
+
* On AWS S3, updating attributes rewrites the object, creating a new version
|
|
354
|
+
* in versioned buckets and resetting the object's lifecycle age.
|
|
362
355
|
*/
|
|
363
356
|
async updateAttrs(
|
|
364
357
|
name: string,
|
|
@@ -384,9 +377,9 @@ export class Bucket
|
|
|
384
377
|
}
|
|
385
378
|
|
|
386
379
|
/**
|
|
387
|
-
*
|
|
388
|
-
* extended
|
|
389
|
-
* `InvalidArgument`.
|
|
380
|
+
* Extends the object's retention until at least `until`. Retention can only
|
|
381
|
+
* be extended — passing a time earlier than the current retention throws
|
|
382
|
+
* `InvalidArgument`. Requires `objectRetention: true` on the bucket.
|
|
390
383
|
*/
|
|
391
384
|
async extendRetention(
|
|
392
385
|
name: string,
|
|
@@ -404,13 +397,11 @@ export class Bucket
|
|
|
404
397
|
}
|
|
405
398
|
|
|
406
399
|
/**
|
|
407
|
-
*
|
|
400
|
+
* Generates a pre-signed URL allowing anyone with the URL to upload to
|
|
401
|
+
* `name` without additional authentication.
|
|
408
402
|
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* The URL doesn't carry the bucket's storage class: an object uploaded
|
|
413
|
-
* through it gets the provider's default class for the bucket.
|
|
403
|
+
* Note: Pre-signed upload URLs do not enforce the bucket's configured
|
|
404
|
+
* `storageClass`; uploaded objects receive the provider's default class.
|
|
414
405
|
*/
|
|
415
406
|
async signedUploadUrl(
|
|
416
407
|
name: string,
|
|
@@ -423,10 +414,8 @@ export class Bucket
|
|
|
423
414
|
}
|
|
424
415
|
|
|
425
416
|
/**
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
* Anyone with possession of the URL can download the given object without
|
|
429
|
-
* any additional auth.
|
|
417
|
+
* Generates a pre-signed URL allowing anyone with the URL to download `name`
|
|
418
|
+
* without additional authentication.
|
|
430
419
|
*/
|
|
431
420
|
async signedDownloadUrl(
|
|
432
421
|
name: string,
|
|
@@ -439,16 +428,15 @@ export class Bucket
|
|
|
439
428
|
}
|
|
440
429
|
|
|
441
430
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* range
|
|
445
|
-
*
|
|
446
|
-
* arrive (`stream`).
|
|
431
|
+
* Starts downloading an object from the bucket. Resolves as soon as the
|
|
432
|
+
* provider responds (throwing immediately if the object is missing or the
|
|
433
|
+
* byte range is invalid), returning a {@link Download} with response
|
|
434
|
+
* metadata and one-shot `bytes()` / `stream()` readers.
|
|
447
435
|
*
|
|
448
436
|
* ```ts
|
|
449
437
|
* const d = await uploads.download("state.json");
|
|
450
438
|
* const state = JSON.parse((await d.bytes()).toString());
|
|
451
|
-
* //
|
|
439
|
+
* // Write only if nobody else updated the object since we read it.
|
|
452
440
|
* await uploads.uploadIfMatch("state.json", next(state), d.revision);
|
|
453
441
|
* ```
|
|
454
442
|
*/
|
|
@@ -473,18 +461,15 @@ export class Bucket
|
|
|
473
461
|
}
|
|
474
462
|
|
|
475
463
|
/**
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* `version` to remove. A missing revision throws `InvalidArgument`.
|
|
464
|
+
* Conditionally removes an object only if its latest version still matches
|
|
465
|
+
* `revision` (returned by `download`, `attrs`, `upload`, `updateAttrs`, or
|
|
466
|
+
* `list`), throwing `PreconditionFailed` if it changed or no longer exists.
|
|
467
|
+
* Throws `InvalidArgument` if `revision` is missing.
|
|
481
468
|
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* bucket, which Encore grants to the services that call this. Cloudflare
|
|
487
|
-
* R2 doesn't support conditional deletes: there it throws
|
|
469
|
+
* Comparisons check object contents rather than metadata, so
|
|
470
|
+
* {@link updateAttrs} does not invalidate a match. On AWS S3, conditional
|
|
471
|
+
* deletes require read permission (granted automatically by Encore).
|
|
472
|
+
* Cloudflare R2 does not support conditional deletes and throws
|
|
488
473
|
* `InvalidArgument`.
|
|
489
474
|
*/
|
|
490
475
|
async removeIfMatch(name: string, revision: Revision): Promise<void> {
|
|
@@ -498,8 +483,8 @@ export class Bucket
|
|
|
498
483
|
}
|
|
499
484
|
|
|
500
485
|
/**
|
|
501
|
-
* Returns the public URL for accessing the object
|
|
502
|
-
* Throws an error if the bucket is not public
|
|
486
|
+
* Returns the public CDN URL for accessing the object.
|
|
487
|
+
* Throws an error if the bucket is not declared with `public: true`.
|
|
503
488
|
*/
|
|
504
489
|
publicUrl(name: string): string {
|
|
505
490
|
const obj = this.impl.object(name);
|
|
@@ -511,13 +496,13 @@ export class Bucket
|
|
|
511
496
|
}
|
|
512
497
|
}
|
|
513
498
|
|
|
514
|
-
/**
|
|
499
|
+
/** Maximum chunk size passed to the native upload writer at a time. */
|
|
515
500
|
const CHUNK_SIZE = 64 * 1024;
|
|
516
501
|
|
|
517
502
|
const STREAM_EXPECTED =
|
|
518
|
-
'uploadStream
|
|
503
|
+
'uploadStream expects a ReadableStream or an async iterable of Uint8Array chunks';
|
|
519
504
|
const BODY_EXPECTED =
|
|
520
|
-
'uploadIfMatch
|
|
505
|
+
'uploadIfMatch expects a Uint8Array, ReadableStream, or async iterable of Uint8Array chunks';
|
|
521
506
|
|
|
522
507
|
async function uploadChunks(
|
|
523
508
|
obj: runtime.BucketObject,
|
|
@@ -529,7 +514,7 @@ async function uploadChunks(
|
|
|
529
514
|
try {
|
|
530
515
|
for await (const chunk of data) {
|
|
531
516
|
if (!(chunk instanceof Uint8Array)) {
|
|
532
|
-
throw new TypeError('upload data must
|
|
517
|
+
throw new TypeError('upload data must consist of Uint8Array chunks');
|
|
533
518
|
}
|
|
534
519
|
for (const slice of slices(chunk)) {
|
|
535
520
|
const err = await stream.write(slice);
|
|
@@ -546,7 +531,7 @@ async function uploadChunks(
|
|
|
546
531
|
return toAttrs(unwrapErr(await stream.finish()));
|
|
547
532
|
}
|
|
548
533
|
|
|
549
|
-
/**
|
|
534
|
+
/** Yields `Buffer` views of `data`, each at most `CHUNK_SIZE` bytes. */
|
|
550
535
|
function* slices(data: Uint8Array): Generator<Buffer> {
|
|
551
536
|
const buf = Buffer.isBuffer(data)
|
|
552
537
|
? data
|
|
@@ -627,20 +612,20 @@ function byteRange(
|
|
|
627
612
|
if (range.last !== undefined) {
|
|
628
613
|
if (range.offset !== undefined || range.length !== undefined) {
|
|
629
614
|
throw new InvalidArgument(
|
|
630
|
-
'
|
|
615
|
+
'byte range must specify either `offset` (with optional `length`) or `last`, not both',
|
|
631
616
|
);
|
|
632
617
|
}
|
|
633
618
|
return {last: range.last};
|
|
634
619
|
}
|
|
635
620
|
if (typeof range.offset !== 'number') {
|
|
636
621
|
throw new InvalidArgument(
|
|
637
|
-
'
|
|
622
|
+
'byte range must specify either a numeric `offset` or `last`',
|
|
638
623
|
);
|
|
639
624
|
}
|
|
640
625
|
return {offset: range.offset, length: range.length};
|
|
641
626
|
}
|
|
642
627
|
|
|
643
|
-
/**
|
|
628
|
+
/** Wraps a native runtime download handle. */
|
|
644
629
|
class NativeDownload implements Download {
|
|
645
630
|
readonly revision: Revision;
|
|
646
631
|
readonly size: number;
|
|
@@ -683,11 +668,11 @@ class NativeDownload implements Download {
|
|
|
683
668
|
);
|
|
684
669
|
}
|
|
685
670
|
|
|
686
|
-
/**
|
|
671
|
+
/** Enforces single consumption of the download body. */
|
|
687
672
|
private take(method: string): void {
|
|
688
673
|
if (this.read) {
|
|
689
674
|
throw new InvalidArgument(
|
|
690
|
-
`${method}:
|
|
675
|
+
`${method}: download body has already been consumed`,
|
|
691
676
|
);
|
|
692
677
|
}
|
|
693
678
|
this.read = true;
|
|
@@ -699,14 +684,13 @@ function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
|
|
|
699
684
|
}
|
|
700
685
|
|
|
701
686
|
/**
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
* otherwise be unconditional.
|
|
687
|
+
* Validates that `*IfMatch` callers supplied a revision so writes or deletes
|
|
688
|
+
* cannot silently become unconditional in untyped JS.
|
|
705
689
|
*/
|
|
706
690
|
function requiredRevision(method: string, rev: Revision): runtime.Revision {
|
|
707
691
|
if (rev == null || typeof rev.etag !== 'string') {
|
|
708
692
|
throw new InvalidArgument(
|
|
709
|
-
`${method}
|
|
693
|
+
`${method} requires a revision (e.g. from download.revision, attrs(), upload(), or updateAttrs())`,
|
|
710
694
|
);
|
|
711
695
|
}
|
|
712
696
|
return {etag: rev.etag, version: rev.version};
|
|
@@ -737,20 +721,20 @@ function toAttrs(attrs: runtime.ObjectAttrs): ObjectAttrs {
|
|
|
737
721
|
*/
|
|
738
722
|
export interface ListOptions {
|
|
739
723
|
/**
|
|
740
|
-
* Only include objects with this prefix
|
|
741
|
-
*
|
|
724
|
+
* Only include objects whose names start with this prefix.
|
|
725
|
+
* Defaults to all objects.
|
|
742
726
|
*/
|
|
743
727
|
prefix?: string;
|
|
744
728
|
|
|
745
729
|
/**
|
|
746
|
-
* Maximum number of entries to return
|
|
747
|
-
*
|
|
730
|
+
* Maximum number of entries to return (including common prefixes).
|
|
731
|
+
* Unlimited when unset.
|
|
748
732
|
*/
|
|
749
733
|
limit?: number;
|
|
750
734
|
|
|
751
735
|
/**
|
|
752
|
-
*
|
|
753
|
-
*
|
|
736
|
+
* Delimiter (typically `"/"`) used to group object names past `prefix` into
|
|
737
|
+
* single common-prefix entries.
|
|
754
738
|
*/
|
|
755
739
|
delimiter?: string;
|
|
756
740
|
}
|
|
@@ -760,37 +744,33 @@ export interface ListOptions {
|
|
|
760
744
|
*/
|
|
761
745
|
export interface ListVersionsOptions {
|
|
762
746
|
/**
|
|
763
|
-
* Only include objects with this prefix
|
|
764
|
-
*
|
|
747
|
+
* Only include objects whose names start with this prefix.
|
|
748
|
+
* Defaults to all objects.
|
|
765
749
|
*/
|
|
766
750
|
prefix?: string;
|
|
767
751
|
|
|
768
|
-
/** Maximum number of versions to return.
|
|
752
|
+
/** Maximum number of versions to return. Unlimited when unset. */
|
|
769
753
|
limit?: number;
|
|
770
754
|
}
|
|
771
755
|
|
|
772
756
|
/**
|
|
773
|
-
* Options for retrieving
|
|
757
|
+
* Options for retrieving an object's attributes.
|
|
774
758
|
*/
|
|
775
759
|
export interface AttrsOptions {
|
|
776
760
|
/**
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
* If bucket versioning is not enabled, this option is ignored.
|
|
761
|
+
* Object version to inspect. Defaults to the latest version.
|
|
762
|
+
* Ignored if bucket versioning is disabled.
|
|
781
763
|
*/
|
|
782
764
|
version?: string;
|
|
783
765
|
}
|
|
784
766
|
|
|
785
767
|
/**
|
|
786
|
-
* Options for checking
|
|
768
|
+
* Options for checking whether an object exists.
|
|
787
769
|
*/
|
|
788
770
|
export interface ExistsOptions {
|
|
789
771
|
/**
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
* If bucket versioning is not enabled, this option is ignored.
|
|
772
|
+
* Object version to check. Defaults to the latest version.
|
|
773
|
+
* Ignored if bucket versioning is disabled.
|
|
794
774
|
*/
|
|
795
775
|
version?: string;
|
|
796
776
|
}
|
|
@@ -800,26 +780,24 @@ export interface ExistsOptions {
|
|
|
800
780
|
*/
|
|
801
781
|
export interface DeleteOptions {
|
|
802
782
|
/**
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
* If bucket versioning is not enabled, this option is ignored.
|
|
783
|
+
* Object version to delete. Defaults to the latest version.
|
|
784
|
+
* Ignored if bucket versioning is disabled.
|
|
807
785
|
*/
|
|
808
786
|
version?: string;
|
|
809
787
|
}
|
|
810
788
|
|
|
811
789
|
/**
|
|
812
|
-
* A contiguous byte range within an object: `length` bytes
|
|
813
|
-
* or the
|
|
790
|
+
* A contiguous byte range within an object: either `length` bytes starting at
|
|
791
|
+
* `offset`, or the final `last` bytes of the object.
|
|
814
792
|
*/
|
|
815
793
|
export type ByteRange =
|
|
816
794
|
| {
|
|
817
|
-
/**
|
|
795
|
+
/** Zero-based index of the first byte to read. */
|
|
818
796
|
offset: number;
|
|
819
797
|
|
|
820
798
|
/**
|
|
821
|
-
*
|
|
822
|
-
*
|
|
799
|
+
* Number of bytes to read. Reads through the end of the object when
|
|
800
|
+
* omitted.
|
|
823
801
|
*/
|
|
824
802
|
length?: number;
|
|
825
803
|
|
|
@@ -827,9 +805,8 @@ export type ByteRange =
|
|
|
827
805
|
}
|
|
828
806
|
| {
|
|
829
807
|
/**
|
|
830
|
-
* Read the
|
|
831
|
-
*
|
|
832
|
-
* is, and so where in it the bytes are.
|
|
808
|
+
* Read the final `last` bytes of the object (or the entire object if it
|
|
809
|
+
* is shorter). Check {@link Download.size} for the object's full length.
|
|
833
810
|
*/
|
|
834
811
|
last: number;
|
|
835
812
|
|
|
@@ -842,70 +819,63 @@ export type ByteRange =
|
|
|
842
819
|
*/
|
|
843
820
|
export interface DownloadOptions {
|
|
844
821
|
/**
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
* If bucket versioning is not enabled, this option is ignored.
|
|
822
|
+
* Object version to download. Defaults to the latest version.
|
|
823
|
+
* Ignored if bucket versioning is disabled.
|
|
849
824
|
*/
|
|
850
825
|
version?: string;
|
|
851
826
|
|
|
852
827
|
/**
|
|
853
|
-
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
828
|
+
* Optional byte range to download instead of the full object. The body
|
|
829
|
+
* contains only the requested slice while {@link Download.size} still
|
|
830
|
+
* reports the full object size.
|
|
856
831
|
*
|
|
857
|
-
* Throws InvalidArgument if the range is empty or
|
|
858
|
-
*
|
|
832
|
+
* Throws `InvalidArgument` if the range is empty or starts past the end of
|
|
833
|
+
* the object.
|
|
859
834
|
*/
|
|
860
835
|
range?: ByteRange;
|
|
861
836
|
}
|
|
862
837
|
|
|
863
838
|
/**
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
* once, whole or as they arrive.
|
|
839
|
+
* An in-progress download returned by {@link Bucket.download}, exposing basic
|
|
840
|
+
* response metadata and one-shot body readers (`bytes()` or `stream()`).
|
|
867
841
|
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
* it is garbage collected. To give one up, cancel its stream:
|
|
873
|
-
* `await d.stream().cancel()`.
|
|
842
|
+
* Includes only the metadata providers send alongside download responses (use
|
|
843
|
+
* {@link Bucket.attrs} for full metadata). An unread download holds its
|
|
844
|
+
* connection open until garbage collected; call `await d.stream().cancel()` to
|
|
845
|
+
* release it early.
|
|
874
846
|
*/
|
|
875
847
|
export interface Download {
|
|
876
848
|
/**
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
* was read.
|
|
849
|
+
* Revision of the downloaded contents. Pass to {@link Bucket.uploadIfMatch}
|
|
850
|
+
* or {@link Bucket.removeIfMatch} for optimistic concurrency control.
|
|
880
851
|
*/
|
|
881
852
|
readonly revision: Revision;
|
|
882
|
-
/**
|
|
853
|
+
/** Full object size in bytes, even when downloading a byte range. */
|
|
883
854
|
readonly size: number;
|
|
884
855
|
readonly contentType?: string;
|
|
885
|
-
/**
|
|
856
|
+
/** Last modification timestamp, if reported by the provider. */
|
|
886
857
|
readonly lastModified?: Date;
|
|
887
858
|
|
|
888
859
|
/**
|
|
889
|
-
*
|
|
890
|
-
* already
|
|
860
|
+
* Buffers and returns the entire download body. Throws `InvalidArgument` if
|
|
861
|
+
* the body has already been consumed.
|
|
891
862
|
*/
|
|
892
863
|
bytes(): Promise<Buffer>;
|
|
893
864
|
|
|
894
865
|
/**
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
866
|
+
* Streams the download body as a Web `ReadableStream`. Canceling the stream
|
|
867
|
+
* aborts the download. Throws `InvalidArgument` if the body has already been
|
|
868
|
+
* consumed.
|
|
898
869
|
*
|
|
899
|
-
* In Node.js, `Readable.fromWeb`
|
|
870
|
+
* In Node.js, use `Readable.fromWeb` to convert this into a Node stream.
|
|
900
871
|
*/
|
|
901
872
|
stream(): ReadableStream<Uint8Array>;
|
|
902
873
|
}
|
|
903
874
|
|
|
904
875
|
/**
|
|
905
|
-
*
|
|
906
|
-
* `
|
|
907
|
-
*
|
|
908
|
-
* download's `revision` is one, of the contents it reads.
|
|
876
|
+
* Identifies a specific content revision of an object for conditional
|
|
877
|
+
* operations (`uploadIfMatch`, `removeIfMatch`, and `updateAttrs` `ifMatch`).
|
|
878
|
+
* Both {@link ObjectAttrs} and {@link Download.revision} satisfy `Revision`.
|
|
909
879
|
*/
|
|
910
880
|
export interface Revision {
|
|
911
881
|
etag: string;
|
|
@@ -913,68 +883,67 @@ export interface Revision {
|
|
|
913
883
|
}
|
|
914
884
|
|
|
915
885
|
/**
|
|
916
|
-
*
|
|
886
|
+
* Preconditions for an upload.
|
|
917
887
|
*/
|
|
918
888
|
export interface Preconditions {
|
|
919
889
|
/**
|
|
920
|
-
* Only write the object if it does not exist
|
|
921
|
-
*
|
|
890
|
+
* Only write the object if it does not already exist; throws
|
|
891
|
+
* `PreconditionFailed` otherwise.
|
|
922
892
|
*/
|
|
923
893
|
notExists?: boolean;
|
|
924
894
|
}
|
|
925
895
|
|
|
926
896
|
/**
|
|
927
|
-
*
|
|
897
|
+
* Attributes of an object stored in a bucket.
|
|
928
898
|
*/
|
|
929
899
|
export interface ObjectAttrs {
|
|
930
900
|
name: string;
|
|
931
901
|
size: number;
|
|
932
|
-
/**
|
|
902
|
+
/** Object version identifier, if bucket versioning is enabled. */
|
|
933
903
|
version?: string;
|
|
934
904
|
etag: string;
|
|
935
905
|
contentType?: string;
|
|
936
906
|
cacheControl?: string;
|
|
937
907
|
contentDisposition?: string;
|
|
938
|
-
/** Custom metadata
|
|
908
|
+
/** Custom metadata map (empty object if none). */
|
|
939
909
|
metadata: Record<string, string>;
|
|
940
|
-
/**
|
|
910
|
+
/** Timestamp when this object version was written. */
|
|
941
911
|
lastModified?: Date;
|
|
942
912
|
/**
|
|
943
|
-
*
|
|
944
|
-
* `
|
|
945
|
-
* set outside Encore.
|
|
913
|
+
* Object storage class (`"auto"` for buckets with `storageClass: "auto"`,
|
|
914
|
+
* or `undefined` if a provider-specific class was set outside Encore).
|
|
946
915
|
*/
|
|
947
916
|
storageClass?: StorageClass | 'auto';
|
|
948
|
-
/**
|
|
917
|
+
/** Per-object retain-until timestamp, if set. */
|
|
949
918
|
retainUntil?: Date;
|
|
950
919
|
}
|
|
951
920
|
|
|
952
921
|
/**
|
|
953
|
-
* A single entry
|
|
922
|
+
* A single entry yielded by {@link Bucket.list}.
|
|
954
923
|
*/
|
|
955
924
|
export interface ListEntry {
|
|
956
|
-
/**
|
|
925
|
+
/** Object key, or common prefix ending with the delimiter. */
|
|
957
926
|
name: string;
|
|
958
927
|
size: number;
|
|
959
928
|
etag: string;
|
|
960
|
-
/**
|
|
929
|
+
/** Timestamp when the object was written (unset for common prefixes). */
|
|
961
930
|
lastModified?: Date;
|
|
962
931
|
/**
|
|
963
|
-
*
|
|
964
|
-
*
|
|
932
|
+
* `true` when this entry represents a common prefix grouped by a delimiter
|
|
933
|
+
* (with `size: 0` and empty `etag`), rather than an object.
|
|
965
934
|
*/
|
|
966
935
|
isPrefix: boolean;
|
|
967
936
|
}
|
|
968
937
|
|
|
969
938
|
/**
|
|
970
|
-
*
|
|
939
|
+
* A single stored object version yielded by {@link Bucket.listVersions}.
|
|
971
940
|
*/
|
|
972
941
|
export interface ObjectVersion {
|
|
973
942
|
name: string;
|
|
974
943
|
version?: string;
|
|
975
944
|
size: number;
|
|
976
945
|
etag: string;
|
|
977
|
-
/** Whether this is the object's current version. */
|
|
946
|
+
/** Whether this is the object's current (latest) version. */
|
|
978
947
|
latest: boolean;
|
|
979
948
|
lastModified?: Date;
|
|
980
949
|
}
|
|
@@ -985,25 +954,25 @@ export interface ObjectVersion {
|
|
|
985
954
|
export interface UploadOptions {
|
|
986
955
|
contentType?: string;
|
|
987
956
|
|
|
988
|
-
/**
|
|
957
|
+
/** `Cache-Control` header returned when downloading the object. */
|
|
989
958
|
cacheControl?: string;
|
|
990
959
|
|
|
991
|
-
/**
|
|
960
|
+
/** `Content-Disposition` header returned when downloading the object. */
|
|
992
961
|
contentDisposition?: string;
|
|
993
962
|
|
|
994
963
|
/**
|
|
995
|
-
* Custom metadata. Keys match `[a-z0-9][a-z0-9_-]*` and
|
|
996
|
-
* printable ASCII.
|
|
964
|
+
* Custom key-value metadata. Keys must match `[a-z0-9][a-z0-9_-]*` and
|
|
965
|
+
* values must be printable ASCII. Total size is limited to 8 KiB on GCS and
|
|
997
966
|
* 2 KiB on S3.
|
|
998
967
|
*/
|
|
999
968
|
metadata?: Record<string, string>;
|
|
1000
969
|
|
|
1001
|
-
/**
|
|
970
|
+
/** Object storage class. Defaults to the bucket's configured storage class. */
|
|
1002
971
|
storageClass?: StorageClass;
|
|
1003
972
|
|
|
1004
973
|
/**
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
974
|
+
* Prevents the object from being deleted or overwritten until this time.
|
|
975
|
+
* Requires `objectRetention: true` on the bucket.
|
|
1007
976
|
*/
|
|
1008
977
|
retainUntil?: Date;
|
|
1009
978
|
|
|
@@ -1011,15 +980,16 @@ export interface UploadOptions {
|
|
|
1011
980
|
}
|
|
1012
981
|
|
|
1013
982
|
/**
|
|
1014
|
-
* Options for
|
|
983
|
+
* Options for {@link Bucket.uploadIfMatch} (all {@link UploadOptions} except
|
|
984
|
+
* `preconditions`).
|
|
1015
985
|
*/
|
|
1016
986
|
export type UploadIfMatchOptions = Omit<UploadOptions, 'preconditions'>;
|
|
1017
987
|
|
|
1018
988
|
/**
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
* `application/octet-stream
|
|
1022
|
-
* clears it.
|
|
989
|
+
* Attributes to update via {@link Bucket.updateAttrs}. Omitted fields remain
|
|
990
|
+
* unchanged; an empty string clears a field (clearing `contentType` resets it
|
|
991
|
+
* to `application/octet-stream`). `metadata` replaces the entire map (`{}`
|
|
992
|
+
* clears it).
|
|
1023
993
|
*/
|
|
1024
994
|
export interface UpdateAttrs {
|
|
1025
995
|
contentType?: string;
|
|
@@ -1032,13 +1002,13 @@ export interface UpdateAttrs {
|
|
|
1032
1002
|
* Options for updating an object's attributes.
|
|
1033
1003
|
*/
|
|
1034
1004
|
export interface UpdateAttrsOptions {
|
|
1035
|
-
/**
|
|
1005
|
+
/** Object version to update. Defaults to the latest version. */
|
|
1036
1006
|
version?: string;
|
|
1037
1007
|
|
|
1038
1008
|
preconditions?: {
|
|
1039
1009
|
/**
|
|
1040
|
-
* Only update the object if it
|
|
1041
|
-
*
|
|
1010
|
+
* Only update the object if it still matches this revision; throws
|
|
1011
|
+
* `PreconditionFailed` otherwise.
|
|
1042
1012
|
*/
|
|
1043
1013
|
ifMatch?: Revision;
|
|
1044
1014
|
};
|
|
@@ -1048,7 +1018,7 @@ export interface UpdateAttrsOptions {
|
|
|
1048
1018
|
* Options for extending an object's retention.
|
|
1049
1019
|
*/
|
|
1050
1020
|
export interface ExtendRetentionOptions {
|
|
1051
|
-
/**
|
|
1021
|
+
/** Object version to retain. Defaults to the latest version. */
|
|
1052
1022
|
version?: string;
|
|
1053
1023
|
}
|
|
1054
1024
|
|
|
@@ -1056,9 +1026,9 @@ export interface ExtendRetentionOptions {
|
|
|
1056
1026
|
* Options for generating a signed upload URL.
|
|
1057
1027
|
*/
|
|
1058
1028
|
export interface UploadUrlOptions {
|
|
1059
|
-
/**
|
|
1060
|
-
*
|
|
1061
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
|
|
1031
|
+
*/
|
|
1062
1032
|
ttl?: number;
|
|
1063
1033
|
}
|
|
1064
1034
|
|
|
@@ -1073,9 +1043,9 @@ export interface SignedUploadUrl {
|
|
|
1073
1043
|
* Options for generating a signed download URL.
|
|
1074
1044
|
*/
|
|
1075
1045
|
export interface DownloadUrlOptions {
|
|
1076
|
-
/**
|
|
1077
|
-
*
|
|
1078
|
-
|
|
1046
|
+
/**
|
|
1047
|
+
* URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
|
|
1048
|
+
*/
|
|
1079
1049
|
ttl?: number;
|
|
1080
1050
|
}
|
|
1081
1051
|
|