@orpc/standard-server 1.3.0 → 1.4.0
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/dist/batch/index.d.mts +9 -3
- package/dist/batch/index.d.ts +9 -3
- package/dist/batch/index.mjs +53 -24
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +24 -2
- package/dist/shared/{standard-server.R_NaHlxw.d.mts → standard-server.BD8Sg1A5.d.mts} +1 -1
- package/dist/shared/{standard-server.R_NaHlxw.d.ts → standard-server.BD8Sg1A5.d.ts} +1 -1
- package/package.json +2 -2
package/dist/batch/index.d.mts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import { S as StandardHeaders,
|
1
|
+
import { S as StandardHeaders, c as StandardRequest, e as StandardResponse } from '../shared/standard-server.BD8Sg1A5.mjs';
|
2
|
+
import { Promisable } from '@orpc/shared';
|
2
3
|
|
3
4
|
interface ToBatchRequestOptions {
|
4
5
|
url: URL;
|
@@ -9,16 +10,21 @@ interface ToBatchRequestOptions {
|
|
9
10
|
declare function toBatchRequest(options: ToBatchRequestOptions): StandardRequest;
|
10
11
|
declare function parseBatchRequest(request: StandardRequest): StandardRequest[];
|
11
12
|
|
13
|
+
type BatchResponseMode = 'streaming' | 'buffered';
|
12
14
|
interface BatchResponseBodyItem extends StandardResponse {
|
13
15
|
index: number;
|
14
16
|
}
|
15
17
|
interface ToBatchResponseOptions extends StandardResponse {
|
16
18
|
body: AsyncIteratorObject<BatchResponseBodyItem>;
|
19
|
+
/**
|
20
|
+
* @default 'streaming'
|
21
|
+
*/
|
22
|
+
mode?: BatchResponseMode;
|
17
23
|
}
|
18
|
-
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse
|
24
|
+
declare function toBatchResponse(options: ToBatchResponseOptions): Promisable<StandardResponse>;
|
19
25
|
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
26
|
|
21
27
|
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
22
28
|
|
23
29
|
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
24
|
-
export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
|
30
|
+
export type { BatchResponseBodyItem, BatchResponseMode, ToBatchRequestOptions, ToBatchResponseOptions };
|
package/dist/batch/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import { S as StandardHeaders,
|
1
|
+
import { S as StandardHeaders, c as StandardRequest, e as StandardResponse } from '../shared/standard-server.BD8Sg1A5.js';
|
2
|
+
import { Promisable } from '@orpc/shared';
|
2
3
|
|
3
4
|
interface ToBatchRequestOptions {
|
4
5
|
url: URL;
|
@@ -9,16 +10,21 @@ interface ToBatchRequestOptions {
|
|
9
10
|
declare function toBatchRequest(options: ToBatchRequestOptions): StandardRequest;
|
10
11
|
declare function parseBatchRequest(request: StandardRequest): StandardRequest[];
|
11
12
|
|
13
|
+
type BatchResponseMode = 'streaming' | 'buffered';
|
12
14
|
interface BatchResponseBodyItem extends StandardResponse {
|
13
15
|
index: number;
|
14
16
|
}
|
15
17
|
interface ToBatchResponseOptions extends StandardResponse {
|
16
18
|
body: AsyncIteratorObject<BatchResponseBodyItem>;
|
19
|
+
/**
|
20
|
+
* @default 'streaming'
|
21
|
+
*/
|
22
|
+
mode?: BatchResponseMode;
|
17
23
|
}
|
18
|
-
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse
|
24
|
+
declare function toBatchResponse(options: ToBatchResponseOptions): Promisable<StandardResponse>;
|
19
25
|
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
26
|
|
21
27
|
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
|
22
28
|
|
23
29
|
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
24
|
-
export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
|
30
|
+
export type { BatchResponseBodyItem, BatchResponseMode, ToBatchRequestOptions, ToBatchResponseOptions };
|
package/dist/batch/index.mjs
CHANGED
@@ -62,8 +62,35 @@ function parseBatchRequest(request) {
|
|
62
62
|
}
|
63
63
|
|
64
64
|
function toBatchResponse(options) {
|
65
|
+
const mode = options.mode ?? "streaming";
|
66
|
+
const minifyResponseItem = (item) => {
|
67
|
+
return {
|
68
|
+
index: item.index,
|
69
|
+
status: item.status === options.status ? void 0 : item.status,
|
70
|
+
headers: Object.keys(item.headers).length ? item.headers : void 0,
|
71
|
+
body: item.body
|
72
|
+
};
|
73
|
+
};
|
74
|
+
if (mode === "buffered") {
|
75
|
+
return (async () => {
|
76
|
+
try {
|
77
|
+
const body = [];
|
78
|
+
for await (const item of options.body) {
|
79
|
+
body.push(minifyResponseItem(item));
|
80
|
+
}
|
81
|
+
return {
|
82
|
+
headers: options.headers,
|
83
|
+
status: options.status,
|
84
|
+
body
|
85
|
+
};
|
86
|
+
} finally {
|
87
|
+
await options.body.return?.();
|
88
|
+
}
|
89
|
+
})();
|
90
|
+
}
|
65
91
|
return {
|
66
|
-
|
92
|
+
headers: options.headers,
|
93
|
+
status: options.status,
|
67
94
|
body: async function* () {
|
68
95
|
try {
|
69
96
|
for await (const item of options.body) {
|
@@ -75,37 +102,39 @@ function toBatchResponse(options) {
|
|
75
102
|
};
|
76
103
|
}
|
77
104
|
} finally {
|
78
|
-
options.body.return?.();
|
105
|
+
await options.body.return?.();
|
79
106
|
}
|
80
107
|
}()
|
81
108
|
};
|
82
109
|
}
|
83
110
|
function parseBatchResponse(response) {
|
84
111
|
const body = response.body;
|
85
|
-
if (
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
112
|
+
if (isAsyncIteratorObject(body) || Array.isArray(body)) {
|
113
|
+
return async function* () {
|
114
|
+
try {
|
115
|
+
for await (const item of body) {
|
116
|
+
if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
|
117
|
+
throw new TypeError("Invalid batch response", {
|
118
|
+
cause: item
|
119
|
+
});
|
120
|
+
}
|
121
|
+
yield {
|
122
|
+
index: item.index,
|
123
|
+
status: item.status ?? response.status,
|
124
|
+
headers: item.headers ?? {},
|
125
|
+
body: item.body
|
126
|
+
};
|
127
|
+
}
|
128
|
+
} finally {
|
129
|
+
if (isAsyncIteratorObject(body)) {
|
130
|
+
await body.return?.();
|
97
131
|
}
|
98
|
-
yield {
|
99
|
-
index: item.index,
|
100
|
-
status: item.status ?? response.status,
|
101
|
-
headers: item.headers ?? {},
|
102
|
-
body: item.body
|
103
|
-
};
|
104
132
|
}
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
133
|
+
}();
|
134
|
+
}
|
135
|
+
throw new TypeError("Invalid batch response", {
|
136
|
+
cause: response
|
137
|
+
});
|
109
138
|
}
|
110
139
|
|
111
140
|
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as StandardHeaders } from './shared/standard-server.
|
2
|
-
export {
|
1
|
+
import { S as StandardHeaders, a as StandardLazyResponse } from './shared/standard-server.BD8Sg1A5.mjs';
|
2
|
+
export { b as StandardBody, d as StandardLazyRequest, c as StandardRequest, e as StandardResponse } from './shared/standard-server.BD8Sg1A5.mjs';
|
3
3
|
|
4
4
|
interface EventMessage {
|
5
5
|
event: string | undefined;
|
@@ -56,6 +56,7 @@ 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
|
declare function flattenHeader(header: string | readonly string[] | undefined): string | undefined;
|
59
|
+
declare function replicateStandardLazyResponse(response: StandardLazyResponse, count: number): StandardLazyResponse[];
|
59
60
|
|
60
|
-
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
61
|
+
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
|
61
62
|
export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as StandardHeaders } from './shared/standard-server.
|
2
|
-
export {
|
1
|
+
import { S as StandardHeaders, a as StandardLazyResponse } from './shared/standard-server.BD8Sg1A5.js';
|
2
|
+
export { b as StandardBody, d as StandardLazyRequest, c as StandardRequest, e as StandardResponse } from './shared/standard-server.BD8Sg1A5.js';
|
3
3
|
|
4
4
|
interface EventMessage {
|
5
5
|
event: string | undefined;
|
@@ -56,6 +56,7 @@ 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
|
declare function flattenHeader(header: string | readonly string[] | undefined): string | undefined;
|
59
|
+
declare function replicateStandardLazyResponse(response: StandardLazyResponse, count: number): StandardLazyResponse[];
|
59
60
|
|
60
|
-
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
61
|
+
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, StandardLazyResponse, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
|
61
62
|
export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
|
package/dist/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isTypescriptObject, toArray } from '@orpc/shared';
|
1
|
+
import { isTypescriptObject, toArray, once, isAsyncIteratorObject, replicateAsyncIterator } from '@orpc/shared';
|
2
2
|
|
3
3
|
class EventEncoderError extends TypeError {
|
4
4
|
}
|
@@ -223,5 +223,27 @@ function flattenHeader(header) {
|
|
223
223
|
}
|
224
224
|
return header.join(", ");
|
225
225
|
}
|
226
|
+
function replicateStandardLazyResponse(response, count) {
|
227
|
+
const replicated = [];
|
228
|
+
let bodyPromise;
|
229
|
+
let replicatedAsyncIteratorObjects;
|
230
|
+
for (let i = 0; i < count; i++) {
|
231
|
+
replicated.push({
|
232
|
+
...response,
|
233
|
+
body: once(async () => {
|
234
|
+
if (replicatedAsyncIteratorObjects) {
|
235
|
+
return replicatedAsyncIteratorObjects.shift();
|
236
|
+
}
|
237
|
+
const body = await (bodyPromise ??= response.body());
|
238
|
+
if (!isAsyncIteratorObject(body)) {
|
239
|
+
return body;
|
240
|
+
}
|
241
|
+
replicatedAsyncIteratorObjects = replicateAsyncIterator(body, count);
|
242
|
+
return replicatedAsyncIteratorObjects.shift();
|
243
|
+
})
|
244
|
+
});
|
245
|
+
}
|
246
|
+
return replicated;
|
247
|
+
}
|
226
248
|
|
227
|
-
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
249
|
+
export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, flattenHeader, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, replicateStandardLazyResponse, withEventMeta };
|
@@ -35,4 +35,4 @@ interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
|
35
35
|
body: () => Promise<StandardBody>;
|
36
36
|
}
|
37
37
|
|
38
|
-
export type { StandardHeaders as S,
|
38
|
+
export type { StandardHeaders as S, StandardLazyResponse as a, StandardBody as b, StandardRequest as c, StandardLazyRequest as d, StandardResponse as e };
|
@@ -35,4 +35,4 @@ interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
|
35
35
|
body: () => Promise<StandardBody>;
|
36
36
|
}
|
37
37
|
|
38
|
-
export type { StandardHeaders as S,
|
38
|
+
export type { StandardHeaders as S, StandardLazyResponse as a, StandardBody as b, StandardRequest as c, StandardLazyRequest as d, StandardResponse as e };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/standard-server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.4.0",
|
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.
|
31
|
+
"@orpc/shared": "1.4.0"
|
32
32
|
},
|
33
33
|
"scripts": {
|
34
34
|
"build": "unbuild",
|