@cloudbitmaps/gcs 0.22.0 → 0.23.0

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 CHANGED
@@ -14,6 +14,8 @@ second service to run.
14
14
  pnpm add @cloudbitmaps/roaring @cloudbitmaps/gcs
15
15
  ```
16
16
 
17
+ Install the same version of every `@cloudbitmaps/*` package: they release together, and each pins the exact version of `core` it was built with.
18
+
17
19
  `roaring` needs its one install script to fetch its native binary, and newer clients run a dependency's script only if you allow it. Allow it before you install:
18
20
 
19
21
  - **npm 12:** add `{ "allowScripts": { "roaring": true } }` to your `package.json`. Without it the install exits 0 and the package throws at `import`. npm 11 runs the script but warns until you allow it the same way.
@@ -28,6 +30,7 @@ pnpm add @cloudbitmaps/roaring @cloudbitmaps/gcs
28
30
 
29
31
  ## Use
30
32
 
33
+ <!-- typecheck -->
31
34
  ```ts
32
35
  import { CloudRoaring } from '@cloudbitmaps/roaring';
33
36
  import { GcsStorage } from '@cloudbitmaps/gcs';
@@ -56,10 +59,18 @@ It builds its own client from Application Default Credentials. Any other key is
56
59
 
57
60
  - **This backend is outside the validated envelope.** It passes the same conformance suites as S3, but the proven
58
61
  scale and the calibration were done on S3. You are an early user.
62
+ - **Run `await store.preflight()` once before the first load.** It writes, tries to write again, reads, lists and deletes one probe
63
+ object, and reads the registry and the bucket's lifecycle rules (`storage.buckets.get` for the last), and answers
64
+ `{ ok, checks }`. It does not check a read after a delete or versioning, among others: [the full list](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/production.md#what-preflight-does-not-check). A first run is eight requests here.
59
65
  - **Grant the bucket's object permissions.** The library creates, reads, lists and deletes objects:
60
66
  `roles/storage.objectAdmin` covers all four.
61
67
  - **The write-once guarantee rides GCS preconditions** (`ifGenerationMatch`), so nothing else needs enabling.
62
68
  - **Never add a lifecycle rule that expires current objects or the `registry/` prefix.**
69
+ - **Check the bucket's lifecycle rules with `await backend.checkLifecycle()`.** It reads the bucket's metadata with one
70
+ request (bounded by `readTimeoutMs`, when set) and answers `problem` for a `Delete` rule that applies to live objects and can match your prefix, `ok`, or
71
+ `unchecked`. It needs `storage.buckets.get`, which a load never uses, `store.preflight()`'s lifecycle step does, and `roles/storage.objectAdmin` does
72
+ not include: without it the answer is `unchecked`, naming the permission
73
+ ([check the lifecycle rules from code](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/production.md#check-the-lifecycle-rules-from-code)).
63
74
  - **The SDK does not retry downloads; the driver does.** In `@google-cloud/storage` 7.x and 8.x (checked on 7.22.0 and
64
75
  8.1.0), a download the SDK retries after any status it retries (408, 429, 500, 502, 503 or 504) can crash the process
65
76
  with `ERR_STREAM_UNABLE_TO_PIPE`, thrown outside any promise, even though the retried request succeeded. The client
@@ -105,15 +116,17 @@ It builds its own client from Application Default Credentials. Any other key is
105
116
  global agent closes a connection idle for 5 seconds (the SDK's own pool does not), so a read after a longer pause
106
117
  opens a new connection, with its TCP and TLS handshake, and downloads share that agent with any other `http` or
107
118
  `https` request in the process. Raising `https.globalAgent.options.timeout` keeps idle connections longer.
108
- - **A transient failure of a write throws `TransientError`, and the write may or may not have landed.** Re-run the
109
- call, or check `store.generations(ref)`. The driver sends each registry write once; a load that gets no answer reads
110
- the row and sends a fresh compare-and-swap from it, at most three times. A generation's object of up to
111
- `simpleUploadThresholdBytes` is sent again, up to three more times, only after a `429` or `503`; every object carries
112
- a random id in its metadata, so a first send that landed is told from another writer's object. A load whose row writes
113
- all go unanswered throws `TransientError` and keeps its object. The waits before an object's re-sends use real
114
- timers: the store's injected clock does not reach them, and `GcsStorage` takes no clock, so a test that throttles
115
- one object write three times waits about 3.5 s at most (the publish's waits before a fresh row write do use the
116
- store's clock).
119
+ - **A transient failure of a write throws `TransientError`, and the write may or may not have landed.** Re-run the call,
120
+ or check `store.generations(ref)`. The driver [sends each registry write
121
+ once](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/correctness.md#sdk-retry); a load that gets no
122
+ answer [reads the row and sends a fresh compare-and-swap from
123
+ it](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/correctness.md#row-write-settled), at most three
124
+ times. A generation's object of up to `simpleUploadThresholdBytes` is sent again, up to three more times, only after a
125
+ `429` or `503`; every object carries a random id in its metadata, so a first send that landed is told from another
126
+ writer's object. A load whose row writes all go unanswered throws `TransientError` and keeps its object. The waits
127
+ before an object's re-sends use real timers: the store's injected clock does not reach them, and `GcsStorage` takes no
128
+ clock, so a test that throttles one object write three times waits about 3.5 s at most (the publish's waits before a
129
+ fresh row write do use the store's clock).
117
130
 
118
131
  The [production checklist](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/production.md) covers each item, and the ones every backend shares: backups of the data and the registry, and a schedule for your loads.
119
132
  - **The driver redacts the credentials it recognises from an error before it throws it.** The SDK keeps the response it
package/dist/backend.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { STORAGE_BACKEND } from '@cloudbitmaps/core/driver-kit';
2
- import type { IRegistryDriver, IStorageDriver, StorageBackend } from '@cloudbitmaps/core/driver-kit';
2
+ import type { IRegistryDriver, IStorageDriver, LifecycleVerdict, StorageBackend } from '@cloudbitmaps/core/driver-kit';
3
3
  import { Storage as GcsClient } from '@google-cloud/storage';
4
4
  /**
5
5
  * What {@link GcsStorage} takes: a `bucket`, and either a `client` or the two settings that build one (`projectId`,
@@ -8,7 +8,7 @@ import { Storage as GcsClient } from '@google-cloud/storage';
8
8
  export interface GcsStorageOptions {
9
9
  /** Target bucket (must already exist). */
