@orpc/server 0.0.0-next.2f8ca7f → 0.0.0-next.31590a1
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/dist/chunk-CVIWJKJC.js +308 -0
- package/dist/chunk-EYGVJA7A.js +136 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/chunk-OXB4YX67.js +111 -0
- package/dist/fetch.js +14 -108
- package/dist/hono.js +42 -0
- package/dist/index.js +312 -375
- package/dist/next.js +39 -0
- package/dist/node.js +175 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +4 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +13 -0
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +4 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +21 -0
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +47 -0
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
- package/dist/src/adapters/standard/types.d.ts +44 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +46 -42
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +16 -10
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +13 -14
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -17
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +18 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +20 -0
- package/dist/src/procedure-decorated.d.ts +21 -0
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +25 -28
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +22 -0
- package/dist/src/router.d.ts +25 -17
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +17 -0
- package/package.json +34 -9
- package/dist/chunk-3JMSDC5L.js +0 -274
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -28
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/router-builder.d.ts +0 -27
- package/dist/src/router-caller.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/types.d.ts +0 -14
| @@ -0,0 +1,380 @@ | |
| 1 | 
            +
            // src/lazy.ts
         | 
| 2 | 
            +
            var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
         | 
| 3 | 
            +
            function lazy(loader) {
         | 
| 4 | 
            +
              return {
         | 
| 5 | 
            +
                [LAZY_LOADER_SYMBOL]: loader
         | 
| 6 | 
            +
              };
         | 
| 7 | 
            +
            }
         | 
| 8 | 
            +
            function isLazy(item) {
         | 
| 9 | 
            +
              return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
         | 
| 10 | 
            +
            }
         | 
| 11 | 
            +
            function unlazy(lazied) {
         | 
| 12 | 
            +
              return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
         | 
| 13 | 
            +
            }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            // src/procedure.ts
         | 
| 16 | 
            +
            import { isContractProcedure } from "@orpc/contract";
         | 
| 17 | 
            +
            var Procedure = class {
         | 
| 18 | 
            +
              "~orpc";
         | 
| 19 | 
            +
              constructor(def) {
         | 
| 20 | 
            +
                this["~orpc"] = def;
         | 
| 21 | 
            +
              }
         | 
| 22 | 
            +
            };
         | 
| 23 | 
            +
            function isProcedure(item) {
         | 
| 24 | 
            +
              if (item instanceof Procedure) {
         | 
| 25 | 
            +
                return true;
         | 
| 26 | 
            +
              }
         | 
| 27 | 
            +
              return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
         | 
| 28 | 
            +
            }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            // src/lazy-utils.ts
         | 
| 31 | 
            +
            function flatLazy(lazied) {
         | 
| 32 | 
            +
              const flattenLoader = async () => {
         | 
| 33 | 
            +
                let current = await unlazy(lazied);
         | 
| 34 | 
            +
                while (true) {
         | 
| 35 | 
            +
                  if (!isLazy(current.default)) {
         | 
| 36 | 
            +
                    break;
         | 
| 37 | 
            +
                  }
         | 
| 38 | 
            +
                  current = await unlazy(current.default);
         | 
| 39 | 
            +
                }
         | 
| 40 | 
            +
                return current;
         | 
| 41 | 
            +
              };
         | 
| 42 | 
            +
              return lazy(flattenLoader);
         | 
| 43 | 
            +
            }
         | 
| 44 | 
            +
            function createLazyProcedureFormAnyLazy(lazied) {
         | 
| 45 | 
            +
              const lazyProcedure = lazy(async () => {
         | 
| 46 | 
            +
                const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
         | 
| 47 | 
            +
                if (!isProcedure(maybeProcedure)) {
         | 
| 48 | 
            +
                  throw new Error(`
         | 
| 49 | 
            +
                        Expected a lazy<procedure> but got lazy<unknown>.
         | 
| 50 | 
            +
                        This should be caught by TypeScript compilation.
         | 
| 51 | 
            +
                        Please report this issue if this makes you feel uncomfortable.
         | 
| 52 | 
            +
                    `);
         | 
| 53 | 
            +
                }
         | 
| 54 | 
            +
                return { default: maybeProcedure };
         | 
| 55 | 
            +
              });
         | 
| 56 | 
            +
              return lazyProcedure;
         | 
| 57 | 
            +
            }
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            // src/middleware.ts
         | 
| 60 | 
            +
            function middlewareOutputFn(output) {
         | 
| 61 | 
            +
              return { output, context: {} };
         | 
| 62 | 
            +
            }
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            // src/procedure-client.ts
         | 
| 65 | 
            +
            import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
         | 
| 66 | 
            +
            import { executeWithHooks, toError, value } from "@orpc/shared";
         | 
