@orpc/server 0.0.0-next.c099c92 → 0.0.0-next.c0afbea

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.
Files changed (72) hide show
  1. package/README.md +120 -0
  2. package/dist/adapters/fetch/index.d.mts +26 -0
  3. package/dist/adapters/fetch/index.d.ts +26 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +19 -0
  6. package/dist/adapters/hono/index.d.ts +19 -0
  7. package/dist/adapters/hono/index.mjs +32 -0
  8. package/dist/adapters/next/index.d.mts +26 -0
  9. package/dist/adapters/next/index.d.ts +26 -0
  10. package/dist/{next.js → adapters/next/index.mjs} +11 -18
  11. package/dist/adapters/node/index.d.mts +34 -0
  12. package/dist/adapters/node/index.d.ts +34 -0
  13. package/dist/adapters/node/index.mjs +31 -0
  14. package/dist/adapters/standard/index.d.mts +25 -0
  15. package/dist/adapters/standard/index.d.ts +25 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +269 -0
  18. package/dist/index.d.ts +269 -0
  19. package/dist/{index.js → index.mjs} +76 -124
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/plugins/index.mjs +103 -0
  23. package/dist/shared/server.CM3tWr3C.d.mts +75 -0
  24. package/dist/shared/server.CMrS28Go.mjs +346 -0
  25. package/dist/shared/server.CPteJIPP.d.mts +143 -0
  26. package/dist/shared/server.CPteJIPP.d.ts +143 -0
  27. package/dist/shared/server.CSZRzcSW.mjs +158 -0
  28. package/dist/shared/server.Cq3B6PoL.mjs +28 -0
  29. package/dist/shared/server.DmW25ynm.d.ts +75 -0
  30. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  31. package/package.json +36 -24
  32. package/dist/chunk-ESTRJAOX.js +0 -299
  33. package/dist/chunk-KK4SDLC7.js +0 -320
  34. package/dist/chunk-WUOGVGWG.js +0 -1
  35. package/dist/fetch.js +0 -15
  36. package/dist/hono.js +0 -30
  37. package/dist/node.js +0 -87
  38. package/dist/src/adapters/fetch/index.d.ts +0 -6
  39. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  40. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  41. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  42. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  43. package/dist/src/adapters/fetch/types.d.ts +0 -21
  44. package/dist/src/adapters/hono/index.d.ts +0 -3
  45. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  46. package/dist/src/adapters/next/index.d.ts +0 -3
  47. package/dist/src/adapters/next/serve.d.ts +0 -19
  48. package/dist/src/adapters/node/index.d.ts +0 -5
  49. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  50. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  51. package/dist/src/adapters/node/types.d.ts +0 -22
  52. package/dist/src/builder-variants.d.ts +0 -74
  53. package/dist/src/builder.d.ts +0 -57
  54. package/dist/src/config.d.ts +0 -6
  55. package/dist/src/context.d.ts +0 -9
  56. package/dist/src/hidden.d.ts +0 -8
  57. package/dist/src/implementer-procedure.d.ts +0 -30
  58. package/dist/src/implementer-variants.d.ts +0 -17
  59. package/dist/src/implementer.d.ts +0 -28
  60. package/dist/src/index.d.ts +0 -21
  61. package/dist/src/lazy-utils.d.ts +0 -6
  62. package/dist/src/lazy.d.ts +0 -22
  63. package/dist/src/middleware-decorated.d.ts +0 -10
  64. package/dist/src/middleware-utils.d.ts +0 -5
  65. package/dist/src/middleware.d.ts +0 -37
  66. package/dist/src/procedure-client.d.ts +0 -20
  67. package/dist/src/procedure-decorated.d.ts +0 -21
  68. package/dist/src/procedure-utils.d.ts +0 -17
  69. package/dist/src/procedure.d.ts +0 -29
  70. package/dist/src/router-accessible-lazy.d.ts +0 -8
  71. package/dist/src/router-client.d.ts +0 -22
  72. package/dist/src/router.d.ts +0 -29
