Skip to content

API reference

storage creates Layeron bucket and KV storage modules and exposes runtime object operations.

Terminal window
import { storage } from "@layeron/modules"

Create an R2-backed Layeron Storage bucket.

TypeSpec operation: bucket.

Terminal window
storage.bucket(options: StorageBucketOptions): StorageBucketModule

Reference to a Layeron Secret used by Storage.

FieldTypeDescription
kind”secret_ref”Secret reference marker.
namestringSecret name declared in the same app.

Encryption settings for a storage bucket or KV namespace.

FieldTypeDescription
modeStorageEncryptionMode | undefinedEncryption mode. Defaults to managed when a secret is provided.
algorithmStorageEncryptionAlgorithm | undefinedEncryption algorithm. Defaults to AES-GCM-256.
secretSecretRef | undefinedSecret used for encryption, decryption, and managed-encryption signed URL tokens.

Lifecycle rules for objects stored in an R2-backed bucket.

FieldTypeDescription
deleteAfterDaysint32 | undefinedDelete bucket objects through native Cloudflare R2 lifecycle after this many days.

Options shared by storage.bucket() and storage.kv().

FieldTypeDescription
namestringStable storage instance name inside the Layeron app.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
bindingstring | undefinedCustom Cloudflare binding name for the product worker.
sharedStorageSharedResourceOptions | undefinedReference an existing R2 bucket or KV namespace in the same Cloudflare account.
accessStorageAccessMode | undefinedDefault access mode for this storage instance.
metadataRecord<unknown> | undefinedStatic metadata recorded on the module declaration.
encryptionStorageEncryptionOptions | undefinedManaged encryption settings for values stored by this instance.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings for storage reads, writes, deletes, listing, and signed URL operations.
placementLayeron.Common.Placement.LayeronPlacement | undefinedPlacement overrides for this storage product instance.

Existing Cloudflare storage resource used by this Storage module.

FieldTypeDescription
resourcestringStable shared resource name used in Layeron metadata.
bucketNamestring | undefinedExisting R2 bucket name. Required for storage.bucket() shared resources.
namespaceIdstring | undefinedExisting KV namespace id. Required for storage.kv() shared resources.
prefixstring | undefinedOptional key prefix applied to reads, writes, deletes, lists, and signed URLs.

Options accepted by storage.bucket() for an R2-backed object bucket.

FieldTypeDescription
lifecycleStorageLifecycleOptions | undefinedNative R2 lifecycle settings for bucket objects.
hoststring | undefinedDedicated hostname for signed URL delivery through the Storage Product Worker.
pathstring | undefinedPath prefix for signed URL delivery. Defaults to /__layeron/r2 when host or url is configured.
urlstring | undefinedAbsolute URL used to infer the signed URL host and path prefix.

Options accepted by storage.kv() for a Cloudflare KV namespace.

FieldTypeDescription
ttlSecondsint32 | undefinedDefault KV expiration in seconds for values written by this instance.

Options accepted by put() when writing a storage value.

FieldTypeDescription
contentTypestring | undefinedMIME type stored with the value and returned from signed URL reads.
metadataRecord<unknown> | undefinedUser metadata stored beside the value.
checksumstring | undefinedCaller-provided checksum stored as public metadata named checksum; callers own checksum validation.
ifNotExistsboolean | undefinedWhen true, the write succeeds only for a key that is absent. Existing keys fail with storage_key_already_exists and HTTP status 409.
ttlSecondsint32 | undefinedPer-write KV expiration in seconds.

Options accepted by bucket.signedUrl().

FieldTypeDescription
actionStorageSignedUrlAction | undefinedOperation allowed by the URL. Defaults to read.
expiresInSecondsint32 | undefinedURL lifetime in seconds. Defaults to 600.
contentTypestring | undefinedRequired content type for write URLs and response content type for stored values.
metadataRecord<unknown> | undefinedMetadata applied when a write signed URL stores the uploaded object.
maxSizeBytesint32 | undefinedMaximum upload size accepted by a write signed URL.
oneTimeboolean | undefinedWhen true, the URL can be consumed once. A replay receives HTTP 410.

Internal result returned by the Storage Product Worker when it creates a signed URL.

FieldTypeDescription
urlstringShort-lived URL to send to the client.
expiresAtstringISO timestamp when the URL expires.
tokenstringOpaque token embedded in the URL.

Result returned after storing a value.

FieldTypeDescription
keystringStorage key written by the operation.
sizeint32Original plaintext byte size.
etagstringEntity tag for the stored value.
contentTypestring | undefinedStored MIME type when provided.
storedAtstringISO timestamp when Layeron accepted the write.
keyVersionstring | undefinedSecret version used for managed encryption.
encryptedboolean | undefinedWhether Layeron encrypted the value before storage.

Metadata returned by head() or attached to a read result.

