New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@orpc/server

Package Overview
Dependencies
Maintainers
1
Versions
1073
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orpc/server - npm Package Compare versions

Comparing version
1.13.13
to
1.13.14
+421
dist/shared/server.BOmqcs4W.mjs
import { isContractProcedure, validateORPCError, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@orpc/shared';
import { ORPCError, mapEventIterator } from '@orpc/client';
import { HibernationEventIterator } from '@orpc/standard-server';
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
function lazy(loader, meta = {}) {
return {
[LAZY_SYMBOL]: {
loader,
meta
}
};
}
function isLazy(item) {
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
}
function getLazyMeta(lazied) {
return lazied[LAZY_SYMBOL].meta;
}
function unlazy(lazied) {
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
}
function isStartWithMiddlewares(middlewares, compare) {
if (compare.length > middlewares.length) {
return false;
}
for (let i = 0; i < middlewares.length; i++) {
if (compare[i] === void 0) {
return true;
}
if (middlewares[i] !== compare[i]) {
return false;
}
}
return true;
}
function mergeMiddlewares(first, second, options) {
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
return second;
}
return [...first, ...second];
}
function addMiddleware(middlewares, addition) {
return [...middlewares, addition];
}
class Procedure {
/**
* This property holds the defined options.
*/
"~orpc";
constructor(def) {
this["~orpc"] = def;
}
}
function isProcedure(item) {
if (item instanceof Procedure) {
return true;
}
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
}
function mergeCurrentContext(context, other) {
return { ...context, ...other };
}
function createORPCErrorConstructorMap(errors) {
const proxy = new Proxy(errors, {
get(target, code) {
if (typeof code !== "string") {
return Reflect.get(target, code);
}
const item = (...rest) => {
const options = resolveMaybeOptionalOptions(rest);
const config = errors[code];
return new ORPCError(code, {
defined: Boolean(config),
status: config?.status,
message: options.message ?? config?.message,
data: options.data,
cause: options.cause
});
};
return item;
}
});
return proxy;
}
function middlewareOutputFn(output) {
return { output, context: {} };
}
function createProcedureClient(lazyableProcedure, ...rest) {
const options = resolveMaybeOptionalOptions(rest);
return async (...[input, callerOptions]) => {
const path = toArray(options.path);
const { default: procedure } = await unlazy(lazyableProcedure);
const clientContext = callerOptions?.context ?? {};
const context = await value(options.context ?? {}, clientContext);
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
const validateError = async (e) => {
if (e instanceof ORPCError) {
return await validateORPCError(procedure["~orpc"].errorMap, e);
}
return e;
};
try {
const output = await runWithSpan(
{ name: "call_procedure", signal: callerOptions?.signal },
(span) => {
span?.setAttribute("procedure.path", [...path]);
return intercept(
toArray(options.interceptors),
{
context,
input,
// input only optional when it undefinable so we can safely cast it
errors,
path,
procedure,
signal: callerOptions?.signal,
lastEventId: callerOptions?.lastEventId
},
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
);
}
);
if (isAsyncIteratorObject(output)) {
if (output instanceof HibernationEventIterator) {
return output;
}
return overlayProxy(output, mapEventIterator(
asyncIteratorWithSpan(
{ name: "consume_event_iterator_output", signal: callerOptions?.signal },
output
),
{
value: (v) => v,
error: (e) => validateError(e)
}
));
}
return output;
} catch (e) {
throw await validateError(e);
}
};
}
async function validateInput(procedure, input) {
const schema = procedure["~orpc"].inputSchema;
if (!schema) {
return input;
}
return runWithSpan(
{ name: "validate_input" },
async () => {
const result = await schema["~standard"].validate(input);
if (result.issues) {
throw new ORPCError("BAD_REQUEST", {
message: "Input validation failed",
data: {
issues: result.issues
},
cause: new ValidationError({
message: "Input validation failed",
issues: result.issues,
data: input
})
});
}
return result.value;
}
);
}
async function validateOutput(procedure, output) {
const schema = procedure["~orpc"].outputSchema;
if (!schema) {
return output;
}
return runWithSpan(
{ name: "validate_output" },
async () => {
const result = await schema["~standard"].validate(output);
if (result.issues) {
throw new ORPCError("INTERNAL_SERVER_ERROR", {
message: "Output validation failed",
cause: new ValidationError({
message: "Output validation failed",
issues: result.issues,
data: output
})
});
}
return result.value;
}
);
}
async function executeProcedureInternal(procedure, options) {
const middlewares = procedure["~orpc"].middlewares;
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
const next = async (index, context, input) => {
let currentInput = input;
if (index === inputValidationIndex) {
currentInput = await validateInput(procedure, currentInput);
}
const mid = middlewares[index];
const output = mid ? await runWithSpan(
{ name: `middleware.${mid.name}`, signal: options.signal },
async (span) => {
span?.setAttribute("middleware.index", index);
span?.setAttribute("middleware.name", mid.name);
const result = await mid({
...options,
context,
next: async (...[nextOptions]) => {
const nextContext = nextOptions?.context ?? {};
return {
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
context: nextContext
};
}
}, currentInput, middlewareOutputFn);
return result.output;
}
) : await runWithSpan(
{ name: "handler", signal: options.signal },
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
);
if (index === outputValidationIndex) {
return await validateOutput(procedure, output);
}
return output;
};
return next(0, options.context, options.input);
}
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
function setHiddenRouterContract(router, contract) {
return new Proxy(router, {
get(target, key) {
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
return contract;
}
return Reflect.get(target, key);
}
});
}
function getHiddenRouterContract(router) {
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
}
function getRouter(router, path) {
let current = router;
for (let i = 0; i < path.length; i++) {
const segment = path[i];
if (!current) {
return void 0;
}
if (isProcedure(current)) {
return void 0;
}
if (typeof current !== "object") {
return void 0;
}
if (!isLazy(current)) {
current = current[segment];
continue;
}
const lazied = current;
const rest = path.slice(i);
return lazy(async () => {
const unwrapped = await unlazy(lazied);
const next = getRouter(unwrapped.default, rest);
return unlazy(next);
}, getLazyMeta(lazied));
}
return current;
}
function createAccessibleLazyRouter(lazied) {
const recursive = new Proxy(lazied, {
get(target, key) {
if (typeof key !== "string") {
return Reflect.get(target, key);
}
const next = getRouter(lazied, [key]);
return createAccessibleLazyRouter(next);
}
});
return recursive;
}
function enhanceRouter(router, options) {
if (isLazy(router)) {
const laziedMeta = getLazyMeta(router);
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
const enhanced2 = lazy(async () => {
const { default: unlaziedRouter } = await unlazy(router);
const enhanced3 = enhanceRouter(unlaziedRouter, options);
return unlazy(enhanced3);
}, {
...laziedMeta,
prefix: enhancedPrefix
});
const accessible = createAccessibleLazyRouter(enhanced2);
return accessible;
}
if (isProcedure(router)) {
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
const enhanced2 = new Procedure({
...router["~orpc"],
route: enhanceRoute(router["~orpc"].route, options),
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
middlewares: newMiddlewares,
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
});
return enhanced2;
}
if (typeof router !== "object" || router === null) {
return router;
}
const enhanced = {};
for (const key in router) {
enhanced[key] = enhanceRouter(router[key], options);
}
return enhanced;
}
function traverseContractProcedures(options, callback, lazyOptions = []) {
if (typeof options.router !== "object" || options.router === null) {
return lazyOptions;
}
let currentRouter = options.router;
const hiddenContract = getHiddenRouterContract(options.router);
if (hiddenContract !== void 0) {
currentRouter = hiddenContract;
}
if (isLazy(currentRouter)) {
lazyOptions.push({
router: currentRouter,
path: options.path
});
} else if (isContractProcedure(currentRouter)) {
callback({
contract: currentRouter,
path: options.path
});
} else if (typeof currentRouter === "object" && currentRouter !== null) {
for (const key in currentRouter) {
traverseContractProcedures(
{
router: currentRouter[key],
path: [...options.path, key]
},
callback,
lazyOptions
);
}
}
return lazyOptions;
}
async function resolveContractProcedures(options, callback) {
const pending = [options];
for (const options2 of pending) {
const lazyOptions = traverseContractProcedures(options2, callback);
for (const options3 of lazyOptions) {
const { default: router } = await unlazy(options3.router);
pending.push({
router,
path: options3.path
});
}
}
}
async function unlazyRouter(router) {
if (isProcedure(router)) {
return router;
}
if (typeof router !== "object" || router === null) {
return router;
}
const unlazied = {};
for (const key in router) {
const item = router[key];
const { default: unlaziedRouter } = await unlazy(item);
unlazied[key] = await unlazyRouter(unlaziedRouter);
}
return unlazied;
}
function createAssertedLazyProcedure(lazied) {
const lazyProcedure = lazy(async () => {
const { default: maybeProcedure } = await unlazy(lazied);
if (!isProcedure(maybeProcedure)) {
throw new Error(`
Expected a lazy<procedure> but got lazy<unknown>.
This should be caught by TypeScript compilation.
Please report this issue if this makes you feel uncomfortable.
`);
}
return { default: maybeProcedure };
}, getLazyMeta(lazied));
return lazyProcedure;
}
function createContractedProcedure(procedure, contract) {
return new Procedure({
...procedure["~orpc"],
errorMap: contract["~orpc"].errorMap,
route: contract["~orpc"].route,
meta: contract["~orpc"].meta
});
}
function call(procedure, input, ...rest) {
const options = resolveMaybeOptionalOptions(rest);
return createProcedureClient(procedure, options)(input, options);
}
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, resolveContractProcedures as v, unlazyRouter as w };
import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
import { ORPCError, toORPCError } from '@orpc/client';
import { toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
import { flattenHeader } from '@orpc/standard-server';
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.BOmqcs4W.mjs';
class CompositeStandardHandlerPlugin {
plugins;
constructor(plugins = []) {
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
init(options, router) {
for (const plugin of this.plugins) {
plugin.init?.(options, router);
}
}
}
class StandardHandler {
constructor(router, matcher, codec, options) {
this.matcher = matcher;
this.codec = codec;
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
plugins.init(options, router);
this.interceptors = toArray(options.interceptors);
this.clientInterceptors = toArray(options.clientInterceptors);
this.rootInterceptors = toArray(options.rootInterceptors);
this.matcher.init(router);
}
interceptors;
clientInterceptors;
rootInterceptors;
async handle(request, options) {
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
return { matched: false, response: void 0 };
}
return intercept(
this.rootInterceptors,
{ ...options, request, prefix },
async (interceptorOptions) => {
return runWithSpan(
{ name: `${request.method} ${request.url.pathname}` },
async (span) => {
let step;
try {
return await intercept(
this.interceptors,
interceptorOptions,
async ({ request: request2, context, prefix: prefix2 }) => {
const method = request2.method;
const url = request2.url;
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
const match = await runWithSpan(
{ name: "find_procedure" },
() => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
);
if (!match) {
return { matched: false, response: void 0 };
}
span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
span?.setAttribute("rpc.system", ORPC_NAME);
span?.setAttribute("rpc.method", match.path.join("."));
step = "decode_input";
let input = await runWithSpan(
{ name: "decode_input" },
() => this.codec.decode(request2, match.params, match.procedure)
);
step = void 0;
if (isAsyncIteratorObject(input)) {
input = asyncIteratorWithSpan(
{ name: "consume_event_iterator_input", signal: request2.signal },
input
);
}
const client = createProcedureClient(match.procedure, {
context,
path: match.path,
interceptors: this.clientInterceptors
});
step = "call_procedure";
const output = await client(input, {
signal: request2.signal,
lastEventId: flattenHeader(request2.headers["last-event-id"])
});
step = void 0;
const response = this.codec.encode(output, match.procedure);
return {
matched: true,
response
};
}
);
} catch (e) {
if (step !== "call_procedure") {
setSpanError(span, e);
}
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
cause: e
}) : toORPCError(e);
const response = this.codec.encodeError(error);
return {
matched: true,
response
};
}
}
);
}
);
}
}
class StandardRPCCodec {
constructor(serializer) {
this.serializer = serializer;
}
async decode(request, _params, _procedure) {
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
return this.serializer.deserialize(serialized);
}
encode(output, _procedure) {
return {
status: 200,
headers: {},
body: this.serializer.serialize(output)
};
}
encodeError(error) {
return {
status: error.status,
headers: {},
body: this.serializer.serialize(error.toJSON())
};
}
}
class StandardRPCMatcher {
filter;
tree = new NullProtoObj();
pendingRouters = [];
constructor(options = {}) {
this.filter = options.filter ?? true;
}
init(router, path = []) {
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
if (!value(this.filter, traverseOptions)) {
return;
}
const { path: path2, contract } = traverseOptions;
const httpPath = toHttpPath(path2);
if (isProcedure(contract)) {
this.tree[httpPath] = {
path: path2,
contract,
procedure: contract,
// this mean dev not used contract-first so we can used contract as procedure directly
router
};
} else {
this.tree[httpPath] = {
path: path2,
contract,
procedure: void 0,
router
};
}
});
this.pendingRouters.push(...laziedOptions.map((option) => ({
...option,
httpPathPrefix: toHttpPath(option.path)
})));
}
async match(_method, pathname) {
if (this.pendingRouters.length) {
const newPendingRouters = [];
for (const pendingRouter of this.pendingRouters) {
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
const { default: router } = await unlazy(pendingRouter.router);
this.init(router, pendingRouter.path);
} else {
newPendingRouters.push(pendingRouter);
}
}
this.pendingRouters = newPendingRouters;
}
const match = this.tree[pathname];
if (!match) {
return void 0;
}
if (!match.procedure) {
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
if (!isProcedure(maybeProcedure)) {
throw new Error(`
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
Ensure that the procedure is correctly defined and matches the expected contract.
`);
}
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
}
return {
path: match.path,
procedure: match.procedure
};
}
}
class StandardRPCHandler extends StandardHandler {
constructor(router, options = {}) {
const jsonSerializer = new StandardRPCJsonSerializer(options);
const serializer = new StandardRPCSerializer(jsonSerializer);
const matcher = new StandardRPCMatcher(options);
const codec = new StandardRPCCodec(serializer);
super(router, matcher, codec, options);
}
}
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
+2
-2

