cdk-common 2.0.1260 → 2.0.1261

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 (34) hide show
  1. package/.jsii +2 -2
  2. package/lib/main.js +1 -1
  3. package/node_modules/fast-uri/.github/workflows/ci.yml +45 -2
  4. package/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +5 -1
  5. package/node_modules/fast-uri/LICENSE +3 -1
  6. package/node_modules/fast-uri/README.md +37 -24
  7. package/node_modules/fast-uri/benchmark/benchmark.mjs +159 -0
  8. package/node_modules/fast-uri/benchmark/equal.mjs +51 -0
  9. package/node_modules/fast-uri/benchmark/non-simple-domain.mjs +22 -0
  10. package/node_modules/fast-uri/benchmark/package.json +17 -0
  11. package/node_modules/fast-uri/benchmark/string-array-to-hex-stripped.mjs +24 -0
  12. package/node_modules/fast-uri/benchmark/ws-is-secure.mjs +65 -0
  13. package/node_modules/fast-uri/index.js +95 -58
  14. package/node_modules/fast-uri/lib/schemes.js +160 -81
  15. package/node_modules/fast-uri/lib/utils.js +214 -122
  16. package/node_modules/fast-uri/package.json +7 -6
  17. package/node_modules/fast-uri/test/ajv.test.js +7 -3
  18. package/node_modules/fast-uri/test/equal.test.js +7 -2
  19. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +501 -0
  20. package/node_modules/fast-uri/test/fixtures/uri-js-serialize.json +120 -0
  21. package/node_modules/fast-uri/test/parse.test.js +31 -31
  22. package/node_modules/fast-uri/test/resolve.test.js +52 -49
  23. package/node_modules/fast-uri/test/rfc-3986.test.js +90 -0
  24. package/node_modules/fast-uri/test/serialize.test.js +55 -47
  25. package/node_modules/fast-uri/test/uri-js-compatibility.test.js +33 -0
  26. package/node_modules/fast-uri/test/uri-js.test.js +230 -230
  27. package/node_modules/fast-uri/test/util.test.js +23 -8
  28. package/node_modules/fast-uri/tsconfig.json +9 -0
  29. package/node_modules/fast-uri/types/index.d.ts +7 -0
  30. package/package.json +1 -1
  31. package/node_modules/fast-uri/benchmark.js +0 -105
  32. package/node_modules/fast-uri/lib/scopedChars.js +0 -30
  33. package/node_modules/fast-uri/test/.gitkeep +0 -0
  34. package/node_modules/fast-uri/test/compatibility.test.js +0 -131
@@ -1,61 +1,99 @@
1
1
  'use strict'
2
2
 
3
- const { HEX } = require('./scopedChars')
3
+ /** @type {(value: string) => boolean} */
4
+ const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu)
4
5
 
5
- const IPV4_REG = /^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u
6
+ /** @type {(value: string) => boolean} */
7
+ const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u)
6
8
 