| 67 | 
            +
            function createProcedureClient(lazyableProcedure, ...[options]) {
         | 
| 68 | 
            +
              return async (...[input, callerOptions]) => {
         | 
| 69 | 
            +
                const path = options?.path ?? [];
         | 
| 70 | 
            +
                const { default: procedure } = await unlazy(lazyableProcedure);
         | 
| 71 | 
            +
                const context = await value(options?.context ?? {}, callerOptions?.context);
         | 
| 72 | 
            +
                const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
         | 
| 73 | 
            +
                const executeOptions = {
         | 
| 74 | 
            +
                  input,
         | 
| 75 | 
            +
                  context,
         | 
| 76 | 
            +
                  errors,
         | 
| 77 | 
            +
                  path,
         | 
| 78 | 
            +
                  procedure,
         | 
| 79 | 
            +
                  signal: callerOptions?.signal
         | 
| 80 | 
            +
                };
         | 
| 81 | 
            +
                try {
         | 
| 82 | 
            +
                  const output = await executeWithHooks({
         | 
| 83 | 
            +
                    hooks: options,
         | 
| 84 | 
            +
                    input,
         | 
| 85 | 
            +
                    context,
         | 
| 86 | 
            +
                    meta: executeOptions,
         | 
| 87 | 
            +
                    execute: () => executeProcedureInternal(procedure, executeOptions)
         | 
| 88 | 
            +
                  });
         | 
| 89 | 
            +
                  return output;
         | 
| 90 | 
            +
                } catch (e) {
         | 
| 91 | 
            +
                  if (!(e instanceof ORPCError)) {
         | 
| 92 | 
            +
                    throw toError(e);
         | 
| 93 | 
            +
                  }
         | 
| 94 | 
            +
                  const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
         | 
| 95 | 
            +
                  throw validated;
         | 
| 96 | 
            +
                }
         | 
| 97 | 
            +
              };
         | 
| 98 | 
            +
            }
         | 
| 99 | 
            +
            async function validateInput(procedure, input) {
         | 
| 100 | 
            +
              const schema = procedure["~orpc"].inputSchema;
         | 
| 101 | 
            +
              if (!schema) {
         | 
| 102 | 
            +
                return input;
         | 
| 103 | 
            +
              }
         | 
| 104 | 
            +
              const result = await schema["~standard"].validate(input);
         | 
| 105 | 
            +
              if (result.issues) {
         | 
| 106 | 
            +
                throw new ORPCError("BAD_REQUEST", {
         | 
| 107 | 
            +
                  message: "Input validation failed",
         | 
| 108 | 
            +
                  data: {
         | 
| 109 | 
            +
                    issues: result.issues
         | 
| 110 | 
            +
                  },
         | 
| 111 | 
            +
                  cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
         | 
| 112 | 
            +
                });
         | 
| 113 | 
            +
              }
         | 
| 114 | 
            +
              return result.value;
         | 
| 115 | 
            +
            }
         | 
| 116 | 
            +
            async function validateOutput(procedure, output) {
         | 
| 117 | 
            +
              const schema = procedure["~orpc"].outputSchema;
         | 
| 118 | 
            +
              if (!schema) {
         | 
| 119 | 
            +
                return output;
         | 
| 120 | 
            +
              }
         | 
| 121 | 
            +
              const result = await schema["~standard"].validate(output);
         | 
| 122 | 
            +
              if (result.issues) {
         | 
| 123 | 
            +
                throw new ORPCError("INTERNAL_SERVER_ERROR", {
         | 
| 124 | 
            +
                  message: "Output validation failed",
         | 
| 125 | 
            +
                  cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
         | 
| 126 | 
            +
                });
         | 
| 127 | 
            +
              }
         | 
| 128 | 
            +
              return result.value;
         | 
| 129 | 
            +
            }
         | 
| 130 | 
            +
            async function executeProcedureInternal(procedure, options) {
         | 
| 131 | 
            +
              const middlewares = procedure["~orpc"].middlewares;
         | 
| 132 | 
            +
              const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
         | 
| 133 | 
            +
              const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
         | 
| 134 | 
            +
              let currentIndex = 0;
         | 
| 135 | 
            +
              let currentContext = options.context;
         | 
| 136 | 
            +
              let currentInput = options.input;
         | 
| 137 | 
            +
              const next = async (...[nextOptions]) => {
         | 
| 138 | 
            +
                const index = currentIndex;
         | 
| 139 | 
            +
                currentIndex += 1;
         | 
| 140 | 
            +
                currentContext = { ...currentContext, ...nextOptions?.context };
         | 
| 141 | 
            +
                if (index === inputValidationIndex) {
         | 
| 142 | 
            +
                  currentInput = await validateInput(procedure, currentInput);
         | 
| 143 | 
            +
                }
         | 
| 144 | 
            +
                const mid = middlewares[index];
         | 
| 145 | 
            +
                const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
         | 
| 146 | 
            +
                if (index === outputValidationIndex) {
         | 
| 147 | 
            +
                  const validatedOutput = await validateOutput(procedure, result.output);
         | 
| 148 | 
            +
                  return {
         | 
| 149 | 
            +
                    ...result,
         | 
| 150 | 
            +
                    output: validatedOutput
         | 
| 151 | 
            +
                  };
         | 
| 152 | 
            +
                }
         | 
| 153 | 
            +
                return result;
         | 
| 154 | 
            +
              };
         | 
| 155 | 
            +
              return (await next({})).output;
         | 
| 156 | 
            +
            }
         | 
