@orpc/standard-server 0.0.0-next.f47352c → 0.0.0-next.f538070
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 +23 -0
- package/dist/batch/index.d.ts +23 -0
- package/dist/batch/index.mjs +85 -0
- package/dist/index.d.mts +4 -38
- package/dist/index.d.ts +4 -38
- package/dist/shared/standard-server.R_NaHlxw.d.mts +38 -0
- package/dist/shared/standard-server.R_NaHlxw.d.ts +38 -0
- package/package.json +7 -2
@@ -0,0 +1,23 @@
|
|
1
|
+
import { S as StandardHeaders, b as StandardRequest, d as StandardResponse } from '../shared/standard-server.R_NaHlxw.mjs';
|
2
|
+
|
3
|
+
interface ToBatchRequestOptions {
|
4
|
+
url: URL;
|
5
|
+
method: 'GET' | 'POST';
|
6
|
+
headers: StandardHeaders;
|
7
|
+
requests: readonly StandardRequest[];
|
8
|
+
}
|
9
|
+
declare function toBatchRequest(options: ToBatchRequestOptions): StandardRequest;
|
10
|
+
declare function parseBatchRequest(request: StandardRequest): StandardRequest[];
|
11
|
+
|
12
|
+
interface BatchResponseBodyItem extends StandardResponse {
|
13
|
+
index: number;
|
14
|
+
}
|
15
|
+
interface ToBatchResponseOptions extends StandardResponse {
|
16
|
+
body: AsyncIteratorObject<BatchResponseBodyItem>;
|
17
|
+
}
|
18
|
+
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
|
19
|
+
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
|
+
|
21
|
+
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
|
22
|
+
|
23
|
+
export { type BatchResponseBodyItem, type ToBatchRequestOptions, type ToBatchResponseOptions, parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { S as StandardHeaders, b as StandardRequest, d as StandardResponse } from '../shared/standard-server.R_NaHlxw.js';
|
2
|
+
|
3
|
+
interface ToBatchRequestOptions {
|
4
|
+
url: URL;
|
5
|
+
method: 'GET' | 'POST';
|
6
|
+
headers: StandardHeaders;
|
7
|
+
requests: readonly StandardRequest[];
|
8
|
+
}
|
9
|
+
declare function toBatchRequest(options: ToBatchRequestOptions): StandardRequest;
|
10
|
+
declare function parseBatchRequest(request: StandardRequest): StandardRequest[];
|
11
|
+
|
12
|
+
interface BatchResponseBodyItem extends StandardResponse {
|
13
|
+
index: number;
|
14
|
+
}
|
15
|
+
interface ToBatchResponseOptions extends StandardResponse {
|
16
|
+
body: AsyncIteratorObject<BatchResponseBodyItem>;
|
17
|
+
}
|
18
|
+
declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
|
19
|
+
declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
|
20
|
+
|
21
|
+
declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
|
22
|
+
|
23
|
+
export { type BatchResponseBodyItem, type ToBatchRequestOptions, type ToBatchResponseOptions, parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import { stringifyJSON, parseEmptyableJSON, isAsyncIteratorObject, isObject } from '@orpc/shared';
|
2
|
+
|
3
|
+
function toBatchAbortSignal(signals) {
|
4
|
+
const realSignals = signals.filter((signal) => signal !== void 0);
|
5
|
+
const controller = new AbortController();
|
6
|
+
const abortedSignals = realSignals.filter((signal) => signal.aborted);
|
7
|
+
if (abortedSignals.length && abortedSignals.length === realSignals.length) {
|
8
|
+
controller.abort();
|
9
|
+
}
|
10
|
+
for (const signal of realSignals) {
|
11
|
+
signal.addEventListener("abort", () => {
|
12
|
+
abortedSignals.push(signal);
|
13
|
+
if (abortedSignals.length === realSignals.length) {
|
14
|
+
controller.abort();
|
15
|
+
}
|
16
|
+
});
|
17
|
+
}
|
18
|
+
return controller.signal;
|
19
|
+
}
|
20
|
+
|
21
|
+
function toBatchRequest(options) {
|
22
|
+
const url = new URL(options.url);
|
23
|
+
let body;
|
24
|
+
const batchRequestItems = options.requests.map((request) => ({
|
25
|
+
body: request.body,
|
26
|
+
headers: request.headers,
|
27
|
+
method: request.method,
|
28
|
+
url: request.url
|
29
|
+
}));
|
30
|
+
if (options.method === "GET") {
|
31
|
+
url.searchParams.append("batch", stringifyJSON(batchRequestItems));
|
32
|
+
} else if (options.method === "POST") {
|
33
|
+
body = batchRequestItems;
|
34
|
+
}
|
35
|
+
return {
|
36
|
+
method: options.method,
|
37
|
+
url,
|
38
|
+
headers: options.headers,
|
39
|
+
body,
|
40
|
+
signal: toBatchAbortSignal(options.requests.map((request) => request.signal))
|
41
|
+
};
|
42
|
+
}
|
43
|
+
function parseBatchRequest(request) {
|
44
|
+
const items = request.method === "GET" ? parseEmptyableJSON(request.url.searchParams.getAll("batch").at(-1)) : request.body;
|
45
|
+
if (!Array.isArray(items)) {
|
46
|
+
throw new TypeError("Invalid batch request");
|
47
|
+
}
|
48
|
+
return items.map((item) => {
|
49
|
+
return {
|
50
|
+
method: item.method,
|
51
|
+
url: new URL(item.url),
|
52
|
+
headers: item.headers,
|
53
|
+
body: item.body,
|
54
|
+
signal: request.signal
|
55
|
+
};
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function toBatchResponse(options) {
|
60
|
+
return options;
|
61
|
+
}
|
62
|
+
function parseBatchResponse(response) {
|
63
|
+
const body = response.body;
|
64
|
+
if (!isAsyncIteratorObject(body)) {
|
65
|
+
throw new TypeError("Invalid batch response", {
|
66
|
+
cause: response
|
67
|
+
});
|
68
|
+
}
|
69
|
+
return async function* () {
|
70
|
+
try {
|
71
|
+
for await (const item of body) {
|
72
|
+
if (!isObject(item) || !("index" in item) || !("status" in item) || !("headers" in item)) {
|
73
|
+
throw new TypeError("Invalid batch response", {
|
74
|
+
cause: item
|
75
|
+
});
|
76
|
+
}
|
77
|
+
yield item;
|
78
|
+
}
|
79
|
+
} finally {
|
80
|
+
await body.return?.();
|
81
|
+
}
|
82
|
+
}();
|
83
|
+
}
|
84
|
+
|
85
|
+
export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
|
package/dist/index.d.mts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
import { S as StandardHeaders } from './shared/standard-server.R_NaHlxw.mjs';
|
2
|
+
export { a as StandardBody, c as StandardLazyRequest, e as StandardLazyResponse, b as StandardRequest, d as StandardResponse } from './shared/standard-server.R_NaHlxw.mjs';
|
3
|
+
|
1
4
|
interface EventMessage {
|
2
5
|
event: string | undefined;
|
3
6
|
id: string | undefined;
|
@@ -49,45 +52,8 @@ type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id' | 'comments'>>;
|
|
49
52
|
declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
|
50
53
|
declare function getEventMeta(container: unknown): EventMeta | undefined;
|
51
54
|
|
52
|
-
interface StandardHeaders {
|
53
|
-
[key: string]: string | string[] | undefined;
|
54
|
-
}
|
55
|
-
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
56
|
-
interface StandardRequest {
|
57
|
-
method: string;
|
58
|
-
url: URL;
|
59
|
-
headers: StandardHeaders;
|
60
|
-
/**
|
61
|
-
* The body has been parsed based on the content-type header.
|
62
|
-
*/
|
63
|
-
body: StandardBody;
|
64
|
-
signal: AbortSignal | undefined;
|
65
|
-
}
|
66
|
-
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
67
|
-
/**
|
68
|
-
* The body has been parsed based on the content-type header.
|
69
|
-
* This method can safely call multiple times (cached).
|
70
|
-
*/
|
71
|
-
body: () => Promise<StandardBody>;
|
72
|
-
}
|
73
|
-
interface StandardResponse {
|
74
|
-
status: number;
|
75
|
-
headers: StandardHeaders;
|
76
|
-
/**
|
77
|
-
* The body has been parsed based on the content-type header.
|
78
|
-
*/
|
79
|
-
body: StandardBody;
|
80
|
-
}
|
81
|
-
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
82
|
-
/**
|
83
|
-
* The body has been parsed based on the content-type header.
|
84
|
-
* This method can safely call multiple times (cached).
|
85
|
-
*/
|
86
|
-
body: () => Promise<StandardBody>;
|
87
|
-
}
|
88
|
-
|
89
55
|
declare function generateContentDisposition(filename: string): string;
|
90
56
|
declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
|
91
57
|
declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
|
92
58
|
|
93
|
-
export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta,
|
59
|
+
export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
import { S as StandardHeaders } from './shared/standard-server.R_NaHlxw.js';
|
2
|
+
export { a as StandardBody, c as StandardLazyRequest, e as StandardLazyResponse, b as StandardRequest, d as StandardResponse } from './shared/standard-server.R_NaHlxw.js';
|
3
|
+
|
1
4
|
interface EventMessage {
|
2
5
|
event: string | undefined;
|
3
6
|
id: string | undefined;
|
@@ -49,45 +52,8 @@ type EventMeta = Partial<Pick<EventMessage, 'retry' | 'id' | 'comments'>>;
|
|
49
52
|
declare function withEventMeta<T extends object>(container: T, meta: EventMeta): T;
|
50
53
|
declare function getEventMeta(container: unknown): EventMeta | undefined;
|
51
54
|
|
52
|
-
interface StandardHeaders {
|
53
|
-
[key: string]: string | string[] | undefined;
|
54
|
-
}
|
55
|
-
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
56
|
-
interface StandardRequest {
|
57
|
-
method: string;
|
58
|
-
url: URL;
|
59
|
-
headers: StandardHeaders;
|
60
|
-
/**
|
61
|
-
* The body has been parsed based on the content-type header.
|
62
|
-
*/
|
63
|
-
body: StandardBody;
|
64
|
-
signal: AbortSignal | undefined;
|
65
|
-
}
|
66
|
-
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
67
|
-
/**
|
68
|
-
* The body has been parsed based on the content-type header.
|
69
|
-
* This method can safely call multiple times (cached).
|
70
|
-
*/
|
71
|
-
body: () => Promise<StandardBody>;
|
72
|
-
}
|
73
|
-
interface StandardResponse {
|
74
|
-
status: number;
|
75
|
-
headers: StandardHeaders;
|
76
|
-
/**
|
77
|
-
* The body has been parsed based on the content-type header.
|
78
|
-
*/
|
79
|
-
body: StandardBody;
|
80
|
-
}
|
81
|
-
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
82
|
-
/**
|
83
|
-
* The body has been parsed based on the content-type header.
|
84
|
-
* This method can safely call multiple times (cached).
|
85
|
-
*/
|
86
|
-
body: () => Promise<StandardBody>;
|
87
|
-
}
|
88
|
-
|
89
55
|
declare function generateContentDisposition(filename: string): string;
|
90
56
|
declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
|
91
57
|
declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
|
92
58
|
|
93
|
-
export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta,
|
59
|
+
export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
|
@@ -0,0 +1,38 @@
|
|
1
|
+
interface StandardHeaders {
|
2
|
+
[key: string]: string | string[] | undefined;
|
3
|
+
}
|
4
|
+
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
5
|
+
interface StandardRequest {
|
6
|
+
method: string;
|
7
|
+
url: URL;
|
8
|
+
headers: StandardHeaders;
|
9
|
+
/**
|
10
|
+
* The body has been parsed based on the content-type header.
|
11
|
+
*/
|
12
|
+
body: StandardBody;
|
13
|
+
signal: AbortSignal | undefined;
|
14
|
+
}
|
15
|
+
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
16
|
+
/**
|
17
|
+
* The body has been parsed based on the content-type header.
|
18
|
+
* This method can safely call multiple times (cached).
|
19
|
+
*/
|
20
|
+
body: () => Promise<StandardBody>;
|
21
|
+
}
|
22
|
+
interface StandardResponse {
|
23
|
+
status: number;
|
24
|
+
headers: StandardHeaders;
|
25
|
+
/**
|
26
|
+
* The body has been parsed based on the content-type header.
|
27
|
+
*/
|
28
|
+
body: StandardBody;
|
29
|
+
}
|
30
|
+
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
31
|
+
/**
|
32
|
+
* The body has been parsed based on the content-type header.
|
33
|
+
* This method can safely call multiple times (cached).
|
34
|
+
*/
|
35
|
+
body: () => Promise<StandardBody>;
|
36
|
+
}
|
37
|
+
|
38
|
+
export type { StandardHeaders as S, StandardBody as a, StandardRequest as b, StandardLazyRequest as c, StandardResponse as d, StandardLazyResponse as e };
|
@@ -0,0 +1,38 @@
|
|
1
|
+
interface StandardHeaders {
|
2
|
+
[key: string]: string | string[] | undefined;
|
3
|
+
}
|
4
|
+
type StandardBody = undefined | unknown | Blob | URLSearchParams | FormData | AsyncIterator<unknown | void, unknown | void, undefined>;
|
5
|
+
interface StandardRequest {
|
6
|
+
method: string;
|
7
|
+
url: URL;
|
8
|
+
headers: StandardHeaders;
|
9
|
+
/**
|
10
|
+
* The body has been parsed based on the content-type header.
|
11
|
+
*/
|
12
|
+
body: StandardBody;
|
13
|
+
signal: AbortSignal | undefined;
|
14
|
+
}
|
15
|
+
interface StandardLazyRequest extends Omit<StandardRequest, 'body'> {
|
16
|
+
/**
|
17
|
+
* The body has been parsed based on the content-type header.
|
18
|
+
* This method can safely call multiple times (cached).
|
19
|
+
*/
|
20
|
+
body: () => Promise<StandardBody>;
|
21
|
+
}
|
22
|
+
interface StandardResponse {
|
23
|
+
status: number;
|
24
|
+
headers: StandardHeaders;
|
25
|
+
/**
|
26
|
+
* The body has been parsed based on the content-type header.
|
27
|
+
*/
|
28
|
+
body: StandardBody;
|
29
|
+
}
|
30
|
+
interface StandardLazyResponse extends Omit<StandardResponse, 'body'> {
|
31
|
+
/**
|
32
|
+
* The body has been parsed based on the content-type header.
|
33
|
+
* This method can safely call multiple times (cached).
|
34
|
+
*/
|
35
|
+
body: () => Promise<StandardBody>;
|
36
|
+
}
|
37
|
+
|
38
|
+
export type { StandardHeaders as S, StandardBody as a, StandardRequest as b, StandardLazyRequest as c, StandardResponse as d, StandardLazyResponse as e };
|
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.f538070",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://unnoq.com",
|
7
7
|
"repository": {
|
@@ -17,13 +17,18 @@
|
|
17
17
|
"types": "./dist/index.d.mts",
|
18
18
|
"import": "./dist/index.mjs",
|
19
19
|
"default": "./dist/index.mjs"
|
20
|
+
},
|
21
|
+
"./batch": {
|
22
|
+
"types": "./dist/batch/index.d.mts",
|
23
|
+
"import": "./dist/batch/index.mjs",
|
24
|
+
"default": "./dist/batch/index.mjs"
|
20
25
|
}
|
21
26
|
},
|
22
27
|
"files": [
|
23
28
|
"dist"
|
24
29
|
],
|
25
30
|
"dependencies": {
|
26
|
-
"@orpc/shared": "0.0.0-next.
|
31
|
+
"@orpc/shared": "0.0.0-next.f538070"
|
27
32
|
},
|
28
33
|
"scripts": {
|
29
34
|
"build": "unbuild",
|