Skip to content

The global registry ​

The build-time view of the whole application.

package @smitejs/core

The global registry is a single Map living on globalThis.globalRegistry that holds every node and edge created in collect mode. It is the build-time window into an application: tooling reads it after the app module has run to discover what was declared.

Collect mode only ​

Registration is gated by the compile-time constant ALLOW_GLOBAL_REGISTRY. When esbuild defines it as "true", defineDescriptor and relate insert their results into the registry. When it folds to false (the production default), the registry code becomes unreachable and is dropped from the bundle. This is why executors never import the registry.

Reading the registry ​

  • lookup(key) — one descriptor by composite key.
  • lookupAll(kind) — every descriptor of a given kind.
  • relationships() — every relationship edge.
  • clear() — empty the registry (used between test cases and compilations).
ts
const app = createApp("api");
const route = defineDescriptor("http.route", "GET /users/:id", {
  path: "/users/:id",
  method: "GET",
});
relate(app, "http.route", route);

const apps = lookupAll("app");
const routes = lookupAll("http.route");
const rels = relationships();
clear();
ts
1
route
1
0

Collisions ​

Keys are unique. Registering the same key twice throws, which catches duplicate route declarations and duplicate app junctions early rather than silently overwriting.

Next ​

  • The junction — the app node that roots the graph
  • Tree-shaking — what survives when the registry is folded away

Released under the MIT License.

/ search•[ ] prev/next•j/k scroll•h home•t theme•guide/internals/registry