Skip to content
API reference

grants

Import
import * as api from "@fungi.computer/ear-tag/grants";
Kind Export Description
class GrantsDefinitionError Rejected when a host’s capability vocabulary violates defineGrants’ invariants.
type alias GrantTargets How a grant’s capability reaches resources.
type alias Grant One capability bound to the resources it may act on.
type alias Scope The bounded authority one key carries: 1 to 64 grants.
type alias GrantVocabulary Zod schemas and grant operations closed over one host’s capability vocabulary.
type alias GrantsDefinition A host’s capability vocabulary and its optional implied-capability classes.
function defineGrants() Declares one host’s capability vocabulary and the zod schemas and grant operations closed over it.

Rejected when a host’s capability vocabulary violates defineGrants’ invariants.

This error retains neither the rejected definition nor a foreign cause.

  • Error
Signature
new GrantsDefinitionError(): GrantsDefinitionError;

Creates a fresh bounded definition error.

GrantsDefinitionError

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

Stable public error name.

Signature
Error.name;

GrantTargetstype alias

Section titled “GrantTargets”
Signature
type GrantTargets =
| Readonly<{
kind: "all";
}>
| Readonly<{
kind: "selected";
ids: readonly string[];
}>;

How a grant’s capability reaches resources.


Signature
type Grant<Capability> = Readonly<{
capability: Capability;
targets: GrantTargets;
}>;

One capability bound to the resources it may act on.

Type Parameter Default type
Capability extends string string

Signature
type Scope<Capability> = Readonly<{
grants: readonly Grant<Capability>[];
}>;

The bounded authority one key carries: 1 to 64 grants.

Type Parameter Default type
Capability extends string string

GrantVocabularytype alias

Section titled “GrantVocabulary”
Signature
type GrantVocabulary<Capability> = Readonly<{
capabilityNameSchema: z.ZodType<Capability>;
grantSchema: z.ZodType<Grant<Capability>>;
scopeSchema: z.ZodType<Scope<Capability>>;
canonicalGrants: (grants) => readonly Grant<Capability>[];
grantsAllow: (grants, capability, resourceId?) => boolean;
grantsList: (grants, capability) => boolean;
isSubset: (child, parent) => boolean;
}>;

Zod schemas and grant operations closed over one host’s capability vocabulary.

Type Parameter
Capability extends string

GrantsDefinitiontype alias

Section titled “GrantsDefinition”
Signature
type GrantsDefinition<Capability> = Readonly<{
capabilities: Capability;
implies?: Readonly<
Partial<Record<Capability[number], readonly Capability[number][]>>
>;
}>;

A host’s capability vocabulary and its optional implied-capability classes.

Type Parameter
Capability extends readonly [string, ...string[]]

defineGrants()function

Section titled “defineGrants()”
Signature
function defineGrants<Capability>(
definition,
): GrantVocabulary<Capability[number]>;

Declares one host’s capability vocabulary and the zod schemas and grant operations closed over it.

Type Parameter
Capability extends readonly [string, string]
Parameter Type
definition GrantsDefinition<Capability>

GrantVocabulary<Capability[number]>

GrantsDefinitionError When the vocabulary repeats a capability, or implies names a capability outside it.