/** * Shared low-level helpers for the S3 storage provider and its append/lease * strategy candidates. * * Kept separate from `s3BlobProvider.ts` so the strategy modules under * `strategies/` can depend on the error-classification + stream helpers * without importing the provider class (which would create a cycle: * provider → strategy registry → strategy → provider). * * The error helpers map the AWS SDK v3 error surface onto the boolean * predicates the provider needs. AWS SDK v3 service errors are thrown as * `S3ServiceException` subclasses carrying a `.name` (the wire error code, * e.g. `NoSuchKey`, `PreconditionFailed`) and a `$metadata.httpStatusCode`. * Socket-level failures surface as plain `Error`s with a `.code` * (`ECONNRESET`, …). We read both without `instanceof` against SDK classes — * class identity is unstable across SDK minor versions and bundler transforms * (the same rationale as `safeRetry.ts` for Azure). */ import type { GetObjectCommandOutput, PutObjectCommand, PutObjectCommandOutput, S3Client } from '@aws-sdk/client-s3'; /** OTEL `storage.provider` attribute value. Grafana dashboards + the runbook key off this. */ export declare const S3_PROVIDER_NAME = "s3"; /** * Everything an append/lease strategy needs to talk to S3. The provider * builds one of these and hands it to the chosen {@link * import('./strategies/types.js').S3AppendLeaseStrategy} candidate at * construction. OTEL instrumentation is applied by the provider *around* each * delegated strategy method (one span per `StorageProvider` call, matching the * Azure provider's granularity), so the context deliberately carries no tracer. */ export type S3StrategyContext = { readonly client: S3Client; readonly bucket: string; }; /** Read the AWS SDK error code (`.name`), e.g. `NoSuchKey`, `PreconditionFailed`. */ export declare function s3ErrorName(err: unknown): string | undefined; /** Read `$metadata.httpStatusCode` off an SDK error, when present. */ export declare function s3HttpStatus(err: unknown): number | undefined; /** A 404 / no-such-key — the provider maps this to `null` on `read`/`head`. */ export declare function isS3NotFound(err: unknown): boolean; /** * A 416 — the requested range starts past EOF (most commonly a range read of a * 0-byte object). The provider surfaces this as an empty read, not an error, * so callers can range-read a short blob of unknown length without a `head` * pre-flight (matching the Azure provider's `InvalidRange` handling). */ export declare function isS3InvalidRange(err: unknown): boolean; /** * A 412 Precondition Failed — the `If-None-Match: *` (create-once) or * `If-Match: ` (compare-and-swap) condition on a conditional write did * not hold. This is the load-bearing S3 primitive: it backs both the * create-once `putBlockBlob` and the CAS fence in Candidate A. */ export declare function isS3PreconditionFailed(err: unknown): boolean; /** * A `409 ConditionalRequestConflict` — real S3's response when a conditional * write (`If-Match`/`If-None-Match`) cannot proceed because another conditional * operation is racing the same object RIGHT NOW. Distinct from `412`, which is a * clean "the precondition (ETag) did not hold" verdict. * * This 409 only surfaces under genuine concurrency and is **retryable**: re-read * the object's current state and try again. It is not proof a write was not * applied — the racing write may be our own. Critically, LocalStack does NOT * reproduce it (it serialises conditional writes), so this branch is only * exercised against real S3 — surfaced by the EXP-30 sandbox run. */ export declare function isS3ConditionalConflict(err: unknown): boolean; /** * Classify an S3 error as transient (broker-retryable): `SlowDown` (throttle), * `ServiceUnavailable`, `InternalError`, 5xx, or a socket-level reset. Mapped * onto {@link import('../types.js').TransientStorageError} so the producer's * application-layer retry budget can fire. Mirror of `isTransientAzureError`. * * NOTE: the AWS SDK v3 already retries these internally (standard retry mode, * `maxAttempts: 3` by default) — unlike the Azure SDK it does NOT retain * request bodies for minutes, so the ADR-0020 body-retention cascade does not * apply here. This classifier exists for the residual failures that survive * the SDK's own retries. */ export declare function isTransientS3Error(err: unknown): boolean; /** * Send `command` with exactly one HTTP attempt, whatever the client's retry * configuration (ADR-0030). The producer's leased conditional appends need * this: an SDK retry can hide an earlier attempt that committed behind a final * 412 or 4xx. A middleware inside the retry loop wraps the attempt's error in a * type the retry strategy will not retry, and it is unwrapped here. */ export declare function sendSingleAttempt(client: S3Client, command: PutObjectCommand): Promise; /** * Drain an S3 `GetObject` body to a Buffer. In Node the SDK augments the * response stream with the `transformToByteArray()` mixin; we prefer it and * fall back to async-iteration for any runtime that lacks it. */ export declare function s3BodyToBuffer(body: GetObjectCommandOutput['Body']): Promise; /** * Extract the total object length from a ranged `GetObject` response. * S3 returns `ContentRange: "bytes 0-1023/4096"` when a `Range` was sent; the * trailing number is the total. On a full-object read `ContentRange` is absent * and `ContentLength` IS the total. Final fallback: bytes collected so far. */ export declare function parseContentRangeTotal(contentRange: string | undefined, contentLength: number | undefined, fallback: number): number; //# sourceMappingURL=s3Common.d.ts.map