FieldTypeDescription
keystringStorage key for the value.
sizeint32Original plaintext byte size.
etagstringEntity tag for the stored value.
contentTypestring | undefinedStored MIME type when present.
metadataRecord<unknown>User metadata stored beside the value.
storedAtstringISO timestamp when the value was stored.
updatedAtstring | undefinedProvider update timestamp when available.
keyVersionstring | undefinedSecret version used for managed encryption.
encryptedboolean | undefinedWhether Layeron encrypted the value before storage.

Read result returned by get().

FieldTypeDescription
bodybytesValue bytes after Layeron-managed decryption when encryption is enabled.

One item returned by list().

FieldTypeDescription
kindStorageVariantStorage backend that owns this item.

Options accepted by list().

FieldTypeDescription
prefixstring | undefinedOnly return keys that start with this prefix.
cursorstring | undefinedProvider cursor returned by a previous list call.
limitint32 | undefinedMaximum number of items to return.

Result returned by list().

FieldTypeDescription
itemsStorageListItem[]Listed storage items.
cursorstring | undefinedCursor for the next page when more items are available.
truncatedboolean | undefinedWhether the provider stopped before returning every matching item.

Result returned by delete().

FieldTypeDescription
keystringStorage key targeted by the delete operation.
deletedbooleanWhether Layeron accepted the delete operation.

Normalized Storage module configuration recorded in the app spec.

FieldTypeDescription
kind”storage”Module config kind.
variantStorageVariantStorage backend variant.
namestringStable storage instance name.
namespacestringPlatform namespace for the instance. Defaults to default.
bindingstringPrimary product worker binding name.
accessStorageAccessModeDefault access mode.
metadataRecord<unknown> | undefinedStatic metadata recorded on the module declaration.
encryptionStorageEncryptionOptions | undefinedManaged encryption configuration.
lifecycleStorageLifecycleOptions | undefinedR2 lifecycle settings for bucket instances.
ttlSecondsint32 | undefinedDefault KV expiration in seconds.
signedUrlStorageSignedUrlEndpointConfig | undefinedSigned URL delivery endpoint for bucket instances.
stateDatabaseStorageStateDatabaseConfig | undefinedLayeron Database-backed state used by one-time signed URLs.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings recorded with the Storage product configuration.
placementLayeron.Common.Placement.LayeronPlacement | undefinedPlacement overrides for this storage product instance.

Dedicated endpoint settings for Storage signed URL traffic.

FieldTypeDescription
hoststring | undefinedDedicated host used for signed URL delivery.
pathstringPath prefix used for signed URL delivery.

Database Product state backing used by Storage for replay-protected signed URLs.

FieldTypeDescription
productName”db”Product that owns the state database.
namespace”layeron”Internal Layeron namespace for product-owned state.
namestringDatabase Product instance name.
storeLogicalIdstringLogical id of the state store resource.
migrationLogicalIdsstring[]Migration resource ids applied to the state store.
signedUrlTokenTablestringTable used to track consumed one-time signed URL tokens.

Layeron bucket module returned by storage.bucket().

FieldTypeDescription
name”storage”Module name.
configStorageModuleConfigNormalized module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Layeron KV module returned by storage.kv().

FieldTypeDescription
name”storage”Module name.
configStorageModuleConfigNormalized module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Managed encryption behavior for stored values.

ValueDescription
noneStore values without Layeron-managed encryption.
managedEncrypt values in the Storage Product Worker before writing them to Cloudflare storage.

Encryption algorithms supported by Layeron Storage.

ValueDescription
aes-gcm-256AES-GCM with 256-bit key material derived from the configured Secret.

Default object access policy for a storage instance.

ValueDescription
privateObjects require application code or a signed URL to read or write.
publicObjects are intended for public delivery when the deployment exposes them.

Action allowed by a generated storage signed URL.

ValueDescription
readAllow downloading or reading an object.
writeAllow uploading or replacing an object.

Storage backend selected by storage.bucket() or storage.kv().

ValueDescription
bucketCloudflare R2 object storage for files, assets, and binary payloads.
kvCloudflare KV for small read-heavy values and edge configuration data.

Create a Cloudflare KV-backed Layeron Storage namespace.

TypeSpec operation: kv.

Terminal window
storage.kv(options: StorageKvOptions): StorageKvModule

Write bytes to a storage key. ifNotExists writes fail with storage_key_already_exists when the key already exists.

Terminal window
storagePut(key: string, value: bytes, options?: StorageBodyOptions): StoragePutResult

Read bytes and metadata from a storage key.

Terminal window
storageGet(key: string): StorageReadResult | null

Read metadata for a storage key without returning the body.

Terminal window
storageHead(key: string): StorageHeadResult | null

Delete a storage key.

Terminal window
storageDelete(key: string): StorageDeleteResult

List keys and metadata in a storage instance.

Terminal window
storageList(options?: StorageListOptions): StorageListResult

Create a short-lived signed URL for a bucket object.

Terminal window
storageSignedUrl(key: string, options?: StorageSignedUrlOptions): string