@arokodev/cli 0.1.0-alpha.5 → 0.1.0-alpha.8

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.
Files changed (167) hide show
  1. package/node_modules/@pairmesh/client/dist/build-info.generated.d.ts +12 -12
  2. package/node_modules/@pairmesh/client/dist/build-info.generated.js +6 -6
  3. package/node_modules/@pairmesh/client/dist/connectivity/relay/hosted-server.js +1 -1
  4. package/node_modules/@pairmesh/client/dist/session/schemas.d.ts +10 -10
  5. package/node_modules/@pairmesh/client/dist/session/schemas.d.ts.map +1 -1
  6. package/node_modules/@pairmesh/client/package.json +5 -5
  7. package/node_modules/@pairmesh/coordination/package.json +5 -5
  8. package/node_modules/@pairmesh/mcp/package.json +5 -5
  9. package/node_modules/@pairmesh/permissions/package.json +2 -2
  10. package/node_modules/@pairmesh/protocol/dist/action.d.ts +1 -1
  11. package/node_modules/@pairmesh/protocol/dist/inspection-execution.d.ts +1 -1
  12. package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts +1 -1
  13. package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts.map +1 -1
  14. package/node_modules/@pairmesh/protocol/dist/inspection.d.ts +2 -2
  15. package/node_modules/@pairmesh/protocol/dist/pairing.d.ts +1 -1
  16. package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts +1 -1
  17. package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts.map +1 -1
  18. package/node_modules/@pairmesh/protocol/package.json +2 -2
  19. package/node_modules/@pairmesh/shared/package.json +1 -1
  20. package/node_modules/body-parser/README.md +17 -13
  21. package/node_modules/body-parser/lib/read.js +74 -57
  22. package/node_modules/body-parser/lib/types/json.js +11 -11
  23. package/node_modules/body-parser/lib/types/urlencoded.js +5 -5
  24. package/node_modules/body-parser/lib/utils.js +0 -15
  25. package/node_modules/body-parser/package.json +7 -12
  26. package/node_modules/encodeurl/README.md +14 -0
  27. package/node_modules/encodeurl/index.js +9 -11
  28. package/node_modules/encodeurl/package.json +13 -6
  29. package/node_modules/jose/README.md +2 -2
  30. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
  31. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
  32. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
  33. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
  34. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
  35. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
  36. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
  37. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
  38. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
  39. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
  40. package/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
  41. package/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
  42. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -6
  43. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
  44. package/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
  45. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +3 -1
  46. package/node_modules/jose/dist/types/jwt/verify.d.ts +6 -5
  47. package/node_modules/jose/dist/types/key/export.d.ts +1 -1
  48. package/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
  49. package/node_modules/jose/dist/types/key/import.d.ts +2 -2
  50. package/node_modules/jose/dist/types/types.d.ts +173 -107
  51. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -2
  52. package/node_modules/jose/dist/types/util/errors.d.ts +1 -1
  53. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +3 -2
  54. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
  55. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
  56. package/node_modules/jose/dist/webapi/jwks/local.js +2 -1
  57. package/node_modules/jose/dist/webapi/jwks/remote.js +6 -4
  58. package/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
  59. package/node_modules/jose/dist/webapi/jws/general/verify.js +5 -11
  60. package/node_modules/jose/dist/webapi/jwt/encrypt.js +6 -9
  61. package/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
  62. package/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
  63. package/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
  64. package/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
  65. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
  66. package/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
  67. package/node_modules/jose/dist/webapi/lib/deflate.js +2 -1
  68. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +26 -23
  69. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +5 -5
  70. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
  71. package/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
  72. package/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
  73. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +48 -44
  74. package/node_modules/jose/dist/webapi/lib/key.js +6 -4
  75. package/node_modules/jose/dist/webapi/lib/key_management.js +17 -18
  76. package/node_modules/jose/dist/webapi/lib/validate.js +10 -10
  77. package/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
  78. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
  79. package/node_modules/jose/package.json +1 -1
  80. package/node_modules/object-inspect/CHANGELOG.md +31 -0
  81. package/node_modules/object-inspect/index.js +326 -24
  82. package/node_modules/object-inspect/package.json +22 -13
  83. package/node_modules/object-inspect/readme.markdown +4 -1
  84. package/node_modules/object-inspect/stringWidth.js +68 -0
  85. package/node_modules/object-inspect/stringWidthRanges.js +38 -0
  86. package/node_modules/on-finished/index.js +14 -2
  87. package/node_modules/on-finished/package.json +11 -7
  88. package/node_modules/qs/.editorconfig +1 -1
  89. package/node_modules/qs/.github/THREAT_MODEL.md +4 -2
  90. package/node_modules/qs/CHANGELOG.md +103 -14
  91. package/node_modules/qs/README.md +90 -9
  92. package/node_modules/qs/dist/qs.js +19 -19
  93. package/node_modules/qs/eslint.config.mjs +61 -50
  94. package/node_modules/qs/lib/formats.js +7 -2
  95. package/node_modules/qs/lib/parse.js +121 -12
  96. package/node_modules/qs/lib/stringify.js +9 -7
  97. package/node_modules/qs/lib/utils.js +158 -15
  98. package/node_modules/qs/package.json +8 -8
  99. package/node_modules/qs/test/parse.js +509 -2
  100. package/node_modules/qs/test/stringify.js +485 -33
  101. package/node_modules/qs/test/utils.js +245 -3
  102. package/node_modules/router/HISTORY.md +67 -52
  103. package/node_modules/router/README.md +222 -2
  104. package/node_modules/router/index.d.ts +188 -0
  105. package/node_modules/router/index.js +86 -50
  106. package/node_modules/router/lib/layer.js +154 -47
  107. package/node_modules/router/lib/param.js +47 -0
  108. package/node_modules/router/lib/route.d.ts +118 -0
  109. package/node_modules/router/lib/route.js +14 -8
  110. package/node_modules/router/lib/symbols.js +4 -0
  111. package/node_modules/router/lib/tracing.js +173 -0
  112. package/node_modules/router/package.json +24 -9
  113. package/node_modules/ws/README.md +22 -31
  114. package/node_modules/ws/lib/buffer-util.js +13 -2
  115. package/node_modules/ws/lib/receiver.js +8 -0
  116. package/node_modules/ws/lib/sender.js +4 -1
  117. package/node_modules/ws/lib/websocket-server.js +3 -0
  118. package/node_modules/ws/lib/websocket.js +66 -16
  119. package/node_modules/ws/package.json +1 -1
  120. package/node_modules/zod/package.json +1 -1
  121. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  122. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  123. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  124. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  125. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  126. package/node_modules/zod/src/v4/core/util.ts +13 -0
  127. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  128. package/node_modules/zod/v4/core/compile.cjs +8 -0
  129. package/node_modules/zod/v4/core/compile.js +8 -0
  130. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  131. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  132. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  133. package/node_modules/zod/v4/core/schemas.js +30 -0
  134. package/node_modules/zod/v4/core/util.cjs +15 -0
  135. package/node_modules/zod/v4/core/util.d.cts +2 -0
  136. package/node_modules/zod/v4/core/util.d.ts +2 -0
  137. package/node_modules/zod/v4/core/util.js +14 -0
  138. package/node_modules/zod/v4/core/versions.cjs +1 -1
  139. package/node_modules/zod/v4/core/versions.js +1 -1
  140. package/package.json +7 -7
  141. package/node_modules/object-inspect/.eslintrc +0 -53
  142. package/node_modules/object-inspect/.nycrc +0 -13
  143. package/node_modules/object-inspect/example/all.js +0 -23
  144. package/node_modules/object-inspect/example/circular.js +0 -6
  145. package/node_modules/object-inspect/example/fn.js +0 -5
  146. package/node_modules/object-inspect/example/inspect.js +0 -10
  147. package/node_modules/object-inspect/test/bigint.js +0 -58
  148. package/node_modules/object-inspect/test/browser/dom.js +0 -15
  149. package/node_modules/object-inspect/test/circular.js +0 -16
  150. package/node_modules/object-inspect/test/deep.js +0 -12
  151. package/node_modules/object-inspect/test/element.js +0 -53
  152. package/node_modules/object-inspect/test/err.js +0 -48
  153. package/node_modules/object-inspect/test/fakes.js +0 -29
  154. package/node_modules/object-inspect/test/fn.js +0 -76
  155. package/node_modules/object-inspect/test/global.js +0 -17
  156. package/node_modules/object-inspect/test/has.js +0 -15
  157. package/node_modules/object-inspect/test/holes.js +0 -15
  158. package/node_modules/object-inspect/test/indent-option.js +0 -271
  159. package/node_modules/object-inspect/test/inspect.js +0 -139
  160. package/node_modules/object-inspect/test/lowbyte.js +0 -12
  161. package/node_modules/object-inspect/test/number.js +0 -58
  162. package/node_modules/object-inspect/test/quoteStyle.js +0 -26
  163. package/node_modules/object-inspect/test/toStringTag.js +0 -40
  164. package/node_modules/object-inspect/test/undef.js +0 -12
  165. package/node_modules/object-inspect/test/values.js +0 -261
  166. package/node_modules/object-inspect/test-core-js.js +0 -26
  167. package/node_modules/on-finished/HISTORY.md +0 -98
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "router",
3
3
  "description": "Simple middleware-style router",
