🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@standardserver/peer

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@standardserver/peer - npm Package Compare versions

Comparing version
0.4.2
to
0.5.0
+40
-4
dist/index.d.mts

@@ -1,2 +0,2 @@

import { StandardRequest, EventMeta, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core';
import { StandardMethod, StandardUrl, StandardHeaders, StandardBody, EventMeta, StandardRequest, StandardLazyResponse, StandardLazyRequest, StandardResponse } from '@standardserver/core';
import { Queue, AsyncCleanupFn, AsyncIteratorClass } from '@standardserver/shared';

@@ -40,3 +40,22 @@

*/
json: Omit<StandardRequest, 'signal'>;
json: {
/**
* @example 'GET', 'POST', etc.
* @default 'POST'
*/
method?: undefined | StandardMethod;
/**
* @example `/example`, `/example?query=param#fragment`
*/
url: StandardUrl;
/**
* @example { 'content-type': 'application/json' }
* @default {}
*/
headers?: undefined | StandardHeaders;
/**
* The JSON-parsed body of the request.
*/
body?: undefined | StandardBody;
};
}

@@ -56,3 +75,18 @@ /**

*/
json: StandardResponse;
json: {
/**
* @example 200, 404, 500, etc.
* @default 200
*/
status?: undefined | number;
/**
* @example { 'set-cookie': ['sessionId=abc123; HttpOnly'] }
* @default {}
*/
headers?: undefined | StandardHeaders;
/**
* The JSON-parsed body of the response.
*/
body?: undefined | StandardBody;
};
}

@@ -96,4 +130,6 @@ /**

* Kind of event
*
* @default 'message'
*/
event: 'message' | 'error' | 'close';
event?: undefined | 'message' | 'error' | 'close';
/**

@@ -100,0 +136,0 @@ * Event data.

@@ -1,2 +0,2 @@

import { StandardRequest, EventMeta, StandardResponse, StandardLazyResponse, StandardLazyRequest } from '@standardserver/core';
import { StandardMethod, StandardUrl, StandardHeaders, StandardBody, EventMeta, StandardRequest, StandardLazyResponse, StandardLazyRequest, StandardResponse } from '@standardserver/core';
import { Queue, AsyncCleanupFn, AsyncIteratorClass } from '@standardserver/shared';

@@ -40,3 +40,22 @@

*/
json: Omit<StandardRequest, 'signal'>;
json: {
/**
* @example 'GET', 'POST', etc.
* @default 'POST'
*/
method?: undefined | StandardMethod;
/**
* @example `/example`, `/example?query=param#fragment`
*/
url: StandardUrl;
/**
* @example { 'content-type': 'application/json' }
* @default {}
*/
headers?: undefined | StandardHeaders;
/**
* The JSON-parsed body of the request.
*/
body?: undefined | StandardBody;
};
}

@@ -56,3 +75,18 @@ /**

*/
json: StandardResponse;
json: {
/**
* @example 200, 404, 500, etc.
* @default 200
*/
status?: undefined | number;
/**
* @example { 'set-cookie': ['sessionId=abc123; HttpOnly'] }
* @default {}
*/
headers?: undefined | StandardHeaders;
/**
* The JSON-parsed body of the response.
*/
body?: undefined | StandardBody;
};
}

