{"version":3,"file":"action-handler.mjs","names":[],"sources":["../src/action-handler.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       🗲 Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { MaybePromise } from \"@stryke/types\";\nimport { experimental_createServerActionHandler } from \"@trpc/next/app-dir/server\";\nimport type {\n  AnyRootTypes,\n  RootConfig\n} from \"@trpc/server/unstable-core-do-not-import\";\nimport defu from \"defu\";\nimport type { ReadonlyRequestCookies } from \"next/dist/server/web/spec-extension/adapters/request-cookies\";\nimport type { BaseContext } from \"./types\";\n\n/**\n * This client invokes procedures directly on the server without fetching over HTTP.\n *\n * @param cookies - A function that returns the cookies to be passed to the API\n * @param t - The tRPC instance\n * @param createContext - An optional function to generate a context\n */\nexport function createTRPCServerActionHandler<\n  TInstance extends {\n    _config: RootConfig<AnyRootTypes>;\n  },\n  TContext extends BaseContext = BaseContext\n>(\n  cookies: () => Promise<ReadonlyRequestCookies>,\n  t: TInstance,\n  createContext: () => MaybePromise<TContext> = async () => ({}) as TContext\n) {\n  return experimental_createServerActionHandler(t, {\n    createContext: async () => {\n      const context = await Promise.resolve(createContext());\n\n      return defu(context, {\n        headers: {\n          // Pass the cookie header to the API\n          cookies: (await cookies()).toString() ?? \"\"\n        }\n      });\n    }\n  });\n}\n"],"mappings":";;;;;;;;;;;AAmCA,SAAgB,8BAMd,SACA,GACA,gBAA8C,aAAa,CAAC,IAC5D;CACA,OAAO,uCAAuC,GAAG,EAC/C,eAAe,YAAY;EACzB,MAAM,UAAU,MAAM,QAAQ,QAAQ,cAAc,CAAC;EAErD,OAAO,KAAK,SAAS,EACnB,SAAS,EAEP,UAAU,MAAM,QAAQ,EAAC,CAAE,SAAS,KAAK,GAC3C,EACF,CAAC;CACH,EACF,CAAC;AACH"}