| 157 | 
            +
             | 
| 158 | 
            +
            // src/hidden.ts
         | 
| 159 | 
            +
            var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
         | 
| 160 | 
            +
            function setRouterContract(obj, contract) {
         | 
| 161 | 
            +
              return new Proxy(obj, {
         | 
| 162 | 
            +
                get(target, key) {
         | 
| 163 | 
            +
                  if (key === ROUTER_CONTRACT_SYMBOL) {
         | 
| 164 | 
            +
                    return contract;
         | 
| 165 | 
            +
                  }
         | 
| 166 | 
            +
                  return Reflect.get(target, key);
         | 
| 167 | 
            +
                }
         | 
| 168 | 
            +
              });
         | 
| 169 | 
            +
            }
         | 
| 170 | 
            +
            function getRouterContract(obj) {
         | 
| 171 | 
            +
              return obj[ROUTER_CONTRACT_SYMBOL];
         | 
| 172 | 
            +
            }
         | 
| 173 | 
            +
            var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
         | 
| 174 | 
            +
            function deepSetLazyRouterPrefix(router, prefix) {
         | 
| 175 | 
            +
              return new Proxy(router, {
         | 
| 176 | 
            +
                get(target, key) {
         | 
| 177 | 
            +
                  if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
         | 
| 178 | 
            +
                    const val = Reflect.get(target, key);
         | 
| 179 | 
            +
                    if (isLazy(val)) {
         | 
| 180 | 
            +
                      return deepSetLazyRouterPrefix(val, prefix);
         | 
| 181 | 
            +
                    }
         | 
| 182 | 
            +
                    return val;
         | 
| 183 | 
            +
                  }
         | 
| 184 | 
            +
                  return prefix;
         | 
| 185 | 
            +
                }
         | 
| 186 | 
            +
              });
         | 
| 187 | 
            +
            }
         | 
| 188 | 
            +
            function getLazyRouterPrefix(obj) {
         | 
| 189 | 
            +
              return obj[LAZY_ROUTER_PREFIX_SYMBOL];
         | 
| 190 | 
            +
            }
         | 
| 191 | 
            +
             | 
| 192 | 
            +
            // src/router.ts
         | 
| 193 | 
            +
            import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
         | 
| 194 | 
            +
             | 
| 195 | 
            +
            // src/middleware-utils.ts
         | 
| 196 | 
            +
            function dedupeMiddlewares(compare, middlewares) {
         | 
| 197 | 
            +
              let min = 0;
         | 
| 198 | 
            +
              for (let i = 0; i < middlewares.length; i++) {
         | 
| 199 | 
            +
                const index = compare.indexOf(middlewares[i], min);
         | 
| 200 | 
            +
                if (index === -1) {
         | 
| 201 | 
            +
                  return middlewares.slice(i);
         | 
| 202 | 
            +
                }
         | 
| 203 | 
            +
                min = index + 1;
         | 
| 204 | 
            +
              }
         | 
| 205 | 
            +
              return [];
         | 
| 206 | 
            +
            }
         | 
| 207 | 
            +
            function mergeMiddlewares(first, second) {
         | 
| 208 | 
            +
              return [...first, ...dedupeMiddlewares(first, second)];
         | 
| 209 | 
            +
            }
         | 
| 210 | 
            +
            function addMiddleware(middlewares, addition) {
         | 
| 211 | 
            +
              return [...middlewares, addition];
         | 
| 212 | 
            +
            }
         | 
| 213 | 
            +
             | 
| 214 | 
            +
            // src/router.ts
         | 
| 215 | 
            +
            function adaptRouter(router, options) {
         | 
| 216 | 
            +
              if (isLazy(router)) {
         | 
| 217 | 
            +
                const adapted2 = lazy(async () => {
         | 
| 218 | 
            +
                  const unlaziedRouter = (await unlazy(router)).default;
         | 
| 219 | 
            +
                  const adapted3 = adaptRouter(unlaziedRouter, options);
         | 
| 220 | 
            +
                  return { default: adapted3 };
         | 
| 221 | 
            +
                });
         | 
| 222 | 
            +
                const accessible = createAccessibleLazyRouter(adapted2);
         | 
| 223 | 
            +
                const currentPrefix = getLazyRouterPrefix(router);
         | 
| 224 | 
            +
                const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
         | 
| 225 | 
            +
                if (prefix) {
         | 
| 226 | 
            +
                  return deepSetLazyRouterPrefix(accessible, prefix);
         | 
| 227 | 
            +
                }
         | 
| 228 | 
            +
                return accessible;
         | 
| 229 | 
            +
              }
         | 
| 230 | 
            +
              if (isProcedure(router)) {
         | 
| 231 | 
            +
                const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
         | 
| 232 | 
            +
                const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
         | 
| 233 | 
            +
                const adapted2 = new Procedure({
         | 
| 234 | 
            +
                  ...router["~orpc"],
         | 
| 235 | 
            +
                  route: adaptRoute(router["~orpc"].route, options),
         | 
| 236 | 
            +
                  errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
         | 
| 237 | 
            +
                  middlewares: newMiddlewares,
         | 
| 238 | 
            +
                  inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
         | 
| 239 | 
            +
                  outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
         | 
| 240 | 
            +
                });
         | 
| 241 | 
            +
                return adapted2;
         | 
| 242 | 
            +
              }
         | 
| 243 | 
            +
              const adapted = {};
         | 
| 244 | 
            +
              for (const key in router) {
         | 
| 245 | 
            +
                adapted[key] = adaptRouter(router[key], options);
         | 
| 246 | 
            +
              }
         | 
| 247 | 
            +
              return adapted;
         | 
| 248 | 
            +
            }
         | 
