Skip to main content
LTHN Documentation
Back to website
Components

Core TS

The TypeScript implementation of Core on Deno — a sandboxed sidecar, a browser runtime, and a standalone CLI.

doc/components/ts.md

Core TS is the TypeScript implementation of the Core framework, running on Deno. It plays three roles in the polyglot stack: a sandboxed CoreDeno sidecar managed by Core Go, the browser runtime built from Web Components and WASM interop, and a standalone TypeScript CLI for tools that do not need Go. It shares the same lifecycle, IPC patterns, and i18n format as the Go and PHP implementations.

Quick start

Core TS runs on Deno, so there is no separate install or build step for TypeScript. Permissions are deny by default and granted explicitly.

# capability-based: deny by default, grant explicitly
deno run --allow-read=./src app.ts

For local development:

git clone forge.lthn.sh/core/ts
deno task dev      # dev server with hot module replacement
deno task build    # production bundle

The runtime is React and Lit Web Components, ES modules throughout, bundled with esbuild.

Three roles

Core TS is one framework wearing three hats.

  • CoreDeno sidecar. A module loader and dev toolchain managed by Core Go as a child process. Go spawns Deno at startup, restarts it on a crash, and stops it on shutdown.
  • Browser runtime. The client-side application shell and component runtime — Web Components plus WASM interop, shared between the desktop shell and the browser.
  • Standalone CLI. TypeScript-native commands and tools that run on Deno alone.

Deno, not Node

Core TS uses Deno rather than Node deliberately. Deno gives native TypeScript with no build step, URL imports and import maps instead of node_modules, and a single binary.

The decisive property is the permission model. Deno denies file, network, and process access by default and grants it explicitly per run. That permission model is the I/O fortress: a module asking for access outside its declared paths is denied at the runtime level, with no wrapper required.

Property Node Deno
Permissions Everything allowed Deny by default
Module loading npm, node_modules URL imports, import maps
TypeScript Needs build step Native
Single binary No Yes

Modules and permissions

A module declares its capabilities in a .core/view.yaml manifest. CoreDeno reads the manifest and translates it into Deno flags before the module runs.

# .core/view.yaml
module: photo-gallery
entry: ./src/photo-gallery.ts
permissions:
  read: ["./photos/"]
  net: []
  run: []

Each module runs in its own Deno isolate. Cross-module communication goes through the IPC layer rather than direct imports, and local imports that resolve outside the entry-point directory are rejected.

Web Components

The browser runtime registers custom elements and manages their lifecycle. Use Lit for components rather than React class components.

import { html, css, LitElement } from "https://lit.dev/lit-element.js";

class MyElement extends LitElement {
  static styles = css`
    :host { display: block; }
  `;

  render() {
    return html`<div>Hello, Core TS</div>`;
  }
}

customElements.define('my-element', MyElement);

Imports use URLs or import maps, not npm.