@sap/cds-dk 10.2.0 → 10.2.1
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.
- package/CHANGELOG.md +13 -0
- package/bin/bind.js +5 -4
- package/bin/completion/scripts/cds.fish +4 -3
- package/bin/completion/scripts/cds.ps1 +4 -4
- package/bin/completion/scripts/cds.sh +4 -4
- package/bin/completion/scripts/cds.zsh +4 -4
- package/bin/debug.js +3 -3
- package/bin/deploy/index.js +2 -2
- package/bin/deploy/to-hana/hana.js +1 -1
- package/bin/deploy/to-hana/hdiDeployUtil.js +25 -14
- package/bin/up.js +3 -3
- package/bin/version.js +1 -1
- package/bin/watch/vite-watch.js +12 -6
- package/lib/bind/shared.js +1 -1
- package/lib/init/index.js +1 -0
- package/lib/init/projectReader.js +3 -2
- package/lib/init/template/approuter/files/values.yaml.hbs +0 -9
- package/lib/init/template/approuter/files/xs-app.json.hbs +0 -22
- package/lib/init/template/approuter/index.js +8 -9
- package/lib/init/template/html5-repo/index.js +12 -0
- package/lib/init/template/react/files/vite.config.{{extension}}.hbs +2 -3
- package/lib/init/template/react/index.js +1 -3
- package/lib/init/template/sample/files/app/index.html.hbs +18 -0
- package/lib/init/template/sample/index.js +1 -0
- package/lib/init/template/vue/files/vite.config.{{extension}}.hbs +2 -3
- package/lib/init/template/vue/index.js +1 -3
- package/lib/mtx/push.js +7 -1
- package/node_modules/@cap-js/asyncapi/README.md +4 -14
- package/node_modules/@cap-js/asyncapi/cds-plugin.js +12 -0
- package/node_modules/@cap-js/asyncapi/index.js +3 -2
- package/node_modules/@cap-js/asyncapi/lib/compile/components/messages/index.js +4 -2
- package/node_modules/@cap-js/asyncapi/lib/compile/components/schemas/definition.js +11 -1
- package/node_modules/@cap-js/asyncapi/lib/compile/components/schemas/utils.js +16 -0
- package/node_modules/@cap-js/asyncapi/lib/compile/utils.js +4 -3
- package/node_modules/@cap-js/asyncapi/lib/import/importAsyncAPI.js +34 -0
- package/node_modules/@cap-js/asyncapi/lib/import/index.js +18 -0
- package/node_modules/@cap-js/asyncapi/lib/import/message.js +9 -0
- package/node_modules/@cap-js/asyncapi/lib/import/parserContext.js +368 -0
- package/node_modules/@cap-js/asyncapi/lib/import/utils.js +85 -0
- package/node_modules/@cap-js/asyncapi/package.json +89 -1
- package/node_modules/@sap/cds/CHANGELOG.md +10 -0
- package/node_modules/@sap/cds/app/index.js +1 -1
- package/node_modules/@sap/cds/lib/env/schemas/cds-package.js +0 -2
- package/node_modules/@sap/cds/lib/env/schemas/cds-rc.js +3 -3
- package/node_modules/@sap/cds/lib/env/schemas/index.js +4 -4
- package/node_modules/@sap/cds/lib/utils/cds-utils.js +21 -8
- package/node_modules/@sap/cds/libx/_runtime/messaging/common-utils/connections.js +45 -39
- package/node_modules/@sap/cds/libx/odata/ODataAdapter.js +1 -1
- package/node_modules/@sap/cds/libx/queue/TaskRunner.js +22 -5
- package/node_modules/@sap/cds/package.json +1 -1
- package/node_modules/@sap/cds-mtxs/CHANGELOG.md +8 -0
- package/node_modules/@sap/cds-mtxs/package.json +1 -1
- package/node_modules/@sap/cds-mtxs/srv/extensibility-service.js +57 -41
- package/node_modules/@sap/cds-mtxs/srv/jobs-service.js +27 -12
- package/node_modules/@sap/cds-mtxs/srv/plugins/hana.js +31 -25
- package/node_modules/body-parser/README.md +17 -13
- package/node_modules/body-parser/lib/read.js +74 -57
- package/node_modules/body-parser/lib/types/json.js +11 -11
- package/node_modules/body-parser/lib/types/urlencoded.js +5 -5
- package/node_modules/body-parser/lib/utils.js +0 -15
- package/node_modules/body-parser/package.json +7 -12
- package/node_modules/encodeurl/README.md +14 -0
- package/node_modules/encodeurl/index.js +5 -10
- package/node_modules/encodeurl/package.json +10 -6
- package/node_modules/on-finished/index.js +14 -2
- package/node_modules/on-finished/package.json +11 -7
- package/node_modules/qs/.editorconfig +1 -1
- package/node_modules/qs/CHANGELOG.md +87 -22
- package/node_modules/qs/README.md +63 -10
- package/node_modules/qs/dist/qs.js +17 -17
- package/node_modules/qs/eslint.config.mjs +61 -50
- package/node_modules/qs/lib/formats.js +7 -2
- package/node_modules/qs/lib/parse.js +29 -10
- package/node_modules/qs/lib/stringify.js +5 -3
- package/node_modules/qs/lib/utils.js +28 -9
- package/node_modules/qs/package.json +6 -6
- package/node_modules/qs/test/parse.js +335 -2
- package/node_modules/qs/test/stringify.js +222 -0
- package/node_modules/qs/test/utils.js +61 -3
- package/node_modules/semver/classes/range.js +2 -2
- package/node_modules/semver/internal/constants.js +30 -0
- package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/semver/package.json +1 -1
- package/node_modules/ws/README.md +21 -29
- package/node_modules/ws/lib/buffer-util.js +13 -2
- package/node_modules/ws/lib/sender.js +4 -1
- package/node_modules/ws/lib/websocket.js +8 -3
- package/node_modules/ws/package.json +1 -1
- package/package.json +1 -1
- package/node_modules/on-finished/HISTORY.md +0 -98
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
// Reproduce safeRe[COMPARATORTRIM] replacement boundaries, not version
|
|
5
|
+
// validation. Each end-index finder returns an exclusive end, or its start
|
|
6
|
+
// on no match.
|
|
7
|
+
// Positions count from zero. An end of 3 means characters 0, 1, and 2 were read;
|
|
8
|
+
// range.slice(start, end) gives the matched text, not a converted number.
|
|
9
|
+
const {
|
|
10
|
+
MAX_LENGTH,
|
|
11
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
12
|
+
WHITESPACE_CHARACTERS,
|
|
13
|
+
} = require('./constants')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Remembers the last two rows of digits so their characters need not be reread.
|
|
17
|
+
* Positions start at -1 until a row has been found.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {object} DigitRunCache
|
|
20
|
+
* @property {number} start The first character of the most recently found row.
|
|
21
|
+
* @property {number} end The position after that row's last character.
|
|
22
|
+
* @property {number} previousStart The first character of the previous row.
|
|
23
|
+
* @property {number} previousEnd The position after the previous row.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// One entry per UTF-16 code unit keeps membership checks constant-time.
|
|
27
|
+
const whitespace = new Uint8Array(0x10000)
|
|
28
|
+
for (const char of WHITESPACE_CHARACTERS) {
|
|
29
|
+
whitespace[char.charCodeAt(0)] = 1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks whether a character is whitespace, like a space, tab, or newline.
|
|
34
|
+
* Looking past the end of the string returns false.
|
|
35
|
+
*
|
|
36
|
+
* @param {string|undefined} char One character, or undefined past the string's end.
|
|
37
|
+
* @returns {boolean} Whether the character is whitespace.
|
|
38
|
+
* @example isWhitespace(' ') // true
|
|
39
|
+
* @example isWhitespace('1') // false
|
|
40
|
+
*/
|
|
41
|
+
const isWhitespace = char =>
|
|
42
|
+
char !== undefined && whitespace[char.charCodeAt(0)] === 1
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks for v, =, or whitespace before the version number.
|
|
46
|
+
* These are historical version prefixes, not range operators:
|
|
47
|
+
* < and > are handled separately, as are tilde and caret ranges.
|
|
48
|
+
*
|
|
49
|
+
* @param {string|undefined} char One character to check.
|
|
50
|
+
* @returns {boolean} Whether the character can belong to a version prefix.
|
|
51
|
+
* @example isVersionPrefix('=') // true
|
|
52
|
+
* @example isVersionPrefix('>') // false
|
|
53
|
+
*/
|
|
54
|
+
const isVersionPrefix = char =>
|
|
55
|
+
char === 'v' ||
|
|
56
|
+
char === '=' ||
|
|
57
|
+
isWhitespace(char)
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Checks whether a character is one of the digits 0 through 9.
|
|
61
|
+
*
|
|
62
|
+
* @param {string|undefined} char One character to check.
|
|
63
|
+
* @returns {boolean} Whether the character is an ASCII digit.
|
|
64
|
+
* @example isDigit('7') // true
|
|
65
|
+
* @example isDigit('.') // false
|
|
66
|
+
*/
|
|
67
|
+
const isDigit = char => char !== undefined && char >= '0' && char <= '9'
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether a character is an English letter, uppercase or lowercase.
|
|
71
|
+
*
|
|
72
|
+
* @param {string|undefined} char One character to check.
|
|
73
|
+
* @returns {boolean} Whether the character is an ASCII letter.
|
|
74
|
+
* @example isLetter('b') // true
|
|
75
|
+
* @example isLetter('7') // false
|
|
76
|
+
*/
|
|
77
|
+
const isLetter = char =>
|
|
78
|
+
char !== undefined && (
|
|
79
|
+
(char >= 'a' && char <= 'z') ||
|
|
80
|
+
(char >= 'A' && char <= 'Z')
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks for a letter, digit, or hyphen: the characters allowed inside
|
|
85
|
+
* prerelease and build names such as beta-1.
|
|
86
|
+
*
|
|
87
|
+
* @param {string|undefined} char One character to check.
|
|
88
|
+
* @returns {boolean} Whether the character can be part of an identifier.
|
|
89
|
+
* @example isIdentifierCharacter('-') // true
|
|
90
|
+
* @example isIdentifierCharacter('.') // false; dots separate identifiers
|
|
91
|
+
*/
|
|
92
|
+
const isIdentifierCharacter = char => isDigit(char) || isLetter(char) || char === '-'
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Checks whether a version component can begin here: with a digit or
|
|
96
|
+
* a wildcard such as x, X, or *.
|
|
97
|
+
*
|
|
98
|
+
* @param {string|undefined} char One character to check.
|
|
99
|
+
* @returns {boolean} Whether a number or wildcard can start with this character.
|
|
100
|
+
* @example isVersionStart('x') // true
|
|
101
|
+
* @example isVersionStart('v') // false; v belongs to the prefix
|
|
102
|
+
*/
|
|
103
|
+
const isVersionStart = char =>
|
|
104
|
+
isDigit(char) ||
|
|
105
|
+
char === 'x' ||
|
|
106
|
+
char === 'X' ||
|
|
107
|
+
char === '*'
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Finds the end of a row of digits, but returns no more than limit digits.
|
|
111
|
+
* Remembers the last two rows so looking at them again does not reread them.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} range The text to read; it is not changed.
|
|
114
|
+
* @param {number} start The position of the first character to check.
|
|
115
|
+
* @param {number} limit The most digit characters the returned match can include.
|
|
116
|
+
* @param {DigitRunCache} digitRuns Shared cache of digit-run positions, updated in place.
|
|
117
|
+
* @returns {number} The position after the matched digits, or start if none match.
|
|
118
|
+
* @example findDigitsEndIndex('123abc', 0, 10, digitRuns) // 3, pointing at a
|
|
119
|
+
* @example findDigitsEndIndex('123abc', 0, 2, digitRuns) // 2, pointing at the unread 3
|
|
120
|
+
*/
|
|
121
|
+
const findDigitsEndIndex = (range, start, limit, digitRuns) => {
|
|
122
|
+
if (!isDigit(range[start])) {
|
|
123
|
+
return start
|
|
124
|
+
}
|
|
125
|
+
if (start >= digitRuns.start && start < digitRuns.end) {
|
|
126
|
+
return Math.min(start + limit, digitRuns.end)
|
|
127
|
+
}
|
|
128
|
+
if (start >= digitRuns.previousStart && start < digitRuns.previousEnd) {
|
|
129
|
+
return Math.min(start + limit, digitRuns.previousEnd)
|
|
130
|
+
}
|
|
131
|
+
let end = start + 1
|
|
132
|
+
while (isDigit(range[end])) {
|
|
133
|
+
end++
|
|
134
|
+
}
|
|
135
|
+
// A failed full version can rewind from its second run to its first.
|
|
136
|
+
digitRuns.previousStart = digitRuns.start
|
|
137
|
+
digitRuns.previousEnd = digitRuns.end
|
|
138
|
+
digitRuns.start = start
|
|
139
|
+
digitRuns.end = end
|
|
140
|
+
return Math.min(start + limit, end)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Reads a number using the old regex's length and leading-zero rules.
|
|
145
|
+
* Strict mode reads just the first zero in 012; loose mode can read all three.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} range The text to read; it is not changed.
|
|
148
|
+
* @param {number} start The position where the number should begin.
|
|
149
|
+
* @param {boolean} loose Whether to allow leading zeros.
|
|
150
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
151
|
+
* @returns {number} The position after the matched digits, not their numeric value.
|
|
152
|
+
* @example findVersionNumberEndIndex('012', 0, false, digitRuns) // 1
|
|
153
|
+
* @example findVersionNumberEndIndex('012', 0, true, digitRuns) // 3
|
|
154
|
+
*/
|
|
155
|
+
const findVersionNumberEndIndex = (range, start, loose, digitRuns) => {
|
|
156
|
+
if (!loose && range[start] === '0') {
|
|
157
|
+
return start + 1
|
|
158
|
+
}
|
|
159
|
+
// Strict syntax allows an initial nonzero digit plus MAX_LENGTH digits.
|
|
160
|
+
return findDigitsEndIndex(range, start, loose ? MAX_LENGTH : MAX_LENGTH + 1, digitRuns)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Reads one piece of a prerelease name, such as beta or 1 in beta.1.
|
|
165
|
+
* Tries the letter-or-hyphen form first, then the number-only form.
|
|
166
|
+
*
|
|
167
|
+
* @param {string} range The text to read; it is not changed.
|
|
168
|
+
* @param {number} start The position where the identifier should begin.
|
|
169
|
+
* @param {boolean} loose Whether numeric identifiers may have leading zeros.
|
|
170
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
171
|
+
* @returns {number} The position after the identifier, or start if none matches.
|
|
172
|
+
* @example findPrereleaseIdentifierEndIndex('beta.1', 0, false, digitRuns) // 4, at the dot
|
|
173
|
+
* @example findPrereleaseIdentifierEndIndex('001beta', 0, false, digitRuns) // 7
|
|
174
|
+
*/
|
|
175
|
+
const findPrereleaseIdentifierEndIndex = (range, start, loose, digitRuns) => {
|
|
176
|
+
const digitsEnd = findDigitsEndIndex(range, start, MAX_LENGTH, digitRuns)
|
|
177
|
+
// The legacy regex tries a nonnumeric identifier before a numeric one.
|
|
178
|
+
if (isLetter(range[digitsEnd]) || range[digitsEnd] === '-') {
|
|
179
|
+
let end = digitsEnd + 1
|
|
180
|
+
const limit = end + MAX_SAFE_BUILD_LENGTH
|
|
181
|
+
while (end < limit && isIdentifierCharacter(range[end])) {
|
|
182
|
+
end++
|
|
183
|
+
}
|
|
184
|
+
return end
|
|
185
|
+
}
|
|
186
|
+
return findVersionNumberEndIndex(range, start, loose, digitRuns)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Reads a prerelease suffix such as -beta.1, one dot-separated piece at a time.
|
|
191
|
+
* Loose mode also allows the name without its opening hyphen.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} range The text to read; it is not changed.
|
|
194
|
+
* @param {number} start The position where the suffix should begin, including -.
|
|
195
|
+
* @param {boolean} loose Whether the opening hyphen is optional and zeros allowed.
|
|
196
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
197
|
+
* @returns {number} The position after the matched suffix, or start if absent.
|
|
198
|
+
* @example findPrereleaseEndIndex('-beta.1+sha', 0, false, digitRuns) // 7, at the plus
|
|
199
|
+
* @example findPrereleaseEndIndex('beta', 0, false, digitRuns) // 0; no opening hyphen
|
|
200
|
+
*/
|
|
201
|
+
const findPrereleaseEndIndex = (range, start, loose, digitRuns) => {
|
|
202
|
+
const hyphen = range[start] === '-'
|
|
203
|
+
if (!loose && !hyphen) {
|
|
204
|
+
return start
|
|
205
|
+
}
|
|
206
|
+
const identifierStart = start + (hyphen ? 1 : 0)
|
|
207
|
+
let end = findPrereleaseIdentifierEndIndex(range, identifierStart, loose, digitRuns)
|
|
208
|
+
if (end === identifierStart) {
|
|
209
|
+
if (!loose || !hyphen) {
|
|
210
|
+
return start
|
|
211
|
+
}
|
|
212
|
+
// In loose syntax, a lone hyphen can itself be the identifier.
|
|
213
|
+
end = findPrereleaseIdentifierEndIndex(range, start, loose, digitRuns)
|
|
214
|
+
}
|
|
215
|
+
while (range[end] === '.') {
|
|
216
|
+
const next = findPrereleaseIdentifierEndIndex(range, end + 1, loose, digitRuns)
|
|
217
|
+
if (next === end + 1) {
|
|
218
|
+
break
|
|
219
|
+
}
|
|
220
|
+
end = next
|
|
221
|
+
}
|
|
222
|
+
return end
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Reads one build-name piece, such as sha or 123 in +sha.123.
|
|
227
|
+
* Stops at a disallowed character or the old regex's length limit.
|
|
228
|
+
*
|
|
229
|
+
* @param {string} range The text to read; it is not changed.
|
|
230
|
+
* @param {number} start The position where the identifier should begin.
|
|
231
|
+
* @returns {number} The position after the identifier, or start if none matches.
|
|
232
|
+
* @example findBuildIdentifierEndIndex('sha.123', 0) // 3, at the dot
|
|
233
|
+
* @example findBuildIdentifierEndIndex('001', 0) // 3; leading zeros are allowed
|
|
234
|
+
*/
|
|
235
|
+
const findBuildIdentifierEndIndex = (range, start) => {
|
|
236
|
+
let end = start
|
|
237
|
+
while (end - start < MAX_SAFE_BUILD_LENGTH && isIdentifierCharacter(range[end])) {
|
|
238
|
+
end++
|
|
239
|
+
}
|
|
240
|
+
return end
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Reads optional build metadata such as +sha.123.
|
|
245
|
+
* Leaves the position unchanged if there is no plus sign followed by a name.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} range The text to read; it is not changed.
|
|
248
|
+
* @param {number} start The position where the opening + should be.
|
|
249
|
+
* @returns {number} The position after the matched metadata, or start if absent.
|
|
250
|
+
* @example findBuildEndIndex('+sha.123 <2', 0) // 8, at the space
|
|
251
|
+
* @example findBuildEndIndex('+', 0) // 0; a plus sign alone is not a match
|
|
252
|
+
*/
|
|
253
|
+
const findBuildEndIndex = (range, start) => {
|
|
254
|
+
if (range[start] !== '+') {
|
|
255
|
+
return start
|
|
256
|
+
}
|
|
257
|
+
let end = findBuildIdentifierEndIndex(range, start + 1)
|
|
258
|
+
if (end === start + 1) {
|
|
259
|
+
return start
|
|
260
|
+
}
|
|
261
|
+
while (range[end] === '.') {
|
|
262
|
+
const next = findBuildIdentifierEndIndex(range, end + 1)
|
|
263
|
+
if (next === end + 1) {
|
|
264
|
+
break
|
|
265
|
+
}
|
|
266
|
+
end = next
|
|
267
|
+
}
|
|
268
|
+
return end
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Reads three numbers separated by dots, then any prerelease and build suffixes.
|
|
273
|
+
* Uses loose rules, so forms such as 01.02.03beta can match here.
|
|
274
|
+
*
|
|
275
|
+
* @param {string} range The text to read; it is not changed.
|
|
276
|
+
* @param {number} start The position of the first number, after any prefix.
|
|
277
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
278
|
+
* @returns {number} The position after the version match, or start if none matches.
|
|
279
|
+
* @example findLooseFullVersionEndIndex('1.2.3-beta+sha <2', 0, digitRuns) // 14
|
|
280
|
+
* @example findLooseFullVersionEndIndex('1.2', 0, digitRuns) // 0; needs three numbers
|
|
281
|
+
*/
|
|
282
|
+
const findLooseFullVersionEndIndex = (range, start, digitRuns) => {
|
|
283
|
+
let end = start
|
|
284
|
+
for (let component = 0; component < 3; component++) {
|
|
285
|
+
const next = findVersionNumberEndIndex(range, end, true, digitRuns)
|
|
286
|
+
if (next === end) {
|
|
287
|
+
return start
|
|
288
|
+
}
|
|
289
|
+
end = next
|
|
290
|
+
if (component < 2) {
|
|
291
|
+
if (range[end] !== '.') {
|
|
292
|
+
return start
|
|
293
|
+
}
|
|
294
|
+
end++
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const prereleaseEnd = findPrereleaseEndIndex(range, end, true, digitRuns)
|
|
298
|
+
return findBuildEndIndex(range, prereleaseEnd)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Reads one component of a partial or wildcard version, such as 2 or x in 2.x.
|
|
303
|
+
* Numbers use strict leading-zero rules; wildcards take up one character.
|
|
304
|
+
*
|
|
305
|
+
* @param {string} range The text to read; it is not changed.
|
|
306
|
+
* @param {number} start The position where the component should begin.
|
|
307
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
308
|
+
* @returns {number} The position after the component, or start if none matches.
|
|
309
|
+
* @example findPartialVersionComponentEndIndex('2.x', 0, digitRuns) // 1, at the dot
|
|
310
|
+
* @example findPartialVersionComponentEndIndex('2.x', 2, digitRuns) // 3, after x
|
|
311
|
+
*/
|
|
312
|
+
const findPartialVersionComponentEndIndex = (range, start, digitRuns) => {
|
|
313
|
+
if (isDigit(range[start])) {
|
|
314
|
+
return findVersionNumberEndIndex(range, start, false, digitRuns)
|
|
315
|
+
}
|
|
316
|
+
return isVersionStart(range[start]) ? start + 1 : start
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Reads up to three components, allowing forms such as 1, 1.2, or 1.x.
|
|
321
|
+
* After the third component, also reads any strict prerelease and build suffixes.
|
|
322
|
+
*
|
|
323
|
+
* @param {string} range The text to read; it is not changed.
|
|
324
|
+
* @param {number} start The position of a number or wildcard, after any prefix.
|
|
325
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
326
|
+
* @returns {number} The position after the matched version text.
|
|
327
|
+
* @example findPartialVersionEndIndex('1.x <2', 0, digitRuns) // 3, at the space
|
|
328
|
+
* @example findPartialVersionEndIndex('1.', 0, digitRuns) // 1; the trailing dot is unread
|
|
329
|
+
*/
|
|
330
|
+
const findPartialVersionEndIndex = (range, start, digitRuns) => {
|
|
331
|
+
let end = findPartialVersionComponentEndIndex(range, start, digitRuns)
|
|
332
|
+
for (let component = 0; component < 2; component++) {
|
|
333
|
+
if (range[end] !== '.') {
|
|
334
|
+
return end
|
|
335
|
+
}
|
|
336
|
+
const next = findPartialVersionComponentEndIndex(range, end + 1, digitRuns)
|
|
337
|
+
if (next === end + 1) {
|
|
338
|
+
return end
|
|
339
|
+
}
|
|
340
|
+
end = next
|
|
341
|
+
}
|
|
342
|
+
const prereleaseEnd = findPrereleaseEndIndex(range, end, false, digitRuns)
|
|
343
|
+
return findBuildEndIndex(range, prereleaseEnd)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Finds where a version match ends, without deciding whether the range is valid.
|
|
348
|
+
* Tries a loose full version first, then a partial or wildcard version, just
|
|
349
|
+
* like the old regex's LOOSEPLAIN and XRANGEPLAIN alternatives.
|
|
350
|
+
*
|
|
351
|
+
* @param {string} range The text to read; it is not changed.
|
|
352
|
+
* @param {number} start The position of a number or wildcard, after any prefix.
|
|
353
|
+
* @param {DigitRunCache} digitRuns Shared digit-run cache, updated as needed.
|
|
354
|
+
* @returns {number} The position where scanning the next candidate can resume.
|
|
355
|
+
* @example findVersionEndIndex('1.2.3 <2', 0, digitRuns) // 5, at the space
|
|
356
|
+
* @example findVersionEndIndex('1.x <2', 0, digitRuns) // 3, at the space
|
|
357
|
+
*/
|
|
358
|
+
const findVersionEndIndex = (range, start, digitRuns) => {
|
|
359
|
+
const fullVersionEnd = findLooseFullVersionEndIndex(range, start, digitRuns)
|
|
360
|
+
return fullVersionEnd !== start
|
|
361
|
+
? fullVersionEnd
|
|
362
|
+
: findPartialVersionEndIndex(range, start, digitRuns)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Finds the one whitespace character the old replacement would remove.
|
|
367
|
+
* Keeps leading whitespace, skips an optional operator, and checks immediately
|
|
368
|
+
* after it. Returns -1 if there is nothing to remove.
|
|
369
|
+
*
|
|
370
|
+
* @param {string} range The text containing a candidate already found by the caller.
|
|
371
|
+
* @param {number} matchStart The candidate's position, including leading whitespace.
|
|
372
|
+
* @returns {number} The position of the removable whitespace, or -1 if absent.
|
|
373
|
+
* @example findRemovableWhitespaceIndex(' > 1', 0) // 2; keep the space at position 0
|
|
374
|
+
* @example findRemovableWhitespaceIndex('>1', 0) // -1
|
|
375
|
+
*/
|
|
376
|
+
const findRemovableWhitespaceIndex = (range, matchStart) => {
|
|
377
|
+
let position = matchStart
|
|
378
|
+
if (isWhitespace(range[position])) {
|
|
379
|
+
position++
|
|
380
|
+
}
|
|
381
|
+
if (range[position] === '<' || range[position] === '>') {
|
|
382
|
+
position++
|
|
383
|
+
}
|
|
384
|
+
if (range[position] === '=') {
|
|
385
|
+
position++
|
|
386
|
+
}
|
|
387
|
+
return isWhitespace(range[position]) ? position : -1
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Joins an operator to its version, turning > 1.2.3 into >1.2.3.
|
|
392
|
+
* Copies everything else according to the old regex's matching rules.
|
|
393
|
+
* Moves forward through prefixes and whole versions to avoid repeatedly
|
|
394
|
+
* searching the same characters on long inputs.
|
|
395
|
+
*
|
|
396
|
+
* @param {string} range The range text to process; the original string is unchanged.
|
|
397
|
+
* @returns {string} The range with matched operator whitespace removed.
|
|
398
|
+
* @example trimComparatorWhitespace('> 1.2.3 < 2') // '>1.2.3 <2'
|
|
399
|
+
* @example trimComparatorWhitespace('> invalid') // '> invalid'
|
|
400
|
+
*/
|
|
401
|
+
const trimComparatorWhitespace = range => {
|
|
402
|
+
let result = ''
|
|
403
|
+
let copyFrom = 0
|
|
404
|
+
let cursor = 0
|
|
405
|
+
const digitRuns = { start: -1, end: -1, previousStart: -1, previousEnd: -1 }
|
|
406
|
+
|
|
407
|
+
while (cursor < range.length) {
|
|
408
|
+
const matchStart = cursor
|
|
409
|
+
if (range[cursor] === '<' || range[cursor] === '>') {
|
|
410
|
+
cursor++
|
|
411
|
+
} else if (!isVersionPrefix(range[cursor]) && !isVersionStart(range[cursor])) {
|
|
412
|
+
cursor++
|
|
413
|
+
continue
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Consume a v/=/whitespace run once, even when no version follows it.
|
|
417
|
+
while (cursor < range.length && isVersionPrefix(range[cursor])) {
|
|
418
|
+
cursor++
|
|
419
|
+
}
|
|
420
|
+
if (!isVersionStart(range[cursor])) {
|
|
421
|
+
continue
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const whitespacePosition = findRemovableWhitespaceIndex(range, matchStart)
|
|
425
|
+
if (whitespacePosition !== -1) {
|
|
426
|
+
result += range.slice(copyFrom, whitespacePosition)
|
|
427
|
+
copyFrom = whitespacePosition + 1
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Skip the entire match, so a prerelease's trailing v cannot be
|
|
431
|
+
// reconsidered as the prefix of another version.
|
|
432
|
+
cursor = findVersionEndIndex(range, cursor, digitRuns)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return result + range.slice(copyFrom)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
module.exports = trimComparatorWhitespace
|
|
@@ -56,39 +56,27 @@ can use one of the many wrappers available on npm, like
|
|
|
56
56
|
npm install ws
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Legacy opt-in for performance
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
On older Node.js versions, ws can leverage optional binary modules to optimize
|
|
62
|
+
performance.
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
```
|
|
64
|
+
- `npm install --save-optional bufferutil`: Provides binary polyfills for
|
|
65
|
+
[`http.websocketMask()`][] and [`http.websocketUnmask()`][].
|
|
66
|
+
- `npm install --save-optional utf-8-validate`: Provides a binary polyfill for
|
|
67
|
+
[`buffer.isUtf8()`][].
|
|
87
68
|
|
|
88
|
-
|
|
69
|
+
On newer Node.js versions (v27.0.0-alpha.0.0.0 or later for bufferutil, and
|
|
70
|
+
v18.14.0 or later for utf-8-validate) that feature built-in alternatives, these
|
|
71
|
+
modules are not loaded even if installed.
|
|
89
72
|
|
|
90
|
-
To force ws not to use utf-8-validate
|
|
91
|
-
|
|
73
|
+
To force ws not to use [bufferutil][] or [utf-8-validate][] on the older Node.js
|
|
74
|
+
versions where they would otherwise be loaded, set the
|
|
75
|
+
[`WS_NO_BUFFER_UTIL`](./doc/ws.md#ws_no_buffer_util) and
|
|
76
|
+
[`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment
|
|
77
|
+
variables. This can be useful to enhance security in systems where a user can
|
|
78
|
+
put a package in the package search path of an application of another user, due
|
|
79
|
+
to how the Node.js resolver algorithm works.
|
|
92
80
|
|
|
93
81
|
## API docs
|
|
94
82
|
|
|
@@ -533,6 +521,10 @@ We're using the GitHub [releases][changelog] for changelog entries.
|
|
|
533
521
|
[MIT](LICENSE)
|
|
534
522
|
|
|
535
523
|
[`buffer.isutf8()`]: https://nodejs.org/api/buffer.html#bufferisutf8input
|
|
524
|
+
[`http.websocketMask()`]:
|
|
525
|
+
https://nodejs.org/api/http.html#httpwebsocketmasksource-mask-output-offset-length
|
|
526
|
+
[`http.websocketUnmask()`]:
|
|
527
|
+
https://nodejs.org/api/http.html#httpwebsocketunmaskbuffer-mask
|
|
536
528
|
[bufferutil]: https://github.com/websockets/bufferutil
|
|
537
529
|
[changelog]: https://github.com/websockets/ws/releases
|
|
538
530
|
[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
|
-
|
|
115
|
-
|
|
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
|
|
|
@@ -153,7 +153,9 @@ class Sender {
|
|
|
153
153
|
target.writeUIntBE(dataLength, 4, 6);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
if (!options.mask)
|
|
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) {
|
|
@@ -819,10 +819,15 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
819
819
|
}
|
|
820
820
|
|
|
821
821
|
if (isIpcUrl) {
|
|
822
|
-
const
|
|
822
|
+
const i = opts.path.indexOf(':');
|
|
823
823
|
|
|
824
|
-
|
|
825
|
-
|
|
824
|
+
if (i === -1) {
|
|
825
|
+
opts.socketPath = opts.path;
|
|
826
|
+
opts.path = '';
|
|
827
|
+
} else {
|
|
828
|
+
opts.socketPath = opts.path.slice(0, i);
|
|
829
|
+
opts.path = opts.path.slice(i + 1);
|
|
830
|
+
}
|
|
826
831
|
}
|
|
827
832
|
|
|
828
833
|
let req;
|
package/package.json
CHANGED