server-library

tcmts.design.server-library · #s356gx4b · md file

#tcm/server as a library

Built (all four units below have landed: #tcm/server is retired, and apps mount the server library tcm ships). Kept as the record of why it's this way; "Today" is how it was before. The API apps write their server code against (table, transaction, enqueue, every, sessions, cookies, the request) becomes a tcm library, server: versioned, released, read and added like any other. The runtime that keeps the data, runs the jobs and answers the requests stays in tcm, behind a host interface. It uses the mechanism React's library uses: the manifest's host protocol version and roles.

Today

What a library gives

The split

Three layers, of which only the middle one is new:

Layer Where What
host tcm: #tcm/host, an external module as #tcm/server is now what needs the process: the call context, a SQLite handle per data file, the store's lock and transactions, the job queue, its worker and the schedules, the wire codec and schema checker. Self-contained source (createServerHost), written to .tcm/cache/tcm-host.js
API the server library (npm: false), in tcm's codebase at tcmts.server what apps call: table<T>, transaction, enqueue, enqueueAfter, every, runJobs, request, cookie, setCookie, deleteCookie, session, setSession, clearSession, revokeSessions, rateLimit, HttpError, withRequest: typed, documented, each built on the host
app the app's codebase imports the API from its mount: #codebase/<root>/lib/server (tcm's own apps: #codebase/tcmts/server)

The host interface, version 1

What #tcm/host exports, for the library (and anyone writing one):

The protocol version

The host and the API meet at that interface, which will change. Each side says which version it speaks:

Finding tables and schedules: by identity, not by import path

The library can be mounted anywhere (app.lib.server, vendor.server2), so tcm can't recognise its table by the path it's imported from. It recognises the definition itself:

transaction and enqueue need no role: nothing in the analysis or build treats them specially.

Three alternatives, for the record:

Placement

Getting it, and what happens to #tcm/server

How to get there

Each a unit of its own, landed apart:

  1. This page.
  2. Roles table and every: tableOf, schedules and the build find them by hash, through rolesIn, as well as by #tcm/server while it lasts. Tested with a library of a test's own whose table wraps #tcm/server's. No change for apps.
  3. The host and the library: createServerHost as #tcm/host; tcmts.server (the deploy files there now move to tcmts.deploy) holding the API on it, with host: 1 and its roles; the runtime knows deliberate errors by their mark. #tcm/server is rebuilt on the host too, so apps on either share one host while both exist (the API is in two places for this one unit). Released as server@0.1.0 on main once landed.
  4. Moving onto it: tcm ships server beside react (R3's mechanism); the forge, the hub, the examples and the fixtures use it; #tcm/server and its generated module are retired, and docs (server-api, server-reference, data, jobs, libraries, limitations, files) say how to get it.

Announced later, by hand, as @tcm.codes/server.