7
- function normalizeIPv4 (host) {
8
- if (findToken(host, '.') < 3) { return { host, isIPV4: false } }
9
- const matches = host.match(IPV4_REG) || []
10
- const [address] = matches
11
- if (address) {
12
- return { host: stripLeadingZeros(address, '.'), isIPV4: true }
13
- } else {
14
- return { host, isIPV4: false }
9
+ /**
10
+ * @param {Array<string>} input
11
+ * @returns {string}
12
+ */
13
+ function stringArrayToHexStripped (input) {
14
+ let acc = ''
15
+ let code = 0
16
+ let i = 0
17
+
18
+ for (i = 0; i < input.length; i++) {
19
+ code = input[i].charCodeAt(0)
20
+ if (code === 48) {
21
+ continue
22
+ }
23
+ if (!((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))) {
24
+ return ''
25
+ }
26
+ acc += input[i]
27
+ break
28
+ }
29
+
30
+ for (i += 1; i < input.length; i++) {
31
+ code = input[i].charCodeAt(0)
32
+ if (!((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))) {
33
+ return ''
34
+ }
35
+ acc += input[i]
15
36
  }
37
+ return acc
16
38
  }
17
39
 
18
40
  /**
19
- * @param {string[]} input
20
- * @param {boolean} [keepZero=false]
21
- * @returns {string|undefined}
41
+ * @typedef {Object} GetIPV6Result
42
+ * @property {boolean} error - Indicates if there was an error parsing the IPv6 address.
43
+ * @property {string} address - The parsed IPv6 address.
44
+ * @property {string} [zone] - The zone identifier, if present.
22
45
  */
23
- function stringArrayToHexStripped (input, keepZero = false) {
24
- let acc = ''
25
- let strip = true
26
- for (const c of input) {
27
- if (HEX[c] === undefined) return undefined
28
- if (c !== '0' && strip === true) strip = false
29
- if (!strip) acc += c
46
+
47
+ /**
48
+ * @param {string} value
49
+ * @returns {boolean}
50
+ */
51
+ const nonSimpleDomain = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u)
52
+
53
+ /**
54
+ * @param {Array<string>} buffer
55
+ * @returns {boolean}
56
+ */
57
+ function consumeIsZone (buffer) {
58
+ buffer.length = 0
59
+ return true
60
+ }
61
+
62
+ /**
63
+ * @param {Array<string>} buffer
64
+ * @param {Array<string>} address
65
+ * @param {GetIPV6Result} output
66
+ * @returns {boolean}
67
+ */
68
+ function consumeHextets (buffer, address, output) {
69
+ if (buffer.length) {
70
+ const hex = stringArrayToHexStripped(buffer)
71
+ if (hex !== '') {
72
+ address.push(hex)
73
+ } else {
74
+ output.error = true
75
+ return false
76
+ }
77
+ buffer.length = 0
30
78
  }
31
- if (keepZero && acc.length === 0) acc = '0'
32
- return acc
79
+ return true
33
80
  }
34
81
 
82
+ /**
83
+ * @param {string} input
84
+ * @returns {GetIPV6Result}
85
+ */
35
86
  function getIPV6 (input) {
36
87
  let tokenCount = 0
37
88
  const output = { error: false, address: '', zone: '' }
89
+ /** @type {Array<string>} */
38
90
  const address = []
91
+ /** @type {Array<string>} */
39
92
  const buffer = []
40
- let isZone = false
41
93
  let endipv6Encountered = false
42
94
  let endIpv6 = false
43
95
 
44
- function consume () {
45
- if (buffer.length) {
46
- if (isZone === false) {
47
- const hex = stringArrayToHexStripped(buffer)
48
- if (hex !== undefined) {
49
- address.push(hex)
50
- } else {
51
- output.error = true
52
- return false
53
- }
54
- }
55
- buffer.length = 0
56
- }
57
- return true
58
- }
96
+ let consume = consumeHextets
59
97
 
60
98
  for (let i = 0; i < input.length; i++) {
61
99
  const cursor = input[i]
@@ -64,29 +102,28 @@ function getIPV6 (input) {
64
102
  if (endipv6Encountered === true) {
65
103
  endIpv6 = true
66
104
  }
67
- if (!consume()) { break }
68
- tokenCount++
69
- address.push(':')
70
- if (tokenCount > 7) {
105
+ if (!consume(buffer, address, output)) { break }
106
+ if (++tokenCount > 7) {
71
107
  // not valid
72
108
  output.error = true
73
109
  break
74
110
  }
75
- if (i - 1 >= 0 && input[i - 1] === ':') {
111
+ if (i > 0 && input[i - 1] === ':') {
76
112
  endipv6Encountered = true
77
113
  }
114
+ address.push(':')
78
115
  continue
79
116
  } else if (cursor === '%') {
80
- if (!consume()) { break }
117
+ if (!consume(buffer, address, output)) { break }
81
118
  // switch to zone detection
82
- isZone = true
119
+ consume = consumeIsZone
83
120
  } else {
84
121
  buffer.push(cursor)
85
122
  continue
86
123
  }
87
124
  }
88
125
  if (buffer.length) {
89
- if (isZone) {
126
+ if (consume === consumeIsZone) {
90
127
  output.zone = buffer.join('')
91
128
  } else if (endIpv6) {
92
129
  address.push(buffer.join(''))
@@ -98,6 +135,17 @@ function getIPV6 (input) {
98
135
  return output
99
136
  }
100
137
 
138
+ /**
139
+ * @typedef {Object} NormalizeIPv6Result
140
+ * @property {string} host - The normalized host.
141
+ * @property {string} [escapedHost] - The escaped host.
142
+ * @property {boolean} isIPV6 - Indicates if the host is an IPv6 address.
143
+ */
144
+
145
+ /**
146
+ * @param {string} host
147
+ * @returns {NormalizeIPv6Result}
148
+ */
101
149
  function normalizeIPv6 (host) {
102
150
  if (findToken(host, ':') < 2) { return { host, isIPV6: false } }
103
151
  const ipv6 = getIPV6(host)
@@ -109,35 +157,17 @@ function normalizeIPv6 (host) {
109
157
  newHost += '%' + ipv6.zone
110
158
  escapedHost += '%25' + ipv6.zone
111
159
  }
112
- return { host: newHost, escapedHost, isIPV6: true }
160
+ return { host: newHost, isIPV6: true, escapedHost }
113
161
  } else {
114
162
  return { host, isIPV6: false }
115
163
  }
116
164
  }
117
165
 
118
- function stripLeadingZeros (str, token) {
119
- let out = ''
120
- let skip = true
121
- const l = str.length
122
- for (let i = 0; i < l; i++) {
123
- const c = str[i]
124
- if (c === '0' && skip) {
125
- if ((i + 1 <= l && str[i + 1] === token) || i + 1 === l) {
126
- out += c
127
- skip = false
128
- }
129
- } else {
130
- if (c === token) {
131
- skip = true
132
- } else {
133
- skip = false
134
- }
135
- out += c
136
- }
137
- }
138
- return out
139
- }
140
-
166
+ /**
167
+ * @param {string} str
168
+ * @param {string} token
169
+ * @returns {number}
170
+ */
141
171
  function findToken (str, token) {
142
172
  let ind = 0
143
173
  for (let i = 0; i < str.length; i++) {
@@ -146,99 +176,161 @@ function findToken (str, token) {
146
176
  return ind
147
177
  }
148
178
 
149
- const RDS1 = /^\.\.?\//u
150
- const RDS2 = /^\/\.(?:\/|$)/u
151
- const RDS3 = /^\/\.\.(?:\/|$)/u
152
- const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u
153
-
154
- function removeDotSegments (input) {
179
+ /**
180
+ * @param {string} path
181
+ * @returns {string}
182
+ *
183
+ * @see https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
184
+ */
185
+ function removeDotSegments (path) {
186
+ let input = path
155
187
  const output = []
188
+ let nextSlash = -1
189
+ let len = 0
156
190
 
157
- while (input.length) {
158
- if (input.match(RDS1)) {
159
- input = input.replace(RDS1, '')
160
- } else if (input.match(RDS2)) {
161
- input = input.replace(RDS2, '/')
162
- } else if (input.match(RDS3)) {
163
- input = input.replace(RDS3, '/')
164
- output.pop()
165
- } else if (input === '.' || input === '..') {
166
- input = ''
167
- } else {
168
- const im = input.match(RDS5)
169
- if (im) {
170
- const s = im[0]
171
- input = input.slice(s.length)
172
- output.push(s)
191
+ // eslint-disable-next-line no-cond-assign
192
+ while (len = input.length) {
193
+ if (len === 1) {
194
+ if (input === '.') {
195
+ break
196
+ } else if (input === '/') {
197
+ output.push('/')
198
+ break
173
199
  } else {
174
- throw new Error('Unexpected dot segment condition')
200
+ output.push(input)
201
+ break
202
+ }
203
+ } else if (len === 2) {
204
+ if (input[0] === '.') {
205
+ if (input[1] === '.') {
206
+ break
207
+ } else if (input[1] === '/') {
208
+ input = input.slice(2)
209
+ continue
210
+ }
211
+ } else if (input[0] === '/') {
212
+ if (input[1] === '.' || input[1] === '/') {
213
+ output.push('/')
214
+ break
215
+ }
216
+ }
217
+ } else if (len === 3) {
218
+ if (input === '/..') {
219
+ if (output.length !== 0) {
220
+ output.pop()
221
+ }
222
+ output.push('/')
223
+ break
224
+ }
225
+ }
226
+ if (input[0] === '.') {
227
+ if (input[1] === '.') {
228
+ if (input[2] === '/') {
229
+ input = input.slice(3)
230
+ continue
231
+ }
232
+ } else if (input[1] === '/') {
233
+ input = input.slice(2)
234
+ continue
175
235
  }
236
+ } else if (input[0] === '/') {
237
+ if (input[1] === '.') {
238
+ if (input[2] === '/') {
239
+ input = input.slice(2)
240
+ continue
241
+ } else if (input[2] === '.') {
242
+ if (input[3] === '/') {
243
+ input = input.slice(3)
244
+ if (output.length !== 0) {
245
+ output.pop()
246
+ }
247
+ continue
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ // Rule 2E: Move normal path segment to output
254
+ if ((nextSlash = input.indexOf('/', 1)) === -1) {
255
+ output.push(input)
256
+ break
257
+ } else {
258
+ output.push(input.slice(0, nextSlash))
259
+ input = input.slice(nextSlash)
176
260
  }
177
261
  }
262
+
178
263
  return output.join('')
179
264
  }
180
265
 
181
- function normalizeComponentEncoding (components, esc) {
266
+ /**
267
+ * @param {import('../types/index').URIComponent} component
268
+ * @param {boolean} esc
269
+ * @returns {import('../types/index').URIComponent}
270
+ */
271
+ function normalizeComponentEncoding (component, esc) {
182
272
  const func = esc !== true ? escape : unescape
183
- if (components.scheme !== undefined) {
184
- components.scheme = func(components.scheme)
273
+ if (component.scheme !== undefined) {
274
+ component.scheme = func(component.scheme)
185
275
  }
186
- if (components.userinfo !== undefined) {
187
- components.userinfo = func(components.userinfo)
276
+ if (component.userinfo !== undefined) {
277
+ component.userinfo = func(component.userinfo)
188
278
  }
189
- if (components.host !== undefined) {
190
- components.host = func(components.host)
279
+ if (component.host !== undefined) {
280
+ component.host = func(component.host)
191
281
  }
192
- if (components.path !== undefined) {
193
- components.path = func(components.path)
282
+ if (component.path !== undefined) {
283
+ component.path = func(component.path)
194
284
  }
195
- if (components.query !== undefined) {
196
- components.query = func(components.query)
285
+ if (component.query !== undefined) {
286
+ component.query = func(component.query)
197
287
  }
198
- if (components.fragment !== undefined) {
199
- components.fragment = func(components.fragment)
288
+ if (component.fragment !== undefined) {
289
+ component.fragment = func(component.fragment)
200
290
  }
201
- return components
291
+ return component
202
292
  }
203
293
 
204
- function recomposeAuthority (components) {
294
+ /**
295
+ * @param {import('../types/index').URIComponent} component
296
+ * @returns {string|undefined}
297
+ */
298
+ function recomposeAuthority (component) {
205
299
  const uriTokens = []
206
300
 
207
- if (components.userinfo !== undefined) {
208
- uriTokens.push(components.userinfo)
301
+ if (component.userinfo !== undefined) {
302
+ uriTokens.push(component.userinfo)
209
303
  uriTokens.push('@')
210
304
  }
211
305
 
212
- if (components.host !== undefined) {
213
- let host = unescape(components.host)
214
- const ipV4res = normalizeIPv4(host)
215
-
216
- if (ipV4res.isIPV4) {
217
- host = ipV4res.host
218
- } else {
219
- const ipV6res = normalizeIPv6(ipV4res.host)
306
+ if (component.host !== undefined) {
307
+ let host = unescape(component.host)
308
+ if (!isIPv4(host)) {
309
+ const ipV6res = normalizeIPv6(host)
220
310
  if (ipV6res.isIPV6 === true) {
221
311
  host = `[${ipV6res.escapedHost}]`
222
312
  } else {
223
- host = components.host
313
+ host = component.host
224
314
  }
225
315
  }
226
316
  uriTokens.push(host)
227
317
  }
228
318
 
229
- if (typeof components.port === 'number' || typeof components.port === 'string') {
319
+ if (typeof component.port === 'number' || typeof component.port === 'string') {
230
320
  uriTokens.push(':')
231
- uriTokens.push(String(components.port))
321
+ uriTokens.push(String(component.port))
232
322
  }
233
323
 
234
324
  return uriTokens.length ? uriTokens.join('') : undefined
235
325
  };
236
326
 
237
327
  module.exports = {
328
+ nonSimpleDomain,
238
329
  recomposeAuthority,
239
330
  normalizeComponentEncoding,
240
331
  removeDotSegments,
241
- normalizeIPv4,
332
+ isIPv4,
333
+ isUUID,
242
334
  normalizeIPv6,
243
335
  stringArrayToHexStripped
244
336
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-uri",
3
3
  "description": "Dependency-free RFC 3986 URI toolbox",
4
- "version": "3.0.6",
4
+ "version": "3.1.0",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "types": "types/index.d.ts",
@@ -46,10 +46,13 @@
46
46
  }
47
47
  ],
48
48
  "scripts": {
49
- "bench": "node benchmark.js",
50
49
  "lint": "eslint",
51
50
  "lint:fix": "eslint --fix",
52
51
  "test": "npm run test:unit && npm run test:typescript",
52
+ "test:browser:chromium": "playwright-test ./test/* --runner tape --browser=chromium",
53
+ "test:browser:firefox": "playwright-test ./test/* --runner tape --browser=firefox",
54
+ "test:browser:webkit": "playwright-test ./test/* --runner tape --browser=webkit",
55
+ "test:browser": "npm run test:browser:chromium && npm run test:browser:firefox && npm run test:browser:webkit",
53
56
  "test:unit": "tape test/**/*.js",
54
57
  "test:unit:dev": "npm run test:unit -- --coverage-report=html",
55
58
  "test:typescript": "tsd"
@@ -57,12 +60,10 @@
57
60
  "devDependencies": {
58
61
  "@fastify/pre-commit": "^2.1.0",
59
62
  "ajv": "^8.16.0",
60
- "benchmark": "^2.1.4",
61
- "coveralls": "^3.1.1",
62
63
  "eslint": "^9.17.0",
63
64
  "neostandard": "^0.12.0",
65
+ "playwright-test": "^14.1.12",
64
66
  "tape": "^5.8.1",
65
- "tsd": "^0.31.0",
66
- "uri-js": "^4.4.1"
67
+ "tsd": "^0.32.0"
67
68
  }
68
69
  }
@@ -1,9 +1,13 @@
1
+ 'use strict'
2
+
3
+ const test = require('tape')
4
+ const fastURI = require('..')
5
+
1
6
  const AJV = require('ajv')
2
- const fastUri = require('../')
7
+
3
8
  const ajv = new AJV({
4
- uriResolver: fastUri // comment this line to see it works with uri-js
9
+ uriResolver: fastURI // comment this line to see it works with uri-js
5
10
  })
6
- const test = require('tape')
7
11
 
8
12
  test('ajv', t => {
9
13
  t.plan(1)
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  const test = require('tape')
4
- const URI = require('../')
4
+ const fastURI = require('..')
5
5
 
6
- const fn = URI.equal
6
+ const fn = fastURI.equal
7
7
  const runTest = (t, suite) => {
8
8
  suite.forEach(s => {
9
9
  const operator = s.result ? '==' : '!='
@@ -65,6 +65,11 @@ test('URN Equals', (t) => {
65
65
  // t.equal(URI.equal('urn:foo:a123%2C456', 'URN:FOO:a123%2c456'), true)
66
66
 
67
67
  runTest(t, suite)
68
+
69
+ t.throws(() => {
70
+ fn('urn:', 'urn:FOO:a123,456')
71
+ }, 'URN without nid cannot be serialized')
72
+
68
73
  t.end()
69
74
  })
70
75