@tachybase/module-backup 0.23.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/.turbo/turbo-build.log +12 -0
  2. package/README.md +118 -0
  3. package/README.zh-CN.md +118 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/Configuration.d.ts +2 -0
  7. package/dist/client/DuplicatorProvider.d.ts +5 -0
  8. package/dist/client/index.d.ts +5 -0
  9. package/dist/client/index.js +1 -0
  10. package/dist/client/locale/index.d.ts +4 -0
  11. package/dist/externalVersion.js +14 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +39 -0
  14. package/dist/locale/en-US.json +44 -0
  15. package/dist/locale/ja-JP.d.ts +25 -0
  16. package/dist/locale/ja-JP.js +46 -0
  17. package/dist/locale/ko_KR.json +50 -0
  18. package/dist/locale/pt-BR.d.ts +26 -0
  19. package/dist/locale/pt-BR.js +48 -0
  20. package/dist/locale/zh-CN.json +50 -0
  21. package/dist/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  22. package/dist/node_modules/@hapi/topo/lib/index.js +1 -0
  23. package/dist/node_modules/@hapi/topo/package.json +1 -0
  24. package/dist/node_modules/archiver/LICENSE +22 -0
  25. package/dist/node_modules/archiver/index.js +68 -0
  26. package/dist/node_modules/archiver/lib/core.js +974 -0
  27. package/dist/node_modules/archiver/lib/error.js +40 -0
  28. package/dist/node_modules/archiver/lib/plugins/json.js +110 -0
  29. package/dist/node_modules/archiver/lib/plugins/tar.js +167 -0
  30. package/dist/node_modules/archiver/lib/plugins/zip.js +120 -0
  31. package/dist/node_modules/archiver/package.json +1 -0
  32. package/dist/node_modules/decompress/index.js +16 -0
  33. package/dist/node_modules/decompress/license +9 -0
  34. package/dist/node_modules/decompress/package.json +1 -0
  35. package/dist/node_modules/mkdirp/LICENSE +21 -0
  36. package/dist/node_modules/mkdirp/bin/cmd.js +68 -0
  37. package/dist/node_modules/mkdirp/index.js +1 -0
  38. package/dist/node_modules/mkdirp/lib/find-made.js +29 -0
  39. package/dist/node_modules/mkdirp/lib/mkdirp-manual.js +64 -0
  40. package/dist/node_modules/mkdirp/lib/mkdirp-native.js +39 -0
  41. package/dist/node_modules/mkdirp/lib/opts-arg.js +23 -0
  42. package/dist/node_modules/mkdirp/lib/path-arg.js +29 -0
  43. package/dist/node_modules/mkdirp/lib/use-native.js +10 -0
  44. package/dist/node_modules/mkdirp/package.json +1 -0
  45. package/dist/node_modules/mkdirp/readme.markdown +266 -0
  46. package/dist/node_modules/semver/LICENSE +15 -0
  47. package/dist/node_modules/semver/bin/semver.js +188 -0
  48. package/dist/node_modules/semver/classes/comparator.js +141 -0
  49. package/dist/node_modules/semver/classes/index.js +5 -0
  50. package/dist/node_modules/semver/classes/range.js +554 -0
  51. package/dist/node_modules/semver/classes/semver.js +302 -0
  52. package/dist/node_modules/semver/functions/clean.js +6 -0
  53. package/dist/node_modules/semver/functions/cmp.js +52 -0
  54. package/dist/node_modules/semver/functions/coerce.js +60 -0
  55. package/dist/node_modules/semver/functions/compare-build.js +7 -0
  56. package/dist/node_modules/semver/functions/compare-loose.js +3 -0
  57. package/dist/node_modules/semver/functions/compare.js +5 -0
  58. package/dist/node_modules/semver/functions/diff.js +65 -0
  59. package/dist/node_modules/semver/functions/eq.js +3 -0
  60. package/dist/node_modules/semver/functions/gt.js +3 -0
  61. package/dist/node_modules/semver/functions/gte.js +3 -0
  62. package/dist/node_modules/semver/functions/inc.js +19 -0
  63. package/dist/node_modules/semver/functions/lt.js +3 -0
  64. package/dist/node_modules/semver/functions/lte.js +3 -0
  65. package/dist/node_modules/semver/functions/major.js +3 -0
  66. package/dist/node_modules/semver/functions/minor.js +3 -0
  67. package/dist/node_modules/semver/functions/neq.js +3 -0
  68. package/dist/node_modules/semver/functions/parse.js +16 -0
  69. package/dist/node_modules/semver/functions/patch.js +3 -0
  70. package/dist/node_modules/semver/functions/prerelease.js +6 -0
  71. package/dist/node_modules/semver/functions/rcompare.js +3 -0
  72. package/dist/node_modules/semver/functions/rsort.js +3 -0
  73. package/dist/node_modules/semver/functions/satisfies.js +10 -0
  74. package/dist/node_modules/semver/functions/sort.js +3 -0
  75. package/dist/node_modules/semver/functions/valid.js +6 -0
  76. package/dist/node_modules/semver/index.js +1 -0
  77. package/dist/node_modules/semver/internal/constants.js +35 -0
  78. package/dist/node_modules/semver/internal/debug.js +9 -0
  79. package/dist/node_modules/semver/internal/identifiers.js +23 -0
  80. package/dist/node_modules/semver/internal/lrucache.js +40 -0
  81. package/dist/node_modules/semver/internal/parse-options.js +15 -0
  82. package/dist/node_modules/semver/internal/re.js +217 -0
  83. package/dist/node_modules/semver/package.json +1 -0
  84. package/dist/node_modules/semver/preload.js +2 -0
  85. package/dist/node_modules/semver/range.bnf +16 -0
  86. package/dist/node_modules/semver/ranges/gtr.js +4 -0
  87. package/dist/node_modules/semver/ranges/intersects.js +7 -0
  88. package/dist/node_modules/semver/ranges/ltr.js +4 -0
  89. package/dist/node_modules/semver/ranges/max-satisfying.js +25 -0
  90. package/dist/node_modules/semver/ranges/min-satisfying.js +24 -0
  91. package/dist/node_modules/semver/ranges/min-version.js +61 -0
  92. package/dist/node_modules/semver/ranges/outside.js +80 -0
  93. package/dist/node_modules/semver/ranges/simplify.js +47 -0
  94. package/dist/node_modules/semver/ranges/subset.js +247 -0
  95. package/dist/node_modules/semver/ranges/to-comparators.js +8 -0
  96. package/dist/node_modules/semver/ranges/valid.js +11 -0
  97. package/dist/server/app-migrator.d.ts +16 -0
  98. package/dist/server/app-migrator.js +61 -0
  99. package/dist/server/collection-group-manager.d.ts +4 -0
  100. package/dist/server/collection-group-manager.js +29 -0
  101. package/dist/server/commands/restore-command.d.ts +2 -0
  102. package/dist/server/commands/restore-command.js +67 -0
  103. package/dist/server/dumper.d.ts +71 -0
  104. package/dist/server/dumper.js +421 -0
  105. package/dist/server/errors/restore-check-error.d.ts +3 -0
  106. package/dist/server/errors/restore-check-error.js +32 -0
  107. package/dist/server/field-value-writer.d.ts +9 -0
  108. package/dist/server/field-value-writer.js +99 -0
  109. package/dist/server/index.d.ts +1 -0
  110. package/dist/server/index.js +33 -0
  111. package/dist/server/locale/zh-CN.d.ts +9 -0
  112. package/dist/server/locale/zh-CN.js +30 -0
  113. package/dist/server/resourcers/backup-files.d.ts +25 -0
  114. package/dist/server/resourcers/backup-files.js +206 -0
  115. package/dist/server/restorer.d.ts +35 -0
  116. package/dist/server/restorer.js +320 -0
  117. package/dist/server/server.d.ts +8 -0
  118. package/dist/server/server.js +52 -0
  119. package/dist/server/utils.d.ts +5 -0
  120. package/dist/server/utils.js +78 -0
  121. package/dist/swagger/index.d.ts +392 -0
  122. package/dist/swagger/index.js +447 -0
  123. package/package.json +48 -0
  124. package/server.d.ts +2 -0
  125. package/server.js +1 -0
