///
///
import { Readable } from "node:stream";
import { BucketNotificationEventType, type BucketNotificationHandlerOptions, type BucketNotificationHandlerSpec, type BucketSpec, type SourceLocation } from "./internal/service-spec.js";
import type { DurationSchedule } from "./schedule.js";
export type PresignedUrlOperation = "put" | "get" | "head" | "delete";
export interface Bucket extends Omit, "handlers"> {
kind: "Bucket";
options: BucketOptions | undefined;
handlers: BucketNotificationHandler[];
/**
* Gets an object from the gets, returns undefined if the object key doesn't exist.
*/
get(key: string, options?: GetBucketObjectOptions): Promise;
/**
* Gets the object metadata from the bucket, returns undefined if the object key doesn't exist.
*/
head(key: string, options?: GetBucketObjectOptions): Promise;
/**
* Creates or updates an object in a bucket.
*/
put(key: string, data: string | Buffer | Readable, options?: PutBucketOptions): Promise;
/**
* Deletes an object from a bucket.
*/
delete(key: string): Promise;
/**
* Copies an object at a key to another key in the same bucket or a key in another bucket.
*/
copyTo(key: string, sourceKey: string, sourceBucket?: Bucket, options?: CopyBucketObjectOptions): Promise;
/**
* Generates an expiring url that can be used to interact with an object
* without needing read permission to the bucket.
*
* For AWS, this url will be an S3 presigned url. See the s3 documentation for how to use it.
*
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html
*
* Presigned urls are not currently supported in Eventual Local dev server.
*/
generatePresignedUrl(
/**
* The key that the url can act on
*/
key: string,
/**
* The operation the user can perform
*/
operation: PresignedUrlOperation,
/**
* Expiration Duration
*
* @default - 1 hour
*/
expires?: DurationSchedule): Promise;
/**
* List keys and their metadata within a bucket.
*/
list(request: ListBucketRequest): Promise;
/**
* The name of the bucket in the cloud environment.
*
* For example, in AWS this is the s3 bucket name.
*
* In a local environment, this will just be the bucket name;
*/
physicalName: string;
/**
* Provide a handler that is called when one of the supported events (put, delete, copy)
* happens within a bucket.
*
* Support filters on key prefix and suffix.
*
* ```ts
* myBucket.on("put", "putHandler", async (event) => {
* // start a workflow when a new object is added to the bucket.
* await myWorkflow.startExecution({ key: event.key });
* });
* ```
*/
on(events: BucketNotificationHandlerEventInput, name: Name, options: Omit, handler: BucketNotificationHandlerFunction): BucketNotificationHandler;
on(events: BucketNotificationHandlerEventInput, name: Name, handler: BucketNotificationHandlerFunction): BucketNotificationHandler;
}
export interface BucketOptions {
versioned?: boolean;
}
export declare function bucket(name: Name, options?: BucketOptions): Bucket;
export interface BucketObjectReference {
key: string;
eTag: string;
size: number;
}
export interface ListBucketResult {
objects: BucketObjectReference[];
keyCount: number;
nextToken?: string;
}
export interface ListBucketRequest {
nextToken?: string;
startAfter?: string;
prefix?: string;
/**
* @default 1000
*/
maxKeys?: number;
}
export interface GetBucketObjectOptions {
etag?: string;
}
export interface GetBucketMetadataResponse extends Omit {
/**
* Content length in bytes
*/
contentLength: number;
etag: string;
}
export interface GetBucketObjectResponse extends GetBucketMetadataResponse {
body: Readable;
/**
* Attempts to convert the body stream into a string.
*
* A value is only computed once. The same value will be returned each call.
*/
getBodyString(encoding?: BufferEncoding): Promise;
}
export interface PutBucketObjectResponse {
etag: string;
}
export interface PutBucketOptions {
cacheControl?: string;
contentEncoding?: string;
contentMD5?: string;
contentType?: string;
expires?: Date;
metadata?: Record;
}
export interface CopyBucketObjectOptions extends Omit {
sourceEtag?: string;
}
export interface CopyBucketObjectResponse {
etag?: string;
}
export interface BucketNotificationHandler extends BucketNotificationHandlerSpec {
kind: "BucketNotificationHandler";
handler: BucketNotificationHandlerFunction;
sourceLocation?: SourceLocation;
}
export interface BucketNotificationHandlerFunction {
(item: BucketNotificationEvent): Promise | void;
}
export interface BucketNotificationEventBase {
handlerName: string;
bucketName: string;
key: string;
}
export interface BucketNotificationPutEvent extends BucketNotificationEventBase {
event: "put" | "copy";
etag: string;
size: number;
}
export interface BucketNotificationDeleteEvent extends BucketNotificationEventBase {
event: "delete";
}
export type BucketNotificationEvent = BucketNotificationPutEvent | BucketNotificationDeleteEvent;
export type BucketNotificationHandlerEventInput = BucketNotificationEventType[] | BucketNotificationEventType | "all";
export interface BucketGeneratePresignedResult {
/**
* S3 Presigned supporting the given operation.
*/
url: string;
/**
* ISO 8601 timestamp representing when the url will expire.
*/
expires: string;
}
//# sourceMappingURL=bucket.d.ts.map