import { Context, Effect, Layer, Schema, Stream } from "effect"; import type { Scope } from "effect"; import type { EventTypeFilter } from "../events/index.js"; import type { Adapter, AdapterCapabilities, Body, BulkOptions, BulkResult, ConditionalUploadOptions, ConditionalUploadResult, CopyOptions, DeleteManyOptions, DeleteManyResult, DeleteOptions, DownloadManyOptions, DownloadOptions, ExistsManyResult, FileInfo, FilesOptions, HeadManyResult, ListOptions, ListResult, OperationOptions, ResumableUploadSession, SearchOptions, SignedUpload, SignUploadOptions, StoredFile, UploadManyItem, UploadManyOptions, UploadManyResult, UploadOptions, UploadResult, UrlOptions } from "../index.js"; import { Files as FilesClient } from "../index.js"; import type { FileEvent } from "../internal/events.js"; export type { FileEvent, FileEventType } from "../internal/events.js"; export type { EventTypeFilter } from "../events/index.js"; declare const NotFound_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** The object or key doesn't exist. */ export declare class NotFound extends NotFound_base { } declare const Unauthorized_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** The provider rejected the credentials or the access they grant. */ export declare class Unauthorized extends Unauthorized_base { } declare const Conflict_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** A precondition failed: a conditional write lost, or the key already exists. */ export declare class Conflict extends Conflict_base { } declare const ReadOnly_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** A write on a read-only `Files` instance. */ export declare class ReadOnly extends ReadOnly_base { } declare const Invalid_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** The call itself is wrong: a bad argument, contradictory options, bad config. */ export declare class Invalid extends Invalid_base { } declare const Unsupported_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** Well-formed, but this adapter (in this mode, with these plugins) can't do it. */ export declare class Unsupported extends Unsupported_base { } declare const Provider_base: Schema.Class; /** `true` when a conditional mutation committed before the call failed. */ readonly applied: Schema.withConstructorDefault; /** The committed ETag, when `applied` is set on an upload. */ readonly appliedEtag: Schema.optional; /** The SDK's `FilesError`, with the provider's own error as its `cause`. */ readonly cause: Schema.optional; readonly message: Schema.String; /** `true` when retrying the same call can only fail the same way. */ readonly permanent: Schema.withConstructorDefault; /** `true` when a configured `timeout` cut the operation off. */ readonly timedOut: Schema.withConstructorDefault; }>, import("effect/Cause").YieldableError>; /** The backend or transport failed. The only code the SDK retries. */ export declare class Provider extends Provider_base { } /** One reason per `FilesErrorCode`, tagged with the code. */ export type FilesErrorReason = NotFound | Unauthorized | Conflict | ReadOnly | Invalid | Unsupported | Provider; declare const FilesError_base: Schema.Class; }>, import("effect/Cause").YieldableError>; /** * Every failure from a `files-sdk/effect` operation. `reason._tag` is the * SDK's `FilesErrorCode`; `reason.cause` is the SDK's own `FilesError`. */ export declare class FilesError extends FilesError_base { get message(): string; } /** * A downloaded object: its {@link FileInfo} plus the body as Effect values. * `text`, `arrayBuffer` and `blob` buffer the body and can be run more than * once; `stream` reads it unbuffered, once, and can't be mixed with them (the * same rule as the SDK's `StoredFile`). Interrupting a buffered read cancels * the body read unless another read still waits on it, and a cancelled body * can't be read again. */ export interface DownloadedFile extends FileInfo { /** Same as `key` (the `File`-like name). */ readonly name: string; /** Same as `contentType` (the `File`-like MIME type). */ readonly type: string; readonly text: Effect.Effect; readonly arrayBuffer: Effect.Effect; readonly blob: Effect.Effect; /** The body, unbuffered. Interrupting the stream cancels the read. */ readonly stream: Stream.Stream; /** The SDK's `StoredFile`, for APIs that take a `File`-like (`Response`, `FormData`). */ readonly file: StoredFile; } /** What the array form of `download()` resolves to. */ export type DownloadedManyResult = BulkResult; /** Handles one storage event. A failure fails the delivery, so the provider redelivers. */ export type FileEventHandler = (event: FileEvent) => Effect.Effect; /** Options for {@link FileEventsService.stream}. */ export interface FileEventStreamOptions { /** * Events buffered for a slow consumer before deliveries wait for room. * Default 16. */ bufferSize?: number; } /** * Storage events, for an instance with the `events()` plugin * (`files-sdk/events`). Without it, every member fails with `Unsupported`. */ export interface FileEventsService { /** * Run `handler` for events of `type` whose key matches `pattern` (a glob, * `**` when omitted), for the lifetime of the current `Scope`. Deliveries * wait for the handler, so a failure (or an interruption when the scope * closes) fails the delivery and the provider redelivers it: delivery stays * at-least-once. Use this to process events durably. */ readonly on: { (type: EventTypeFilter, handler: FileEventHandler): Effect.Effect; (type: EventTypeFilter, pattern: string, handler: FileEventHandler): Effect.Effect; }; /** * Events of `type` (default `"*"`) whose key matches `pattern` (default * `**`), as a `Stream`. A delivery is acknowledged once its event is * buffered, before the consumer processes it, so an event in the buffer when * the process stops is lost: use {@link on} when every event must be * handled. When the buffer is full, deliveries wait; any still waiting when * the stream ends fail, so the provider redelivers them. */ readonly stream: (type?: EventTypeFilter, pattern?: string, options?: FileEventStreamOptions) => Stream.Stream; /** `files.events.parse()`: normalize deliveries into events without running handlers. */ readonly parse: (input: unknown) => Effect.Effect; /** `files.events.dispatch()`: parse, then run the matching handlers. */ readonly dispatch: (input: unknown) => Effect.Effect; } /** * The `Files` service: each `Files` method as an `Effect` (or a `Stream`), * failing with {@link FilesError}. Options are the SDK's own; a `signal` you * pass still aborts the call alongside the fiber's. */ export interface FilesService { /** The wrapped instance, for what the service doesn't cover (`raw`, `prefix`, `file()`). */ readonly client: F; /** `files.capabilities`: what this adapter (and plugin stack) supports. */ readonly capabilities: AdapterCapabilities; readonly upload: { (key: string, body: Body, opts: ConditionalUploadOptions): Effect.Effect; (key: string, body: Body, opts?: UploadOptions): Effect.Effect; (items: UploadManyItem[], opts?: UploadManyOptions): Effect.Effect; }; readonly download: { (key: string, opts?: DownloadOptions): Effect.Effect; (keys: string[], opts?: DownloadManyOptions): Effect.Effect; }; readonly head: { (key: string, opts?: OperationOptions): Effect.Effect; (keys: string[], opts?: BulkOptions): Effect.Effect; }; readonly exists: { (key: string, opts?: OperationOptions): Effect.Effect; (keys: string[], opts?: BulkOptions): Effect.Effect; }; readonly delete: { (key: string, opts?: DeleteOptions): Effect.Effect; (keys: string[], opts?: DeleteManyOptions): Effect.Effect; }; readonly copy: (from: string, to: string, opts?: CopyOptions) => Effect.Effect; readonly move: (from: string, to: string, opts?: OperationOptions) => Effect.Effect; readonly list: (opts?: ListOptions) => Effect.Effect; /** Every object, page by page. Stopping the stream early stops the walk. */ readonly listAll: (opts?: ListOptions) => Stream.Stream; /** `files.search()`: objects whose key matches `pattern`, as a `Stream`. */ readonly search: (pattern: string | RegExp, opts?: SearchOptions) => Stream.Stream; readonly url: (key: string, opts?: UrlOptions) => Effect.Effect; readonly signedUploadUrl: (key: string, opts: SignUploadOptions) => Effect.Effect; readonly abortUpload: (key: string, session: ResumableUploadSession, opts?: OperationOptions) => Effect.Effect; /** * Run any call on the wrapped instance (a plugin method, `transfer()`) * with the same error mapping as the built-in operations. Pass `signal` to * calls that take one, and interrupting the fiber aborts them too. */ readonly tryPromise: (run: (client: F, signal: AbortSignal) => PromiseLike) => Effect.Effect; readonly events: FileEventsService; } /** * The {@link FilesService} for a `Files` instance. `Files.layer()` covers the * common case; call this to provide the service under your own * `Context.Service` (one per bucket, or typed with a `createFiles()` * instance's plugin methods). */ export declare const make: (client: F) => FilesService; declare const Files_base: Context.ServiceClass>>>; /** * The `Files` service. Provide it with {@link Files.layer}, then * `yield* Files` to get the {@link FilesService}. * * ```ts * const program = Effect.gen(function* () { * const files = yield* Files; * yield* files.upload("hello.txt", "Hello"); * }); * program.pipe(Effect.provide(Files.layer({ adapter: s3() }))); * ``` */ export declare class Files extends Files_base { /** * Provide {@link Files} from a `Files` instance, or from the options to * construct one (invalid options fail the layer with `Invalid`). */ static readonly layer: (clientOrOptions: FilesClient | FilesOptions) => Layer.Layer; } //# sourceMappingURL=index.d.ts.map