UNPKG

@trpc/server

Version:

The tRPC server library

60 lines (59 loc) 1.78 kB
import { u as isObject } from "./codes-D5Ya6_Bi.mjs"; //#region src/unstable-core-do-not-import/procedure.ts const procedureTypes = [ "query", "mutation", "subscription" ]; //#endregion //#region src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts /* istanbul ignore next -- @preserve */ function assertIsObject(obj) { if (!isObject(obj)) throw new Error("Not an object"); } /* istanbul ignore next -- @preserve */ function assertIsProcedureType(obj) { if (!procedureTypes.includes(obj)) throw new Error("Invalid procedure type"); } /* istanbul ignore next -- @preserve */ function assertIsRequestId(obj) { if (obj !== null && typeof obj !== "string" && (typeof obj !== "number" || isNaN(obj))) throw new Error("Invalid request id"); } /* istanbul ignore next -- @preserve */ function assertIsString(obj) { if (typeof obj !== "string") throw new Error("Invalid string"); } /* istanbul ignore next -- @preserve */ function assertIsJSONRPC2OrUndefined(obj) { if (typeof obj !== "undefined" && obj !== "2.0") throw new Error("Must be JSONRPC 2.0"); } /** @public */ function parseTRPCMessage(obj, transformer) { assertIsObject(obj); const { id, jsonrpc, method, params } = obj; assertIsRequestId(id); assertIsJSONRPC2OrUndefined(jsonrpc); if (method === "subscription.stop") return { id, jsonrpc, method }; assertIsProcedureType(method); assertIsObject(params); const { input: rawInput, path, lastEventId } = params; assertIsString(path); if (lastEventId !== void 0) assertIsString(lastEventId); return { id, jsonrpc, method, params: { input: transformer.input.deserialize(rawInput), path, lastEventId } }; } //#endregion export { procedureTypes as n, parseTRPCMessage as t }; //# sourceMappingURL=parseTRPCMessage-MJWDg1vX.mjs.map