| 249 | 
            +
            function getRouterChild(router, ...path) {
         | 
| 250 | 
            +
              let current = router;
         | 
| 251 | 
            +
              for (let i = 0; i < path.length; i++) {
         | 
| 252 | 
            +
                const segment = path[i];
         | 
| 253 | 
            +
                if (!current) {
         | 
| 254 | 
            +
                  return void 0;
         | 
| 255 | 
            +
                }
         | 
| 256 | 
            +
                if (isProcedure(current)) {
         | 
| 257 | 
            +
                  return void 0;
         | 
| 258 | 
            +
                }
         | 
| 259 | 
            +
                if (!isLazy(current)) {
         | 
| 260 | 
            +
                  current = current[segment];
         | 
| 261 | 
            +
                  continue;
         | 
| 262 | 
            +
                }
         | 
| 263 | 
            +
                const lazied = current;
         | 
| 264 | 
            +
                const rest = path.slice(i);
         | 
| 265 | 
            +
                const newLazy = lazy(async () => {
         | 
| 266 | 
            +
                  const unwrapped = await unlazy(lazied);
         | 
| 267 | 
            +
                  if (!unwrapped.default) {
         | 
| 268 | 
            +
                    return unwrapped;
         | 
| 269 | 
            +
                  }
         | 
| 270 | 
            +
                  const next = getRouterChild(unwrapped.default, ...rest);
         | 
| 271 | 
            +
                  return { default: next };
         | 
| 272 | 
            +
                });
         | 
| 273 | 
            +
                return flatLazy(newLazy);
         | 
| 274 | 
            +
              }
         | 
| 275 | 
            +
              return current;
         | 
| 276 | 
            +
            }
         | 
| 277 | 
            +
             | 
| 278 | 
            +
            // src/router-accessible-lazy.ts
         | 
| 279 | 
            +
            function createAccessibleLazyRouter(lazied) {
         | 
| 280 | 
            +
              const flattenLazy = flatLazy(lazied);
         | 
| 281 | 
            +
              const recursive = new Proxy(flattenLazy, {
         | 
| 282 | 
            +
                get(target, key) {
         | 
| 283 | 
            +
                  if (typeof key !== "string") {
         | 
| 284 | 
            +
                    return Reflect.get(target, key);
         | 
| 285 | 
            +
                  }
         | 
| 286 | 
            +
                  const next = getRouterChild(flattenLazy, key);
         | 
| 287 | 
            +
                  return createAccessibleLazyRouter(next);
         | 
| 288 | 
            +
                }
         | 
| 289 | 
            +
              });
         | 
| 290 | 
            +
              return recursive;
         | 
| 291 | 
            +
            }
         | 
| 292 | 
            +
             | 
| 293 | 
            +
            // src/utils.ts
         | 
| 294 | 
            +
            import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
         | 
| 295 | 
            +
            function eachContractProcedure(options, callback, laziedOptions = []) {
         | 
| 296 | 
            +
              const hiddenContract = getRouterContract(options.router);
         | 
| 297 | 
            +
              if (hiddenContract) {
         | 
| 298 | 
            +
                return eachContractProcedure(
         | 
| 299 | 
            +
                  {
         | 
| 300 | 
            +
                    router: hiddenContract,
         | 
| 301 | 
            +
                    path: options.path
         | 
| 302 | 
            +
                  },
         | 
| 303 | 
            +
                  callback,
         | 
| 304 | 
            +
                  laziedOptions
         | 
| 305 | 
            +
                );
         | 
| 306 | 
            +
              }
         | 
| 307 | 
            +
              if (isLazy(options.router)) {
         | 
| 308 | 
            +
                laziedOptions.push({
         | 
| 309 | 
            +
                  lazied: options.router,
         | 
| 310 | 
            +
                  path: options.path
         | 
| 311 | 
            +
                });
         | 
| 312 | 
            +
              } else if (isContractProcedure2(options.router)) {
         | 
| 313 | 
            +
                callback({
         | 
| 314 | 
            +
                  contract: options.router,
         | 
| 315 | 
            +
                  path: options.path
         | 
| 316 | 
            +
                });
         | 
| 317 | 
            +
              } else {
         | 
| 318 | 
            +
                for (const key in options.router) {
         | 
| 319 | 
            +
                  eachContractProcedure(
         | 
| 320 | 
            +
                    {
         | 
| 321 | 
            +
                      router: options.router[key],
         | 
| 322 | 
            +
                      path: [...options.path, key]
         | 
| 323 | 
            +
                    },
         | 
| 324 | 
            +
                    callback,
         | 
| 325 | 
            +
                    laziedOptions
         | 
| 326 | 
            +
                  );
         | 
| 327 | 
            +
                }
         | 
| 328 | 
            +
              }
         | 
| 329 | 
            +
              return laziedOptions;
         | 
| 330 | 
            +
            }
         | 
