@jsenv/server 17.3.1 → 17.4.0
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.
|
@@ -297,41 +297,41 @@ var hasRequiredUtils;
|
|
|
297
297
|
function requireUtils () {
|
|
298
298
|
if (hasRequiredUtils) return utils;
|
|
299
299
|
hasRequiredUtils = 1;
|
|
300
|
-
(function (exports
|
|
300
|
+
(function (exports) {
|
|
301
301
|
/**
|
|
302
302
|
* Utilities for hex, bytes, CSPRNG.
|
|
303
303
|
* @module
|
|
304
304
|
*/
|
|
305
305
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
306
|
-
Object.defineProperty(exports
|
|
307
|
-
exports
|
|
308
|
-
exports
|
|
309
|
-
exports
|
|
310
|
-
exports
|
|
311
|
-
exports
|
|
312
|
-
exports
|
|
313
|
-
exports
|
|
314
|
-
exports
|
|
315
|
-
exports
|
|
316
|
-
exports
|
|
317
|
-
exports
|
|
318
|
-
exports
|
|
319
|
-
exports
|
|
320
|
-
exports
|
|
321
|
-
exports
|
|
322
|
-
exports
|
|
323
|
-
exports
|
|
324
|
-
exports
|
|
325
|
-
exports
|
|
326
|
-
exports
|
|
327
|
-
exports
|
|
328
|
-
exports
|
|
329
|
-
exports
|
|
330
|
-
exports
|
|
331
|
-
exports
|
|
332
|
-
exports
|
|
333
|
-
exports
|
|
334
|
-
exports
|
|
306
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
307
|
+
exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
|
|
308
|
+
exports.isBytes = isBytes;
|
|
309
|
+
exports.anumber = anumber;
|
|
310
|
+
exports.abytes = abytes;
|
|
311
|
+
exports.ahash = ahash;
|
|
312
|
+
exports.aexists = aexists;
|
|
313
|
+
exports.aoutput = aoutput;
|
|
314
|
+
exports.u8 = u8;
|
|
315
|
+
exports.u32 = u32;
|
|
316
|
+
exports.clean = clean;
|
|
317
|
+
exports.createView = createView;
|
|
318
|
+
exports.rotr = rotr;
|
|
319
|
+
exports.rotl = rotl;
|
|
320
|
+
exports.byteSwap = byteSwap;
|
|
321
|
+
exports.byteSwap32 = byteSwap32;
|
|
322
|
+
exports.bytesToHex = bytesToHex;
|
|
323
|
+
exports.hexToBytes = hexToBytes;
|
|
324
|
+
exports.asyncLoop = asyncLoop;
|
|
325
|
+
exports.utf8ToBytes = utf8ToBytes;
|
|
326
|
+
exports.bytesToUtf8 = bytesToUtf8;
|
|
327
|
+
exports.toBytes = toBytes;
|
|
328
|
+
exports.kdfInputToBytes = kdfInputToBytes;
|
|
329
|
+
exports.concatBytes = concatBytes;
|
|
330
|
+
exports.checkOpts = checkOpts;
|
|
331
|
+
exports.createHasher = createHasher;
|
|
332
|
+
exports.createOptHasher = createOptHasher;
|
|
333
|
+
exports.createXOFer = createXOFer;
|
|
334
|
+
exports.randomBytes = randomBytes;
|
|
335
335
|
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
336
336
|
// node.js versions earlier than v19 don't declare it in global scope.
|
|
337
337
|
// For node.js, package.json#exports field mapping rewrites import
|
|
@@ -404,7 +404,7 @@ function requireUtils () {
|
|
|
404
404
|
return (word << shift) | ((word >>> (32 - shift)) >>> 0);
|
|
405
405
|
}
|
|
406
406
|
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
407
|
-
exports
|
|
407
|
+
exports.isLE = (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
|
|
408
408
|
/** The byte swap operation for uint32 */
|
|
409
409
|
function byteSwap(word) {
|
|
410
410
|
return (((word << 24) & 0xff000000) |
|
|
@@ -413,11 +413,11 @@ function requireUtils () {
|
|
|
413
413
|
((word >>> 24) & 0xff));
|
|
414
414
|
}
|
|
415
415
|
/** Conditionally byte swap if on a big-endian platform */
|
|
416
|
-
exports
|
|
416
|
+
exports.swap8IfBE = exports.isLE
|
|
417
417
|
? (n) => n
|
|
418
418
|
: (n) => byteSwap(n);
|
|
419
419
|
/** @deprecated */
|
|
420
|
-
exports
|
|
420
|
+
exports.byteSwapIfBE = exports.swap8IfBE;
|
|
421
421
|
/** In place byte swap for Uint32Array */
|
|
422
422
|
function byteSwap32(arr) {
|
|
423
423
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -425,7 +425,7 @@ function requireUtils () {
|
|
|
425
425
|
}
|
|
426
426
|
return arr;
|
|
427
427
|
}
|
|
428
|
-
exports
|
|
428
|
+
exports.swap32IfBE = exports.isLE
|
|
429
429
|
? (u) => u
|
|
430
430
|
: byteSwap32;
|
|
431
431
|
// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
|
|
@@ -493,7 +493,7 @@ function requireUtils () {
|
|
|
493
493
|
* next scheduler queue processing step and this is exactly what we need.
|
|
494
494
|
*/
|
|
495
495
|
const nextTick = async () => { };
|
|
496
|
-
exports
|
|
496
|
+
exports.nextTick = nextTick;
|
|
497
497
|
/** Returns control to thread each 'tick' ms to avoid blocking. */
|
|
498
498
|
async function asyncLoop(iters, tick, cb) {
|
|
499
499
|
let ts = Date.now();
|
|
@@ -503,7 +503,7 @@ function requireUtils () {
|
|
|
503
503
|
const diff = Date.now() - ts;
|
|
504
504
|
if (diff >= 0 && diff < tick)
|
|
505
505
|
continue;
|
|
506
|
-
await (0, exports
|
|
506
|
+
await (0, exports.nextTick)();
|
|
507
507
|
ts += diff;
|
|
508
508
|
}
|
|
509
509
|
}
|
|
@@ -569,7 +569,7 @@ function requireUtils () {
|
|
|
569
569
|
/** For runtime check if class implements interface */
|
|
570
570
|
class Hash {
|
|
571
571
|
}
|
|
572
|
-
exports
|
|
572
|
+
exports.Hash = Hash;
|
|
573
573
|
/** Wraps hash function, creating an interface on top of it */
|
|
574
574
|
function createHasher(hashCons) {
|
|
575
575
|
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
@@ -595,9 +595,9 @@ function requireUtils () {
|
|
|
595
595
|
hashC.create = (opts) => hashCons(opts);
|
|
596
596
|
return hashC;
|
|
597
597
|
}
|
|
598
|
-
exports
|
|
599
|
-
exports
|
|
600
|
-
exports
|
|
598
|
+
exports.wrapConstructor = createHasher;
|
|
599
|
+
exports.wrapConstructorWithOpts = createOptHasher;
|
|
600
|
+
exports.wrapXOFConstructorWithOpts = createXOFer;
|
|
601
601
|
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
602
602
|
function randomBytes(bytesLength = 32) {
|
|
603
603
|
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') {
|
package/dist/jsenv_server.js
CHANGED
|
@@ -2907,6 +2907,30 @@ const trackHttp1ServerPendingRequests = (nodeServer) => {
|
|
|
2907
2907
|
* But we don't really need a class so we are just returning a regular object under the hood
|
|
2908
2908
|
*/
|
|
2909
2909
|
|
|
2910
|
+
/**
|
|
2911
|
+
* Return this from a route `fetch` to accept a websocket upgrade on that
|
|
2912
|
+
* endpoint.
|
|
2913
|
+
*
|
|
2914
|
+
* @param {(websocket: import("ws").WebSocket) => void | (() => void)} webSocketHandler
|
|
2915
|
+
* Called with the raw `ws` socket once the upgrade completes. Use
|
|
2916
|
+
* `websocket.on("message", …)` / `websocket.send(…)`. If it returns a
|
|
2917
|
+
* function, that function runs as cleanup when the socket closes.
|
|
2918
|
+
* @param {object} [init]
|
|
2919
|
+
* @param {number} [init.status=101]
|
|
2920
|
+
* @param {string} [init.statusText]
|
|
2921
|
+
* @param {object} [init.headers]
|
|
2922
|
+
*
|
|
2923
|
+
* @example
|
|
2924
|
+
* {
|
|
2925
|
+
* endpoint: "GET /chat.websocket",
|
|
2926
|
+
* fetch: () => new WebSocketResponse((websocket) => {
|
|
2927
|
+
* websocket.on("message", (data) => websocket.send(data));
|
|
2928
|
+
* return () => {
|
|
2929
|
+
* // socket closed
|
|
2930
|
+
* };
|
|
2931
|
+
* }),
|
|
2932
|
+
* }
|
|
2933
|
+
*/
|
|
2910
2934
|
class WebSocketResponse {
|
|
2911
2935
|
constructor(
|
|
2912
2936
|
webSocketHandler,
|
|
@@ -2986,7 +3010,7 @@ const getWebSocketHandler = (responseProperties) => {
|
|
|
2986
3010
|
* // Use in server route
|
|
2987
3011
|
* {
|
|
2988
3012
|
* endpoint: "GET /events",
|
|
2989
|
-
*
|
|
3013
|
+
* fetch: (request) => serverEvents.fetch(request)
|
|
2990
3014
|
* }
|
|
2991
3015
|
*/
|
|
2992
3016
|
class ServerEvents {
|
|
@@ -3044,7 +3068,7 @@ class ServerEvents {
|
|
|
3044
3068
|
* // Use in server route
|
|
3045
3069
|
* {
|
|
3046
3070
|
* endpoint: "GET /events",
|
|
3047
|
-
*
|
|
3071
|
+
* fetch: (request) => events.fetch(request)
|
|
3048
3072
|
* }
|
|
3049
3073
|
*/
|
|
3050
3074
|
class LazyServerEvents {
|
package/dist/ws/ws.js
CHANGED
|
@@ -9,6 +9,8 @@ import require$$7 from "node:url";
|
|
|
9
9
|
import require$$0 from "node:zlib";
|
|
10
10
|
import require$$0$1 from "node:buffer";
|
|
11
11
|
|
|
12
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
13
|
+
|
|
12
14
|
function getDefaultExportFromCjs (x) {
|
|
13
15
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
14
16
|
}
|
|
@@ -987,6 +989,10 @@ function requireReceiver () {
|
|
|
987
989
|
* extensions
|
|
988
990
|
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
|
989
991
|
* client or server mode
|
|
992
|
+
* @param {Number} [options.maxBufferedChunks=0] The maximum number of
|
|
993
|
+
* buffered data chunks
|
|
994
|
+
* @param {Number} [options.maxFragments=0] The maximum number of message
|
|
995
|
+
* fragments
|
|
990
996
|
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
991
997
|
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
992
998
|
* not to skip UTF-8 validation for text and close messages
|
|
@@ -1001,6 +1007,8 @@ function requireReceiver () {
|
|
|
1001
1007
|
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
1002
1008
|
this._extensions = options.extensions || {};
|
|
1003
1009
|
this._isServer = !!options.isServer;
|
|
1010
|
+
this._maxBufferedChunks = options.maxBufferedChunks | 0;
|
|
1011
|
+
this._maxFragments = options.maxFragments | 0;
|
|
1004
1012
|
this._maxPayload = options.maxPayload | 0;
|
|
1005
1013
|
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
1006
1014
|
this[kWebSocket] = undefined;
|
|
@@ -1018,6 +1026,7 @@ function requireReceiver () {
|
|
|
1018
1026
|
|
|
1019
1027
|
this._totalPayloadLength = 0;
|
|
1020
1028
|
this._messageLength = 0;
|
|
1029
|
+
this._numFragments = 0;
|
|
1021
1030
|
this._fragments = [];
|
|
1022
1031
|
|
|
1023
1032
|
this._errored = false;
|
|
@@ -1036,6 +1045,22 @@ function requireReceiver () {
|
|
|
1036
1045
|
_write(chunk, encoding, cb) {
|
|
1037
1046
|
if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
|
|
1038
1047
|
|
|
1048
|
+
if (
|
|
1049
|
+
this._maxBufferedChunks > 0 &&
|
|
1050
|
+
this._buffers.length >= this._maxBufferedChunks
|
|
1051
|
+
) {
|
|
1052
|
+
cb(
|
|
1053
|
+
this.createError(
|
|
1054
|
+
RangeError,
|
|
1055
|
+
'Too many buffered chunks',
|
|
1056
|
+
false,
|
|
1057
|
+
1008,
|
|
1058
|
+
'WS_ERR_TOO_MANY_BUFFERED_PARTS'
|
|
1059
|
+
)
|
|
1060
|
+
);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1039
1064
|
this._bufferedBytes += chunk.length;
|
|
1040
1065
|
this._buffers.push(chunk);
|
|
1041
1066
|
this.startLoop(cb);
|
|
@@ -1425,6 +1450,19 @@ function requireReceiver () {
|
|
|
1425
1450
|
return;
|
|
1426
1451
|
}
|
|
1427
1452
|
|
|
1453
|
+
if (this._maxFragments > 0 && ++this._numFragments > this._maxFragments) {
|
|
1454
|
+
const error = this.createError(
|
|
1455
|
+
RangeError,
|
|
1456
|
+
'Too many message fragments',
|
|
1457
|
+
false,
|
|
1458
|
+
1008,
|
|
1459
|
+
'WS_ERR_TOO_MANY_BUFFERED_PARTS'
|
|
1460
|
+
);
|
|
1461
|
+
|
|
1462
|
+
cb(error);
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1428
1466
|
if (this._compressed) {
|
|
1429
1467
|
this._state = INFLATING;
|
|
1430
1468
|
this.decompress(data, cb);
|
|
@@ -1497,6 +1535,7 @@ function requireReceiver () {
|
|
|
1497
1535
|
this._totalPayloadLength = 0;
|
|
1498
1536
|
this._messageLength = 0;
|
|
1499
1537
|
this._fragmented = 0;
|
|
1538
|
+
this._numFragments = 0;
|
|
1500
1539
|
this._fragments = [];
|
|
1501
1540
|
|
|
1502
1541
|
if (this._opcode === 2) {
|
|
@@ -1654,6 +1693,664 @@ function requireReceiver () {
|
|
|
1654
1693
|
return receiver$1;
|
|
1655
1694
|
}
|
|
1656
1695
|
|
|
1696
|
+
var util = {};
|
|
1697
|
+
|
|
1698
|
+
var isBuffer;
|
|
1699
|
+
var hasRequiredIsBuffer;
|
|
1700
|
+
|
|
1701
|
+
function requireIsBuffer () {
|
|
1702
|
+
if (hasRequiredIsBuffer) return isBuffer;
|
|
1703
|
+
hasRequiredIsBuffer = 1;
|
|
1704
|
+
isBuffer = function isBuffer(arg) {
|
|
1705
|
+
return arg instanceof Buffer;
|
|
1706
|
+
};
|
|
1707
|
+
return isBuffer;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
var inherits = {exports: {}};
|
|
1711
|
+
|
|
1712
|
+
var inherits_browser = {exports: {}};
|
|
1713
|
+
|
|
1714
|
+
var hasRequiredInherits_browser;
|
|
1715
|
+
|
|
1716
|
+
function requireInherits_browser () {
|
|
1717
|
+
if (hasRequiredInherits_browser) return inherits_browser.exports;
|
|
1718
|
+
hasRequiredInherits_browser = 1;
|
|
1719
|
+
if (typeof Object.create === 'function') {
|
|
1720
|
+
// implementation from standard node.js 'util' module
|
|
1721
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
1722
|
+
ctor.super_ = superCtor;
|
|
1723
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
|
1724
|
+
constructor: {
|
|
1725
|
+
value: ctor,
|
|
1726
|
+
enumerable: false,
|
|
1727
|
+
writable: true,
|
|
1728
|
+
configurable: true
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
};
|
|
1732
|
+
} else {
|
|
1733
|
+
// old school shim for old browsers
|
|
1734
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
1735
|
+
ctor.super_ = superCtor;
|
|
1736
|
+
var TempCtor = function () {};
|
|
1737
|
+
TempCtor.prototype = superCtor.prototype;
|
|
1738
|
+
ctor.prototype = new TempCtor();
|
|
1739
|
+
ctor.prototype.constructor = ctor;
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
return inherits_browser.exports;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
var hasRequiredInherits;
|
|
1746
|
+
|
|
1747
|
+
function requireInherits () {
|
|
1748
|
+
if (hasRequiredInherits) return inherits.exports;
|
|
1749
|
+
hasRequiredInherits = 1;
|
|
1750
|
+
try {
|
|
1751
|
+
var util = requireUtil();
|
|
1752
|
+
if (typeof util.inherits !== 'function') throw '';
|
|
1753
|
+
inherits.exports = util.inherits;
|
|
1754
|
+
} catch (e) {
|
|
1755
|
+
inherits.exports = requireInherits_browser();
|
|
1756
|
+
}
|
|
1757
|
+
return inherits.exports;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
var hasRequiredUtil;
|
|
1761
|
+
|
|
1762
|
+
function requireUtil () {
|
|
1763
|
+
if (hasRequiredUtil) return util;
|
|
1764
|
+
hasRequiredUtil = 1;
|
|
1765
|
+
(function (exports) {
|
|
1766
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
1767
|
+
//
|
|
1768
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
1769
|
+
// copy of this software and associated documentation files (the
|
|
1770
|
+
// "Software"), to deal in the Software without restriction, including
|
|
1771
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
1772
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
1773
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
1774
|
+
// following conditions:
|
|
1775
|
+
//
|
|
1776
|
+
// The above copyright notice and this permission notice shall be included
|
|
1777
|
+
// in all copies or substantial portions of the Software.
|
|
1778
|
+
//
|
|
1779
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
1780
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
1781
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
1782
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
1783
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
1784
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
1785
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1786
|
+
|
|
1787
|
+
var formatRegExp = /%[sdj%]/g;
|
|
1788
|
+
exports.format = function(f) {
|
|
1789
|
+
if (!isString(f)) {
|
|
1790
|
+
var objects = [];
|
|
1791
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
1792
|
+
objects.push(inspect(arguments[i]));
|
|
1793
|
+
}
|
|
1794
|
+
return objects.join(' ');
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
var i = 1;
|
|
1798
|
+
var args = arguments;
|
|
1799
|
+
var len = args.length;
|
|
1800
|
+
var str = String(f).replace(formatRegExp, function(x) {
|
|
1801
|
+
if (x === '%%') return '%';
|
|
1802
|
+
if (i >= len) return x;
|
|
1803
|
+
switch (x) {
|
|
1804
|
+
case '%s': return String(args[i++]);
|
|
1805
|
+
case '%d': return Number(args[i++]);
|
|
1806
|
+
case '%j':
|
|
1807
|
+
try {
|
|
1808
|
+
return JSON.stringify(args[i++]);
|
|
1809
|
+
} catch (_) {
|
|
1810
|
+
return '[Circular]';
|
|
1811
|
+
}
|
|
1812
|
+
default:
|
|
1813
|
+
return x;
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
for (var x = args[i]; i < len; x = args[++i]) {
|
|
1817
|
+
if (isNull(x) || !isObject(x)) {
|
|
1818
|
+
str += ' ' + x;
|
|
1819
|
+
} else {
|
|
1820
|
+
str += ' ' + inspect(x);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
return str;
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
// Mark that a method should not be used.
|
|
1828
|
+
// Returns a modified function which warns once by default.
|
|
1829
|
+
// If --no-deprecation is set, then it is a no-op.
|
|
1830
|
+
exports.deprecate = function(fn, msg) {
|
|
1831
|
+
// Allow for deprecating things in the process of starting up.
|
|
1832
|
+
if (isUndefined(commonjsGlobal.process)) {
|
|
1833
|
+
return function() {
|
|
1834
|
+
return exports.deprecate(fn, msg).apply(this, arguments);
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
if (process.noDeprecation === true) {
|
|
1839
|
+
return fn;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
var warned = false;
|
|
1843
|
+
function deprecated() {
|
|
1844
|
+
if (!warned) {
|
|
1845
|
+
if (process.throwDeprecation) {
|
|
1846
|
+
throw new Error(msg);
|
|
1847
|
+
} else if (process.traceDeprecation) {
|
|
1848
|
+
console.trace(msg);
|
|
1849
|
+
} else {
|
|
1850
|
+
console.error(msg);
|
|
1851
|
+
}
|
|
1852
|
+
warned = true;
|
|
1853
|
+
}
|
|
1854
|
+
return fn.apply(this, arguments);
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
return deprecated;
|
|
1858
|
+
};
|
|
1859
|
+
|
|
1860
|
+
|
|
1861
|
+
var debugs = {};
|
|
1862
|
+
var debugEnviron;
|
|
1863
|
+
exports.debuglog = function(set) {
|
|
1864
|
+
if (isUndefined(debugEnviron))
|
|
1865
|
+
debugEnviron = process.env.NODE_DEBUG || '';
|
|
1866
|
+
set = set.toUpperCase();
|
|
1867
|
+
if (!debugs[set]) {
|
|
1868
|
+
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
|
1869
|
+
var pid = process.pid;
|
|
1870
|
+
debugs[set] = function() {
|
|
1871
|
+
var msg = exports.format.apply(exports, arguments);
|
|
1872
|
+
console.error('%s %d: %s', set, pid, msg);
|
|
1873
|
+
};
|
|
1874
|
+
} else {
|
|
1875
|
+
debugs[set] = function() {};
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return debugs[set];
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* Echos the value of a value. Trys to print the value out
|
|
1884
|
+
* in the best way possible given the different types.
|
|
1885
|
+
*
|
|
1886
|
+
* @param {Object} obj The object to print out.
|
|
1887
|
+
* @param {Object} opts Optional options object that alters the output.
|
|
1888
|
+
*/
|
|
1889
|
+
/* legacy: obj, showHidden, depth, colors*/
|
|
1890
|
+
function inspect(obj, opts) {
|
|
1891
|
+
// default options
|
|
1892
|
+
var ctx = {
|
|
1893
|
+
seen: [],
|
|
1894
|
+
stylize: stylizeNoColor
|
|
1895
|
+
};
|
|
1896
|
+
// legacy...
|
|
1897
|
+
if (arguments.length >= 3) ctx.depth = arguments[2];
|
|
1898
|
+
if (arguments.length >= 4) ctx.colors = arguments[3];
|
|
1899
|
+
if (isBoolean(opts)) {
|
|
1900
|
+
// legacy...
|
|
1901
|
+
ctx.showHidden = opts;
|
|
1902
|
+
} else if (opts) {
|
|
1903
|
+
// got an "options" object
|
|
1904
|
+
exports._extend(ctx, opts);
|
|
1905
|
+
}
|
|
1906
|
+
// set default options
|
|
1907
|
+
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
|
1908
|
+
if (isUndefined(ctx.depth)) ctx.depth = 2;
|
|
1909
|
+
if (isUndefined(ctx.colors)) ctx.colors = false;
|
|
1910
|
+
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
|
1911
|
+
if (ctx.colors) ctx.stylize = stylizeWithColor;
|
|
1912
|
+
return formatValue(ctx, obj, ctx.depth);
|
|
1913
|
+
}
|
|
1914
|
+
exports.inspect = inspect;
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
1918
|
+
inspect.colors = {
|
|
1919
|
+
'bold' : [1, 22],
|
|
1920
|
+
'italic' : [3, 23],
|
|
1921
|
+
'underline' : [4, 24],
|
|
1922
|
+
'inverse' : [7, 27],
|
|
1923
|
+
'white' : [37, 39],
|
|
1924
|
+
'grey' : [90, 39],
|
|
1925
|
+
'black' : [30, 39],
|
|
1926
|
+
'blue' : [34, 39],
|
|
1927
|
+
'cyan' : [36, 39],
|
|
1928
|
+
'green' : [32, 39],
|
|
1929
|
+
'magenta' : [35, 39],
|
|
1930
|
+
'red' : [31, 39],
|
|
1931
|
+
'yellow' : [33, 39]
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
// Don't use 'blue' not visible on cmd.exe
|
|
1935
|
+
inspect.styles = {
|
|
1936
|
+
'special': 'cyan',
|
|
1937
|
+
'number': 'yellow',
|
|
1938
|
+
'boolean': 'yellow',
|
|
1939
|
+
'undefined': 'grey',
|
|
1940
|
+
'null': 'bold',
|
|
1941
|
+
'string': 'green',
|
|
1942
|
+
'date': 'magenta',
|
|
1943
|
+
// "name": intentionally not styling
|
|
1944
|
+
'regexp': 'red'
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
function stylizeWithColor(str, styleType) {
|
|
1949
|
+
var style = inspect.styles[styleType];
|
|
1950
|
+
|
|
1951
|
+
if (style) {
|
|
1952
|
+
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
|
1953
|
+
'\u001b[' + inspect.colors[style][1] + 'm';
|
|
1954
|
+
} else {
|
|
1955
|
+
return str;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
|
|
1960
|
+
function stylizeNoColor(str, styleType) {
|
|
1961
|
+
return str;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
|
|
1965
|
+
function arrayToHash(array) {
|
|
1966
|
+
var hash = {};
|
|
1967
|
+
|
|
1968
|
+
array.forEach(function(val, idx) {
|
|
1969
|
+
hash[val] = true;
|
|
1970
|
+
});
|
|
1971
|
+
|
|
1972
|
+
return hash;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
function formatValue(ctx, value, recurseTimes) {
|
|
1977
|
+
// Provide a hook for user-specified inspect functions.
|
|
1978
|
+
// Check that value is an object with an inspect function on it
|
|
1979
|
+
if (ctx.customInspect &&
|
|
1980
|
+
value &&
|
|
1981
|
+
isFunction(value.inspect) &&
|
|
1982
|
+
// Filter out the util module, it's inspect function is special
|
|
1983
|
+
value.inspect !== exports.inspect &&
|
|
1984
|
+
// Also filter out any prototype objects using the circular check.
|
|
1985
|
+
!(value.constructor && value.constructor.prototype === value)) {
|
|
1986
|
+
var ret = value.inspect(recurseTimes, ctx);
|
|
1987
|
+
if (!isString(ret)) {
|
|
1988
|
+
ret = formatValue(ctx, ret, recurseTimes);
|
|
1989
|
+
}
|
|
1990
|
+
return ret;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
// Primitive types cannot have properties
|
|
1994
|
+
var primitive = formatPrimitive(ctx, value);
|
|
1995
|
+
if (primitive) {
|
|
1996
|
+
return primitive;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
// Look up the keys of the object.
|
|
2000
|
+
var keys = Object.keys(value);
|
|
2001
|
+
var visibleKeys = arrayToHash(keys);
|
|
2002
|
+
|
|
2003
|
+
if (ctx.showHidden) {
|
|
2004
|
+
keys = Object.getOwnPropertyNames(value);
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// IE doesn't make error fields non-enumerable
|
|
2008
|
+
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
|
|
2009
|
+
if (isError(value)
|
|
2010
|
+
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
|
2011
|
+
return formatError(value);
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// Some type of object without properties can be shortcutted.
|
|
2015
|
+
if (keys.length === 0) {
|
|
2016
|
+
if (isFunction(value)) {
|
|
2017
|
+
var name = value.name ? ': ' + value.name : '';
|
|
2018
|
+
return ctx.stylize('[Function' + name + ']', 'special');
|
|
2019
|
+
}
|
|
2020
|
+
if (isRegExp(value)) {
|
|
2021
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
2022
|
+
}
|
|
2023
|
+
if (isDate(value)) {
|
|
2024
|
+
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|
2025
|
+
}
|
|
2026
|
+
if (isError(value)) {
|
|
2027
|
+
return formatError(value);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
var base = '', array = false, braces = ['{', '}'];
|
|
2032
|
+
|
|
2033
|
+
// Make Array say that they are Array
|
|
2034
|
+
if (isArray(value)) {
|
|
2035
|
+
array = true;
|
|
2036
|
+
braces = ['[', ']'];
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// Make functions say that they are functions
|
|
2040
|
+
if (isFunction(value)) {
|
|
2041
|
+
var n = value.name ? ': ' + value.name : '';
|
|
2042
|
+
base = ' [Function' + n + ']';
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
// Make RegExps say that they are RegExps
|
|
2046
|
+
if (isRegExp(value)) {
|
|
2047
|
+
base = ' ' + RegExp.prototype.toString.call(value);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
// Make dates with properties first say the date
|
|
2051
|
+
if (isDate(value)) {
|
|
2052
|
+
base = ' ' + Date.prototype.toUTCString.call(value);
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// Make error with message first say the error
|
|
2056
|
+
if (isError(value)) {
|
|
2057
|
+
base = ' ' + formatError(value);
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
if (keys.length === 0 && (!array || value.length == 0)) {
|
|
2061
|
+
return braces[0] + base + braces[1];
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
if (recurseTimes < 0) {
|
|
2065
|
+
if (isRegExp(value)) {
|
|
2066
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
2067
|
+
} else {
|
|
2068
|
+
return ctx.stylize('[Object]', 'special');
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
ctx.seen.push(value);
|
|
2073
|
+
|
|
2074
|
+
var output;
|
|
2075
|
+
if (array) {
|
|
2076
|
+
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|
2077
|
+
} else {
|
|
2078
|
+
output = keys.map(function(key) {
|
|
2079
|
+
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
ctx.seen.pop();
|
|
2084
|
+
|
|
2085
|
+
return reduceToSingleString(output, base, braces);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
function formatPrimitive(ctx, value) {
|
|
2090
|
+
if (isUndefined(value))
|
|
2091
|
+
return ctx.stylize('undefined', 'undefined');
|
|
2092
|
+
if (isString(value)) {
|
|
2093
|
+
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
2094
|
+
.replace(/'/g, "\\'")
|
|
2095
|
+
.replace(/\\"/g, '"') + '\'';
|
|
2096
|
+
return ctx.stylize(simple, 'string');
|
|
2097
|
+
}
|
|
2098
|
+
if (isNumber(value))
|
|
2099
|
+
return ctx.stylize('' + value, 'number');
|
|
2100
|
+
if (isBoolean(value))
|
|
2101
|
+
return ctx.stylize('' + value, 'boolean');
|
|
2102
|
+
// For some reason typeof null is "object", so special case here.
|
|
2103
|
+
if (isNull(value))
|
|
2104
|
+
return ctx.stylize('null', 'null');
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
function formatError(value) {
|
|
2109
|
+
return '[' + Error.prototype.toString.call(value) + ']';
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
2114
|
+
var output = [];
|
|
2115
|
+
for (var i = 0, l = value.length; i < l; ++i) {
|
|
2116
|
+
if (hasOwnProperty(value, String(i))) {
|
|
2117
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
2118
|
+
String(i), true));
|
|
2119
|
+
} else {
|
|
2120
|
+
output.push('');
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
keys.forEach(function(key) {
|
|
2124
|
+
if (!key.match(/^\d+$/)) {
|
|
2125
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
2126
|
+
key, true));
|
|
2127
|
+
}
|
|
2128
|
+
});
|
|
2129
|
+
return output;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
2134
|
+
var name, str, desc;
|
|
2135
|
+
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|
2136
|
+
if (desc.get) {
|
|
2137
|
+
if (desc.set) {
|
|
2138
|
+
str = ctx.stylize('[Getter/Setter]', 'special');
|
|
2139
|
+
} else {
|
|
2140
|
+
str = ctx.stylize('[Getter]', 'special');
|
|
2141
|
+
}
|
|
2142
|
+
} else {
|
|
2143
|
+
if (desc.set) {
|
|
2144
|
+
str = ctx.stylize('[Setter]', 'special');
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
if (!hasOwnProperty(visibleKeys, key)) {
|
|
2148
|
+
name = '[' + key + ']';
|
|
2149
|
+
}
|
|
2150
|
+
if (!str) {
|
|
2151
|
+
if (ctx.seen.indexOf(desc.value) < 0) {
|
|
2152
|
+
if (isNull(recurseTimes)) {
|
|
2153
|
+
str = formatValue(ctx, desc.value, null);
|
|
2154
|
+
} else {
|
|
2155
|
+
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|
2156
|
+
}
|
|
2157
|
+
if (str.indexOf('\n') > -1) {
|
|
2158
|
+
if (array) {
|
|
2159
|
+
str = str.split('\n').map(function(line) {
|
|
2160
|
+
return ' ' + line;
|
|
2161
|
+
}).join('\n').substr(2);
|
|
2162
|
+
} else {
|
|
2163
|
+
str = '\n' + str.split('\n').map(function(line) {
|
|
2164
|
+
return ' ' + line;
|
|
2165
|
+
}).join('\n');
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
} else {
|
|
2169
|
+
str = ctx.stylize('[Circular]', 'special');
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
if (isUndefined(name)) {
|
|
2173
|
+
if (array && key.match(/^\d+$/)) {
|
|
2174
|
+
return str;
|
|
2175
|
+
}
|
|
2176
|
+
name = JSON.stringify('' + key);
|
|
2177
|
+
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
2178
|
+
name = name.substr(1, name.length - 2);
|
|
2179
|
+
name = ctx.stylize(name, 'name');
|
|
2180
|
+
} else {
|
|
2181
|
+
name = name.replace(/'/g, "\\'")
|
|
2182
|
+
.replace(/\\"/g, '"')
|
|
2183
|
+
.replace(/(^"|"$)/g, "'");
|
|
2184
|
+
name = ctx.stylize(name, 'string');
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
return name + ': ' + str;
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
function reduceToSingleString(output, base, braces) {
|
|
2193
|
+
var length = output.reduce(function(prev, cur) {
|
|
2194
|
+
if (cur.indexOf('\n') >= 0) ;
|
|
2195
|
+
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
|
2196
|
+
}, 0);
|
|
2197
|
+
|
|
2198
|
+
if (length > 60) {
|
|
2199
|
+
return braces[0] +
|
|
2200
|
+
(base === '' ? '' : base + '\n ') +
|
|
2201
|
+
' ' +
|
|
2202
|
+
output.join(',\n ') +
|
|
2203
|
+
' ' +
|
|
2204
|
+
braces[1];
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
|
|
2211
|
+
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|
2212
|
+
// because it is fragile and can be easily faked with `Object.create()`.
|
|
2213
|
+
function isArray(ar) {
|
|
2214
|
+
return Array.isArray(ar);
|
|
2215
|
+
}
|
|
2216
|
+
exports.isArray = isArray;
|
|
2217
|
+
|
|
2218
|
+
function isBoolean(arg) {
|
|
2219
|
+
return typeof arg === 'boolean';
|
|
2220
|
+
}
|
|
2221
|
+
exports.isBoolean = isBoolean;
|
|
2222
|
+
|
|
2223
|
+
function isNull(arg) {
|
|
2224
|
+
return arg === null;
|
|
2225
|
+
}
|
|
2226
|
+
exports.isNull = isNull;
|
|
2227
|
+
|
|
2228
|
+
function isNullOrUndefined(arg) {
|
|
2229
|
+
return arg == null;
|
|
2230
|
+
}
|
|
2231
|
+
exports.isNullOrUndefined = isNullOrUndefined;
|
|
2232
|
+
|
|
2233
|
+
function isNumber(arg) {
|
|
2234
|
+
return typeof arg === 'number';
|
|
2235
|
+
}
|
|
2236
|
+
exports.isNumber = isNumber;
|
|
2237
|
+
|
|
2238
|
+
function isString(arg) {
|
|
2239
|
+
return typeof arg === 'string';
|
|
2240
|
+
}
|
|
2241
|
+
exports.isString = isString;
|
|
2242
|
+
|
|
2243
|
+
function isSymbol(arg) {
|
|
2244
|
+
return typeof arg === 'symbol';
|
|
2245
|
+
}
|
|
2246
|
+
exports.isSymbol = isSymbol;
|
|
2247
|
+
|
|
2248
|
+
function isUndefined(arg) {
|
|
2249
|
+
return arg === void 0;
|
|
2250
|
+
}
|
|
2251
|
+
exports.isUndefined = isUndefined;
|
|
2252
|
+
|
|
2253
|
+
function isRegExp(re) {
|
|
2254
|
+
return isObject(re) && objectToString(re) === '[object RegExp]';
|
|
2255
|
+
}
|
|
2256
|
+
exports.isRegExp = isRegExp;
|
|
2257
|
+
|
|
2258
|
+
function isObject(arg) {
|
|
2259
|
+
return typeof arg === 'object' && arg !== null;
|
|
2260
|
+
}
|
|
2261
|
+
exports.isObject = isObject;
|
|
2262
|
+
|
|
2263
|
+
function isDate(d) {
|
|
2264
|
+
return isObject(d) && objectToString(d) === '[object Date]';
|
|
2265
|
+
}
|
|
2266
|
+
exports.isDate = isDate;
|
|
2267
|
+
|
|
2268
|
+
function isError(e) {
|
|
2269
|
+
return isObject(e) &&
|
|
2270
|
+
(objectToString(e) === '[object Error]' || e instanceof Error);
|
|
2271
|
+
}
|
|
2272
|
+
exports.isError = isError;
|
|
2273
|
+
|
|
2274
|
+
function isFunction(arg) {
|
|
2275
|
+
return typeof arg === 'function';
|
|
2276
|
+
}
|
|
2277
|
+
exports.isFunction = isFunction;
|
|
2278
|
+
|
|
2279
|
+
function isPrimitive(arg) {
|
|
2280
|
+
return arg === null ||
|
|
2281
|
+
typeof arg === 'boolean' ||
|
|
2282
|
+
typeof arg === 'number' ||
|
|
2283
|
+
typeof arg === 'string' ||
|
|
2284
|
+
typeof arg === 'symbol' || // ES6 symbol
|
|
2285
|
+
typeof arg === 'undefined';
|
|
2286
|
+
}
|
|
2287
|
+
exports.isPrimitive = isPrimitive;
|
|
2288
|
+
|
|
2289
|
+
exports.isBuffer = requireIsBuffer();
|
|
2290
|
+
|
|
2291
|
+
function objectToString(o) {
|
|
2292
|
+
return Object.prototype.toString.call(o);
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
|
|
2296
|
+
function pad(n) {
|
|
2297
|
+
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
|
|
2301
|
+
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|
2302
|
+
'Oct', 'Nov', 'Dec'];
|
|
2303
|
+
|
|
2304
|
+
// 26 Feb 16:19:34
|
|
2305
|
+
function timestamp() {
|
|
2306
|
+
var d = new Date();
|
|
2307
|
+
var time = [pad(d.getHours()),
|
|
2308
|
+
pad(d.getMinutes()),
|
|
2309
|
+
pad(d.getSeconds())].join(':');
|
|
2310
|
+
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
// log is just a thin wrapper to console.log that prepends a timestamp
|
|
2315
|
+
exports.log = function() {
|
|
2316
|
+
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
|
2317
|
+
};
|
|
2318
|
+
|
|
2319
|
+
|
|
2320
|
+
/**
|
|
2321
|
+
* Inherit the prototype methods from one constructor into another.
|
|
2322
|
+
*
|
|
2323
|
+
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|
2324
|
+
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
|
2325
|
+
* during bootstrapping this function needs to be rewritten using some native
|
|
2326
|
+
* functions as prototype setup using normal JavaScript does not work as
|
|
2327
|
+
* expected during bootstrapping (see mirror.js in r114903).
|
|
2328
|
+
*
|
|
2329
|
+
* @param {function} ctor Constructor function which needs to inherit the
|
|
2330
|
+
* prototype.
|
|
2331
|
+
* @param {function} superCtor Constructor function to inherit prototype from.
|
|
2332
|
+
*/
|
|
2333
|
+
exports.inherits = requireInherits();
|
|
2334
|
+
|
|
2335
|
+
exports._extend = function(origin, add) {
|
|
2336
|
+
// Don't do anything if add isn't an object
|
|
2337
|
+
if (!add || !isObject(add)) return origin;
|
|
2338
|
+
|
|
2339
|
+
var keys = Object.keys(add);
|
|
2340
|
+
var i = keys.length;
|
|
2341
|
+
while (i--) {
|
|
2342
|
+
origin[keys[i]] = add[keys[i]];
|
|
2343
|
+
}
|
|
2344
|
+
return origin;
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2347
|
+
function hasOwnProperty(obj, prop) {
|
|
2348
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
2349
|
+
}
|
|
2350
|
+
} (util));
|
|
2351
|
+
return util;
|
|
2352
|
+
}
|
|
2353
|
+
|
|
1657
2354
|
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex" }] */
|
|
1658
2355
|
|
|
1659
2356
|
var sender$1;
|
|
@@ -1665,6 +2362,9 @@ function requireSender () {
|
|
|
1665
2362
|
|
|
1666
2363
|
const { Duplex } = require$$0$2;
|
|
1667
2364
|
const { randomFillSync } = require$$1;
|
|
2365
|
+
const {
|
|
2366
|
+
types: { isUint8Array }
|
|
2367
|
+
} = requireUtil();
|
|
1668
2368
|
|
|
1669
2369
|
const PerMessageDeflate = requirePermessageDeflate();
|
|
1670
2370
|
const { EMPTY_BUFFER, kWebSocket, NOOP } = requireConstants();
|
|
@@ -1861,8 +2561,10 @@ function requireSender () {
|
|
|
1861
2561
|
|
|
1862
2562
|
if (typeof data === 'string') {
|
|
1863
2563
|
buf.write(data, 2);
|
|
1864
|
-
} else {
|
|
2564
|
+
} else if (isUint8Array(data)) {
|
|
1865
2565
|
buf.set(data, 2);
|
|
2566
|
+
} else {
|
|
2567
|
+
throw new TypeError('Second argument must be a string or a Uint8Array');
|
|
1866
2568
|
}
|
|
1867
2569
|
}
|
|
1868
2570
|
|
|
@@ -2983,6 +3685,10 @@ function requireWebsocket () {
|
|
|
2983
3685
|
* multiple times in the same tick
|
|
2984
3686
|
* @param {Function} [options.generateMask] The function used to generate the
|
|
2985
3687
|
* masking key
|
|
3688
|
+
* @param {Number} [options.maxBufferedChunks=0] The maximum number of
|
|
3689
|
+
* buffered data chunks
|
|
3690
|
+
* @param {Number} [options.maxFragments=0] The maximum number of message
|
|
3691
|
+
* fragments
|
|
2986
3692
|
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
2987
3693
|
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
2988
3694
|
* not to skip UTF-8 validation for text and close messages
|
|
@@ -2994,6 +3700,8 @@ function requireWebsocket () {
|
|
|
2994
3700
|
binaryType: this.binaryType,
|
|
2995
3701
|
extensions: this._extensions,
|
|
2996
3702
|
isServer: this._isServer,
|
|
3703
|
+
maxBufferedChunks: options.maxBufferedChunks,
|
|
3704
|
+
maxFragments: options.maxFragments,
|
|
2997
3705
|
maxPayload: options.maxPayload,
|
|
2998
3706
|
skipUTF8Validation: options.skipUTF8Validation
|
|
2999
3707
|
});
|
|
@@ -3422,6 +4130,10 @@ function requireWebsocket () {
|
|
|
3422
4130
|
* masking key
|
|
3423
4131
|
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
|
|
3424
4132
|
* handshake request
|
|
4133
|
+
* @param {Number} [options.maxBufferedChunks=262144] The maximum number of
|
|
4134
|
+
* buffered data chunks
|
|
4135
|
+
* @param {Number} [options.maxFragments=16384] The maximum number of message
|
|
4136
|
+
* fragments
|
|
3425
4137
|
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
3426
4138
|
* size
|
|
3427
4139
|
* @param {Number} [options.maxRedirects=10] The maximum number of redirects
|
|
@@ -3442,6 +4154,8 @@ function requireWebsocket () {
|
|
|
3442
4154
|
autoPong: true,
|
|
3443
4155
|
closeTimeout: CLOSE_TIMEOUT,
|
|
3444
4156
|
protocolVersion: protocolVersions[1],
|
|
4157
|
+
maxBufferedChunks: 256 * 1024,
|
|
4158
|
+
maxFragments: 16 * 1024,
|
|
3445
4159
|
maxPayload: 100 * 1024 * 1024,
|
|
3446
4160
|
skipUTF8Validation: false,
|
|
3447
4161
|
perMessageDeflate: true,
|
|
@@ -3799,6 +4513,8 @@ function requireWebsocket () {
|
|
|
3799
4513
|
websocket.setSocket(socket, head, {
|
|
3800
4514
|
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
3801
4515
|
generateMask: opts.generateMask,
|
|
4516
|
+
maxBufferedChunks: opts.maxBufferedChunks,
|
|
4517
|
+
maxFragments: opts.maxFragments,
|
|
3802
4518
|
maxPayload: opts.maxPayload,
|
|
3803
4519
|
skipUTF8Validation: opts.skipUTF8Validation
|
|
3804
4520
|
});
|
|
@@ -4480,6 +5196,10 @@ function requireWebsocketServer () {
|
|
|
4480
5196
|
* called
|
|
4481
5197
|
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
4482
5198
|
* @param {String} [options.host] The hostname where to bind the server
|
|
5199
|
+
* @param {Number} [options.maxBufferedChunks=262144] The maximum number of
|
|
5200
|
+
* buffered data chunks
|
|
5201
|
+
* @param {Number} [options.maxFragments=16384] The maximum number of message
|
|
5202
|
+
* fragments
|
|
4483
5203
|
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
4484
5204
|
* size
|
|
4485
5205
|
* @param {Boolean} [options.noServer=false] Enable no server mode
|
|
@@ -4502,6 +5222,8 @@ function requireWebsocketServer () {
|
|
|
4502
5222
|
options = {
|
|
4503
5223
|
allowSynchronousEvents: true,
|
|
4504
5224
|
autoPong: true,
|
|
5225
|
+
maxBufferedChunks: 256 * 1024,
|
|
5226
|
+
maxFragments: 16 * 1024,
|
|
4505
5227
|
maxPayload: 100 * 1024 * 1024,
|
|
4506
5228
|
skipUTF8Validation: false,
|
|
4507
5229
|
perMessageDeflate: false,
|
|
@@ -4861,6 +5583,8 @@ function requireWebsocketServer () {
|
|
|
4861
5583
|
|
|
4862
5584
|
ws.setSocket(socket, head, {
|
|
4863
5585
|
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
5586
|
+
maxBufferedChunks: this.options.maxBufferedChunks,
|
|
5587
|
+
maxFragments: this.options.maxFragments,
|
|
4864
5588
|
maxPayload: this.options.maxPayload,
|
|
4865
5589
|
skipUTF8Validation: this.options.skipUTF8Validation
|
|
4866
5590
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/server",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A modern Node.js HTTP server with declarative routing, content negotiation, and WebSocket support",
|
|
6
6
|
"repository": {
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"@jsenv/utils": "../../tooling/utils",
|
|
57
57
|
"eventsource": "4.1.0",
|
|
58
58
|
"formidable": "3.5.4",
|
|
59
|
-
"playwright": "1.
|
|
60
|
-
"undici": "
|
|
61
|
-
"ws": "8.
|
|
59
|
+
"playwright": "1.61.1",
|
|
60
|
+
"undici": "8.8.0",
|
|
61
|
+
"ws": "8.21.1"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
package/src/server_events.js
CHANGED
|
@@ -49,7 +49,7 @@ import { WebSocketResponse } from "./web_socket_response.js";
|
|
|
49
49
|
* // Use in server route
|
|
50
50
|
* {
|
|
51
51
|
* endpoint: "GET /events",
|
|
52
|
-
*
|
|
52
|
+
* fetch: (request) => serverEvents.fetch(request)
|
|
53
53
|
* }
|
|
54
54
|
*/
|
|
55
55
|
export class ServerEvents {
|
|
@@ -107,7 +107,7 @@ export class ServerEvents {
|
|
|
107
107
|
* // Use in server route
|
|
108
108
|
* {
|
|
109
109
|
* endpoint: "GET /events",
|
|
110
|
-
*
|
|
110
|
+
* fetch: (request) => events.fetch(request)
|
|
111
111
|
* }
|
|
112
112
|
*/
|
|
113
113
|
export class LazyServerEvents {
|
|
@@ -14,6 +14,30 @@
|
|
|
14
14
|
* But we don't really need a class so we are just returning a regular object under the hood
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Return this from a route `fetch` to accept a websocket upgrade on that
|
|
19
|
+
* endpoint.
|
|
20
|
+
*
|
|
21
|
+
* @param {(websocket: import("ws").WebSocket) => void | (() => void)} webSocketHandler
|
|
22
|
+
* Called with the raw `ws` socket once the upgrade completes. Use
|
|
23
|
+
* `websocket.on("message", …)` / `websocket.send(…)`. If it returns a
|
|
24
|
+
* function, that function runs as cleanup when the socket closes.
|
|
25
|
+
* @param {object} [init]
|
|
26
|
+
* @param {number} [init.status=101]
|
|
27
|
+
* @param {string} [init.statusText]
|
|
28
|
+
* @param {object} [init.headers]
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* {
|
|
32
|
+
* endpoint: "GET /chat.websocket",
|
|
33
|
+
* fetch: () => new WebSocketResponse((websocket) => {
|
|
34
|
+
* websocket.on("message", (data) => websocket.send(data));
|
|
35
|
+
* return () => {
|
|
36
|
+
* // socket closed
|
|
37
|
+
* };
|
|
38
|
+
* }),
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
17
41
|
export class WebSocketResponse {
|
|
18
42
|
constructor(
|
|
19
43
|
webSocketHandler,
|