@orpc/standard-server 0.0.0-next.cc4cb21 → 0.0.0-next.d0e429d
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,68 @@
|
|
|
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/standard-server">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fstandard-server?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/standard-server`
|
|
63
|
+
|
|
64
|
+
This package is designed to be used as a base for other server implementations.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.js
CHANGED
|
@@ -10,29 +10,25 @@ var ErrorEvent = class extends Error {
|
|
|
10
10
|
this.data = options?.data;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
var UnknownEvent = class extends ErrorEvent {
|
|
14
|
-
};
|
|
15
13
|
|
|
16
14
|
// src/event-source/decoder.ts
|
|
17
15
|
function decodeEventMessage(encoded) {
|
|
18
16
|
const lines = encoded.replace(/\n+$/, "").split(/\n/);
|
|
19
17
|
const message = {
|
|
20
|
-
data:
|
|
18
|
+
data: void 0,
|
|
21
19
|
event: void 0,
|
|
22
20
|
id: void 0,
|
|
23
|
-
retry: void 0
|
|
21
|
+
retry: void 0,
|
|
22
|
+
comments: []
|
|
24
23
|
};
|
|
25
24
|
for (const line of lines) {
|
|
26
|
-
const index = line.indexOf(":
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new EventDecoderError(`Duplicate EventSource message key: ${key}`);
|
|
34
|
-
}
|
|
35
|
-
if (key === "data") {
|
|
25
|
+
const index = line.indexOf(":");
|
|
26
|
+
const key = index === -1 ? line : line.slice(0, index);
|
|
27
|
+
const value = index === -1 ? "" : line.slice(index + 1).replace(/^\s/, "");
|
|
28
|
+
if (index === 0) {
|
|
29
|
+
message.comments.push(value);
|
|
30
|
+
} else if (key === "data") {
|
|
31
|
+
message.data ??= "";
|
|
36
32
|
message.data += `${value}
|
|
37
33
|
`;
|
|
38
34
|
} else if (key === "event") {
|
|
@@ -41,15 +37,12 @@ function decodeEventMessage(encoded) {
|
|
|
41
37
|
message.id = value;
|
|
42
38
|
} else if (key === "retry") {
|
|
43
39
|
const maybeInteger = Number.parseInt(value);
|
|
44
|
-
if (
|
|
45
|
-
|
|
40
|
+
if (Number.isInteger(maybeInteger) && maybeInteger >= 0 && maybeInteger.toString() === value) {
|
|
41
|
+
message.retry = maybeInteger;
|
|
46
42
|
}
|
|
47
|
-
message.retry = maybeInteger;
|
|
48
|
-
} else {
|
|
49
|
-
throw new EventDecoderError(`Unknown EventSource message key: ${key}`);
|
|
50
43
|
}
|
|
51
44
|
}
|
|
52
|
-
message.data = message.data
|
|
45
|
+
message.data = message.data?.replace(/\n$/, "");
|
|
53
46
|
return message;
|
|
54
47
|
}
|
|
55
48
|
var EventDecoder = class {
|
|
@@ -63,12 +56,9 @@ var EventDecoder = class {
|
|
|
63
56
|
if (lastCompleteIndex === -1) {
|
|
64
57
|
return;
|
|
65
58
|
}
|
|
66
|
-
const completes = this.incomplete.slice(0, lastCompleteIndex
|
|
59
|
+
const completes = this.incomplete.slice(0, lastCompleteIndex).split(/\n\n/);
|
|
67
60
|
this.incomplete = this.incomplete.slice(lastCompleteIndex + 2);
|
|
68
61
|
for (const encoded of completes) {
|
|
69
|
-
if (!encoded) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
62
|
const message = decodeEventMessage(`${encoded}
|
|
73
63
|
|
|
74
64
|
`);
|
|
@@ -79,7 +69,9 @@ var EventDecoder = class {
|
|
|
79
69
|
this.incomplete = "";
|
|
80
70
|
}
|
|
81
71
|
end() {
|
|
82
|
-
this.
|
|
72
|
+
if (this.incomplete) {
|
|
73
|
+
throw new EventDecoderError("EventSource ended before complete");
|
|
74
|
+
}
|
|
83
75
|
}
|
|
84
76
|
};
|
|
85
77
|
var EventDecoderStream = class extends TransformStream {
|
|
@@ -119,8 +111,13 @@ function assertEventRetry(retry) {
|
|
|
119
111
|
throw new EventEncoderError("Event-source retry must be a integer and >= 0");
|
|
120
112
|
}
|
|
121
113
|
}
|
|
114
|
+
function assertEventComment(comment) {
|
|
115
|
+
if (comment.includes("\n")) {
|
|
116
|
+
throw new EventEncoderError("Event-source comment must not contain a newline character");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
122
119
|
function encodeEventData(data) {
|
|
123
|
-
const lines = data
|
|
120
|
+
const lines = data?.split(/\n/) ?? [];
|
|
124
121
|
let output = "";
|
|
125
122
|
for (const line of lines) {
|
|
126
123
|
output += `data: ${line}
|
|
@@ -128,8 +125,18 @@ function encodeEventData(data) {
|
|
|
128
125
|
}
|
|
129
126
|
return output;
|
|
130
127
|
}
|
|
128
|
+
function encodeEventComments(comments) {
|
|
129
|
+
let output = "";
|
|
130
|
+
for (const comment of comments ?? []) {
|
|
131
|
+
assertEventComment(comment);
|
|
132
|
+
output += `: ${comment}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
return output;
|
|
136
|
+
}
|
|
131
137
|
function encodeEventMessage(message) {
|
|
132
138
|
let output = "";
|
|
139
|
+
output += encodeEventComments(message.comments);
|
|
133
140
|
if (message.event !== void 0) {
|
|
134
141
|
assertEventName(message.event);
|
|
135
142
|
output += `event: ${message.event}
|
|
@@ -160,6 +167,11 @@ function withEventMeta(container, meta) {
|
|
|
160
167
|
if (meta.retry !== void 0) {
|
|
161
168
|
assertEventRetry(meta.retry);
|
|
162
169
|
}
|
|
170
|
+
if (meta.comments !== void 0) {
|
|
171
|
+
for (const comment of meta.comments) {
|
|
172
|
+
assertEventComment(comment);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
163
175
|
return new Proxy(container, {
|
|
164
176
|
get(target, prop, receiver) {
|
|
165
177
|
if (prop === EVENT_SOURCE_META_SYMBOL) {
|
|
@@ -181,12 +193,13 @@ export {
|
|
|
181
193
|
EventDecoderError,
|
|
182
194
|
EventDecoderStream,
|
|
183
195
|
EventEncoderError,
|
|
184
|
-
|
|
196
|
+
assertEventComment,
|
|
185
197
|
assertEventId,
|
|
186
198
|
assertEventName,
|
|
187
199
|
assertEventRetry,
|
|
188
200
|
contentDisposition,
|
|
189
201
|
decodeEventMessage,
|
|
202
|
+
encodeEventComments,
|
|
190
203
|
encodeEventData,
|
|
191
204
|
encodeEventMessage,
|
|
192
205
|
getEventMeta,
|
|
@@ -2,6 +2,8 @@ import type { EventMessage } from './types';
|
|
|
2
2
|
export declare function assertEventId(id: string): void;
|
|
3
3
|
export declare function assertEventName(event: string): void;
|
|
4
4
|
export declare function assertEventRetry(retry: number): void;
|
|
5
|
+
export declare function assertEventComment(comment: string): void;
|
|
5
6
|
export declare function encodeEventData(data: string | undefined): string;
|
|
7
|
+
export declare function encodeEventComments(comments: string[] | undefined): string;
|
|
6
8
|
export declare function encodeEventMessage(message: Partial<EventMessage>): string;
|
|
7
9
|
//# sourceMappingURL=encoder.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventMessage } from './types';
|
|
2
|
-
export type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id'>>;
|
|
2
|
+
export type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id' | 'comments'>>;
|
|
3
3
|
export declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
|
|
4
4
|
export declare function getEventMeta(container: unknown): EventMeta | undefined;
|
|
5
5
|
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export interface EventMessage {
|
|
2
2
|
event: string | undefined;
|
|
3
3
|
id: string | undefined;
|
|
4
|
-
data: string;
|
|
4
|
+
data: string | undefined;
|
|
5
5
|
/**
|
|
6
6
|
* The number of milliseconds to wait before retrying the event source if error occurs.
|
|
7
7
|
*/
|
|
8
8
|
retry: number | undefined;
|
|
9
|
+
comments: string[];
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.d0e429d",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@tinyhttp/content-disposition": "^2.2.2",
|
|
32
|
-
"@orpc/shared": "0.0.0-next.
|
|
32
|
+
"@orpc/shared": "0.0.0-next.d0e429d"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|