@orpc/standard-server 1.0.0-beta.6 → 1.0.3
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 +13 -17
- package/dist/batch/index.d.mts +3 -2
- package/dist/batch/index.d.ts +3 -2
- package/dist/batch/index.mjs +41 -15
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
@@ -21,28 +21,24 @@
|
|
21
21
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
23
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
|
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
|
25
25
|
|
26
26
|
---
|
27
27
|
|
28
28
|
## Highlights
|
29
29
|
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
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.
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
46
42
|
|
47
43
|
## Documentation
|
48
44
|
|
package/dist/batch/index.d.mts
CHANGED
@@ -18,6 +18,7 @@ interface ToBatchResponseOptions extends StandardResponse {
|
|
18
18
|
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
|
19
19
|
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
20
|
|
21
|
-
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
|
21
|
+
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
22
22
|
|
23
|
-
export {
|
23
|
+
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
24
|
+
export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
|
package/dist/batch/index.d.ts
CHANGED
@@ -18,6 +18,7 @@ interface ToBatchResponseOptions extends StandardResponse {
|
|
18
18
|
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
|
19
19
|
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
20
|
|
21
|
-
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
|
21
|
+
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
22
22
|
|
23
|
-
export {
|
23
|
+
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
24
|
+
export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
|
package/dist/batch/index.mjs
CHANGED
@@ -2,17 +2,22 @@ import { stringifyJSON, parseEmptyableJSON, isAsyncIteratorObject, isObject } fr
|
|
2
2
|
|
3
3
|
function toBatchAbortSignal(signals) {
|
4
4
|
const realSignals = signals.filter((signal) => signal !== void 0);
|
5
|
-
|
6
|
-
|
7
|
-
if (abortedSignals.length && abortedSignals.length === realSignals.length) {
|
8
|
-
controller.abort();
|
5
|
+
if (realSignals.length === 0 || realSignals.length !== signals.length) {
|
6
|
+
return void 0;
|
9
7
|
}
|
8
|
+
const controller = new AbortController();
|
9
|
+
const abortIfAllInputsAborted = () => {
|
10
|
+
if (realSignals.every((signal) => signal.aborted)) {
|
11
|
+
controller.abort();
|
12
|
+
}
|
13
|
+
};
|
14
|
+
abortIfAllInputsAborted();
|
10
15
|
for (const signal of realSignals) {
|
11
16
|
signal.addEventListener("abort", () => {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
abortIfAllInputsAborted();
|
18
|
+
}, {
|
19
|
+
once: true,
|
20
|
+
signal: controller.signal
|
16
21
|
});
|
17
22
|
}
|
18
23
|
return controller.signal;
|
@@ -23,8 +28,8 @@ function toBatchRequest(options) {
|
|
23
28
|
let body;
|
24
29
|
const batchRequestItems = options.requests.map((request) => ({
|
25
30
|
body: request.body,
|
26
|
-
headers: request.headers,
|
27
|
-
method: request.method,
|
31
|
+
headers: Object.keys(request.headers).length ? request.headers : void 0,
|
32
|
+
method: request.method === options.method ? void 0 : request.method,
|
28
33
|
url: request.url
|
29
34
|
}));
|
30
35
|
if (options.method === "GET") {
|
@@ -47,9 +52,9 @@ function parseBatchRequest(request) {
|
|
47
52
|
}
|
48
53
|
return items.map((item) => {
|
49
54
|
return {
|
50
|
-
method: item.method,
|
55
|
+
method: item.method ?? request.method,
|
51
56
|
url: new URL(item.url),
|
52
|
-
headers: item.headers,
|
57
|
+
headers: item.headers ?? {},
|
53
58
|
body: item.body,
|
54
59
|
signal: request.signal
|
55
60
|
};
|
@@ -57,7 +62,23 @@ function parseBatchRequest(request) {
|
|
57
62
|
}
|
58
63
|
|
59
64
|
function toBatchResponse(options) {
|
60
|
-
return
|
65
|
+
return {
|
66
|
+
...options,
|
67
|
+
body: async function* () {
|
68
|
+
try {
|
69
|
+
for await (const item of options.body) {
|
70
|
+
yield {
|
71
|
+
index: item.index,
|
72
|
+
status: item.status === options.status ? void 0 : item.status,
|
73
|
+
headers: Object.keys(item.headers).length ? item.headers : void 0,
|
74
|
+
body: item.body
|
75
|
+
};
|
76
|
+
}
|
77
|
+
} finally {
|
78
|
+
options.body.return?.();
|
79
|
+
}
|
80
|
+
}()
|
81
|
+
};
|
61
82
|
}
|
62
83
|
function parseBatchResponse(response) {
|
63
84
|
const body = response.body;
|
@@ -69,12 +90,17 @@ function parseBatchResponse(response) {
|
|
69
90
|
return async function* () {
|
70
91
|
try {
|
71
92
|
for await (const item of body) {
|
72
|
-
if (!isObject(item) || !("index" in item) ||
|
93
|
+
if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
|
73
94
|
throw new TypeError("Invalid batch response", {
|
74
95
|
cause: item
|
75
96
|
});
|
76
97
|
}
|
77
|
-
yield
|
98
|
+
yield {
|
99
|
+
index: item.index,
|
100
|
+
status: item.status ?? response.status,
|
101
|
+
headers: item.headers ?? {},
|
102
|
+
body: item.body
|
103
|
+
};
|
78
104
|
}
|
79
105
|
} finally {
|
80
106
|
await body.return?.();
|
package/dist/index.d.mts
CHANGED
@@ -56,4 +56,5 @@ declare function generateContentDisposition(filename: string): string;
|
|
56
56
|
declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
|
57
57
|
declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
|
58
58
|
|
59
|
-
export { ErrorEvent,
|
59
|
+
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
60
|
+
export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
|
package/dist/index.d.ts
CHANGED
@@ -56,4 +56,5 @@ declare function generateContentDisposition(filename: string): string;
|
|
56
56
|
declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
|
57
57
|
declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
|
58
58
|
|
59
|
-
export { ErrorEvent,
|
59
|
+
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
60
|
+
export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/standard-server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://unnoq.com",
|
7
7
|
"repository": {
|
@@ -28,7 +28,7 @@
|
|
28
28
|
"dist"
|
29
29
|
],
|
30
30
|
"dependencies": {
|
31
|
-
"@orpc/shared": "1.0.
|
31
|
+
"@orpc/shared": "1.0.3"
|
32
32
|
},
|
33
33
|
"scripts": {
|
34
34
|
"build": "unbuild",
|