@@ -10,5 +10,5 @@ import { resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -15,0 +15,0 @@ class AwsLambdaHandler {

@@ -7,6 +7,6 @@ import { resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.DZ5BIITo.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -13,0 +13,0 @@ class BunWsHandler {

@@ -7,6 +7,6 @@ import { resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.DZ5BIITo.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -13,0 +13,0 @@ class experimental_CrosswsHandler {

@@ -10,5 +10,5 @@ import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -15,0 +15,0 @@ class FastifyHandler {

@@ -7,7 +7,7 @@ import { ORPCError } from '@orpc/client';

import '@orpc/contract';
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '@orpc/standard-server/batch';
import { S as StrictGetMethodPlugin } from '../../shared/server.TEVCLCFC.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -14,0 +14,0 @@ class BodyLimitPlugin {

@@ -8,6 +8,6 @@ import { postMessagePortMessage, onMessagePortMessage, onMessagePortClose } from '@orpc/client/message-port';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.DZ5BIITo.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -14,0 +14,0 @@ class MessagePortHandler {

@@ -8,3 +8,3 @@ import { ORPCError } from '@orpc/client';

import '@orpc/contract';
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';

@@ -14,3 +14,3 @@ import '@orpc/standard-server/batch';

import { S as StrictGetMethodPlugin } from '../../shared/server.TEVCLCFC.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -17,0 +17,0 @@ class BodyLimitPlugin {

@@ -1,2 +0,2 @@

export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.Bxx6tqNe.mjs';
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.FBh3u_u-.mjs';
export { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';

@@ -7,3 +7,3 @@ import '@orpc/client/standard';

import '@orpc/standard-server';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';
import '@orpc/contract';

@@ -7,6 +7,6 @@ import { readAsBuffer, resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.DZ5BIITo.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -13,0 +13,0 @@ class WebsocketHandler {

@@ -7,6 +7,6 @@ import { readAsBuffer, resolveMaybeOptionalOptions } from '@orpc/shared';

import '@orpc/contract';
import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs';
import { b as StandardRPCHandler } from '../../shared/server.FBh3u_u-.mjs';
import '@orpc/client/standard';
import '../../shared/server.DZ5BIITo.mjs';
import '../../shared/server.Ds4HPpvH.mjs';
import '../../shared/server.BOmqcs4W.mjs';

@@ -13,0 +13,0 @@ class WsHandler {

import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
export { ValidationError, eventIterator, type, validateORPCError } from '@orpc/contract';
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.Ds4HPpvH.mjs';
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, v as resolveContractProcedures, t as traverseContractProcedures, w as unlazyRouter } from './shared/server.Ds4HPpvH.mjs';
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.BOmqcs4W.mjs';
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, v as resolveContractProcedures, t as traverseContractProcedures, w as unlazyRouter } from './shared/server.BOmqcs4W.mjs';
import { toORPCError } from '@orpc/client';

@@ -6,0 +6,0 @@ export { ORPCError, isDefinedError, safe } from '@orpc/client';

{
"name": "@orpc/server",
"type": "module",
"version": "1.13.13",
"version": "1.13.14",
"license": "MIT",

@@ -109,12 +109,12 @@ "homepage": "https://orpc.dev",

"cookie": "^1.1.1",
"@orpc/client": "1.13.13",
"@orpc/contract": "1.13.13",
"@orpc/interop": "1.13.13",
"@orpc/shared": "1.13.13",
"@orpc/standard-server-aws-lambda": "1.13.13",
"@orpc/standard-server": "1.13.13",
"@orpc/standard-server-fastify": "1.13.13",
"@orpc/standard-server-node": "1.13.13",
"@orpc/standard-server-fetch": "1.13.13",
"@orpc/standard-server-peer": "1.13.13"
"@orpc/interop": "1.13.14",
"@orpc/contract": "1.13.14",
"@orpc/shared": "1.13.14",
"@orpc/client": "1.13.14",
"@orpc/standard-server-aws-lambda": "1.13.14",
"@orpc/standard-server": "1.13.14",
"@orpc/standard-server-fastify": "1.13.14",
"@orpc/standard-server-fetch": "1.13.14",
"@orpc/standard-server-node": "1.13.14",
"@orpc/standard-server-peer": "1.13.14"
},

@@ -125,3 +125,3 @@ "devDependencies": {

"crossws": "^0.4.4",
"fastify": "^5.8.2",
"fastify": "^5.8.3",
"next": "^16.1.7",

@@ -128,0 +128,0 @@ "supertest": "^7.1.4",

+35
-41

@@ -133,10 +133,2 @@ <div align="center">

### 🥇 Gold Sponsor
<table>
<tr>
<td align="center"><a href="https://zuplo.link/orpc?ref=orpc" target="_blank" rel="noopener" title="Zuplo"><img src="https://avatars.githubusercontent.com/u/85497839?v=4" width="209" alt="Zuplo"/><br />Zuplo</a></td>
</tr>
</table>
### 🥈 Silver Sponsor

@@ -146,4 +138,4 @@

<tr>
<td align="center"><a href="https://misskey.io/?ref=orpc" target="_blank" rel="noopener" title="村上さん"><img src="https://avatars.githubusercontent.com/u/37681609?u=0dd4c7e4ba937cbb52b068c55914b1d8164dc0c7&amp;v=4" width="167" alt="村上さん"/><br />村上さん</a></td>
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
<td align="center"><a href="https://misskey.io/?ref=orpc" target="_blank" rel="noopener" title="村上さん"><img src="https://avatars.githubusercontent.com/u/37681609?u=0dd4c7e4ba937cbb52b068c55914b1d8164dc0c7&amp;v=4" width="209" alt="村上さん"/><br />村上さん</a></td>
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="209" alt="christ12938"/><br />christ12938</a></td>
</tr>

@@ -156,3 +148,3 @@ </table>

<tr>
<td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="139" alt="LN Markets"/><br />LN Markets</a></td>
<td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="167" alt="LN Markets"/><br />LN Markets</a></td>
</tr>

@@ -165,23 +157,23 @@ </table>

<tr>
<td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="119" alt="Reece McDonald"/><br />Reece McDonald</a></td>
<td align="center"><a href="https://github.com/u1-liquid?ref=orpc" target="_blank" rel="noopener" title="あわわわとーにゅ"><img src="https://avatars.githubusercontent.com/u/17376330?u=de3353804be889f009f7e0a1582daf04d0ab292d&amp;v=4" width="119" alt="あわわわとーにゅ"/><br />あわわわとーにゅ</a></td>
<td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&amp;v=4" width="119" alt="nk"/><br />nk</a></td>
<td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="119" alt="supastarter"/><br />supastarter</a></td>
<td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&amp;v=4" width="119" alt="Dexter Miguel"/><br />Dexter Miguel</a></td>
<td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&amp;v=4" width="119" alt="herrfugbaum"/><br />herrfugbaum</a></td>
<td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&amp;v=4" width="119" alt="Ryota Murakami"/><br />Ryota Murakami</a></td>
<td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="139" alt="Reece McDonald"/><br />Reece McDonald</a></td>
<td align="center"><a href="https://github.com/u1-liquid?ref=orpc" target="_blank" rel="noopener" title="あわわわとーにゅ"><img src="https://avatars.githubusercontent.com/u/17376330?u=de3353804be889f009f7e0a1582daf04d0ab292d&amp;v=4" width="139" alt="あわわわとーにゅ"/><br />あわわわとーにゅ</a></td>
<td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&amp;v=4" width="139" alt="nk"/><br />nk</a></td>
<td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="139" alt="supastarter"/><br />supastarter</a></td>
<td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&amp;v=4" width="139" alt="Dexter Miguel"/><br />Dexter Miguel</a></td>
<td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&amp;v=4" width="139" alt="herrfugbaum"/><br />herrfugbaum</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="119" alt="David Cramer"/><br />David Cramer</a></td>
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="119" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
<td align="center"><a href="https://github.com/happyboy2022?ref=orpc" target="_blank" rel="noopener" title="happyboy"><img src="https://avatars.githubusercontent.com/u/103669586?u=65b49c4b893ed3703909fbb3a7a22313f3f9c121&amp;v=4" width="119" alt="happyboy"/><br />happyboy</a></td>
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="119" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="119" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
<td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="119" alt="Andrew Peters"/><br />Andrew Peters</a></td>
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="119" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
<td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&amp;v=4" width="139" alt="Ryota Murakami"/><br />Ryota Murakami</a></td>
<td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="139" alt="David Cramer"/><br />David Cramer</a></td>
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
<td align="center"><a href="https://github.com/happyboy2022?ref=orpc" target="_blank" rel="noopener" title="happyboy"><img src="https://avatars.githubusercontent.com/u/103669586?u=65b49c4b893ed3703909fbb3a7a22313f3f9c121&amp;v=4" width="139" alt="happyboy"/><br />happyboy</a></td>
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="119" alt="Peter Adam"/><br />Peter Adam</a></td>
<td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&amp;v=4" width="119" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td>
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="119" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
<td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
<td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="139" alt="Peter Adam"/><br />Peter Adam</a></td>
<td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&amp;v=4" width="139" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td>
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
</tr>

@@ -194,17 +186,18 @@ </table>

<tr>
<td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&amp;v=4" width="104" alt="David Walsh"/><br />David Walsh</a></td>
<td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&amp;v=4" width="104" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
<td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="104" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
<td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&amp;v=4" width="104" alt="soonoo"/><br />soonoo</a></td>
<td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&amp;v=4" width="104" alt="Kevin Porten"/><br />Kevin Porten</a></td>
<td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="104" alt="Denis"/><br />Denis</a></td>
<td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?v=4" width="104" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
<td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="104" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
<td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&amp;v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td>
<td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&amp;v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td>
<td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td>
<td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&amp;v=4" width="119" alt="soonoo"/><br />soonoo</a></td>
<td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&amp;v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td>
<td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="119" alt="Denis"/><br />Denis</a></td>
<td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="104" alt="Sam"/><br />Sam</a></td>
<td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="104" alt="Titoine"/><br />Titoine</a></td>
<td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="104" alt="Igor Makowski"/><br />Igor Makowski</a></td>
<td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&amp;v=4" width="104" alt="Anees Iqbal"/><br />Anees Iqbal</a></td>
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="104" alt="Alex"/><br />Alex</a></td>
<td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
<td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="119" alt="Sam"/><br />Sam</a></td>
<td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="119" alt="Titoine"/><br />Titoine</a></td>
<td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td>
<td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&amp;v=4" width="119" alt="Anees Iqbal"/><br />Anees Iqbal</a></td>
<td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="wang chenyu"><img src="https://avatars.githubusercontent.com/u/26056783?u=98c5ceda64b19874ed2a31515467332ea991e590&amp;v=4" width="119" alt="wang chenyu"/><br />wang chenyu</a></td>
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="119" alt="Alex"/><br />Alex</a></td>
</tr>

@@ -218,2 +211,3 @@ </table>

<a href="https://github.com/Stijn-Timmer?ref=orpc" target="_blank" rel="noopener" title="Stijn Timmer"><img src="https://avatars.githubusercontent.com/u/100147665?u=106b2c18e9c98a61861b4ee7fc100f5b9906a6c9&amp;v=4" width="32" height="32" alt="Stijn Timmer" /></a>
<a href="https://github.com/zuplo?ref=orpc" target="_blank" rel="noopener" title="Zuplo"><img src="https://avatars.githubusercontent.com/u/85497839?v=4" width="32" height="32" alt="Zuplo" /></a>
<a href="https://github.com/motopods?ref=orpc" target="_blank" rel="noopener" title="motopods"><img src="https://avatars.githubusercontent.com/u/58200641?u=18833983d65b481ae90a4adec2373064ec58bcf3&amp;v=4" width="32" height="32" alt="motopods" /></a>

@@ -220,0 +214,0 @@ <a href="https://github.com/franciscohermida?ref=orpc" target="_blank" rel="noopener" title="Francisco Hermida"><img src="https://avatars.githubusercontent.com/u/483242?u=bbcbc80eb9d8781ff401f7dafc3b59cd7bea0561&amp;v=4" width="32" height="32" alt="Francisco Hermida" /></a>

import { toHttpPath, StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
import { ORPCError, toORPCError } from '@orpc/client';
import { toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, parseEmptyableJSON, NullProtoObj, value } from '@orpc/shared';
import { flattenHeader } from '@orpc/standard-server';
import { c as createProcedureClient, t as traverseContractProcedures, i as isProcedure, u as unlazy, g as getRouter, a as createContractedProcedure } from './server.Ds4HPpvH.mjs';
class CompositeStandardHandlerPlugin {
plugins;
constructor(plugins = []) {
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
}
init(options, router) {
for (const plugin of this.plugins) {
plugin.init?.(options, router);
}
}
}
class StandardHandler {
constructor(router, matcher, codec, options) {
this.matcher = matcher;
this.codec = codec;
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
plugins.init(options, router);
this.interceptors = toArray(options.interceptors);
this.clientInterceptors = toArray(options.clientInterceptors);
this.rootInterceptors = toArray(options.rootInterceptors);
this.matcher.init(router);
}
interceptors;
clientInterceptors;
rootInterceptors;
async handle(request, options) {
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
return { matched: false, response: void 0 };
}
return intercept(
this.rootInterceptors,
{ ...options, request, prefix },
async (interceptorOptions) => {
return runWithSpan(
{ name: `${request.method} ${request.url.pathname}` },
async (span) => {
let step;
try {
return await intercept(
this.interceptors,
interceptorOptions,
async ({ request: request2, context, prefix: prefix2 }) => {
const method = request2.method;
const url = request2.url;
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
const match = await runWithSpan(
{ name: "find_procedure" },
() => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
);
if (!match) {
return { matched: false, response: void 0 };
}
span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
span?.setAttribute("rpc.system", ORPC_NAME);
span?.setAttribute("rpc.method", match.path.join("."));
step = "decode_input";
let input = await runWithSpan(
{ name: "decode_input" },
() => this.codec.decode(request2, match.params, match.procedure)
);
step = void 0;
if (isAsyncIteratorObject(input)) {
input = asyncIteratorWithSpan(
{ name: "consume_event_iterator_input", signal: request2.signal },
input
);
}
const client = createProcedureClient(match.procedure, {
context,
path: match.path,
interceptors: this.clientInterceptors
});
step = "call_procedure";
const output = await client(input, {
signal: request2.signal,
lastEventId: flattenHeader(request2.headers["last-event-id"])
});
step = void 0;
const response = this.codec.encode(output, match.procedure);
return {
matched: true,
response
};
}
);
} catch (e) {
if (step !== "call_procedure") {
setSpanError(span, e);
}
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
cause: e
}) : toORPCError(e);
const response = this.codec.encodeError(error);
return {
matched: true,
response
};
}
}
);
}
);
}
}
class StandardRPCCodec {
constructor(serializer) {
this.serializer = serializer;
}
async decode(request, _params, _procedure) {
const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
return this.serializer.deserialize(serialized);
}
encode(output, _procedure) {
return {
status: 200,
headers: {},
body: this.serializer.serialize(output)
};
}
encodeError(error) {
return {
status: error.status,
headers: {},
body: this.serializer.serialize(error.toJSON())
};
}
}
class StandardRPCMatcher {
filter;
tree = new NullProtoObj();
pendingRouters = [];
constructor(options = {}) {
this.filter = options.filter ?? true;
}
init(router, path = []) {
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
if (!value(this.filter, traverseOptions)) {
return;
}
const { path: path2, contract } = traverseOptions;
const httpPath = toHttpPath(path2);
if (isProcedure(contract)) {
this.tree[httpPath] = {
path: path2,
contract,
procedure: contract,
// this mean dev not used contract-first so we can used contract as procedure directly
router
};
} else {
this.tree[httpPath] = {
path: path2,
contract,
procedure: void 0,
router
};
}
});
this.pendingRouters.push(...laziedOptions.map((option) => ({
...option,
httpPathPrefix: toHttpPath(option.path)
})));
}
async match(_method, pathname) {
if (this.pendingRouters.length) {
const newPendingRouters = [];
for (const pendingRouter of this.pendingRouters) {
if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
const { default: router } = await unlazy(pendingRouter.router);
this.init(router, pendingRouter.path);
} else {
newPendingRouters.push(pendingRouter);
}
}
this.pendingRouters = newPendingRouters;
}
const match = this.tree[pathname];
if (!match) {
return void 0;
}
if (!match.procedure) {
const { default: maybeProcedure } = await unlazy(getRouter(match.router, match.path));
if (!isProcedure(maybeProcedure)) {
throw new Error(`
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.path)}.
Ensure that the procedure is correctly defined and matches the expected contract.
`);
}
match.procedure = createContractedProcedure(maybeProcedure, match.contract);
}
return {
path: match.path,
procedure: match.procedure
};
}
}
class StandardRPCHandler extends StandardHandler {
constructor(router, options = {}) {
const jsonSerializer = new StandardRPCJsonSerializer(options);
const serializer = new StandardRPCSerializer(jsonSerializer);
const matcher = new StandardRPCMatcher(options);
const codec = new StandardRPCCodec(serializer);
super(router, matcher, codec, options);
}
}
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, StandardRPCCodec as a, StandardRPCHandler as b, StandardRPCMatcher as c };
import { isContractProcedure, validateORPCError, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@orpc/shared';
import { ORPCError, mapEventIterator } from '@orpc/client';
import { HibernationEventIterator } from '@orpc/standard-server';
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
function lazy(loader, meta = {}) {
return {
[LAZY_SYMBOL]: {
loader,
meta
}
};
}
function isLazy(item) {
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
}
function getLazyMeta(lazied) {
return lazied[LAZY_SYMBOL].meta;
}
function unlazy(lazied) {
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
}
function isStartWithMiddlewares(middlewares, compare) {
if (compare.length > middlewares.length) {
return false;
}
for (let i = 0; i < middlewares.length; i++) {
if (compare[i] === void 0) {
return true;
}
if (middlewares[i] !== compare[i]) {
return false;
}
}
return true;
}
function mergeMiddlewares(first, second, options) {
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
return second;
}
return [...first, ...second];
}
function addMiddleware(middlewares, addition) {
return [...middlewares, addition];
}
class Procedure {
/**
* This property holds the defined options.
*/
"~orpc";
constructor(def) {
this["~orpc"] = def;
}
}
function isProcedure(item) {
if (item instanceof Procedure) {
return true;
}
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
}
function mergeCurrentContext(context, other) {
return { ...context, ...other };
}
function createORPCErrorConstructorMap(errors) {
const proxy = new Proxy(errors, {
get(target, code) {
if (typeof code !== "string") {
return Reflect.get(target, code);
}
const item = (...rest) => {
const options = resolveMaybeOptionalOptions(rest);
const config = errors[code];
return new ORPCError(code, {
defined: Boolean(config),
status: config?.status,
message: options.message ?? config?.message,
data: options.data,
cause: options.cause
});
};
return item;
}
});
return proxy;
}
function middlewareOutputFn(output) {
return { output, context: {} };
}
function createProcedureClient(lazyableProcedure, ...rest) {
const options = resolveMaybeOptionalOptions(rest);
return async (...[input, callerOptions]) => {
const path = toArray(options.path);
const { default: procedure } = await unlazy(lazyableProcedure);
const clientContext = callerOptions?.context ?? {};
const context = await value(options.context ?? {}, clientContext);
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
const validateError = async (e) => {
if (e instanceof ORPCError) {
return await validateORPCError(procedure["~orpc"].errorMap, e);
}
return e;
};
try {
const output = await runWithSpan(
{ name: "call_procedure", signal: callerOptions?.signal },
(span) => {
span?.setAttribute("procedure.path", [...path]);
return intercept(
toArray(options.interceptors),
{
context,
input,
// input only optional when it undefinable so we can safely cast it
errors,
path,
procedure,
signal: callerOptions?.signal,
lastEventId: callerOptions?.lastEventId
},
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
);
}
);
if (isAsyncIteratorObject(output)) {
if (output instanceof HibernationEventIterator) {
return output;
}
return overlayProxy(output, mapEventIterator(
asyncIteratorWithSpan(
{ name: "consume_event_iterator_output", signal: callerOptions?.signal },
output
),
{
value: (v) => v,
error: (e) => validateError(e)
}
));
}
return output;
} catch (e) {
throw await validateError(e);
}
};
}
async function validateInput(procedure, input) {
const schema = procedure["~orpc"].inputSchema;
if (!schema) {
return input;
}
return runWithSpan(
{ name: "validate_input" },
async () => {
const result = await schema["~standard"].validate(input);
if (result.issues) {
throw new ORPCError("BAD_REQUEST", {
message: "Input validation failed",
data: {
issues: result.issues
},
cause: new ValidationError({
message: "Input validation failed",
issues: result.issues,
data: input
})
});
}
return result.value;
}
);
}
async function validateOutput(procedure, output) {
const schema = procedure["~orpc"].outputSchema;
if (!schema) {
return output;
}
return runWithSpan(
{ name: "validate_output" },
async () => {
const result = await schema["~standard"].validate(output);
if (result.issues) {
throw new ORPCError("INTERNAL_SERVER_ERROR", {
message: "Output validation failed",
cause: new ValidationError({
message: "Output validation failed",
issues: result.issues,
data: output
})
});
}
return result.value;
}
);
}
async function executeProcedureInternal(procedure, options) {
const middlewares = procedure["~orpc"].middlewares;
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
const next = async (index, context, input) => {
let currentInput = input;
if (index === inputValidationIndex) {
currentInput = await validateInput(procedure, currentInput);
}
const mid = middlewares[index];
const output = mid ? await runWithSpan(
{ name: `middleware.${mid.name}`, signal: options.signal },
async (span) => {
span?.setAttribute("middleware.index", index);
span?.setAttribute("middleware.name", mid.name);
const result = await mid({
...options,
context,
next: async (...[nextOptions]) => {
const nextContext = nextOptions?.context ?? {};
return {
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
context: nextContext
};
}
}, currentInput, middlewareOutputFn);
return result.output;
}
) : await runWithSpan(
{ name: "handler", signal: options.signal },
() => procedure["~orpc"].handler({ ...options, context, input: currentInput })
);
if (index === outputValidationIndex) {
return await validateOutput(procedure, output);
}
return output;
};
return next(0, options.context, options.input);
}
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
function setHiddenRouterContract(router, contract) {
return new Proxy(router, {
get(target, key) {
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
return contract;
}
return Reflect.get(target, key);
}
});
}
function getHiddenRouterContract(router) {
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
}
function getRouter(router, path) {
let current = router;
for (let i = 0; i < path.length; i++) {
const segment = path[i];
if (!current) {
return void 0;
}
if (isProcedure(current)) {
return void 0;
}
if (!isLazy(current)) {
current = current[segment];
continue;
}
const lazied = current;
const rest = path.slice(i);
return lazy(async () => {
const unwrapped = await unlazy(lazied);
const next = getRouter(unwrapped.default, rest);
return unlazy(next);
}, getLazyMeta(lazied));
}
return current;
}
function createAccessibleLazyRouter(lazied) {
const recursive = new Proxy(lazied, {
get(target, key) {
if (typeof key !== "string") {
return Reflect.get(target, key);
}
const next = getRouter(lazied, [key]);
return createAccessibleLazyRouter(next);
}
});
return recursive;
}
function enhanceRouter(router, options) {
if (isLazy(router)) {
const laziedMeta = getLazyMeta(router);
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
const enhanced2 = lazy(async () => {
const { default: unlaziedRouter } = await unlazy(router);
const enhanced3 = enhanceRouter(unlaziedRouter, options);
return unlazy(enhanced3);
}, {
...laziedMeta,
prefix: enhancedPrefix
});
const accessible = createAccessibleLazyRouter(enhanced2);
return accessible;
}
if (isProcedure(router)) {
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
const enhanced2 = new Procedure({
...router["~orpc"],
route: enhanceRoute(router["~orpc"].route, options),
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
middlewares: newMiddlewares,
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
});
return enhanced2;
}
const enhanced = {};
for (const key in router) {
enhanced[key] = enhanceRouter(router[key], options);
}
return enhanced;
}
function traverseContractProcedures(options, callback, lazyOptions = []) {
let currentRouter = options.router;
const hiddenContract = getHiddenRouterContract(options.router);
if (hiddenContract !== void 0) {
currentRouter = hiddenContract;
}
if (isLazy(currentRouter)) {
lazyOptions.push({
router: currentRouter,
path: options.path
});
} else if (isContractProcedure(currentRouter)) {
callback({
contract: currentRouter,
path: options.path
});
} else {
for (const key in currentRouter) {
traverseContractProcedures(
{
router: currentRouter[key],
path: [...options.path, key]
},
callback,
lazyOptions
);
}
}
return lazyOptions;
}
async function resolveContractProcedures(options, callback) {
const pending = [options];
for (const options2 of pending) {
const lazyOptions = traverseContractProcedures(options2, callback);
for (const options3 of lazyOptions) {
const { default: router } = await unlazy(options3.router);
pending.push({
router,
path: options3.path
});
}
}
}
async function unlazyRouter(router) {
if (isProcedure(router)) {
return router;
}
const unlazied = {};
for (const key in router) {
const item = router[key];
const { default: unlaziedRouter } = await unlazy(item);
unlazied[key] = await unlazyRouter(unlaziedRouter);
}
return unlazied;
}
function createAssertedLazyProcedure(lazied) {
const lazyProcedure = lazy(async () => {
const { default: maybeProcedure } = await unlazy(lazied);
if (!isProcedure(maybeProcedure)) {
throw new Error(`
Expected a lazy<procedure> but got lazy<unknown>.
This should be caught by TypeScript compilation.
Please report this issue if this makes you feel uncomfortable.
`);
}
return { default: maybeProcedure };
}, getLazyMeta(lazied));
return lazyProcedure;
}
function createContractedProcedure(procedure, contract) {
return new Procedure({
...procedure["~orpc"],
errorMap: contract["~orpc"].errorMap,
route: contract["~orpc"].route,
meta: contract["~orpc"].meta
});
}
function call(procedure, input, ...rest) {
const options = resolveMaybeOptionalOptions(rest);
return createProcedureClient(procedure, options)(input, options);
}
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, resolveContractProcedures as v, unlazyRouter as w };