@@ -96,4 +130,6 @@ /**

* Kind of event
*
* @default 'message'
*/
event: 'message' | 'error' | 'close';
event?: undefined | 'message' | 'error' | 'close';
/**

@@ -100,0 +136,0 @@ * Event data.

+42
-17
import { AsyncIteratorClass, isTypescriptObject, isAsyncIteratorObject, Queue, SequentialIdGenerator, AbortError, stringifyJSON } from '@standardserver/shared';
import { withEventMeta, ErrorEvent, unwrapEvent, generateContentDisposition, flattenStandardHeader, getFilenameFromContentDisposition, isStandardRequest, isStandardResponse } from '@standardserver/core';
import { withEventMeta, ErrorEvent, unwrapEvent, generateContentDisposition, flattenStandardHeader, getFilenameFromContentDisposition, isStandardMethod, isStandardHeaders, isStandardUrl, isStandardStatus } from '@standardserver/core';

@@ -9,2 +9,3 @@ function toAsyncIteratorObject(queue, cleanup) {

switch (json.event) {
case void 0:
case "message": {

@@ -62,3 +63,3 @@ let data = json.data;

id: this.messageId,
json: { ...meta, event: item.done ? "close" : "message", data }
json: { ...meta, event: item.done ? "close" : void 0, data }
});

@@ -161,4 +162,4 @@ } catch (error) {

function toStandardBody(message, cleanup) {
const contentType = flattenStandardHeader(message.json.headers["content-type"]);
const bodyHint = flattenStandardHeader(message.json.headers["standard-server"]);
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) {

@@ -195,6 +196,6 @@ if (contentType === void 0 && bodyHint === "event-stream") {

}
const contentDisposition = flattenStandardHeader(message.json.headers["content-disposition"]);
const contentDisposition = flattenStandardHeader(message.json.headers?.["content-disposition"]);
const filename = contentDisposition !== void 0 ? getFilenameFromContentDisposition(contentDisposition) : void 0;
const file = new File(message.binary ? [message.binary] : [], filename ?? "blob", {
type: flattenStandardHeader(message.json.headers["content-type"]) ?? "application/octet-stream"
type: flattenStandardHeader(message.json.headers?.["content-type"]) ?? "application/octet-stream"
});

@@ -284,5 +285,5 @@ return file;

json: {
method: request.method,
method: request.method === "POST" ? void 0 : request.method,
url: request.url,
headers: encodedAtomicBody.headers,
headers: Object.entries(encodedAtomicBody.headers).every(([, v]) => v === void 0) ? void 0 : encodedAtomicBody.headers,
body: encodedAtomicBody.jsonBody

@@ -366,4 +367,4 @@ },

resolve({
headers: message.json.headers,
status: message.json.status,
headers: message.json.headers ?? {},
status: message.json.status ?? 200,
resolveBody: decoded.resolveBody

@@ -451,6 +452,30 @@ });

function isPeerRequestMessage(maybe) {
return maybe.kind === "request" && isStandardRequest(maybe.json);
if (maybe.kind !== "request") {
return false;
}
if (!isTypescriptObject(maybe.json)) {
return false;
}
if (maybe.json.method !== void 0 && !isStandardMethod(maybe.json.method)) {
return false;
}
if (maybe.json.headers !== void 0 && !isStandardHeaders(maybe.json.headers)) {
return false;
}
return isStandardUrl(maybe.json.url);
}
function isPeerResponseMessage(maybe) {
return maybe.kind === "response" && isStandardResponse(maybe.json);
if (maybe.kind !== "response") {
return false;
}
if (!isTypescriptObject(maybe.json)) {
return false;
}
if (maybe.json.status !== void 0 && !isStandardStatus(maybe.json.status)) {
return false;
}
if (maybe.json.headers !== void 0 && !isStandardHeaders(maybe.json.headers)) {
return false;
}
return true;
}

@@ -470,3 +495,3 @@ function isPeerCancelMessage(maybe) {

}
if (maybe.json.event !== "message" && maybe.json.event !== "error" && maybe.json.event !== "close") {
if (maybe.json.event !== void 0 && maybe.json.event !== "message" && maybe.json.event !== "error" && maybe.json.event !== "close") {
return false;

@@ -619,4 +644,4 @@ }

url: message.json.url,
method: message.json.method,
headers: message.json.headers,
method: message.json.method ?? "POST",
headers: message.json.headers ?? {},
resolveBody: decoded.resolveBody,

@@ -636,4 +661,4 @@ signal

json: {
status: response.status,
headers: encodedAtomicBody.headers,
status: response.status === 200 ? void 0 : response.status,
headers: Object.entries(encodedAtomicBody.headers).every(([, v]) => v === void 0) ? void 0 : encodedAtomicBody.headers,
body: encodedAtomicBody.jsonBody

@@ -640,0 +665,0 @@ },

{
"name": "@standardserver/peer",
"type": "module",
"version": "0.4.2",
"version": "0.5.0",
"license": "MIT",

@@ -25,4 +25,4 @@ "homepage": "https://standardserver.dev",

"dependencies": {
"@standardserver/shared": "0.4.2",
"@standardserver/core": "0.4.2"
"@standardserver/core": "0.5.0",
"@standardserver/shared": "0.5.0"
},

@@ -29,0 +29,0 @@ "scripts": {