Asset Cache
Publishes named image, audio, and text assets as the asset kind.
Complete block reference (1 blocks)
TurboWarp custom extension · Composition API · v0.4.0
Named Data is a shared contract and provider registry for unsandboxed TurboWarp
extensions. One extension registers a provider for a namespace and kind; any other
extension resolves namespace + name + kind + scope and receives metadata and
a byte or stream body, without the payload ever passing through the registry.
Who uses it
Named Data has almost no blocks of its own. Its value is the registry that data-owning
extensions share. Separately bundled extensions find the same registry through the stable
key Symbol.for('@kubohiroya/turbowarp-named-data/registry'), so load order and
bundling do not split it.
Publishes named image, audio, and text assets as the asset kind.
Publishes JSON and YAML values as the structured kind, optionally with a schema identity.
Publishes HTML and Markdown documents as the document kind.
Publishes raw bytes as the binary kind for other extensions to stream.
Quick start
The registry is a startup-fixed feature that is off by default. The flag is read once when the bundle starts, so it must be set before the extension loads.
In the host page, or in the editor's browser console for a quick test, set:
globalThis.__TW_NAMED_DATA_FEATURE_FLAGS__ = {
NAMED_DATA_REGISTRY_MVP: true
};
In TurboWarp, choose Add Extension → Custom Extension, use this file, and enable Run extension without sandbox:
https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-named-data@0.4.0/dist/named-data.js
The single Boolean block confirms that the shared registry was installed.
if <named data registry available?> then
say [ready]
How it works
The registry keeps only provider registrations, keyed by (namespace, kind),
and the release callbacks of bodies that are currently open. Payload, storage, and caching
stay inside each provider.
A consumer passes a reference, a representation, and a target or project context to the registry. The registry selects the provider registered for the reference's namespace and kind, asks whether it can resolve the request, then calls stat or openBody. The consumer receives metadata and a borrowed body, and releases it when finished.
| Field | Values | Meaning |
|---|---|---|
namespace |
Lowercase, starts with a letter, up to 64 of a-z 0-9 . - |
Logical ownership domain. Providers of different kinds may share one namespace. |
name |
Provider-defined string | The value's name inside the namespace. |
kind |
structured, document, binary, asset |
Data type. Together with the namespace it selects the provider. |
scope |
target, project |
Target scope needs a target identity; project scope needs a project identity. One is never substituted for the other. |
schemaRef (optional) |
{id, version} |
Structured references only. A stable schema ID and a complete SemVer version, never a schema body. |
nativeRepresentation: how the provider stores itrepresentation: the form selected for this bodymediaType, optional byteLength and sha256- digestrevision: opaque; never parse or order itreplayable: whether the body can be read againUint8Array or ReadableStream<Uint8Array>release(reason) when finishedComposition API
Other packages import the side-effect-free ESM entrypoint. Importing it does not register a TurboWarp extension; it only exposes the contract, registry functions, and feature-flag declarations.
pnpm add --save-exact @kubohiroya/turbowarp-named-data@0.4.0
import {
installNamedDataRegistry,
type NamedDataProvider
} from '@kubohiroya/turbowarp-named-data/composition';
const registry = installNamedDataRegistry(runtime);
const provider: NamedDataProvider = {
namespace: 'com.example.notes',
kind: 'document',
canResolve: (ref, rep) => rep === 'markdown',
stat: (ref, rep, ctx) => ({ /* metadata */ }),
openBody: (ref, rep, ctx) => ({ /* metadata, body, release */ }),
release: () => {}
};
const registration = registry.registerProvider(provider);
A second provider for the same (namespace, kind) fails with
NAMED_DATA_PROVIDER_CONFLICT.
import {getNamedDataRegistry}
from '@kubohiroya/turbowarp-named-data/composition';
const registry = getNamedDataRegistry(runtime);
const opened = await registry?.openBody(
{namespace: 'com.example.notes', name: 'intro',
kind: 'document', scope: 'project'},
'markdown',
{project: projectIdentity}
);
try {
// read opened.body
} finally {
await opened?.release('complete');
}
getNamedDataRegistry returns undefined when no registry is installed.
| Export | Use it to… |
|---|---|
installNamedDataRegistry(runtime) | Install the shared registry, or return the compatible one already on the runtime. |
getNamedDataRegistry(runtime) | Retrieve the shared registry without installing one. |
bindNamedDataRegistryLifecycle(runtime, registry) | Clear session state on PROJECT_STOP_ALL. Returns an unbind function; bindings are reference-counted. |
NamedDataError, NAMED_DATA_ERROR_CODES | Throw and recognize stable NAMED_DATA_* codes. |
NAMED_DATA_KINDS, NAMED_DATA_SCOPES, NAMED_DATA_REPRESENTATIONS | Validate inputs against the canonical lists. |
FEATURE_FLAGS | Read the startup-fixed flags the bundle saw. |
Types are published from dist/types/composition.d.ts. The wire-safe reference
shape is also available as a JSON Schema.
Lifecycle and schema identity
clearSession().Registrations are session-scoped unless registered with
{lifetime: 'persistent'}. Release operations are idempotent, so a provider can
safely be released more than once.
Structured references may carry schemaRef: {id, version}, for example
{id: 'com.example.profile', version: '1.2.0'}. The provider must return the
exact same identity in its metadata. The registry transports the identity only; schema
documents, validators, and JSON values remain the provider's and consumer's responsibility.
Providers publish schema references only when the separate startup flag
NAMED_DATA_SCHEMA_REF is enabled (default off).
Reference
| I want to… | Use | Important behavior |
|---|---|---|
| Check from a script that the registry exists | named data registry available? | Shown only while NAMED_DATA_REGISTRY_MVP is on. |
| Turn the registry on | NAMED_DATA_REGISTRY_MVP: true | Read once at bundle startup; default off. |
| Publish schema identities | NAMED_DATA_SCHEMA_REF: true | Opt-in for providers; default off. |
| Register or read data | Composition API | Extension-to-extension only; there are no value blocks for bodies. |
| Code | Meaning |
|---|---|
NAMED_DATA_INVALID_REF | The reference or provider descriptor is malformed. |
NAMED_DATA_INVALID_REGISTRY | The shared symbol slot holds an incompatible object. It is never overwritten. |
NAMED_DATA_PROVIDER_CONFLICT | A provider is already registered for this (namespace, kind). |
NAMED_DATA_PROVIDER_NOT_FOUND | No provider is registered for this namespace. |
NAMED_DATA_KIND_MISMATCH | The namespace has providers, but none for this kind. |
NAMED_DATA_NOT_FOUND | The provider has no value under this name. |
NAMED_DATA_SCOPE_MISMATCH | The context lacks the target or project identity the scope requires. |
NAMED_DATA_SCHEMA_NOT_FOUND / …_VERSION_MISMATCH / …_UNRESOLVED | Schema identity is missing, differs, or cannot be resolved. |
NAMED_DATA_REPRESENTATION_UNSUPPORTED | The provider cannot produce the requested representation. |
NAMED_DATA_INVALID_METADATA | The provider returned metadata or a body that fails validation. |
NAMED_DATA_BODY_TOO_LARGE | The body exceeds a provider or consumer limit. |
NAMED_DATA_ABORTED | The context's AbortSignal fired. |
NAMED_DATA_PROVIDER_RELEASED | The provider was released before or during the request. |
Troubleshooting
NAMED_DATA_REGISTRY_MVP was not true when the bundle started.
Set globalThis.__TW_NAMED_DATA_FEATURE_FLAGS__ first, then reload the editor
and load the extension again. Changing the flag after loading has no effect.
installNamedDataRegistry or getNamedDataRegistry
on the same TurboWarp runtime. A private registry created inside one extension is not
shared. If the symbol slot already holds an incompatible object, the call fails with
NAMED_DATA_INVALID_REGISTRY.
context.target and project scope requires
context.project. The registry reports NAMED_DATA_SCOPE_MISMATCH
instead of substituting one for the other.
PROJECT_STOP_ALL. Register long-lived
providers with {lifetime: 'persistent'} and implement
clearSession() to drop only per-run state.
All 1 blocks are documented below, including compatibility blocks and blocks available through optional features. Select a block to read its behavior, arguments, default values, and menu choices. Each block has a permanent link.
named data registry available?Reports whether the startup-fixed Named Data registry feature is enabled.
Block type: BOOLEAN. Opcode: isRegistryAvailable. Permanent link
This block has no arguments.