Adds a per-subsystem measurement of reactive.js, made by minifying it repeatedly with one subsystem removed rather than counting source bytes. This corrects the earlier audit on both figures and on the conclusion drawn from them. Component controllers are 23,722 bytes minified / 6,660 gzipped -- 30.6% of transfer, not the "about 18%" previously claimed -- and splitting them out saves 6.6 kB gzipped on a typical page, not "3-4 kB". Measured against the example app, / and /login use none of the ten controllers and /layout uses one, so most pages download and parse the lot for nothing. The larger finding is that the runtime is not where the weight is. One page parses 490,212 decoded bytes across 11 generated client modules while transferring 21,026, and the largest module is 89.8% duplicated lines: the state-restore prologue appears 162 times because client-codegen.ts inlines the sync into every peer alias of every client function. Gzip hides it on the wire, but parse cost follows decoded bytes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import type { Context } from "@wrnexus/core";
|
|
import { exportSubjectContext, importSubjectContext, type SubjectContext } from "@wrnexus/rpc";
|
|
import type { AddOptions, Job, Queue } from "./index.ts";
|
|
|
|
const QUEUE_AUDIENCE = "wrnexus-queue";
|
|
interface SubjectEnvelope<T> {
|
|
payload: T;
|
|
identity?: string;
|
|
}
|
|
|
|
export interface SubjectJob<T> extends Omit<Job<SubjectEnvelope<T>>, "data"> {
|
|
data: T;
|
|
subject?: SubjectContext;
|
|
}
|
|
|
|
export interface SubjectQueue {
|
|
add<T>(
|
|
ctx: Context,
|
|
name: string,
|
|
data: T,
|
|
options?: AddOptions,
|
|
): Promise<Job<SubjectEnvelope<T>>>;
|
|
process<T>(
|
|
name: string,
|
|
handler: (job: SubjectJob<T>, context: { signal: AbortSignal }) => void | Promise<void>,
|
|
): void;
|
|
}
|
|
|
|
/** Queue adapter that persists a signed end-user context alongside job data. */
|
|
export function subjectQueue(queue: Queue): SubjectQueue {
|
|
return {
|
|
async add(ctx, name, data, options) {
|
|
const identity = await exportSubjectContext(ctx, QUEUE_AUDIENCE);
|
|
return queue.add(name, { payload: data, ...(identity ? { identity } : {}) }, options);
|
|
},
|
|
process(name, handler) {
|
|
queue.process<SubjectEnvelope<unknown>>(name, async (job, context) => {
|
|
const envelope = job.data;
|
|
if (!envelope || typeof envelope !== "object" || !("payload" in envelope)) return;
|
|
let subject: SubjectContext | undefined;
|
|
if (envelope.identity !== undefined) {
|
|
if (typeof envelope.identity !== "string") return;
|
|
try {
|
|
subject = await importSubjectContext(envelope.identity, QUEUE_AUDIENCE);
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
await handler(
|
|
{ ...job, data: envelope.payload as never, ...(subject ? { subject } : {}) },
|
|
context,
|
|
);
|
|
});
|
|
},
|
|
};
|
|
}
|