import { Readable } from "node:stream"; import { File } from "./file.js"; import { Image } from "./image.js"; import { Resource } from "./resource.js"; export * from "./file.js"; export * from "./image.js"; export * from "./resource.js"; export interface WithBodyTimeoutOptions { /** * The maximum time allowed for the request to complete, in milliseconds. * * @default 86400000 (1 day) */ reqeustTimeout?: number | null; /** * The maximum time the connection can remain idle before being closed, in milliseconds. * * @default 30000 (30 seconds) */ idleTimeout?: number | null; } export interface ResourcePutOptions extends WithBodyTimeoutOptions { /** * The file content as a readable stream. * * Can be either a `ReadableStream` (for web) or a Node.js `Readable` stream. */ fileStream: ReadableStream | Readable; /** * The name of the file, including its extension (e.g., `"file.txt"`). * * If not provided (`undefined`), Datalith will automatically determine the file name. * * @default undefined */ fileName?: string; /** * The MIME type of the file (e.g., `"image/jpeg"`, `"application/pdf"`). * * If not provided (`undefined`), Datalith will automatically determine the file type. * * @default undefined */ fileType?: string; /** * The file size. * * If not provided (`undefined`), Datalith will not be aware of the correct file size, which may result in the file being incomplete. * * If you're unsure about the file size, you can set it to the maximum file size you want it to be. * * @default undefined */ fileSize?: number; /** * Indicates if the file is temporary. If `true`, the file may be deleted after a short period and can use the `getRecource` method to retrieve it only once. * * If not provided (`undefined`), Datalith will decide whether the file is temporary, defaulting to `false`. * * @default undefined (Datalith defaults to `false`) */ temporary?: boolean; } export interface ImagePutOptions extends WithBodyTimeoutOptions { /** * The file content as a readable stream. * * Can be either a `ReadableStream` (for web) or a Node.js `Readable` stream. */ fileStream: ReadableStream | Readable; /** * The name of the image file, including its extension (e.g., `"image.jpg"`). * * If not provided (`undefined`), Datalith will automatically determine the file name. * * @default undefined */ fileName?: string; /** * The file size. * * If not provided (`undefined`), Datalith will not be aware of the correct file size, which may result in the file being incomplete. * * If you're unsure about the file size, you can set it to the maximum file size you want it to be. * * @default undefined */ fileSize?: number; /** * The maximum width of the image in pixels. * * If not provided (`undefined`), Datalith will not resize the image by width. * * @default undefined */ maxWidth?: number; /** * The maximum height of the image in pixels. * * If not provided (`undefined`), Datalith will not resize the image by height. * * @default undefined */ maxHeight?: number; /** * The aspect ratio for cropping the image (e.g., `"1:1"`). * * If not provided (`undefined`), Datalith will not crop the image. * * @default undefined * * @example "1:1" */ centerCrop?: string; /** * Indicates whether to save the original image file. * * If not provided (`undefined`), Datalith will automatically decide whether to save the original file, with the default being `true`. * * @default undefined (Datalith defaults to `true`) */ saveOriginalFile?: boolean; /** * The maximum time allowed for the request to complete, in milliseconds. * * @default 86400000 (1 day) */ reqeustTimeout?: number | null; /** * The maximum time the connection can remain idle before being closed, in milliseconds. * * @default 30000 (30 seconds) */ idleTimeout?: number | null; } export interface FileGetOptions extends WithBodyTimeoutOptions { /** * Whether to download as a file. It will affect the `contentDisposition` field of the returned `File` instance. * * If not provided (`undefined`), Datalith will default to `false`. * * @default undefined (Datalith defaults to `false`) */ download?: boolean; } export type ResourceGetOptions = FileGetOptions; export type Resolution = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}x` | "original"; export interface ImageGetOptions extends FileGetOptions { /** * The desired resolution of the image. * * Can be a scaling factor from `"1x"`, `"2x"`, `"3x"`, ..., etc, or `"original"` for the original resolution. * * If not provided (`undefined`), Datalith will automatically set the resolution to `1x`. * * @default undefined (Datalith defaults to `"1x"`) */ resolution?: Resolution; /** * Whether to use a fallback image (in PNG/JPEG format instead of WebP). * * If not provided (`undefined`), Datalith will default to `false` and will not use a fallback image. * * @default undefined (Datalith defaults to `false`) */ fallback?: boolean; /** * The maximum time allowed for the request to complete, in milliseconds. * * @default 86400000 (1 day) */ reqeustTimeout?: number | null; /** * The maximum time the connection can remain idle before being closed, in milliseconds. * * @default 30000 (30 seconds) */ idleTimeout?: number | null; } export interface DeleteOptions { /** * The maximum time allowed for the request to complete, in milliseconds. * * @default 30000 (30 seconds) */ reqeustTimeout?: number | null; } export * from "./errors.js"; export declare class Datalith { private readonly _apiOperate; private readonly _apiOperateImage; private readonly _apiFetch; private readonly _apiFetchImage; constructor(apiPrefix: URL | string); /** * Input a resource into Datalith. * * @throws {BadRequestError} * @throws {PayloadTooLargeError} * @throws {Error} */ putResource(options: ResourcePutOptions): Promise; /** * Input a image into Datalith. * * @throws {BadRequestError} * @throws {PayloadTooLargeError} * @throws {Error} */ putImage(options: ImagePutOptions): Promise; /** * Get a resource from Datalith. * * @throws {BadRequestError} * @throws {Error} */ getResource(id: string, options?: ResourceGetOptions): Promise; /** * Get an image from Datalith. * * @throws {BadRequestError} * @throws {Error} */ getImage(id: string, options?: ImageGetOptions): Promise; /** * Delete a resource from Datalith. * * @throws {BadRequestError} * @throws {Error} */ deleteResource(id: string, options?: DeleteOptions): Promise; /** * Delete an image from Datalith. * * @throws {BadRequestError} * @throws {Error} */ deleteImage(id: string, options?: DeleteOptions): Promise; delete(id: string, apiURL: URL, options?: DeleteOptions): Promise; /** * Convert a resource into an image. * * @throws {NotFoundError} * @throws {BadRequestError} * @throws {Error} */ convertResourceToImage(id: string, options: DeleteOptions & Pick): Promise; } /** * Validates if the input string is a valid center crop string (in the format of `":"`). */ export declare const validateCenterCrop: (centerCrop?: string) => boolean; /** * Validates if the given resolution is either `undefined`, `"original"`, or follows the format of `"x"`. */ export declare const validateResolution: (resolution?: string) => resolution is Resolution;