@temporary-name/standard-server-fetch 1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.mjs +296 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stainless
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@temporary-name/standard-server';
|
|
2
|
+
import { SetSpanErrorOptions, AsyncIteratorClass } from '@temporary-name/shared';
|
|
3
|
+
|
|
4
|
+
interface ToEventIteratorOptions extends SetSpanErrorOptions {
|
|
5
|
+
}
|
|
6
|
+
declare function toEventIterator(stream: ReadableStream | null, options?: ToEventIteratorOptions): AsyncIteratorClass<unknown>;
|
|
7
|
+
interface ToEventStreamOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
16
|
+
*
|
|
17
|
+
* @default 5000
|
|
18
|
+
*/
|
|
19
|
+
eventIteratorKeepAliveInterval?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The content of the ping comment. Must not include newline characters.
|
|
22
|
+
*
|
|
23
|
+
* @default ''
|
|
24
|
+
*/
|
|
25
|
+
eventIteratorKeepAliveComment?: string;
|
|
26
|
+
}
|
|
27
|
+
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
28
|
+
|
|
29
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
30
|
+
}
|
|
31
|
+
declare function toStandardBody(re: Request | Response, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
32
|
+
interface ToFetchBodyOptions extends ToEventStreamOptions {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @param body
|
|
36
|
+
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
37
|
+
*/
|
|
38
|
+
declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param standardHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
43
|
+
*/
|
|
44
|
+
declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardHeaders): StandardHeaders;
|
|
45
|
+
/**
|
|
46
|
+
* @param headers
|
|
47
|
+
* @param fetchHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
48
|
+
*/
|
|
49
|
+
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
50
|
+
|
|
51
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
52
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
53
|
+
}
|
|
54
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
55
|
+
|
|
56
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
57
|
+
}
|
|
58
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
59
|
+
interface ToStandardLazyResponseOptions extends ToStandardBodyOptions {
|
|
60
|
+
}
|
|
61
|
+
declare function toStandardLazyResponse(response: Response, options?: ToStandardLazyResponseOptions): StandardLazyResponse;
|
|
62
|
+
|
|
63
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
64
|
+
export type { ToEventIteratorOptions, ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions, ToStandardBodyOptions, ToStandardLazyResponseOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@temporary-name/standard-server';
|
|
2
|
+
import { SetSpanErrorOptions, AsyncIteratorClass } from '@temporary-name/shared';
|
|
3
|
+
|
|
4
|
+
interface ToEventIteratorOptions extends SetSpanErrorOptions {
|
|
5
|
+
}
|
|
6
|
+
declare function toEventIterator(stream: ReadableStream | null, options?: ToEventIteratorOptions): AsyncIteratorClass<unknown>;
|
|
7
|
+
interface ToEventStreamOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
16
|
+
*
|
|
17
|
+
* @default 5000
|
|
18
|
+
*/
|
|
19
|
+
eventIteratorKeepAliveInterval?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The content of the ping comment. Must not include newline characters.
|
|
22
|
+
*
|
|
23
|
+
* @default ''
|
|
24
|
+
*/
|
|
25
|
+
eventIteratorKeepAliveComment?: string;
|
|
26
|
+
}
|
|
27
|
+
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
28
|
+
|
|
29
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
30
|
+
}
|
|
31
|
+
declare function toStandardBody(re: Request | Response, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
32
|
+
interface ToFetchBodyOptions extends ToEventStreamOptions {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @param body
|
|
36
|
+
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
37
|
+
*/
|
|
38
|
+
declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param standardHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
43
|
+
*/
|
|
44
|
+
declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardHeaders): StandardHeaders;
|
|
45
|
+
/**
|
|
46
|
+
* @param headers
|
|
47
|
+
* @param fetchHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
48
|
+
*/
|
|
49
|
+
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
50
|
+
|
|
51
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
52
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
53
|
+
}
|
|
54
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
55
|
+
|
|
56
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
57
|
+
}
|
|
58
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
59
|
+
interface ToStandardLazyResponseOptions extends ToStandardBodyOptions {
|
|
60
|
+
}
|
|
61
|
+
declare function toStandardLazyResponse(response: Response, options?: ToStandardLazyResponseOptions): StandardLazyResponse;
|
|
62
|
+
|
|
63
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
64
|
+
export type { ToEventIteratorOptions, ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions, ToStandardBodyOptions, ToStandardLazyResponseOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { AsyncIteratorClass, startSpan, runInSpanContext, AbortError, parseEmptyableJSON, isTypescriptObject, setSpanError, stringifyJSON, runWithSpan, isAsyncIteratorObject, once } from '@temporary-name/shared';
|
|
2
|
+
import { EventDecoderStream, withEventMeta, ErrorEvent, encodeEventMessage, getEventMeta, getFilenameFromContentDisposition, generateContentDisposition } from '@temporary-name/standard-server';
|
|
3
|
+
|
|
4
|
+
function toEventIterator(stream, options = {}) {
|
|
5
|
+
const eventStream = stream?.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
6
|
+
const reader = eventStream?.getReader();
|
|
7
|
+
let span;
|
|
8
|
+
let isCancelled = false;
|
|
9
|
+
return new AsyncIteratorClass(
|
|
10
|
+
async () => {
|
|
11
|
+
span ??= startSpan("consume_event_iterator_stream");
|
|
12
|
+
try {
|
|
13
|
+
while (true) {
|
|
14
|
+
if (reader === void 0) {
|
|
15
|
+
return { done: true, value: void 0 };
|
|
16
|
+
}
|
|
17
|
+
const { done, value } = await runInSpanContext(span, () => reader.read());
|
|
18
|
+
if (done) {
|
|
19
|
+
if (isCancelled) {
|
|
20
|
+
throw new AbortError("Stream was cancelled");
|
|
21
|
+
}
|
|
22
|
+
return { done: true, value: void 0 };
|
|
23
|
+
}
|
|
24
|
+
switch (value.event) {
|
|
25
|
+
case "message": {
|
|
26
|
+
let message = parseEmptyableJSON(value.data);
|
|
27
|
+
if (isTypescriptObject(message)) {
|
|
28
|
+
message = withEventMeta(message, value);
|
|
29
|
+
}
|
|
30
|
+
span?.addEvent("message");
|
|
31
|
+
return { done: false, value: message };
|
|
32
|
+
}
|
|
33
|
+
case "error": {
|
|
34
|
+
let error = new ErrorEvent({
|
|
35
|
+
data: parseEmptyableJSON(value.data)
|
|
36
|
+
});
|
|
37
|
+
error = withEventMeta(error, value);
|
|
38
|
+
span?.addEvent("error");
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
case "done": {
|
|
42
|
+
let done2 = parseEmptyableJSON(value.data);
|
|
43
|
+
if (isTypescriptObject(done2)) {
|
|
44
|
+
done2 = withEventMeta(done2, value);
|
|
45
|
+
}
|
|
46
|
+
span?.addEvent("done");
|
|
47
|
+
return { done: true, value: done2 };
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
span?.addEvent("maybe_keepalive");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
if (!(e instanceof ErrorEvent)) {
|
|
56
|
+
setSpanError(span, e, options);
|
|
57
|
+
}
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
async (reason) => {
|
|
62
|
+
try {
|
|
63
|
+
if (reason !== "next") {
|
|
64
|
+
isCancelled = true;
|
|
65
|
+
span?.addEvent("cancelled");
|
|
66
|
+
}
|
|
67
|
+
await runInSpanContext(span, () => reader?.cancel());
|
|
68
|
+
} catch (e) {
|
|
69
|
+
setSpanError(span, e, options);
|
|
70
|
+
throw e;
|
|
71
|
+
} finally {
|
|
72
|
+
span?.end();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function toEventStream(iterator, options = {}) {
|
|
78
|
+
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
79
|
+
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
80
|
+
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
81
|
+
let cancelled = false;
|
|
82
|
+
let timeout;
|
|
83
|
+
let span;
|
|
84
|
+
const stream = new ReadableStream({
|
|
85
|
+
start() {
|
|
86
|
+
span = startSpan("stream_event_iterator");
|
|
87
|
+
},
|
|
88
|
+
async pull(controller) {
|
|
89
|
+
try {
|
|
90
|
+
if (keepAliveEnabled) {
|
|
91
|
+
timeout = setInterval(() => {
|
|
92
|
+
controller.enqueue(
|
|
93
|
+
encodeEventMessage({
|
|
94
|
+
comments: [keepAliveComment]
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
span?.addEvent("keepalive");
|
|
98
|
+
}, keepAliveInterval);
|
|
99
|
+
}
|
|
100
|
+
const value = await runInSpanContext(span, () => iterator.next());
|
|
101
|
+
clearInterval(timeout);
|
|
102
|
+
if (cancelled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const meta = getEventMeta(value.value);
|
|
106
|
+
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
107
|
+
const event = value.done ? "done" : "message";
|
|
108
|
+
controller.enqueue(
|
|
109
|
+
encodeEventMessage({
|
|
110
|
+
...meta,
|
|
111
|
+
event,
|
|
112
|
+
data: stringifyJSON(value.value)
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
span?.addEvent(event);
|
|
116
|
+
}
|
|
117
|
+
if (value.done) {
|
|
118
|
+
controller.close();
|
|
119
|
+
span?.end();
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
clearInterval(timeout);
|
|
123
|
+
if (cancelled) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (err instanceof ErrorEvent) {
|
|
127
|
+
controller.enqueue(
|
|
128
|
+
encodeEventMessage({
|
|
129
|
+
...getEventMeta(err),
|
|
130
|
+
event: "error",
|
|
131
|
+
data: stringifyJSON(err.data)
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
span?.addEvent("error");
|
|
135
|
+
controller.close();
|
|
136
|
+
} else {
|
|
137
|
+
setSpanError(span, err);
|
|
138
|
+
controller.error(err);
|
|
139
|
+
}
|
|
140
|
+
span?.end();
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
async cancel() {
|
|
144
|
+
try {
|
|
145
|
+
cancelled = true;
|
|
146
|
+
clearInterval(timeout);
|
|
147
|
+
span?.addEvent("cancelled");
|
|
148
|
+
await runInSpanContext(span, () => iterator.return?.());
|
|
149
|
+
} catch (e) {
|
|
150
|
+
setSpanError(span, e);
|
|
151
|
+
throw e;
|
|
152
|
+
} finally {
|
|
153
|
+
span?.end();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}).pipeThrough(new TextEncoderStream());
|
|
157
|
+
return stream;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function toStandardBody(re, options = {}) {
|
|
161
|
+
return runWithSpan({ name: "parse_standard_body", signal: options.signal }, async () => {
|
|
162
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
163
|
+
if (typeof contentDisposition === "string") {
|
|
164
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
165
|
+
const blob2 = await re.blob();
|
|
166
|
+
return new File([blob2], fileName, {
|
|
167
|
+
type: blob2.type
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const contentType = re.headers.get("content-type");
|
|
171
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
|
172
|
+
const text = await re.text();
|
|
173
|
+
return parseEmptyableJSON(text);
|
|
174
|
+
}
|
|
175
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
176
|
+
return await re.formData();
|
|
177
|
+
}
|
|
178
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
179
|
+
const text = await re.text();
|
|
180
|
+
return new URLSearchParams(text);
|
|
181
|
+
}
|
|
182
|
+
if (contentType.startsWith("text/event-stream")) {
|
|
183
|
+
return toEventIterator(re.body, options);
|
|
184
|
+
}
|
|
185
|
+
if (contentType.startsWith("text/plain")) {
|
|
186
|
+
return await re.text();
|
|
187
|
+
}
|
|
188
|
+
const blob = await re.blob();
|
|
189
|
+
return new File([blob], "blob", {
|
|
190
|
+
type: blob.type
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function toFetchBody(body, headers, options = {}) {
|
|
195
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
196
|
+
headers.delete("content-type");
|
|
197
|
+
headers.delete("content-disposition");
|
|
198
|
+
if (body === void 0) {
|
|
199
|
+
return void 0;
|
|
200
|
+
}
|
|
201
|
+
if (body instanceof Blob) {
|
|
202
|
+
headers.set("content-type", body.type);
|
|
203
|
+
headers.set("content-length", body.size.toString());
|
|
204
|
+
headers.set(
|
|
205
|
+
"content-disposition",
|
|
206
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
207
|
+
);
|
|
208
|
+
return body;
|
|
209
|
+
}
|
|
210
|
+
if (body instanceof FormData) {
|
|
211
|
+
return body;
|
|
212
|
+
}
|
|
213
|
+
if (body instanceof URLSearchParams) {
|
|
214
|
+
return body;
|
|
215
|
+
}
|
|
216
|
+
if (isAsyncIteratorObject(body)) {
|
|
217
|
+
headers.set("content-type", "text/event-stream");
|
|
218
|
+
return toEventStream(body, options);
|
|
219
|
+
}
|
|
220
|
+
headers.set("content-type", "application/json");
|
|
221
|
+
return stringifyJSON(body);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function toStandardHeaders(headers, standardHeaders = {}) {
|
|
225
|
+
headers.forEach((value, key) => {
|
|
226
|
+
if (Array.isArray(standardHeaders[key])) {
|
|
227
|
+
standardHeaders[key].push(value);
|
|
228
|
+
} else if (standardHeaders[key] !== void 0) {
|
|
229
|
+
standardHeaders[key] = [standardHeaders[key], value];
|
|
230
|
+
} else {
|
|
231
|
+
standardHeaders[key] = value;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
return standardHeaders;
|
|
235
|
+
}
|
|
236
|
+
function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
237
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
238
|
+
if (Array.isArray(value)) {
|
|
239
|
+
for (const v of value) {
|
|
240
|
+
fetchHeaders.append(key, v);
|
|
241
|
+
}
|
|
242
|
+
} else if (value !== void 0) {
|
|
243
|
+
fetchHeaders.append(key, value);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return fetchHeaders;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function toStandardLazyRequest(request) {
|
|
250
|
+
return {
|
|
251
|
+
url: new URL(request.url),
|
|
252
|
+
signal: request.signal,
|
|
253
|
+
method: request.method,
|
|
254
|
+
body: once(() => toStandardBody(request, { signal: request.signal })),
|
|
255
|
+
get headers() {
|
|
256
|
+
const headers = toStandardHeaders(request.headers);
|
|
257
|
+
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
258
|
+
return headers;
|
|
259
|
+
},
|
|
260
|
+
set headers(value) {
|
|
261
|
+
Object.defineProperty(this, "headers", { value, writable: true });
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function toFetchRequest(request, options = {}) {
|
|
266
|
+
const headers = toFetchHeaders(request.headers);
|
|
267
|
+
const body = toFetchBody(request.body, headers, options);
|
|
268
|
+
return new Request(request.url, {
|
|
269
|
+
signal: request.signal,
|
|
270
|
+
method: request.method,
|
|
271
|
+
headers,
|
|
272
|
+
body
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function toFetchResponse(response, options = {}) {
|
|
277
|
+
const headers = toFetchHeaders(response.headers);
|
|
278
|
+
const body = toFetchBody(response.body, headers, options);
|
|
279
|
+
return new Response(body, { headers, status: response.status });
|
|
280
|
+
}
|
|
281
|
+
function toStandardLazyResponse(response, options = {}) {
|
|
282
|
+
return {
|
|
283
|
+
body: once(() => toStandardBody(response, options)),
|
|
284
|
+
status: response.status,
|
|
285
|
+
get headers() {
|
|
286
|
+
const headers = toStandardHeaders(response.headers);
|
|
287
|
+
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
288
|
+
return headers;
|
|
289
|
+
},
|
|
290
|
+
set headers(value) {
|
|
291
|
+
Object.defineProperty(this, "headers", { value, writable: true });
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@temporary-name/standard-server-fetch",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://www.stainless.com/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/unnoq/krusty.git",
|
|
10
|
+
"directory": "packages/standard-server-fetch"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"krusty"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@temporary-name/shared": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8",
|
|
27
|
+
"@temporary-name/standard-server": "1.9.3-alpha.0d2fa3247b6b23bbc2e3097a95f631b86740e4d8"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@hono/node-server": "^1.19.5"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "unbuild",
|
|
34
|
+
"build:watch": "pnpm run build --watch",
|
|
35
|
+
"type:check": "tsc -b"
|
|
36
|
+
}
|
|
37
|
+
}
|