@standardserver/peer
Advanced tools
+3
-7
@@ -1,2 +0,2 @@ | ||
| import { StandardRequest, StandardBodyHint, EventStreamMessage, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core'; | ||
| import { StandardRequest, EventStreamMessage, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core'; | ||
| import { Queue, AsyncCleanupFn, AsyncIteratorClass } from '@standardserver/shared'; | ||
@@ -40,5 +40,3 @@ | ||
| */ | ||
| json: Omit<StandardRequest, 'signal'> & { | ||
| bodyHint: StandardBodyHint; | ||
| }; | ||
| json: Omit<StandardRequest, 'signal'>; | ||
| } | ||
@@ -58,5 +56,3 @@ /** | ||
| */ | ||
| json: StandardResponse & { | ||
| bodyHint: StandardBodyHint; | ||
| }; | ||
| json: StandardResponse; | ||
| } | ||
@@ -63,0 +59,0 @@ /** |
+3
-7
@@ -1,2 +0,2 @@ | ||
| import { StandardRequest, StandardBodyHint, EventStreamMessage, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core'; | ||
| import { StandardRequest, EventStreamMessage, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core'; | ||
| import { Queue, AsyncCleanupFn, AsyncIteratorClass } from '@standardserver/shared'; | ||
@@ -40,5 +40,3 @@ | ||
| */ | ||
| json: Omit<StandardRequest, 'signal'> & { | ||
| bodyHint: StandardBodyHint; | ||
| }; | ||
| json: Omit<StandardRequest, 'signal'>; | ||
| } | ||
@@ -58,5 +56,3 @@ /** | ||
| */ | ||
| json: StandardResponse & { | ||
| bodyHint: StandardBodyHint; | ||
| }; | ||
| json: StandardResponse; | ||
| } | ||
@@ -63,0 +59,0 @@ /** |
+45
-43
@@ -159,36 +159,35 @@ import { AsyncIteratorClass, isTypescriptObject, isAsyncIteratorObject, Queue, SequentialIdGenerator, AbortError, stringifyJSON } from '@standardserver/shared'; | ||
| function toStandardBody(message, cleanup) { | ||
| const bodyHint = message.json.bodyHint; | ||
| if (bodyHint === "event-stream") { | ||
| const eventStreamMessageQueue = new Queue(); | ||
| return { | ||
| resolveBody: async () => toAsyncIteratorObject(eventStreamMessageQueue, cleanup), | ||
| eventStreamMessageQueue | ||
| }; | ||
| const contentType = flattenStandardHeader(message.json.headers["content-type"]); | ||
| const bodyHint = flattenStandardHeader(message.json.headers["standard-server"]); | ||
| if (message.json.body === void 0 && message.binary === void 0) { | ||
| if (contentType === void 0 && bodyHint === "event-stream") { | ||
| const eventStreamMessageQueue = new Queue(); | ||
| return { | ||
| resolveBody: async () => toAsyncIteratorObject(eventStreamMessageQueue, cleanup), | ||
| eventStreamMessageQueue | ||
| }; | ||
| } | ||
| if (contentType !== void 0) { | ||
| const octetStreamMessageQueue = new Queue(); | ||
| return { | ||
| resolveBody: async () => toOctetStream(octetStreamMessageQueue, cleanup), | ||
| octetStreamMessageQueue | ||
| }; | ||
| } | ||
| } | ||
| if (bodyHint === "octet-stream") { | ||
| const octetStreamMessageQueue = new Queue(); | ||
| return { | ||
| resolveBody: async () => toOctetStream(octetStreamMessageQueue, cleanup), | ||
| octetStreamMessageQueue | ||
| }; | ||
| } | ||
| const resolveBody = async () => { | ||
| let errorRef; | ||
| try { | ||
| if (bodyHint === "url-search-params") { | ||
| if (typeof message.json.body !== "string") { | ||
| throw new TypeError("Expected body to be a string for url-search-params bodyHint"); | ||
| if (message.binary) { | ||
| if (bodyHint === "form-data") { | ||
| const headers = {}; | ||
| if (contentType !== void 0) { | ||
| headers["content-type"] = contentType; | ||
| } | ||
| const res = new Response(message.binary, { | ||
| headers | ||
| }); | ||
| const form = await res.formData(); | ||
| return form; | ||
| } | ||
| return new URLSearchParams(message.json.body); | ||
| } | ||
| if (bodyHint === "form-data") { | ||
| const res = new Response(message.binary, { | ||
| headers: { | ||
| "content-type": flattenStandardHeader(message.json.headers["content-type"]) ?? "multipart/form-data" | ||
| } | ||
| }); | ||
| const form = await res.formData(); | ||
| return form; | ||
| } | ||
| if (bodyHint === "file") { | ||
| const contentDisposition = flattenStandardHeader(message.json.headers["content-disposition"]); | ||
@@ -201,6 +200,8 @@ const filename = contentDisposition !== void 0 ? getFilenameFromContentDisposition(contentDisposition) : void 0; | ||
| } | ||
| if (bodyHint === "none") { | ||
| return void 0; | ||
| if (bodyHint === "url-search-params") { | ||
| if (typeof message.json.body !== "string") { | ||
| throw new TypeError("Expected body to be a string for url-search-params bodyHint"); | ||
| } | ||
| return new URLSearchParams(message.json.body); | ||
| } | ||
| const _expect = bodyHint; | ||
| return message.json.body; | ||
@@ -219,3 +220,4 @@ } catch (error) { | ||
| if (body instanceof ReadableStream) { | ||
| return { bodyHint: "octet-stream", jsonBody: void 0, headers, binary: void 0 }; | ||
| headers["content-type"] ??= "application/octet-stream"; | ||
| return { jsonBody: void 0, headers, binary: void 0 }; | ||
| } | ||
@@ -230,6 +232,9 @@ if (body instanceof Blob) { | ||
| } | ||
| return { bodyHint: "file", jsonBody: void 0, headers, binary: body }; | ||
| return { jsonBody: void 0, headers, binary: body }; | ||
| } | ||
| headers["standard-server"] = void 0; | ||
| headers["content-type"] = void 0; | ||
| if (isAsyncIteratorObject(body)) { | ||
| return { bodyHint: "event-stream", jsonBody: void 0, headers, binary: void 0 }; | ||
| headers["standard-server"] = "event-stream"; | ||
| return { jsonBody: void 0, headers, binary: void 0 }; | ||
| } | ||
@@ -239,13 +244,12 @@ if (body instanceof FormData) { | ||
| const blob = await res.blob(); | ||
| headers["standard-server"] = "form-data"; | ||
| headers["content-type"] = res.headers.get("content-type"); | ||
| headers["content-length"] = blob.size.toString(); | ||
| return { bodyHint: "form-data", jsonBody: void 0, headers, binary: blob }; | ||
| return { jsonBody: void 0, headers, binary: blob }; | ||
| } | ||
| if (body instanceof URLSearchParams) { | ||
| return { bodyHint: "url-search-params", jsonBody: body.toString(), headers, binary: void 0 }; | ||
| headers["standard-server"] = "url-search-params"; | ||
| return { jsonBody: body.toString(), headers, binary: void 0 }; | ||
| } | ||
| if (body === void 0) { | ||
| return { bodyHint: "none", jsonBody: void 0, headers, binary: void 0 }; | ||
| } | ||
| return { bodyHint: "json", jsonBody: body, headers, binary: void 0 }; | ||
| return { jsonBody: body, headers, binary: void 0 }; | ||
| } | ||
@@ -284,3 +288,2 @@ | ||
| headers: encodedAtomicBody.headers, | ||
| bodyHint: encodedAtomicBody.bodyHint, | ||
| body: encodedAtomicBody.jsonBody | ||
@@ -632,3 +635,2 @@ }, | ||
| headers: encodedAtomicBody.headers, | ||
| bodyHint: encodedAtomicBody.bodyHint, | ||
| body: encodedAtomicBody.jsonBody | ||
@@ -635,0 +637,0 @@ }, |
+3
-3
| { | ||
| "name": "@standardserver/peer", | ||
| "type": "module", | ||
| "version": "0.2.1", | ||
| "version": "0.3.0", | ||
| "license": "MIT", | ||
@@ -25,4 +25,4 @@ "homepage": "https://standardserver.dev", | ||
| "dependencies": { | ||
| "@standardserver/core": "0.2.1", | ||
| "@standardserver/shared": "0.2.1" | ||
| "@standardserver/core": "0.3.0", | ||
| "@standardserver/shared": "0.3.0" | ||
| }, | ||
@@ -29,0 +29,0 @@ "scripts": { |
+1
-1
@@ -270,5 +270,5 @@ # @standardserver/peer | ||
| <a href="https://github.com/Scrumplex?ref=orpc" target="_blank" rel="noopener" title="Sefa Eyeoglu"><img src="https://avatars.githubusercontent.com/u/11587657?u=ab503582165c0bbff0cca47ce31c9450bb1553c9&v=4" width="32" height="32" alt="Sefa Eyeoglu" /></a> | ||
| <a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="NΛTT"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="32" height="32" alt="NΛTT" /></a> | ||
| <a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="natt"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="32" height="32" alt="natt" /></a> | ||
| <a href="https://github.com/ChromeGG?ref=orpc" target="_blank" rel="noopener" title="Adam Tkaczyk"><img src="https://avatars.githubusercontent.com/u/39050595?u=a58ca6042a6950e94e6e92442db76ef584279bc0&v=4" width="32" height="32" alt="Adam Tkaczyk" /></a> | ||
| <a href="https://github.com/plancraft?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="32" height="32" alt="plancraft" /></a> | ||
| </p> |
71507
-0.17%968
-0.21%+ Added
+ Added
- Removed
- Removed
Updated
Updated