import { a as StandardSchemaProps, i as ParseResult, n as JsonSchema, o as ValidBrand, t as Id } from "./types-hGBnCpJj.mjs"; //#region src/codecs/reverse/index.d.ts /** * Configuration options for a Reverse Timestamp codec instance. */ type ReverseTimestampOptions = { /** Returns the current timestamp in milliseconds. Defaults to `Date.now`. */now?: () => number; /** Writes the 10-byte random tail into `target`. Defaults to a `crypto.randomUUID` harvest fast path (same as the Timestamp codec). */ rng?: (target: Uint8Array) => void; /** If true, silences the duplicate-brand warning in non-production environments. */ allowDuplicateBrand?: boolean; }; /** * A brand-scoped codec for generating and validating Reverse Timestamp IDs. * * Wire format: `{brand}_` plus 26 lowercase Crockford base32 characters encoding a * 16-byte payload (6-byte bitwise-inverted ms timestamp + 10 random bytes). IDs sort * by creation time in **descending** (newest-first) order. * * Range queries across a time interval [t_old, t_new] should scan from * `minIdForTime(t_new)` to `maxIdForTime(t_old)` — the reversed sort order means * newer timestamps produce lexicographically smaller IDs. * * Constructed via `createReverseTimestampId(brand)` from `@smonn/ids/reverse`. */ type ReverseTimestampCodec = { /** Produces a new canonical ID using the codec's `now` and `rng`. */generate(): Id; /** Produces a new canonical ID with timestamp bytes from `date` and a fresh random tail. Throws on invalid dates. */ generateAt(date: Date): Id; /** * Strict type guard: `true` only for already-canonical strings for this brand. * For untrusted input, use `safeParse()` or `parse()` instead. See ADR-0003. */ is(value: unknown): value is Id; /** * Lenient parse: normalises case and Crockford aliases, returns canonical `Id`, or throws. */ parse(value: unknown): Id; /** * Lenient parse without throwing: normalises to canonical form, or returns `{ ok: false, error }`. */ safeParse(value: unknown): ParseResult; /** * Decodes the creation `Date` from an `Id` by inverting the timestamp bytes. * Trusts the type — use `safeParse()` at boundaries first. * * Best-effort: inverts and decodes the timestamp bytes in the payload without any * additional verification. An ID that bypassed `safeParse()` (e.g. via a type * assertion) may return a plausible-looking but incorrect `Date`. */ extractTimestamp(id: Id): Date; /** * Lexicographically smallest ID for any ID generated at `date` (random portion `0x00`). * Because timestamps are inverted, a newer `date` yields a lexicographically smaller result — * use `minIdForTime(t_new)` as the lower bound when scanning [t_old, t_new]. * Throws on invalid dates. */ minIdForTime(date: Date): Id; /** * Lexicographically largest ID for any ID generated at `date` (random portion `0xff`). * Because timestamps are inverted, an older `date` yields a lexicographically larger result — * use `maxIdForTime(t_old)` as the upper bound when scanning [t_old, t_new]. * Throws on invalid dates. */ maxIdForTime(date: Date): Id; /** * JSON Schema for the canonical wire form. The `pattern` matches the canonical stored * form only and is deliberately stricter than `parse()`/`safeParse()`, which accept * uppercase letters and Crockford aliases (`o`/`i`/`l`) before normalising. See ADR-0003. */ toJsonSchema(): JsonSchema; /** Standard Schema validate entry point. */ readonly "~standard": StandardSchemaProps; /** * Converts a trusted `Id` to an RFC 9562 canonical (lowercase, hyphenated) * UUID string by reinterpreting the 16-byte payload verbatim. Total — cannot fail. * Returns a plain `string` (brand is shed). See ADR-0024. */ toUUID(id: Id): string; /** * Parses a UUID string into an `Id`. Accepts case-insensitive `8-4-4-4-12` * hyphenated form only. Throws `IdsError` with `code: "invalid_id"` on bad input. * See ADR-0024. */ fromUUID(value: string): Id; /** * Non-throwing UUID parse. Returns `{ ok: true, id }` or * `{ ok: false, error: "not_string" | "invalid_uuid" }`. See ADR-0024. */ safeFromUUID(value: unknown): ParseResult; }; /** * Creates a Reverse Timestamp codec for `brand` (three lowercase a–z characters). * * IDs sort newest-first: the 48-bit timestamp field is bitwise-inverted before encoding, * so lexicographic ID order equals descending creation-time order. `extractTimestamp` * inverts back to recover the original millisecond. * * @param brand - Entity type brand validated once at construction. * @param opts - Optional `now`, `rng`, and `allowDuplicateBrand` overrides. * @example * ```ts * const posts = createReverseTimestampId("pst"); * * const id = posts.generate(); // Id<"pst"> (newest-first sort) * posts.extractTimestamp(id); // Date * ``` */ declare function createReverseTimestampId(brand: Brand & ValidBrand, opts?: ReverseTimestampOptions): ReverseTimestampCodec; //#endregion export { ReverseTimestampCodec, ReverseTimestampOptions, createReverseTimestampId }; //# sourceMappingURL=reverse.d.mts.map