| 331 | 
            +
            async function eachAllContractProcedure(options, callback) {
         | 
| 332 | 
            +
              const pending = [options];
         | 
| 333 | 
            +
              for (const item of pending) {
         | 
| 334 | 
            +
                const lazies = eachContractProcedure(item, callback);
         | 
| 335 | 
            +
                for (const lazy2 of lazies) {
         | 
| 336 | 
            +
                  const { default: router } = await unlazy(lazy2.lazied);
         | 
| 337 | 
            +
                  pending.push({
         | 
| 338 | 
            +
                    path: lazy2.path,
         | 
| 339 | 
            +
                    router
         | 
| 340 | 
            +
                  });
         | 
| 341 | 
            +
                }
         | 
| 342 | 
            +
              }
         | 
| 343 | 
            +
            }
         | 
| 344 | 
            +
            function convertPathToHttpPath(path) {
         | 
| 345 | 
            +
              return `/${path.map(encodeURIComponent).join("/")}`;
         | 
| 346 | 
            +
            }
         | 
| 347 | 
            +
            function createContractedProcedure(contract, procedure) {
         | 
| 348 | 
            +
              return new Procedure({
         | 
| 349 | 
            +
                ...procedure["~orpc"],
         | 
| 350 | 
            +
                errorMap: contract["~orpc"].errorMap,
         | 
| 351 | 
            +
                route: contract["~orpc"].route,
         | 
| 352 | 
            +
                meta: contract["~orpc"].meta
         | 
| 353 | 
            +
              });
         | 
| 354 | 
            +
            }
         | 
| 355 | 
            +
             | 
| 356 | 
            +
            export {
         | 
| 357 | 
            +
              LAZY_LOADER_SYMBOL,
         | 
| 358 | 
            +
              lazy,
         | 
| 359 | 
            +
              isLazy,
         | 
| 360 | 
            +
              unlazy,
         | 
| 361 | 
            +
              Procedure,
         | 
| 362 | 
            +
              isProcedure,
         | 
| 363 | 
            +
              flatLazy,
         | 
| 364 | 
            +
              createLazyProcedureFormAnyLazy,
         | 
| 365 | 
            +
              addMiddleware,
         | 
| 366 | 
            +
              middlewareOutputFn,
         | 
| 367 | 
            +
              createProcedureClient,
         | 
| 368 | 
            +
              setRouterContract,
         | 
| 369 | 
            +
              getRouterContract,
         | 
| 370 | 
            +
              deepSetLazyRouterPrefix,
         | 
| 371 | 
            +
              getLazyRouterPrefix,
         | 
| 372 | 
            +
              createAccessibleLazyRouter,
         | 
| 373 | 
            +
              adaptRouter,
         | 
| 374 | 
            +
              getRouterChild,
         | 
| 375 | 
            +
              eachContractProcedure,
         | 
| 376 | 
            +
              eachAllContractProcedure,
         | 
| 377 | 
            +
              convertPathToHttpPath,
         | 
| 378 | 
            +
              createContractedProcedure
         | 
| 379 | 
            +
            };
         | 
| 380 | 
            +
            //# sourceMappingURL=chunk-NOA3GBJQ.js.map
         | 
| @@ -0,0 +1,111 @@ | |
| 1 | 
            +
            // src/plugins/base.ts
         | 
| 2 | 
            +
            var CompositePlugin = class {
         | 
| 3 | 
            +
              constructor(plugins = []) {
         | 
| 4 | 
            +
                this.plugins = plugins;
         | 
| 5 | 
            +
              }
         | 
| 6 | 
            +
              init(options) {
         | 
| 7 | 
            +
                for (const plugin of this.plugins) {
         | 
| 8 | 
            +
                  plugin.init?.(options);
         | 
| 9 | 
            +
                }
         | 
| 10 | 
            +
              }
         | 
| 11 | 
            +
            };
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            // src/plugins/cors.ts
         | 
| 14 | 
            +
            import { value } from "@orpc/shared";
         | 
