/** * Shared binding helpers for auto-materialized members (functions + views). * * The worker ROUTE URL a member is served at — `//` — is * decoupled from the member's GRAPH layout (`//{functions,views}/`, * a fixed kernel convention). `folderSlug` names only the URL segment. */ import type { FunctionBinding } from '@astrale-os/kernel-api/routed' /** Join a worker-relative mount path onto the serving url (single slash). */ export function joinWorkerPath(url: string, mount: string): string { const base = url.replace(/\/+$/, '') return `${base}/${mount.replace(/^\/+/, '')}` } /** * Resolve a member's effective binding against the serving `url`. An explicit * `override.remoteUrl` wins; otherwise defaults to `//`. * Same trailing-slash discipline as {@link joinWorkerPath} — a `url` ending in * `/` must not produce `//` (the kernel pins `iss` by exact string). */ export function resolveBinding( override: FunctionBinding | undefined, url: string, folderSlug: string, slug: string, ): FunctionBinding { const base = url.replace(/\/+$/, '') if (override) { return { ...override, remoteUrl: override.remoteUrl ?? `${base}/${folderSlug}/${slug}`, } } return { remoteUrl: `${base}/${folderSlug}/${slug}` } }