cdk-common 2.0.900 → 2.0.901
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/.jsii +2 -2
- package/lib/main.js +1 -1
- package/node_modules/fast-uri/.gitattributes +2 -0
- package/node_modules/fast-uri/.github/.stale.yml +21 -0
- package/node_modules/fast-uri/.github/dependabot.yml +13 -0
- package/node_modules/fast-uri/.github/tests_checker.yml +8 -0
- package/node_modules/fast-uri/.github/workflows/ci.yml +23 -0
- package/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +20 -0
- package/node_modules/fast-uri/.taprc +3 -0
- package/node_modules/fast-uri/LICENSE +30 -0
- package/node_modules/fast-uri/README.md +125 -0
- package/node_modules/fast-uri/benchmark.js +105 -0
- package/node_modules/fast-uri/index.js +309 -0
- package/node_modules/fast-uri/lib/schemes.js +188 -0
- package/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/node_modules/fast-uri/lib/utils.js +242 -0
- package/node_modules/fast-uri/package.json +39 -0
- package/node_modules/fast-uri/test/.gitkeep +0 -0
- package/node_modules/fast-uri/test/ajv.test.js +39 -0
- package/node_modules/fast-uri/test/compatibility.test.js +130 -0
- package/node_modules/fast-uri/test/equal.test.js +104 -0
- package/node_modules/fast-uri/test/parse.test.js +319 -0
- package/node_modules/fast-uri/test/resolve.test.js +76 -0
- package/node_modules/fast-uri/test/serialize.test.js +144 -0
- package/node_modules/fast-uri/test/uri-js.test.js +940 -0
- package/node_modules/fast-uri/test/util.test.js +24 -0
- package/node_modules/fast-uri/types/index.d.ts +53 -0
- package/node_modules/fast-uri/types/index.test-d.ts +17 -0
- package/node_modules/table/node_modules/ajv/dist/compile/codegen/code.js +1 -0
- package/node_modules/table/node_modules/ajv/dist/compile/codegen/code.js.map +1 -1
- package/node_modules/table/node_modules/ajv/dist/compile/index.js.map +1 -1
- package/node_modules/table/node_modules/ajv/dist/compile/resolve.d.ts +2 -2
- package/node_modules/table/node_modules/ajv/dist/compile/resolve.js.map +1 -1
- package/node_modules/table/node_modules/ajv/dist/runtime/uri.d.ts +1 -1
- package/node_modules/table/node_modules/ajv/dist/runtime/uri.js +1 -1
- package/node_modules/table/node_modules/ajv/dist/runtime/uri.js.map +1 -1
- package/node_modules/table/node_modules/ajv/dist/types/index.d.ts +3 -3
- package/node_modules/table/node_modules/ajv/dist/types/json-schema.d.ts +10 -10
- package/node_modules/table/node_modules/ajv/lib/compile/codegen/code.ts +1 -0
- package/node_modules/table/node_modules/ajv/lib/compile/index.ts +2 -2
- package/node_modules/table/node_modules/ajv/lib/compile/resolve.ts +2 -2
- package/node_modules/table/node_modules/ajv/lib/runtime/uri.ts +1 -1
- package/node_modules/table/node_modules/ajv/lib/types/index.ts +3 -3
- package/node_modules/table/node_modules/ajv/lib/types/json-schema.ts +10 -10
- package/node_modules/table/node_modules/ajv/package.json +5 -5
- package/package.json +1 -1
- package/node_modules/punycode/LICENSE-MIT.txt +0 -20
- package/node_modules/punycode/README.md +0 -148
- package/node_modules/punycode/package.json +0 -58
- package/node_modules/punycode/punycode.es6.js +0 -444
- package/node_modules/punycode/punycode.js +0 -443
- package/node_modules/uri-js/LICENSE +0 -11
- package/node_modules/uri-js/README.md +0 -203
- package/node_modules/uri-js/dist/es5/uri.all.d.ts +0 -59
- package/node_modules/uri-js/dist/es5/uri.all.js +0 -1443
- package/node_modules/uri-js/dist/es5/uri.all.js.map +0 -1
- package/node_modules/uri-js/dist/es5/uri.all.min.d.ts +0 -59
- package/node_modules/uri-js/dist/es5/uri.all.min.js +0 -3
- package/node_modules/uri-js/dist/es5/uri.all.min.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/index.d.ts +0 -1
- package/node_modules/uri-js/dist/esnext/index.js +0 -17
- package/node_modules/uri-js/dist/esnext/index.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/regexps-iri.d.ts +0 -3
- package/node_modules/uri-js/dist/esnext/regexps-iri.js +0 -3
- package/node_modules/uri-js/dist/esnext/regexps-iri.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/regexps-uri.d.ts +0 -4
- package/node_modules/uri-js/dist/esnext/regexps-uri.js +0 -42
- package/node_modules/uri-js/dist/esnext/regexps-uri.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/http.d.ts +0 -3
- package/node_modules/uri-js/dist/esnext/schemes/http.js +0 -28
- package/node_modules/uri-js/dist/esnext/schemes/http.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/https.d.ts +0 -3
- package/node_modules/uri-js/dist/esnext/schemes/https.js +0 -9
- package/node_modules/uri-js/dist/esnext/schemes/https.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/mailto.d.ts +0 -12
- package/node_modules/uri-js/dist/esnext/schemes/mailto.js +0 -148
- package/node_modules/uri-js/dist/esnext/schemes/mailto.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/urn-uuid.d.ts +0 -7
- package/node_modules/uri-js/dist/esnext/schemes/urn-uuid.js +0 -23
- package/node_modules/uri-js/dist/esnext/schemes/urn-uuid.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/urn.d.ts +0 -10
- package/node_modules/uri-js/dist/esnext/schemes/urn.js +0 -49
- package/node_modules/uri-js/dist/esnext/schemes/urn.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/ws.d.ts +0 -7
- package/node_modules/uri-js/dist/esnext/schemes/ws.js +0 -41
- package/node_modules/uri-js/dist/esnext/schemes/ws.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/schemes/wss.d.ts +0 -3
- package/node_modules/uri-js/dist/esnext/schemes/wss.js +0 -9
- package/node_modules/uri-js/dist/esnext/schemes/wss.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/uri.d.ts +0 -59
- package/node_modules/uri-js/dist/esnext/uri.js +0 -480
- package/node_modules/uri-js/dist/esnext/uri.js.map +0 -1
- package/node_modules/uri-js/dist/esnext/util.d.ts +0 -6
- package/node_modules/uri-js/dist/esnext/util.js +0 -36
- package/node_modules/uri-js/dist/esnext/util.js.map +0 -1
- package/node_modules/uri-js/package.json +0 -77
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = require('./lib/utils')
|
|
4
|
+
const SCHEMES = require('./lib/schemes')
|
|
5
|
+
|
|
6
|
+
function normalize (uri, options) {
|
|
7
|
+
if (typeof uri === 'string') {
|
|
8
|
+
uri = serialize(parse(uri, options), options)
|
|
9
|
+
} else if (typeof uri === 'object') {
|
|
10
|
+
uri = parse(serialize(uri, options), options)
|
|
11
|
+
}
|
|
12
|
+
return uri
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function resolve (baseURI, relativeURI, options) {
|
|
16
|
+
const schemelessOptions = Object.assign({ scheme: 'null' }, options)
|
|
17
|
+
const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
|
|
18
|
+
return serialize(resolved, { ...schemelessOptions, skipEscape: true })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resolveComponents (base, relative, options, skipNormalization) {
|
|
22
|
+
const target = {}
|
|
23
|
+
if (!skipNormalization) {
|
|
24
|
+
base = parse(serialize(base, options), options) // normalize base components
|
|
25
|
+
relative = parse(serialize(relative, options), options) // normalize relative components
|
|
26
|
+
}
|
|
27
|
+
options = options || {}
|
|
28
|
+
|
|
29
|
+
if (!options.tolerant && relative.scheme) {
|
|
30
|
+
target.scheme = relative.scheme
|
|
31
|
+
// target.authority = relative.authority;
|
|
32
|
+
target.userinfo = relative.userinfo
|
|
33
|
+
target.host = relative.host
|
|
34
|
+
target.port = relative.port
|
|
35
|
+
target.path = removeDotSegments(relative.path || '')
|
|
36
|
+
target.query = relative.query
|
|
37
|
+
} else {
|
|
38
|
+
if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
|
|
39
|
+
// target.authority = relative.authority;
|
|
40
|
+
target.userinfo = relative.userinfo
|
|
41
|
+
target.host = relative.host
|
|
42
|
+
target.port = relative.port
|
|
43
|
+
target.path = removeDotSegments(relative.path || '')
|
|
44
|
+
target.query = relative.query
|
|
45
|
+
} else {
|
|
46
|
+
if (!relative.path) {
|
|
47
|
+
target.path = base.path
|
|
48
|
+
if (relative.query !== undefined) {
|
|
49
|
+
target.query = relative.query
|
|
50
|
+
} else {
|
|
51
|
+
target.query = base.query
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
if (relative.path.charAt(0) === '/') {
|
|
55
|
+
target.path = removeDotSegments(relative.path)
|
|
56
|
+
} else {
|
|
57
|
+
if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
|
|
58
|
+
target.path = '/' + relative.path
|
|
59
|
+
} else if (!base.path) {
|
|
60
|
+
target.path = relative.path
|
|
61
|
+
} else {
|
|
62
|
+
target.path = base.path.slice(0, base.path.lastIndexOf('/') + 1) + relative.path
|
|
63
|
+
}
|
|
64
|
+
target.path = removeDotSegments(target.path)
|
|
65
|
+
}
|
|
66
|
+
target.query = relative.query
|
|
67
|
+
}
|
|
68
|
+
// target.authority = base.authority;
|
|
69
|
+
target.userinfo = base.userinfo
|
|
70
|
+
target.host = base.host
|
|
71
|
+
target.port = base.port
|
|
72
|
+
}
|
|
73
|
+
target.scheme = base.scheme
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
target.fragment = relative.fragment
|
|
77
|
+
|
|
78
|
+
return target
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function equal (uriA, uriB, options) {
|
|
82
|
+
if (typeof uriA === 'string') {
|
|
83
|
+
uriA = unescape(uriA)
|
|
84
|
+
uriA = serialize(normalizeComponentEncoding(parse(uriA, options), true), { ...options, skipEscape: true })
|
|
85
|
+
} else if (typeof uriA === 'object') {
|
|
86
|
+
uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof uriB === 'string') {
|
|
90
|
+
uriB = unescape(uriB)
|
|
91
|
+
uriB = serialize(normalizeComponentEncoding(parse(uriB, options), true), { ...options, skipEscape: true })
|
|
92
|
+
} else if (typeof uriB === 'object') {
|
|
93
|
+
uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true })
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return uriA.toLowerCase() === uriB.toLowerCase()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function serialize (cmpts, opts) {
|
|
100
|
+
const components = {
|
|
101
|
+
host: cmpts.host,
|
|
102
|
+
scheme: cmpts.scheme,
|
|
103
|
+
userinfo: cmpts.userinfo,
|
|
104
|
+
port: cmpts.port,
|
|
105
|
+
path: cmpts.path,
|
|
106
|
+
query: cmpts.query,
|
|
107
|
+
nid: cmpts.nid,
|
|
108
|
+
nss: cmpts.nss,
|
|
109
|
+
uuid: cmpts.uuid,
|
|
110
|
+
fragment: cmpts.fragment,
|
|
111
|
+
reference: cmpts.reference,
|
|
112
|
+
resourceName: cmpts.resourceName,
|
|
113
|
+
secure: cmpts.secure,
|
|
114
|
+
error: ''
|
|
115
|
+
}
|
|
116
|
+
const options = Object.assign({}, opts)
|
|
117
|
+
const uriTokens = []
|
|
118
|
+
|
|
119
|
+
// find scheme handler
|
|
120
|
+
const schemeHandler = SCHEMES[(options.scheme || components.scheme || '').toLowerCase()]
|
|
121
|
+
|
|
122
|
+
// perform scheme specific serialization
|
|
123
|
+
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options)
|
|
124
|
+
|
|
125
|
+
if (components.path !== undefined) {
|
|
126
|
+
if (!options.skipEscape) {
|
|
127
|
+
components.path = escape(components.path)
|
|
128
|
+
|
|
129
|
+
if (components.scheme !== undefined) {
|
|
130
|
+
components.path = components.path.split('%3A').join(':')
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
components.path = unescape(components.path)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (options.reference !== 'suffix' && components.scheme) {
|
|
138
|
+
uriTokens.push(components.scheme)
|
|
139
|
+
uriTokens.push(':')
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const authority = recomposeAuthority(components, options)
|
|
143
|
+
if (authority !== undefined) {
|
|
144
|
+
if (options.reference !== 'suffix') {
|
|
145
|
+
uriTokens.push('//')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
uriTokens.push(authority)
|
|
149
|
+
|
|
150
|
+
if (components.path && components.path.charAt(0) !== '/') {
|
|
151
|
+
uriTokens.push('/')
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (components.path !== undefined) {
|
|
155
|
+
let s = components.path
|
|
156
|
+
|
|
157
|
+
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
|
|
158
|
+
s = removeDotSegments(s)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (authority === undefined) {
|
|
162
|
+
s = s.replace(/^\/\//u, '/%2F') // don't allow the path to start with "//"
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
uriTokens.push(s)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (components.query !== undefined) {
|
|
169
|
+
uriTokens.push('?')
|
|
170
|
+
uriTokens.push(components.query)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (components.fragment !== undefined) {
|
|
174
|
+
uriTokens.push('#')
|
|
175
|
+
uriTokens.push(components.fragment)
|
|
176
|
+
}
|
|
177
|
+
return uriTokens.join('')
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const hexLookUp = Array.from({ length: 127 }, (v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)))
|
|
181
|
+
|
|
182
|
+
function nonSimpleDomain (value) {
|
|
183
|
+
let code = 0
|
|
184
|
+
for (let i = 0, len = value.length; i < len; ++i) {
|
|
185
|
+
code = value.charCodeAt(i)
|
|
186
|
+
if (code > 126 || hexLookUp[code]) {
|
|
187
|
+
return true
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u
|
|
194
|
+
|
|
195
|
+
function parse (uri, opts) {
|
|
196
|
+
const options = Object.assign({}, opts)
|
|
197
|
+
const parsed = {
|
|
198
|
+
scheme: undefined,
|
|
199
|
+
userinfo: undefined,
|
|
200
|
+
host: '',
|
|
201
|
+
port: undefined,
|
|
202
|
+
path: '',
|
|
203
|
+
query: undefined,
|
|
204
|
+
fragment: undefined
|
|
205
|
+
}
|
|
206
|
+
const gotEncoding = uri.indexOf('%') !== -1
|
|
207
|
+
let isIP = false
|
|
208
|
+
if (options.reference === 'suffix') uri = (options.scheme ? options.scheme + ':' : '') + '//' + uri
|
|
209
|
+
|
|
210
|
+
const matches = uri.match(URI_PARSE)
|
|
211
|
+
|
|
212
|
+
if (matches) {
|
|
213
|
+
// store each component
|
|
214
|
+
parsed.scheme = matches[1]
|
|
215
|
+
parsed.userinfo = matches[3]
|
|
216
|
+
parsed.host = matches[4]
|
|
217
|
+
parsed.port = parseInt(matches[5], 10)
|
|
218
|
+
parsed.path = matches[6] || ''
|
|
219
|
+
parsed.query = matches[7]
|
|
220
|
+
parsed.fragment = matches[8]
|
|
221
|
+
|
|
222
|
+
// fix port number
|
|
223
|
+
if (isNaN(parsed.port)) {
|
|
224
|
+
parsed.port = matches[5]
|
|
225
|
+
}
|
|
226
|
+
if (parsed.host) {
|
|
227
|
+
const ipv4result = normalizeIPv4(parsed.host)
|
|
228
|
+
if (ipv4result.isIPV4 === false) {
|
|
229
|
+
const ipv6result = normalizeIPv6(ipv4result.host, { isIPV4: false })
|
|
230
|
+
parsed.host = ipv6result.host.toLowerCase()
|
|
231
|
+
isIP = ipv6result.isIPV6
|
|
232
|
+
} else {
|
|
233
|
+
parsed.host = ipv4result.host
|
|
234
|
+
isIP = true
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (parsed.scheme === undefined && parsed.userinfo === undefined && parsed.host === undefined && parsed.port === undefined && !parsed.path && parsed.query === undefined) {
|
|
238
|
+
parsed.reference = 'same-document'
|
|
239
|
+
} else if (parsed.scheme === undefined) {
|
|
240
|
+
parsed.reference = 'relative'
|
|
241
|
+
} else if (parsed.fragment === undefined) {
|
|
242
|
+
parsed.reference = 'absolute'
|
|
243
|
+
} else {
|
|
244
|
+
parsed.reference = 'uri'
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// check for reference errors
|
|
248
|
+
if (options.reference && options.reference !== 'suffix' && options.reference !== parsed.reference) {
|
|
249
|
+
parsed.error = parsed.error || 'URI is not a ' + options.reference + ' reference.'
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// find scheme handler
|
|
253
|
+
const schemeHandler = SCHEMES[(options.scheme || parsed.scheme || '').toLowerCase()]
|
|
254
|
+
|
|
255
|
+
// check if scheme can't handle IRIs
|
|
256
|
+
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
|
|
257
|
+
// if host component is a domain name
|
|
258
|
+
if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {
|
|
259
|
+
// convert Unicode IDN -> ASCII IDN
|
|
260
|
+
try {
|
|
261
|
+
parsed.host = URL.domainToASCII(parsed.host.toLowerCase())
|
|
262
|
+
} catch (e) {
|
|
263
|
+
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// convert IRI -> URI
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
|
|
270
|
+
if (gotEncoding && parsed.scheme !== undefined) {
|
|
271
|
+
parsed.scheme = unescape(parsed.scheme)
|
|
272
|
+
}
|
|
273
|
+
if (gotEncoding && parsed.userinfo !== undefined) {
|
|
274
|
+
parsed.userinfo = unescape(parsed.userinfo)
|
|
275
|
+
}
|
|
276
|
+
if (gotEncoding && parsed.host !== undefined) {
|
|
277
|
+
parsed.host = unescape(parsed.host)
|
|
278
|
+
}
|
|
279
|
+
if (parsed.path !== undefined && parsed.path.length) {
|
|
280
|
+
parsed.path = escape(unescape(parsed.path))
|
|
281
|
+
}
|
|
282
|
+
if (parsed.fragment !== undefined && parsed.fragment.length) {
|
|
283
|
+
parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment))
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// perform scheme specific parsing
|
|
288
|
+
if (schemeHandler && schemeHandler.parse) {
|
|
289
|
+
schemeHandler.parse(parsed, options)
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
parsed.error = parsed.error || 'URI can not be parsed.'
|
|
293
|
+
}
|
|
294
|
+
return parsed
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const fastUri = {
|
|
298
|
+
SCHEMES,
|
|
299
|
+
normalize,
|
|
300
|
+
resolve,
|
|
301
|
+
resolveComponents,
|
|
302
|
+
equal,
|
|
303
|
+
serialize,
|
|
304
|
+
parse
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = fastUri
|
|
308
|
+
module.exports.default = fastUri
|
|
309
|
+
module.exports.fastUri = fastUri
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const UUID_REG = /^[\da-f]{8}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{4}\b-[\da-f]{12}$/iu
|
|
4
|
+
const URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu
|
|
5
|
+
|
|
6
|
+
function isSecure (wsComponents) {
|
|
7
|
+
return typeof wsComponents.secure === 'boolean' ? wsComponents.secure : String(wsComponents.scheme).toLowerCase() === 'wss'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function httpParse (components) {
|
|
11
|
+
if (!components.host) {
|
|
12
|
+
components.error = components.error || 'HTTP URIs must have a host.'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return components
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function httpSerialize (components) {
|
|
19
|
+
const secure = String(components.scheme).toLowerCase() === 'https'
|
|
20
|
+
|
|
21
|
+
// normalize the default port
|
|
22
|
+
if (components.port === (secure ? 443 : 80) || components.port === '') {
|
|
23
|
+
components.port = undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// normalize the empty path
|
|
27
|
+
if (!components.path) {
|
|
28
|
+
components.path = '/'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// NOTE: We do not parse query strings for HTTP URIs
|
|
32
|
+
// as WWW Form Url Encoded query strings are part of the HTML4+ spec,
|
|
33
|
+
// and not the HTTP spec.
|
|
34
|
+
|
|
35
|
+
return components
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function wsParse (wsComponents) {
|
|
39
|
+
// indicate if the secure flag is set
|
|
40
|
+
wsComponents.secure = isSecure(wsComponents)
|
|
41
|
+
|
|
42
|
+
// construct resouce name
|
|
43
|
+
wsComponents.resourceName = (wsComponents.path || '/') + (wsComponents.query ? '?' + wsComponents.query : '')
|
|
44
|
+
wsComponents.path = undefined
|
|
45
|
+
wsComponents.query = undefined
|
|
46
|
+
|
|
47
|
+
return wsComponents
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function wsSerialize (wsComponents) {
|
|
51
|
+
// normalize the default port
|
|
52
|
+
if (wsComponents.port === (isSecure(wsComponents) ? 443 : 80) || wsComponents.port === '') {
|
|
53
|
+
wsComponents.port = undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ensure scheme matches secure flag
|
|
57
|
+
if (typeof wsComponents.secure === 'boolean') {
|
|
58
|
+
wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws')
|
|
59
|
+
wsComponents.secure = undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// reconstruct path from resource name
|
|
63
|
+
if (wsComponents.resourceName) {
|
|
64
|
+
const [path, query] = wsComponents.resourceName.split('?')
|
|
65
|
+
wsComponents.path = (path && path !== '/' ? path : undefined)
|
|
66
|
+
wsComponents.query = query
|
|
67
|
+
wsComponents.resourceName = undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// forbid fragment component
|
|
71
|
+
wsComponents.fragment = undefined
|
|
72
|
+
|
|
73
|
+
return wsComponents
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function urnParse (urnComponents, options) {
|
|
77
|
+
if (!urnComponents.path) {
|
|
78
|
+
urnComponents.error = 'URN can not be parsed'
|
|
79
|
+
return urnComponents
|
|
80
|
+
}
|
|
81
|
+
const matches = urnComponents.path.match(URN_REG)
|
|
82
|
+
if (matches) {
|
|
83
|
+
const scheme = options.scheme || urnComponents.scheme || 'urn'
|
|
84
|
+
urnComponents.nid = matches[1].toLowerCase()
|
|
85
|
+
urnComponents.nss = matches[2]
|
|
86
|
+
const urnScheme = `${scheme}:${options.nid || urnComponents.nid}`
|
|
87
|
+
const schemeHandler = SCHEMES[urnScheme]
|
|
88
|
+
urnComponents.path = undefined
|
|
89
|
+
|
|
90
|
+
if (schemeHandler) {
|
|
91
|
+
urnComponents = schemeHandler.parse(urnComponents, options)
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
urnComponents.error = urnComponents.error || 'URN can not be parsed.'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return urnComponents
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function urnSerialize (urnComponents, options) {
|
|
101
|
+
const scheme = options.scheme || urnComponents.scheme || 'urn'
|
|
102
|
+
const nid = urnComponents.nid.toLowerCase()
|
|
103
|
+
const urnScheme = `${scheme}:${options.nid || nid}`
|
|
104
|
+
const schemeHandler = SCHEMES[urnScheme]
|
|
105
|
+
|
|
106
|
+
if (schemeHandler) {
|
|
107
|
+
urnComponents = schemeHandler.serialize(urnComponents, options)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const uriComponents = urnComponents
|
|
111
|
+
const nss = urnComponents.nss
|
|
112
|
+
uriComponents.path = `${nid || options.nid}:${nss}`
|
|
113
|
+
|
|
114
|
+
options.skipEscape = true
|
|
115
|
+
return uriComponents
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function urnuuidParse (urnComponents, options) {
|
|
119
|
+
const uuidComponents = urnComponents
|
|
120
|
+
uuidComponents.uuid = uuidComponents.nss
|
|
121
|
+
uuidComponents.nss = undefined
|
|
122
|
+
|
|
123
|
+
if (!options.tolerant && (!uuidComponents.uuid || !UUID_REG.test(uuidComponents.uuid))) {
|
|
124
|
+
uuidComponents.error = uuidComponents.error || 'UUID is not valid.'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return uuidComponents
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function urnuuidSerialize (uuidComponents) {
|
|
131
|
+
const urnComponents = uuidComponents
|
|
132
|
+
// normalize UUID
|
|
133
|
+
urnComponents.nss = (uuidComponents.uuid || '').toLowerCase()
|
|
134
|
+
return urnComponents
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const http = {
|
|
138
|
+
scheme: 'http',
|
|
139
|
+
domainHost: true,
|
|
140
|
+
parse: httpParse,
|
|
141
|
+
serialize: httpSerialize
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const https = {
|
|
145
|
+
scheme: 'https',
|
|
146
|
+
domainHost: http.domainHost,
|
|
147
|
+
parse: httpParse,
|
|
148
|
+
serialize: httpSerialize
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const ws = {
|
|
152
|
+
scheme: 'ws',
|
|
153
|
+
domainHost: true,
|
|
154
|
+
parse: wsParse,
|
|
155
|
+
serialize: wsSerialize
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const wss = {
|
|
159
|
+
scheme: 'wss',
|
|
160
|
+
domainHost: ws.domainHost,
|
|
161
|
+
parse: ws.parse,
|
|
162
|
+
serialize: ws.serialize
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const urn = {
|
|
166
|
+
scheme: 'urn',
|
|
167
|
+
parse: urnParse,
|
|
168
|
+
serialize: urnSerialize,
|
|
169
|
+
skipNormalize: true
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const urnuuid = {
|
|
173
|
+
scheme: 'urn:uuid',
|
|
174
|
+
parse: urnuuidParse,
|
|
175
|
+
serialize: urnuuidSerialize,
|
|
176
|
+
skipNormalize: true
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const SCHEMES = {
|
|
180
|
+
http,
|
|
181
|
+
https,
|
|
182
|
+
ws,
|
|
183
|
+
wss,
|
|
184
|
+
urn,
|
|
185
|
+
'urn:uuid': urnuuid
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = SCHEMES
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const HEX = {
|
|
4
|
+
0: 0,
|
|
5
|
+
1: 1,
|
|
6
|
+
2: 2,
|
|
7
|
+
3: 3,
|
|
8
|
+
4: 4,
|
|
9
|
+
5: 5,
|
|
10
|
+
6: 6,
|
|
11
|
+
7: 7,
|
|
12
|
+
8: 8,
|
|
13
|
+
9: 9,
|
|
14
|
+
a: 10,
|
|
15
|
+
A: 10,
|
|
16
|
+
b: 11,
|
|
17
|
+
B: 11,
|
|
18
|
+
c: 12,
|
|
19
|
+
C: 12,
|
|
20
|
+
d: 13,
|
|
21
|
+
D: 13,
|
|
22
|
+
e: 14,
|
|
23
|
+
E: 14,
|
|
24
|
+
f: 15,
|
|
25
|
+
F: 15
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
HEX
|
|
30
|
+
}
|