IF Commons GitHub

logical/legacy-id

Written to: 1 requirement: 0 proved, 0 partly, 0 failing, 1 with no test recorded. 0002-planning-core FR-010

The ids of a record read from another scheme (0037-planning FR-044). An external id that is a valid ULID gives its item or event id by a pure function: the 48 bits of time of the ULID are the unix_ts_ms of a UUID version 7 and the first 74 of its 80 random bits are rand_a and rand_b (RFC 9562 section 5.7; ULID, 48 bits of time and 80 of chance), so that two stores that read one file make the same ids. An id that is not a ULID gives its id by the same function from the time of its event and the SHA-256 of the external id (the source's name, a zero byte and the value). The external id is carried beside the id, as the source named it, and no id's wording says where it came from.

import { uuid7OfUlid } from "./legacy-id.ts";
uuid7OfUlid("01ARZ3NDEKTSV4RRFFQ69G5FAV"); // { kind: "ok", value: "01563e3a-b5d3-7..." }

Source: commons/planning/src/logical/legacy-id.ts

0 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

logical.parseUlidfunctionno test imports it
function parseUlid(text: string): Result<{ readonly ms: number; readonly random: bigint; }, IdProblem>

The 48 bits of time and the 80 bits of chance of a ULID, or why a text is not one: 26 characters of Crockford's base 32, in either case, no larger than 7ZZZZZZZZZZZZZZZZZZZZZZZZZ.

logical.uuid7Textfunctionno test imports it
function uuid7Text(ms: number, bits74: bigint): string

The text of the UUID version 7 made of a time in milliseconds and 74 bits: the 12 leftmost are rand_a and the 62 others rand_b, with the version and the variant set.

logical.uuid7OfUlidfunctionno test imports it
function uuid7OfUlid(text: string): Result<string, IdProblem>

The UUID version 7 of a ULID, as text, or why the text is not a ULID.

logical.uuid7OfExternalfunctionno test imports it
function uuid7OfExternal(source: string, value: string, atMs: number): Promise<string>

The UUID version 7 of an id that is not a ULID, as text: the time of its event and the first 74 bits of the SHA-256 of the source's name, a zero byte and the value.

logical.itemIdOfExternalfunctionno test imports it
function itemIdOfExternal(source: string, value: string, atMs: number): Promise<Result<ItemId, IdProblem>>

The item id of an external id: the id of a ULID, else of the source's name, the value and the time of the item's opening.

logical.eventIdOfExternalfunctionno test imports it
function eventIdOfExternal(source: string, value: string, atMs: number): Promise<Result<EventId, IdProblem>>

The event id of an external id: the id of a ULID, else of the source's name, the value and the time of the event.

logical.ulidOfUuid7functionno test imports it
function ulidOfUuid7(id: EventId | ItemId): string

The ULID text that reads back as this id: its time as the 48 bits and its 74 random bits as the first 74 of the 80, so that uuid7OfUlid of it is the id again (the last six bits are zero).

parseUlidfunctionno test imports it
function parseUlid(text: string): Result<{ readonly ms: number; readonly random: bigint; }, IdProblem>

The 48 bits of time and the 80 bits of chance of a ULID, or why a text is not one: 26 characters of Crockford's base 32, in either case, no larger than 7ZZZZZZZZZZZZZZZZZZZZZZZZZ.

uuid7Textfunctionno test imports it
function uuid7Text(ms: number, bits74: bigint): string

The text of the UUID version 7 made of a time in milliseconds and 74 bits: the 12 leftmost are rand_a and the 62 others rand_b, with the version and the variant set.

uuid7OfUlidfunctionno test imports it
function uuid7OfUlid(text: string): Result<string, IdProblem>

The UUID version 7 of a ULID, as text, or why the text is not a ULID.

uuid7OfExternalfunctionno test imports it
function uuid7OfExternal(source: string, value: string, atMs: number): Promise<string>

The UUID version 7 of an id that is not a ULID, as text: the time of its event and the first 74 bits of the SHA-256 of the source's name, a zero byte and the value.

itemIdOfExternalfunctionno test imports it
function itemIdOfExternal(source: string, value: string, atMs: number): Promise<Result<ItemId, IdProblem>>

The item id of an external id: the id of a ULID, else of the source's name, the value and the time of the item's opening.

eventIdOfExternalfunctionno test imports it
function eventIdOfExternal(source: string, value: string, atMs: number): Promise<Result<EventId, IdProblem>>

The event id of an external id: the id of a ULID, else of the source's name, the value and the time of the event.

ulidOfUuid7functionno test imports it
function ulidOfUuid7(id: EventId | ItemId): string

The ULID text that reads back as this id: its time as the 48 bits and its 74 random bits as the first 74 of the 80, so that uuid7OfUlid of it is the id again (the last six bits are zero).

Titles, headings, exports, tables, columns and requirements. Esc closes.