{"version":3,"file":"parseTRPCMessage-MJWDg1vX.mjs","names":[],"sources":["../src/unstable-core-do-not-import/procedure.ts","../src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts"],"sourcesContent":["import type { TRPCError } from './error/TRPCError';\nimport type { Parser } from './parser';\nimport type { ProcedureCallOptions } from './procedureBuilder';\nimport type { inferAsyncIterableYield } from './types';\n\nexport const procedureTypes = ['query', 'mutation', 'subscription'] as const;\n/**\n * @public\n */\nexport type ProcedureType = (typeof procedureTypes)[number];\n\ninterface BuiltProcedureDef {\n  meta: unknown;\n  input: unknown;\n  output: unknown;\n}\n\n/**\n *\n * @internal\n */\nexport interface Procedure<\n  TType extends ProcedureType,\n  TDef extends BuiltProcedureDef,\n> {\n  _def: {\n    /**\n     * These are just types, they can't be used at runtime\n     * @internal\n     */\n    $types: {\n      input: TDef['input'];\n      output: TDef['output'];\n    };\n    procedure: true;\n    type: TType;\n    /**\n     * @internal\n     * Meta is not inferrable on individual procedures, only on the router\n     */\n    meta: unknown;\n    experimental_caller: boolean;\n    /**\n     * The input parsers for the procedure\n     */\n    inputs: Parser[];\n  };\n  meta: TDef['meta'];\n  /**\n   * @internal\n   */\n  (opts: ProcedureCallOptions<unknown>): Promise<TDef['output']>;\n}\n\nexport interface QueryProcedure<\n  TDef extends BuiltProcedureDef,\n> extends Procedure<'query', TDef> {}\n\nexport interface MutationProcedure<\n  TDef extends BuiltProcedureDef,\n> extends Procedure<'mutation', TDef> {}\n\nexport interface SubscriptionProcedure<\n  TDef extends BuiltProcedureDef,\n> extends Procedure<'subscription', TDef> {}\n\n/**\n * @deprecated\n */\nexport interface LegacyObservableSubscriptionProcedure<\n  TDef extends BuiltProcedureDef,\n> extends SubscriptionProcedure<TDef> {\n  _observable: true;\n}\n\nexport type AnyQueryProcedure = QueryProcedure<any>;\nexport type AnyMutationProcedure = MutationProcedure<any>;\nexport type AnySubscriptionProcedure =\n  SubscriptionProcedure<any> | LegacyObservableSubscriptionProcedure<any>;\n\nexport type AnyProcedure =\n  AnyQueryProcedure | AnyMutationProcedure | AnySubscriptionProcedure;\n\nexport type inferProcedureInput<TProcedure extends AnyProcedure> =\n  undefined extends inferProcedureParams<TProcedure>['$types']['input']\n    ? void | inferProcedureParams<TProcedure>['$types']['input']\n    : inferProcedureParams<TProcedure>['$types']['input'];\n\nexport type inferProcedureParams<TProcedure> = TProcedure extends AnyProcedure\n  ? TProcedure['_def']\n  : never;\nexport type inferProcedureOutput<TProcedure> =\n  inferProcedureParams<TProcedure>['$types']['output'];\n\nexport type inferSubscriptionInput<\n  TProcedure extends AnySubscriptionProcedure,\n> = inferProcedureInput<TProcedure>;\n\nexport type inferSubscriptionOutput<\n  TProcedure extends AnySubscriptionProcedure,\n> =\n  TProcedure extends LegacyObservableSubscriptionProcedure<any>\n    ? inferProcedureOutput<TProcedure>\n    : inferAsyncIterableYield<inferProcedureOutput<TProcedure>>;\n\n/**\n * @internal\n */\nexport interface ErrorHandlerOptions<TContext> {\n  error: TRPCError;\n  type: ProcedureType | 'unknown';\n  path: string | undefined;\n  input: unknown;\n  ctx: TContext | undefined;\n}\n","import { procedureTypes, type ProcedureType } from '../procedure';\nimport type { CombinedDataTransformer } from '../transformer';\nimport { isObject } from '../utils';\nimport type { TRPCClientOutgoingMessage } from './envelopes';\n\n/* istanbul ignore next -- @preserve */\nfunction assertIsObject(obj: unknown): asserts obj is Record<string, unknown> {\n  if (!isObject(obj)) {\n    throw new Error('Not an object');\n  }\n}\n\n/* istanbul ignore next -- @preserve */\nfunction assertIsProcedureType(obj: unknown): asserts obj is ProcedureType {\n  if (!procedureTypes.includes(obj as any)) {\n    throw new Error('Invalid procedure type');\n  }\n}\n\n/* istanbul ignore next -- @preserve */\nfunction assertIsRequestId(\n  obj: unknown,\n): asserts obj is number | string | null {\n  if (\n    obj !== null &&\n    typeof obj !== 'string' &&\n    (typeof obj !== 'number' || isNaN(obj))\n  ) {\n    throw new Error('Invalid request id');\n  }\n}\n\n/* istanbul ignore next -- @preserve */\nfunction assertIsString(obj: unknown): asserts obj is string {\n  if (typeof obj !== 'string') {\n    throw new Error('Invalid string');\n  }\n}\n\n/* istanbul ignore next -- @preserve */\nfunction assertIsJSONRPC2OrUndefined(\n  obj: unknown,\n): asserts obj is '2.0' | undefined {\n  if (typeof obj !== 'undefined' && obj !== '2.0') {\n    throw new Error('Must be JSONRPC 2.0');\n  }\n}\n\n/** @public */\nexport function parseTRPCMessage(\n  obj: unknown,\n  transformer: CombinedDataTransformer,\n): TRPCClientOutgoingMessage {\n  assertIsObject(obj);\n\n  const { id, jsonrpc, method, params } = obj;\n  assertIsRequestId(id);\n  assertIsJSONRPC2OrUndefined(jsonrpc);\n\n  if (method === 'subscription.stop') {\n    return {\n      id,\n      jsonrpc,\n      method,\n    };\n  }\n  assertIsProcedureType(method);\n  assertIsObject(params);\n  const { input: rawInput, path, lastEventId } = params;\n\n  assertIsString(path);\n  if (lastEventId !== undefined) {\n    assertIsString(lastEventId);\n  }\n\n  const input = transformer.input.deserialize(rawInput);\n\n  return {\n    id,\n    jsonrpc,\n    method,\n    params: {\n      input,\n      path,\n      lastEventId,\n    },\n  };\n}\n"],"mappings":";;AAKA,MAAa,iBAAiB;CAAC;CAAS;CAAY;AAAc;;;;ACClE,SAAS,eAAe,KAAsD;CAC5E,IAAI,CAAC,SAAS,GAAG,GACf,MAAM,IAAI,MAAM,eAAe;AAEnC;;AAGA,SAAS,sBAAsB,KAA4C;CACzE,IAAI,CAAC,eAAe,SAAS,GAAU,GACrC,MAAM,IAAI,MAAM,wBAAwB;AAE5C;;AAGA,SAAS,kBACP,KACuC;CACvC,IACE,QAAQ,QACR,OAAO,QAAQ,aACd,OAAO,QAAQ,YAAY,MAAM,GAAG,IAErC,MAAM,IAAI,MAAM,oBAAoB;AAExC;;AAGA,SAAS,eAAe,KAAqC;CAC3D,IAAI,OAAO,QAAQ,UACjB,MAAM,IAAI,MAAM,gBAAgB;AAEpC;;AAGA,SAAS,4BACP,KACkC;CAClC,IAAI,OAAO,QAAQ,eAAe,QAAQ,OACxC,MAAM,IAAI,MAAM,qBAAqB;AAEzC;;AAGA,SAAgB,iBACd,KACA,aAC2B;CAC3B,eAAe,GAAG;CAElB,MAAM,EAAE,IAAI,SAAS,QAAQ,WAAW;CACxC,kBAAkB,EAAE;CACpB,4BAA4B,OAAO;CAEnC,IAAI,WAAW,qBACb,OAAO;EACL;EACA;EACA;CACF;CAEF,sBAAsB,MAAM;CAC5B,eAAe,MAAM;CACrB,MAAM,EAAE,OAAO,UAAU,MAAM,gBAAgB;CAE/C,eAAe,IAAI;CACnB,IAAI,gBAAgB,KAAA,GAClB,eAAe,WAAW;CAK5B,OAAO;EACL;EACA;EACA;EACA,QAAQ;GACN,OAPU,YAAY,MAAM,YAAY,QAOpC;GACJ;GACA;EACF;CACF;AACF"}