Skip to content
API reference

identifier

Import
import * as api from "@fungi.computer/cairn/id";
Kind Export Description
class CairnDefinitionError Bounded error thrown when a trusted family declaration violates Cairn’s version 1 definition invariants.
class CairnGenerationError Bounded error thrown when secure entropy is unavailable during codec generation.
type alias CairnId Canonical opaque identifier branded by its declaring family, kind, and wire grammar version.
type alias IdOf Extracts the distinctly branded identifier produced by an ID codec.
type alias IdParseError Bounded public description of a rejected identifier value.
type alias IdParseResult Successful canonical parsing or one bounded parse error.
type alias IdCodec Generator and canonical parser for one declared identifier family and kind.
type alias IdKindDefinition Trusted declaration for one identifier kind within a family.
type alias IdFamily Readonly family whose every own kind key maps to one distinctly branded version 1 codec.
function defineIdFamily() Validates one trusted version 1 family declaration and creates its readonly family-scoped codecs.

Bounded error thrown when a trusted family declaration violates Cairn’s version 1 definition invariants.

This error retains no rejected definition, family, kind, cause, or detail.

  • Error
Signature
new CairnDefinitionError(): CairnDefinitionError;

Creates a fresh bounded family-definition error.

CairnDefinitionError

Signature
Error.constructor;
Signature
readonly name: "CairnDefinitionError" = "CairnDefinitionError";

Stable public error name.

Signature
Error.name;
Signature
readonly code: "invalid_definition" = "invalid_definition";

Stable machine-readable error discriminator.


Bounded error thrown when secure entropy is unavailable during codec generation.

This error retains only validated family and kind metadata and never exposes a foreign cause, detail, or random bytes.

  • Error
Signature
new CairnGenerationError(input): CairnGenerationError;

Creates a fresh bounded generation error.

Parameter Type Description
input Readonly<{ family: string; kind: string; }> Validated family and kind metadata for the failing codec.

CairnGenerationError

Signature
Error.constructor;
Signature
readonly name: "CairnGenerationError" = "CairnGenerationError";

Stable public error name.

Signature
Error.name;
Signature
readonly code: "entropy_unavailable" = "entropy_unavailable";

Stable machine-readable error discriminator.

Signature
readonly family: string;

Validated family whose codec could not generate an identifier.

Signature
readonly kind: string;

Validated kind whose codec could not generate an identifier.

Signature
readonly version: 1 = 1;

Wire grammar version used by the codec.

Signature
type CairnId<F, K, V> = string & object;

Canonical opaque identifier branded by its declaring family, kind, and wire grammar version.

Name Type Description
[cairnIdBrand] readonly [F, K, V] Compile-time identity metadata that is never serialized.
Type Parameter Default type Description
F extends string - Declaring identifier family.
K extends string - Identifier kind within the family.
V extends 1 1 Retained wire grammar version; currently version 1.

Signature
type IdOf<C> =
C extends IdCodec<infer F, infer K, infer V> ? CairnId<F, K, V> : never;

Extracts the distinctly branded identifier produced by an ID codec.

Type Parameter Description
C Codec whose identifier type is required.

IdParseErrortype alias

Section titled “IdParseError”
Signature
type IdParseError<F, K> = Readonly<{
code: "invalid_id";
family: F;
kind: K;
version: 1;
reason: "bounds" | "grammar" | "non_canonical";
}>;

Bounded public description of a rejected identifier value.

The error deliberately retains neither the rejected value nor a foreign cause.

Type Parameter Description
F extends string Declaring identifier family.
K extends string Identifier kind within the family.

IdParseResulttype alias

Section titled “IdParseResult”
Signature
type IdParseResult<I, F, K> =
| Readonly<{
ok: true;
value: I;
}>
| Readonly<{
ok: false;
error: IdParseError<F, K>;
}>;

Successful canonical parsing or one bounded parse error.

Type Parameter Description
I Branded identifier returned after successful parsing.
F extends string Declaring identifier family.
K extends string Identifier kind within the family.

Signature
type IdCodec<F, K, V> = object;

Generator and canonical parser for one declared identifier family and kind.

Type Parameter Default type Description
F extends string - Declaring identifier family.
K extends string - Identifier kind within the family.
V extends 1 1 Retained wire grammar version; currently version 1.
Signature
readonly family: F;

Declared identifier family; it is not serialized into metadata.

Signature
readonly kind: K;

Declared identifier kind; it is not serialized into metadata.

Signature
readonly version: V;

Wire grammar version implemented by this codec.

Signature
readonly schema: z.ZodType<CairnId<F, K, V>, string>;

Schema for the untrusted wire boundary; outputs this codec’s branded ID.

Signature
generate(): CairnId<F, K, V>;

Generates one canonical identifier with a 21-character base36 suffix.

CairnId<F, K, V>

A fresh canonical identifier branded for this codec.

CairnGenerationError When secure entropy is unavailable.

Signature
parse(value): IdParseResult<CairnId<F, K, V>, F, K>;

Parses a decoded string candidate without trimming, decoding, or normalization.

Parameter Type Description
value string Decoded string candidate.

IdParseResult<CairnId<F, K, V>, F, K>

The original branded value or one bounded parse error.

Signature
is(value): value is CairnId<F, K, V>;

Reports whether a decoded string candidate is canonical for this codec.

Parameter Type Description
value string Decoded string candidate.

value is CairnId<F, K, V>

Whether the value is accepted by IdCodec.parse.


IdKindDefinitiontype alias

Section titled “IdKindDefinition”
Signature
type IdKindDefinition = Readonly<{
prefix: string;
}>;

Trusted declaration for one identifier kind within a family.


Signature
type IdFamily<F, D> = Readonly<{
readonly [K in keyof D]: IdCodec<F, K & string>;
}>;

Readonly family whose every own kind key maps to one distinctly branded version 1 codec.

Type Parameter Description
F extends string Declaring identifier family.
D extends Readonly<Record<string, IdKindDefinition>> Own identifier-kind declarations for the family.

defineIdFamily()function

Section titled “defineIdFamily()”
Signature
function defineIdFamily<F, D>(definition): IdFamily<F, D>;

Validates one trusted version 1 family declaration and creates its readonly family-scoped codecs.

Family and kind names, prefixes, own-key counts, and prefix uniqueness must satisfy the accepted Cairn invariants before any codec is returned.

Type Parameter Description
F extends string Literal identifier-family name.
D extends Readonly<Record<string, Readonly<{ prefix: string; }>>> Literal own kind declarations for the family.
Parameter Type Description
definition Readonly<{ family: F; version: 1; kinds: D; }> Trusted version 1 family declaration to validate.

IdFamily<F, D>

One readonly codec property for every own kind key.

CairnDefinitionError When any declaration invariant or property access fails.

Re-exports identifierCandidateSchema


Re-exports identifierDefinitionSchema