D19 as amended 2026-10-24: nothing that shipped in 26.9.0-beta.2 is removed. Every symbol D19 had listed for removal or review is in that release, so this change only adds exports and marks scope. - Export `AppOptions`, `ExplainNode`, `WsRequest` and `WsSocket`. Each appears in a public signature (`createApp`, `Explain.chain`, `app.upgrade`) but could not be imported. `AppOptions` is the former inline options type of `createApp`, moved verbatim into an interface. - Add `RequestHeaders`. `Headers` shadows the Fetch global wherever it is imported, so it stays only as a `@deprecated` alias of the same type. - Mark the mesh exports and `MeshConfig` `@experimental`. They stay exported and unchanged, but sit outside the freeze, like the `experimental: true` flag the mesh already needs. - The seven review candidates (`withConsoleFallback`, `UNMATCHED_ROUTE`, `HTTP_ERROR`, `VALIDATION_ERROR`, `TransportMismatchError`, `isAsyncIterable`, `buildOpenApi`) stay as they are. CHANGELOG: `### Added` for the types, `### Changed` for the mesh tag, and a new `### Deprecated` for `Headers`. No `### Breaking`. test/types/public-surface.test.ts fails to compile if any of the new names stops being exported. `deno publish --dry-run` passes. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import type { Link } from './link';
|
|
import type { RequestEnvelope } from './protocol';
|
|
import type { ResponseShape } from '../pipeline';
|
|
|
|
/** Local proxy for a remote scope: runs the RPC and returns its token→value binding. */
|
|
export interface RemoteScopeNode {
|
|
name: string;
|
|
run: (ctx: any) => Promise<Record<string, unknown>>;
|
|
}
|
|
/** Local proxy for a remote route: forwards the request envelope over the link. */
|
|
export interface RemoteRoute {
|
|
method: string;
|
|
pattern: string;
|
|
handler: (req: RequestEnvelope) => Promise<ResponseShape>;
|
|
}
|
|
|
|
/**
|
|
* Extract a {@link RequestEnvelope} from a local request context for transmission over the mesh.
|
|
*
|
|
* `url` and `correlation` are read off `ctx.req`, the handler argument the pipeline seeds the
|
|
* context with — so a request that crosses to a teapot arrives carrying the id it already had,
|
|
* and its events on the far side join the same trace instead of starting a new one.
|
|
*
|
|
* @experimental Part of the mesh, which needs `createApp({ experimental: true })`: outside the
|
|
* API freeze, so it may change in a minor release.
|
|
*/
|
|
export function envelopeFrom(ctx: any): RequestEnvelope {
|
|
const req = ctx?.req;
|
|
const correlation = { requestId: req?.requestId, traceId: req?.traceId };
|
|
|
|
return {
|
|
method: req?.method ?? ctx?.method ?? 'GET',
|
|
params: ctx?.params ?? {},
|
|
query: ctx?.query ?? {},
|
|
body: ctx?.body,
|
|
headers: ctx?.headers ?? {},
|
|
url: req?.url,
|
|
// omitted rather than sent empty: an envelope with no identity should look like one
|
|
...(correlation.requestId || correlation.traceId ? { correlation } : {}),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Turn a link's manifest into local proxy nodes: lazy request-scope steps, and routes.
|
|
*
|
|
* @experimental Part of the mesh, which needs `createApp({ experimental: true })`: outside the
|
|
* API freeze, so it may change in a minor release.
|
|
*/
|
|
export function buildRemote(link: Link): { steps: RemoteScopeNode[]; routes: RemoteRoute[] } {
|
|
const steps: RemoteScopeNode[] = link.manifest.steps.map((token) => ({
|
|
name: token,
|
|
run: async (ctx: any) => ({ [token]: await link.rpc('scope', token, envelopeFrom(ctx)) }),
|
|
}));
|
|
|
|
const routes: RemoteRoute[] = link.manifest.routes.map((route) => ({
|
|
method: route.method,
|
|
pattern: route.pattern,
|
|
handler: async (req: RequestEnvelope) => (await link.rpc('route', route.pattern, req)) as ResponseShape,
|
|
}));
|
|
|
|
return { steps, routes };
|
|
}
|