Generated from the public declaration entry point packages/storage/dist/index.d.ts. Internal modules are intentionally excluded.
Kind: type
Result of appending one lifecycle event.
export type AppendRoleAssignmentAuditEventResult =
| Readonly<{
readonly status: "appended" | "unchanged";
readonly record: SequencedRoleAssignmentAuditEvent;
}>
| Readonly<{
readonly status: "conflict";
readonly reason: "event_id" | "lifecycle_position";
}>;Kind: interface
Atomically revokes one role and appends its derived audit event.
export interface AuditedRevokeRoleAssignmentCommand extends RevokeRoleAssignmentCommand {
readonly auditEventId: RoleAssignmentAuditEventId;
}Kind: type
Result of one atomic audited revoke attempt.
export type AuditedRevokeRoleAssignmentResult =
| Readonly<{
readonly status: "revoked" | "unchanged";
readonly record: VersionedRoleAssignment<RevokedRoleAssignment>;
readonly auditRecord: SequencedRoleAssignmentAuditEvent;
}>
| Readonly<{
readonly status: "not_found";
}>
| Readonly<{
readonly status: "conflict";
readonly reason:
"concurrency" | "lifecycle" | "event_id" | "lifecycle_position";
}>;Kind: interface
Safe combined role-and-audit mutation boundary.
Implementations decide role-side conflicts before audit-side conflicts. Audit payloads are derived from the role lifecycle; callers supply only an exact event ID. An unchanged revoke replay matches the completed event ID and revocation evidence; the opaque pre-revocation token is not retained.
An unchanged grant replay attests to the assignment ID, its principal, scope,
and role, and the grant event ID — not to the whole command. A replay whose
principal, scope, or role differs is a reused assignment ID and conflicts;
one that differs only in grantedBy or grantedAtEpochMs is unchanged, and
the returned record is the stored assignment rather than the command's, so a
caller always reads back what is actually persisted.
export interface AuditedRoleAssignmentMutationStore {
readonly grantRoleAssignmentWithAudit: (
command: GrantRoleAssignmentCommand,
) => Promise<GrantRoleAssignmentResult>;
readonly revokeRoleAssignmentWithAudit: (
command: AuditedRevokeRoleAssignmentCommand,
) => Promise<AuditedRevokeRoleAssignmentResult>;
}Kind: const
Creates an isolated, ephemeral reference adapter for one host application.
It is the storage-core memory store behind {@link createRoleStore}, so it enforces the same key, transaction, and optimistic-concurrency rules a durable backend does. It is not durable and not a cross-process transaction.
export declare const createInMemoryStorageAdapter: (
options?: InMemoryStorageAdapterOptions,
) => InMemoryStorageAdapter;Kind: type
Result of atomically attempting to create one active assignment.
export type CreateRoleAssignmentResult =
| Readonly<{
readonly status: "created";
readonly record: VersionedRoleAssignment<ActiveRoleAssignment>;
}>
| Readonly<{
readonly status: "unchanged";
readonly record: VersionedRoleAssignment;
}>
| Readonly<{
readonly status: "conflict";
readonly reason: "assignment_id" | "active_tuple";
}>;Kind: const
Binds the authorization collections to one backend and one host application.
The returned object is the safe combined surface: exact reads plus audited grant and revoke. It deliberately has no raw role or audit write, so every mutation preserves the combined lifecycle-and-audit invariant.
Durability, cross-process transactions, and restart recovery are properties
of the Store that is passed in, not of this binding.
export declare const createRoleStore: (
store: Store,
applicationId: ApplicationId,
) => InMemoryStorageAdapter;Kind: interface
Atomically grants one role and appends its derived audit event.
export interface GrantRoleAssignmentCommand {
readonly assignment: ActiveRoleAssignment;
readonly auditEventId: RoleAssignmentAuditEventId;
}Kind: type
Result of one atomic audited grant attempt.
export type GrantRoleAssignmentResult =
| Readonly<{
readonly status: "granted";
readonly record: VersionedRoleAssignment<ActiveRoleAssignment>;
readonly auditRecord: SequencedRoleAssignmentAuditEvent;
}>
| Readonly<{
readonly status: "unchanged";
readonly record: VersionedRoleAssignment;
readonly auditRecord: SequencedRoleAssignmentAuditEvent;
}>
| Readonly<{
readonly status: "conflict";
readonly reason:
"assignment_id" | "active_tuple" | "event_id" | "lifecycle_position";
}>;Kind: interface
Durable identity-link persistence.
linkIdentity atomically claims one exact, case-sensitive issuer-and-subject
tuple for one host principal. The first write for a tuple is linked; a
replay carrying the same principal is unchanged; a write whose tuple is
already linked to a different principal is a conflict, because each tuple
links to at most one principal while one principal may hold many tuples.
Successful results return the stored link, so a caller always reads back what is actually persisted. Links have no unlink or relink operation on this surface; moving a tuple between principals is a host administrative decision outside this port.
export interface IdentityLinkStore extends PrincipalLookupStore {
readonly linkIdentity: (link: IdentityLink) => Promise<LinkIdentityResult>;
}Kind: interface
Ephemeral single-process reference adapter.
Its public surface intentionally omits the raw role and audit write ports so every mutation preserves the combined lifecycle-and-audit invariant.
export interface InMemoryStorageAdapter
extends
IdentityLinkStore,
RoleAssignmentReader,
RoleHolderReader,
RoleHolderIndexMaintenance,
RoleAssignmentAuditReader,
AuditedRoleAssignmentMutationStore {}Kind: interface
Optional read-only identity-link seeds for one in-memory instance.
export interface InMemoryStorageAdapterOptions {
readonly identityLinks?: readonly IdentityLink[];
}Kind: type
Result of atomically attempting to persist one durable identity link.
export type LinkIdentityResult =
| Readonly<{
readonly status: "linked" | "unchanged";
readonly link: IdentityLink;
}>
| Readonly<{
readonly status: "conflict";
readonly reason: "principal";
}>;Kind: interface
Exact, read-only identity-link lookup.
One instance or namespace belongs to one host application. Shared backends bind that application partition at construction.
null means the link is definitively absent. Implementations reject for
operational failures, incomplete reads, and corrupt records.
export interface PrincipalLookupStore extends IdentityAdapter<IdentityLinkKey> {}Kind: interface
Result of one by-role index rebuild.
export interface RebuildRoleHolderIndexResult {
/** Index rows written by this run; rows already present are not counted. */
readonly recorded: number;
}Kind: interface
Conditional, exact-ID revocation command.
The expected token belongs only to the specified assignment record.
export interface RevokeRoleAssignmentCommand {
readonly assignmentId: RoleAssignmentId;
readonly expectedConcurrencyToken: RoleAssignmentConcurrencyToken;
readonly revokedBy: RoleAssignmentActor;
readonly revokedAtEpochMs: number;
readonly reason?: string;
}Kind: type
Result of attempting one exact-ID conditional revocation.
export type RevokeRoleAssignmentResult =
| Readonly<{
readonly status: "revoked" | "unchanged";
readonly record: VersionedRoleAssignment<RevokedRoleAssignment>;
}>
| Readonly<{
readonly status: "not_found";
}>
| Readonly<{
readonly status: "conflict";
readonly reason: "concurrency" | "lifecycle";
}>;Kind: type
Role-lifecycle-specific append-only audit event.
export type RoleAssignmentAuditEvent =
| Readonly<{
readonly id: RoleAssignmentAuditEventId;
readonly kind: "granted";
readonly assignment: ActiveRoleAssignment;
}>
| Readonly<{
readonly id: RoleAssignmentAuditEventId;
readonly kind: "revoked";
readonly assignment: RevokedRoleAssignment;
}>;Kind: type
Opaque, exact event identifier selected by the host.
export type RoleAssignmentAuditEventId = string;Kind: interface
Read-only append-only role-audit history.
export interface RoleAssignmentAuditReader {
/**
* Complete per-assignment history in strictly increasing sequence order.
*
* An empty array means definitive absence. Implementations reject partial,
* operationally failed, or corrupt results.
*/
readonly listRoleAssignmentAuditEvents: (
assignmentId: RoleAssignmentId,
) => Promise<readonly SequencedRoleAssignmentAuditEvent[]>;
}Kind: interface
Append-only role lifecycle audit port.
Like the role-assignment port, one instance or namespace belongs to one host application, with any shared-backend partition bound at construction.
Sequence values are positive safe integers assigned independently for each assignment and listed in strictly increasing order. This port makes no global gapless-order, update/delete, retention, signing, or tamper-evidence promise.
export interface RoleAssignmentAuditStore extends RoleAssignmentAuditReader {
readonly appendRoleAssignmentAuditEvent: (
event: RoleAssignmentAuditEvent,
) => Promise<AppendRoleAssignmentAuditEventResult>;
}Kind: type
Opaque record-scoped optimistic-concurrency token.
export type RoleAssignmentConcurrencyToken = string;Kind: interface
Read-only role-assignment persistence shared by stores and safe adapters.
export interface RoleAssignmentReader {
/** Exact-ID lifecycle read; `null` means definitive absence. */
readonly getRoleAssignment: (
assignmentId: RoleAssignmentId,
) => Promise<VersionedRoleAssignment | null>;
/**
* Complete exact-principal and exact-scope active selection.
*
* An empty array means definitive emptiness. Implementations reject partial,
* operationally failed, or corrupt results.
*/
readonly listActiveRoleAssignments: (
principalId: PrincipalId,
scope: RoleAssignmentScope,
) => Promise<readonly ActiveRoleAssignment[]>;
/**
* Complete exact-principal and exact-scope lifecycle selection.
*
* Returns every assignment the principal has ever held in the scope — active
* and revoked alike — with grant and revocation evidence intact, ordered by
* `grantedAtEpochMs` ascending and then by assignment ID code-unit order.
*
* An empty array means definitive emptiness. Implementations reject partial,
* operationally failed, or corrupt results.
*/
readonly listRoleAssignments: (
principalId: PrincipalId,
scope: RoleAssignmentScope,
) => Promise<readonly RoleAssignment[]>;
}Kind: interface
Provider-neutral role-assignment persistence.
A store instance or namespace belongs to exactly one host application. Shared backends bind that application partition when constructing the store; application identity is deliberately absent from every query.
export interface RoleAssignmentStore extends RoleAssignmentReader {
/**
* Atomically creates one active record while enforcing unique assignment ID
* and one active exact `(principalId, role, scope)` tuple.
*/
readonly createRoleAssignment: (
assignment: ActiveRoleAssignment,
) => Promise<CreateRoleAssignmentResult>;
/**
* Conditionally and irreversibly revokes exactly one assignment ID.
*
* Implementations preserve grant evidence, advance the record token, and
* treat an exact replay of completed revocation evidence as unchanged.
*/
readonly revokeRoleAssignment: (
command: RevokeRoleAssignmentCommand,
) => Promise<RevokeRoleAssignmentResult>;
}Kind: interface
Maintenance for the library-maintained by-role index.
Grants made through this version and later maintain the index themselves.
Assignments granted by an earlier version have no index row until
rebuildRoleHolderIndex runs once over the backing store. It is
idempotent and safe to run concurrently with grants and revocations.
export interface RoleHolderIndexMaintenance {
readonly rebuildRoleHolderIndex: () => Promise<RebuildRoleHolderIndexResult>;
}Kind: interface
Cross-principal by-role selection.
Separate from {@link RoleAssignmentReader} so hosts that implement the storage ports themselves are not required to provide it. Role administration surfaces use it to answer "who holds role R in this scope", including the last-administrator guard's "does another active holder exist".
export interface RoleHolderReader {
/**
* Every active assignment of one role in one exact scope, across
* principals, ordered by `grantedAtEpochMs` ascending and then by
* assignment ID code-unit order.
*
* Every result is verified against the authoritative lifecycle record, so
* a revoked or refused assignment is never reported as active. Like the
* per-principal listings this is a non-snapshot read: a concurrent grant or
* revoke in another principal's partition may or may not be reflected, so
* an at-least-one invariant still needs the re-verify-after-commit
* treatment in `docs/STORAGE.md`.
*
* Implementations must verify every reported assignment against the
* authoritative lifecycle record; an unverified secondary-index read is
* not conforming, because a stale row would count a revoked holder.
*
* An empty array means definitive emptiness once the index covers every
* stored assignment. For the provided adapters that holds after
* `rebuildRoleHolderIndex` has run once over a store that holds grants
* made before the index existed; until then an empty result can omit
* those grants. Implementations reject partial, operationally failed, or
* corrupt results.
*/
readonly listActiveRoleAssignmentsByRole: (
role: RoleName,
scope: RoleAssignmentScope,
) => Promise<readonly ActiveRoleAssignment[]>;
}Kind: interface
Audit event with its store-assigned per-assignment sequence.
export interface SequencedRoleAssignmentAuditEvent {
readonly sequence: number;
readonly event: RoleAssignmentAuditEvent;
}Kind: interface
One immutable lifecycle record and its current concurrency token.
export interface VersionedRoleAssignment<
Assignment extends RoleAssignment = RoleAssignment,
> {
readonly assignment: Assignment;
readonly concurrencyToken: RoleAssignmentConcurrencyToken;
}