Skip to content
API reference

storage

Import
import * as api from "@fungi.computer/agar/storage";
Kind Export Description
class AppStorageError Thrown by the storage client when a read, write, reset, or watch is rejected by the host; code identifies why.
type alias ResolvedAppStorage The resolved value for a storage key, as returned by read: the merged value, which layer it came from, the raw team/member layers, and whether this App may write to the team layer.
type alias AppStorageWrite A validated write request for one storage key.
type alias AppStorageReset A validated reset request for one storage key.
type alias AppStorageEvent A change-event payload identifying which App, key, scope, and resulting revision changed.
type alias AppStorageResult The wire-level outcome of a storage operation: either an accepted value or a rejection carrying an AppStorageError code.
type alias AppStorageWatch A live subscription to one storage key’s resolved value: read the current value, subscribe to changes, and close when done watching.
type alias AppStorage This App’s storage client, scoped to its declared member/team data.
type alias AppStorageEventHandle A live object capability backing one key’s change-event stream, adapted to Fetch so it can drive an EventSource.
type alias AppStorageWire The raw wire contract this capability negotiates with the host, before client-side input validation and error unwrapping.
constant appStorageErrorCodes Storage error codes the host and client agree on: invalid input, an undeclared key, a scope this App never declared, a member-only action tried without a member, a value or quota that is too large, a write conflict, or a transient host failure.
constant appStorageErrorCodeSchema Validates that a value is one of the known storage error codes.
constant resolvedAppStorageSchema Validates the resolved shape of a storage key: its merged value, which layer it came from, the raw team and member layers it was merged from, and whether this App may write to the team layer.
constant appStorageWriteSchema Validates a write request: the key, scope, value to store, and the expected revision of that layer (null requires the layer to be absent).
constant appStorageResetSchema Validates a reset request: the key, scope, and the revision it’s conditioned on (null requires the layer to be absent).
constant appStorageRevisionSchema Validates a bare revision number returned after a write or reset.
constant appStorageEventSchema Validates a change-event payload pushed when a storage key’s value changes, naming the App, key, scope, and resulting revision.
constant appStorageReadResultSchema Validates the wire result of a read: either an accepted resolved value or a rejection code.
constant appStorageMutationResultSchema Validates the wire result of a write or reset: either an accepted revision or a rejection code.
constant appStorageBrokerReadResultSchema The read result at a host broker, retaining its existing admission/failure reply.
constant appStorageBrokerMutationResultSchema The shared write/reset result at a host broker, including its existing failure reply.
constant appStorage This App’s own declared data. The host seals App and member identities.
constant appStorageKeyNameSchema Maintained grammar for one bounded key in an App’s private storage.

Thrown by the storage client when a read, write, reset, or watch is rejected by the host; code identifies why.

  • Error
Signature
new AppStorageError(code, options?): AppStorageError;
Parameter Type
code | "unavailable" | "invalid" | "conflict" | "too_large" | "undeclared_key" | "scope_not_declared" | "owner_required" | "quota_exceeded"
options? ErrorOptions

AppStorageError

Signature
Error.constructor;
Signature
readonly code:
| "unavailable"
| "invalid"
| "conflict"
| "too_large"
| "undeclared_key"
| "scope_not_declared"
| "owner_required"
| "quota_exceeded";

ResolvedAppStoragetype alias

Section titled “ResolvedAppStorage”
Signature
type ResolvedAppStorage = typeof resolvedAppStorageSchema.Type;

The resolved value for a storage key, as returned by read: the merged value, which layer it came from, the raw team/member layers, and whether this App may write to the team layer.


AppStorageWritetype alias

Section titled “AppStorageWrite”
Signature
type AppStorageWrite = typeof appStorageWriteSchema.Type;

A validated write request for one storage key.


AppStorageResettype alias

Section titled “AppStorageReset”
Signature
type AppStorageReset = typeof appStorageResetSchema.Type;

A validated reset request for one storage key.


AppStorageEventtype alias

Section titled “AppStorageEvent”
Signature
type AppStorageEvent = typeof appStorageEventSchema.Type;

A change-event payload identifying which App, key, scope, and resulting revision changed.


AppStorageResulttype alias

Section titled “AppStorageResult”
Signature
type AppStorageResult<A> =
| Readonly<{
kind: "accepted";
value: A;
}>
| Readonly<{
kind: "rejected";
code: AppStorageError["code"];
}>;

The wire-level outcome of a storage operation: either an accepted value or a rejection carrying an AppStorageError code.

Type Parameter
A

AppStorageWatchtype alias

Section titled “AppStorageWatch”
Signature
type AppStorageWatch = ReadonlyStore<ResolvedAppStorage> & Disposable & object;