| 15 | 
            +
            var CORSPlugin = class {
         | 
| 16 | 
            +
              options;
         | 
| 17 | 
            +
              constructor(options) {
         | 
| 18 | 
            +
                const defaults = {
         | 
| 19 | 
            +
                  origin: "*",
         | 
| 20 | 
            +
                  allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
         | 
| 21 | 
            +
                };
         | 
| 22 | 
            +
                this.options = {
         | 
| 23 | 
            +
                  ...defaults,
         | 
| 24 | 
            +
                  ...options
         | 
| 25 | 
            +
                };
         | 
| 26 | 
            +
              }
         | 
| 27 | 
            +
              init(options) {
         | 
| 28 | 
            +
                options.interceptorsRoot ??= [];
         | 
| 29 | 
            +
                options.interceptorsRoot.unshift(async (interceptorOptions) => {
         | 
| 30 | 
            +
                  if (interceptorOptions.request.method === "OPTIONS") {
         | 
| 31 | 
            +
                    const resHeaders = {};
         | 
| 32 | 
            +
                    if (this.options.maxAge !== void 0) {
         | 
| 33 | 
            +
                      resHeaders["access-control-max-age"] = this.options.maxAge.toString();
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
                    if (this.options.allowMethods?.length) {
         | 
| 36 | 
            +
                      resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
         | 
| 37 | 
            +
                    }
         | 
| 38 | 
            +
                    const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
         | 
| 39 | 
            +
                    if (Array.isArray(allowHeaders) && allowHeaders.length) {
         | 
| 40 | 
            +
                      resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
         | 
| 41 | 
            +
                    } else if (typeof allowHeaders === "string") {
         | 
| 42 | 
            +
                      resHeaders["access-control-allow-headers"] = allowHeaders;
         | 
| 43 | 
            +
                    }
         | 
| 44 | 
            +
                    return {
         | 
| 45 | 
            +
                      matched: true,
         | 
| 46 | 
            +
                      response: {
         | 
| 47 | 
            +
                        status: 204,
         | 
| 48 | 
            +
                        headers: resHeaders,
         | 
| 49 | 
            +
                        body: void 0
         | 
| 50 | 
            +
                      }
         | 
| 51 | 
            +
                    };
         | 
| 52 | 
            +
                  }
         | 
| 53 | 
            +
                  return interceptorOptions.next();
         | 
| 54 | 
            +
                });
         | 
| 55 | 
            +
                options.interceptorsRoot.unshift(async (interceptorOptions) => {
         | 
| 56 | 
            +
                  const result = await interceptorOptions.next();
         | 
| 57 | 
            +
                  if (!result.matched) {
         | 
| 58 | 
            +
                    return result;
         | 
| 59 | 
            +
                  }
         | 
| 60 | 
            +
                  const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
         | 
| 61 | 
            +
                  const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
         | 
| 62 | 
            +
                  const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
         | 
| 63 | 
            +
                  if (allowedOriginArr.includes(origin)) {
         | 
| 64 | 
            +
                    result.response.headers["access-control-allow-origin"] = origin;
         | 
| 65 | 
            +
                  }
         | 
| 66 | 
            +
                  if (!allowedOriginArr.includes("*")) {
         | 
| 67 | 
            +
                    result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
         | 
| 68 | 
            +
                  }
         | 
| 69 | 
            +
                  if (this.options.credentials) {
         | 
| 70 | 
            +
                    result.response.headers["access-control-allow-credentials"] = "true";
         | 
| 71 | 
            +
                  }
         | 
| 72 | 
            +
                  if (this.options.exposeHeaders?.length) {
         | 
| 73 | 
            +
                    result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
         | 
| 74 | 
            +
                  }
         | 
| 75 | 
            +
                  return result;
         | 
| 76 | 
            +
                });
         | 
| 77 | 
            +
              }
         | 
| 78 | 
            +
            };
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            // src/plugins/response-headers.ts
         | 
| 81 | 
            +
            var ResponseHeadersPlugin = class {
         | 
| 82 | 
            +
              init(options) {
         | 
| 83 | 
            +
                options.interceptorsRoot ??= [];
         | 
| 84 | 
            +
                options.interceptorsRoot.push(async (interceptorOptions) => {
         | 
| 85 | 
            +
                  const headers = new Headers();
         | 
| 86 | 
            +
                  interceptorOptions.context.resHeaders = headers;
         | 
| 87 | 
            +
                  const result = await interceptorOptions.next();
         | 
| 88 | 
            +
                  if (!result.matched) {
         | 
| 89 | 
            +
                    return result;
         | 
| 90 | 
            +
                  }
         | 
| 91 | 
            +
                  const responseHeaders = result.response.headers;
         | 
| 92 | 
            +
                  for (const [key, value2] of headers) {
         | 
| 93 | 
            +
                    if (Array.isArray(responseHeaders[key])) {
         | 
| 94 | 
            +
                      responseHeaders[key].push(value2);
         | 
| 95 | 
            +
                    } else if (responseHeaders[key] !== void 0) {
         | 
| 96 | 
            +
                      responseHeaders[key] = [responseHeaders[key], value2];
         | 
| 97 | 
            +
                    } else {
         | 
| 98 | 
            +
                      responseHeaders[key] = value2;
         | 
| 99 | 
            +
                    }
         | 
| 100 | 
            +
                  }
         | 
| 101 | 
            +
                  return result;
         | 
| 102 | 
            +
                });
         | 
| 103 | 
            +
              }
         | 
| 104 | 
            +
            };
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            export {
         | 
| 107 | 
            +
              CompositePlugin,
         | 
| 108 | 
            +
              CORSPlugin,
         | 
| 109 | 
            +
              ResponseHeadersPlugin
         | 
| 110 | 
            +
            };
         | 
| 111 | 
            +
            //# sourceMappingURL=chunk-OXB4YX67.js.map
         | 
    
        package/dist/fetch.js
    CHANGED
    
    | @@ -1,112 +1,18 @@ | |
| 1 1 | 
             
            import {
         | 
| 2 | 
            -
               | 
| 3 | 
            -
               | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
            import  | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
                const response = await handler(options);
         | 
| 12 | 
            -
                if (response) {
         | 
| 13 | 
            -
                  return response;
         | 
| 14 | 
            -
                }
         | 
| 15 | 
            -
              }
         | 
| 16 | 
            -
              const error = new ORPCError({ code: "NOT_FOUND", message: "Not found" });
         | 
| 17 | 
            -
              return new Response(JSON.stringify(error.toJSON()), {
         | 
| 18 | 
            -
                status: error.status,
         | 
| 19 | 
            -
                headers: {
         | 
| 20 | 
            -
                  "Content-Type": "application/json"
         | 
| 21 | 
            -
                }
         | 
| 22 | 
            -
              });
         | 
| 23 | 
            -
            }
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            // src/fetch/handler.ts
         | 
