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;
}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
}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>;
}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";
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.