A live subscription to one storage key’s resolved value: read the current value, subscribe to changes, and close when done watching.

Name Type Description
close() () => void Stop watching and release the underlying event subscription.

AppStoragetype alias

Section titled “AppStorage”
Signature
type AppStorage = Readonly<{
read: Promise<{
value: Json;
source: "none" | "member" | "team";
team: {
value: Json;
revision: number;
} | null;
member: {
value: Json;
revision: number;
} | null;
canWriteTeam: boolean;
}>;
write: Promise<{
revision: number;
}>;
reset: Promise<{
revision: number;
}>;
watch: Promise<AppStorageWatch>;
}>;

This App’s storage client, scoped to its declared member/team data.


AppStorageEventHandletype alias

Section titled “AppStorageEventHandle”
Signature
type AppStorageEventHandle = Disposable & object;

A live object capability backing one key’s change-event stream, adapted to Fetch so it can drive an EventSource.

Name Type Description
fetch() (request) => Promise<Response> Forward one EventSource request to the host’s event stream.
close() () => Promise<void> Release the change-event stream’s underlying object capability.

AppStorageWiretype alias

Section titled “AppStorageWire”
Signature
type AppStorageWire = object;

The raw wire contract this capability negotiates with the host, before client-side input validation and error unwrapping.

Signature
read(key): Promise<AppStorageResult<{
value: Json;
source: "none" | "member" | "team";
team: | {
value: Json;
revision: number;
}
| null;
member: | {
value: Json;
revision: number;
}
| null;
canWriteTeam: boolean;
}>>;

Read a key’s resolved value over the wire; resolves with an accepted value or a rejection code.

Parameter Type
key string

Promise<AppStorageResult<{ value: Json; source: "none" | "member" | "team"; team: | { value: Json; revision: number; } | null; member: | { value: Json; revision: number; } | null; canWriteTeam: boolean; }>>

Signature
write(input): Promise<AppStorageResult<{
revision: number;
}>>;

Write a key’s value over the wire; resolves with the accepted revision or a rejection code.

Parameter Type
input { key: string; scope: "member" | "team"; basedOn: number | null; value: Json; }
input.key string
input.scope "member" | "team"
input.basedOn number | null
input.value Json

Promise<AppStorageResult<{ revision: number; }>>

Signature
reset(input): Promise<AppStorageResult<{
revision: number;
}>>;

Reset a key’s value over the wire; resolves with the accepted revision or a rejection code.

Parameter Type
input { key: string; scope: "member" | "team"; basedOn: number | null; }
input.key string
input.scope "member" | "team"
input.basedOn number | null

Promise<AppStorageResult<{ revision: number; }>>

Signature
openEvents(key): Promise<AppStorageEventHandle>;

Open the change-event stream for a key, as a Fetch-adapted handle.

Parameter Type
key string

Promise<AppStorageEventHandle>

appStorageErrorCodesconstant

Section titled “appStorageErrorCodes”
Signature
const appStorageErrorCodes: readonly [
"invalid",
"undeclared_key",
"scope_not_declared",
"owner_required",
"too_large",
"quota_exceeded",
"conflict",
"unavailable",
];

Storage error codes the host and client agree on: invalid input, an undeclared key, a scope this App never declared, a member-only action tried without a member, a value or quota that is too large, a write conflict, or a transient host failure.


appStorageErrorCodeSchemaconstant

Section titled “appStorageErrorCodeSchema”
Signature
const appStorageErrorCodeSchema: Literals<
readonly [
"invalid",
"undeclared_key",
"scope_not_declared",
"owner_required",
"too_large",
"quota_exceeded",
"conflict",
"unavailable",
]
>;

Validates that a value is one of the known storage error codes.


resolvedAppStorageSchemaconstant

Section titled “resolvedAppStorageSchema”
Signature
const resolvedAppStorageSchema: Struct<{
value: Codec<Json, Json, never, never>;
source: Literals<readonly ["member", "team", "none"]>;
team: NullOr<
Struct<{
value: Codec<Json, Json, never, never>;
revision: Int;
}>
>;
member: NullOr<
Struct<{
value: Codec<Json, Json, never, never>;
revision: Int;
}>
>;
canWriteTeam: Boolean;
}>;

Validates the resolved shape of a storage key: its merged value, which layer it came from, the raw team and member layers it was merged from, and whether this App may write to the team layer.


appStorageWriteSchemaconstant

Section titled “appStorageWriteSchema”
Signature
const appStorageWriteSchema: Struct<{
key: String;
scope: Literals<readonly ["team", "member"]>;
basedOn: NullOr<Int>;
value: Codec<Json, Json, never, never>;
}>;

