Metakit / @doeixd/metakit/domain

Id

namespace · packages/metakit/src/domain/id.ts:8

export * as Id from './domain/id.js'

Id: branded, non-empty, NUL-free entity identifiers (@doeixd/metakit/domain).

Id.make('User') produces a Schema branded by 'User' so TypeScript rejects accidental cross-entity comparisons (Eq.is(user.id, org.id)), while remaining a plain string at runtime, in SQL (TEXT), and in Z3 (nulFree).

In the guides

Members

Id.IdOptions

interface · packages/metakit/src/domain/id.ts:18

interface IdOptions {
  readonly prefix?: string
  readonly minLength?: number
  readonly maxLength?: number
}

Id.IdValue

type · packages/metakit/src/domain/id.ts:14

type IdValue<Entity extends string = string> = string & {
  readonly [IdBrand]: Entity
}

A branded string identifier for entity Entity.

Id.make

function · packages/metakit/src/domain/id.ts:31

function make<const Entity extends string>(
  entity: Entity,
  options?: IdOptions,
): Schema.Codec<IdValue<Entity>, string>

Create a branded, non-empty, NUL-free identifier Schema for entity. Recognized as nulFree by MetaKit's checker and Z3 prover.

Id.value

function · packages/metakit/src/domain/id.ts:74

function value<Entity extends string>(
  id: Schema.Codec<IdValue<Entity>, string>,
  raw: string,
): IdValue<Entity>

Construct a branded IdValue<Entity>, throwing the Schema's message if raw breaks its prefix, lengths or NUL rule.