orpc-fn 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -8
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/create-fn.d.ts +3 -3
- package/dist/create-fn.d.ts.map +1 -1
- package/dist/create-fn.js +2 -7
- package/dist/create-fn.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/live/fn-live.d.ts +9 -5
- package/dist/live/fn-live.d.ts.map +1 -1
- package/dist/live/fn-live.js.map +1 -1
- package/dist/live/pub-sub.d.ts +5 -1
- package/dist/live/pub-sub.d.ts.map +1 -1
- package/dist/live/pub-sub.js +29 -14
- package/dist/live/pub-sub.js.map +1 -1
- package/dist/mcp/core.d.ts +41 -0
- package/dist/mcp/core.d.ts.map +1 -0
- package/dist/mcp/core.js +61 -0
- package/dist/mcp/core.js.map +1 -0
- package/dist/mcp/sdk.d.ts +8 -16
- package/dist/mcp/sdk.d.ts.map +1 -1
- package/dist/mcp/sdk.js +10 -78
- package/dist/mcp/sdk.js.map +1 -1
- package/dist/mcp/server.d.ts +11 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +13 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/otel.d.ts +5 -0
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +7 -0
- package/dist/otel.js.map +1 -1
- package/dist/router.d.ts +8 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +13 -0
- package/dist/router.js.map +1 -1
- package/dist/types.d.ts +16 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +15 -3
- package/src/cli.ts +68 -0
- package/src/create-fn.ts +5 -10
- package/src/index.ts +2 -1
- package/src/live/fn-live.ts +9 -5
- package/src/live/pub-sub.ts +38 -19
- package/src/mcp/core.ts +102 -0
- package/src/mcp/sdk.ts +20 -102
- package/src/mcp/server.ts +35 -0
- package/src/otel.ts +8 -0
- package/src/router.ts +19 -0
- package/src/types.ts +24 -42
package/dist/live/fn-live.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn-live.js","sourceRoot":"","sources":["../../src/live/fn-live.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,SAAS,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAA;AAoB1D,wEAAwE;AACxE,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAEjC,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAchD,MAAM,UAAU,WAAW,CAC1B,KAAc,EACd,IAAW;IAEX,OAAO,EAAE,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AAClD,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,iBAAiB,IAAI,KAAK,CACzE,CAAA;AACF,CAAC;AAqND;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CACxC,GAAY,EACZ,QAAgB,EAChB,MAA+B;AAC/B,kEAAkE;AAClE,UAAU,GAAgC,CAAC,KAAK,EAAE,EAAE,CACnD,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;IAEjD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE;YAC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IAAI,CAAC,UAAU;wBAC3B,GAAG,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS;4BAClC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE;4BACrC,CAAC,CAAC,EAAE,CAAC;wBACN,KAAK;wBACL,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBACrC,CAAC,CAAA;gBACH,CAAC;wBAAS,CAAC;oBACV,YAAY,CAAC,KAAK,EAAE,CAAA;gBACrB,CAAC;YACF,CAAC;SACD,CAAC,CAAA;QAEF,OAAO;YACN,SAAS;YACT,SAAS;YACT,OAAO;YACP,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;YAC9D,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;SACpD,CAAA;IACF,CAAC,CAAA;AACF,CAAC","sourcesContent":["import type { AnySchema, ErrorMap, Schema } from '@orpc/contract'\nimport { type AnyProcedure, ORPCError } from '@orpc/server'\nimport type { ZodType, z } from 'zod'\nimport { RAW_INPUT } from '../timing.js'\nimport { LIVE_GAP, positiveInteger } from './lifecycle.js'\nimport type { FnLogger } from '../logger.js'\nimport { errorMessageOf, type SpanLike } from '../otel.js'\nimport type {\n\tFnContext,\n\tFnDefinition,\n\tFnProcedure,\n\tFnRouteOptions,\n\tHandlerParams,\n\tMaybePromise,\n\tProcedureKey\n} from '../types.js'\nimport type {\n\tAuthFn,\n\tChannel,\n\tChannelDefinition,\n\tChannelOptions,\n\tChannelQueueOptions,\n\tObjectSchema,\n\tPublisherConfig\n} from './pub-sub.js'\n\n/** Marks a coalesce window that ended before the next event arrived. */\nconst TIMEOUT = Symbol('timeout')\n\nconst fnLivePatchMarker = Symbol('fnLive.patch')\n\n/**\n * Transformer result that splits the internal accumulator from the wire\n * payload: `state` becomes the `previous` snapshot for later events while only\n * `emit` is sent to the subscriber. Lets high-frequency streams avoid\n * re-serializing the full snapshot per event.\n */\nexport type FnLivePatch<TOutput, TEmit> = {\n\t[fnLivePatchMarker]: true\n\tstate: TOutput\n\temit: TEmit\n}\n\nexport function fnLivePatch<TOutput, TEmit>(\n\tstate: TOutput,\n\temit: TEmit\n): FnLivePatch<TOutput, TEmit> {\n\treturn { [fnLivePatchMarker]: true, state, emit }\n}\n\nfunction isFnLivePatch(value: unknown): value is FnLivePatch<unknown, unknown> {\n\treturn (\n\t\ttypeof value === 'object' && value !== null && fnLivePatchMarker in value\n\t)\n}\n\nexport type FnLiveConfig<\n\tTDef extends FnDefinition,\n\tTInput,\n\tTEventSchema extends ZodType,\n\tTOutput,\n\tTKey extends ProcedureKey<TDef>,\n\tTEmit = never,\n\tTErrors extends ErrorMap = Record<never, never>\n> = Omit<PublisherConfig, 'name'> &\n\tChannelQueueOptions & {\n\t\t/** Subscribe route name; default `${name}.live`. */\n\t\tname?: string\n\t\t/** Validates parsed reducer state without reapplying an output transform. Required with a transformer. */\n\t\tstateSchema?: Schema<TOutput, TOutput>\n\t\t/** Validates patch payloads. Required when a transformer returns fnLivePatch. */\n\t\temitSchema?: Schema<TEmit, TEmit>\n\t\t/** Optional access check before each update; idle streams keep their initial authorization. */\n\t\treauthorize?: AuthFn<TInput, FnContext<TDef, TKey>>\n\t\teventSchema: TEventSchema\n\t\tchannel: ChannelDefinition<\n\t\t\tTInput,\n\t\t\tz.output<TEventSchema>,\n\t\t\tFnContext<TDef, TKey>\n\t\t>\n\t\t/** Fold an event into the snapshot; without it every event re-runs the handler. */\n\t\ttransformerFn?: FnLiveConfigTransformer<\n\t\t\tTDef,\n\t\t\tTInput,\n\t\t\tTEventSchema,\n\t\t\tTOutput,\n\t\t\tTKey,\n\t\t\tTEmit,\n\t\t\tTErrors\n\t\t>\n\t\t/** Return false to skip an event. */\n\t\tshouldUpdate?: (\n\t\t\tparams: HandlerParams<TDef, TInput, TKey, TErrors> & {\n\t\t\t\tevent: z.output<TEventSchema>\n\t\t\t\tprevious: TOutput\n\t\t\t}\n\t\t) => MaybePromise<boolean>\n\t\tauthFn?: AuthFn<TInput, FnContext<TDef, TKey>>\n\t\t/** Log publish failures instead of throwing them into the publishing route. */\n\t\tsafePublish?: boolean\n\t\t/** Batch events arriving within this window into one snapshot update. */\n\t\tcoalesceMs?: number\n\t\t/** Maximum events collected in one coalescing batch (default 1000). */\n\t\tmaxBatchSize?: number\n\t\t/**\n\t\t * When a slow subscriber's queue overflows (drop-oldest), this marker is\n\t\t * enqueued INSTEAD of the dropped event so the client resyncs. Return\n\t\t * `null` to skip.\n\t\t */\n\t\toverflowMarker?: (input: TInput) => z.output<TEventSchema> | null\n\t\tsummary?: string\n\t\tdescription?: string\n\t} & (\n\t\t| { transformerFn?: undefined }\n\t\t| {\n\t\t\t\ttransformerFn: FnLiveConfigTransformer<\n\t\t\t\t\tTDef,\n\t\t\t\t\tTInput,\n\t\t\t\t\tTEventSchema,\n\t\t\t\t\tTOutput,\n\t\t\t\t\tTKey,\n\t\t\t\t\tTEmit,\n\t\t\t\t\tTErrors\n\t\t\t\t>\n\t\t\t\tstateSchema: Schema<TOutput, TOutput>\n\t\t }\n\t) &\n\t([TEmit] extends [never] ? object : { emitSchema: Schema<TEmit, TEmit> })\n\ntype FnLiveConfigTransformer<\n\tTDef extends FnDefinition,\n\tTInput,\n\tTEventSchema extends ZodType,\n\tTOutput,\n\tTKey extends ProcedureKey<TDef>,\n\tTEmit,\n\tTErrors extends ErrorMap\n> = (\n\tparams: HandlerParams<TDef, TInput, TKey, TErrors> & {\n\t\tevent: z.output<TEventSchema>\n\t\tprevious: TOutput\n\t\trerun: () => Promise<TOutput>\n\t}\n) => MaybePromise<TOutput | FnLivePatch<TOutput, TEmit> | undefined>\n\nexport type FnLiveReturn<\n\tTDef extends FnDefinition,\n\tTKey extends ProcedureKey<TDef>,\n\tTInput extends ObjectSchema,\n\tTOutputSchema extends Schema<unknown, unknown>,\n\tTOutput,\n\tTEventSchema extends ZodType,\n\tTEmit = never,\n\tTErrors extends ErrorMap = Record<never, never>\n> = {\n\tprocedure: FnProcedure<TDef, TKey, TInput, TOutputSchema, TErrors>\n\tsubscribe: FnProcedure<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tSchema<AsyncGenerator<TOutput | TEmit>, AsyncGenerator<TOutput | TEmit>>,\n\t\tTErrors\n\t>\n\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: z.output<TInput>\n\t\tcontext: FnContext<TDef, TKey>\n\t}) => string\n\tgetPublishChannelName: (event: z.output<TEventSchema>) => string\n\t/** @deprecated Prefer the separate required-input resolver methods. */\n\tgetChannelName: (\n\t\tparams: Partial<z.output<TInput>> | Partial<z.output<TEventSchema>>,\n\t\tcontext?: FnContext<TDef, TKey>\n\t) => string\n}\n\n/**\n * A route plus a subscribe route that streams its result: the initial\n * snapshot, then an update for every event published on the channel.\n */\nexport interface FnLive<TDef extends FnDefinition> {\n\t<\n\t\tTInput extends ObjectSchema,\n\t\tTOutputSchema extends ZodType,\n\t\tTEventSchema extends ZodType,\n\t\tTKey extends ProcedureKey<TDef> = TDef['default'],\n\t\tTEmit = never,\n\t\tTErrors extends ErrorMap = Record<never, never>\n\t>(\n\t\toptions: {\n\t\t\tinput: TInput\n\t\t\toutput: TOutputSchema\n\t\t\thandler: (\n\t\t\t\tparams: HandlerParams<\n\t\t\t\t\tTDef,\n\t\t\t\t\tz.output<TInput>,\n\t\t\t\t\tNoInfer<TKey>,\n\t\t\t\t\tTErrors\n\t\t\t\t> & {\n\t\t\t\t\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\t\t\t\t}\n\t\t\t\t// The output schema parses what the handler returns: its input type.\n\t\t\t) => MaybePromise<z.input<TOutputSchema>>\n\t\t\tlive: FnLiveConfig<\n\t\t\t\tTDef,\n\t\t\t\tz.output<TInput>,\n\t\t\t\tTEventSchema,\n\t\t\t\tz.output<TOutputSchema>,\n\t\t\t\tNoInfer<TKey>,\n\t\t\t\tTEmit,\n\t\t\t\tTErrors\n\t\t\t>\n\t\t} & FnRouteOptions<TDef, TKey, z.output<TInput>, TErrors>\n\t): FnLiveReturn<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tTOutputSchema,\n\t\tz.output<TOutputSchema>,\n\t\tTEventSchema,\n\t\tTEmit,\n\t\tTErrors\n\t>\n\n\t<\n\t\tTInput extends ObjectSchema,\n\t\tTOutput,\n\t\tTEventSchema extends ZodType,\n\t\tTKey extends ProcedureKey<TDef> = TDef['default'],\n\t\tTEmit = never,\n\t\tTErrors extends ErrorMap = Record<never, never>\n\t>(\n\t\toptions: {\n\t\t\tinput: TInput\n\t\t\toutput?: undefined\n\t\t\thandler: (\n\t\t\t\tparams: HandlerParams<\n\t\t\t\t\tTDef,\n\t\t\t\t\tz.output<TInput>,\n\t\t\t\t\tNoInfer<TKey>,\n\t\t\t\t\tTErrors\n\t\t\t\t> & {\n\t\t\t\t\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\t\t\t\t}\n\t\t\t) => MaybePromise<TOutput>\n\t\t\tlive: FnLiveConfig<\n\t\t\t\tTDef,\n\t\t\t\tz.output<TInput>,\n\t\t\t\tTEventSchema,\n\t\t\t\tTOutput,\n\t\t\t\tNoInfer<TKey>,\n\t\t\t\tTEmit,\n\t\t\t\tTErrors\n\t\t\t>\n\t\t} & FnRouteOptions<TDef, TKey, z.output<TInput>, TErrors>\n\t): FnLiveReturn<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tSchema<TOutput, TOutput>,\n\t\tTOutput,\n\t\tTEventSchema,\n\t\tTEmit,\n\t\tTErrors\n\t>\n}\n\n/**\n * Fail a live subscription whose initial snapshot could not be built.\n *\n * An expected client failure - an `ORPCError` with a 4xx status, e.g. the\n * subscribed resource was not found or access was refused - reaches the\n * subscriber unchanged and is NOT logged as a server fault. Only 5xx and\n * unknown failures are logged. Unknown errors are wrapped as\n * `INTERNAL_SERVER_ERROR`.\n */\nexport function throwInitialSnapshotError(\n\terr: unknown,\n\tliveName: string,\n\tlogger: Pick<FnLogger, 'error'>,\n\t/** `createFn`'s `isExpectedError`; default: a 4xx `ORPCError`. */\n\tisExpected: (error: unknown) => boolean = (error) =>\n\t\terror instanceof ORPCError && error.status < 500\n): never {\n\tif (!isExpected(err)) {\n\t\tlogger.error('fnLive initial snapshot failed', {\n\t\t\tname: liveName,\n\t\t\terr: errorMessageOf(err)\n\t\t})\n\t}\n\tthrow toSnapshotError(err, liveName)\n}\n\n/** An `ORPCError` passes through; anything else becomes INTERNAL_SERVER_ERROR. */\nfunction toSnapshotError(\n\terr: unknown,\n\tliveName: string\n): ORPCError<string, unknown> {\n\tif (err instanceof ORPCError) return err\n\treturn new ORPCError('INTERNAL_SERVER_ERROR', {\n\t\tmessage: `Failed to load initial snapshot for ${liveName}`,\n\t\tcause: err\n\t})\n}\n\n/**\n * Drives a live subscription: yields the initial snapshot, then folds each\n * inbound event into the running snapshot via `apply`, yielding after every\n * change. With `coalesceMs`, events arriving within that window are batched so\n * bursty streams apply together.\n *\n * `apply` may return an {@link FnLivePatch} to keep the full snapshot as the\n * internal accumulator while yielding only the lighter `emit` payload.\n *\n * Invariant: there is never more than one outstanding `source.next()` read. On\n * a coalesce-window timeout the still-pending read is stashed in `pending` and\n * reused by the next `readNext()` - issuing a second concurrent read would\n * strand the in-flight event behind the next one (delivering it \"one behind\").\n */\nexport async function* streamLiveSnapshots<\n\tTEvent,\n\tTOutput,\n\tTEmit = never\n>(opts: {\n\tsource: AsyncIterator<TEvent>\n\t/** Maximum events retained in one coalescing batch. */\n\tmaxBatchSize?: number\n\tapplyBatch?: (\n\t\tevents: readonly TEvent[],\n\t\tprevious: TOutput\n\t) => MaybePromise<TOutput | undefined>\n\tinitial: TOutput\n\tcoalesceMs?: number | undefined\n\tapply: (\n\t\tevent: TEvent,\n\t\tprevious: TOutput\n\t) => MaybePromise<TOutput | FnLivePatch<TOutput, TEmit> | undefined>\n}): AsyncGenerator<TOutput | TEmit> {\n\tconst { source, initial, coalesceMs, apply } = opts\n\tconst maxBatchSize = positiveInteger(\n\t\topts.maxBatchSize ?? 1000,\n\t\t'maxBatchSize'\n\t)\n\tif (\n\t\tcoalesceMs !== undefined &&\n\t\t(!Number.isFinite(coalesceMs) || coalesceMs < 0)\n\t)\n\t\tthrow new RangeError('orpc-fn: coalesceMs must be finite and nonnegative')\n\n\tlet pending: Promise<IteratorResult<TEvent>> | null = null\n\tconst readNext = () => {\n\t\tconst read = pending ?? source.next()\n\t\tpending = null\n\t\treturn read\n\t}\n\n\tlet previous = initial\n\tyield previous\n\n\twhile (true) {\n\t\tconst current = await readNext()\n\t\tif (current.done) break\n\n\t\tconst batch: TEvent[] = [current.value]\n\n\t\tif (coalesceMs) {\n\t\t\tconst endAt = Date.now() + coalesceMs\n\t\t\twhile (Date.now() < endAt && batch.length < maxBatchSize) {\n\t\t\t\tconst remainingMs = endAt - Date.now()\n\t\t\t\tconst read = readNext()\n\t\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined\n\t\t\t\tconst result = await Promise.race([\n\t\t\t\t\tread,\n\t\t\t\t\tnew Promise<typeof TIMEOUT>((resolve) => {\n\t\t\t\t\t\ttimer = setTimeout(resolve, remainingMs, TIMEOUT)\n\t\t\t\t\t})\n\t\t\t\t])\n\t\t\t\tclearTimeout(timer)\n\n\t\t\t\tif (result === TIMEOUT) {\n\t\t\t\t\t// Reuse the SAME in-flight read next iteration instead of starting\n\t\t\t\t\t// a new one - this is what prevents the \"one behind\" stranding.\n\t\t\t\t\tpending = read\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\tpending = Promise.resolve(result)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tbatch.push(result.value)\n\t\t\t}\n\t\t}\n\n\t\tif (opts.applyBatch) {\n\t\t\tconst next = await opts.applyBatch(batch, previous)\n\t\t\tif (next !== undefined) {\n\t\t\t\tprevious = next\n\t\t\t\tyield previous\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tlet changed = false\n\t\tfor (const event of batch) {\n\t\t\tconst next = await apply(event, previous)\n\t\t\tif (next === undefined) continue\n\t\t\tif (isFnLivePatch(next)) {\n\t\t\t\tif (changed) {\n\t\t\t\t\tyield previous\n\t\t\t\t\tchanged = false\n\t\t\t\t}\n\t\t\t\tprevious = next.state as TOutput\n\t\t\t\tyield next.emit as TEmit\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprevious = next\n\t\t\tchanged = true\n\t\t}\n\t\tif (changed) yield previous\n\t}\n}\n\ntype RuntimeParams = Record<string, unknown> & {\n\tinput: Record<string, unknown>\n\tcontext: unknown\n\tsignal: AbortSignal | undefined\n\tlogger: FnLogger\n\tcall: (procedure: AnyProcedure, input: unknown) => Promise<unknown>\n\t[RAW_INPUT]: unknown\n}\n\n/** `FnLiveConfig` with the generics erased: what the implementation reads. */\ntype RuntimeLiveConfig = Omit<ChannelOptions, 'name'> & {\n\tname?: string\n\tstateSchema?: AnySchema\n\temitSchema?: AnySchema\n\treauthorize?: AuthFn<Record<string, unknown>, unknown>\n\ttransformerFn?: (params: RuntimeParams & Record<string, unknown>) => unknown\n\tshouldUpdate?: (params: RuntimeParams & Record<string, unknown>) => unknown\n\tsafePublish?: boolean\n\tcoalesceMs?: number\n\tmaxBatchSize?: number\n\tsummary?: string\n\tdescription?: string\n}\n\n/**\n * @internal Wires `fnLive` onto an `fn` and channel runtime of the same\n * instance. `createFn` returns it typed as {@link FnLive}.\n */\nexport function createFnLive(runtime: {\n\t// biome-ignore lint/suspicious/noExplicitAny: runtime half of the typed `Fn`\n\tfn: (options: any) => AnyProcedure\n\tcreateChannel: (options: ChannelOptions) => Channel\n\tcreateLogger: (scope: string, span: SpanLike | undefined) => FnLogger\n\tisGuard: (option: string) => boolean\n}) {\n\tconst { fn, createChannel, isGuard } = runtime\n\tconst liveLogger = runtime.createLogger('fn-live', undefined)\n\n\treturn (\n\t\toptions: {\n\t\t\tlive: RuntimeLiveConfig\n\t\t\thandler: (params: RuntimeParams) => unknown\n\t\t\tinput: ZodType\n\t\t\toutput?: ZodType\n\t\t\tname: string\n\t\t\tprocedure?: string\n\t\t\tsummary?: string\n\t\t\tdescription?: string\n\t\t\ttags?: string[]\n\t\t} & Record<string, unknown>\n\t) => {\n\t\tconst { live, handler, input, output, name, ...routeConfig } = options\n\t\tif (live.transformerFn && !live.stateSchema)\n\t\t\tthrow new TypeError(\n\t\t\t\t'orpc-fn: live transformers require a stateSchema for parsed state'\n\t\t\t)\n\t\tif (\n\t\t\tlive.coalesceMs !== undefined &&\n\t\t\t(!Number.isFinite(live.coalesceMs) || live.coalesceMs < 0)\n\t\t)\n\t\t\tthrow new RangeError('orpc-fn: coalesceMs must be finite and nonnegative')\n\t\tif (live.maxBatchSize !== undefined)\n\t\t\tpositiveInteger(live.maxBatchSize, 'maxBatchSize')\n\t\tconst liveName = live.name ?? `${name}.live`\n\t\tconst liveSummary =\n\t\t\tlive.summary ?? `Live updates of ${routeConfig.summary ?? name}`\n\t\tconst liveDescription = live.description ?? routeConfig.description\n\n\t\t// `createChannel` reads only the channel keys of the live config.\n\t\tconst channel = createChannel({ ...live, name: liveName })\n\n\t\tconst publish = async (event: unknown) => {\n\t\t\tif (!live.safePublish) return channel.publish(event)\n\t\t\ttry {\n\t\t\t\tawait channel.publish(event)\n\t\t\t} catch (err) {\n\t\t\t\t// Live update failures must not roll back the route that emitted them,\n\t\t\t\t// but they should still be visible in logs.\n\t\t\t\tliveLogger.error('fnLive publish failed', {\n\t\t\t\t\tname: liveName,\n\t\t\t\t\terr: errorMessageOf(err)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tconst runHandler = (params: RuntimeParams) =>\n\t\t\thandler({ ...params, publish })\n\n\t\tconst procedure = fn({\n\t\t\t...routeConfig,\n\t\t\tname,\n\t\t\tinput,\n\t\t\toutput,\n\t\t\thandler: runHandler\n\t\t})\n\n\t\tconst validate = async (schema: AnySchema, value: unknown) => {\n\t\t\tconst result = await schema['~standard'].validate(value)\n\t\t\tif (result.issues)\n\t\t\t\tthrow new ORPCError('INTERNAL_SERVER_ERROR', {\n\t\t\t\t\tmessage: 'Invalid live state or patch',\n\t\t\t\t\tcause: result.issues\n\t\t\t\t})\n\t\t\treturn result.value\n\t\t}\n\t\tconst runSnapshot = (params: RuntimeParams) =>\n\t\t\tparams.call(procedure, params[RAW_INPUT])\n\t\t// Generated streams inherit access policies and metadata; tool adapters reject streams.\n\n\t\tconst guardOptions = Object.fromEntries(\n\t\t\tObject.entries(routeConfig).filter(([option]) => isGuard(option))\n\t\t)\n\t\tconst subscribe = fn({\n\t\t\t...guardOptions,\n\t\t\tguardResolvers: routeConfig.guardResolvers,\n\t\t\terrors: routeConfig.errors,\n\t\t\tmeta: routeConfig.meta,\n\t\t\tstream: true,\n\t\t\tprocedure: routeConfig.procedure,\n\t\t\ttags: routeConfig.tags,\n\t\t\tname: liveName,\n\t\t\tmethod: 'GET',\n\t\t\tinput,\n\t\t\tsummary: liveSummary,\n\t\t\tdescription: liveDescription,\n\t\t\thandler: async function* (params: RuntimeParams) {\n\t\t\t\t// Authorize and subscribe before the snapshot: a refused subscriber\n\t\t\t\t// gets nothing, and events published while it loads are queued.\n\t\t\t\tconst subscription = await channel.open({\n\t\t\t\t\tinput: params.input,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tsignal: params.signal,\n\t\t\t\t\trecoverGaps: true\n\t\t\t\t})\n\t\t\t\ttry {\n\t\t\t\t\tif (subscription.isClosed()) return\n\t\t\t\t\tlet initial: unknown\n\t\t\t\t\ttry {\n\t\t\t\t\t\tinitial = await runSnapshot(params)\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t// `fn.completed` logs it, at the level `isExpectedError` picks.\n\t\t\t\t\t\tthrow toSnapshotError(err, liveName)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst rerun = () => runSnapshot(params)\n\t\t\t\t\tconst authorize = async () => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tlive.reauthorize &&\n\t\t\t\t\t\t\tlive.reauthorize !== true &&\n\t\t\t\t\t\t\t!(await live.reauthorize({\n\t\t\t\t\t\t\t\tinput: params.input,\n\t\t\t\t\t\t\t\tctx: params.context\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new ORPCError('FORBIDDEN')\n\t\t\t\t\t}\n\t\t\t\t\tconst apply = async (event: unknown, previous: unknown) => {\n\t\t\t\t\t\tawait authorize()\n\t\t\t\t\t\tif (event === LIVE_GAP) return rerun()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tlive.shouldUpdate &&\n\t\t\t\t\t\t\t!(await live.shouldUpdate({ ...params, event, previous }))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\tif (!live.transformerFn) return rerun()\n\t\t\t\t\t\tconst next = await live.transformerFn({\n\t\t\t\t\t\t\t...params,\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t\trerun\n\t\t\t\t\t\t})\n\t\t\t\t\t\tif (next === undefined) return undefined\n\t\t\t\t\t\tif (isFnLivePatch(next)) {\n\t\t\t\t\t\t\tif (!live.emitSchema)\n\t\t\t\t\t\t\t\tthrow new TypeError('orpc-fn: live patches require emitSchema')\n\t\t\t\t\t\t\treturn fnLivePatch(\n\t\t\t\t\t\t\t\tawait validate(live.stateSchema as AnySchema, next.state),\n\t\t\t\t\t\t\t\tawait validate(live.emitSchema, next.emit)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn validate(live.stateSchema as AnySchema, next)\n\t\t\t\t\t}\n\t\t\t\t\tconst applyBatch = live.transformerFn\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: async (events: readonly unknown[], previous: unknown) => {\n\t\t\t\t\t\t\t\tawait authorize()\n\t\t\t\t\t\t\t\tlet invalidated = false\n\t\t\t\t\t\t\t\tfor (const event of events)\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tevent === LIVE_GAP ||\n\t\t\t\t\t\t\t\t\t\t!live.shouldUpdate ||\n\t\t\t\t\t\t\t\t\t\t(await live.shouldUpdate({ ...params, event, previous }))\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tinvalidated = true\n\t\t\t\t\t\t\t\treturn invalidated ? rerun() : undefined\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\tyield* streamLiveSnapshots({\n\t\t\t\t\t\tsource: subscription.events,\n\t\t\t\t\t\tinitial,\n\t\t\t\t\t\tcoalesceMs: live.coalesceMs,\n\t\t\t\t\t\t...(live.maxBatchSize !== undefined\n\t\t\t\t\t\t\t? { maxBatchSize: live.maxBatchSize }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\tapply,\n\t\t\t\t\t\t...(applyBatch ? { applyBatch } : {})\n\t\t\t\t\t})\n\t\t\t\t} finally {\n\t\t\t\t\tsubscription.close()\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn {\n\t\t\tprocedure,\n\t\t\tsubscribe,\n\t\t\tpublish,\n\t\t\tgetChannelName: channel.getChannelName,\n\t\t\tgetSubscriptionChannelName: channel.getSubscriptionChannelName,\n\t\t\tgetPublishChannelName: channel.getPublishChannelName\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fn-live.js","sourceRoot":"","sources":["../../src/live/fn-live.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,SAAS,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAA;AAoB1D,wEAAwE;AACxE,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAEjC,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AC","sourcesContent":["import type { AnySchema, ErrorMap, Schema } from '@orpc/contract'\nimport { type AnyProcedure, ORPCError } from '@orpc/server'\nimport type { ZodType, z } from 'zod'\nimport { RAW_INPUT } from '../timing.js'\nimport { LIVE_GAP, positiveInteger } from './lifecycle.js'\nimport type { FnLogger } from '../logger.js'\nimport { errorMessageOf, type SpanLike } from '../otel.js'\nimport type {\n\tFnContext,\n\tFnDefinition,\n\tFnProcedure,\n\tFnRouteOptions,\n\tHandlerParams,\n\tMaybePromise,\n\tProcedureKey\n} from '../types.js'\nimport type {\n\tAuthFn,\n\tChannel,\n\tChannelDefinition,\n\tChannelOptions,\n\tChannelQueueOptions,\n\tObjectSchema,\n\tPublisherConfig\n} from './pub-sub.js'\n\n/** Marks a coalesce window that ended before the next event arrived. */\nconst TIMEOUT = Symbol('timeout')\n\nconst fnLivePatchMarker = Symbol('fnLive.patch')\n\n/**\n * Transformer result that splits the internal accumulator from the wire\n * payload: `state` becomes the `previous` snapshot for later events while only\n * `emit` is sent to the subscriber. Lets high-frequency streams avoid\n * re-serializing the full snapshot per event.\n */\nexport type FnLivePatch<TOutput, TEmit> = {\n\t[fnLivePatchMarker]: true\n\tstate: TOutput\n\temit: TEmit\n}\n\nexport function fnLivePatch<TOutput, TEmit>(\n\tstate: TOutput,\n\temit: TEmit\n): FnLivePatch<TOutput, TEmit> {\n\treturn { [fnLivePatchMarker]: true, state, emit }\n}\n\nfunction isFnLivePatch(value: unknown): value is FnLivePatch<unknown, unknown> {\n\treturn (\n\t\ttypeof value === 'object' && value !== null && fnLivePatchMarker in value\n\t)\n}\n\nexport type FnLiveConfig<\n\tTDef extends FnDefinition,\n\tTInput,\n\tTEventSchema extends ZodType,\n\tTOutput,\n\tTKey extends ProcedureKey<TDef>,\n\tTEmit = never,\n\tTErrors extends ErrorMap = Record<never, never>\n> = Omit<PublisherConfig, 'name'> &\n\tChannelQueueOptions & {\n\t\t/** Subscribe route name; default `${name}.live`. */\n\t\tname?: string\n\t\t/**\n\t\t * Validates reducer state without reapplying an output transform. Required with a\n\t\t * transformer. Its input may be looser than its output (e.g. branded IDs); it is\n\t\t * checked at runtime.\n\t\t */\n\t\tstateSchema?: Schema<unknown, TOutput>\n\t\t/** Validates patch payloads. Required when a transformer returns fnLivePatch. */\n\t\temitSchema?: Schema<unknown, TEmit>\n\t\t/** Optional access check before each update; idle streams keep their initial authorization. */\n\t\treauthorize?: AuthFn<TInput, FnContext<TDef, TKey>>\n\t\teventSchema: TEventSchema\n\t\tchannel: ChannelDefinition<\n\t\t\tTInput,\n\t\t\tz.output<TEventSchema>,\n\t\t\tFnContext<TDef, TKey>\n\t\t>\n\t\t/** Fold an event into the snapshot; without it every event re-runs the handler. */\n\t\ttransformerFn?: FnLiveConfigTransformer<\n\t\t\tTDef,\n\t\t\tTInput,\n\t\t\tTEventSchema,\n\t\t\tTOutput,\n\t\t\tTKey,\n\t\t\tTEmit,\n\t\t\tTErrors\n\t\t>\n\t\t/** Return false to skip an event. */\n\t\tshouldUpdate?: (\n\t\t\tparams: HandlerParams<TDef, TInput, TKey, TErrors> & {\n\t\t\t\tevent: z.output<TEventSchema>\n\t\t\t\tprevious: TOutput\n\t\t\t}\n\t\t) => MaybePromise<boolean>\n\t\tauthFn?: AuthFn<TInput, FnContext<TDef, TKey>>\n\t\t/** Log publish failures instead of throwing them into the publishing route. */\n\t\tsafePublish?: boolean\n\t\t/** Batch events arriving within this window into one snapshot update. */\n\t\tcoalesceMs?: number\n\t\t/** Maximum events collected in one coalescing batch (default 1000). */\n\t\tmaxBatchSize?: number\n\t\t/**\n\t\t * When a slow subscriber's queue overflows (drop-oldest), this marker is\n\t\t * enqueued INSTEAD of the dropped event so the client resyncs. Return\n\t\t * `null` to skip.\n\t\t */\n\t\toverflowMarker?: (input: TInput) => z.output<TEventSchema> | null\n\t\tsummary?: string\n\t\tdescription?: string\n\t} & (\n\t\t| { transformerFn?: undefined }\n\t\t| {\n\t\t\t\ttransformerFn: FnLiveConfigTransformer<\n\t\t\t\t\tTDef,\n\t\t\t\t\tTInput,\n\t\t\t\t\tTEventSchema,\n\t\t\t\t\tTOutput,\n\t\t\t\t\tTKey,\n\t\t\t\t\tTEmit,\n\t\t\t\t\tTErrors\n\t\t\t\t>\n\t\t\t\tstateSchema: Schema<unknown, TOutput>\n\t\t }\n\t) &\n\t([TEmit] extends [never] ? object : { emitSchema: Schema<unknown, TEmit> })\n\ntype FnLiveConfigTransformer<\n\tTDef extends FnDefinition,\n\tTInput,\n\tTEventSchema extends ZodType,\n\tTOutput,\n\tTKey extends ProcedureKey<TDef>,\n\tTEmit,\n\tTErrors extends ErrorMap\n> = (\n\tparams: HandlerParams<TDef, TInput, TKey, TErrors> & {\n\t\tevent: z.output<TEventSchema>\n\t\tprevious: TOutput\n\t\trerun: () => Promise<TOutput>\n\t}\n) => MaybePromise<TOutput | FnLivePatch<TOutput, TEmit> | undefined>\n\nexport type FnLiveReturn<\n\tTDef extends FnDefinition,\n\tTKey extends ProcedureKey<TDef>,\n\tTInput extends ObjectSchema,\n\tTOutputSchema extends Schema<unknown, unknown>,\n\tTOutput,\n\tTEventSchema extends ZodType,\n\tTEmit = never,\n\tTErrors extends ErrorMap = Record<never, never>\n> = {\n\tprocedure: FnProcedure<TDef, TKey, TInput, TOutputSchema, TErrors>\n\tsubscribe: FnProcedure<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tSchema<AsyncGenerator<TOutput | TEmit>, AsyncGenerator<TOutput | TEmit>>,\n\t\tTErrors\n\t>\n\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: z.output<TInput>\n\t\tcontext: FnContext<TDef, TKey>\n\t}) => string\n\tgetPublishChannelName: (event: z.output<TEventSchema>) => string\n\t/** @deprecated Prefer the separate required-input resolver methods. */\n\tgetChannelName: (\n\t\tparams: Partial<z.output<TInput>> | Partial<z.output<TEventSchema>>,\n\t\tcontext?: FnContext<TDef, TKey>\n\t) => string\n}\n\n/**\n * A route plus a subscribe route that streams its result: the initial\n * snapshot, then an update for every event published on the channel.\n */\nexport interface FnLive<TDef extends FnDefinition> {\n\t<\n\t\tTInput extends ObjectSchema,\n\t\tTOutputSchema extends ZodType,\n\t\tTEventSchema extends ZodType,\n\t\tTKey extends ProcedureKey<TDef> = TDef['default'],\n\t\tTEmit = never,\n\t\tTErrors extends ErrorMap = Record<never, never>\n\t>(\n\t\toptions: {\n\t\t\tinput: TInput\n\t\t\toutput: TOutputSchema\n\t\t\thandler: (\n\t\t\t\tparams: HandlerParams<\n\t\t\t\t\tTDef,\n\t\t\t\t\tz.output<TInput>,\n\t\t\t\t\tNoInfer<TKey>,\n\t\t\t\t\tTErrors\n\t\t\t\t> & {\n\t\t\t\t\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\t\t\t\t}\n\t\t\t\t// The output schema parses what the handler returns: its input type.\n\t\t\t) => MaybePromise<z.input<TOutputSchema>>\n\t\t\tlive: FnLiveConfig<\n\t\t\t\tTDef,\n\t\t\t\tz.output<TInput>,\n\t\t\t\tTEventSchema,\n\t\t\t\tz.output<TOutputSchema>,\n\t\t\t\tNoInfer<TKey>,\n\t\t\t\tTEmit,\n\t\t\t\tTErrors\n\t\t\t>\n\t\t} & FnRouteOptions<TDef, TKey, z.output<TInput>, TErrors>\n\t): FnLiveReturn<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tTOutputSchema,\n\t\tz.output<TOutputSchema>,\n\t\tTEventSchema,\n\t\tTEmit,\n\t\tTErrors\n\t>\n\n\t<\n\t\tTInput extends ObjectSchema,\n\t\tTOutput,\n\t\tTEventSchema extends ZodType,\n\t\tTKey extends ProcedureKey<TDef> = TDef['default'],\n\t\tTEmit = never,\n\t\tTErrors extends ErrorMap = Record<never, never>\n\t>(\n\t\toptions: {\n\t\t\tinput: TInput\n\t\t\toutput?: undefined\n\t\t\thandler: (\n\t\t\t\tparams: HandlerParams<\n\t\t\t\t\tTDef,\n\t\t\t\t\tz.output<TInput>,\n\t\t\t\t\tNoInfer<TKey>,\n\t\t\t\t\tTErrors\n\t\t\t\t> & {\n\t\t\t\t\tpublish: (event: z.input<TEventSchema>) => Promise<void>\n\t\t\t\t}\n\t\t\t) => MaybePromise<TOutput>\n\t\t\tlive: FnLiveConfig<\n\t\t\t\tTDef,\n\t\t\t\tz.output<TInput>,\n\t\t\t\tTEventSchema,\n\t\t\t\tTOutput,\n\t\t\t\tNoInfer<TKey>,\n\t\t\t\tTEmit,\n\t\t\t\tTErrors\n\t\t\t>\n\t\t} & FnRouteOptions<TDef, TKey, z.output<TInput>, TErrors>\n\t): FnLiveReturn<\n\t\tTDef,\n\t\tTKey,\n\t\tTInput,\n\t\tSchema<TOutput, TOutput>,\n\t\tTOutput,\n\t\tTEventSchema,\n\t\tTEmit,\n\t\tTErrors\n\t>\n}\n\n/**\n * Fail a live subscription whose initial snapshot could not be built.\n *\n * An expected client failure - an `ORPCError` with a 4xx status, e.g. the\n * subscribed resource was not found or access was refused - reaches the\n * subscriber unchanged and is NOT logged as a server fault. Only 5xx and\n * unknown failures are logged. Unknown errors are wrapped as\n * `INTERNAL_SERVER_ERROR`.\n */\nexport function throwInitialSnapshotError(\n\terr: unknown,\n\tliveName: string,\n\tlogger: Pick<FnLogger, 'error'>,\n\t/** `createFn`'s `isExpectedError`; default: a 4xx `ORPCError`. */\n\tisExpected: (error: unknown) => boolean = (error) =>\n\t\terror instanceof ORPCError && error.status < 500\n): never {\n\tif (!isExpected(err)) {\n\t\tlogger.error('fnLive initial snapshot failed', {\n\t\t\tname: liveName,\n\t\t\terr: errorMessageOf(err)\n\t\t})\n\t}\n\tthrow toSnapshotError(err, liveName)\n}\n\n/** An `ORPCError` passes through; anything else becomes INTERNAL_SERVER_ERROR. */\nfunction toSnapshotError(\n\terr: unknown,\n\tliveName: string\n): ORPCError<string, unknown> {\n\tif (err instanceof ORPCError) return err\n\treturn new ORPCError('INTERNAL_SERVER_ERROR', {\n\t\tmessage: `Failed to load initial snapshot for ${liveName}`,\n\t\tcause: err\n\t})\n}\n\n/**\n * Drives a live subscription: yields the initial snapshot, then folds each\n * inbound event into the running snapshot via `apply`, yielding after every\n * change. With `coalesceMs`, events arriving within that window are batched so\n * bursty streams apply together.\n *\n * `apply` may return an {@link FnLivePatch} to keep the full snapshot as the\n * internal accumulator while yielding only the lighter `emit` payload.\n *\n * Invariant: there is never more than one outstanding `source.next()` read. On\n * a coalesce-window timeout the still-pending read is stashed in `pending` and\n * reused by the next `readNext()` - issuing a second concurrent read would\n * strand the in-flight event behind the next one (delivering it \"one behind\").\n */\nexport async function* streamLiveSnapshots<\n\tTEvent,\n\tTOutput,\n\tTEmit = never\n>(opts: {\n\tsource: AsyncIterator<TEvent>\n\t/** Maximum events retained in one coalescing batch. */\n\tmaxBatchSize?: number\n\tapplyBatch?: (\n\t\tevents: readonly TEvent[],\n\t\tprevious: TOutput\n\t) => MaybePromise<TOutput | undefined>\n\tinitial: TOutput\n\tcoalesceMs?: number | undefined\n\tapply: (\n\t\tevent: TEvent,\n\t\tprevious: TOutput\n\t) => MaybePromise<TOutput | FnLivePatch<TOutput, TEmit> | undefined>\n}): AsyncGenerator<TOutput | TEmit> {\n\tconst { source, initial, coalesceMs, apply } = opts\n\tconst maxBatchSize = positiveInteger(\n\t\topts.maxBatchSize ?? 1000,\n\t\t'maxBatchSize'\n\t)\n\tif (\n\t\tcoalesceMs !== undefined &&\n\t\t(!Number.isFinite(coalesceMs) || coalesceMs < 0)\n\t)\n\t\tthrow new RangeError('orpc-fn: coalesceMs must be finite and nonnegative')\n\n\tlet pending: Promise<IteratorResult<TEvent>> | null = null\n\tconst readNext = () => {\n\t\tconst read = pending ?? source.next()\n\t\tpending = null\n\t\treturn read\n\t}\n\n\tlet previous = initial\n\tyield previous\n\n\twhile (true) {\n\t\tconst current = await readNext()\n\t\tif (current.done) break\n\n\t\tconst batch: TEvent[] = [current.value]\n\n\t\tif (coalesceMs) {\n\t\t\tconst endAt = Date.now() + coalesceMs\n\t\t\twhile (Date.now() < endAt && batch.length < maxBatchSize) {\n\t\t\t\tconst remainingMs = endAt - Date.now()\n\t\t\t\tconst read = readNext()\n\t\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined\n\t\t\t\tconst result = await Promise.race([\n\t\t\t\t\tread,\n\t\t\t\t\tnew Promise<typeof TIMEOUT>((resolve) => {\n\t\t\t\t\t\ttimer = setTimeout(resolve, remainingMs, TIMEOUT)\n\t\t\t\t\t})\n\t\t\t\t])\n\t\t\t\tclearTimeout(timer)\n\n\t\t\t\tif (result === TIMEOUT) {\n\t\t\t\t\t// Reuse the SAME in-flight read next iteration instead of starting\n\t\t\t\t\t// a new one - this is what prevents the \"one behind\" stranding.\n\t\t\t\t\tpending = read\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tif (result.done) {\n\t\t\t\t\tpending = Promise.resolve(result)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tbatch.push(result.value)\n\t\t\t}\n\t\t}\n\n\t\tif (opts.applyBatch) {\n\t\t\tconst next = await opts.applyBatch(batch, previous)\n\t\t\tif (next !== undefined) {\n\t\t\t\tprevious = next\n\t\t\t\tyield previous\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tlet changed = false\n\t\tfor (const event of batch) {\n\t\t\tconst next = await apply(event, previous)\n\t\t\tif (next === undefined) continue\n\t\t\tif (isFnLivePatch(next)) {\n\t\t\t\tif (changed) {\n\t\t\t\t\tyield previous\n\t\t\t\t\tchanged = false\n\t\t\t\t}\n\t\t\t\tprevious = next.state as TOutput\n\t\t\t\tyield next.emit as TEmit\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprevious = next\n\t\t\tchanged = true\n\t\t}\n\t\tif (changed) yield previous\n\t}\n}\n\ntype RuntimeParams = Record<string, unknown> & {\n\tinput: Record<string, unknown>\n\tcontext: unknown\n\tsignal: AbortSignal | undefined\n\tlogger: FnLogger\n\tcall: (procedure: AnyProcedure, input: unknown) => Promise<unknown>\n\t[RAW_INPUT]: unknown\n}\n\n/** `FnLiveConfig` with the generics erased: what the implementation reads. */\ntype RuntimeLiveConfig = Omit<ChannelOptions, 'name'> & {\n\tname?: string\n\tstateSchema?: AnySchema\n\temitSchema?: AnySchema\n\treauthorize?: AuthFn<Record<string, unknown>, unknown>\n\ttransformerFn?: (params: RuntimeParams & Record<string, unknown>) => unknown\n\tshouldUpdate?: (params: RuntimeParams & Record<string, unknown>) => unknown\n\tsafePublish?: boolean\n\tcoalesceMs?: number\n\tmaxBatchSize?: number\n\tsummary?: string\n\tdescription?: string\n}\n\n/**\n * @internal Wires `fnLive` onto an `fn` and channel runtime of the same\n * instance. `createFn` returns it typed as {@link FnLive}.\n */\nexport function createFnLive(runtime: {\n\t// biome-ignore lint/suspicious/noExplicitAny: runtime half of the typed `Fn`\n\tfn: (options: any) => AnyProcedure\n\tcreateChannel: (options: ChannelOptions) => Channel\n\tcreateLogger: (scope: string, span: SpanLike | undefined) => FnLogger\n\tisGuard: (option: string) => boolean\n}) {\n\tconst { fn, createChannel, isGuard } = runtime\n\tconst liveLogger = runtime.createLogger('fn-live', undefined)\n\n\treturn (\n\t\toptions: {\n\t\t\tlive: RuntimeLiveConfig\n\t\t\thandler: (params: RuntimeParams) => unknown\n\t\t\tinput: ZodType\n\t\t\toutput?: ZodType\n\t\t\tname: string\n\t\t\tprocedure?: string\n\t\t\tsummary?: string\n\t\t\tdescription?: string\n\t\t\ttags?: string[]\n\t\t} & Record<string, unknown>\n\t) => {\n\t\tconst { live, handler, input, output, name, ...routeConfig } = options\n\t\tif (live.transformerFn && !live.stateSchema)\n\t\t\tthrow new TypeError(\n\t\t\t\t'orpc-fn: live transformers require a stateSchema for parsed state'\n\t\t\t)\n\t\tif (\n\t\t\tlive.coalesceMs !== undefined &&\n\t\t\t(!Number.isFinite(live.coalesceMs) || live.coalesceMs < 0)\n\t\t)\n\t\t\tthrow new RangeError('orpc-fn: coalesceMs must be finite and nonnegative')\n\t\tif (live.maxBatchSize !== undefined)\n\t\t\tpositiveInteger(live.maxBatchSize, 'maxBatchSize')\n\t\tconst liveName = live.name ?? `${name}.live`\n\t\tconst liveSummary =\n\t\t\tlive.summary ?? `Live updates of ${routeConfig.summary ?? name}`\n\t\tconst liveDescription = live.description ?? routeConfig.description\n\n\t\t// `createChannel` reads only the channel keys of the live config.\n\t\tconst channel = createChannel({ ...live, name: liveName })\n\n\t\tconst publish = async (event: unknown) => {\n\t\t\tif (!live.safePublish) return channel.publish(event)\n\t\t\ttry {\n\t\t\t\tawait channel.publish(event)\n\t\t\t} catch (err) {\n\t\t\t\t// Live update failures must not roll back the route that emitted them,\n\t\t\t\t// but they should still be visible in logs.\n\t\t\t\tliveLogger.error('fnLive publish failed', {\n\t\t\t\t\tname: liveName,\n\t\t\t\t\terr: errorMessageOf(err)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tconst runHandler = (params: RuntimeParams) =>\n\t\t\thandler({ ...params, publish })\n\n\t\tconst procedure = fn({\n\t\t\t...routeConfig,\n\t\t\tname,\n\t\t\tinput,\n\t\t\toutput,\n\t\t\thandler: runHandler\n\t\t})\n\n\t\tconst validate = async (schema: AnySchema, value: unknown) => {\n\t\t\tconst result = await schema['~standard'].validate(value)\n\t\t\tif (result.issues)\n\t\t\t\tthrow new ORPCError('INTERNAL_SERVER_ERROR', {\n\t\t\t\t\tmessage: 'Invalid live state or patch',\n\t\t\t\t\tcause: result.issues\n\t\t\t\t})\n\t\t\treturn result.value\n\t\t}\n\t\tconst runSnapshot = (params: RuntimeParams) =>\n\t\t\tparams.call(procedure, params[RAW_INPUT])\n\t\t// Generated streams inherit access policies and metadata; tool adapters reject streams.\n\n\t\tconst guardOptions = Object.fromEntries(\n\t\t\tObject.entries(routeConfig).filter(([option]) => isGuard(option))\n\t\t)\n\t\tconst subscribe = fn({\n\t\t\t...guardOptions,\n\t\t\tguardResolvers: routeConfig.guardResolvers,\n\t\t\terrors: routeConfig.errors,\n\t\t\tmeta: routeConfig.meta,\n\t\t\tstream: true,\n\t\t\tprocedure: routeConfig.procedure,\n\t\t\ttags: routeConfig.tags,\n\t\t\tname: liveName,\n\t\t\tmethod: 'GET',\n\t\t\tinput,\n\t\t\tsummary: liveSummary,\n\t\t\tdescription: liveDescription,\n\t\t\thandler: async function* (params: RuntimeParams) {\n\t\t\t\t// Authorize and subscribe before the snapshot: a refused subscriber\n\t\t\t\t// gets nothing, and events published while it loads are queued.\n\t\t\t\tconst subscription = await channel.open({\n\t\t\t\t\tinput: params.input,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tsignal: params.signal,\n\t\t\t\t\trecoverGaps: true\n\t\t\t\t})\n\t\t\t\ttry {\n\t\t\t\t\tif (subscription.isClosed()) return\n\t\t\t\t\tlet initial: unknown\n\t\t\t\t\ttry {\n\t\t\t\t\t\tinitial = await runSnapshot(params)\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t// `fn.completed` logs it, at the level `isExpectedError` picks.\n\t\t\t\t\t\tthrow toSnapshotError(err, liveName)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst rerun = () => runSnapshot(params)\n\t\t\t\t\tconst authorize = async () => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tlive.reauthorize &&\n\t\t\t\t\t\t\tlive.reauthorize !== true &&\n\t\t\t\t\t\t\t!(await live.reauthorize({\n\t\t\t\t\t\t\t\tinput: params.input,\n\t\t\t\t\t\t\t\tctx: params.context\n\t\t\t\t\t\t\t}))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthrow new ORPCError('FORBIDDEN')\n\t\t\t\t\t}\n\t\t\t\t\tconst apply = async (event: unknown, previous: unknown) => {\n\t\t\t\t\t\tawait authorize()\n\t\t\t\t\t\tif (event === LIVE_GAP) return rerun()\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tlive.shouldUpdate &&\n\t\t\t\t\t\t\t!(await live.shouldUpdate({ ...params, event, previous }))\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\tif (!live.transformerFn) return rerun()\n\t\t\t\t\t\tconst next = await live.transformerFn({\n\t\t\t\t\t\t\t...params,\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t\trerun\n\t\t\t\t\t\t})\n\t\t\t\t\t\tif (next === undefined) return undefined\n\t\t\t\t\t\tif (isFnLivePatch(next)) {\n\t\t\t\t\t\t\tif (!live.emitSchema)\n\t\t\t\t\t\t\t\tthrow new TypeError('orpc-fn: live patches require emitSchema')\n\t\t\t\t\t\t\treturn fnLivePatch(\n\t\t\t\t\t\t\t\tawait validate(live.stateSchema as AnySchema, next.state),\n\t\t\t\t\t\t\t\tawait validate(live.emitSchema, next.emit)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn validate(live.stateSchema as AnySchema, next)\n\t\t\t\t\t}\n\t\t\t\t\tconst applyBatch = live.transformerFn\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: async (events: readonly unknown[], previous: unknown) => {\n\t\t\t\t\t\t\t\tawait authorize()\n\t\t\t\t\t\t\t\tlet invalidated = false\n\t\t\t\t\t\t\t\tfor (const event of events)\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tevent === LIVE_GAP ||\n\t\t\t\t\t\t\t\t\t\t!live.shouldUpdate ||\n\t\t\t\t\t\t\t\t\t\t(await live.shouldUpdate({ ...params, event, previous }))\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tinvalidated = true\n\t\t\t\t\t\t\t\treturn invalidated ? rerun() : undefined\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\tyield* streamLiveSnapshots({\n\t\t\t\t\t\tsource: subscription.events,\n\t\t\t\t\t\tinitial,\n\t\t\t\t\t\tcoalesceMs: live.coalesceMs,\n\t\t\t\t\t\t...(live.maxBatchSize !== undefined\n\t\t\t\t\t\t\t? { maxBatchSize: live.maxBatchSize }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\tapply,\n\t\t\t\t\t\t...(applyBatch ? { applyBatch } : {})\n\t\t\t\t\t})\n\t\t\t\t} finally {\n\t\t\t\t\tsubscription.close()\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn {\n\t\t\tprocedure,\n\t\t\tsubscribe,\n\t\t\tpublish,\n\t\t\tgetChannelName: channel.getChannelName,\n\t\t\tgetSubscriptionChannelName: channel.getSubscriptionChannelName,\n\t\t\tgetPublishChannelName: channel.getPublishChannelName\n\t\t}\n\t}\n}\n"]}
|
package/dist/live/pub-sub.d.ts
CHANGED
|
@@ -128,7 +128,11 @@ export type CreatePublisher = <TEventSchema extends ZodType>(options: PublisherO
|
|
|
128
128
|
export type PubSubRuntimeOptions = {
|
|
129
129
|
/** Queue depths, drops, successful reconnects and parse failures. */
|
|
130
130
|
onMetric?: (event: PubSubMetric) => void;
|
|
131
|
-
|
|
131
|
+
/**
|
|
132
|
+
* The broker, or a function creating it on first use so importing routes
|
|
133
|
+
* opens no connection: `transport: () => bunRedisTransport(getRedis())`.
|
|
134
|
+
*/
|
|
135
|
+
transport: PubSubTransport | (() => PubSubTransport);
|
|
132
136
|
/**
|
|
133
137
|
* Called per event dropped from ingress, replay or delivery queues.
|
|
134
138
|
* Delivery drops count events before subscriber filtering.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pub-sub.d.ts","sourceRoot":"","sources":["../../src/live/pub-sub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"pub-sub.d.ts","sourceRoot":"","sources":["../../src/live/pub-sub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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KAAK,MAAM;uCACmB,KAAK,KAAK,MAAM;;wCAuwBJ,gBAAgB,CAAC,OAAO,CAAC;wBApnBlD,OAAO;6BACI,SAAS,OAAO,EAAE;iCAonBd,KAAK;;IAyBrC,oEAAoE;;IAEpE,iEAAiE;;EAiBlE"}
|
package/dist/live/pub-sub.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ORPCError } from '@orpc/server';
|
|
2
|
-
import { errorMessageOf } from '../otel.js';
|
|
2
|
+
import { errorAttributes, errorMessageOf } from '../otel.js';
|
|
3
3
|
import { decodeMessage, encodePayload } from './codec.js';
|
|
4
4
|
import { LIVE_GAP, positiveInteger, safely, waitFor } from './lifecycle.js';
|
|
5
5
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -203,11 +203,18 @@ export function createLiveRuntime(options) {
|
|
|
203
203
|
// with the process: the generator returns, oRPC closes the SSE response and
|
|
204
204
|
// the client's backoff reconnects to the new deployment.
|
|
205
205
|
const activeSubscriberCleanups = new Set();
|
|
206
|
+
let transport;
|
|
206
207
|
const requireTransport = () => {
|
|
207
208
|
if (!options.pubsub) {
|
|
208
209
|
throw new Error('orpc-fn: live routes need a transport, pass createFn({ pubsub: { transport } })');
|
|
209
210
|
}
|
|
210
|
-
|
|
211
|
+
if (transport)
|
|
212
|
+
return transport;
|
|
213
|
+
// A lazy transport is never created during or after shutdown.
|
|
214
|
+
assertOpen();
|
|
215
|
+
const configured = options.pubsub.transport;
|
|
216
|
+
transport = typeof configured === 'function' ? configured() : configured;
|
|
217
|
+
return transport;
|
|
211
218
|
};
|
|
212
219
|
/**
|
|
213
220
|
* Shared publish pipeline: validate the raw event, resolve the channel from
|
|
@@ -354,8 +361,9 @@ export function createLiveRuntime(options) {
|
|
|
354
361
|
name: config.name,
|
|
355
362
|
channel
|
|
356
363
|
});
|
|
357
|
-
logger.warn(
|
|
358
|
-
|
|
364
|
+
logger.warn('pubsub.message_dropped', {
|
|
365
|
+
channel,
|
|
366
|
+
...errorAttributes(error)
|
|
359
367
|
});
|
|
360
368
|
}
|
|
361
369
|
}
|
|
@@ -370,7 +378,8 @@ export function createLiveRuntime(options) {
|
|
|
370
378
|
return;
|
|
371
379
|
const delayMs = getResubscribeDelayMs(attempt);
|
|
372
380
|
attempt++;
|
|
373
|
-
logger.warn(
|
|
381
|
+
logger.warn('pubsub.resubscribe_scheduled', {
|
|
382
|
+
channel,
|
|
374
383
|
reason,
|
|
375
384
|
attempt,
|
|
376
385
|
delayMs
|
|
@@ -396,8 +405,9 @@ export function createLiveRuntime(options) {
|
|
|
396
405
|
connected = false;
|
|
397
406
|
markPending();
|
|
398
407
|
}
|
|
399
|
-
logger.error(
|
|
400
|
-
|
|
408
|
+
logger.error('pubsub.subscription_lost', {
|
|
409
|
+
channel,
|
|
410
|
+
...errorAttributes(error)
|
|
401
411
|
});
|
|
402
412
|
scheduleResubscribe('lost');
|
|
403
413
|
}, {
|
|
@@ -433,11 +443,12 @@ export function createLiveRuntime(options) {
|
|
|
433
443
|
connectedOnce = true;
|
|
434
444
|
markReady();
|
|
435
445
|
attempt = 0;
|
|
436
|
-
logger.
|
|
446
|
+
logger.debug('pubsub.subscribed', { channel });
|
|
437
447
|
}
|
|
438
448
|
catch (error) {
|
|
439
|
-
logger.error(
|
|
440
|
-
|
|
449
|
+
logger.error('pubsub.subscribe_failed', {
|
|
450
|
+
channel,
|
|
451
|
+
...errorAttributes(error)
|
|
441
452
|
});
|
|
442
453
|
scheduleResubscribe('subscribe-failed');
|
|
443
454
|
}
|
|
@@ -534,7 +545,7 @@ export function createLiveRuntime(options) {
|
|
|
534
545
|
tracing.end(span, error);
|
|
535
546
|
throw error;
|
|
536
547
|
}
|
|
537
|
-
subscriberLogger.
|
|
548
|
+
subscriberLogger.debug('pubsub.subscribing', { channel: channelName });
|
|
538
549
|
let messageCount = 0;
|
|
539
550
|
let droppedCount = 0;
|
|
540
551
|
const delivery = createSubscriberDelivery({
|
|
@@ -648,7 +659,8 @@ export function createLiveRuntime(options) {
|
|
|
648
659
|
span?.setAttribute('pubsub.message_count', messageCount);
|
|
649
660
|
span?.setAttribute('pubsub.dropped_count', droppedCount);
|
|
650
661
|
tracing.end(span, ...error);
|
|
651
|
-
subscriberLogger.
|
|
662
|
+
subscriberLogger.debug('pubsub.unsubscribed', {
|
|
663
|
+
channel: channelName,
|
|
652
664
|
messageCount,
|
|
653
665
|
droppedCount,
|
|
654
666
|
durationMs: Math.round(durationMs)
|
|
@@ -697,7 +709,10 @@ export function createLiveRuntime(options) {
|
|
|
697
709
|
}
|
|
698
710
|
catch (error) {
|
|
699
711
|
replayGap = true;
|
|
700
|
-
subscriberLogger.warn(
|
|
712
|
+
subscriberLogger.warn('pubsub.replay_failed', {
|
|
713
|
+
channel: channelName,
|
|
714
|
+
...errorAttributes(error)
|
|
715
|
+
});
|
|
701
716
|
}
|
|
702
717
|
}
|
|
703
718
|
for (const { data, id } of replaying ?? [])
|
|
@@ -803,7 +818,7 @@ export function createLiveRuntime(options) {
|
|
|
803
818
|
await Promise.allSettled([...pendingOpens]);
|
|
804
819
|
await Promise.all([...releases]);
|
|
805
820
|
if (options.pubsub?.ownsTransport)
|
|
806
|
-
await
|
|
821
|
+
await transport?.close?.();
|
|
807
822
|
})();
|
|
808
823
|
return shutdownPromise;
|
|
809
824
|
},
|