@orpc/server 0.0.0-next.8b5a6d6 → 0.0.0-next.8f101b9

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 +298 -375
  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 +46 -42
  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 +8 -0
  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 +15 -11
  32. package/dist/src/lazy-utils.d.ts +6 -0
  33. package/dist/src/lazy.d.ts +13 -14
  34. package/dist/src/middleware-decorated.d.ts +10 -0
  35. package/dist/src/middleware-utils.d.ts +5 -0
  36. package/dist/src/middleware.d.ts +28 -17
  37. package/dist/src/procedure-client.d.ts +20 -0
  38. package/dist/src/procedure-decorated.d.ts +21 -0
  39. package/dist/src/procedure-utils.d.ts +17 -0
  40. package/dist/src/procedure.d.ts +25 -28
  41. package/dist/src/router-accessible-lazy.d.ts +8 -0
  42. package/dist/src/router-client.d.ts +22 -0
  43. package/dist/src/router.d.ts +25 -17
  44. package/package.json +22 -11
  45. package/dist/chunk-3JMSDC5L.js +0 -274
  46. package/dist/src/fetch/handle.d.ts +0 -7
  47. package/dist/src/fetch/handler.d.ts +0 -3
  48. package/dist/src/fetch/index.d.ts +0 -4
  49. package/dist/src/fetch/types.d.ts +0 -28
  50. package/dist/src/procedure-builder.d.ts +0 -31
  51. package/dist/src/procedure-caller.d.ts +0 -26
  52. package/dist/src/procedure-implementer.d.ts +0 -22
  53. package/dist/src/router-builder.d.ts +0 -27
  54. package/dist/src/router-caller.d.ts +0 -25
  55. package/dist/src/router-implementer.d.ts +0 -24
  56. package/dist/src/types.d.ts +0 -14
  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
- createProcedureCaller,
3
- isLazy,
4
- isProcedure
5
- } from "./chunk-3JMSDC5L.js";
6
-
7
- // src/fetch/handle.ts
8
- import { ORPCError } from "@orpc/shared/error";
9
- async function handleFetchRequest(options) {
10
- for (const handler of options.handlers) {
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
- }
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