| 26 | 
            -
            import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract";
         | 
| 27 | 
            -
            import { executeWithHooks, trim, value } from "@orpc/shared";
         | 
| 28 | 
            -
            import { ORPCError as ORPCError2 } from "@orpc/shared/error";
         | 
| 29 | 
            -
            import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
         | 
| 30 | 
            -
            var serializer = new ORPCSerializer();
         | 
| 31 | 
            -
            var deserializer = new ORPCDeserializer();
         | 
| 32 | 
            -
            function createORPCHandler() {
         | 
| 33 | 
            -
              return async (options) => {
         | 
| 34 | 
            -
                if (options.request.headers.get(ORPC_HEADER) !== ORPC_HEADER_VALUE) {
         | 
| 35 | 
            -
                  return void 0;
         | 
| 36 | 
            -
                }
         | 
| 37 | 
            -
                const context = await value(options.context);
         | 
| 38 | 
            -
                const handler = async () => {
         | 
| 39 | 
            -
                  const url = new URL(options.request.url);
         | 
| 40 | 
            -
                  const pathname = `/${trim(url.pathname.replace(options.prefix ?? "", ""), "/")}`;
         | 
| 41 | 
            -
                  const match = resolveORPCRouter(options.router, pathname);
         | 
| 42 | 
            -
                  if (!match) {
         | 
| 43 | 
            -
                    throw new ORPCError2({ code: "NOT_FOUND", message: "Not found" });
         | 
| 44 | 
            -
                  }
         | 
| 45 | 
            -
                  const input = await deserializeRequest(options.request);
         | 
| 46 | 
            -
                  const caller = createProcedureCaller({
         | 
| 47 | 
            -
                    context,
         | 
| 48 | 
            -
                    procedure: match.procedure,
         | 
| 49 | 
            -
                    path: match.path
         | 
| 50 | 
            -
                  });
         | 
| 51 | 
            -
                  const output = await caller(input, { signal: options.signal });
         | 
| 52 | 
            -
                  const { body, headers } = serializer.serialize(output);
         | 
| 53 | 
            -
                  return new Response(body, {
         | 
| 54 | 
            -
                    status: 200,
         | 
| 55 | 
            -
                    headers
         | 
| 56 | 
            -
                  });
         | 
| 57 | 
            -
                };
         | 
| 58 | 
            -
                try {
         | 
| 59 | 
            -
                  return await executeWithHooks({
         | 
| 60 | 
            -
                    hooks: options,
         | 
| 61 | 
            -
                    context,
         | 
| 62 | 
            -
                    execute: handler,
         | 
| 63 | 
            -
                    input: options.request,
         | 
| 64 | 
            -
                    meta: {
         | 
| 65 | 
            -
                      signal: options.signal
         | 
| 66 | 
            -
                    }
         | 
| 67 | 
            -
                  });
         | 
| 68 | 
            -
                } catch (e) {
         | 
| 69 | 
            -
                  const error = e instanceof ORPCError2 ? e : new ORPCError2({
         | 
| 70 | 
            -
                    code: "INTERNAL_SERVER_ERROR",
         | 
| 71 | 
            -
                    message: "Internal server error",
         | 
| 72 | 
            -
                    cause: e
         | 
| 73 | 
            -
                  });
         | 
| 74 | 
            -
                  const { body, headers } = serializer.serialize(error.toJSON());
         | 
| 75 | 
            -
                  return new Response(body, {
         | 
| 76 | 
            -
                    status: error.status,
         | 
| 77 | 
            -
                    headers
         | 
| 78 | 
            -
                  });
         | 
| 79 | 
            -
                }
         | 
| 80 | 
            -
              };
         | 
| 81 | 
            -
            }
         | 