4
- "version": "2.2.0",
4
+ "version": "2.3.0",
5
5
  "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6
6
  "contributors": [
7
7
  "Blake Embrey <hello@blakeembrey.com>"
8
8
  ],
9
9
  "license": "MIT",
10
10
  "repository": "pillarjs/router",
11
+ "type": "commonjs",
12
+ "main": "index.js",
13
+ "types": "index.d.ts",
14
+ "funding": {
15
+ "type": "opencollective",
16
+ "url": "https://opencollective.com/express"
17
+ },
11
18
  "dependencies": {
12
19
  "debug": "^4.4.0",
13
20
  "depd": "^2.0.0",
@@ -16,29 +23,37 @@
16
23
  "path-to-regexp": "^8.0.0"
17
24
  },
18
25
  "devDependencies": {
26
+ "@arethetypeswrong/cli": "0.18.5",
27
+ "@tsconfig/node18": "18.2.7",
28
+ "@types/node": "18.19.130",
29
+ "eslint": "^9.0.0",
19
30
  "finalhandler": "^2.1.0",
20
- "mocha": "10.2.0",
31
+ "expect-type": "1.4.0",
32
+ "mocha": "10.8.2",
33
+ "neostandard": "^0.14.1",
21
34
  "nyc": "15.1.0",
22
35
  "run-series": "^1.1.9",
23
- "standard": "^17.1.0",
24
- "supertest": "6.3.3"
36
+ "supertest": "6.3.3",
37
+ "typescript": "5.9.3"
25
38
  },
