@orpc/server 0.0.0-next.fd0ca3d → 0.0.0-next.fd117b2

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/README.md ADDED
@@ -0,0 +1,118 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/server">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fserver?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
+
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
+ - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
+ - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
+ - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
+ - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
+ - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
+ - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
+ - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
+ - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
+ - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
+ - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
+ - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
+ - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
+ - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
+ - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
46
+
47
+ ## Documentation
48
+
49
+ You can find the full documentation [here](https://orpc.unnoq.com).
50
+
51
+ ## Packages
52
+
53
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+
62
+ ## `@orpc/server`
63
+
64
+ Build your API or implement API contract. Read the [documentation](https://orpc.unnoq.com/docs/getting-started) for more information.
65
+
66
+ ```ts
67
+ import type { IncomingHttpHeaders } from 'node:http'
68
+ import { ORPCError, os } from '@orpc/server'
69
+ import { z } from 'zod'
70
+
71
+ const PlanetSchema = z.object({
72
+ id: z.number().int().min(1),
73
+ name: z.string(),
74
+ description: z.string().optional(),
75
+ })
76
+
77
+ export const listPlanet = os
78
+ .input(
79
+ z.object({
80
+ limit: z.number().int().min(1).max(100).optional(),
81
+ cursor: z.number().int().min(0).default(0),
82
+ }),
83
+ )
84
+ .handler(async ({ input }) => {
85
+ // your list code here
86
+ return [{ id: 1, name: 'name' }]
87
+ })
88
+
89
+ export const findPlanet = os
90
+ .input(PlanetSchema.pick({ id: true }))
91
+ .handler(async ({ input }) => {
92
+ // your find code here
93
+ return { id: 1, name: 'name' }
94
+ })
95
+
96
+ export const createPlanet = os
97
+ .$context<{ headers: IncomingHttpHeaders }>()
98
+ .use(({ context, next }) => {
99
+ const user = parseJWT(context.headers.authorization?.split(' ')[1])
100
+
101
+ if (user) {
102
+ return next({ context: { user } })
103
+ }
104
+
105
+ throw new ORPCError('UNAUTHORIZED')
106
+ })
107
+ .input(PlanetSchema.omit({ id: true }))
108
+ .handler(async ({ input, context }) => {
109
+ // your create code here
110
+ return { id: 1, name: 'name' }
111
+ })
112
+
113
+ export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
114
+ ```
115
+
116
+ ## License
117
+
118
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -82,13 +82,14 @@ var StandardHandler = class {
82
82
 
83
83
  // src/adapters/standard/rpc-codec.ts
84
84
  import { RPCSerializer } from "@orpc/client/rpc";
85
+ import { parseEmptyableJSON } from "@orpc/server-standard";
85
86
  var RPCCodec = class {
86
87
  serializer;
87
88
  constructor(options = {}) {
88
89
  this.serializer = options.serializer ?? new RPCSerializer();
89
90
  }
90
91
  async decode(request, _params, _procedure) {
91
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
92
+ const serialized = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("data").at(-1)) : await request.body();
92
93
  return this.serializer.deserialize(serialized);
93
94
  }
94
95
  encode(output, _procedure) {
@@ -178,4 +179,4 @@ export {
178
179
  RPCCodec,
179
180
  RPCMatcher
180
181
  };
181
- //# sourceMappingURL=chunk-77FU7QSO.js.map
182
+ //# sourceMappingURL=chunk-7A2ZRAPK.js.map
@@ -2,7 +2,7 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-77FU7QSO.js";
5
+ } from "./chunk-7A2ZRAPK.js";
6
6
 
7
7
  // src/adapters/fetch/rpc-handler.ts
8
8
  import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
@@ -29,4 +29,4 @@ var RPCHandler = class {
29
29
  export {
30
30
  RPCHandler
31
31
  };
32
- //# sourceMappingURL=chunk-47YYO5JS.js.map
32
+ //# sourceMappingURL=chunk-MEBJNUSY.js.map
package/dist/fetch.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-47YYO5JS.js";
4
- import "./chunk-77FU7QSO.js";
3
+ } from "./chunk-MEBJNUSY.js";
4
+ import "./chunk-7A2ZRAPK.js";
5
5
  import "./chunk-MHVECKBC.js";
6
6
  import "./chunk-WQNNSBXW.js";
7
7
  export {
package/dist/hono.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-47YYO5JS.js";
4
- import "./chunk-77FU7QSO.js";
3
+ } from "./chunk-MEBJNUSY.js";
4
+ import "./chunk-7A2ZRAPK.js";
5
5
  import "./chunk-MHVECKBC.js";
6
6
  import "./chunk-WQNNSBXW.js";
7
7
 
package/dist/next.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RPCHandler
3
- } from "./chunk-47YYO5JS.js";
4
- import "./chunk-77FU7QSO.js";
3
+ } from "./chunk-MEBJNUSY.js";
4
+ import "./chunk-7A2ZRAPK.js";
5
5
  import "./chunk-MHVECKBC.js";
6
6
  import "./chunk-WQNNSBXW.js";
7
7
 
package/dist/node.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-77FU7QSO.js";
5
+ } from "./chunk-7A2ZRAPK.js";
6
6
  import "./chunk-MHVECKBC.js";
7
7
  import "./chunk-WQNNSBXW.js";
8
8
 
@@ -1,8 +1,8 @@
1
1
  import type { ORPCError } from '@orpc/client';
2
- import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
2
  import type { AnyProcedure } from '../../procedure';
4
3
  import type { StandardCodec, StandardParams } from './types';
5
4
  import { RPCSerializer } from '@orpc/client/rpc';
5
+ import { type StandardRequest, type StandardResponse } from '@orpc/server-standard';
6
6
  export interface StandardCodecOptions {
7
7
  serializer?: RPCSerializer;
8
8
  }
package/dist/standard.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  RPCCodec,
3
3
  RPCMatcher,
4
4
  StandardHandler
5
- } from "./chunk-77FU7QSO.js";
5
+ } from "./chunk-7A2ZRAPK.js";
6
6
  import "./chunk-MHVECKBC.js";
7
7
  import "./chunk-WQNNSBXW.js";
8
8
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.0.0-next.fd0ca3d",
4
+ "version": "0.0.0-next.fd117b2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -66,9 +66,9 @@
66
66
  "@orpc/server-standard": "^0.4.0",
67
67
  "@orpc/server-standard-fetch": "^0.4.0",
68
68
  "@orpc/server-standard-node": "^0.4.0",
69
- "@orpc/client": "0.0.0-next.fd0ca3d",
70
- "@orpc/contract": "0.0.0-next.fd0ca3d",
71
- "@orpc/shared": "0.0.0-next.fd0ca3d"
69
+ "@orpc/contract": "0.0.0-next.fd117b2",
70
+ "@orpc/client": "0.0.0-next.fd117b2",
71
+ "@orpc/shared": "0.0.0-next.fd117b2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "light-my-request": "^6.5.1"