@@ -1,320 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/lazy.ts
8
- var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
9
- function lazy(loader) {
10
- return {
11
- [LAZY_LOADER_SYMBOL]: loader
12
- };
13
- }
14
- function isLazy(item) {
15
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
16
- }
17
- function unlazy(lazied) {
18
- return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
19
- }
20
-
21
- // src/procedure.ts
22
- import { isContractProcedure } from "@orpc/contract";
23
- var Procedure = class {
24
- "~orpc";
25
- constructor(def) {
26
- this["~orpc"] = def;
27
- }
28
- };
29
- function isProcedure(item) {
30
- if (item instanceof Procedure) {
31
- return true;
32
- }
33
- return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
34
- }
35
-
36
- // src/lazy-utils.ts
37
- function flatLazy(lazied) {
38
- const flattenLoader = async () => {
39
- let current = await unlazy(lazied);
40
- while (true) {
41
- if (!isLazy(current.default)) {
42
- break;
43
- }
44
- current = await unlazy(current.default);
45
- }
46
- return current;
47
- };
48
- return lazy(flattenLoader);
49
- }
50
- function createLazyProcedureFormAnyLazy(lazied) {
51
- const lazyProcedure = lazy(async () => {
52
- const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
53
- if (!isProcedure(maybeProcedure)) {
54
- throw new Error(`
55
- Expected a lazy<procedure> but got lazy<unknown>.
56
- This should be caught by TypeScript compilation.
57
- Please report this issue if this makes you feel uncomfortable.
58
- `);
59
- }
60
- return { default: maybeProcedure };
61
- });
62
- return lazyProcedure;
63
- }
64
-
65
- // src/middleware.ts
66
- function middlewareOutputFn(output) {
67
- return { output, context: {} };
68
- }
69
-
70
- // src/procedure-client.ts
71
- import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
72
- import { executeWithHooks, toError, value } from "@orpc/shared";
73
- function createProcedureClient(lazyableProcedure, ...[options]) {
74
- return async (...[input, callerOptions]) => {
75
- const path = options?.path ?? [];
76
- const { default: procedure } = await unlazy(lazyableProcedure);
77
- const context = await value(options?.context ?? {}, callerOptions?.context);
78
- const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
79
- const executeOptions = {
80
- input,
81
- context,
82
- errors,
83
- path,
84
- procedure,
85
- signal: callerOptions?.signal
86
- };
87
- try {
88
- const output = await executeWithHooks({
89
- hooks: options,
90
- input,
91
- context,
92
- meta: executeOptions,
93
- execute: () => executeProcedureInternal(procedure, executeOptions)
94
- });
95
- return output;
96
- } catch (e) {
97
- if (!(e instanceof ORPCError)) {
98
- throw toError(e);
99
- }
100
- const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
101
- throw validated;
102
- }
103
- };
104
- }
105
- async function validateInput(procedure, input) {
106
- const schema = procedure["~orpc"].inputSchema;
107
- if (!schema) {
108
- return input;
109
- }
110
- const result = await schema["~standard"].validate(input);
111
- if (result.issues) {
112
- throw new ORPCError("BAD_REQUEST", {
113
- message: "Input validation failed",
114
- data: {
115
- issues: result.issues
116
- },
117
- cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
118
- });
119
- }
120
- return result.value;
121
- }
122
- async function validateOutput(procedure, output) {
123
- const schema = procedure["~orpc"].outputSchema;
124
- if (!schema) {
125
- return output;
126
- }
127
- const result = await schema["~standard"].validate(output);
128
- if (result.issues) {
129
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
130
- message: "Output validation failed",
131
- cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
132
- });
133
- }
134
- return result.value;
135
- }
136
- async function executeProcedureInternal(procedure, options) {
137
- const middlewares = procedure["~orpc"].middlewares;
138
- const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
139
- const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
140
- let currentIndex = 0;
141
- let currentContext = options.context;
142
- let currentInput = options.input;
143
- const next = async (...[nextOptions]) => {
144
- const index = currentIndex;
145
- currentIndex += 1;
146
- currentContext = { ...currentContext, ...nextOptions?.context };
147
- if (index === inputValidationIndex) {
148
- currentInput = await validateInput(procedure, currentInput);
149
- }
150
- const mid = middlewares[index];
151
- const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
152
- if (index === outputValidationIndex) {
153
- const validatedOutput = await validateOutput(procedure, result.output);
154
- return {
155
- ...result,
156
- output: validatedOutput
157
- };
158
- }
159
- return result;
160
- };
161
- return (await next({})).output;
162
- }
163
-
164
- // src/hidden.ts
165
- var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
166
- function setRouterContract(obj, contract) {
167
- return new Proxy(obj, {
168
- get(target, key) {
169
- if (key === ROUTER_CONTRACT_SYMBOL) {
170
- return contract;
171
- }
172
- return Reflect.get(target, key);
173
- }
174
- });
175
- }
176
- function getRouterContract(obj) {
177
- return obj[ROUTER_CONTRACT_SYMBOL];
178
- }
179
- var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
180
- function deepSetLazyRouterPrefix(router, prefix) {
181
- return new Proxy(router, {
182
- get(target, key) {
183
- if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
184
- const val = Reflect.get(target, key);
185
- if (isLazy(val)) {
186
- return deepSetLazyRouterPrefix(val, prefix);
187
- }
188
- return val;
189
- }
190
- return prefix;
191
- }
192
- });
193
- }
194
- function getLazyRouterPrefix(obj) {
195
- return obj[LAZY_ROUTER_PREFIX_SYMBOL];
196
- }
197
-
198
- // src/router.ts
199
- import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
200
-
201
- // src/middleware-utils.ts
202
- function dedupeMiddlewares(compare, middlewares) {
203
- let min = 0;
204
- for (let i = 0; i < middlewares.length; i++) {
205
- const index = compare.indexOf(middlewares[i], min);
206
- if (index === -1) {
207
- return middlewares.slice(i);
208
- }
209
- min = index + 1;
210
- }
211
- return [];
212
- }
213
- function mergeMiddlewares(first, second) {
214
- return [...first, ...dedupeMiddlewares(first, second)];
215
- }
216
- function addMiddleware(middlewares, addition) {
217
- return [...middlewares, addition];
218
- }
219
-
220
- // src/router.ts
221
- function adaptRouter(router, options) {
222
- if (isLazy(router)) {
223
- const adapted2 = lazy(async () => {
224
- const unlaziedRouter = (await unlazy(router)).default;
225
- const adapted3 = adaptRouter(unlaziedRouter, options);
226
- return { default: adapted3 };
227
- });
228
- const accessible = createAccessibleLazyRouter(adapted2);
229
- const currentPrefix = getLazyRouterPrefix(router);
230
- const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
231
- if (prefix) {
232
- return deepSetLazyRouterPrefix(accessible, prefix);
233
- }
234
- return accessible;
235
- }
236
- if (isProcedure(router)) {
237
- const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
238
- const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
239
- const adapted2 = new Procedure({
240
- ...router["~orpc"],
241
- route: adaptRoute(router["~orpc"].route, options),
242
- errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
243
- middlewares: newMiddlewares,
244
- inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
245
- outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
246
- });
247
- return adapted2;
248
- }
249
- const adapted = {};
250
- for (const key in router) {
251
- adapted[key] = adaptRouter(router[key], options);
252
- }
253
- return adapted;
254
- }
255
- function getRouterChild(router, ...path) {
256
- let current = router;
257
- for (let i = 0; i < path.length; i++) {
258
- const segment = path[i];
259
- if (!current) {
260
- return void 0;
261
- }
262
- if (isProcedure(current)) {
263
- return void 0;
264
- }
265
- if (!isLazy(current)) {
266
- current = current[segment];
267
- continue;
268
- }
269
- const lazied = current;
270
- const rest = path.slice(i);
271
- const newLazy = lazy(async () => {
272
- const unwrapped = await unlazy(lazied);
273
- if (!unwrapped.default) {
274
- return unwrapped;
275
- }
276
- const next = getRouterChild(unwrapped.default, ...rest);
277
- return { default: next };
278
- });
279
- return flatLazy(newLazy);
280
- }
281
- return current;
282
- }
283
-
284
- // src/router-accessible-lazy.ts
285
- function createAccessibleLazyRouter(lazied) {
286
- const flattenLazy = flatLazy(lazied);
287
- const recursive = new Proxy(flattenLazy, {
288
- get(target, key) {
289
- if (typeof key !== "string") {
290
- return Reflect.get(target, key);
291
- }
292
- const next = getRouterChild(flattenLazy, key);
293
- return createAccessibleLazyRouter(next);
294
- }
295
- });
296
- return recursive;
297
- }
298
-
299
- export {
300
- __export,
301
- LAZY_LOADER_SYMBOL,
302
- lazy,
303
- isLazy,
304
- unlazy,
305
- Procedure,
306
- isProcedure,
307
- flatLazy,
308
- createLazyProcedureFormAnyLazy,
309
- addMiddleware,
310
- middlewareOutputFn,
311
- createProcedureClient,
312
- setRouterContract,
313
- getRouterContract,
314
- deepSetLazyRouterPrefix,
315
- getLazyRouterPrefix,
316
- createAccessibleLazyRouter,
317
- adaptRouter,
318
- getRouterChild
319
- };
320
- //# sourceMappingURL=chunk-KK4SDLC7.js.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-WUOGVGWG.js.map
package/dist/fetch.js DELETED
@@ -1,15 +0,0 @@
1
- import "./chunk-WUOGVGWG.js";
2
- import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
9
- export {
10
- ORPCPayloadCodec,
11
- ORPCProcedureMatcher,
12
- RPCHandler,
13
- super_json_exports as SuperJSON
14
- };
15
- //# sourceMappingURL=fetch.js.map
package/dist/hono.js DELETED
@@ -1,30 +0,0 @@
1
- import "./chunk-WUOGVGWG.js";
2
- import {
3
- ORPCPayloadCodec,
4
- ORPCProcedureMatcher,
5
- RPCHandler,
6
- super_json_exports
7
- } from "./chunk-ESTRJAOX.js";
8
- import "./chunk-KK4SDLC7.js";
9
-
10
- // src/adapters/hono/middleware.ts
11
- import { value } from "@orpc/shared";
12
- function createMiddleware(handler, ...[options]) {
13
- return async (c, next) => {
14
- const context = await value(options?.context ?? {}, c);
15
- const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
16
- if (matched) {
17
- c.res = response;
18
- return;
19
- }
20
- await next();
21
- };
22
- }
23
- export {
24
- ORPCPayloadCodec,
25
- ORPCProcedureMatcher,
26
- RPCHandler,
27
- super_json_exports as SuperJSON,
28
- createMiddleware
29
- };
30
- //# sourceMappingURL=hono.js.map
package/dist/node.js DELETED
@@ -1,87 +0,0 @@
1
- import {
2
- RPCHandler
3
- } from "./chunk-ESTRJAOX.js";
4
- import "./chunk-KK4SDLC7.js";
5
-
6
- // src/adapters/node/request-listener.ts
7
- function createRequest(req, res) {
8
- const controller = new AbortController();
9
- res.on("close", () => {
10
- controller.abort();
11
- });
12
- const method = req.method ?? "GET";
13
- const headers = createHeaders(req);
14
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
15
- const host = headers.get("Host") ?? "localhost";
16
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
17
- const init = { method, headers, signal: controller.signal };
18
- if (method !== "GET" && method !== "HEAD") {
19
- init.body = new ReadableStream({
20
- start(controller2) {
21
- req.on("data", (chunk) => {
22
- controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
23
- });
24
- req.on("end", () => {
25
- controller2.close();
26
- });
27
- }
28
- });
29
- init.duplex = "half";
30
- }
31
- return new Request(url, init);
32
- }
33
- function createHeaders(req) {
34
- const headers = new Headers();
35
- const rawHeaders = req.rawHeaders;
36
- for (let i = 0; i < rawHeaders.length; i += 2) {
37
- headers.append(rawHeaders[i], rawHeaders[i + 1]);
38
- }
39
- return headers;
40
- }
41
- async function sendResponse(res, response) {
42
- const headers = {};
43
- for (const [key, value] of response.headers) {
44
- if (key in headers) {
45
- if (Array.isArray(headers[key])) {
46
- headers[key].push(value);
47
- } else {
48
- headers[key] = [headers[key], value];
49
- }
50
- } else {
51
- headers[key] = value;
52
- }
53
- }
54
- res.writeHead(response.status, headers);
55
- if (response.body != null && res.req.method !== "HEAD") {
56
- for await (const chunk of response.body) {
57
- res.write(chunk);
58
- }
59
- }
60
- res.end();
61
- }
62
-
63
- // src/adapters/node/orpc-handler.ts
64
- var RPCHandler2 = class {
65
- orpcFetchHandler;
66
- constructor(router, options) {
67
- this.orpcFetchHandler = new RPCHandler(router, options);
68
- }
69
- async handle(req, res, ...rest) {
70
- const request = createRequest(req, res);
71
- const result = await this.orpcFetchHandler.handle(request, ...rest);
72
- if (result.matched === false) {
73
- return { matched: false };
74
- }
75
- const context = rest[0]?.context ?? {};
76
- await rest[0]?.beforeSend?.(result.response, context);
77
- await sendResponse(res, result.response);
78
- return { matched: true };
79
- }
80
- };
81
- export {
82
- RPCHandler2 as RPCHandler,
83
- createHeaders,
84
- createRequest,
85
- sendResponse
86
- };
87
- //# sourceMappingURL=node.js.map
@@ -1,6 +0,0 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-payload-codec';
3
- export * from './orpc-procedure-matcher';
4
- export * as SuperJSON from './super-json';
5
- export * from './types';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { Hooks } from '@orpc/shared';
2
- import type { Context } from '../../context';
3
- import type { Router } from '../../router';
4
- import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
5
- import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
6
- import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
7
- export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
8
- signal?: AbortSignal;
9
- }> & {
10
- procedureMatcher?: PublicORPCProcedureMatcher;
11
- payloadCodec?: PublicORPCPayloadCodec;
12
- };
13
- export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
14
- private readonly options?;
15
- private readonly procedureMatcher;
16
- private readonly payloadCodec;
17
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
18
- handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
19
- }
20
- //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,16 +0,0 @@
1
- import { type HTTPMethod } from '@orpc/contract';
2
- export declare class ORPCPayloadCodec {
3
- /**
4
- * If method is GET, the payload will be encoded as query string.
5
- * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
6
- */
7
- encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
8
- query?: URLSearchParams;
9
- body?: FormData | string;
10
- headers?: Headers;
11
- method: HTTPMethod;
12
- };
13
- decode(re: Request | Response): Promise<unknown>;
14
- }
15
- export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
16
- //# sourceMappingURL=orpc-payload-codec.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { AnyProcedure } from '../../procedure';
2
- import type { AnyRouter } from '../../router';
3
- export declare class ORPCProcedureMatcher {
4
- private readonly router;
5
- constructor(router: AnyRouter);
6
- match(pathname: string): Promise<{
7
- path: string[];
8
- procedure: AnyProcedure;
9
- } | undefined>;
10
- }
11
- export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
12
- //# sourceMappingURL=orpc-procedure-matcher.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { Segment } from '@orpc/shared';
2
- export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
3
- export type JSONMeta = [JSONExtraType, Segment[]][];
4
- export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
5
- data: unknown;
6
- meta: JSONMeta;
7
- };
8
- export declare function deserialize({ data, meta, }: {
9
- data: unknown;
10
- meta: JSONMeta;
11
- }): unknown;
12
- //# sourceMappingURL=super-json.d.ts.map
@@ -1,21 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Context } from '../../context';
3
- export type FetchHandleOptions<T extends Context> = {
4
- prefix?: HTTPPath;
5
- } & (Record<never, never> extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
11
- export type FetchHandleResult = {
12
- matched: true;
13
- response: Response;
14
- } | {
15
- matched: false;
16
- response: undefined;
17
- };
18
- export interface FetchHandler<T extends Context> {
19
- handle(request: Request, ...rest: FetchHandleRest<T>): Promise<FetchHandleResult>;
20
- }
21
- //# sourceMappingURL=types.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './middleware';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { Context as HonoContext, MiddlewareHandler } from 'hono';
2
- import type { Context } from '../../context';
3
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
- context?: Value<T, [HonoContext]>;
7
- } : {
8
- context: Value<T, [HonoContext]>;
9
- });
10
- export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
11
- export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
12
- //# sourceMappingURL=middleware.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './serve';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,19 +0,0 @@
1
- import type { NextRequest } from 'next/server';
2
- import type { Context } from '../../context';
3
- import type { FetchHandleOptions, FetchHandler } from '../fetch';
4
- import { type Value } from '@orpc/shared';
5
- export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
- context?: Value<T, [NextRequest]>;
7
- } : {
8
- context: Value<T, [NextRequest]>;
9
- });
10
- export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
11
- export interface ServeResult {
12
- GET(req: NextRequest): Promise<Response>;
13
- POST(req: NextRequest): Promise<Response>;
14
- PUT(req: NextRequest): Promise<Response>;
15
- PATCH(req: NextRequest): Promise<Response>;
16
- DELETE(req: NextRequest): Promise<Response>;
17
- }
18
- export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
19
- //# sourceMappingURL=serve.d.ts.map
@@ -1,5 +0,0 @@
1
- export * from './orpc-handler';
2
- export * from './orpc-handler';
3
- export * from './request-listener';
4
- export * from './types';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ServerResponse } from 'node:http';
2
- import type { Context } from '../../context';
3
- import type { Router } from '../../router';
4
- import type { RPCHandlerOptions } from '../fetch/orpc-handler';
5
- import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
6
- import { type ExpressableIncomingMessage } from './request-listener';
7
- export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
8
- private readonly orpcFetchHandler;
9
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
10
- handle(req: ExpressableIncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
11
- }
12
- //# sourceMappingURL=orpc-handler.d.ts.map
@@ -1,28 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http';
2
- export interface ExpressableIncomingMessage extends IncomingMessage {
3
- originalUrl?: string;
4
- }
5
- /**
6
- * Creates a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object from a Node.js
7
- * [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) and
8
- * [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) pair.
9
- *
10
- */
11
- export declare function createRequest(req: ExpressableIncomingMessage, res: ServerResponse): Request;
12
- /**
13
- * Creates a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object from the headers
14
- * in a Node.js [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
15
- *
16
- * @param req The incoming request object.
17
- * @returns A headers object.
18
- */
19
- export declare function createHeaders(req: IncomingMessage): Headers;
20
- /**
21
- * Sends a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to the client using the
22
- * Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) object.
23
- *
24
- * @param res The server response object.
25
- * @param response The response to send.
26
- */
27
- export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
28
- //# sourceMappingURL=request-listener.d.ts.map
@@ -1,22 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
3
- import type { IncomingMessage, ServerResponse } from 'node:http';
4
- import type { Context } from '../../context';
5
- export type RequestHandleOptions<T extends Context> = {
6
- prefix?: HTTPPath;
7
- beforeSend?(response: Response, context: T): Promisable<void>;
8
- } & (Record<never, never> extends T ? {
9
- context?: T;
10
- } : {
11
- context: T;
12
- });
13
- export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
14
- export type RequestHandleResult = {
15
- matched: true;
16
- } | {
17
- matched: false;
18
- };
19
- export interface RequestHandler<T extends Context> {
20
- handle(req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
21
- }
22
- //# sourceMappingURL=types.d.ts.map