26
39
  "files": [
27
40
  "lib/",
28
41
  "LICENSE",
29
42
  "HISTORY.md",
30
43
  "README.md",
31
- "index.js"
44
+ "index.js",
45
+ "index.d.ts"
32
46
  ],
33
47
  "engines": {
34
48
  "node": ">= 18"
35
49
  },
36
50
  "scripts": {
37
- "lint": "standard",
38
- "test": "mocha --reporter spec --bail --check-leaks test/",
39
- "test:debug": "mocha --reporter spec --bail --check-leaks test/ --inspect --inspect-brk",
51
+ "lint": "eslint .",
52
+ "test": "mocha --reporter spec --check-leaks test/",
53
+ "test:debug": "mocha --reporter spec --check-leaks test/ --inspect --inspect-brk",
40
54
  "test-ci": "nyc --reporter=lcov --reporter=text npm test",
41
55
  "test-cov": "nyc --reporter=text npm test",
42
- "version": "node scripts/version-history.js && git add HISTORY.md"
56
+ "version": "node scripts/version-history.js && git add HISTORY.md",
57
+ "test-types": "tsc --noEmit && tsc -p test/types/tsconfig.augmentation.json && attw --pack"
43
58
  }
44
59
  }
@@ -22,8 +22,7 @@ can use one of the many wrappers available on npm, like
22
22
 
