@encore.dev/sdk 2.0.0-beta.14 → 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 +144 -90
- package/app_meta.ts +56 -54
- package/config/config.test.ts +47 -13
- package/config/config.ts +60 -57
- package/config/secrets.ts +47 -50
- package/config/value.ts +23 -26
- package/cron/mod.test.ts +12 -0
- package/cron/mod.ts +37 -22
- 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 -50
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +11 -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 +34 -20
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -13
- 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/otel/http.d.ts +4 -2
- package/dist/internal/otel/http.d.ts.map +1 -1
- package/dist/internal/otel/http.js +32 -5
- package/dist/internal/otel/http.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +6 -5
- package/dist/internal/runtime/napi/napi.d.cts +58 -16
- 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/redaction/mod.d.ts +62 -0
- package/dist/redaction/mod.d.ts.map +1 -0
- package/dist/redaction/mod.js +102 -0
- package/dist/redaction/mod.js.map +1 -0
- 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 +230 -203
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +146 -106
- 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/objects/mod.d.ts +1 -1
- package/dist/storage/objects/mod.d.ts.map +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +2 -5
- package/dist/storage/objects/refs.d.ts.map +1 -1
- package/dist/storage/objects/refs.js.map +1 -1
- 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/tracing/http.d.ts +2 -1
- package/dist/tracing/http.d.ts.map +1 -1
- package/dist/tracing/http.js +2 -1
- package/dist/tracing/http.js.map +1 -1
- package/dist/tracing/node.d.ts.map +1 -1
- package/dist/tracing/node.js +1 -1
- package/dist/tracing/node.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/otel/http.test.ts +50 -0
- package/internal/otel/http.ts +40 -5
- package/internal/runtime/napi/napi.cjs +6 -5
- package/internal/runtime/napi/napi.d.cts +58 -16
- 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 +6 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/redaction/bridge.test.ts +99 -0
- package/redaction/mod.test.ts +188 -0
- package/redaction/mod.ts +226 -0
- 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.test.ts +168 -16
- package/storage/objects/bucket.ts +336 -247
- package/storage/objects/error.ts +4 -4
- package/storage/objects/mod.ts +1 -0
- package/storage/objects/refs.ts +2 -5
- 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
- package/tracing/http.ts +2 -1
- package/tracing/native.test.ts +158 -8
- package/tracing/node.ts +1 -0
|
@@ -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();
|
|
@@ -214,7 +210,13 @@ export class Bucket
|
|
|
214
210
|
if (entry === null) {
|
|
215
211
|
break;
|
|
216
212
|
}
|
|
217
|
-
yield
|
|
213
|
+
yield {
|
|
214
|
+
name: entry.name,
|
|
215
|
+
size: entry.size,
|
|
216
|
+
etag: entry.etag,
|
|
217
|
+
lastModified: toDate(entry.lastModified),
|
|
218
|
+
isPrefix: entry.isPrefix,
|
|
219
|
+
};
|
|
218
220
|
}
|
|
219
221
|
} finally {
|
|
220
222
|
iter.markDone();
|
|
@@ -222,9 +224,9 @@ export class Bucket
|
|
|
222
224
|
}
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
|
-
* Lists
|
|
226
|
-
*
|
|
227
|
-
*
|
|
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.
|
|
228
230
|
*/
|
|
229
231
|
async *listVersions(
|
|
230
232
|
options?: ListVersionsOptions,
|
|
@@ -269,7 +271,7 @@ export class Bucket
|
|
|
269
271
|
|
|
270
272
|
/**
|
|
271
273
|
* Returns the object's attributes.
|
|
272
|
-
* Throws
|
|
274
|
+
* Throws `ObjectNotFound` if the object does not exist.
|
|
273
275
|
*/
|
|
274
276
|
async attrs(name: string, options?: AttrsOptions): Promise<ObjectAttrs> {
|
|
275
277
|
const source = activeCtxBytes();
|
|
@@ -294,10 +296,9 @@ export class Bucket
|
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
/**
|
|
297
|
-
* Uploads an object
|
|
298
|
-
* `
|
|
299
|
-
*
|
|
300
|
-
* 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.
|
|
301
302
|
*
|
|
302
303
|
* If the stream errors, the upload is aborted and nothing is stored.
|
|
303
304
|
*/
|
|
@@ -314,21 +315,19 @@ export class Bucket
|
|
|
314
315
|
}
|
|
315
316
|
|
|
316
317
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* A missing revision throws `InvalidArgument`.
|
|
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.
|
|
322
322
|
*
|
|
323
|
-
* `data`
|
|
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`.
|
|
324
328
|
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
* revision's `version`, so a revision without one throws
|
|
328
|
-
* `InvalidArgument` there; Amazon S3 and Cloudflare R2 match its `etag`.
|
|
329
|
-
*
|
|
330
|
-
* On Amazon S3 a conditional write also needs read access to the bucket,
|
|
331
|
-
* which Encore grants to the services that call this.
|
|
329
|
+
* On AWS S3, conditional writes also require read permission, which Encore
|
|
330
|
+
* grants automatically to calling services.
|
|
332
331
|
*/
|
|
333
332
|
async uploadIfMatch(
|
|
334
333
|
name: string,
|
|
@@ -346,13 +345,13 @@ export class Bucket
|
|
|
346
345
|
}
|
|
347
346
|
|
|
348
347
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* `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).
|
|
353
352
|
*
|
|
354
|
-
* On S3
|
|
355
|
-
*
|
|
353
|
+
* On AWS S3, updating attributes rewrites the object, creating a new version
|
|
354
|
+
* in versioned buckets and resetting the object's lifecycle age.
|
|
356
355
|
*/
|
|
357
356
|
async updateAttrs(
|
|
358
357
|
name: string,
|
|
@@ -378,9 +377,9 @@ export class Bucket
|
|
|
378
377
|
}
|
|
379
378
|
|
|
380
379
|
/**
|
|
381
|
-
*
|
|
382
|
-
* extended
|
|
383
|
-
* `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.
|
|
384
383
|
*/
|
|
385
384
|
async extendRetention(
|
|
386
385
|
name: string,
|
|
@@ -398,13 +397,11 @@ export class Bucket
|
|
|
398
397
|
}
|
|
399
398
|
|
|
400
399
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* Anyone with possession of the URL can write to the given object name
|
|
404
|
-
* without any additional auth.
|
|
400
|
+
* Generates a pre-signed URL allowing anyone with the URL to upload to
|
|
401
|
+
* `name` without additional authentication.
|
|
405
402
|
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
403
|
+
* Note: Pre-signed upload URLs do not enforce the bucket's configured
|
|
404
|
+
* `storageClass`; uploaded objects receive the provider's default class.
|
|
408
405
|
*/
|
|
409
406
|
async signedUploadUrl(
|
|
410
407
|
name: string,
|
|
@@ -417,10 +414,8 @@ export class Bucket
|
|
|
417
414
|
}
|
|
418
415
|
|
|
419
416
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* Anyone with possession of the URL can download the given object without
|
|
423
|
-
* any additional auth.
|
|
417
|
+
* Generates a pre-signed URL allowing anyone with the URL to download `name`
|
|
418
|
+
* without additional authentication.
|
|
424
419
|
*/
|
|
425
420
|
async signedDownloadUrl(
|
|
426
421
|
name: string,
|
|
@@ -433,48 +428,23 @@ export class Bucket
|
|
|
433
428
|
}
|
|
434
429
|
|
|
435
430
|
/**
|
|
436
|
-
*
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const impl = this.impl.object(name);
|
|
441
|
-
const res = await impl.downloadAll(downloadOptions(options), source);
|
|
442
|
-
return unwrapErr(res);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Downloads an object from the bucket as a Web `ReadableStream`, read
|
|
447
|
-
* from the provider as the consumer reads it. A missing object throws
|
|
448
|
-
* here, before any bytes. Cancelling the stream stops the download.
|
|
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.
|
|
449
435
|
*
|
|
450
|
-
*
|
|
436
|
+
* ```ts
|
|
437
|
+
* const d = await uploads.download("state.json");
|
|
438
|
+
* const state = JSON.parse((await d.bytes()).toString());
|
|
439
|
+
* // Write only if nobody else updated the object since we read it.
|
|
440
|
+
* await uploads.uploadIfMatch("state.json", next(state), d.revision);
|
|
441
|
+
* ```
|
|
451
442
|
*/
|
|
452
|
-
async
|
|
453
|
-
name: string,
|
|
454
|
-
options?: DownloadOptions,
|
|
455
|
-
): Promise<ReadableStream<Uint8Array>> {
|
|
443
|
+
async download(name: string, options?: DownloadOptions): Promise<Download> {
|
|
456
444
|
const source = activeCtxBytes();
|
|
457
445
|
const impl = this.impl.object(name);
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
);
|
|
461
|
-
return new ReadableStream<Uint8Array>(
|
|
462
|
-
{
|
|
463
|
-
async pull(controller) {
|
|
464
|
-
const chunk = unwrapErr(await stream.next());
|
|
465
|
-
if (chunk === null) {
|
|
466
|
-
controller.close();
|
|
467
|
-
} else {
|
|
468
|
-
controller.enqueue(chunk);
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
async cancel() {
|
|
472
|
-
await stream.close();
|
|
473
|
-
},
|
|
474
|
-
},
|
|
475
|
-
// Read ahead of the consumer by nothing.
|
|
476
|
-
{highWaterMark: 0},
|
|
477
|
-
);
|
|
446
|
+
const res = await impl.download(downloadOptions(options), source);
|
|
447
|
+
return new NativeDownload(unwrapErr(res));
|
|
478
448
|
}
|
|
479
449
|
|
|
480
450
|
/**
|
|
@@ -491,18 +461,15 @@ export class Bucket
|
|
|
491
461
|
}
|
|
492
462
|
|
|
493
463
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
* remove. A missing revision throws `InvalidArgument`.
|
|
499
|
-
*
|
|
500
|
-
* The match compares the object's contents, not its attributes:
|
|
501
|
-
* `updateAttrs` doesn't break it.
|
|
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.
|
|
502
468
|
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
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
|
|
506
473
|
* `InvalidArgument`.
|
|
507
474
|
*/
|
|
508
475
|
async removeIfMatch(name: string, revision: Revision): Promise<void> {
|
|
@@ -516,8 +483,8 @@ export class Bucket
|
|
|
516
483
|
}
|
|
517
484
|
|
|
518
485
|
/**
|
|
519
|
-
* Returns the public URL for accessing the object
|
|
520
|
-
* 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`.
|
|
521
488
|
*/
|
|
522
489
|
publicUrl(name: string): string {
|
|
523
490
|
const obj = this.impl.object(name);
|
|
@@ -529,13 +496,13 @@ export class Bucket
|
|
|
529
496
|
}
|
|
530
497
|
}
|
|
531
498
|
|
|
532
|
-
/**
|
|
499
|
+
/** Maximum chunk size passed to the native upload writer at a time. */
|
|
533
500
|
const CHUNK_SIZE = 64 * 1024;
|
|
534
501
|
|
|
535
502
|
const STREAM_EXPECTED =
|
|
536
|
-
'uploadStream
|
|
503
|
+
'uploadStream expects a ReadableStream or an async iterable of Uint8Array chunks';
|
|
537
504
|
const BODY_EXPECTED =
|
|
538
|
-
'uploadIfMatch
|
|
505
|
+
'uploadIfMatch expects a Uint8Array, ReadableStream, or async iterable of Uint8Array chunks';
|
|
539
506
|
|
|
540
507
|
async function uploadChunks(
|
|
541
508
|
obj: runtime.BucketObject,
|
|
@@ -547,7 +514,7 @@ async function uploadChunks(
|
|
|
547
514
|
try {
|
|
548
515
|
for await (const chunk of data) {
|
|
549
516
|
if (!(chunk instanceof Uint8Array)) {
|
|
550
|
-
throw new TypeError('upload data must
|
|
517
|
+
throw new TypeError('upload data must consist of Uint8Array chunks');
|
|
551
518
|
}
|
|
552
519
|
for (const slice of slices(chunk)) {
|
|
553
520
|
const err = await stream.write(slice);
|
|
@@ -564,7 +531,7 @@ async function uploadChunks(
|
|
|
564
531
|
return toAttrs(unwrapErr(await stream.finish()));
|
|
565
532
|
}
|
|
566
533
|
|
|
567
|
-
/**
|
|
534
|
+
/** Yields `Buffer` views of `data`, each at most `CHUNK_SIZE` bytes. */
|
|
568
535
|
function* slices(data: Uint8Array): Generator<Buffer> {
|
|
569
536
|
const buf = Buffer.isBuffer(data)
|
|
570
537
|
? data
|
|
@@ -632,7 +599,84 @@ function uploadOptions(
|
|
|
632
599
|
function downloadOptions(
|
|
633
600
|
options: DownloadOptions | undefined,
|
|
634
601
|
): runtime.DownloadOptions | undefined {
|
|
635
|
-
return options && {version: options.version, range: options.range};
|
|
602
|
+
return options && {version: options.version, range: byteRange(options.range)};
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function byteRange(
|
|
606
|
+
range: ByteRange | undefined,
|
|
607
|
+
): runtime.ByteRange | undefined {
|
|
608
|
+
if (range === undefined) {
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
// What the types forbid, plain JavaScript can pass.
|
|
612
|
+
if (range.last !== undefined) {
|
|
613
|
+
if (range.offset !== undefined || range.length !== undefined) {
|
|
614
|
+
throw new InvalidArgument(
|
|
615
|
+
'byte range must specify either `offset` (with optional `length`) or `last`, not both',
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
return {last: range.last};
|
|
619
|
+
}
|
|
620
|
+
if (typeof range.offset !== 'number') {
|
|
621
|
+
throw new InvalidArgument(
|
|
622
|
+
'byte range must specify either a numeric `offset` or `last`',
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
return {offset: range.offset, length: range.length};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** Wraps a native runtime download handle. */
|
|
629
|
+
class NativeDownload implements Download {
|
|
630
|
+
readonly revision: Revision;
|
|
631
|
+
readonly size: number;
|
|
632
|
+
readonly contentType?: string;
|
|
633
|
+
readonly lastModified?: Date;
|
|
634
|
+
private read = false;
|
|
635
|
+
|
|
636
|
+
constructor(private readonly impl: runtime.Download) {
|
|
637
|
+
const info = impl.info;
|
|
638
|
+
this.revision = {etag: info.etag, version: info.version};
|
|
639
|
+
this.size = info.size;
|
|
640
|
+
this.contentType = info.contentType;
|
|
641
|
+
this.lastModified = toDate(info.lastModified);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async bytes(): Promise<Buffer> {
|
|
645
|
+
this.take('bytes');
|
|
646
|
+
return unwrapErr(await this.impl.bytes());
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
stream(): ReadableStream<Uint8Array> {
|
|
650
|
+
this.take('stream');
|
|
651
|
+
const impl = this.impl;
|
|
652
|
+
return new ReadableStream<Uint8Array>(
|
|
653
|
+
{
|
|
654
|
+
async pull(controller) {
|
|
655
|
+
const chunk = unwrapErr(await impl.next());
|
|
656
|
+
if (chunk === null) {
|
|
657
|
+
controller.close();
|
|
658
|
+
} else {
|
|
659
|
+
controller.enqueue(chunk);
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
async cancel() {
|
|
663
|
+
await impl.close();
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
// Read ahead of the consumer by nothing.
|
|
667
|
+
{highWaterMark: 0},
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** Enforces single consumption of the download body. */
|
|
672
|
+
private take(method: string): void {
|
|
673
|
+
if (this.read) {
|
|
674
|
+
throw new InvalidArgument(
|
|
675
|
+
`${method}: download body has already been consumed`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
this.read = true;
|
|
679
|
+
}
|
|
636
680
|
}
|
|
637
681
|
|
|
638
682
|
function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
|
|
@@ -640,14 +684,13 @@ function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
|
|
|
640
684
|
}
|
|
641
685
|
|
|
642
686
|
/**
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
* otherwise be unconditional.
|
|
687
|
+
* Validates that `*IfMatch` callers supplied a revision so writes or deletes
|
|
688
|
+
* cannot silently become unconditional in untyped JS.
|
|
646
689
|
*/
|
|
647
690
|
function requiredRevision(method: string, rev: Revision): runtime.Revision {
|
|
648
691
|
if (rev == null || typeof rev.etag !== 'string') {
|
|
649
692
|
throw new InvalidArgument(
|
|
650
|
-
`${method}
|
|
693
|
+
`${method} requires a revision (e.g. from download.revision, attrs(), upload(), or updateAttrs())`,
|
|
651
694
|
);
|
|
652
695
|
}
|
|
653
696
|
return {etag: rev.etag, version: rev.version};
|
|
@@ -678,20 +721,20 @@ function toAttrs(attrs: runtime.ObjectAttrs): ObjectAttrs {
|
|
|
678
721
|
*/
|
|
679
722
|
export interface ListOptions {
|
|
680
723
|
/**
|
|
681
|
-
* Only include objects with this prefix
|
|
682
|
-
*
|
|
724
|
+
* Only include objects whose names start with this prefix.
|
|
725
|
+
* Defaults to all objects.
|
|
683
726
|
*/
|
|
684
727
|
prefix?: string;
|
|
685
728
|
|
|
686
729
|
/**
|
|
687
|
-
* Maximum number of entries to return
|
|
688
|
-
*
|
|
730
|
+
* Maximum number of entries to return (including common prefixes).
|
|
731
|
+
* Unlimited when unset.
|
|
689
732
|
*/
|
|
690
733
|
limit?: number;
|
|
691
734
|
|
|
692
735
|
/**
|
|
693
|
-
*
|
|
694
|
-
*
|
|
736
|
+
* Delimiter (typically `"/"`) used to group object names past `prefix` into
|
|
737
|
+
* single common-prefix entries.
|
|
695
738
|
*/
|
|
696
739
|
delimiter?: string;
|
|
697
740
|
}
|
|
@@ -701,37 +744,33 @@ export interface ListOptions {
|
|
|
701
744
|
*/
|
|
702
745
|
export interface ListVersionsOptions {
|
|
703
746
|
/**
|
|
704
|
-
* Only include objects with this prefix
|
|
705
|
-
*
|
|
747
|
+
* Only include objects whose names start with this prefix.
|
|
748
|
+
* Defaults to all objects.
|
|
706
749
|
*/
|
|
707
750
|
prefix?: string;
|
|
708
751
|
|
|
709
|
-
/** Maximum number of versions to return.
|
|
752
|
+
/** Maximum number of versions to return. Unlimited when unset. */
|
|
710
753
|
limit?: number;
|
|
711
754
|
}
|
|
712
755
|
|
|
713
756
|
/**
|
|
714
|
-
* Options for retrieving
|
|
757
|
+
* Options for retrieving an object's attributes.
|
|
715
758
|
*/
|
|
716
759
|
export interface AttrsOptions {
|
|
717
760
|
/**
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
* 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.
|
|
722
763
|
*/
|
|
723
764
|
version?: string;
|
|
724
765
|
}
|
|
725
766
|
|
|
726
767
|
/**
|
|
727
|
-
* Options for checking
|
|
768
|
+
* Options for checking whether an object exists.
|
|
728
769
|
*/
|
|
729
770
|
export interface ExistsOptions {
|
|
730
771
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
* 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.
|
|
735
774
|
*/
|
|
736
775
|
version?: string;
|
|
737
776
|
}
|
|
@@ -741,54 +780,102 @@ export interface ExistsOptions {
|
|
|
741
780
|
*/
|
|
742
781
|
export interface DeleteOptions {
|
|
743
782
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
* 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.
|
|
748
785
|
*/
|
|
749
786
|
version?: string;
|
|
750
787
|
}
|
|
751
788
|
|
|
752
789
|
/**
|
|
753
|
-
* A contiguous byte range within an object
|
|
790
|
+
* A contiguous byte range within an object: either `length` bytes starting at
|
|
791
|
+
* `offset`, or the final `last` bytes of the object.
|
|
754
792
|
*/
|
|
755
|
-
export
|
|
756
|
-
|
|
757
|
-
|
|
793
|
+
export type ByteRange =
|
|
794
|
+
| {
|
|
795
|
+
/** Zero-based index of the first byte to read. */
|
|
796
|
+
offset: number;
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Number of bytes to read. Reads through the end of the object when
|
|
800
|
+
* omitted.
|
|
801
|
+
*/
|
|
802
|
+
length?: number;
|
|
803
|
+
|
|
804
|
+
last?: never;
|
|
805
|
+
}
|
|
806
|
+
| {
|
|
807
|
+
/**
|
|
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.
|
|
810
|
+
*/
|
|
811
|
+
last: number;
|
|
758
812
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
*/
|
|
763
|
-
length?: number;
|
|
764
|
-
}
|
|
813
|
+
offset?: never;
|
|
814
|
+
length?: never;
|
|
815
|
+
};
|
|
765
816
|
|
|
766
817
|
/**
|
|
767
818
|
* Options for downloading an object from a bucket.
|
|
768
819
|
*/
|
|
769
820
|
export interface DownloadOptions {
|
|
770
821
|
/**
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
* 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.
|
|
775
824
|
*/
|
|
776
825
|
version?: string;
|
|
777
826
|
|
|
778
827
|
/**
|
|
779
|
-
*
|
|
780
|
-
*
|
|
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.
|
|
781
831
|
*
|
|
782
|
-
* Throws InvalidArgument if the range is empty or
|
|
783
|
-
*
|
|
832
|
+
* Throws `InvalidArgument` if the range is empty or starts past the end of
|
|
833
|
+
* the object.
|
|
784
834
|
*/
|
|
785
835
|
range?: ByteRange;
|
|
786
836
|
}
|
|
787
837
|
|
|
788
838
|
/**
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
839
|
+
* An in-progress download returned by {@link Bucket.download}, exposing basic
|
|
840
|
+
* response metadata and one-shot body readers (`bytes()` or `stream()`).
|
|
841
|
+
*
|
|
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.
|
|
846
|
+
*/
|
|
847
|
+
export interface Download {
|
|
848
|
+
/**
|
|
849
|
+
* Revision of the downloaded contents. Pass to {@link Bucket.uploadIfMatch}
|
|
850
|
+
* or {@link Bucket.removeIfMatch} for optimistic concurrency control.
|
|
851
|
+
*/
|
|
852
|
+
readonly revision: Revision;
|
|
853
|
+
/** Full object size in bytes, even when downloading a byte range. */
|
|
854
|
+
readonly size: number;
|
|
855
|
+
readonly contentType?: string;
|
|
856
|
+
/** Last modification timestamp, if reported by the provider. */
|
|
857
|
+
readonly lastModified?: Date;
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Buffers and returns the entire download body. Throws `InvalidArgument` if
|
|
861
|
+
* the body has already been consumed.
|
|
862
|
+
*/
|
|
863
|
+
bytes(): Promise<Buffer>;
|
|
864
|
+
|
|
865
|
+
/**
|
|
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.
|
|
869
|
+
*
|
|
870
|
+
* In Node.js, use `Readable.fromWeb` to convert this into a Node stream.
|
|
871
|
+
*/
|
|
872
|
+
stream(): ReadableStream<Uint8Array>;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
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`.
|
|
792
879
|
*/
|
|
793
880
|
export interface Revision {
|
|
794
881
|
etag: string;
|
|
@@ -796,66 +883,67 @@ export interface Revision {
|
|
|
796
883
|
}
|
|
797
884
|
|
|
798
885
|
/**
|
|
799
|
-
*
|
|
886
|
+
* Preconditions for an upload.
|
|
800
887
|
*/
|
|
801
888
|
export interface Preconditions {
|
|
802
889
|
/**
|
|
803
|
-
* Only write the object if it does not exist
|
|
804
|
-
*
|
|
890
|
+
* Only write the object if it does not already exist; throws
|
|
891
|
+
* `PreconditionFailed` otherwise.
|
|
805
892
|
*/
|
|
806
893
|
notExists?: boolean;
|
|
807
894
|
}
|
|
808
895
|
|
|
809
896
|
/**
|
|
810
|
-
*
|
|
897
|
+
* Attributes of an object stored in a bucket.
|
|
811
898
|
*/
|
|
812
899
|
export interface ObjectAttrs {
|
|
813
900
|
name: string;
|
|
814
901
|
size: number;
|
|
815
|
-
/**
|
|
902
|
+
/** Object version identifier, if bucket versioning is enabled. */
|
|
816
903
|
version?: string;
|
|
817
904
|
etag: string;
|
|
818
905
|
contentType?: string;
|
|
819
906
|
cacheControl?: string;
|
|
820
907
|
contentDisposition?: string;
|
|
821
|
-
/** Custom metadata
|
|
908
|
+
/** Custom metadata map (empty object if none). */
|
|
822
909
|
metadata: Record<string, string>;
|
|
823
|
-
/**
|
|
910
|
+
/** Timestamp when this object version was written. */
|
|
824
911
|
lastModified?: Date;
|
|
825
912
|
/**
|
|
826
|
-
*
|
|
827
|
-
* `
|
|
828
|
-
* 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).
|
|
829
915
|
*/
|
|
830
916
|
storageClass?: StorageClass | 'auto';
|
|
831
|
-
/**
|
|
917
|
+
/** Per-object retain-until timestamp, if set. */
|
|
832
918
|
retainUntil?: Date;
|
|
833
919
|
}
|
|
834
920
|
|
|
835
921
|
/**
|
|
836
|
-
* A single entry
|
|
922
|
+
* A single entry yielded by {@link Bucket.list}.
|
|
837
923
|
*/
|
|
838
924
|
export interface ListEntry {
|
|
839
|
-
/**
|
|
925
|
+
/** Object key, or common prefix ending with the delimiter. */
|
|
840
926
|
name: string;
|
|
841
927
|
size: number;
|
|
842
928
|
etag: string;
|
|
929
|
+
/** Timestamp when the object was written (unset for common prefixes). */
|
|
930
|
+
lastModified?: Date;
|
|
843
931
|
/**
|
|
844
|
-
*
|
|
845
|
-
*
|
|
932
|
+
* `true` when this entry represents a common prefix grouped by a delimiter
|
|
933
|
+
* (with `size: 0` and empty `etag`), rather than an object.
|
|
846
934
|
*/
|
|
847
935
|
isPrefix: boolean;
|
|
848
936
|
}
|
|
849
937
|
|
|
850
938
|
/**
|
|
851
|
-
*
|
|
939
|
+
* A single stored object version yielded by {@link Bucket.listVersions}.
|
|
852
940
|
*/
|
|
853
941
|
export interface ObjectVersion {
|
|
854
942
|
name: string;
|
|
855
943
|
version?: string;
|
|
856
944
|
size: number;
|
|
857
945
|
etag: string;
|
|
858
|
-
/** Whether this is the object's current version. */
|
|
946
|
+
/** Whether this is the object's current (latest) version. */
|
|
859
947
|
latest: boolean;
|
|
860
948
|
lastModified?: Date;
|
|
861
949
|
}
|
|
@@ -866,25 +954,25 @@ export interface ObjectVersion {
|
|
|
866
954
|
export interface UploadOptions {
|
|
867
955
|
contentType?: string;
|
|
868
956
|
|
|
869
|
-
/**
|
|
957
|
+
/** `Cache-Control` header returned when downloading the object. */
|
|
870
958
|
cacheControl?: string;
|
|
871
959
|
|
|
872
|
-
/**
|
|
960
|
+
/** `Content-Disposition` header returned when downloading the object. */
|
|
873
961
|
contentDisposition?: string;
|
|
874
962
|
|
|
875
963
|
/**
|
|
876
|
-
* Custom metadata. Keys match `[a-z0-9][a-z0-9_-]*` and
|
|
877
|
-
* 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
|
|
878
966
|
* 2 KiB on S3.
|
|
879
967
|
*/
|
|
880
968
|
metadata?: Record<string, string>;
|
|
881
969
|
|
|
882
|
-
/**
|
|
970
|
+
/** Object storage class. Defaults to the bucket's configured storage class. */
|
|
883
971
|
storageClass?: StorageClass;
|
|
884
972
|
|
|
885
973
|
/**
|
|
886
|
-
*
|
|
887
|
-
*
|
|
974
|
+
* Prevents the object from being deleted or overwritten until this time.
|
|
975
|
+
* Requires `objectRetention: true` on the bucket.
|
|
888
976
|
*/
|
|
889
977
|
retainUntil?: Date;
|
|
890
978
|
|
|
@@ -892,15 +980,16 @@ export interface UploadOptions {
|
|
|
892
980
|
}
|
|
893
981
|
|
|
894
982
|
/**
|
|
895
|
-
* Options for
|
|
983
|
+
* Options for {@link Bucket.uploadIfMatch} (all {@link UploadOptions} except
|
|
984
|
+
* `preconditions`).
|
|
896
985
|
*/
|
|
897
986
|
export type UploadIfMatchOptions = Omit<UploadOptions, 'preconditions'>;
|
|
898
987
|
|
|
899
988
|
/**
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
* `application/octet-stream
|
|
903
|
-
* 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).
|
|
904
993
|
*/
|
|
905
994
|
export interface UpdateAttrs {
|
|
906
995
|
contentType?: string;
|
|
@@ -913,13 +1002,13 @@ export interface UpdateAttrs {
|
|
|
913
1002
|
* Options for updating an object's attributes.
|
|
914
1003
|
*/
|
|
915
1004
|
export interface UpdateAttrsOptions {
|
|
916
|
-
/**
|
|
1005
|
+
/** Object version to update. Defaults to the latest version. */
|
|
917
1006
|
version?: string;
|
|
918
1007
|
|
|
919
1008
|
preconditions?: {
|
|
920
1009
|
/**
|
|
921
|
-
* Only update the object if it
|
|
922
|
-
*
|
|
1010
|
+
* Only update the object if it still matches this revision; throws
|
|
1011
|
+
* `PreconditionFailed` otherwise.
|
|
923
1012
|
*/
|
|
924
1013
|
ifMatch?: Revision;
|
|
925
1014
|
};
|
|
@@ -929,7 +1018,7 @@ export interface UpdateAttrsOptions {
|
|
|
929
1018
|
* Options for extending an object's retention.
|
|
930
1019
|
*/
|
|
931
1020
|
export interface ExtendRetentionOptions {
|
|
932
|
-
/**
|
|
1021
|
+
/** Object version to retain. Defaults to the latest version. */
|
|
933
1022
|
version?: string;
|
|
934
1023
|
}
|
|
935
1024
|
|
|
@@ -937,9 +1026,9 @@ export interface ExtendRetentionOptions {
|
|
|
937
1026
|
* Options for generating a signed upload URL.
|
|
938
1027
|
*/
|
|
939
1028
|
export interface UploadUrlOptions {
|
|
940
|
-
/**
|
|
941
|
-
*
|
|
942
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
|
|
1031
|
+
*/
|
|
943
1032
|
ttl?: number;
|
|
944
1033
|
}
|
|
945
1034
|
|
|
@@ -954,9 +1043,9 @@ export interface SignedUploadUrl {
|
|
|
954
1043
|
* Options for generating a signed download URL.
|
|
955
1044
|
*/
|
|
956
1045
|
export interface DownloadUrlOptions {
|
|
957
|
-
/**
|
|
958
|
-
*
|
|
959
|
-
|
|
1046
|
+
/**
|
|
1047
|
+
* URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
|
|
1048
|
+
*/
|
|
960
1049
|
ttl?: number;
|
|
961
1050
|
}
|
|
962
1051
|
|