/** * Copyright 2026 Angus.Fenying * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { ETimeReversedStrategy } from './Constants.js'; export interface IUuid7GeneratorOptions { /** * The strategy for handling time reversal events. * * @default ETimeReversedStrategy.THROW_ERROR */ onTimeReversed?: ETimeReversedStrategy; } /** * The default strategy for the time reversal event, * which throws an `E_TIME_REVERSED` error. */ export declare const UUID7_DEFAULT_TIME_REVERSAL_STRATEGY = ETimeReversedStrategy.THROW_ERROR; /** * The class for generating UUID in version 7. */ export declare class Uuid7Generator { private _prevTime; private readonly _onTimeReversedStrategy; constructor(opts?: IUuid7GeneratorOptions); /** * Generate a UUIDv7 string, which is based on the current timestamp and random values. * * @returns A UUIDv7 string. * * @example * ```ts * const generator = new Uuid7Generator(); * const uuid = generator.generate(); * console.log(uuid); * ``` */ generate(): string; /** * Generate a binary UUIDv7 as a 16-byte buffer, which is based on the current timestamp and random values. * * @returns A Buffer containing the UUIDv7. * * @example * ```ts * const generator = new Uuid7Generator(); * const uuidBuffer = generator.generateAsBuffer(); * console.log(uuidBuffer); * ``` */ generateAsBuffer(): Buffer; /** * Generate a UUIDv7 string based on the provided timestamp and random value. * * > This method is implemented in pure JavaScript. * * @param timestamp The 48-bit timestamp in milliseconds since the Unix epoch. If not provided, the current time will be used. * @param randA A 12-bit random value to ensure uniqueness. If not provided, a random value will be generated. * * @returns A UUIDv7 string based on the provided timestamp and random value. * * @throws {RangeError} If the timestamp is not a non-negative integer or exceeds the maximum allowed value. * * @example * ```ts * const uuid = Uuid7Generator.generate(Date.parse('2024-01-01T00:00:00Z'), 123456); * console.log(uuid); * ``` */ static generate(timestamp?: number, randA?: number): string; /** * Generate a binary UUIDv7 based on the provided timestamp and random value, and return it as a Buffer. * * > This method is implemented in pure JavaScript. * * @param timestamp The 48-bit timestamp in milliseconds since the Unix epoch. If not provided, the current time will be used. * @param randA A 12-bit random value to ensure uniqueness. If not provided, a random value will be generated. * * @returns A Buffer containing the UUIDv7 based on the provided timestamp and random value. * * @throws {RangeError} If the timestamp is not a non-negative integer or exceeds the maximum allowed value. * * @example * ```ts * const uuid = Uuid7Generator.generateBuffer(Date.parse('2024-01-01T00:00:00Z'), 123456); * console.log(uuid); * ``` */ static generateBuffer(timestamp?: number, randA?: number): Buffer; } //# sourceMappingURL=UUIDv7.d.ts.map