New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@orpc/server-standard-fetch

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orpc/server-standard-fetch - npm Package Compare versions

Comparing version 0.0.0-next.64a419b to 0.0.0-next.7ab2d31

dist/src/event-source.d.ts

113

dist/index.js
// src/body.ts
import { contentDisposition, parseContentDisposition, parseEmptyableJSON } from "@orpc/server-standard";
import { contentDisposition, isAsyncIteratorObject, parseContentDisposition, parseEmptyableJSON as parseEmptyableJSON2 } from "@orpc/server-standard";
// src/event-source.ts
import {
encodeEventSource,
EventSourceDecoderStream,
EventSourceErrorEvent,
EventSourceUnknownErrorEvent,
getEventSourceRetry,
getTrackId,
isProxyable,
parseEmptyableJSON,
setEventSourceMeta
} from "@orpc/server-standard";
function toEventSourceAsyncGenerator(stream) {
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceDecoderStream());
const reader = eventStream.getReader();
async function* gen() {
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
return;
}
switch (value.event) {
case "message": {
let message = parseEmptyableJSON(value.data);
if (isProxyable(message)) {
message = setEventSourceMeta(value, message);
}
yield message;
break;
}
case "error": {
let error = new EventSourceErrorEvent({
data: parseEmptyableJSON(value.data)
});
error = setEventSourceMeta(value, error);
throw error;
}
case "done": {
let done2 = parseEmptyableJSON(value.data);
if (isProxyable(done2)) {
done2 = setEventSourceMeta(value, done2);
}
return done2;
}
default: {
let error = new EventSourceUnknownErrorEvent({
message: `Unknown event: ${value.event}`,
data: parseEmptyableJSON(value.data)
});
error = setEventSourceMeta(value, error);
throw error;
}
}
}
} finally {
await reader.cancel();
}
}
return gen();
}
function toEventSourceReadableStream(iterator) {
const stream = new ReadableStream({
async pull(controller) {
try {
const value = await iterator.next();
controller.enqueue(encodeEventSource({
event: value.done ? "done" : "message",
retry: getEventSourceRetry(value.value),
id: getTrackId(value.value),
data: JSON.stringify(value.value)
}));
if (value.done) {
controller.close();
}
} catch (err) {
controller.enqueue(encodeEventSource({
event: "error",
retry: getEventSourceRetry(err),
id: getTrackId(err),
data: err instanceof EventSourceErrorEvent ? JSON.stringify(err.data) : void 0
}));
controller.close();
}
},
async cancel(reason) {
if (reason) {
await iterator.throw?.(reason);
} else {
await iterator.return?.();
}
}
}).pipeThrough(new TextEncoderStream());
return stream;
}
// src/body.ts
async function toStandardBody(re) {

@@ -20,3 +118,3 @@ if (!re.body) {

const text = await re.text();
return parseEmptyableJSON(text);
return parseEmptyableJSON2(text);
}

@@ -30,2 +128,5 @@ if (contentType.startsWith("multipart/form-data")) {

}
if (contentType.startsWith("text/event-stream")) {
return toEventSourceAsyncGenerator(re.body);
}
if (contentType.startsWith("text/")) {

@@ -60,2 +161,8 @@ return await re.text();

}
if (isAsyncIteratorObject(body)) {
headers.set("content-type", "text/event-stream");
headers.set("cache-control", "no-cache");
headers.set("connection", "keep-alive");
return toEventSourceReadableStream(body);
}
headers.set("content-type", "application/json");

@@ -118,2 +225,4 @@ return JSON.stringify(body);

export {
toEventSourceAsyncGenerator,
toEventSourceReadableStream,
toFetchBody,

@@ -120,0 +229,0 @@ toFetchHeaders,

2

dist/src/body.d.ts

@@ -7,3 +7,3 @@ import type { StandardBody } from '@orpc/server-standard';

*/
export declare function toFetchBody(body: StandardBody, headers: Headers): string | Blob | FormData | URLSearchParams | undefined;
export declare function toFetchBody(body: StandardBody, headers: Headers): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
//# sourceMappingURL=body.d.ts.map
export * from './body';
export * from './event-source';
export * from './headers';

@@ -3,0 +4,0 @@ export * from './request';

{
"name": "@orpc/server-standard-fetch",
"type": "module",
"version": "0.0.0-next.64a419b",
"version": "0.0.0-next.7ab2d31",
"license": "MIT",

@@ -31,4 +31,7 @@ "homepage": "https://unnoq.com",

"dependencies": {
"@orpc/server-standard": "0.0.0-next.64a419b"
"@orpc/server-standard": "0.0.0-next.7ab2d31"
},
"devDependencies": {
"@types/bun": "^1.2.2"
},
"scripts": {

@@ -35,0 +38,0 @@ "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc