@whatwg-node/server
Advanced tools
Comparing version 0.9.55-alpha-20241113131053-631d899170a4be474752b774f7a4881855ee585a to 0.9.55-alpha-20241113152551-99dc2fae1faa31a67535d6376eb19f716c02dca8
104
cjs/utils.js
@@ -448,14 +448,98 @@ "use strict"; | ||
} | ||
return { | ||
waitUntil(promise) { | ||
waitUntilPromises?.push(promise.catch(err => console.error(err))); | ||
}, | ||
}; | ||
originalCtx = {}; | ||
} | ||
return Object.create(originalCtx, { | ||
waitUntil: { | ||
value(promise) { | ||
waitUntilPromises?.push(promise.catch(err => console.error(err))); | ||
}, | ||
const extraPropsByReceiver = new WeakMap(); | ||
const deletedPropsByReceiver = new WeakMap(); | ||
function getExtraProps(receiver) { | ||
let extraProps = extraPropsByReceiver.get(receiver); | ||
if (!extraProps) { | ||
extraProps = {}; | ||
extraPropsByReceiver.set(receiver, extraProps); | ||
} | ||
return extraProps; | ||
} | ||
function getDeletedProps(receiver) { | ||
let deletedProps = deletedPropsByReceiver.get(receiver); | ||
if (!deletedProps) { | ||
deletedProps = new Set(); | ||
deletedPropsByReceiver.set(receiver, deletedProps); | ||
} | ||
return deletedProps; | ||
} | ||
return new Proxy(originalCtx, { | ||
get(originalCtx, prop, receiver) { | ||
if (waitUntilPromises != null && prop === 'waitUntil') { | ||
return function waitUntil(promise) { | ||
waitUntilPromises.push(promise.catch(err => console.error(err))); | ||
}; | ||
} | ||
const extraProps = getExtraProps(receiver); | ||
const extraPropVal = extraProps[prop]; | ||
if (extraPropVal != null) { | ||
if (typeof extraPropVal === 'function') { | ||
return extraPropVal.bind(extraProps); | ||
} | ||
return extraPropVal; | ||
} | ||
const deletedProps = getDeletedProps(receiver); | ||
if (deletedProps.has(prop)) { | ||
return undefined; | ||
} | ||
return originalCtx[prop]; | ||
}, | ||
set(_originalCtx, prop, value, receiver) { | ||
const extraProps = getExtraProps(receiver); | ||
extraProps[prop] = value; | ||
return true; | ||
}, | ||
has(originalCtx, prop) { | ||
if (waitUntilPromises != null && prop === 'waitUntil') { | ||
return true; | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
if (deletedProps.has(prop)) { | ||
return false; | ||
} | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return true; | ||
} | ||
return prop in originalCtx; | ||
}, | ||
defineProperty(originalCtx, prop, descriptor) { | ||
const extraProps = getExtraProps(originalCtx); | ||
return Reflect.defineProperty(extraProps, prop, descriptor); | ||
}, | ||
deleteProperty(originalCtx, prop) { | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return Reflect.deleteProperty(extraProps, prop); | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
deletedProps.add(prop); | ||
return true; | ||
}, | ||
ownKeys(originalCtx) { | ||
const extraProps = getExtraProps(originalCtx); | ||
const extraKeys = Reflect.ownKeys(extraProps); | ||
const originalKeys = Reflect.ownKeys(originalCtx); | ||
const deletedProps = getDeletedProps(originalCtx); | ||
const deletedKeys = Array.from(deletedProps); | ||
const allKeys = new Set(extraKeys.concat(originalKeys.filter(keys => !deletedKeys.includes(keys)))); | ||
if (waitUntilPromises != null) { | ||
allKeys.add('waitUntil'); | ||
} | ||
return Array.from(allKeys); | ||
}, | ||
getOwnPropertyDescriptor(originalCtx, prop) { | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return Reflect.getOwnPropertyDescriptor(extraProps, prop); | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
if (deletedProps.has(prop)) { | ||
return undefined; | ||
} | ||
return Reflect.getOwnPropertyDescriptor(originalCtx, prop); | ||
}, | ||
}); | ||
@@ -462,0 +546,0 @@ } |
@@ -163,6 +163,10 @@ "use strict"; | ||
write(chunk) { | ||
uwsResponse.write(chunk); | ||
uwsResponse.cork(() => { | ||
uwsResponse.write(chunk); | ||
}); | ||
}, | ||
close() { | ||
uwsResponse.end(); | ||
uwsResponse.cork(() => { | ||
uwsResponse.end(); | ||
}); | ||
}, | ||
@@ -201,10 +205,9 @@ }); | ||
} | ||
else if (!fetchResponse.body) { | ||
uwsResponse.end(); | ||
} | ||
}); | ||
if (bufferOfRes) { | ||
if (bufferOfRes || !fetchResponse.body) { | ||
return; | ||
} | ||
if (!fetchResponse.body) { | ||
uwsResponse.end(); | ||
return; | ||
} | ||
signal.addEventListener('abort', () => { | ||
@@ -211,0 +214,0 @@ if (!fetchResponse.body?.locked) { |
104
esm/utils.js
@@ -426,14 +426,98 @@ export function isAsyncIterable(body) { | ||
} | ||
return { | ||
waitUntil(promise) { | ||
waitUntilPromises?.push(promise.catch(err => console.error(err))); | ||
}, | ||
}; | ||
originalCtx = {}; | ||
} | ||
return Object.create(originalCtx, { | ||
waitUntil: { | ||
value(promise) { | ||
waitUntilPromises?.push(promise.catch(err => console.error(err))); | ||
}, | ||
const extraPropsByReceiver = new WeakMap(); | ||
const deletedPropsByReceiver = new WeakMap(); | ||
function getExtraProps(receiver) { | ||
let extraProps = extraPropsByReceiver.get(receiver); | ||
if (!extraProps) { | ||
extraProps = {}; | ||
extraPropsByReceiver.set(receiver, extraProps); | ||
} | ||
return extraProps; | ||
} | ||
function getDeletedProps(receiver) { | ||
let deletedProps = deletedPropsByReceiver.get(receiver); | ||
if (!deletedProps) { | ||
deletedProps = new Set(); | ||
deletedPropsByReceiver.set(receiver, deletedProps); | ||
} | ||
return deletedProps; | ||
} | ||
return new Proxy(originalCtx, { | ||
get(originalCtx, prop, receiver) { | ||
if (waitUntilPromises != null && prop === 'waitUntil') { | ||
return function waitUntil(promise) { | ||
waitUntilPromises.push(promise.catch(err => console.error(err))); | ||
}; | ||
} | ||
const extraProps = getExtraProps(receiver); | ||
const extraPropVal = extraProps[prop]; | ||
if (extraPropVal != null) { | ||
if (typeof extraPropVal === 'function') { | ||
return extraPropVal.bind(extraProps); | ||
} | ||
return extraPropVal; | ||
} | ||
const deletedProps = getDeletedProps(receiver); | ||
if (deletedProps.has(prop)) { | ||
return undefined; | ||
} | ||
return originalCtx[prop]; | ||
}, | ||
set(_originalCtx, prop, value, receiver) { | ||
const extraProps = getExtraProps(receiver); | ||
extraProps[prop] = value; | ||
return true; | ||
}, | ||
has(originalCtx, prop) { | ||
if (waitUntilPromises != null && prop === 'waitUntil') { | ||
return true; | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
if (deletedProps.has(prop)) { | ||
return false; | ||
} | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return true; | ||
} | ||
return prop in originalCtx; | ||
}, | ||
defineProperty(originalCtx, prop, descriptor) { | ||
const extraProps = getExtraProps(originalCtx); | ||
return Reflect.defineProperty(extraProps, prop, descriptor); | ||
}, | ||
deleteProperty(originalCtx, prop) { | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return Reflect.deleteProperty(extraProps, prop); | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
deletedProps.add(prop); | ||
return true; | ||
}, | ||
ownKeys(originalCtx) { | ||
const extraProps = getExtraProps(originalCtx); | ||
const extraKeys = Reflect.ownKeys(extraProps); | ||
const originalKeys = Reflect.ownKeys(originalCtx); | ||
const deletedProps = getDeletedProps(originalCtx); | ||
const deletedKeys = Array.from(deletedProps); | ||
const allKeys = new Set(extraKeys.concat(originalKeys.filter(keys => !deletedKeys.includes(keys)))); | ||
if (waitUntilPromises != null) { | ||
allKeys.add('waitUntil'); | ||
} | ||
return Array.from(allKeys); | ||
}, | ||
getOwnPropertyDescriptor(originalCtx, prop) { | ||
const extraProps = getExtraProps(originalCtx); | ||
if (prop in extraProps) { | ||
return Reflect.getOwnPropertyDescriptor(extraProps, prop); | ||
} | ||
const deletedProps = getDeletedProps(originalCtx); | ||
if (deletedProps.has(prop)) { | ||
return undefined; | ||
} | ||
return Reflect.getOwnPropertyDescriptor(originalCtx, prop); | ||
}, | ||
}); | ||
@@ -440,0 +524,0 @@ } |
@@ -156,6 +156,10 @@ import { isPromise } from './utils.js'; | ||
write(chunk) { | ||
uwsResponse.write(chunk); | ||
uwsResponse.cork(() => { | ||
uwsResponse.write(chunk); | ||
}); | ||
}, | ||
close() { | ||
uwsResponse.end(); | ||
uwsResponse.cork(() => { | ||
uwsResponse.end(); | ||
}); | ||
}, | ||
@@ -194,10 +198,9 @@ }); | ||
} | ||
else if (!fetchResponse.body) { | ||
uwsResponse.end(); | ||
} | ||
}); | ||
if (bufferOfRes) { | ||
if (bufferOfRes || !fetchResponse.body) { | ||
return; | ||
} | ||
if (!fetchResponse.body) { | ||
uwsResponse.end(); | ||
return; | ||
} | ||
signal.addEventListener('abort', () => { | ||
@@ -204,0 +207,0 @@ if (!fetchResponse.body?.locked) { |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.9.55-alpha-20241113131053-631d899170a4be474752b774f7a4881855ee585a", | ||
"version": "0.9.55-alpha-20241113152551-99dc2fae1faa31a67535d6376eb19f716c02dca8", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154762
232597
3316
78
290
22
0