| 82 | 
            -
            function resolveORPCRouter(router, pathname) {
         | 
| 83 | 
            -
              const path = trim(pathname, "/").split("/").map(decodeURIComponent);
         | 
| 84 | 
            -
              let current = router;
         | 
| 85 | 
            -
              for (const segment of path) {
         | 
| 86 | 
            -
                if (typeof current !== "object" && typeof current !== "function" || !current) {
         | 
| 87 | 
            -
                  current = void 0;
         | 
| 88 | 
            -
                  break;
         | 
| 89 | 
            -
                }
         | 
| 90 | 
            -
                current = current[segment];
         | 
| 91 | 
            -
              }
         | 
| 92 | 
            -
              return isProcedure(current) || isLazy(current) ? {
         | 
| 93 | 
            -
                procedure: current,
         | 
| 94 | 
            -
                path
         | 
| 95 | 
            -
              } : void 0;
         | 
| 96 | 
            -
            }
         | 
| 97 | 
            -
            async function deserializeRequest(request) {
         | 
| 98 | 
            -
              try {
         | 
| 99 | 
            -
                return await deserializer.deserialize(request);
         | 
| 100 | 
            -
              } catch (e) {
         | 
| 101 | 
            -
                throw new ORPCError2({
         | 
| 102 | 
            -
                  code: "BAD_REQUEST",
         | 
| 103 | 
            -
                  message: "Cannot parse request. Please check the request body and Content-Type header.",
         | 
| 104 | 
            -
                  cause: e
         | 
| 105 | 
            -
                });
         | 
| 106 | 
            -
              }
         | 
| 107 | 
            -
            }
         | 
| 2 | 
            +
              RPCHandler,
         | 
| 3 | 
            +
              fetchReToStandardBody,
         | 
| 4 | 
            +
              fetchRequestToStandardRequest,
         | 
| 5 | 
            +
              standardBodyToFetchBody,
         | 
| 6 | 
            +
              standardResponseToFetchResponse
         | 
| 7 | 
            +
            } from "./chunk-EYGVJA7A.js";
         | 
| 8 | 
            +
            import "./chunk-CVIWJKJC.js";
         | 
| 9 | 
            +
            import "./chunk-NOA3GBJQ.js";
         | 
| 10 | 
            +
            import "./chunk-OXB4YX67.js";
         | 
| 108 11 | 
             
            export {
         | 
| 109 | 
            -
               | 
| 110 | 
            -
               | 
| 12 | 
            +
              RPCHandler,
         | 
| 13 | 
            +
              fetchReToStandardBody,
         | 
| 14 | 
            +
              fetchRequestToStandardRequest,
         | 
| 15 | 
            +
              standardBodyToFetchBody,
         | 
| 16 | 
            +
              standardResponseToFetchResponse
         | 
| 111 17 | 
             
            };
         | 
| 112 18 | 
             
            //# sourceMappingURL=fetch.js.map
         | 
    
        package/dist/hono.js
    ADDED
    
    | @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            import {
         | 
| 2 | 
            +
              RPCHandler,
         | 
| 3 | 
            +
              fetchReToStandardBody,
         | 
| 4 | 
            +
              fetchRequestToStandardRequest,
         | 
| 5 | 
            +
              standardBodyToFetchBody,
         | 
| 6 | 
            +
              standardResponseToFetchResponse
         | 
| 7 | 
            +
            } from "./chunk-EYGVJA7A.js";
         | 
| 8 | 
            +
            import "./chunk-CVIWJKJC.js";
         | 
| 9 | 
            +
            import "./chunk-NOA3GBJQ.js";
         | 
| 10 | 
            +
            import "./chunk-OXB4YX67.js";
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            // src/adapters/hono/middleware.ts
         | 
| 13 | 
            +
            import { value } from "@orpc/shared";
         | 
| 14 | 
            +
            function createMiddleware(handler, ...[options]) {
         | 
| 15 | 
            +
              return async (c, next) => {
         | 
| 16 | 
            +
                const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
         | 
| 17 | 
            +
                const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
         | 
| 18 | 
            +
                  // https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
         | 
| 19 | 
            +
                  get(target, prop) {
         | 
| 20 | 
            +
                    if (bodyProps.has(prop)) {
         | 
| 21 | 
            +
                      return () => c.req[prop]();
         | 
| 22 | 
            +
                    }
         | 
| 23 | 
            +
                    return Reflect.get(target, prop, target);
         | 
| 24 | 
            +
                  }
         | 
| 25 | 
            +
                });
         | 
| 26 | 
            +
                const context = await value(options?.context ?? {}, c);
         | 
| 27 | 
            +
                const { matched, response } = await handler.handle(request, { ...options, context });
         | 
| 28 | 
            +
                if (matched) {
         | 
| 29 | 
            +
                  return c.body(response.body, response);
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
                await next();
         | 
| 32 | 
            +
              };
         | 
| 33 | 
            +
            }
         | 
| 34 | 
            +
            export {
         | 
| 35 | 
            +
              RPCHandler,
         | 
| 36 | 
            +
              createMiddleware,
         | 
| 37 | 
            +
              fetchReToStandardBody,
         | 
| 38 | 
            +
              fetchRequestToStandardRequest,
         | 
| 39 | 
            +
              standardBodyToFetchBody,
         | 
| 40 | 
            +
              standardResponseToFetchResponse
         | 
| 41 | 
            +
            };
         | 
| 42 | 
            +
            //# sourceMappingURL=hono.js.map
         |