Reference
Types
Type reference for the @fileway/core public API
All types are exported from @fileway/core. See Observability for the semantics of errors, logging, and onError.
UploadOptions
interface UploadOptions {
filename: string;
mimeType?: string;
path?: string;
metadata?: Record<string, string>;
size?: number;
signal?: AbortSignal;
onProgress?: (progress: UploadProgress) => void;
streamFactory?: () => ReadableStream<Uint8Array>; // sync today; async return is a planned future feature
}UploadProgress
interface UploadProgress {
bytes: number;
total?: number;
progress?: number; // 0..1, present only when total is known
}UploadResult<TMeta>
interface UploadResult<TMeta extends Record<string, unknown>> {
id: string;
url: string;
path: string;
size: number;
meta: TMeta;
}PresignedUrlOptions
interface PresignedUrlOptions {
expiresIn?: number; // seconds; default 3600, bounds driver-specific
}RetryConfig
Controls automatic retries for transient failures. Passed as retry in FilewayConfig. Only network, provider-error, and HTTP 429/5xx statuses are retried — validation, config, auth-failed, not-found, bucket-not-found, size-exceeded, and AbortError are never retried. See Retries for how it behaves.
interface RetryConfig {
maxRetries?: number; // attempts after the first; default 3, 0 disables
baseDelayMs?: number; // first delay; default 300
maxDelayMs?: number; // cap on any single delay; default 10000
multiplier?: number; // exponential backoff factor; default 2
jitter?: boolean; // full jitter over [0, delay]; default true
retryHttpStatuses?: number[]; // extra HTTP statuses to treat as retryable
retryGenericErrors?: boolean; // retry non-StorageError failures; default true
}BaseDriver<TMeta>
interface BaseDriver<TMeta extends Record<string, unknown> = Record<string, unknown>> {
name: string;
upload(
stream: ReadableStream<Uint8Array>,
options: UploadOptions,
): Promise<UploadResult<TMeta>>;
delete(path: string): Promise<boolean>;
getUrl(path: string): Promise<string>;
get(path: string): Promise<ReadableStream<Uint8Array>>;
getPresignedUrl?(path: string, options?: PresignedUrlOptions): Promise<string>;
}MiddlewareHook
interface MiddlewareHook {
beforeUpload?: (
stream: ReadableStream<Uint8Array>,
options: UploadOptions,
) => Promise<
| { stream?: ReadableStream<Uint8Array>; options?: UploadOptions }
| void
>;
afterUpload?: (result: UploadResult<Record<string, unknown>>) => Promise<void>;
}FilewayConfig
interface FilewayConfig<TDriver extends BaseDriver> {
driver: TDriver;
middlewares?: MiddlewareHook[];
logger?: Logger;
onError?: (error: unknown, context: ErrorContext) => void | Promise<void>;
retry?: RetryConfig;
}Logger
interface Logger {
debug?(message: string, meta?: Record<string, unknown>): void;
info?(message: string, meta?: Record<string, unknown>): void;
warn?(message: string, meta?: Record<string, unknown>): void;
error?(message: string, meta?: Record<string, unknown>): void;
}ErrorContext
interface ErrorContext {
operation: "upload" | "delete" | "get" | "getUrl" | "getPresignedUrl" | "retry";
durationMs: number;
filename?: string;
path?: string;
mimeType?: string;
size?: number;
}StorageError & StorageErrorCode
type StorageErrorCode =
| "validation"
| "config"
| "not-found"
| "bucket-not-found"
| "auth-failed"
| "size-exceeded"
| "network"
| "provider-error";
class StorageError extends Error {
readonly code: StorageErrorCode;
readonly statusCode?: number;
readonly provider?: string;
readonly cause?: unknown;
toJSON(): { name: string; code: StorageErrorCode; message: string; statusCode?: number; provider?: string };
}ValidationError is a StorageError subclass with code === "validation". isAbortError(err) detects the AbortError thrown by upload cancellation. See the error reference for what each code means and when to retry.