UNPKG

fraci

Version:

Fractional indexing that's robust, performant, and secure, with first-class support for Drizzle ORM and Prisma ORM.

134 lines (130 loc) 6.11 kB
export { e as AnyBinaryFraci, b as AnyBinaryFractionalIndex, p as AnyBinaryFractionalIndexBase, A as AnyFraci, a as AnyFractionalIndex, f as AnyStringFraci, t as AnyStringFractionalIndex, q as AnyStringFractionalIndexBase, B as BinaryFraciOptions, D as DEFAULT_MAX_LENGTH, c as DEFAULT_MAX_RETRIES, d as Fraci, j as FraciCache, o as FraciOf, i as FraciOptions, g as FraciOptionsBase, h as FraciOptionsBaseToBase, s as FractionalIndex, r as FractionalIndexBase, F as FractionalIndexOf, S as StringFraciOptions, k as createFraciCache, n as fraci, l as fraciBinary, m as fraciString } from './types-Gn-I8HuO.cjs'; /** Decimal */ declare const BASE10 = "0123456789"; /** Lowercase hex */ declare const BASE16L = "0123456789abcdef"; /** Uppercase hex */ declare const BASE16U = "0123456789ABCDEF"; /** Lowercase alphabets */ declare const BASE26L = "abcdefghijklmnopqrstuvwxyz"; /** Uppercase alphabets */ declare const BASE26U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** Lowercase alphanumeric characters */ declare const BASE36L = "0123456789abcdefghijklmnopqrstuvwxyz"; /** Uppercase alphanumeric characters */ declare const BASE36U = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /** Alphabets */ declare const BASE52 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; /** Alphanumeric characters */ declare const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; /** Characters used in Base64 URL */ declare const BASE64URL = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; /** HTML safe chars */ declare const BASE88 = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"; /** All ASCII (excluding control chars and newlines) */ declare const BASE95 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; /** * Error codes for the Fraci library. * * These codes help identify specific error conditions that may occur during library operations. * * - `INITIALIZATION_FAILED`: Indicates that the library failed to initialize. * Currently seen when the base string does not meet the requirements, or when the specified model or field does not exist in the generated Prisma client. * - `INTERNAL_ERROR`: Indicates an internal error in the library. Please file an issue if you see this. * - `INVALID_FRACTIONAL_INDEX`: Indicates that an invalid fractional index was provided to `generateKeyBetween` or `generateNKeysBetween` functions. * - `MAX_LENGTH_EXCEEDED`: Indicates that the maximum length of the generated key was exceeded. * - `MAX_RETRIES_EXCEEDED`: Indicates that the maximum number of retries was exceeded when generating a key. * * @see {@link FraciError} - The custom error class for the Fraci library */ type FraciErrorCode = "INITIALIZATION_FAILED" | "INTERNAL_ERROR" | "INVALID_FRACTIONAL_INDEX" | "MAX_LENGTH_EXCEEDED" | "MAX_RETRIES_EXCEEDED"; /** * Custom error class for the Fraci library. * * This class encapsulates errors that occur during fractional indexing operations, * providing structured error information through error codes and descriptive messages. * Use the utility functions {@link isFraciError} and {@link getFraciErrorCode} to safely work with these errors. * * @see {@link FraciErrorCode} - The error codes for the Fraci library * @see {@link isFraciError} - Type guard to check if an error is a FraciError * @see {@link getFraciErrorCode} - Function to extract the error code from a FraciError */ declare class FraciError extends Error { /** * The specific error code identifying the type of error. */ readonly code: FraciErrorCode; /** * A descriptive message providing details about the error condition. */ readonly message: string; readonly name: "FraciError"; constructor( /** * The specific error code identifying the type of error. */ code: FraciErrorCode, /** * A descriptive message providing details about the error condition. */ message: string); } /** * Type guard that checks if the given error is an instance of {@link FraciError}. * * This is useful in error handling blocks to determine if an error originated from the Fraci library. * * @param error - The error to check * @returns `true` if the error is a {@link FraciError}, `false` otherwise * * @example * ```typescript * try { * // Some Fraci operation * } catch (error) { * if (isFraciError(error)) { * // Handle Fraci-specific error * } else { * // Handle other types of errors * } * } * ``` * * @see {@link FraciError} - The custom error class for the Fraci library * @see {@link getFraciErrorCode} - Function to extract the error code from a {@link FraciError} */ declare function isFraciError(error: unknown): error is FraciError; /** * Extracts the error code from a {@link FraciError}. * * This function safely extracts the error code without requiring type checking first. * If the error is not a {@link FraciError}, it returns `undefined`. * * @param error - The error to extract the code from * @returns The {@link FraciErrorCode} if the error is a {@link FraciError}, `undefined` otherwise * * @example * ```typescript * try { * // Some Fraci operation * } catch (error) { * switch (getFraciErrorCode(error)) { * case "MAX_LENGTH_EXCEEDED": * case "MAX_RETRIES_EXCEEDED": * // Handle specific error case * break; * * default: * // Handle other cases, including unknown errors * // or Fraci errors that are not handled above * break; * } * } * ``` * * @see {@link FraciError} - The custom error class for the Fraci library * @see {@link FraciErrorCode} - The error codes for the Fraci library * @see {@link isFraciError} - Type guard to check if an error is a {@link FraciError} */ declare function getFraciErrorCode(error: unknown): FraciErrorCode | undefined; export { BASE10, BASE16L, BASE16U, BASE26L, BASE26U, BASE36L, BASE36U, BASE52, BASE62, BASE64URL, BASE88, BASE95, FraciError, type FraciErrorCode, getFraciErrorCode, isFraciError };