10
10
  readonly bucket: string;
11
- /** Optional object-name prefix under which everything lives — generations and the registry alike. */
11
+ /** Optional object-name prefix under which everything lives — generations and the registry alike. A string, else `ValidationError`. */
12
12
  readonly prefix?: string;
13
13
  /**
14
14
  * A constructed `@google-cloud/storage` client. One is built from the ambient credentials when absent. Its retry
@@ -25,9 +25,15 @@ export interface GcsStorageOptions {
25
25
  * built, other than an interceptor, is not carried to the twin.
26
26
  */
27
27
  readonly client?: GcsClient;
28
- /** Project id for the client built when `client` is absent (refused beside `client`). Falls back to the SDK's own resolution. */
28
+ /**
29
+ * Project id for the client built when `client` is absent (refused beside `client`): a non-empty string, else
30
+ * `ValidationError`. Falls back to the SDK's own resolution.
31
+ */
29
32
  readonly projectId?: string;
30
- /** Endpoint override — point it at fake-gcs-server locally. Refused beside `client`, which carries its own. */
33
+ /**
34
+ * Endpoint override — point it at fake-gcs-server locally: a non-empty string, since an empty one would send
35
+ * requests to the public endpoint, else `ValidationError`. Refused beside `client`, which carries its own.
36
+ */
31
37
  readonly apiEndpoint?: string;
32
38
  /** Largest object the backend will write and advertise (default = GCS's 5 TiB max). Must be a positive safe integer. */
33
39
  readonly maxObjectBytes?: number;
@@ -88,5 +94,25 @@ export declare class GcsStorage implements StorageBackend {
88
94
  readonly registry: IRegistryDriver;
89
95
  /** The client both halves share — built here unless one was supplied. */
90
96
  readonly client: GcsClient;
97
+ private readonly bucket;
98
+ /** The name prefix every object sits under: `''`, or `trimmed/`. */
99
+ private readonly keyPrefix;
100
+ private readonly readTimeoutMs;
101
+ /**
102
+ * Builds the GCS backend over one bucket, which `bucket` names. Pass `client`, or `projectId` and `apiEndpoint` to
103
+ * have one built, not both. `prefix` puts every object under a name prefix. Throws `ValidationError` for an unknown
104
+ * option, no bucket, a `now` that is not a function, a client setting beside `client`, a `maxObjectBytes` or
105
+ * `simpleUploadThresholdBytes` that is not a positive integer, a `conditionalDelete` that is not a boolean, an
106
+ * empty or non-string `apiEndpoint` or `projectId`, or an invalid `prefix` or `readTimeoutMs`.
107
+ */
91
108
  constructor(options: GcsStorageOptions);
109
+ /**
110
+ * Reads the bucket's metadata (one request, plus the SDK's own retries, bounded by `readTimeoutMs` when it is set) and
111
+ * reports a lifecycle rule with a `Delete` action (or one it does not know) that applies to live
112
+ * objects whose names can be this store's: generations and registry rows alike. Needs `storage.buckets.get`, which
113
+ * a load never uses (`store.preflight()`'s lifecycle step does) and `roles/storage.objectAdmin` does not include: without it the answer is
114
+ * `unchecked`, naming the permission. Never rejects; a `detail` carries no credential. Rule reading: see the
115
+ * production guide.
116
+ */
117
+ checkLifecycle(): Promise<LifecycleVerdict>;
92
118
  }