Skip to main content
A JS or TS library shares business logic across components in the same instance. Put its main public API in @default for a short, stable caller contract; use ordinary elements to organize additional capabilities. Only active libraries appear in the runtime. The library segment is the component name, not its category. Names and keys are case-sensitive. Use the lib namespace for all library calls.

Start with an empty default

Every new CODE_JS_LIB or CODE_TS_LIB contains a permanent @default, including creation requests that provide other elements. Its generated source contains only a /* ... */ documentation comment. It exports no values, calls no platform APIs, forwards no other elements and includes no executable sample code. The starter explains @public, @private, @access, @alias and @protected. These annotations are documentation, not compiler flags. Public visibility depends on actual export statements. Studio displays the default with a code icon and the lowercase italic label default. VS Code uses the same lowercase label and a code icon. The persisted key and CLI/VS Code filename remain @default, for example -1_@default.ts. Its source and description are editable; renaming, deleting or replacing this element is rejected by the API and blocked in Studio. Deleting the whole library remains a separate resource operation.

Build and inspect a typed Library

Create a pricing rule, see expected Monaco completion and test its consuming Component.

Define the public API

Add your own source to the default element. This TypeScript example exports the input type and one function; normalize() and allowedDomains remain private local bindings.
A consuming TypeScript component gets the same public types as Monaco:
Private helpers are called locally as normalize(value). They are absent from runtime lib.*, completion, declaration lookup and definition navigation. Neither lib.Customers.normalize nor lib.Customers['@default'].normalize is a public method. JavaScript uses the same named-export rule and can document types with JSDoc:
Use export function, export const, export class, exported TypeScript declarations, or a local clause such as export { display as displayName }. A technical @default element does not mean an ES module export default: ES default exports, module imports, external re-exports and source exports.* / module.exports are rejected. Public names in @default, including type names, cannot collide with any element key in the same library.

Organize ordinary elements

Keep implementation capabilities in ordinary elements when callers benefit from a qualified name:
If you want a short entry point, explicitly author it in the default. This is user-written code; the platform never generates forwarding exports:
Each element has its own lexical scope. Another element or library is reached through lib.*; its local unexported bindings are inaccessible. Reuse across libraries also uses ordinary runtime calls, for example lib.Formatting.displayName(value), rather than ES imports.

Default aliases and TypeScript

lib.Orders.calculateTotal and lib.Orders['@default'].calculateTotal are the same function, not two wrappers. The bracket form is useful when inspecting element identity; prefer the short form in application source. TypeScript types use the canonical namespace, for example lib.Customers.EmailInput. The bracket alias types runtime values; a type-only declaration has no runtime property. Use the short namespace in source and type annotations. Completion and definition navigation expose the same public symbols as runtime calls. An element containing only export interface, export type or export {}; is valid. It exposes no executable members and leaves no module marker in the generated runtime initializer.

Initialization and private state

Element order controls editor sorting. Dependencies initialize when first used, regardless of where their element appears in the tree. Each element initializes once per execution; circular initialization fails explicitly. Prefer cross-library calls inside exported functions and keep I/O out of initialization. Exported primitive values are captured during initialization. For mutable state, expose functions over a private local variable:
Exporting an object exposes its properties. TypeScript private is a compile-time restriction; use unexported bindings or closures for runtime-private state. Library state belongs to the current execution, not durable instance storage.

Upgrade existing libraries

Upgraded Libraries use explicit named exports and keep ordinary element names and qualified caller paths. The platform preserves the source used by historical executions. An ordinary DEFAULT element remains ordinary; it does not become the permanent @default. Review current diagnostics and refresh canonical source in CLI or VS Code workspaces after an upgrade. An outdated manifest cannot remove the permanent default. Source that cannot execute requires correction before reuse; historical source is not silently rewritten into a different business implementation. For a complete authoring walkthrough, including the expected Monaco suggestions, use Build a typed library API.

Choose a library boundary

Use the default for a small, stable business API that callers can recognize. Use ordinary elements for additional named capabilities. Keep validation or normalization helpers local unless they are intentionally part of your public contract. Document public functions with JSDoc, await asynchronous calls, and test both the exported function and a consuming component.
Last modified on November 11, 2026