UNPKG

@chop-url/lib

Version:

A TypeScript library for URL shortening functionality with Cloudflare D1 database support

67 lines (66 loc) 1.69 kB
/** * Configuration options for ChopUrl instance */ export interface ChopUrlConfig { /** Base URL for generating short URLs (e.g., https://example.com) */ baseUrl: string; /** D1 Database instance */ db: D1Database; } /** * Information about a shortened URL */ export interface UrlInfo { /** Generated short ID */ shortId: string; /** Original URL */ originalUrl: string; /** Complete short URL */ shortUrl: string; /** Creation timestamp */ createdAt: Date; /** Number of visits */ visits: number; } /** * Custom error class for ChopUrl operations */ export declare class ChopUrlError extends Error { code: ChopUrlErrorCode; details?: Record<string, unknown> | undefined; constructor(message: string, code: ChopUrlErrorCode, details?: Record<string, unknown> | undefined); } /** * Error codes for ChopUrl operations */ export declare enum ChopUrlErrorCode { URL_NOT_FOUND = "URL_NOT_FOUND", INVALID_URL = "INVALID_URL", DATABASE_ERROR = "DATABASE_ERROR", INVALID_SHORT_ID = "INVALID_SHORT_ID" } declare global { /** * Cloudflare D1 Database interface */ interface D1Database { prepare(query: string): D1PreparedStatement; } /** * Cloudflare D1 Prepared Statement interface */ interface D1PreparedStatement { bind(...values: unknown[]): D1PreparedStatement; first<T = unknown>(): Promise<T | null>; run(): Promise<D1Result>; } /** * Cloudflare D1 Query Result interface */ interface D1Result { success: boolean; error?: string; lastRowId?: number; changes?: number; } }