@@ -0,0 +1,141 @@
1
+ const ANY = Symbol('SemVer ANY')
2
+ // hoisted class for cyclic dependency
3
+ class Comparator {
4
+ static get ANY () {
5
+ return ANY
6
+ }
7
+
8
+ constructor (comp, options) {
9
+ options = parseOptions(options)
10
+
11
+ if (comp instanceof Comparator) {
12
+ if (comp.loose === !!options.loose) {
13
+ return comp
14
+ } else {
15
+ comp = comp.value
16
+ }
17
+ }
18
+
19
+ comp = comp.trim().split(/\s+/).join(' ')
20
+ debug('comparator', comp, options)
21
+ this.options = options
22
+ this.loose = !!options.loose
23
+ this.parse(comp)
24
+
25
+ if (this.semver === ANY) {
26
+ this.value = ''
27
+ } else {
28
+ this.value = this.operator + this.semver.version
29
+ }
30
+
31
+ debug('comp', this)
32
+ }
33
+
34
+ parse (comp) {
35
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
36
+ const m = comp.match(r)
37
+
38
+ if (!m) {
39
+ throw new TypeError(`Invalid comparator: ${comp}`)
40
+ }
41
+
42
+ this.operator = m[1] !== undefined ? m[1] : ''
43
+ if (this.operator === '=') {
44
+ this.operator = ''
45
+ }
46
+
47
+ // if it literally is just '>' or '' then allow anything.
48
+ if (!m[2]) {
49
+ this.semver = ANY
50
+ } else {
51
+ this.semver = new SemVer(m[2], this.options.loose)
52
+ }
53
+ }
54
+
55
+ toString () {
56
+ return this.value
57
+ }
58
+
59
+ test (version) {
60
+ debug('Comparator.test', version, this.options.loose)
61
+
62
+ if (this.semver === ANY || version === ANY) {
63
+ return true
64
+ }
65
+
66
+ if (typeof version === 'string') {
67
+ try {
68
+ version = new SemVer(version, this.options)
69
+ } catch (er) {
70
+ return false
71
+ }
72
+ }
73
+
74
+ return cmp(version, this.operator, this.semver, this.options)
75
+ }
76
+
77
+ intersects (comp, options) {
78
+ if (!(comp instanceof Comparator)) {
79
+ throw new TypeError('a Comparator is required')
80
+ }
81
+
82
+ if (this.operator === '') {
83
+ if (this.value === '') {
84
+ return true
85
+ }
86
+ return new Range(comp.value, options).test(this.value)
87
+ } else if (comp.operator === '') {
88
+ if (comp.value === '') {
89
+ return true
90
+ }
91
+ return new Range(this.value, options).test(comp.semver)
92
+ }
93
+
94
+ options = parseOptions(options)
95
+
96
+ // Special cases where nothing can possibly be lower
97
+ if (options.includePrerelease &&
98
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
99
+ return false
100
+ }
101
+ if (!options.includePrerelease &&
102
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
103
+ return false
104
+ }
105
+
106
+ // Same direction increasing (> or >=)
107
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
108
+ return true
109
+ }
110
+ // Same direction decreasing (< or <=)
111
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
112
+ return true
113
+ }
114
+ // same SemVer and both sides are inclusive (<= or >=)
115
+ if (
116
+ (this.semver.version === comp.semver.version) &&
117
+ this.operator.includes('=') && comp.operator.includes('=')) {
118
+ return true
119
+ }
120
+ // opposite directions less than
121
+ if (cmp(this.semver, '<', comp.semver, options) &&
122
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
123
+ return true
124
+ }
125
+ // opposite directions greater than
126
+ if (cmp(this.semver, '>', comp.semver, options) &&
127
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
128
+ return true
129
+ }
130
+ return false
131
+ }
132
+ }
133
+
134
+ module.exports = Comparator
135
+
136
+ const parseOptions = require('../internal/parse-options')
137
+ const { safeRe: re, t } = require('../internal/re')
138
+ const cmp = require('../functions/cmp')
139
+ const debug = require('../internal/debug')
140
+ const SemVer = require('./semver')
141
+ const Range = require('./range')
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ SemVer: require('./semver.js'),
3
+ Range: require('./range.js'),
4
+ Comparator: require('./comparator.js'),
5
+ }
@@ -0,0 +1,554 @@
1
+ const SPACE_CHARACTERS = /\s+/g
2
+
3
+ // hoisted class for cyclic dependency
4
+ class Range {
5
+ constructor (range, options) {
6
+ options = parseOptions(options)
7
+
8
+ if (range instanceof Range) {
9
+ if (
10
+ range.loose === !!options.loose &&
11
+ range.includePrerelease === !!options.includePrerelease
12
+ ) {
13
+ return range
14
+ } else {
15
+ return new Range(range.raw, options)
16
+ }
17
+ }
18
+
19
+ if (range instanceof Comparator) {
20
+ // just put it in the set and return
21
+ this.raw = range.value
22
+ this.set = [[range]]
23
+ this.formatted = undefined
24
+ return this
25
+ }
26
+
27
+ this.options = options
28
+ this.loose = !!options.loose
29
+ this.includePrerelease = !!options.includePrerelease
30
+
31
+ // First reduce all whitespace as much as possible so we do not have to rely
32
+ // on potentially slow regexes like \s*. This is then stored and used for
33
+ // future error messages as well.
34
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ')
35
+
36
+ // First, split on ||
37
+ this.set = this.raw
38
+ .split('||')
39
+ // map the range to a 2d array of comparators
40
+ .map(r => this.parseRange(r.trim()))
41
+ // throw out any comparator lists that are empty
42
+ // this generally means that it was not a valid range, which is allowed
43
+ // in loose mode, but will still throw if the WHOLE range is invalid.
44
+ .filter(c => c.length)
45
+
46
+ if (!this.set.length) {
47
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
48
+ }
49
+
50
+ // if we have any that are not the null set, throw out null sets.
51
+ if (this.set.length > 1) {
52
+ // keep the first one, in case they're all null sets
53
+ const first = this.set[0]
54
+ this.set = this.set.filter(c => !isNullSet(c[0]))
55
+ if (this.set.length === 0) {
56
+ this.set = [first]
57
+ } else if (this.set.length > 1) {
58
+ // if we have any that are *, then the range is just *
59
+ for (const c of this.set) {
60
+ if (c.length === 1 && isAny(c[0])) {
61
+ this.set = [c]
62
+ break
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ this.formatted = undefined
69
+ }
70
+
71
+ get range () {
72
+ if (this.formatted === undefined) {
73
+ this.formatted = ''
74
+ for (let i = 0; i < this.set.length; i++) {
75
+ if (i > 0) {
76
+ this.formatted += '||'
77
+ }
78
+ const comps = this.set[i]
79
+ for (let k = 0; k < comps.length; k++) {
80
+ if (k > 0) {
81
+ this.formatted += ' '
82
+ }
83
+ this.formatted += comps[k].toString().trim()
84
+ }
85
+ }
86
+ }
87
+ return this.formatted
88
+ }
89
+
90
+ format () {
91
+ return this.range
92
+ }
93
+
94
+ toString () {
95
+ return this.range
96
+ }
97
+
98
+ parseRange (range) {
99
+ // memoize range parsing for performance.
100
+ // this is a very hot path, and fully deterministic.
101
+ const memoOpts =
102
+ (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
103
+ (this.options.loose && FLAG_LOOSE)
104
+ const memoKey = memoOpts + ':' + range
105
+ const cached = cache.get(memoKey)
106
+ if (cached) {
107
+ return cached
108
+ }
109
+
110
+ const loose = this.options.loose
111
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
112
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
113
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease))
114
+ debug('hyphen replace', range)
115
+
116
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
117
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
118
+ debug('comparator trim', range)
119
+
120
+ // `~ 1.2.3` => `~1.2.3`
121
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
122
+ debug('tilde trim', range)
123
+
124
+ // `^ 1.2.3` => `^1.2.3`
125
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace)
126
+ debug('caret trim', range)
127
+
128
+ // At this point, the range is completely trimmed and
129
+ // ready to be split into comparators.
130
+
131
+ let rangeList = range
132
+ .split(' ')
133
+ .map(comp => parseComparator(comp, this.options))
134
+ .join(' ')
135
+ .split(/\s+/)
136
+ // >=0.0.0 is equivalent to *
137
+ .map(comp => replaceGTE0(comp, this.options))
138
+
139
+ if (loose) {
140
+ // in loose mode, throw out any that are not valid comparators
141
+ rangeList = rangeList.filter(comp => {
142
+ debug('loose invalid filter', comp, this.options)
143
+ return !!comp.match(re[t.COMPARATORLOOSE])
144
+ })
145
+ }
146
+ debug('range list', rangeList)
147
+
148
+ // if any comparators are the null set, then replace with JUST null set
149
+ // if more than one comparator, remove any * comparators
150
+ // also, don't include the same comparator more than once
151
+ const rangeMap = new Map()
152
+ const comparators = rangeList.map(comp => new Comparator(comp, this.options))
153
+ for (const comp of comparators) {
154
+ if (isNullSet(comp)) {
155
+ return [comp]
156
+ }
157
+ rangeMap.set(comp.value, comp)
158
+ }
159
+ if (rangeMap.size > 1 && rangeMap.has('')) {
160
+ rangeMap.delete('')
161
+ }
162
+
163
+ const result = [...rangeMap.values()]
164
+ cache.set(memoKey, result)
165
+ return result
166
+ }
167
+
168
+ intersects (range, options) {
169
+ if (!(range instanceof Range)) {
170
+ throw new TypeError('a Range is required')
171
+ }
172
+
173
+ return this.set.some((thisComparators) => {
174
+ return (
175
+ isSatisfiable(thisComparators, options) &&
176
+ range.set.some((rangeComparators) => {
177
+ return (
178
+ isSatisfiable(rangeComparators, options) &&
179
+ thisComparators.every((thisComparator) => {
180
+ return rangeComparators.every((rangeComparator) => {
181
+ return thisComparator.intersects(rangeComparator, options)
182
+ })
183
+ })
184
+ )
185
+ })
186
+ )
187
+ })
188
+ }
189
+
190
+ // if ANY of the sets match ALL of its comparators, then pass
191
+ test (version) {
192
+ if (!version) {
193
+ return false
194
+ }
195
+
196
+ if (typeof version === 'string') {
197
+ try {
198
+ version = new SemVer(version, this.options)
199
+ } catch (er) {
200
+ return false
201
+ }
202
+ }
203
+
204
+ for (let i = 0; i < this.set.length; i++) {
205
+ if (testSet(this.set[i], version, this.options)) {
206
+ return true
207
+ }
208
+ }
209
+ return false
210
+ }
211
+ }
212
+
213
+ module.exports = Range
214
+
215
+ const LRU = require('../internal/lrucache')
216
+ const cache = new LRU()
217
+
218
+ const parseOptions = require('../internal/parse-options')
219
+ const Comparator = require('./comparator')
220
+ const debug = require('../internal/debug')
221
+ const SemVer = require('./semver')
222
+ const {
223
+ safeRe: re,
224
+ t,
225
+ comparatorTrimReplace,
226
+ tildeTrimReplace,
227
+ caretTrimReplace,
228
+ } = require('../internal/re')
229
+ const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')
230
+
231
+ const isNullSet = c => c.value === '<0.0.0-0'
232
+ const isAny = c => c.value === ''
233
+
234
+ // take a set of comparators and determine whether there
235
+ // exists a version which can satisfy it
236
+ const isSatisfiable = (comparators, options) => {
237
+ let result = true
238
+ const remainingComparators = comparators.slice()
239
+ let testComparator = remainingComparators.pop()
240
+
241
+ while (result && remainingComparators.length) {
242
+ result = remainingComparators.every((otherComparator) => {
243
+ return testComparator.intersects(otherComparator, options)
244
+ })
245
+
246
+ testComparator = remainingComparators.pop()
247
+ }
248
+
249
+ return result
250
+ }
251
+
252
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
253
+ // already replaced the hyphen ranges
254
+ // turn into a set of JUST comparators.
255
+ const parseComparator = (comp, options) => {
256
+ debug('comp', comp, options)
257
+ comp = replaceCarets(comp, options)
258
+ debug('caret', comp)
259
+ comp = replaceTildes(comp, options)
260
+ debug('tildes', comp)
261
+ comp = replaceXRanges(comp, options)
262
+ debug('xrange', comp)
263
+ comp = replaceStars(comp, options)
264
+ debug('stars', comp)
265
+ return comp
266
+ }
267
+
268
+ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
269
+
270
+ // ~, ~> --> * (any, kinda silly)
271
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
272
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
273
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
274
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
275
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
276
+ // ~0.0.1 --> >=0.0.1 <0.1.0-0
277
+ const replaceTildes = (comp, options) => {
278
+ return comp
279
+ .trim()
280
+ .split(/\s+/)
281
+ .map((c) => replaceTilde(c, options))
282
+ .join(' ')
283
+ }
284
+
285
+ const replaceTilde = (comp, options) => {
286
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
287
+ return comp.replace(r, (_, M, m, p, pr) => {
288
+ debug('tilde', comp, _, M, m, p, pr)
289
+ let ret
290
+
291
+ if (isX(M)) {
292
+ ret = ''
293
+ } else if (isX(m)) {
294
+ ret = `>=${M}.0.0 <${+M + 1}.0.0-0`
295
+ } else if (isX(p)) {
296
+ // ~1.2 == >=1.2.0 <1.3.0-0
297
+ ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`
298
+ } else if (pr) {
299
+ debug('replaceTilde pr', pr)
300
+ ret = `>=${M}.${m}.${p}-${pr
301
+ } <${M}.${+m + 1}.0-0`
302
+ } else {
303
+ // ~1.2.3 == >=1.2.3 <1.3.0-0
304
+ ret = `>=${M}.${m}.${p
305
+ } <${M}.${+m + 1}.0-0`
306
+ }
307
+
308
+ debug('tilde return', ret)
309
+ return ret
310
+ })
311
+ }
312
+
313
+ // ^ --> * (any, kinda silly)
314
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
315
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
316
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
317
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
318
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
319
+ // ^0.0.1 --> >=0.0.1 <0.0.2-0
320
+ // ^0.1.0 --> >=0.1.0 <0.2.0-0
321
+ const replaceCarets = (comp, options) => {
322
+ return comp
323
+ .trim()
324
+ .split(/\s+/)
325
+ .map((c) => replaceCaret(c, options))
326
+ .join(' ')
327
+ }
328
+
329
+ const replaceCaret = (comp, options) => {
330
+ debug('caret', comp, options)
331
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
332
+ const z = options.includePrerelease ? '-0' : ''
333
+ return comp.replace(r, (_, M, m, p, pr) => {
334
+ debug('caret', comp, _, M, m, p, pr)
335
+ let ret
336
+
337
+ if (isX(M)) {
338
+ ret = ''
339
+ } else if (isX(m)) {
340
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`
341
+ } else if (isX(p)) {
342
+ if (M === '0') {
343
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`
344
+ } else {
345
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`
346
+ }
347
+ } else if (pr) {
348
+ debug('replaceCaret pr', pr)
349
+ if (M === '0') {
350
+ if (m === '0') {
351
+ ret = `>=${M}.${m}.${p}-${pr
352
+ } <${M}.${m}.${+p + 1}-0`
353
+ } else {
354
+ ret = `>=${M}.${m}.${p}-${pr
355
+ } <${M}.${+m + 1}.0-0`
356
+ }
357
+ } else {
358
+ ret = `>=${M}.${m}.${p}-${pr
359
+ } <${+M + 1}.0.0-0`
360
+ }
361
+ } else {
362
+ debug('no pr')
363
+ if (M === '0') {
364
+ if (m === '0') {
365
+ ret = `>=${M}.${m}.${p
366
+ }${z} <${M}.${m}.${+p + 1}-0`
367
+ } else {
368
+ ret = `>=${M}.${m}.${p
369
+ }${z} <${M}.${+m + 1}.0-0`
370
+ }
371
+ } else {
372
+ ret = `>=${M}.${m}.${p
373
+ } <${+M + 1}.0.0-0`
374
+ }
375
+ }
376
+
377
+ debug('caret return', ret)
378
+ return ret
379
+ })
380
+ }
381
+
382
+ const replaceXRanges = (comp, options) => {
383
+ debug('replaceXRanges', comp, options)
384
+ return comp
385
+ .split(/\s+/)
386
+ .map((c) => replaceXRange(c, options))
387
+ .join(' ')
388
+ }
389
+
390
+ const replaceXRange = (comp, options) => {
391
+ comp = comp.trim()
392
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
393
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
394
+ debug('xRange', comp, ret, gtlt, M, m, p, pr)
395
+ const xM = isX(M)
396
+ const xm = xM || isX(m)
397
+ const xp = xm || isX(p)
398
+ const anyX = xp
399
+
400
+ if (gtlt === '=' && anyX) {
401
+ gtlt = ''
402
+ }
403
+
404
+ // if we're including prereleases in the match, then we need
405
+ // to fix this to -0, the lowest possible prerelease value
406
+ pr = options.includePrerelease ? '-0' : ''
407
+
408
+ if (xM) {
409
+ if (gtlt === '>' || gtlt === '<') {
410
+ // nothing is allowed
411
+ ret = '<0.0.0-0'
412
+ } else {
413
+ // nothing is forbidden
414
+ ret = '*'
415
+ }
416
+ } else if (gtlt && anyX) {
417
+ // we know patch is an x, because we have any x at all.
418
+ // replace X with 0
419
+ if (xm) {
420
+ m = 0
421
+ }
422
+ p = 0
423
+
424
+ if (gtlt === '>') {
425
+ // >1 => >=2.0.0
426
+ // >1.2 => >=1.3.0
427
+ gtlt = '>='
428
+ if (xm) {
429
+ M = +M + 1
430
+ m = 0
431
+ p = 0
432
+ } else {
433
+ m = +m + 1
434
+ p = 0
435
+ }
436
+ } else if (gtlt === '<=') {
437
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
438
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
439
+ gtlt = '<'
440
+ if (xm) {
441
+ M = +M + 1
442
+ } else {
443
+ m = +m + 1
444
+ }
445
+ }
446
+
447
+ if (gtlt === '<') {
448
+ pr = '-0'
449
+ }
450
+
451
+ ret = `${gtlt + M}.${m}.${p}${pr}`
452
+ } else if (xm) {
453
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`
454
+ } else if (xp) {
455
+ ret = `>=${M}.${m}.0${pr
456
+ } <${M}.${+m + 1}.0-0`
457
+ }
458
+
459
+ debug('xRange return', ret)
460
+
461
+ return ret
462
+ })
463
+ }
464
+
465
+ // Because * is AND-ed with everything else in the comparator,
466
+ // and '' means "any version", just remove the *s entirely.
467
+ const replaceStars = (comp, options) => {
468
+ debug('replaceStars', comp, options)
469
+ // Looseness is ignored here. star is always as loose as it gets!
470
+ return comp
471
+ .trim()
472
+ .replace(re[t.STAR], '')
473
+ }
474
+
475
+ const replaceGTE0 = (comp, options) => {
476
+ debug('replaceGTE0', comp, options)
477
+ return comp
478
+ .trim()
479
+ .replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
480
+ }
481
+
482
+ // This function is passed to string.replace(re[t.HYPHENRANGE])
483
+ // M, m, patch, prerelease, build
484
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
485
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
486
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0-0
487
+ // TODO build?
488
+ const hyphenReplace = incPr => ($0,
489
+ from, fM, fm, fp, fpr, fb,
490
+ to, tM, tm, tp, tpr) => {
491
+ if (isX(fM)) {
492
+ from = ''
493
+ } else if (isX(fm)) {
494
+ from = `>=${fM}.0.0${incPr ? '-0' : ''}`
495
+ } else if (isX(fp)) {
496
+ from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`
497
+ } else if (fpr) {
498
+ from = `>=${from}`
499
+ } else {
500
+ from = `>=${from}${incPr ? '-0' : ''}`
501
+ }
502
+
503
+ if (isX(tM)) {
504
+ to = ''
505
+ } else if (isX(tm)) {
506
+ to = `<${+tM + 1}.0.0-0`
507
+ } else if (isX(tp)) {
508
+ to = `<${tM}.${+tm + 1}.0-0`
509
+ } else if (tpr) {
510
+ to = `<=${tM}.${tm}.${tp}-${tpr}`
511
+ } else if (incPr) {
512
+ to = `<${tM}.${tm}.${+tp + 1}-0`
513
+ } else {
514
+ to = `<=${to}`
515
+ }
516
+
517
+ return `${from} ${to}`.trim()
518
+ }
519
+
520
+ const testSet = (set, version, options) => {
521
+ for (let i = 0; i < set.length; i++) {
522
+ if (!set[i].test(version)) {
523
+ return false
524
+ }
525
+ }
526
+
527
+ if (version.prerelease.length && !options.includePrerelease) {
528
+ // Find the set of versions that are allowed to have prereleases
529
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
530
+ // That should allow `1.2.3-pr.2` to pass.
531
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
532
+ // even though it's within the range set by the comparators.
533
+ for (let i = 0; i < set.length; i++) {
534
+ debug(set[i].semver)
535
+ if (set[i].semver === Comparator.ANY) {
536
+ continue
537
+ }
538
+
539
+ if (set[i].semver.prerelease.length > 0) {
540
+ const allowed = set[i].semver
541
+ if (allowed.major === version.major &&
542
+ allowed.minor === version.minor &&
543
+ allowed.patch === version.patch) {
544
+ return true
545
+ }
546
+ }
547
+ }
548
+
549
+ // Version has a -pre, but it's not one of the ones we like.
550
+ return false
551
+ }
552
+
553
+ return true
554
+ }