Skip to main content

Gcs Datastore

@swamp/gcs-datastorev2026.10.24.2· AGPL-3.0-or-later· 1d agoDATASTORES
01README

Store data in a Google Cloud Storage bucket with local cache synchronization. Provides distributed locking via GCS generation-based preconditions with exponential backoff under contention and bidirectional sync between a local cache directory and GCS. Emits OpenTelemetry spans for GCS operations, lock acquisition/release, and push/pull sync so datastore activity is visible in traces when a TracerProvider is configured. Features shard-first indexing with per-model partition shards under _index/ as the source of truth (v2 repos skip the monolithic index upload entirely), commitSeq-based zero-diff fast path, compare-and-swap (ifGenerationMatch) merges for every shard and _meta.json write so concurrent writers never drop each other's index entries, two-phase sync to narrow the global-lock critical section, SHA-256 content hashing, per-path dirty tracking, namespace-scoped sync for multi-repo shared datastores, configurable transfer concurrency, configurable per-request timeout, managed config refresh for pulling config partitions from the datastore, and a single-file remote read that writes nothing to the local cache.

Groundwork for the v3 datastore format: a datastore-wide control plane at the root _control/ that holds the v3 writer lease and replication lineage (no namespaced pull or push moves _control/writer/, _control/lineage/ or _control/datastore-format, and the provider declares datastoreWideLease), and storage/1 chunk storage under _blobs/ with 16 MiB single-request puts, a price-tuned has, and a touch that refreshes a chunk by a rewrite of it onto itself, with no re-upload and no new permissions.

The Litestream replica target for v3: replicaTarget() names the bucket and the datastore root that storage() and the control plane write under, with no credentials (Litestream reads the same default credential chain), and refuses a config it cannot describe, including a custom apiEndpoint, which Litestream cannot use. replicaPaths() lists and removes the Litestream lineage paths under <prefix>/_litestream/<fence>/, so swamp can collect a lineage a takeover replaced and stop deferring chunk collection. Swamp's v3 on buckets (Phase 4E) needs this version or later.

Keeps the v2 file sync off a v3 datastore, for swamp releases older than v20261008.201010.0 that check no format marker: _litestream/ is never indexed, pulled or pushed, and the sync service reads the root _control/datastore-format once, alongside the credentials preflight, and refuses format 3 or newer, or a garbled marker, with datastore_format_unsupported before it syncs anything. An unreadable marker does not block that operation, and the next one reads it again.

Authentication

Uses Google Cloud Application Default Credentials (ADC) — no credentials in config. Provide credentials via one of:

  • Environment variable: GOOGLE_APPLICATION_CREDENTIALS pointing to a service account key JSON file
  • User credentials: gcloud auth application-default login
  • Attached service account on GCE, Cloud Run, or GKE

Required IAM Permissions

  • storage.buckets.get
  • storage.objects.create
  • storage.objects.get
  • storage.objects.delete
  • storage.objects.list

The predefined role roles/storage.objectAdmin covers all of these.

Usage

swamp datastore setup @swamp/gcs-datastore \
  --config '{"bucket": "my-bucket", "prefix": "swamp"}' --json
02Datastores1
Google Cloud Storageconfigurable
@swamp/gcs-datastoregcs.ts

Store data in a Google Cloud Storage bucket with local cache synchronization. Provides distributed locking via GCS generation-based preconditions and bidirectional sync between a local cache directory and GCS.

Config Fields

FieldTypeDescription
bucketstringGCS bucket name
prefix?stringObject name prefix within the bucket
projectId?stringGCP project ID (defaults to ADC project)
apiEndpoint?stringCustom API endpoint URL (for emulators like fake-gcs-server)
pullConcurrency?numberMaximum concurrent GCS downloads during pull. Default: 50
pushConcurrency?numberMaximum concurrent GCS uploads during push. Default: 25
requestTimeoutMs?numberPer-request timeout in milliseconds. Default: 30000.
03Previous Versions19
2026.10.23.1AGPL-3.0-or-later
2026.10.20.2AGPL-3.0-or-later
2026.10.20.1AGPL-3.0-or-later
2026.10.16.5AGPL-3.0-or-later
2026.10.16.4AGPL-3.0-or-later
2026.10.16.3AGPL-3.0-or-later
2026.10.16.2AGPL-3.0-or-later
2026.10.16.1AGPL-3.0-or-later
2026.10.15.2AGPL-3.0-or-later
2026.10.15.1AGPL-3.0-or-later(was none)
2026.10.13.1
2026.10.07.1
2026.10.06.1
2026.10.01.1
2026.09.24.1
2026.09.23.1
2026.09.22.1
2026.09.21.2
2026.09.21.1
04Stats
A
93 / 100
Downloads
493,062
Archive size
179.0 KB
Verified by Swamp
  • Has README or module doc2/2earned
  • README has a code example1/1earned
  • README is substantive1/1earned
  • Most symbols documented1/1earned
  • No slow types (deprecated)1/1earned
  • Dependencies pass trust audit1/2partial
    • @std/fs--jsr:@std/fs@1 is a range; audited 1.0.24, the version the registry resolved (from deno.lock)
    • @std/path--jsr:@std/path@1 is a range; audited 1.1.6, the version the registry resolved (from deno.lock)
    4 dependencies found
    • jsr:@std/fs@1 -- audited 1.0.24
    • jsr:@std/path@1 -- audited 1.1.6
    • jsr:@std/path@1.1.4 -- audited 1.1.4
    • npm:@opentelemetry/api@1.9.0 -- audited 1.9.0
  • Docs keep secrets in a vault1/1earned
  • Has description1/1earned
  • Platform support declared (or universal)2/2earned
  • License2/2earned
  • Verified public repository2/2earned
05Platforms
06Labels