Validates a write request: the key, scope, value to store, and the expected revision of that layer (null requires the layer to be absent).


appStorageResetSchemaconstant

Section titled “appStorageResetSchema”
Signature
const appStorageResetSchema: Struct<{
key: String;
scope: Literals<readonly ["team", "member"]>;
basedOn: NullOr<Int>;
}>;

Validates a reset request: the key, scope, and the revision it’s conditioned on (null requires the layer to be absent).


appStorageRevisionSchemaconstant

Section titled “appStorageRevisionSchema”
Signature
const appStorageRevisionSchema: Struct<{
revision: Int;
}>;

Validates a bare revision number returned after a write or reset.


appStorageEventSchemaconstant

Section titled “appStorageEventSchema”
Signature
const appStorageEventSchema: Struct<{
appId: String;
key: String;
scope: Literals<readonly ["team", "member"]>;
revision: Int;
}>;

Validates a change-event payload pushed when a storage key’s value changes, naming the App, key, scope, and resulting revision.


appStorageReadResultSchemaconstant

Section titled “appStorageReadResultSchema”
Signature
const appStorageReadResultSchema: Union<
readonly [
Struct<{
kind: Literal<"accepted">;
value: Struct<{
value: Codec<Json, Json, never, never>;
source: Literals<readonly ["member", "team", "none"]>;
team: NullOr<
Struct<{
value: Codec<Json, Json, never, never>;
revision: Int;
}>
>;
member: NullOr<
Struct<{
value: Codec<Json, Json, never, never>;
revision: Int;
}>
>;
canWriteTeam: Boolean;
}>;
}>,
Struct<{
kind: Literal<"rejected">;
code: Literals<
readonly [
"invalid",
"undeclared_key",
"scope_not_declared",
"owner_required",
"too_large",
"quota_exceeded",
"conflict",
"unavailable",
]
>;
}>,
]
>;

Validates the wire result of a read: either an accepted resolved value or a rejection code.


appStorageMutationResultSchemaconstant

Section titled “appStorageMutationResultSchema”
Signature
const appStorageMutationResultSchema: Union<
readonly [
Struct<{
kind: Literal<"accepted">;
value: Struct<{
revision: Int;
}>;
}>,
Struct<{
kind: Literal<"rejected">;
code: Literals<
readonly [
"invalid",
"undeclared_key",
"scope_not_declared",
"owner_required",
"too_large",
"quota_exceeded",
"conflict",
"unavailable",
]
>;
}>,
]
>;

Validates the wire result of a write or reset: either an accepted revision or a rejection code.


appStorageBrokerReadResultSchemaconstant

Section titled “appStorageBrokerReadResultSchema”
Signature
const appStorageBrokerReadResultSchema: Union<readonly [Union<readonly [Struct<{
kind: Literal<"accepted">;
value: Struct<{
value: Codec<Json, Json, never, never>;
source: Literals<readonly ["member", "team", "none"]>;
team: NullOr<Struct<{
value: ...;
revision: ...;
}>>;
member: NullOr<Struct<{
value: ...;
revision: ...;
}>>;
canWriteTeam: Boolean;
}>;
}>, Struct<{
kind: Literal<"rejected">;
code: Literals<readonly ["invalid", "undeclared_key", "scope_not_declared", "owner_required", "too_large", "quota_exceeded", "conflict", "unavailable"]>;
}>]>, Struct<{
error: String;
}>]>;

The read result at a host broker, retaining its existing admission/failure reply.


appStorageBrokerMutationResultSchemaconstant

Section titled “appStorageBrokerMutationResultSchema”
Signature
const appStorageBrokerMutationResultSchema: Union<
readonly [
Union<
readonly [
Struct<{
kind: Literal<"accepted">;
value: Struct<{
revision: Int;
}>;
}>,
Struct<{
kind: Literal<"rejected">;
code: Literals<
readonly [
"invalid",
"undeclared_key",
"scope_not_declared",
"owner_required",
"too_large",
"quota_exceeded",
"conflict",
"unavailable",
]
>;
}>,
]
>,
Struct<{
error: String;
}>,
]
>;

The shared write/reset result at a host broker, including its existing failure reply.


appStorageconstant

Section titled “appStorage”
Signature
const appStorage: CapabilityContract<AppStorage>;

This App’s own declared data. The host seals App and member identities.


appStorageKeyNameSchemaconstant

Section titled “appStorageKeyNameSchema”
Signature
const appStorageKeyNameSchema: Schema.String;

Maintained grammar for one bounded key in an App’s private storage.