A capability is a tag: an NSID plus the TypeScript type of its values. Capability.make declares a multi
capability, which any number of modules contribute to. Capability.makeSingleton declares one with exactly one
provider.
A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.
Uint8Array;
6
};
7
8
// A multi capability: any number of modules may contribute one.
Enables basic storage and retrieval of dates and times.
Date>()(
15
'com.example.plugin.export.capability.clock',
16
);
17
A module contributes by returning Capability.contribute(tag, value) from its body, and lists the tag in
provides. A module requests with yield* on the tag, or with Capability.getAll for every contribution to a
multi capability, and lists what it cannot run without in requires.
Helper to define an eager module body with the same spec-carrying shape as
lazyModule
— for bodies that are plain values (translations, schema) or too small
to justify a chunk, so plugin definitions stay a uniform chain of spec-carrying modules.
@param ― name The module name — used to auto-compute module IDs.
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
The console module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
A global console instance configured to write to process.stdout and
process.stderr. The global console can be used without importing the node:console module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O for
more information.
Example using the global console:
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(newError('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console class:
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(newError('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
Prints to stdout with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()).
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map((
exporter: Exporter
exporter) =>
exporter: Exporter
exporter.
format: string
format),
14
);
15
}),
16
);
17
The capability manager holds every contribution. It is the Capability.Service in a module’s Effect context, and the
plugin manager owns it.
Helper to define an eager module body with the same spec-carrying shape as
lazyModule
— for bodies that are plain values (translations, schema) or too small
to justify a chunk, so plugin definitions stay a uniform chain of spec-carrying modules.
@param ― name The module name — used to auto-compute module IDs.
@param ― spec The requires/provides declaration.
@param ― activate The module body.
inlineModule(
9
'GraphReady',
10
{
provides: readonly []
provides: [],
activatesOn?: Events | undefined
Activates when this runtime event fires instead of during the dependency pass.
activatesOn:
import ActivationEvents
ActivationEvents.
const Startup: ActivationEvent
Fired when the app is started.
Defined in core; see
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
The graph builder instance. Its graph is the reactive node tree; the builder also carries the
urlKey declarations and node→extension provenance that URL resolution (@dxos/app-graph's
path-resolution.ts) reads and reverse-maps — neither derivable from graph alone.
@category ― Capability
AppGraph);
14
// An atom of every contribution, for reactive code.
The console module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
A global console instance configured to write to process.stdout and
process.stderr. The global console can be used without importing the node:console module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O for
more information.
Example using the global console:
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(newError('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console class:
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(newError('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
Prints to stdout with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()).
One plugin extends another by contributing to a capability the other reads. Stash adds itself to the Space
plugin’s create menu this way: the Space plugin declares SpaceCapabilities.CreateObjectEntry and lists every
contribution in its menu, and Stash contributes one entry.
Helper to define a capability module with explicit typing.
Wraps the default export function to provide better type inference and make the pattern explicit.
This helper provides explicit typing for the module activation function,
making it clear that the function should:
Access declared requires via yield* (or the ambient Capability.Service/Plugin.Service)
Persisted Type.Type entities carry typename in EntityMeta.key (the
canonical registry-provenance field); unnamed drafts fall back to the
entity's object id so the helper always returns a string. Any dxn: or
echo:/ prefix is stripped — typename is a bare identifier, not a URI.
@performance ― O(1) meta read with jsonSchema and id fallbacks.
The created object's parent; absent files at the space root of db.
target },
23
{
InvokeOptions.spaceId?: SpaceId | undefined
Space ID to provide database context for the handler.
spaceId:
options: {
db: Database;
target?: Unknown;
targetNodeId?: string;
}
options.
db: Database
db.
Database.spaceId: SpaceId
spaceId },
24
),
25
}),
26
),
27
);
28
Contributions change after startup, when a module activates late or a person turns a plugin on or off.
Capability.contributions and Capability.atom stay current; a value read once with getAll does not.
When a module deactivates, its contributions are removed and its finalizers run.
A singleton capability with two providers is an error. Use a multi capability for anything more than one plugin
might contribute.
The capability manager does not check a value against anything but its TypeScript type. Two plugins that build
against different versions of a capability’s type are not caught at runtime.
Capabilities are in-process. They do not cross from the app to a worker or another device.