23
23
  - [Protocol support](#protocol-support)
24
24
  - [Installing](#installing)
25
- - [Opt-in for performance](#opt-in-for-performance)
26
- - [Legacy opt-in for performance](#legacy-opt-in-for-performance)
25
+ - [Legacy opt-in for performance](#legacy-opt-in-for-performance)
27
26
  - [API docs](#api-docs)
28
27
  - [WebSocket compression](#websocket-compression)
29
28
  - [Usage examples](#usage-examples)
@@ -56,39 +55,27 @@ can use one of the many wrappers available on npm, like
56
55
  npm install ws
57
56
  ```
58
57
 
59
- ### Opt-in for performance
58
+ ### Legacy opt-in for performance
60
59
 
61
- [bufferutil][] is an optional module that can be installed alongside the ws
62
- module:
60
+ On older Node.js versions, ws can leverage optional binary modules to optimize
61
+ performance.
63
62
 
64
- ```
65
- npm install --save-optional bufferutil
66
- ```
67
-
68
- This is a binary addon that improves the performance of certain operations such
69
- as masking and unmasking the data payload of the WebSocket frames. Prebuilt
70
- binaries are available for the most popular platforms, so you don't necessarily
71
- need to have a C++ compiler installed on your machine.
72
-
73
- To force ws to not use bufferutil, use the
74
- [`WS_NO_BUFFER_UTIL`](./doc/ws.md#ws_no_buffer_util) environment variable. This
75
- can be useful to enhance security in systems where a user can put a package in
76
- the package search path of an application of another user, due to how the
77
- Node.js resolver algorithm works.
78
-
79
- #### Legacy opt-in for performance
80
-
81
- If you are running on an old version of Node.js (prior to v18.14.0), ws also
82
- supports the [utf-8-validate][] module:
83
-
84
- ```
85
- npm install --save-optional utf-8-validate
86
- ```
63
+ - `npm install --save-optional bufferutil`: Provides binary polyfills for
64
+ [`http.websocketMask()`][] and [`http.websocketUnmask()`][].
65
+ - `npm install --save-optional utf-8-validate`: Provides a binary polyfill for
66
+ [`buffer.isUtf8()`][].
87
67
 
88
- This contains a binary polyfill for [`buffer.isUtf8()`][].
68
+ On newer Node.js versions (v26.12.0 or later for bufferutil, and
69
+ v18.14.0 or later for utf-8-validate) that feature built-in alternatives, these
70
+ modules are not loaded even if installed.
89
71
 
90
- To force ws not to use utf-8-validate, use the
91
- [`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment variable.
72
+ To force ws not to use [bufferutil][] or [utf-8-validate][] on the older Node.js
73
+ versions where they would otherwise be loaded, set the
74
+ [`WS_NO_BUFFER_UTIL`](./doc/ws.md#ws_no_buffer_util) and
75
+ [`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment
76
+ variables. This can be useful to enhance security in systems where a user can
77
+ put a package in the package search path of an application of another user, due
78
+ to how the Node.js resolver algorithm works.
92
79
 
93
80
  ## API docs
94
81
 
@@ -533,6 +520,10 @@ We're using the GitHub [releases][changelog] for changelog entries.
533
520
  [MIT](LICENSE)
534
521
 
535
522
  [`buffer.isutf8()`]: https://nodejs.org/api/buffer.html#bufferisutf8input
523
+ [`http.websocketMask()`]:
524
+ https://nodejs.org/api/http.html#httpwebsocketmasksource-mask-output-offset-length
525
+ [`http.websocketUnmask()`]:
526
+ https://nodejs.org/api/http.html#httpwebsocketunmaskbuffer-mask
536
527
  [bufferutil]: https://github.com/websockets/bufferutil
537
528
  [changelog]: https://github.com/websockets/ws/releases
538
529
  [client-report]: http://websockets.github.io/ws/autobahn/clients/
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { websocketMask, websocketUnmask } = require('http');
4
+
3
5
  const { EMPTY_BUFFER } = require('./constants');
4
6
 
5
7
  const FastBuffer = Buffer[Symbol.species];
@@ -111,8 +113,17 @@ module.exports = {
111
113
  unmask: _unmask
112
114
  };
113
115
 
114
- /* istanbul ignore else */
115
- if (!process.env.WS_NO_BUFFER_UTIL) {
116
+ if (websocketMask) {
117
+ module.exports.mask = function (source, mask, output, offset, length) {
118
+ if (length < 24) _mask(source, mask, output, offset, length);
119
+ else websocketMask(source, mask, output, offset, length);
120
+ };
121
+
122
+ module.exports.unmask = function (buffer, mask) {
123
+ if (buffer.length < 24) _unmask(buffer, mask);
124
+ else websocketUnmask(buffer, mask);
125
+ };
126
+ } /* istanbul ignore else */ else if (!process.env.WS_NO_BUFFER_UTIL) {
116
127
  try {
117
128
  const bufferUtil = require('bufferutil');
118
129
 
@@ -496,6 +496,14 @@ class Receiver extends Writable {
496
496
  }
497
497
  }
498
498
 
499
+ //
500
+ // The mask is a view into the buffer the stream delivered, which is commonly
501
+ // 64 KiB, and it is not needed once the payload above has been unmasked.
502
+ // Leaving it set would pin that whole buffer until the next frame arrives,
503
+ // which on an idle connection can be indefinitely.
504
+ //
505
+ this._mask = undefined;
506
+
499
507
  if (this._opcode > 0x07) {
500
508
  this.controlMessage(data, cb);
501
509
  return;
@@ -153,7 +153,9 @@ class Sender {
153
153
  target.writeUIntBE(dataLength, 4, 6);
154
154
  }
155
155
 
156
- if (!options.mask) return [target, data];
156
+ if (!options.mask) {
157
+ return dataLength ? [target, data] : [target];
158
+ }
157
159
 
158
160
  target[1] |= 0x80;
159
161
  target[offset - 4] = mask[0];
@@ -161,6 +163,7 @@ class Sender {
161
163
  target[offset - 2] = mask[2];
162
164
  target[offset - 1] = mask[3];
163
165
 
166
+ if (!dataLength) return [target];
164
167
  if (skipMasking) return [target, data];
165
168
 
166
169
  if (merge) {
@@ -49,6 +49,8 @@ class WebSocketServer extends EventEmitter {
49
49
  * fragments
50
50
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
51
51
  * size
52
+ * @param {Number} [options.maxPendingAutoPongs=60] The maximum number of
53
+ * pending automatic pongs
52
54
  * @param {Boolean} [options.noServer=false] Enable no server mode
53
55
  * @param {String} [options.path] Accept only connections matching this path
54
56
  * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
@@ -72,6 +74,7 @@ class WebSocketServer extends EventEmitter {
72
74
  maxBufferedChunks: 256 * 1024,
73
75
  maxFragments: 16 * 1024,
74
76
  maxPayload: 100 * 1024 * 1024,
77
+ maxPendingAutoPongs: 60,
75
78
  skipUTF8Validation: false,
76
79
  perMessageDeflate: false,
77
80
  handleProtocols: null,
@@ -6,6 +6,7 @@ const EventEmitter = require('events');
6
6
  const https = require('https');
7
7
  const http = require('http');
8
8
  const net = require('net');
9
+ const querystring = require('querystring');
9
10
  const tls = require('tls');
10
11
  const { randomBytes, createHash } = require('crypto');
11
12
  const { Duplex, Readable } = require('stream');
@@ -98,12 +99,19 @@ class WebSocket extends EventEmitter {
98
99
  }
99
100
  }
100
101
 
101
- initAsClient(this, address, protocols, options);
102
+ options = initAsClient(this, address, protocols, options);
102
103
  } else {
103
- this._autoPong = options.autoPong;
104
- this._closeTimeout = options.closeTimeout;
105
104
  this._isServer = true;
106
105
  }
106
+
107
+ if (options.autoPong) {
108
+ this._autoPong = true;
109
+ this._autoPongComplete = () => autoPongComplete(this);
110
+ this._pendingAutoPongs = 0;
111
+ this._maxPendingAutoPongs = options.maxPendingAutoPongs | 0;
112
+ }
113
+
114
+ this._closeTimeout = options.closeTimeout;
107
115
  }
108
116
 
109
117
  /**
@@ -665,6 +673,8 @@ module.exports = WebSocket;
665
673
  * fragments
666
674
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
667
675
  * size
676
+ * @param {Number} [options.maxPendingAutoPongs=60] The maximum number of
677
+ * pending automatic pongs
668
678
  * @param {Number} [options.maxRedirects=10] The maximum number of redirects
669
679
  * allowed
670
680
  * @param {String} [options.origin] Value of the `Origin` or
@@ -675,6 +685,7 @@ module.exports = WebSocket;
675
685
  * `Sec-WebSocket-Version` header
676
686
  * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
677
687
  * not to skip UTF-8 validation for text and close messages
688
+ * @return {Object} The resolved options object used for initialization
678
689
  * @private
679
690
  */
680
691
  function initAsClient(websocket, address, protocols, options) {
@@ -686,6 +697,7 @@ function initAsClient(websocket, address, protocols, options) {
686
697
  maxBufferedChunks: 256 * 1024,
687
698
  maxFragments: 16 * 1024,
688
699
  maxPayload: 100 * 1024 * 1024,
700
+ maxPendingAutoPongs: 60,
689
701
  skipUTF8Validation: false,
690
702
  perMessageDeflate: true,
691
703
  followRedirects: false,
@@ -702,9 +714,6 @@ function initAsClient(websocket, address, protocols, options) {
702
714
  port: undefined
703
715
  };
704
716
 
705
- websocket._autoPong = opts.autoPong;
706
- websocket._closeTimeout = opts.closeTimeout;
707
-
708
717
  if (!protocolVersions.includes(opts.protocolVersion)) {
709
718
  throw new RangeError(
710
719
  `Unsupported protocol version: ${opts.protocolVersion} ` +
@@ -724,10 +733,9 @@ function initAsClient(websocket, address, protocols, options) {
724
733
  }
725
734
  }
726
735
 
727
- if (parsedUrl.protocol === 'http:') {
728
- parsedUrl.protocol = 'ws:';
729
- } else if (parsedUrl.protocol === 'https:') {
730
- parsedUrl.protocol = 'wss:';
736
+ if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
737
+ parsedUrl = new URL(parsedUrl);
738
+ parsedUrl.protocol = parsedUrl.protocol === 'http:' ? 'ws:' : 'wss:';
731
739
  }
732
740
 
733
741
  websocket._url = parsedUrl.href;
@@ -815,14 +823,22 @@ function initAsClient(websocket, address, protocols, options) {
815
823
  }
816
824
  }
817
825
  if (parsedUrl.username || parsedUrl.password) {
818
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
826
+ const username = querystring.unescape(parsedUrl.username);
827
+ const password = querystring.unescape(parsedUrl.password);
828
+
829
+ opts.auth = `${username}:${password}`;
819
830
  }
820
831
 
821
832
  if (isIpcUrl) {
822
- const parts = opts.path.split(':');
833
+ const i = opts.path.indexOf(':');
823
834
 
824
- opts.socketPath = parts[0];
825
- opts.path = parts[1];
835
+ if (i === -1) {
836
+ opts.socketPath = opts.path;
837
+ opts.path = '';
838
+ } else {
839
+ opts.socketPath = opts.path.slice(0, i);
840
+ opts.path = opts.path.slice(i + 1);
841
+ }
826
842
  }
827
843
 
828
844
  let req;
@@ -1055,6 +1071,8 @@ function initAsClient(websocket, address, protocols, options) {
1055
1071
  } else {
1056
1072
  req.end();
1057
1073
  }
1074
+
1075
+ return opts;
1058
1076
  }
1059
1077
 
1060
1078
  /**
@@ -1183,9 +1201,20 @@ function receiverOnConclude(code, reason) {
1183
1201
  const websocket = this[kWebSocket];
1184
1202
 
1185
1203
  websocket._closeFrameReceived = true;
1186
- websocket._closeMessage = reason;
1187
1204
  websocket._closeCode = code;
1188
1205
 
1206
+ //
1207
+ // The reason is a view into the buffer the socket delivered. Copy it so that
1208
+ // the `WebSocket` does not keep that buffer alive. The copy is not pooled
1209
+ // because a pooled one would keep the pool alive in the same way.
1210
+ //
1211
+ if (reason.length === 0) {
1212
+ websocket._closeMessage = EMPTY_BUFFER;
1213
+ } else {
1214
+ websocket._closeMessage = Buffer.allocUnsafeSlow(reason.length);
1215
+ websocket._closeMessage.set(reason);
1216
+ }
1217
+
1189
1218
  if (websocket._socket[kWebSocket] === undefined) return;
1190
1219
 
1191
1220
  websocket._socket.removeListener('data', socketOnData);
@@ -1262,10 +1291,31 @@ function receiverOnMessage(data, isBinary) {
1262
1291
  function receiverOnPing(data) {
1263
1292
  const websocket = this[kWebSocket];
1264
1293
 
1265
- if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
1294
+ if (websocket._autoPong && websocket.readyState === WebSocket.OPEN) {
1295
+ if (
1296
+ websocket._maxPendingAutoPongs > 0 &&
1297
+ websocket._pendingAutoPongs >= websocket._maxPendingAutoPongs
1298
+ ) {
1299
+ websocket.terminate();
1300
+ } else {
1301
+ websocket._pendingAutoPongs++;
1302
+ websocket.pong(data, !this._isServer, websocket._autoPongComplete);
1303
+ }
1304
+ }
1305
+
1266
1306
  websocket.emit('ping', data);
1267
1307
  }
1268
1308
 
1309
+ /**
1310
+ * The callback for automatic pong responses.
1311
+ *
1312
+ * @param {WebSocket} websocket The WebSocket instance
1313
+ * @private
1314
+ */
1315
+ function autoPongComplete(websocket) {
1316
+ websocket._pendingAutoPongs--;
1317
+ }
1318
+
1269
1319
  /**
1270
1320
  * The listener of the `Receiver` `'pong'` event.
1271
1321
  *
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ws",
3
- "version": "8.22.0",
3
+ "version": "8.23.0",
4
4
  "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
5
5
  "keywords": [
6
6
  "HyBi",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.6.5",
3
+ "version": "4.6.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -140,6 +140,33 @@ test("continue parsing despite array size error", () => {
140
140
  `);
141
141
  });
142
142
 
143
+ test("an upper size bound fails before any element is parsed", () => {
144
+ let parsed = 0;
145
+ const el = z.string().refine(() => ++parsed);
146
+ let refined = 0;
147
+ const schema = z
148
+ .array(el)
149
+ .max(2, "too many")
150
+ .refine(() => ++refined);
151
+ expect(schema.safeParse([1, 2, 3]).error!.issues).toMatchObject([{ code: "too_big", path: [], message: "too many" }]);
152
+ expect(z.array(el).length(2).safeParse(["a", "b", "c"]).error!.issues).toMatchObject([
153
+ { code: "too_big", exact: true },
154
+ ]);
155
+ expect(z.object({ a: z.array(el).max(1) }).safeParse({ a: [1, 2] }).error!.issues).toMatchObject([
156
+ { code: "too_big", path: ["a"] },
157
+ ]);
158
+ expect([parsed, refined]).toEqual([0, 0]);
159
+
160
+ // a check that may rewrite the value ends the gate
161
+ expect(
162
+ z
163
+ .array(z.number())
164
+ .overwrite((a) => a.slice(0, 2))
165
+ .max(2)
166
+ .parse([1, 2, 3])
167
+ ).toEqual([1, 2]);
168
+ });
169
+
143
170
  test("parse should fail given sparse array", () => {
144
171
  const schema = z.array(z.string()).nonempty().min(1).max(3);
145
172
  const result = schema.safeParse(new Array(3));
@@ -97,6 +97,13 @@ test("failing when map is bigger than max() ", () => {
97
97
  expect(result.success).toEqual(false);
98
98
  expect(result.error!.issues.length).toEqual(1);
99
99
  expect(result.error!.issues[0].code).toEqual("too_big");
100
+ const bad = new Map([
101
+ [1, 1],
102
+ [2, 2],
103
+ ]);
104
+ const capped = z.map(z.string(), z.string()).max(1);
105
+ expect(capped.safeParse(bad).error!.issues).toMatchObject([{ code: "too_big" }]);
106
+ expect(capped.safeParse(new Set([1, 2])).error!.issues[0]).toMatchObject({ code: "invalid_type", expected: "map" });
100
107
  });
101
108
 
102
109
  test("failing when map does not match size() ", () => {
@@ -83,6 +83,12 @@ test("failing when set is bigger than max() ", () => {
83
83
  expect(result.success).toEqual(false);
84
84
  expect(result.error!.issues.length).toEqual(1);
85
85
  expect(result.error!.issues[0].code).toEqual("too_big");
86
+ expect(
87
+ z
88
+ .set(z.string())
89
+ .max(1)
90
+ .safeParse(new Set([1, 2])).error!.issues
91
+ ).toMatchObject([{ code: "too_big" }]);
86
92
  });
87
93
 
88
94
  test("failing when set does not match size() ", () => {
@@ -1551,6 +1551,12 @@ function generateNullableCheck(
1551
1551
  return outputVar;
1552
1552
  }
1553
1553
 
1554
+ function generateSizeGate(doc: Doc, schema: SomeType, size: string): void {
1555
+ for (const [max, check] of util.sizeCaps(schema._zod.def.checks)) {
1556
+ doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
1557
+ }
1558
+ }
1559
+
1554
1560
  function generateArrayCheck(
1555
1561
  doc: Doc,
1556
1562
  ctx: CompileContext,
@@ -1560,6 +1566,7 @@ function generateArrayCheck(
1560
1566
  ): string | null {
1561
1567
  const def = schema._zod.def as unknown as { element: SomeType };
1562
1568
  doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
1569
+ generateSizeGate(doc, schema, `${accessor}.length`);
1563
1570
 
1564
1571
  // Build a new array with validated/transformed elements.
1565
1572
  const outputVar = buildsValue ? newVar(ctx) : null;
@@ -2094,6 +2101,7 @@ function generateMapCheck(doc: Doc, ctx: CompileContext, schema: SomeType, acces
2094
2101
  const def = schema._zod.def as unknown as { keyType: SomeType; valueType: SomeType };
2095
2102
 
2096
2103
  doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
2104
+ generateSizeGate(doc, schema, `${accessor}.size`);
2097
2105
 
2098
2106
  const outputVar = newVar(ctx);
2099
2107
  const kVar = newVar(ctx);
@@ -2115,6 +2123,7 @@ function generateSetCheck(doc: Doc, ctx: CompileContext, schema: SomeType, acces
2115
2123
  const def = schema._zod.def as unknown as { valueType: SomeType };
2116
2124
 
2117
2125
  doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
2126
+ generateSizeGate(doc, schema, `${accessor}.size`);
2118
2127
 
2119
2128
  const outputVar = newVar(ctx);
2120
2129
  const valVar = newVar(ctx);
@@ -1844,6 +1844,34 @@ export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$Zod
1844
1844
 
1845
1845
  export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {}
1846
1846
 
1847
+ // an oversized container fails its leading size checks before any element is parsed
1848
+ function capSize(inst: $ZodType, size: (input: any) => number): void {
1849
+ const caps = util.sizeCaps(inst._zod.def.checks);
1850
+ if (!caps.length) return;
1851
+ const cap = Math.min(...caps.map((c) => c[0]));
1852
+ const parse = inst._zod.parse;
1853
+ inst._zod.parse = (payload, ctx) => {
1854
+ const n = size(payload.value);
1855
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
1856
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
1857
+ if (n > max && ch._zod.def.when!(payload)) {
1858
+ const start = payload.issues.length;
1859
+ ch._zod.check(payload as ParsePayload<never>);
1860
+ // the value is still the raw input, so no later check may read it
1861
+ (payload.issues[start] as { continue?: boolean }).continue = false;
1862
+ util.attachSchema(payload.issues, start, inst);
1863
+ return payload;
1864
+ }
1865
+ }
1866
+ }
1867
+ return parse(payload, ctx);
1868
+ };
1869
+ }
1870
+
1871
+ const arraySize = (input: unknown): number => (Array.isArray(input) ? input.length : -1);
1872
+ const mapSize = (input: unknown): number => (input instanceof Map ? input.size : -1);
1873
+ const setSize = (input: unknown): number => (input instanceof Set ? input.size : -1);
1874
+
1847
1875
  function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>, index: number) {
1848
1876
  if (result.issues.length) {
1849
1877
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -1899,6 +1927,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1899
1927
 
1900
1928
  return payload; //handleArrayResultsAsync(parseResults, final);
1901
1929
  };
1930
+ capSize(inst, arraySize);
1902
1931
  });
1903
1932
 
1904
1933
  //////////////////////////////////////////
@@ -3218,8 +3247,11 @@ export type $InferZodRecordInput<
3218
3247
  : Record<core.input<Key> & PropertyKey, core.input<Value>>;
3219
3248
 
3220
3249
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
3221
- extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
3250
+ extends $ZodTypeInternals {
3222
3251
  def: $ZodRecordDef<Key, Value>;
3252
+ // members rather than base type arguments, which TypeScript 7.1 reports as circular for `z.json()`
3253
+ output: $InferZodRecordOutput<Key, Value>;
3254
+ input: $InferZodRecordInput<Key, Value>;
3223
3255
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
3224
3256
  optin?: "optional" | undefined;
3225
3257
  optout?: "optional" | undefined;
@@ -3480,6 +3512,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
3480
3512
  if (proms.length) return Promise.all(proms).then(() => payload);
3481
3513
  return payload;
3482
3514
  };
3515
+ capSize(inst, mapSize);
3483
3516
  });
3484
3517
 
3485
3518
  function handleMapResult(
@@ -3582,6 +3615,7 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
3582
3615
  if (proms.length) return Promise.all(proms).then(() => payload);
3583
3616
  return payload;
3584
3617
  };
3618
+ capSize(inst, setSize);
3585
3619
  });
3586
3620
 
3587
3621
  function handleSetResult(result: ParsePayload, final: ParsePayload<Set<any>>) {
@@ -935,6 +935,19 @@ export function unwrapMessage(message: string | { message: string } | undefined
935
935
  }
936
936
 
937
937
  /* A check holds no link back to the schema it is attached to — the same check instance is shared by every clone of that schema — so the owner is stamped onto the issues a check just raised, at the only point where both are in scope. Runs on the failure path only; `start` is the issue count from before the check ran. */
938
+ /** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
939
+ export function sizeCaps(defChecks: checks.$ZodCheck<never>[] | undefined): [number, checks.$ZodCheck<never>][] {
940
+ const caps: [number, checks.$ZodCheck<never>][] = [];
941
+ for (const ch of defChecks ?? []) {
942
+ const d = ch._zod.def as any;
943
+ // a later check may rewrite the value
944
+ if (!/_(length|size)$|_equals$/.test(d.check)) break;
945
+ const max = d.maximum ?? d.length ?? d.size;
946
+ if (max >= 0) caps.push([max, ch]);
947
+ }
948
+ return caps;
949
+ }
950
+
938
951
  export function attachSchema(issues: errors.$ZodRawIssue[], start: number, inst: schemas.$ZodType): void {
939
952
  for (let i = start; i < issues.length; i++) {
940
953
  (issues[i] as any).schema ??= inst;
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 6,
4
- patch: 5 as number,
4
+ patch: 7 as number,
5
5
  } as const;
@@ -1241,9 +1241,15 @@ function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
1241
1241
  doc.write(`}`);
1242
1242
  return outputVar;
1243
1243
  }
1244
+ function generateSizeGate(doc, schema, size) {
1245
+ for (const [max, check] of util.sizeCaps(schema._zod.def.checks)) {
1246
+ doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
1247
+ }
1248
+ }
1244
1249
  function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
1245
1250
  const def = schema._zod.def;
1246
1251
  doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
1252
+ generateSizeGate(doc, schema, `${accessor}.length`);
1247
1253
  // Build a new array with validated/transformed elements.
1248
1254
  const outputVar = buildsValue ? newVar(ctx) : null;
1249
1255
  const iVar = newVar(ctx);
@@ -1707,6 +1713,7 @@ function literalPropertyKey(ctx, key) {
1707
1713
  function generateMapCheck(doc, ctx, schema, accessor) {
1708
1714
  const def = schema._zod.def;
1709
1715
  doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
1716
+ generateSizeGate(doc, schema, `${accessor}.size`);
1710
1717
  const outputVar = newVar(ctx);
1711
1718
  const kVar = newVar(ctx);
1712
1719
  const valVar = newVar(ctx);
@@ -1723,6 +1730,7 @@ function generateMapCheck(doc, ctx, schema, accessor) {
1723
1730
  function generateSetCheck(doc, ctx, schema, accessor) {
1724
1731
  const def = schema._zod.def;
1725
1732
  doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
1733
+ generateSizeGate(doc, schema, `${accessor}.size`);
1726
1734
  const outputVar = newVar(ctx);
1727
1735
  const valVar = newVar(ctx);
1728
1736
  doc.write(`const ${outputVar} = new Set();`);