@blueking/bkui-form 1.0.1-beta.1 → 1.0.1-beta.3
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/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
- package/esm/adapter/field/ArrayField.tsx.js +55 -0
- package/esm/adapter/field/BooleanField.tsx.js +41 -0
- package/esm/adapter/field/CompositionField.tsx.js +113 -0
- package/esm/adapter/field/FieldProps.ts.js +85 -0
- package/esm/adapter/field/NumberField.tsx.js +19 -0
- package/esm/adapter/field/ObjectField.tsx.js +58 -0
- package/esm/adapter/field/SchemaField.tsx.js +28 -0
- package/esm/adapter/field/StringField.tsx.js +4 -0
- package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
- package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
- package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
- package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
- package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
- package/esm/adapter/widget/InputWidget.ts.js +79 -0
- package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
- package/esm/adapter/widget/RadioWidget.ts.js +98 -0
- package/esm/adapter/widget/SelectWidget.ts.js +98 -0
- package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
- package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
- package/esm/adapter/widget/TableWidget.ts.js +205 -0
- package/esm/adapter/widget/Widget.ts.js +497 -0
- package/esm/assets/fonts/iconcool.eot +0 -0
- package/esm/assets/fonts/iconcool.ttf +0 -0
- package/esm/assets/fonts/iconcool.woff +0 -0
- package/esm/assets/style.css +43 -0
- package/esm/controller/form.css +164 -0
- package/esm/controller/form.tsx.js +159 -0
- package/esm/controller/props.ts.js +75 -0
- package/esm/core/events.ts.js +74 -0
- package/esm/core/expression.ts.js +67 -0
- package/esm/core/lang.ts.js +25 -0
- package/esm/core/layout.ts.js +149 -0
- package/esm/core/path.ts.js +60 -0
- package/esm/core/proxy.ts.js +10 -0
- package/esm/core/reaction.ts.js +116 -0
- package/esm/core/register.ts.js +74 -0
- package/esm/core/schema.ts.js +302 -0
- package/esm/core/validator.ts.js +248 -0
- package/esm/core/widgetTree.ts.js +163 -0
- package/esm/index.ts.js +6 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
- package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
- package/esm/node_modules/ajv/dist/ajv.js +50 -0
- package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
- package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
- package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
- package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
- package/esm/node_modules/ajv/dist/compile/index.js +242 -0
- package/esm/node_modules/ajv/dist/compile/names.js +28 -0
- package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
- package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
- package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
- package/esm/node_modules/ajv/dist/compile/util.js +178 -0
- package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
- package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
- package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
- package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
- package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
- package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
- package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
- package/esm/node_modules/ajv/dist/core.js +618 -0
- package/esm/node_modules/ajv/dist/refs/data.json +13 -0
- package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
- package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
- package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
- package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
- package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
- package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
- package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
- package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
- package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
- package/esm/node_modules/ajv-formats/dist/index.js +37 -0
- package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
- package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
- package/esm/node_modules/fast-deep-equal/index.js +46 -0
- package/esm/node_modules/fast-uri/index.js +303 -0
- package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
- package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/esm/node_modules/fast-uri/lib/utils.js +244 -0
- package/esm/node_modules/json-schema-traverse/index.js +89 -0
- package/esm/node_modules/semver/classes/comparator.js +143 -0
- package/esm/node_modules/semver/classes/range.js +557 -0
- package/esm/node_modules/semver/classes/semver.js +333 -0
- package/esm/node_modules/semver/functions/clean.js +8 -0
- package/esm/node_modules/semver/functions/cmp.js +54 -0
- package/esm/node_modules/semver/functions/coerce.js +62 -0
- package/esm/node_modules/semver/functions/compare-build.js +9 -0
- package/esm/node_modules/semver/functions/compare-loose.js +5 -0
- package/esm/node_modules/semver/functions/compare.js +7 -0
- package/esm/node_modules/semver/functions/diff.js +60 -0
- package/esm/node_modules/semver/functions/eq.js +5 -0
- package/esm/node_modules/semver/functions/gt.js +5 -0
- package/esm/node_modules/semver/functions/gte.js +5 -0
- package/esm/node_modules/semver/functions/inc.js +21 -0
- package/esm/node_modules/semver/functions/lt.js +5 -0
- package/esm/node_modules/semver/functions/lte.js +5 -0
- package/esm/node_modules/semver/functions/major.js +5 -0
- package/esm/node_modules/semver/functions/minor.js +5 -0
- package/esm/node_modules/semver/functions/neq.js +5 -0
- package/esm/node_modules/semver/functions/parse.js +18 -0
- package/esm/node_modules/semver/functions/patch.js +5 -0
- package/esm/node_modules/semver/functions/prerelease.js +8 -0
- package/esm/node_modules/semver/functions/rcompare.js +5 -0
- package/esm/node_modules/semver/functions/rsort.js +5 -0
- package/esm/node_modules/semver/functions/satisfies.js +12 -0
- package/esm/node_modules/semver/functions/sort.js +5 -0
- package/esm/node_modules/semver/functions/valid.js +8 -0
- package/esm/node_modules/semver/index.js +91 -0
- package/esm/node_modules/semver/internal/constants.js +37 -0
- package/esm/node_modules/semver/internal/debug.js +11 -0
- package/esm/node_modules/semver/internal/identifiers.js +29 -0
- package/esm/node_modules/semver/internal/lrucache.js +42 -0
- package/esm/node_modules/semver/internal/parse-options.js +17 -0
- package/esm/node_modules/semver/internal/re.js +223 -0
- package/esm/node_modules/semver/ranges/gtr.js +6 -0
- package/esm/node_modules/semver/ranges/intersects.js +9 -0
- package/esm/node_modules/semver/ranges/ltr.js +6 -0
- package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/esm/node_modules/semver/ranges/min-version.js +63 -0
- package/esm/node_modules/semver/ranges/outside.js +82 -0
- package/esm/node_modules/semver/ranges/simplify.js +49 -0
- package/esm/node_modules/semver/ranges/subset.js +249 -0
- package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
- package/esm/node_modules/semver/ranges/valid.js +13 -0
- package/esm/util/fetch.ts.js +190 -0
- package/esm/util/index.ts.js +276 -0
- package/package.json +3 -4
- package/dist/main.css +0 -208
- package/dist/main.js +0 -17353
- /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { HEX } = require('./scopedChars.js')
|
|
4
|
+
|
|
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
|
+
|
|
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 }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {string[]} input
|
|
20
|
+
* @param {boolean} [keepZero=false]
|
|
21
|
+
* @returns {string|undefined}
|
|
22
|
+
*/
|
|
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
|
|
30
|
+
}
|
|
31
|
+
if (keepZero && acc.length === 0) acc = '0'
|
|
32
|
+
return acc
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getIPV6 (input) {
|
|
36
|
+
let tokenCount = 0
|
|
37
|
+
const output = { error: false, address: '', zone: '' }
|
|
38
|
+
const address = []
|
|
39
|
+
const buffer = []
|
|
40
|
+
let isZone = false
|
|
41
|
+
let endipv6Encountered = false
|
|
42
|
+
let endIpv6 = false
|
|
43
|
+
|
|
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
|
+
}
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < input.length; i++) {
|
|
61
|
+
const cursor = input[i]
|
|
62
|
+
if (cursor === '[' || cursor === ']') { continue }
|
|
63
|
+
if (cursor === ':') {
|
|
64
|
+
if (endipv6Encountered === true) {
|
|
65
|
+
endIpv6 = true
|
|
66
|
+
}
|
|
67
|
+
if (!consume()) { break }
|
|
68
|
+
tokenCount++
|
|
69
|
+
address.push(':')
|
|
70
|
+
if (tokenCount > 7) {
|
|
71
|
+
// not valid
|
|
72
|
+
output.error = true
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
if (i - 1 >= 0 && input[i - 1] === ':') {
|
|
76
|
+
endipv6Encountered = true
|
|
77
|
+
}
|
|
78
|
+
continue
|
|
79
|
+
} else if (cursor === '%') {
|
|
80
|
+
if (!consume()) { break }
|
|
81
|
+
// switch to zone detection
|
|
82
|
+
isZone = true
|
|
83
|
+
} else {
|
|
84
|
+
buffer.push(cursor)
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (buffer.length) {
|
|
89
|
+
if (isZone) {
|
|
90
|
+
output.zone = buffer.join('')
|
|
91
|
+
} else if (endIpv6) {
|
|
92
|
+
address.push(buffer.join(''))
|
|
93
|
+
} else {
|
|
94
|
+
address.push(stringArrayToHexStripped(buffer))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
output.address = address.join('')
|
|
98
|
+
return output
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeIPv6 (host) {
|
|
102
|
+
if (findToken(host, ':') < 2) { return { host, isIPV6: false } }
|
|
103
|
+
const ipv6 = getIPV6(host)
|
|
104
|
+
|
|
105
|
+
if (!ipv6.error) {
|
|
106
|
+
let newHost = ipv6.address
|
|
107
|
+
let escapedHost = ipv6.address
|
|
108
|
+
if (ipv6.zone) {
|
|
109
|
+
newHost += '%' + ipv6.zone
|
|
110
|
+
escapedHost += '%25' + ipv6.zone
|
|
111
|
+
}
|
|
112
|
+
return { host: newHost, escapedHost, isIPV6: true }
|
|
113
|
+
} else {
|
|
114
|
+
return { host, isIPV6: false }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
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
|
+
|
|
141
|
+
function findToken (str, token) {
|
|
142
|
+
let ind = 0
|
|
143
|
+
for (let i = 0; i < str.length; i++) {
|
|
144
|
+
if (str[i] === token) ind++
|
|
145
|
+
}
|
|
146
|
+
return ind
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const RDS1 = /^\.\.?\//u
|
|
150
|
+
const RDS2 = /^\/\.(?:\/|$)/u
|
|
151
|
+
const RDS3 = /^\/\.\.(?:\/|$)/u
|
|
152
|
+
const RDS5 = /^\/?(?:.|\n)*?(?=\/|$)/u
|
|
153
|
+
|
|
154
|
+
function removeDotSegments (input) {
|
|
155
|
+
const output = []
|
|
156
|
+
|
|
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)
|
|
173
|
+
} else {
|
|
174
|
+
throw new Error('Unexpected dot segment condition')
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return output.join('')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function normalizeComponentEncoding (components, esc) {
|
|
182
|
+
const func = esc !== true ? escape : unescape
|
|
183
|
+
if (components.scheme !== undefined) {
|
|
184
|
+
components.scheme = func(components.scheme)
|
|
185
|
+
}
|
|
186
|
+
if (components.userinfo !== undefined) {
|
|
187
|
+
components.userinfo = func(components.userinfo)
|
|
188
|
+
}
|
|
189
|
+
if (components.host !== undefined) {
|
|
190
|
+
components.host = func(components.host)
|
|
191
|
+
}
|
|
192
|
+
if (components.path !== undefined) {
|
|
193
|
+
components.path = func(components.path)
|
|
194
|
+
}
|
|
195
|
+
if (components.query !== undefined) {
|
|
196
|
+
components.query = func(components.query)
|
|
197
|
+
}
|
|
198
|
+
if (components.fragment !== undefined) {
|
|
199
|
+
components.fragment = func(components.fragment)
|
|
200
|
+
}
|
|
201
|
+
return components
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function recomposeAuthority (components) {
|
|
205
|
+
const uriTokens = []
|
|
206
|
+
|
|
207
|
+
if (components.userinfo !== undefined) {
|
|
208
|
+
uriTokens.push(components.userinfo)
|
|
209
|
+
uriTokens.push('@')
|
|
210
|
+
}
|
|
211
|
+
|
|
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)
|
|
220
|
+
if (ipV6res.isIPV6 === true) {
|
|
221
|
+
host = `[${ipV6res.escapedHost}]`
|
|
222
|
+
} else {
|
|
223
|
+
host = components.host
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
uriTokens.push(host)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (typeof components.port === 'number' || typeof components.port === 'string') {
|
|
230
|
+
uriTokens.push(':')
|
|
231
|
+
uriTokens.push(String(components.port))
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return uriTokens.length ? uriTokens.join('') : undefined
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
module.exports = {
|
|
238
|
+
recomposeAuthority,
|
|
239
|
+
normalizeComponentEncoding,
|
|
240
|
+
removeDotSegments,
|
|
241
|
+
normalizeIPv4,
|
|
242
|
+
normalizeIPv6,
|
|
243
|
+
stringArrayToHexStripped
|
|
244
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var traverse = module.exports = function (schema, opts, cb) {
|
|
4
|
+
// Legacy support for v0.3.1 and earlier.
|
|
5
|
+
if (typeof opts == 'function') {
|
|
6
|
+
cb = opts;
|
|
7
|
+
opts = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
cb = opts.cb || cb;
|
|
11
|
+
var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};
|
|
12
|
+
var post = cb.post || function() {};
|
|
13
|
+
|
|
14
|
+
_traverse(opts, pre, post, schema, '', schema);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
traverse.keywords = {
|
|
19
|
+
additionalItems: true,
|
|
20
|
+
items: true,
|
|
21
|
+
contains: true,
|
|
22
|
+
additionalProperties: true,
|
|
23
|
+
propertyNames: true,
|
|
24
|
+
not: true
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
traverse.arrayKeywords = {
|
|
28
|
+
items: true,
|
|
29
|
+
allOf: true,
|
|
30
|
+
anyOf: true,
|
|
31
|
+
oneOf: true
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
traverse.propsKeywords = {
|
|
35
|
+
definitions: true,
|
|
36
|
+
properties: true,
|
|
37
|
+
patternProperties: true,
|
|
38
|
+
dependencies: true
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
traverse.skipKeywords = {
|
|
42
|
+
default: true,
|
|
43
|
+
enum: true,
|
|
44
|
+
const: true,
|
|
45
|
+
required: true,
|
|
46
|
+
maximum: true,
|
|
47
|
+
minimum: true,
|
|
48
|
+
exclusiveMaximum: true,
|
|
49
|
+
exclusiveMinimum: true,
|
|
50
|
+
multipleOf: true,
|
|
51
|
+
maxLength: true,
|
|
52
|
+
minLength: true,
|
|
53
|
+
pattern: true,
|
|
54
|
+
format: true,
|
|
55
|
+
maxItems: true,
|
|
56
|
+
minItems: true,
|
|
57
|
+
uniqueItems: true,
|
|
58
|
+
maxProperties: true,
|
|
59
|
+
minProperties: true
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
|
64
|
+
if (schema && typeof schema == 'object' && !Array.isArray(schema)) {
|
|
65
|
+
pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
66
|
+
for (var key in schema) {
|
|
67
|
+
var sch = schema[key];
|
|
68
|
+
if (Array.isArray(sch)) {
|
|
69
|
+
if (key in traverse.arrayKeywords) {
|
|
70
|
+
for (var i=0; i<sch.length; i++)
|
|
71
|
+
_traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);
|
|
72
|
+
}
|
|
73
|
+
} else if (key in traverse.propsKeywords) {
|
|
74
|
+
if (sch && typeof sch == 'object') {
|
|
75
|
+
for (var prop in sch)
|
|
76
|
+
_traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
|
|
77
|
+
}
|
|
78
|
+
} else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {
|
|
79
|
+
_traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function escapeJsonPtr(str) {
|
|
88
|
+
return str.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
89
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const ANY = Symbol('SemVer ANY')
|
|
4
|
+
// hoisted class for cyclic dependency
|
|
5
|
+
class Comparator {
|
|
6
|
+
static get ANY () {
|
|
7
|
+
return ANY
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor (comp, options) {
|
|
11
|
+
options = parseOptions(options)
|
|
12
|
+
|
|
13
|
+
if (comp instanceof Comparator) {
|
|
14
|
+
if (comp.loose === !!options.loose) {
|
|
15
|
+
return comp
|
|
16
|
+
} else {
|
|
17
|
+
comp = comp.value
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
comp = comp.trim().split(/\s+/).join(' ')
|
|
22
|
+
debug('comparator', comp, options)
|
|
23
|
+
this.options = options
|
|
24
|
+
this.loose = !!options.loose
|
|
25
|
+
this.parse(comp)
|
|
26
|
+
|
|
27
|
+
if (this.semver === ANY) {
|
|
28
|
+
this.value = ''
|
|
29
|
+
} else {
|
|
30
|
+
this.value = this.operator + this.semver.version
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
debug('comp', this)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
parse (comp) {
|
|
37
|
+
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
|
38
|
+
const m = comp.match(r)
|
|
39
|
+
|
|
40
|
+
if (!m) {
|
|
41
|
+
throw new TypeError(`Invalid comparator: ${comp}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.operator = m[1] !== undefined ? m[1] : ''
|
|
45
|
+
if (this.operator === '=') {
|
|
46
|
+
this.operator = ''
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// if it literally is just '>' or '' then allow anything.
|
|
50
|
+
if (!m[2]) {
|
|
51
|
+
this.semver = ANY
|
|
52
|
+
} else {
|
|
53
|
+
this.semver = new SemVer(m[2], this.options.loose)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toString () {
|
|
58
|
+
return this.value
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test (version) {
|
|
62
|
+
debug('Comparator.test', version, this.options.loose)
|
|
63
|
+
|
|
64
|
+
if (this.semver === ANY || version === ANY) {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof version === 'string') {
|
|
69
|
+
try {
|
|
70
|
+
version = new SemVer(version, this.options)
|
|
71
|
+
} catch (er) {
|
|
72
|
+
return false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return cmp(version, this.operator, this.semver, this.options)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
intersects (comp, options) {
|
|
80
|
+
if (!(comp instanceof Comparator)) {
|
|
81
|
+
throw new TypeError('a Comparator is required')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.operator === '') {
|
|
85
|
+
if (this.value === '') {
|
|
86
|
+
return true
|
|
87
|
+
}
|
|
88
|
+
return new Range(comp.value, options).test(this.value)
|
|
89
|
+
} else if (comp.operator === '') {
|
|
90
|
+
if (comp.value === '') {
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
return new Range(this.value, options).test(comp.semver)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
options = parseOptions(options)
|
|
97
|
+
|
|
98
|
+
// Special cases where nothing can possibly be lower
|
|
99
|
+
if (options.includePrerelease &&
|
|
100
|
+
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
if (!options.includePrerelease &&
|
|
104
|
+
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Same direction increasing (> or >=)
|
|
109
|
+
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
// Same direction decreasing (< or <=)
|
|
113
|
+
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
// same SemVer and both sides are inclusive (<= or >=)
|
|
117
|
+
if (
|
|
118
|
+
(this.semver.version === comp.semver.version) &&
|
|
119
|
+
this.operator.includes('=') && comp.operator.includes('=')) {
|
|
120
|
+
return true
|
|
121
|
+
}
|
|
122
|
+
// opposite directions less than
|
|
123
|
+
if (cmp(this.semver, '<', comp.semver, options) &&
|
|
124
|
+
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
|
|
125
|
+
return true
|
|
126
|
+
}
|
|
127
|
+
// opposite directions greater than
|
|
128
|
+
if (cmp(this.semver, '>', comp.semver, options) &&
|
|
129
|
+
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
return false
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = Comparator
|
|
137
|
+
|
|
138
|
+
const parseOptions = require('../internal/parse-options.js')
|
|
139
|
+
const { safeRe: re, t } = require('../internal/re.js')
|
|
140
|
+
const cmp = require('../functions/cmp.js')
|
|
141
|
+
const debug = require('../internal/debug.js')
|
|
142
|
+
const SemVer = require('./semver.js')
|
|
143
|
+
const Range = require('./range.js')
|