@orpc/standard-server 0.0.0-next.b2e67f7 → 0.0.0-next.b36125c
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 +68 -0
- package/dist/index.js +20 -58
- package/dist/src/event-source/errors.d.ts +2 -5
- package/dist/src/event-source/meta.d.ts +0 -1
- package/dist/src/event-source/types.d.ts +2 -1
- package/dist/src/types.d.ts +1 -3
- package/dist/src/utils.d.ts +0 -4
- package/package.json +2 -2
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 {
|
|
@@ -120,7 +112,7 @@ function assertEventRetry(retry) {
|
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
function encodeEventData(data) {
|
|
123
|
-
const lines = data
|
|
115
|
+
const lines = data?.split(/\n/) ?? [];
|
|
124
116
|
let output = "";
|
|
125
117
|
for (const line of lines) {
|
|
126
118
|
output += `data: ${line}
|
|
@@ -151,10 +143,8 @@ function encodeEventMessage(message) {
|
|
|
151
143
|
}
|
|
152
144
|
|
|
153
145
|
// src/event-source/meta.ts
|
|
146
|
+
import { isTypescriptObject } from "@orpc/shared";
|
|
154
147
|
var EVENT_SOURCE_META_SYMBOL = Symbol("ORPC_EVENT_SOURCE_META");
|
|
155
|
-
function isEventMetaContainer(value) {
|
|
156
|
-
return !!value && (typeof value === "object" || typeof value === "function");
|
|
157
|
-
}
|
|
158
148
|
function withEventMeta(container, meta) {
|
|
159
149
|
if (meta.id !== void 0) {
|
|
160
150
|
assertEventId(meta.id);
|
|
@@ -172,41 +162,17 @@ function withEventMeta(container, meta) {
|
|
|
172
162
|
});
|
|
173
163
|
}
|
|
174
164
|
function getEventMeta(container) {
|
|
175
|
-
return
|
|
165
|
+
return isTypescriptObject(container) ? Reflect.get(container, EVENT_SOURCE_META_SYMBOL) : void 0;
|
|
176
166
|
}
|
|
177
167
|
|
|
178
168
|
// src/utils.ts
|
|
179
169
|
import { contentDisposition, parse } from "@tinyhttp/content-disposition";
|
|
180
|
-
function once(fn) {
|
|
181
|
-
let cached;
|
|
182
|
-
return () => {
|
|
183
|
-
if (cached) {
|
|
184
|
-
return cached.result;
|
|
185
|
-
}
|
|
186
|
-
const result = fn();
|
|
187
|
-
cached = { result };
|
|
188
|
-
return result;
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function parseEmptyableJSON(text) {
|
|
192
|
-
if (!text) {
|
|
193
|
-
return void 0;
|
|
194
|
-
}
|
|
195
|
-
return JSON.parse(text);
|
|
196
|
-
}
|
|
197
|
-
function isAsyncIteratorObject(maybe) {
|
|
198
|
-
if (!maybe || typeof maybe !== "object") {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
202
|
-
}
|
|
203
170
|
export {
|
|
204
171
|
ErrorEvent,
|
|
205
172
|
EventDecoder,
|
|
206
173
|
EventDecoderError,
|
|
207
174
|
EventDecoderStream,
|
|
208
175
|
EventEncoderError,
|
|
209
|
-
UnknownEvent,
|
|
210
176
|
assertEventId,
|
|
211
177
|
assertEventName,
|
|
212
178
|
assertEventRetry,
|
|
@@ -215,11 +181,7 @@ export {
|
|
|
215
181
|
encodeEventData,
|
|
216
182
|
encodeEventMessage,
|
|
217
183
|
getEventMeta,
|
|
218
|
-
isAsyncIteratorObject,
|
|
219
|
-
isEventMetaContainer,
|
|
220
|
-
once,
|
|
221
184
|
parse as parseContentDisposition,
|
|
222
|
-
parseEmptyableJSON,
|
|
223
185
|
withEventMeta
|
|
224
186
|
};
|
|
225
187
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import type { JsonValue } from 'type-fest';
|
|
2
1
|
export declare class EventEncoderError extends TypeError {
|
|
3
2
|
}
|
|
4
3
|
export declare class EventDecoderError extends TypeError {
|
|
5
4
|
}
|
|
6
5
|
export interface ErrorEventOptions extends ErrorOptions {
|
|
7
6
|
message?: string;
|
|
8
|
-
data?:
|
|
7
|
+
data?: unknown;
|
|
9
8
|
}
|
|
10
9
|
export declare class ErrorEvent extends Error {
|
|
11
|
-
data:
|
|
10
|
+
data: unknown;
|
|
12
11
|
constructor(options?: ErrorEventOptions);
|
|
13
12
|
}
|
|
14
|
-
export declare class UnknownEvent extends ErrorEvent {
|
|
15
|
-
}
|
|
16
13
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EventMessage } from './types';
|
|
2
2
|
export type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id'>>;
|
|
3
|
-
export declare function isEventMetaContainer(value: unknown): value is Record<PropertyKey, unknown>;
|
|
4
3
|
export declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
|
|
5
4
|
export declare function getEventMeta(container: unknown): EventMeta | undefined;
|
|
6
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/dist/src/types.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { JsonValue } from 'type-fest';
|
|
2
|
-
export type { JsonValue };
|
|
3
1
|
export interface StandardHeaders {
|
|
4
2
|
[key: string]: string | string[] | undefined;
|
|
5
3
|
}
|
|
6
|
-
export type StandardBody = undefined |
|
|
4
|
+
export type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
|
7
5
|
export interface StandardRequest {
|
|
8
6
|
/**
|
|
9
7
|
* Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { JsonValue } from 'type-fest';
|
|
2
|
-
export declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
|
|
3
|
-
export declare function parseEmptyableJSON(text: string): JsonValue | undefined;
|
|
4
|
-
export declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
|
|
5
1
|
export { contentDisposition, parse as parseContentDisposition } from '@tinyhttp/content-disposition';
|
|
6
2
|
//# sourceMappingURL=utils.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.b36125c",
|
|
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
|
-
"
|
|
32
|
+
"@orpc/shared": "0.0.0-next.b36125c"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|