@orpc/server 0.0.0-next.316c163 → 0.0.0-next.32cb70c

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 (57) hide show
  1. package/dist/chunk-ESTRJAOX.js +299 -0
  2. package/dist/chunk-KK4SDLC7.js +320 -0
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +11 -108
  5. package/dist/hono.js +30 -0
  6. package/dist/index.js +257 -385
  7. package/dist/next.js +36 -0
  8. package/dist/node.js +87 -0
  9. package/dist/src/adapters/fetch/index.d.ts +6 -0
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
  12. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
  13. package/dist/src/adapters/fetch/super-json.d.ts +12 -0
  14. package/dist/src/adapters/fetch/types.d.ts +21 -0
  15. package/dist/src/adapters/hono/index.d.ts +3 -0
  16. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  17. package/dist/src/adapters/next/index.d.ts +3 -0
  18. package/dist/src/adapters/next/serve.d.ts +19 -0
  19. package/dist/src/adapters/node/index.d.ts +5 -0
  20. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  21. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  22. package/dist/src/adapters/node/types.d.ts +22 -0
  23. package/dist/src/builder-variants.d.ts +74 -0
  24. package/dist/src/builder.d.ts +52 -30
  25. package/dist/src/config.d.ts +6 -0
  26. package/dist/src/context.d.ts +9 -0
  27. package/dist/src/hidden.d.ts +6 -4
  28. package/dist/src/implementer-procedure.d.ts +30 -0
  29. package/dist/src/implementer-variants.d.ts +16 -0
  30. package/dist/src/implementer.d.ts +27 -0
  31. package/dist/src/index.d.ts +10 -12
  32. package/dist/src/lazy-utils.d.ts +4 -2
  33. package/dist/src/lazy.d.ts +9 -5
  34. package/dist/src/middleware-decorated.d.ts +7 -5
  35. package/dist/src/middleware-utils.d.ts +5 -0
  36. package/dist/src/middleware.d.ts +28 -14
  37. package/dist/src/procedure-client.d.ts +8 -17
  38. package/dist/src/procedure-decorated.d.ts +18 -11
  39. package/dist/src/procedure-utils.d.ts +17 -0
  40. package/dist/src/procedure.d.ts +24 -18
  41. package/dist/src/router-accessible-lazy.d.ts +8 -0
  42. package/dist/src/router-client.d.ts +7 -10
  43. package/dist/src/router.d.ts +25 -12
  44. package/package.json +22 -10
  45. package/dist/chunk-FN62GL22.js +0 -182
  46. package/dist/src/fetch/handle-request.d.ts +0 -7
  47. package/dist/src/fetch/index.d.ts +0 -4
  48. package/dist/src/fetch/orpc-handler.d.ts +0 -3
  49. package/dist/src/fetch/types.d.ts +0 -28
  50. package/dist/src/implementer-chainable.d.ts +0 -10
  51. package/dist/src/lazy-decorated.d.ts +0 -10
  52. package/dist/src/procedure-builder.d.ts +0 -22
  53. package/dist/src/procedure-implementer.d.ts +0 -18
  54. package/dist/src/router-builder.d.ts +0 -29
  55. package/dist/src/router-implementer.d.ts +0 -21
  56. package/dist/src/types.d.ts +0 -12
  57. package/dist/src/utils.d.ts +0 -3
package/dist/fetch.js CHANGED
@@ -1,112 +1,15 @@
1
+ import "./chunk-WUOGVGWG.js";
1
2
  import {
2
- createProcedureClient,
3
- getRouterChild,
4
- isProcedure,
5
- unlazy
6
- } from "./chunk-FN62GL22.js";
7
-
8
- // src/fetch/handle-request.ts
9
- import { ORPCError } from "@orpc/shared/error";
10
- async function handleFetchRequest(options) {
11
- for (const handler of options.handlers) {
12
- const response = await handler(options);
13
- if (response) {
14
- return response;
15
- }
16
- }
17
- const error = new ORPCError({ code: "NOT_FOUND", message: "Not found" });
18
- return new Response(JSON.stringify(error.toJSON()), {
19
- status: error.status,
20
- headers: {
21
- "Content-Type": "application/json"
22
- }
23
- });
24
- }
25
-
26
- // src/fetch/orpc-handler.ts
27
- import { executeWithHooks, ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, 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_PROTOCOL_HEADER)?.includes(ORPC_PROTOCOL_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 = await resolveRouterMatch(options.router, pathname);
42
- if (!match) {
43
- throw new ORPCError2({ code: "NOT_FOUND", message: "Not found" });
44
- }
45
- const input = await parseRequestInput(options.request);
46
- const caller = createProcedureClient({
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 (error) {
69
- return handleErrorResponse(error);
70
- }
71
- };
72
- }
73
- async function resolveRouterMatch(router, pathname) {
74
- const pathSegments = trim(pathname, "/").split("/").map(decodeURIComponent);
75
- const match = getRouterChild(router, ...pathSegments);
76
- const { default: maybeProcedure } = await unlazy(match);
77
- if (!isProcedure(maybeProcedure)) {
78
- return void 0;
79
- }
80
- return {
81
- procedure: maybeProcedure,
82
- path: pathSegments
83
- };
84
- }
85
- async function parseRequestInput(request) {
86
- try {
87
- return await deserializer.deserialize(request);
88
- } catch (error) {
89
- throw new ORPCError2({
90
- code: "BAD_REQUEST",
91
- message: "Cannot parse request. Please check the request body and Content-Type header.",
92
- cause: error
93
- });
94
- }
95
- }
96
- function handleErrorResponse(error) {
97
- const orpcError = error instanceof ORPCError2 ? error : new ORPCError2({
98
- code: "INTERNAL_SERVER_ERROR",
99
- message: "Internal server error",
100
- cause: error
101
- });
102
- const { body, headers } = serializer.serialize(orpcError.toJSON());
103
- return new Response(body, {
104
- status: orpcError.status,
105
- headers
106
- });
107
- }
3
+ ORPCPayloadCodec,
4
+ ORPCProcedureMatcher,
5
+ RPCHandler,
6
+ super_json_exports
7
+ } from "./chunk-ESTRJAOX.js";
8
+ import "./chunk-KK4SDLC7.js";
108
9
  export {
109
- createORPCHandler,
110
- handleFetchRequest
10
+ ORPCPayloadCodec,
11
+ ORPCProcedureMatcher,
12
+ RPCHandler,
13
+ super_json_exports as SuperJSON
111
14
  };
112
15
  //# sourceMappingURL=fetch.js.map
package/dist/hono.js ADDED
@@ -0,0 +1,30 @@
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