@ponharu/pkgflare 0.0.0

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/dist/worker.js ADDED
@@ -0,0 +1,3245 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // node_modules/semver/internal/constants.js
28
+ var require_constants = __commonJS({
29
+ "node_modules/semver/internal/constants.js"(exports, module) {
30
+ "use strict";
31
+ var SEMVER_SPEC_VERSION = "2.0.0";
32
+ var MAX_LENGTH = 256;
33
+ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
34
+ 9007199254740991;
35
+ var MAX_SAFE_COMPONENT_LENGTH = 16;
36
+ var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
37
+ var RELEASE_TYPES = [
38
+ "major",
39
+ "premajor",
40
+ "minor",
41
+ "preminor",
42
+ "patch",
43
+ "prepatch",
44
+ "prerelease"
45
+ ];
46
+ module.exports = {
47
+ MAX_LENGTH,
48
+ MAX_SAFE_COMPONENT_LENGTH,
49
+ MAX_SAFE_BUILD_LENGTH,
50
+ MAX_SAFE_INTEGER,
51
+ RELEASE_TYPES,
52
+ SEMVER_SPEC_VERSION,
53
+ FLAG_INCLUDE_PRERELEASE: 1,
54
+ FLAG_LOOSE: 2
55
+ };
56
+ }
57
+ });
58
+
59
+ // node_modules/semver/internal/debug.js
60
+ var require_debug = __commonJS({
61
+ "node_modules/semver/internal/debug.js"(exports, module) {
62
+ "use strict";
63
+ var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
64
+ };
65
+ module.exports = debug;
66
+ }
67
+ });
68
+
69
+ // node_modules/semver/internal/re.js
70
+ var require_re = __commonJS({
71
+ "node_modules/semver/internal/re.js"(exports, module) {
72
+ "use strict";
73
+ var {
74
+ MAX_SAFE_COMPONENT_LENGTH,
75
+ MAX_SAFE_BUILD_LENGTH,
76
+ MAX_LENGTH
77
+ } = require_constants();
78
+ var debug = require_debug();
79
+ exports = module.exports = {};
80
+ var re = exports.re = [];
81
+ var safeRe = exports.safeRe = [];
82
+ var src = exports.src = [];
83
+ var safeSrc = exports.safeSrc = [];
84
+ var t = exports.t = {};
85
+ var R = 0;
86
+ var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
87
+ var safeRegexReplacements = [
88
+ ["\\s", 1],
89
+ ["\\d", MAX_LENGTH],
90
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
91
+ ];
92
+ var makeSafeRegex = (value) => {
93
+ for (const [token, max] of safeRegexReplacements) {
94
+ value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
95
+ }
96
+ return value;
97
+ };
98
+ var createToken = (name, value, isGlobal) => {
99
+ const safe = makeSafeRegex(value);
100
+ const index = R++;
101
+ debug(name, index, value);
102
+ t[name] = index;
103
+ src[index] = value;
104
+ safeSrc[index] = safe;
105
+ re[index] = new RegExp(value, isGlobal ? "g" : void 0);
106
+ safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
107
+ };
108
+ createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
109
+ createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
110
+ createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
111
+ createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
112
+ createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
113
+ createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
114
+ createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
115
+ createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
116
+ createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
117
+ createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
118
+ createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
119
+ createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
120
+ createToken("FULL", `^${src[t.FULLPLAIN]}$`);
121
+ createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
122
+ createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
123
+ createToken("GTLT", "((?:<|>)?=?)");
124
+ createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
125
+ createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
126
+ createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
127
+ createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
128
+ createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
129
+ createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
130
+ createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
131
+ createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
132
+ createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
133
+ createToken("COERCERTL", src[t.COERCE], true);
134
+ createToken("COERCERTLFULL", src[t.COERCEFULL], true);
135
+ createToken("LONETILDE", "(?:~>?)");
136
+ createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
137
+ exports.tildeTrimReplace = "$1~";
138
+ createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
139
+ createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
140
+ createToken("LONECARET", "(?:\\^)");
141
+ createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
142
+ exports.caretTrimReplace = "$1^";
143
+ createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
144
+ createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
145
+ createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
146
+ createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
147
+ createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
148
+ exports.comparatorTrimReplace = "$1$2$3";
149
+ createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
150
+ createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
151
+ createToken("STAR", "(<|>)?=?\\s*\\*");
152
+ createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
153
+ createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
154
+ }
155
+ });
156
+
157
+ // node_modules/semver/internal/parse-options.js
158
+ var require_parse_options = __commonJS({
159
+ "node_modules/semver/internal/parse-options.js"(exports, module) {
160
+ "use strict";
161
+ var looseOption = Object.freeze({ loose: true });
162
+ var emptyOpts = Object.freeze({});
163
+ var parseOptions = (options) => {
164
+ if (!options) {
165
+ return emptyOpts;
166
+ }
167
+ if (typeof options !== "object") {
168
+ return looseOption;
169
+ }
170
+ return options;
171
+ };
172
+ module.exports = parseOptions;
173
+ }
174
+ });
175
+
176
+ // node_modules/semver/internal/identifiers.js
177
+ var require_identifiers = __commonJS({
178
+ "node_modules/semver/internal/identifiers.js"(exports, module) {
179
+ "use strict";
180
+ var numeric = /^[0-9]+$/;
181
+ var compareIdentifiers = (a, b) => {
182
+ if (typeof a === "number" && typeof b === "number") {
183
+ return a === b ? 0 : a < b ? -1 : 1;
184
+ }
185
+ const anum = numeric.test(a);
186
+ const bnum = numeric.test(b);
187
+ if (anum && bnum) {
188
+ a = +a;
189
+ b = +b;
190
+ }
191
+ return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
192
+ };
193
+ var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
194
+ module.exports = {
195
+ compareIdentifiers,
196
+ rcompareIdentifiers
197
+ };
198
+ }
199
+ });
200
+
201
+ // node_modules/semver/classes/semver.js
202
+ var require_semver = __commonJS({
203
+ "node_modules/semver/classes/semver.js"(exports, module) {
204
+ "use strict";
205
+ var debug = require_debug();
206
+ var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
207
+ var { safeRe: re, t } = require_re();
208
+ var parseOptions = require_parse_options();
209
+ var { compareIdentifiers } = require_identifiers();
210
+ var isPrereleaseIdentifier = (prerelease, identifier) => {
211
+ const identifiers = identifier.split(".");
212
+ if (identifiers.length > prerelease.length) {
213
+ return false;
214
+ }
215
+ for (let i = 0; i < identifiers.length; i++) {
216
+ if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) {
217
+ return false;
218
+ }
219
+ }
220
+ return true;
221
+ };
222
+ var SemVer = class _SemVer {
223
+ constructor(version, options) {
224
+ options = parseOptions(options);
225
+ if (version instanceof _SemVer) {
226
+ if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
227
+ return version;
228
+ } else {
229
+ version = version.version;
230
+ }
231
+ } else if (typeof version !== "string") {
232
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
233
+ }
234
+ if (version.length > MAX_LENGTH) {
235
+ throw new TypeError(
236
+ `version is longer than ${MAX_LENGTH} characters`
237
+ );
238
+ }
239
+ debug("SemVer", version, options);
240
+ this.options = options;
241
+ this.loose = !!options.loose;
242
+ this.includePrerelease = !!options.includePrerelease;
243
+ const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
244
+ if (!m) {
245
+ throw new TypeError(`Invalid Version: ${version}`);
246
+ }
247
+ this.raw = version;
248
+ this.major = +m[1];
249
+ this.minor = +m[2];
250
+ this.patch = +m[3];
251
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
252
+ throw new TypeError("Invalid major version");
253
+ }
254
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
255
+ throw new TypeError("Invalid minor version");
256
+ }
257
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
258
+ throw new TypeError("Invalid patch version");
259
+ }
260
+ if (!m[4]) {
261
+ this.prerelease = [];
262
+ } else {
263
+ this.prerelease = m[4].split(".").map((id) => {
264
+ if (/^[0-9]+$/.test(id)) {
265
+ const num = +id;
266
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
267
+ return num;
268
+ }
269
+ }
270
+ return id;
271
+ });
272
+ }
273
+ this.build = m[5] ? m[5].split(".") : [];
274
+ this.format();
275
+ }
276
+ format() {
277
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
278
+ if (this.prerelease.length) {
279
+ this.version += `-${this.prerelease.join(".")}`;
280
+ }
281
+ return this.version;
282
+ }
283
+ toString() {
284
+ return this.version;
285
+ }
286
+ compare(other) {
287
+ debug("SemVer.compare", this.version, this.options, other);
288
+ if (!(other instanceof _SemVer)) {
289
+ if (typeof other === "string" && other === this.version) {
290
+ return 0;
291
+ }
292
+ other = new _SemVer(other, this.options);
293
+ }
294
+ if (other.version === this.version) {
295
+ return 0;
296
+ }
297
+ return this.compareMain(other) || this.comparePre(other);
298
+ }
299
+ compareMain(other) {
300
+ if (!(other instanceof _SemVer)) {
301
+ other = new _SemVer(other, this.options);
302
+ }
303
+ if (this.major < other.major) {
304
+ return -1;
305
+ }
306
+ if (this.major > other.major) {
307
+ return 1;
308
+ }
309
+ if (this.minor < other.minor) {
310
+ return -1;
311
+ }
312
+ if (this.minor > other.minor) {
313
+ return 1;
314
+ }
315
+ if (this.patch < other.patch) {
316
+ return -1;
317
+ }
318
+ if (this.patch > other.patch) {
319
+ return 1;
320
+ }
321
+ return 0;
322
+ }
323
+ comparePre(other) {
324
+ if (!(other instanceof _SemVer)) {
325
+ other = new _SemVer(other, this.options);
326
+ }
327
+ if (this.prerelease.length && !other.prerelease.length) {
328
+ return -1;
329
+ } else if (!this.prerelease.length && other.prerelease.length) {
330
+ return 1;
331
+ } else if (!this.prerelease.length && !other.prerelease.length) {
332
+ return 0;
333
+ }
334
+ let i = 0;
335
+ do {
336
+ const a = this.prerelease[i];
337
+ const b = other.prerelease[i];
338
+ debug("prerelease compare", i, a, b);
339
+ if (a === void 0 && b === void 0) {
340
+ return 0;
341
+ } else if (b === void 0) {
342
+ return 1;
343
+ } else if (a === void 0) {
344
+ return -1;
345
+ } else if (a === b) {
346
+ continue;
347
+ } else {
348
+ return compareIdentifiers(a, b);
349
+ }
350
+ } while (++i);
351
+ }
352
+ compareBuild(other) {
353
+ if (!(other instanceof _SemVer)) {
354
+ other = new _SemVer(other, this.options);
355
+ }
356
+ let i = 0;
357
+ do {
358
+ const a = this.build[i];
359
+ const b = other.build[i];
360
+ debug("build compare", i, a, b);
361
+ if (a === void 0 && b === void 0) {
362
+ return 0;
363
+ } else if (b === void 0) {
364
+ return 1;
365
+ } else if (a === void 0) {
366
+ return -1;
367
+ } else if (a === b) {
368
+ continue;
369
+ } else {
370
+ return compareIdentifiers(a, b);
371
+ }
372
+ } while (++i);
373
+ }
374
+ // preminor will bump the version up to the next minor release, and immediately
375
+ // down to pre-release. premajor and prepatch work the same way.
376
+ inc(release, identifier, identifierBase) {
377
+ if (release.startsWith("pre")) {
378
+ if (!identifier && identifierBase === false) {
379
+ throw new Error("invalid increment argument: identifier is empty");
380
+ }
381
+ if (identifier) {
382
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
383
+ if (!match || match[1] !== identifier) {
384
+ throw new Error(`invalid identifier: ${identifier}`);
385
+ }
386
+ }
387
+ }
388
+ switch (release) {
389
+ case "premajor":
390
+ this.prerelease.length = 0;
391
+ this.patch = 0;
392
+ this.minor = 0;
393
+ this.major++;
394
+ this.inc("pre", identifier, identifierBase);
395
+ break;
396
+ case "preminor":
397
+ this.prerelease.length = 0;
398
+ this.patch = 0;
399
+ this.minor++;
400
+ this.inc("pre", identifier, identifierBase);
401
+ break;
402
+ case "prepatch":
403
+ this.prerelease.length = 0;
404
+ this.inc("patch", identifier, identifierBase);
405
+ this.inc("pre", identifier, identifierBase);
406
+ break;
407
+ // If the input is a non-prerelease version, this acts the same as
408
+ // prepatch.
409
+ case "prerelease":
410
+ if (this.prerelease.length === 0) {
411
+ this.inc("patch", identifier, identifierBase);
412
+ }
413
+ this.inc("pre", identifier, identifierBase);
414
+ break;
415
+ case "release":
416
+ if (this.prerelease.length === 0) {
417
+ throw new Error(`version ${this.raw} is not a prerelease`);
418
+ }
419
+ this.prerelease.length = 0;
420
+ break;
421
+ case "major":
422
+ if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
423
+ this.major++;
424
+ }
425
+ this.minor = 0;
426
+ this.patch = 0;
427
+ this.prerelease = [];
428
+ break;
429
+ case "minor":
430
+ if (this.patch !== 0 || this.prerelease.length === 0) {
431
+ this.minor++;
432
+ }
433
+ this.patch = 0;
434
+ this.prerelease = [];
435
+ break;
436
+ case "patch":
437
+ if (this.prerelease.length === 0) {
438
+ this.patch++;
439
+ }
440
+ this.prerelease = [];
441
+ break;
442
+ // This probably shouldn't be used publicly.
443
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
444
+ case "pre": {
445
+ const base = Number(identifierBase) ? 1 : 0;
446
+ if (this.prerelease.length === 0) {
447
+ this.prerelease = [base];
448
+ } else {
449
+ let i = this.prerelease.length;
450
+ while (--i >= 0) {
451
+ if (typeof this.prerelease[i] === "number") {
452
+ this.prerelease[i]++;
453
+ i = -2;
454
+ }
455
+ }
456
+ if (i === -1) {
457
+ if (identifier === this.prerelease.join(".") && identifierBase === false) {
458
+ throw new Error("invalid increment argument: identifier already exists");
459
+ }
460
+ this.prerelease.push(base);
461
+ }
462
+ }
463
+ if (identifier) {
464
+ let prerelease = [identifier, base];
465
+ if (identifierBase === false) {
466
+ prerelease = [identifier];
467
+ }
468
+ if (isPrereleaseIdentifier(this.prerelease, identifier)) {
469
+ const prereleaseBase = this.prerelease[identifier.split(".").length];
470
+ if (isNaN(prereleaseBase)) {
471
+ this.prerelease = prerelease;
472
+ }
473
+ } else {
474
+ this.prerelease = prerelease;
475
+ }
476
+ }
477
+ break;
478
+ }
479
+ default:
480
+ throw new Error(`invalid increment argument: ${release}`);
481
+ }
482
+ this.raw = this.format();
483
+ if (this.build.length) {
484
+ this.raw += `+${this.build.join(".")}`;
485
+ }
486
+ return this;
487
+ }
488
+ };
489
+ module.exports = SemVer;
490
+ }
491
+ });
492
+
493
+ // node_modules/semver/functions/parse.js
494
+ var require_parse = __commonJS({
495
+ "node_modules/semver/functions/parse.js"(exports, module) {
496
+ "use strict";
497
+ var SemVer = require_semver();
498
+ var parse = (version, options, throwErrors = false) => {
499
+ if (version instanceof SemVer) {
500
+ return version;
501
+ }
502
+ try {
503
+ return new SemVer(version, options);
504
+ } catch (er) {
505
+ if (!throwErrors) {
506
+ return null;
507
+ }
508
+ throw er;
509
+ }
510
+ };
511
+ module.exports = parse;
512
+ }
513
+ });
514
+
515
+ // node_modules/semver/functions/valid.js
516
+ var require_valid = __commonJS({
517
+ "node_modules/semver/functions/valid.js"(exports, module) {
518
+ "use strict";
519
+ var parse = require_parse();
520
+ var valid = (version, options) => {
521
+ const v = parse(version, options);
522
+ return v ? v.version : null;
523
+ };
524
+ module.exports = valid;
525
+ }
526
+ });
527
+
528
+ // node_modules/semver/functions/clean.js
529
+ var require_clean = __commonJS({
530
+ "node_modules/semver/functions/clean.js"(exports, module) {
531
+ "use strict";
532
+ var parse = require_parse();
533
+ var clean = (version, options) => {
534
+ const s = parse(version.trim().replace(/^[=v]+/, ""), options);
535
+ return s ? s.version : null;
536
+ };
537
+ module.exports = clean;
538
+ }
539
+ });
540
+
541
+ // node_modules/semver/functions/inc.js
542
+ var require_inc = __commonJS({
543
+ "node_modules/semver/functions/inc.js"(exports, module) {
544
+ "use strict";
545
+ var SemVer = require_semver();
546
+ var inc = (version, release, options, identifier, identifierBase) => {
547
+ if (typeof options === "string") {
548
+ identifierBase = identifier;
549
+ identifier = options;
550
+ options = void 0;
551
+ }
552
+ try {
553
+ return new SemVer(
554
+ version instanceof SemVer ? version.version : version,
555
+ options
556
+ ).inc(release, identifier, identifierBase).version;
557
+ } catch (er) {
558
+ return null;
559
+ }
560
+ };
561
+ module.exports = inc;
562
+ }
563
+ });
564
+
565
+ // node_modules/semver/functions/diff.js
566
+ var require_diff = __commonJS({
567
+ "node_modules/semver/functions/diff.js"(exports, module) {
568
+ "use strict";
569
+ var parse = require_parse();
570
+ var diff = (version1, version2) => {
571
+ const v1 = parse(version1, null, true);
572
+ const v2 = parse(version2, null, true);
573
+ const comparison = v1.compare(v2);
574
+ if (comparison === 0) {
575
+ return null;
576
+ }
577
+ const v1Higher = comparison > 0;
578
+ const highVersion = v1Higher ? v1 : v2;
579
+ const lowVersion = v1Higher ? v2 : v1;
580
+ const highHasPre = !!highVersion.prerelease.length;
581
+ const lowHasPre = !!lowVersion.prerelease.length;
582
+ if (lowHasPre && !highHasPre) {
583
+ if (!lowVersion.patch && !lowVersion.minor) {
584
+ return "major";
585
+ }
586
+ if (lowVersion.compareMain(highVersion) === 0) {
587
+ if (lowVersion.minor && !lowVersion.patch) {
588
+ return "minor";
589
+ }
590
+ return "patch";
591
+ }
592
+ }
593
+ const prefix = highHasPre ? "pre" : "";
594
+ if (v1.major !== v2.major) {
595
+ return prefix + "major";
596
+ }
597
+ if (v1.minor !== v2.minor) {
598
+ return prefix + "minor";
599
+ }
600
+ if (v1.patch !== v2.patch) {
601
+ return prefix + "patch";
602
+ }
603
+ return "prerelease";
604
+ };
605
+ module.exports = diff;
606
+ }
607
+ });
608
+
609
+ // node_modules/semver/functions/major.js
610
+ var require_major = __commonJS({
611
+ "node_modules/semver/functions/major.js"(exports, module) {
612
+ "use strict";
613
+ var SemVer = require_semver();
614
+ var major = (a, loose) => new SemVer(a, loose).major;
615
+ module.exports = major;
616
+ }
617
+ });
618
+
619
+ // node_modules/semver/functions/minor.js
620
+ var require_minor = __commonJS({
621
+ "node_modules/semver/functions/minor.js"(exports, module) {
622
+ "use strict";
623
+ var SemVer = require_semver();
624
+ var minor = (a, loose) => new SemVer(a, loose).minor;
625
+ module.exports = minor;
626
+ }
627
+ });
628
+
629
+ // node_modules/semver/functions/patch.js
630
+ var require_patch = __commonJS({
631
+ "node_modules/semver/functions/patch.js"(exports, module) {
632
+ "use strict";
633
+ var SemVer = require_semver();
634
+ var patch = (a, loose) => new SemVer(a, loose).patch;
635
+ module.exports = patch;
636
+ }
637
+ });
638
+
639
+ // node_modules/semver/functions/prerelease.js
640
+ var require_prerelease = __commonJS({
641
+ "node_modules/semver/functions/prerelease.js"(exports, module) {
642
+ "use strict";
643
+ var parse = require_parse();
644
+ var prerelease = (version, options) => {
645
+ const parsed = parse(version, options);
646
+ return parsed && parsed.prerelease.length ? parsed.prerelease : null;
647
+ };
648
+ module.exports = prerelease;
649
+ }
650
+ });
651
+
652
+ // node_modules/semver/functions/compare.js
653
+ var require_compare = __commonJS({
654
+ "node_modules/semver/functions/compare.js"(exports, module) {
655
+ "use strict";
656
+ var SemVer = require_semver();
657
+ var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
658
+ module.exports = compare;
659
+ }
660
+ });
661
+
662
+ // node_modules/semver/functions/rcompare.js
663
+ var require_rcompare = __commonJS({
664
+ "node_modules/semver/functions/rcompare.js"(exports, module) {
665
+ "use strict";
666
+ var compare = require_compare();
667
+ var rcompare = (a, b, loose) => compare(b, a, loose);
668
+ module.exports = rcompare;
669
+ }
670
+ });
671
+
672
+ // node_modules/semver/functions/compare-loose.js
673
+ var require_compare_loose = __commonJS({
674
+ "node_modules/semver/functions/compare-loose.js"(exports, module) {
675
+ "use strict";
676
+ var compare = require_compare();
677
+ var compareLoose = (a, b) => compare(a, b, true);
678
+ module.exports = compareLoose;
679
+ }
680
+ });
681
+
682
+ // node_modules/semver/functions/compare-build.js
683
+ var require_compare_build = __commonJS({
684
+ "node_modules/semver/functions/compare-build.js"(exports, module) {
685
+ "use strict";
686
+ var SemVer = require_semver();
687
+ var compareBuild = (a, b, loose) => {
688
+ const versionA = new SemVer(a, loose);
689
+ const versionB = new SemVer(b, loose);
690
+ return versionA.compare(versionB) || versionA.compareBuild(versionB);
691
+ };
692
+ module.exports = compareBuild;
693
+ }
694
+ });
695
+
696
+ // node_modules/semver/functions/sort.js
697
+ var require_sort = __commonJS({
698
+ "node_modules/semver/functions/sort.js"(exports, module) {
699
+ "use strict";
700
+ var compareBuild = require_compare_build();
701
+ var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
702
+ module.exports = sort;
703
+ }
704
+ });
705
+
706
+ // node_modules/semver/functions/rsort.js
707
+ var require_rsort = __commonJS({
708
+ "node_modules/semver/functions/rsort.js"(exports, module) {
709
+ "use strict";
710
+ var compareBuild = require_compare_build();
711
+ var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
712
+ module.exports = rsort;
713
+ }
714
+ });
715
+
716
+ // node_modules/semver/functions/gt.js
717
+ var require_gt = __commonJS({
718
+ "node_modules/semver/functions/gt.js"(exports, module) {
719
+ "use strict";
720
+ var compare = require_compare();
721
+ var gt = (a, b, loose) => compare(a, b, loose) > 0;
722
+ module.exports = gt;
723
+ }
724
+ });
725
+
726
+ // node_modules/semver/functions/lt.js
727
+ var require_lt = __commonJS({
728
+ "node_modules/semver/functions/lt.js"(exports, module) {
729
+ "use strict";
730
+ var compare = require_compare();
731
+ var lt = (a, b, loose) => compare(a, b, loose) < 0;
732
+ module.exports = lt;
733
+ }
734
+ });
735
+
736
+ // node_modules/semver/functions/eq.js
737
+ var require_eq = __commonJS({
738
+ "node_modules/semver/functions/eq.js"(exports, module) {
739
+ "use strict";
740
+ var compare = require_compare();
741
+ var eq = (a, b, loose) => compare(a, b, loose) === 0;
742
+ module.exports = eq;
743
+ }
744
+ });
745
+
746
+ // node_modules/semver/functions/neq.js
747
+ var require_neq = __commonJS({
748
+ "node_modules/semver/functions/neq.js"(exports, module) {
749
+ "use strict";
750
+ var compare = require_compare();
751
+ var neq = (a, b, loose) => compare(a, b, loose) !== 0;
752
+ module.exports = neq;
753
+ }
754
+ });
755
+
756
+ // node_modules/semver/functions/gte.js
757
+ var require_gte = __commonJS({
758
+ "node_modules/semver/functions/gte.js"(exports, module) {
759
+ "use strict";
760
+ var compare = require_compare();
761
+ var gte = (a, b, loose) => compare(a, b, loose) >= 0;
762
+ module.exports = gte;
763
+ }
764
+ });
765
+
766
+ // node_modules/semver/functions/lte.js
767
+ var require_lte = __commonJS({
768
+ "node_modules/semver/functions/lte.js"(exports, module) {
769
+ "use strict";
770
+ var compare = require_compare();
771
+ var lte = (a, b, loose) => compare(a, b, loose) <= 0;
772
+ module.exports = lte;
773
+ }
774
+ });
775
+
776
+ // node_modules/semver/functions/cmp.js
777
+ var require_cmp = __commonJS({
778
+ "node_modules/semver/functions/cmp.js"(exports, module) {
779
+ "use strict";
780
+ var eq = require_eq();
781
+ var neq = require_neq();
782
+ var gt = require_gt();
783
+ var gte = require_gte();
784
+ var lt = require_lt();
785
+ var lte = require_lte();
786
+ var cmp = (a, op, b, loose) => {
787
+ switch (op) {
788
+ case "===":
789
+ if (typeof a === "object") {
790
+ a = a.version;
791
+ }
792
+ if (typeof b === "object") {
793
+ b = b.version;
794
+ }
795
+ return a === b;
796
+ case "!==":
797
+ if (typeof a === "object") {
798
+ a = a.version;
799
+ }
800
+ if (typeof b === "object") {
801
+ b = b.version;
802
+ }
803
+ return a !== b;
804
+ case "":
805
+ case "=":
806
+ case "==":
807
+ return eq(a, b, loose);
808
+ case "!=":
809
+ return neq(a, b, loose);
810
+ case ">":
811
+ return gt(a, b, loose);
812
+ case ">=":
813
+ return gte(a, b, loose);
814
+ case "<":
815
+ return lt(a, b, loose);
816
+ case "<=":
817
+ return lte(a, b, loose);
818
+ default:
819
+ throw new TypeError(`Invalid operator: ${op}`);
820
+ }
821
+ };
822
+ module.exports = cmp;
823
+ }
824
+ });
825
+
826
+ // node_modules/semver/functions/coerce.js
827
+ var require_coerce = __commonJS({
828
+ "node_modules/semver/functions/coerce.js"(exports, module) {
829
+ "use strict";
830
+ var SemVer = require_semver();
831
+ var parse = require_parse();
832
+ var { safeRe: re, t } = require_re();
833
+ var coerce = (version, options) => {
834
+ if (version instanceof SemVer) {
835
+ return version;
836
+ }
837
+ if (typeof version === "number") {
838
+ version = String(version);
839
+ }
840
+ if (typeof version !== "string") {
841
+ return null;
842
+ }
843
+ options = options || {};
844
+ let match = null;
845
+ if (!options.rtl) {
846
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
847
+ } else {
848
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
849
+ let next;
850
+ while ((next = coerceRtlRegex.exec(version)) && (!match || match.index + match[0].length !== version.length)) {
851
+ if (!match || next.index + next[0].length !== match.index + match[0].length) {
852
+ match = next;
853
+ }
854
+ coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
855
+ }
856
+ coerceRtlRegex.lastIndex = -1;
857
+ }
858
+ if (match === null) {
859
+ return null;
860
+ }
861
+ const major = match[2];
862
+ const minor = match[3] || "0";
863
+ const patch = match[4] || "0";
864
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
865
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
866
+ return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
867
+ };
868
+ module.exports = coerce;
869
+ }
870
+ });
871
+
872
+ // node_modules/semver/functions/truncate.js
873
+ var require_truncate = __commonJS({
874
+ "node_modules/semver/functions/truncate.js"(exports, module) {
875
+ "use strict";
876
+ var parse = require_parse();
877
+ var constants = require_constants();
878
+ var SemVer = require_semver();
879
+ var truncate = (version, truncation, options) => {
880
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
881
+ return null;
882
+ }
883
+ const clonedVersion = cloneInputVersion(version, options);
884
+ return clonedVersion && doTruncation(clonedVersion, truncation);
885
+ };
886
+ var cloneInputVersion = (version, options) => {
887
+ const versionStringToParse = version instanceof SemVer ? version.version : version;
888
+ return parse(versionStringToParse, options);
889
+ };
890
+ var doTruncation = (version, truncation) => {
891
+ if (isPrerelease(truncation)) {
892
+ return version.version;
893
+ }
894
+ version.prerelease = [];
895
+ switch (truncation) {
896
+ case "major":
897
+ version.minor = 0;
898
+ version.patch = 0;
899
+ break;
900
+ case "minor":
901
+ version.patch = 0;
902
+ break;
903
+ }
904
+ return version.format();
905
+ };
906
+ var isPrerelease = (type) => {
907
+ return type.startsWith("pre");
908
+ };
909
+ module.exports = truncate;
910
+ }
911
+ });
912
+
913
+ // node_modules/semver/internal/lrucache.js
914
+ var require_lrucache = __commonJS({
915
+ "node_modules/semver/internal/lrucache.js"(exports, module) {
916
+ "use strict";
917
+ var LRUCache = class {
918
+ constructor() {
919
+ this.max = 1e3;
920
+ this.map = /* @__PURE__ */ new Map();
921
+ }
922
+ get(key) {
923
+ const value = this.map.get(key);
924
+ if (value === void 0) {
925
+ return void 0;
926
+ } else {
927
+ this.map.delete(key);
928
+ this.map.set(key, value);
929
+ return value;
930
+ }
931
+ }
932
+ delete(key) {
933
+ return this.map.delete(key);
934
+ }
935
+ set(key, value) {
936
+ const deleted = this.delete(key);
937
+ if (!deleted && value !== void 0) {
938
+ if (this.map.size >= this.max) {
939
+ const firstKey = this.map.keys().next().value;
940
+ this.delete(firstKey);
941
+ }
942
+ this.map.set(key, value);
943
+ }
944
+ return this;
945
+ }
946
+ };
947
+ module.exports = LRUCache;
948
+ }
949
+ });
950
+
951
+ // node_modules/semver/classes/range.js
952
+ var require_range = __commonJS({
953
+ "node_modules/semver/classes/range.js"(exports, module) {
954
+ "use strict";
955
+ var SPACE_CHARACTERS = /\s+/g;
956
+ var Range = class _Range {
957
+ constructor(range, options) {
958
+ options = parseOptions(options);
959
+ if (range instanceof _Range) {
960
+ if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
961
+ return range;
962
+ } else {
963
+ return new _Range(range.raw, options);
964
+ }
965
+ }
966
+ if (range instanceof Comparator) {
967
+ this.raw = range.value;
968
+ this.set = [[range]];
969
+ this.formatted = void 0;
970
+ return this;
971
+ }
972
+ this.options = options;
973
+ this.loose = !!options.loose;
974
+ this.includePrerelease = !!options.includePrerelease;
975
+ this.raw = range.trim().replace(SPACE_CHARACTERS, " ");
976
+ this.set = this.raw.split("||").map((r) => this.parseRange(r.trim())).filter((c) => c.length);
977
+ if (!this.set.length) {
978
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`);
979
+ }
980
+ if (this.set.length > 1) {
981
+ const first = this.set[0];
982
+ this.set = this.set.filter((c) => !isNullSet(c[0]));
983
+ if (this.set.length === 0) {
984
+ this.set = [first];
985
+ } else if (this.set.length > 1) {
986
+ for (const c of this.set) {
987
+ if (c.length === 1 && isAny(c[0])) {
988
+ this.set = [c];
989
+ break;
990
+ }
991
+ }
992
+ }
993
+ }
994
+ this.formatted = void 0;
995
+ }
996
+ get range() {
997
+ if (this.formatted === void 0) {
998
+ this.formatted = "";
999
+ for (let i = 0; i < this.set.length; i++) {
1000
+ if (i > 0) {
1001
+ this.formatted += "||";
1002
+ }
1003
+ const comps = this.set[i];
1004
+ for (let k = 0; k < comps.length; k++) {
1005
+ if (k > 0) {
1006
+ this.formatted += " ";
1007
+ }
1008
+ this.formatted += comps[k].toString().trim();
1009
+ }
1010
+ }
1011
+ }
1012
+ return this.formatted;
1013
+ }
1014
+ format() {
1015
+ return this.range;
1016
+ }
1017
+ toString() {
1018
+ return this.range;
1019
+ }
1020
+ parseRange(range) {
1021
+ range = range.replace(BUILDSTRIPRE, "");
1022
+ const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
1023
+ const memoKey = memoOpts + ":" + range;
1024
+ const cached = cache.get(memoKey);
1025
+ if (cached) {
1026
+ return cached;
1027
+ }
1028
+ const loose = this.options.loose;
1029
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
1030
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
1031
+ debug("hyphen replace", range);
1032
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
1033
+ debug("comparator trim", range);
1034
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
1035
+ debug("tilde trim", range);
1036
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
1037
+ debug("caret trim", range);
1038
+ let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
1039
+ if (loose) {
1040
+ rangeList = rangeList.filter((comp) => {
1041
+ debug("loose invalid filter", comp, this.options);
1042
+ return !!comp.match(re[t.COMPARATORLOOSE]);
1043
+ });
1044
+ }
1045
+ debug("range list", rangeList);
1046
+ const rangeMap = /* @__PURE__ */ new Map();
1047
+ const comparators = rangeList.map((comp) => new Comparator(comp, this.options));
1048
+ for (const comp of comparators) {
1049
+ if (isNullSet(comp)) {
1050
+ return [comp];
1051
+ }
1052
+ rangeMap.set(comp.value, comp);
1053
+ }
1054
+ if (rangeMap.size > 1 && rangeMap.has("")) {
1055
+ rangeMap.delete("");
1056
+ }
1057
+ const result = [...rangeMap.values()];
1058
+ cache.set(memoKey, result);
1059
+ return result;
1060
+ }
1061
+ intersects(range, options) {
1062
+ if (!(range instanceof _Range)) {
1063
+ throw new TypeError("a Range is required");
1064
+ }
1065
+ return this.set.some((thisComparators) => {
1066
+ return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => {
1067
+ return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => {
1068
+ return rangeComparators.every((rangeComparator) => {
1069
+ return thisComparator.intersects(rangeComparator, options);
1070
+ });
1071
+ });
1072
+ });
1073
+ });
1074
+ }
1075
+ // if ANY of the sets match ALL of its comparators, then pass
1076
+ test(version) {
1077
+ if (!version) {
1078
+ return false;
1079
+ }
1080
+ if (typeof version === "string") {
1081
+ try {
1082
+ version = new SemVer(version, this.options);
1083
+ } catch (er) {
1084
+ return false;
1085
+ }
1086
+ }
1087
+ for (let i = 0; i < this.set.length; i++) {
1088
+ if (testSet(this.set[i], version, this.options)) {
1089
+ return true;
1090
+ }
1091
+ }
1092
+ return false;
1093
+ }
1094
+ };
1095
+ module.exports = Range;
1096
+ var LRU = require_lrucache();
1097
+ var cache = new LRU();
1098
+ var parseOptions = require_parse_options();
1099
+ var Comparator = require_comparator();
1100
+ var debug = require_debug();
1101
+ var SemVer = require_semver();
1102
+ var {
1103
+ safeRe: re,
1104
+ src,
1105
+ t,
1106
+ comparatorTrimReplace,
1107
+ tildeTrimReplace,
1108
+ caretTrimReplace
1109
+ } = require_re();
1110
+ var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
1111
+ var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g");
1112
+ var isNullSet = (c) => c.value === "<0.0.0-0";
1113
+ var isAny = (c) => c.value === "";
1114
+ var isSatisfiable = (comparators, options) => {
1115
+ let result = true;
1116
+ const remainingComparators = comparators.slice();
1117
+ let testComparator = remainingComparators.pop();
1118
+ while (result && remainingComparators.length) {
1119
+ result = remainingComparators.every((otherComparator) => {
1120
+ return testComparator.intersects(otherComparator, options);
1121
+ });
1122
+ testComparator = remainingComparators.pop();
1123
+ }
1124
+ return result;
1125
+ };
1126
+ var parseComparator = (comp, options) => {
1127
+ comp = comp.replace(re[t.BUILD], "");
1128
+ debug("comp", comp, options);
1129
+ comp = replaceCarets(comp, options);
1130
+ debug("caret", comp);
1131
+ comp = replaceTildes(comp, options);
1132
+ debug("tildes", comp);
1133
+ comp = replaceXRanges(comp, options);
1134
+ debug("xrange", comp);
1135
+ comp = replaceStars(comp, options);
1136
+ debug("stars", comp);
1137
+ return comp;
1138
+ };
1139
+ var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
1140
+ var invalidXRangeOrder = (M, m, p) => isX(M) && !isX(m) || isX(m) && p && !isX(p);
1141
+ var replaceTildes = (comp, options) => {
1142
+ return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
1143
+ };
1144
+ var replaceTilde = (comp, options) => {
1145
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
1146
+ const z = options.includePrerelease ? "-0" : "";
1147
+ return comp.replace(r, (_, M, m, p, pr) => {
1148
+ debug("tilde", comp, _, M, m, p, pr);
1149
+ let ret;
1150
+ if (isX(M)) {
1151
+ ret = "";
1152
+ } else if (isX(m)) {
1153
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1154
+ } else if (isX(p)) {
1155
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1156
+ } else if (pr) {
1157
+ debug("replaceTilde pr", pr);
1158
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
1159
+ } else {
1160
+ ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
1161
+ }
1162
+ debug("tilde return", ret);
1163
+ return ret;
1164
+ });
1165
+ };
1166
+ var replaceCarets = (comp, options) => {
1167
+ return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" ");
1168
+ };
1169
+ var replaceCaret = (comp, options) => {
1170
+ debug("caret", comp, options);
1171
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
1172
+ const z = options.includePrerelease ? "-0" : "";
1173
+ return comp.replace(r, (_, M, m, p, pr) => {
1174
+ debug("caret", comp, _, M, m, p, pr);
1175
+ let ret;
1176
+ if (isX(M)) {
1177
+ ret = "";
1178
+ } else if (isX(m)) {
1179
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1180
+ } else if (isX(p)) {
1181
+ if (M === "0") {
1182
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1183
+ } else {
1184
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
1185
+ }
1186
+ } else if (pr) {
1187
+ debug("replaceCaret pr", pr);
1188
+ if (M === "0") {
1189
+ if (m === "0") {
1190
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
1191
+ } else {
1192
+ ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
1193
+ }
1194
+ } else {
1195
+ ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
1196
+ }
1197
+ } else {
1198
+ debug("no pr");
1199
+ if (M === "0") {
1200
+ if (m === "0") {
1201
+ ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
1202
+ } else {
1203
+ ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
1204
+ }
1205
+ } else {
1206
+ ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
1207
+ }
1208
+ }
1209
+ debug("caret return", ret);
1210
+ return ret;
1211
+ });
1212
+ };
1213
+ var replaceXRanges = (comp, options) => {
1214
+ debug("replaceXRanges", comp, options);
1215
+ return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" ");
1216
+ };
1217
+ var replaceXRange = (comp, options) => {
1218
+ comp = comp.trim();
1219
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
1220
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
1221
+ debug("xRange", comp, ret, gtlt, M, m, p, pr);
1222
+ if (invalidXRangeOrder(M, m, p)) {
1223
+ return comp;
1224
+ }
1225
+ const xM = isX(M);
1226
+ const xm = xM || isX(m);
1227
+ const xp = xm || isX(p);
1228
+ const anyX = xp;
1229
+ if (gtlt === "=" && anyX) {
1230
+ gtlt = "";
1231
+ }
1232
+ pr = options.includePrerelease ? "-0" : "";
1233
+ if (xM) {
1234
+ if (gtlt === ">" || gtlt === "<") {
1235
+ ret = "<0.0.0-0";
1236
+ } else {
1237
+ ret = "*";
1238
+ }
1239
+ } else if (gtlt && anyX) {
1240
+ if (xm) {
1241
+ m = 0;
1242
+ }
1243
+ p = 0;
1244
+ if (gtlt === ">") {
1245
+ gtlt = ">=";
1246
+ if (xm) {
1247
+ M = +M + 1;
1248
+ m = 0;
1249
+ p = 0;
1250
+ } else {
1251
+ m = +m + 1;
1252
+ p = 0;
1253
+ }
1254
+ } else if (gtlt === "<=") {
1255
+ gtlt = "<";
1256
+ if (xm) {
1257
+ M = +M + 1;
1258
+ } else {
1259
+ m = +m + 1;
1260
+ }
1261
+ }
1262
+ if (gtlt === "<") {
1263
+ pr = "-0";
1264
+ }
1265
+ ret = `${gtlt + M}.${m}.${p}${pr}`;
1266
+ } else if (xm) {
1267
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
1268
+ } else if (xp) {
1269
+ ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
1270
+ }
1271
+ debug("xRange return", ret);
1272
+ return ret;
1273
+ });
1274
+ };
1275
+ var replaceStars = (comp, options) => {
1276
+ debug("replaceStars", comp, options);
1277
+ return comp.trim().replace(re[t.STAR], "");
1278
+ };
1279
+ var replaceGTE0 = (comp, options) => {
1280
+ debug("replaceGTE0", comp, options);
1281
+ return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
1282
+ };
1283
+ var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
1284
+ if (isX(fM)) {
1285
+ from = "";
1286
+ } else if (isX(fm)) {
1287
+ from = `>=${fM}.0.0${incPr ? "-0" : ""}`;
1288
+ } else if (isX(fp)) {
1289
+ from = `>=${fM}.${fm}.0${incPr ? "-0" : ""}`;
1290
+ } else if (fpr) {
1291
+ from = `>=${from}`;
1292
+ } else {
1293
+ from = `>=${from}${incPr ? "-0" : ""}`;
1294
+ }
1295
+ if (isX(tM)) {
1296
+ to = "";
1297
+ } else if (isX(tm)) {
1298
+ to = `<${+tM + 1}.0.0-0`;
1299
+ } else if (isX(tp)) {
1300
+ to = `<${tM}.${+tm + 1}.0-0`;
1301
+ } else if (tpr) {
1302
+ to = `<=${tM}.${tm}.${tp}-${tpr}`;
1303
+ } else if (incPr) {
1304
+ to = `<${tM}.${tm}.${+tp + 1}-0`;
1305
+ } else {
1306
+ to = `<=${to}`;
1307
+ }
1308
+ return `${from} ${to}`.trim();
1309
+ };
1310
+ var testSet = (set, version, options) => {
1311
+ for (let i = 0; i < set.length; i++) {
1312
+ if (!set[i].test(version)) {
1313
+ return false;
1314
+ }
1315
+ }
1316
+ if (version.prerelease.length && !options.includePrerelease) {
1317
+ for (let i = 0; i < set.length; i++) {
1318
+ debug(set[i].semver);
1319
+ if (set[i].semver === Comparator.ANY) {
1320
+ continue;
1321
+ }
1322
+ if (set[i].semver.prerelease.length > 0) {
1323
+ const allowed = set[i].semver;
1324
+ if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
1325
+ return true;
1326
+ }
1327
+ }
1328
+ }
1329
+ return false;
1330
+ }
1331
+ return true;
1332
+ };
1333
+ }
1334
+ });
1335
+
1336
+ // node_modules/semver/classes/comparator.js
1337
+ var require_comparator = __commonJS({
1338
+ "node_modules/semver/classes/comparator.js"(exports, module) {
1339
+ "use strict";
1340
+ var ANY = /* @__PURE__ */ Symbol("SemVer ANY");
1341
+ var Comparator = class _Comparator {
1342
+ static get ANY() {
1343
+ return ANY;
1344
+ }
1345
+ constructor(comp, options) {
1346
+ options = parseOptions(options);
1347
+ if (comp instanceof _Comparator) {
1348
+ if (comp.loose === !!options.loose) {
1349
+ return comp;
1350
+ } else {
1351
+ comp = comp.value;
1352
+ }
1353
+ }
1354
+ comp = comp.trim().split(/\s+/).join(" ");
1355
+ debug("comparator", comp, options);
1356
+ this.options = options;
1357
+ this.loose = !!options.loose;
1358
+ this.parse(comp);
1359
+ if (this.semver === ANY) {
1360
+ this.value = "";
1361
+ } else {
1362
+ this.value = this.operator + this.semver.version;
1363
+ }
1364
+ debug("comp", this);
1365
+ }
1366
+ parse(comp) {
1367
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
1368
+ const m = comp.match(r);
1369
+ if (!m) {
1370
+ throw new TypeError(`Invalid comparator: ${comp}`);
1371
+ }
1372
+ this.operator = m[1] !== void 0 ? m[1] : "";
1373
+ if (this.operator === "=") {
1374
+ this.operator = "";
1375
+ }
1376
+ if (!m[2]) {
1377
+ this.semver = ANY;
1378
+ } else {
1379
+ this.semver = new SemVer(m[2], this.options.loose);
1380
+ }
1381
+ }
1382
+ toString() {
1383
+ return this.value;
1384
+ }
1385
+ test(version) {
1386
+ debug("Comparator.test", version, this.options.loose);
1387
+ if (this.semver === ANY || version === ANY) {
1388
+ return true;
1389
+ }
1390
+ if (typeof version === "string") {
1391
+ try {
1392
+ version = new SemVer(version, this.options);
1393
+ } catch (er) {
1394
+ return false;
1395
+ }
1396
+ }
1397
+ return cmp(version, this.operator, this.semver, this.options);
1398
+ }
1399
+ intersects(comp, options) {
1400
+ if (!(comp instanceof _Comparator)) {
1401
+ throw new TypeError("a Comparator is required");
1402
+ }
1403
+ if (this.operator === "") {
1404
+ if (this.value === "") {
1405
+ return true;
1406
+ }
1407
+ return new Range(comp.value, options).test(this.value);
1408
+ } else if (comp.operator === "") {
1409
+ if (comp.value === "") {
1410
+ return true;
1411
+ }
1412
+ return new Range(this.value, options).test(comp.semver);
1413
+ }
1414
+ options = parseOptions(options);
1415
+ if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) {
1416
+ return false;
1417
+ }
1418
+ if (!options.includePrerelease && (this.value.startsWith("<0.0.0") || comp.value.startsWith("<0.0.0"))) {
1419
+ return false;
1420
+ }
1421
+ if (this.operator.startsWith(">") && comp.operator.startsWith(">")) {
1422
+ return true;
1423
+ }
1424
+ if (this.operator.startsWith("<") && comp.operator.startsWith("<")) {
1425
+ return true;
1426
+ }
1427
+ if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) {
1428
+ return true;
1429
+ }
1430
+ if (cmp(this.semver, "<", comp.semver, options) && this.operator.startsWith(">") && comp.operator.startsWith("<")) {
1431
+ return true;
1432
+ }
1433
+ if (cmp(this.semver, ">", comp.semver, options) && this.operator.startsWith("<") && comp.operator.startsWith(">")) {
1434
+ return true;
1435
+ }
1436
+ return false;
1437
+ }
1438
+ };
1439
+ module.exports = Comparator;
1440
+ var parseOptions = require_parse_options();
1441
+ var { safeRe: re, t } = require_re();
1442
+ var cmp = require_cmp();
1443
+ var debug = require_debug();
1444
+ var SemVer = require_semver();
1445
+ var Range = require_range();
1446
+ }
1447
+ });
1448
+
1449
+ // node_modules/semver/functions/satisfies.js
1450
+ var require_satisfies = __commonJS({
1451
+ "node_modules/semver/functions/satisfies.js"(exports, module) {
1452
+ "use strict";
1453
+ var Range = require_range();
1454
+ var satisfies = (version, range, options) => {
1455
+ try {
1456
+ range = new Range(range, options);
1457
+ } catch (er) {
1458
+ return false;
1459
+ }
1460
+ return range.test(version);
1461
+ };
1462
+ module.exports = satisfies;
1463
+ }
1464
+ });
1465
+
1466
+ // node_modules/semver/ranges/to-comparators.js
1467
+ var require_to_comparators = __commonJS({
1468
+ "node_modules/semver/ranges/to-comparators.js"(exports, module) {
1469
+ "use strict";
1470
+ var Range = require_range();
1471
+ var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
1472
+ module.exports = toComparators;
1473
+ }
1474
+ });
1475
+
1476
+ // node_modules/semver/ranges/max-satisfying.js
1477
+ var require_max_satisfying = __commonJS({
1478
+ "node_modules/semver/ranges/max-satisfying.js"(exports, module) {
1479
+ "use strict";
1480
+ var SemVer = require_semver();
1481
+ var Range = require_range();
1482
+ var maxSatisfying = (versions, range, options) => {
1483
+ let max = null;
1484
+ let maxSV = null;
1485
+ let rangeObj = null;
1486
+ try {
1487
+ rangeObj = new Range(range, options);
1488
+ } catch (er) {
1489
+ return null;
1490
+ }
1491
+ versions.forEach((v) => {
1492
+ if (rangeObj.test(v)) {
1493
+ if (!max || maxSV.compare(v) === -1) {
1494
+ max = v;
1495
+ maxSV = new SemVer(max, options);
1496
+ }
1497
+ }
1498
+ });
1499
+ return max;
1500
+ };
1501
+ module.exports = maxSatisfying;
1502
+ }
1503
+ });
1504
+
1505
+ // node_modules/semver/ranges/min-satisfying.js
1506
+ var require_min_satisfying = __commonJS({
1507
+ "node_modules/semver/ranges/min-satisfying.js"(exports, module) {
1508
+ "use strict";
1509
+ var SemVer = require_semver();
1510
+ var Range = require_range();
1511
+ var minSatisfying = (versions, range, options) => {
1512
+ let min = null;
1513
+ let minSV = null;
1514
+ let rangeObj = null;
1515
+ try {
1516
+ rangeObj = new Range(range, options);
1517
+ } catch (er) {
1518
+ return null;
1519
+ }
1520
+ versions.forEach((v) => {
1521
+ if (rangeObj.test(v)) {
1522
+ if (!min || minSV.compare(v) === 1) {
1523
+ min = v;
1524
+ minSV = new SemVer(min, options);
1525
+ }
1526
+ }
1527
+ });
1528
+ return min;
1529
+ };
1530
+ module.exports = minSatisfying;
1531
+ }
1532
+ });
1533
+
1534
+ // node_modules/semver/ranges/min-version.js
1535
+ var require_min_version = __commonJS({
1536
+ "node_modules/semver/ranges/min-version.js"(exports, module) {
1537
+ "use strict";
1538
+ var SemVer = require_semver();
1539
+ var Range = require_range();
1540
+ var gt = require_gt();
1541
+ var minVersion = (range, loose) => {
1542
+ range = new Range(range, loose);
1543
+ let minver = new SemVer("0.0.0");
1544
+ if (range.test(minver)) {
1545
+ return minver;
1546
+ }
1547
+ minver = new SemVer("0.0.0-0");
1548
+ if (range.test(minver)) {
1549
+ return minver;
1550
+ }
1551
+ minver = null;
1552
+ for (let i = 0; i < range.set.length; ++i) {
1553
+ const comparators = range.set[i];
1554
+ let setMin = null;
1555
+ comparators.forEach((comparator) => {
1556
+ const compver = new SemVer(comparator.semver.version);
1557
+ switch (comparator.operator) {
1558
+ case ">":
1559
+ if (compver.prerelease.length === 0) {
1560
+ compver.patch++;
1561
+ } else {
1562
+ compver.prerelease.push(0);
1563
+ }
1564
+ compver.raw = compver.format();
1565
+ /* fallthrough */
1566
+ case "":
1567
+ case ">=":
1568
+ if (!setMin || gt(compver, setMin)) {
1569
+ setMin = compver;
1570
+ }
1571
+ break;
1572
+ case "<":
1573
+ case "<=":
1574
+ break;
1575
+ /* istanbul ignore next */
1576
+ default:
1577
+ throw new Error(`Unexpected operation: ${comparator.operator}`);
1578
+ }
1579
+ });
1580
+ if (setMin && (!minver || gt(minver, setMin))) {
1581
+ minver = setMin;
1582
+ }
1583
+ }
1584
+ if (minver && range.test(minver)) {
1585
+ return minver;
1586
+ }
1587
+ return null;
1588
+ };
1589
+ module.exports = minVersion;
1590
+ }
1591
+ });
1592
+
1593
+ // node_modules/semver/ranges/valid.js
1594
+ var require_valid2 = __commonJS({
1595
+ "node_modules/semver/ranges/valid.js"(exports, module) {
1596
+ "use strict";
1597
+ var Range = require_range();
1598
+ var validRange2 = (range, options) => {
1599
+ try {
1600
+ return new Range(range, options).range || "*";
1601
+ } catch (er) {
1602
+ return null;
1603
+ }
1604
+ };
1605
+ module.exports = validRange2;
1606
+ }
1607
+ });
1608
+
1609
+ // node_modules/semver/ranges/outside.js
1610
+ var require_outside = __commonJS({
1611
+ "node_modules/semver/ranges/outside.js"(exports, module) {
1612
+ "use strict";
1613
+ var SemVer = require_semver();
1614
+ var Comparator = require_comparator();
1615
+ var { ANY } = Comparator;
1616
+ var Range = require_range();
1617
+ var satisfies = require_satisfies();
1618
+ var gt = require_gt();
1619
+ var lt = require_lt();
1620
+ var lte = require_lte();
1621
+ var gte = require_gte();
1622
+ var outside = (version, range, hilo, options) => {
1623
+ version = new SemVer(version, options);
1624
+ range = new Range(range, options);
1625
+ let gtfn, ltefn, ltfn, comp, ecomp;
1626
+ switch (hilo) {
1627
+ case ">":
1628
+ gtfn = gt;
1629
+ ltefn = lte;
1630
+ ltfn = lt;
1631
+ comp = ">";
1632
+ ecomp = ">=";
1633
+ break;
1634
+ case "<":
1635
+ gtfn = lt;
1636
+ ltefn = gte;
1637
+ ltfn = gt;
1638
+ comp = "<";
1639
+ ecomp = "<=";
1640
+ break;
1641
+ default:
1642
+ throw new TypeError('Must provide a hilo val of "<" or ">"');
1643
+ }
1644
+ if (satisfies(version, range, options)) {
1645
+ return false;
1646
+ }
1647
+ for (let i = 0; i < range.set.length; ++i) {
1648
+ const comparators = range.set[i];
1649
+ let high = null;
1650
+ let low = null;
1651
+ comparators.forEach((comparator) => {
1652
+ if (comparator.semver === ANY) {
1653
+ comparator = new Comparator(">=0.0.0");
1654
+ }
1655
+ high = high || comparator;
1656
+ low = low || comparator;
1657
+ if (gtfn(comparator.semver, high.semver, options)) {
1658
+ high = comparator;
1659
+ } else if (ltfn(comparator.semver, low.semver, options)) {
1660
+ low = comparator;
1661
+ }
1662
+ });
1663
+ if (high.operator === comp || high.operator === ecomp) {
1664
+ return false;
1665
+ }
1666
+ if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
1667
+ return false;
1668
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
1669
+ return false;
1670
+ }
1671
+ }
1672
+ return true;
1673
+ };
1674
+ module.exports = outside;
1675
+ }
1676
+ });
1677
+
1678
+ // node_modules/semver/ranges/gtr.js
1679
+ var require_gtr = __commonJS({
1680
+ "node_modules/semver/ranges/gtr.js"(exports, module) {
1681
+ "use strict";
1682
+ var outside = require_outside();
1683
+ var gtr = (version, range, options) => outside(version, range, ">", options);
1684
+ module.exports = gtr;
1685
+ }
1686
+ });
1687
+
1688
+ // node_modules/semver/ranges/ltr.js
1689
+ var require_ltr = __commonJS({
1690
+ "node_modules/semver/ranges/ltr.js"(exports, module) {
1691
+ "use strict";
1692
+ var outside = require_outside();
1693
+ var ltr = (version, range, options) => outside(version, range, "<", options);
1694
+ module.exports = ltr;
1695
+ }
1696
+ });
1697
+
1698
+ // node_modules/semver/ranges/intersects.js
1699
+ var require_intersects = __commonJS({
1700
+ "node_modules/semver/ranges/intersects.js"(exports, module) {
1701
+ "use strict";
1702
+ var Range = require_range();
1703
+ var intersects = (r1, r2, options) => {
1704
+ r1 = new Range(r1, options);
1705
+ r2 = new Range(r2, options);
1706
+ return r1.intersects(r2, options);
1707
+ };
1708
+ module.exports = intersects;
1709
+ }
1710
+ });
1711
+
1712
+ // node_modules/semver/ranges/simplify.js
1713
+ var require_simplify = __commonJS({
1714
+ "node_modules/semver/ranges/simplify.js"(exports, module) {
1715
+ "use strict";
1716
+ var satisfies = require_satisfies();
1717
+ var compare = require_compare();
1718
+ module.exports = (versions, range, options) => {
1719
+ const set = [];
1720
+ let first = null;
1721
+ let prev = null;
1722
+ const v = versions.sort((a, b) => compare(a, b, options));
1723
+ for (const version of v) {
1724
+ const included = satisfies(version, range, options);
1725
+ if (included) {
1726
+ prev = version;
1727
+ if (!first) {
1728
+ first = version;
1729
+ }
1730
+ } else {
1731
+ if (prev) {
1732
+ set.push([first, prev]);
1733
+ }
1734
+ prev = null;
1735
+ first = null;
1736
+ }
1737
+ }
1738
+ if (first) {
1739
+ set.push([first, null]);
1740
+ }
1741
+ const ranges = [];
1742
+ for (const [min, max] of set) {
1743
+ if (min === max) {
1744
+ ranges.push(min);
1745
+ } else if (!max && min === v[0]) {
1746
+ ranges.push("*");
1747
+ } else if (!max) {
1748
+ ranges.push(`>=${min}`);
1749
+ } else if (min === v[0]) {
1750
+ ranges.push(`<=${max}`);
1751
+ } else {
1752
+ ranges.push(`${min} - ${max}`);
1753
+ }
1754
+ }
1755
+ const simplified = ranges.join(" || ");
1756
+ const original = typeof range.raw === "string" ? range.raw : String(range);
1757
+ return simplified.length < original.length ? simplified : range;
1758
+ };
1759
+ }
1760
+ });
1761
+
1762
+ // node_modules/semver/ranges/subset.js
1763
+ var require_subset = __commonJS({
1764
+ "node_modules/semver/ranges/subset.js"(exports, module) {
1765
+ "use strict";
1766
+ var Range = require_range();
1767
+ var Comparator = require_comparator();
1768
+ var { ANY } = Comparator;
1769
+ var satisfies = require_satisfies();
1770
+ var compare = require_compare();
1771
+ var subset = (sub, dom, options = {}) => {
1772
+ if (sub === dom) {
1773
+ return true;
1774
+ }
1775
+ sub = new Range(sub, options);
1776
+ dom = new Range(dom, options);
1777
+ let sawNonNull = false;
1778
+ OUTER: for (const simpleSub of sub.set) {
1779
+ for (const simpleDom of dom.set) {
1780
+ const isSub = simpleSubset(simpleSub, simpleDom, options);
1781
+ sawNonNull = sawNonNull || isSub !== null;
1782
+ if (isSub) {
1783
+ continue OUTER;
1784
+ }
1785
+ }
1786
+ if (sawNonNull) {
1787
+ return false;
1788
+ }
1789
+ }
1790
+ return true;
1791
+ };
1792
+ var minimumVersionWithPreRelease = [new Comparator(">=0.0.0-0")];
1793
+ var minimumVersion = [new Comparator(">=0.0.0")];
1794
+ var simpleSubset = (sub, dom, options) => {
1795
+ if (sub === dom) {
1796
+ return true;
1797
+ }
1798
+ if (sub.length === 1 && sub[0].semver === ANY) {
1799
+ if (dom.length === 1 && dom[0].semver === ANY) {
1800
+ return true;
1801
+ } else if (options.includePrerelease) {
1802
+ sub = minimumVersionWithPreRelease;
1803
+ } else {
1804
+ sub = minimumVersion;
1805
+ }
1806
+ }
1807
+ if (dom.length === 1 && dom[0].semver === ANY) {
1808
+ if (options.includePrerelease) {
1809
+ return true;
1810
+ } else {
1811
+ dom = minimumVersion;
1812
+ }
1813
+ }
1814
+ const eqSet = /* @__PURE__ */ new Set();
1815
+ let gt, lt;
1816
+ for (const c of sub) {
1817
+ if (c.operator === ">" || c.operator === ">=") {
1818
+ gt = higherGT(gt, c, options);
1819
+ } else if (c.operator === "<" || c.operator === "<=") {
1820
+ lt = lowerLT(lt, c, options);
1821
+ } else {
1822
+ eqSet.add(c.semver);
1823
+ }
1824
+ }
1825
+ if (eqSet.size > 1) {
1826
+ return null;
1827
+ }
1828
+ let gtltComp;
1829
+ if (gt && lt) {
1830
+ gtltComp = compare(gt.semver, lt.semver, options);
1831
+ if (gtltComp > 0) {
1832
+ return null;
1833
+ } else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
1834
+ return null;
1835
+ }
1836
+ }
1837
+ for (const eq of eqSet) {
1838
+ if (gt && !satisfies(eq, String(gt), options)) {
1839
+ return null;
1840
+ }
1841
+ if (lt && !satisfies(eq, String(lt), options)) {
1842
+ return null;
1843
+ }
1844
+ for (const c of dom) {
1845
+ if (!satisfies(eq, String(c), options)) {
1846
+ return false;
1847
+ }
1848
+ }
1849
+ return true;
1850
+ }
1851
+ let higher, lower;
1852
+ let hasDomLT, hasDomGT;
1853
+ let needDomLTPre = lt && !options.includePrerelease && lt.semver.prerelease.length ? lt.semver : false;
1854
+ let needDomGTPre = gt && !options.includePrerelease && gt.semver.prerelease.length ? gt.semver : false;
1855
+ if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt.operator === "<" && needDomLTPre.prerelease[0] === 0) {
1856
+ needDomLTPre = false;
1857
+ }
1858
+ for (const c of dom) {
1859
+ hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">=";
1860
+ hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<=";
1861
+ if (gt) {
1862
+ if (needDomGTPre) {
1863
+ if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) {
1864
+ needDomGTPre = false;
1865
+ }
1866
+ }
1867
+ if (c.operator === ">" || c.operator === ">=") {
1868
+ higher = higherGT(gt, c, options);
1869
+ if (higher === c && higher !== gt) {
1870
+ return false;
1871
+ }
1872
+ } else if (gt.operator === ">=" && !c.test(gt.semver)) {
1873
+ return false;
1874
+ }
1875
+ }
1876
+ if (lt) {
1877
+ if (needDomLTPre) {
1878
+ if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) {
1879
+ needDomLTPre = false;
1880
+ }
1881
+ }
1882
+ if (c.operator === "<" || c.operator === "<=") {
1883
+ lower = lowerLT(lt, c, options);
1884
+ if (lower === c && lower !== lt) {
1885
+ return false;
1886
+ }
1887
+ } else if (lt.operator === "<=" && !c.test(lt.semver)) {
1888
+ return false;
1889
+ }
1890
+ }
1891
+ if (!c.operator && (lt || gt) && gtltComp !== 0) {
1892
+ return false;
1893
+ }
1894
+ }
1895
+ if (gt && hasDomLT && !lt && gtltComp !== 0) {
1896
+ return false;
1897
+ }
1898
+ if (lt && hasDomGT && !gt && gtltComp !== 0) {
1899
+ return false;
1900
+ }
1901
+ if (needDomGTPre || needDomLTPre) {
1902
+ return false;
1903
+ }
1904
+ return true;
1905
+ };
1906
+ var higherGT = (a, b, options) => {
1907
+ if (!a) {
1908
+ return b;
1909
+ }
1910
+ const comp = compare(a.semver, b.semver, options);
1911
+ return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
1912
+ };
1913
+ var lowerLT = (a, b, options) => {
1914
+ if (!a) {
1915
+ return b;
1916
+ }
1917
+ const comp = compare(a.semver, b.semver, options);
1918
+ return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
1919
+ };
1920
+ module.exports = subset;
1921
+ }
1922
+ });
1923
+
1924
+ // node_modules/semver/index.js
1925
+ var require_semver2 = __commonJS({
1926
+ "node_modules/semver/index.js"(exports, module) {
1927
+ "use strict";
1928
+ var internalRe = require_re();
1929
+ var constants = require_constants();
1930
+ var SemVer = require_semver();
1931
+ var identifiers = require_identifiers();
1932
+ var parse = require_parse();
1933
+ var valid = require_valid();
1934
+ var clean = require_clean();
1935
+ var inc = require_inc();
1936
+ var diff = require_diff();
1937
+ var major = require_major();
1938
+ var minor = require_minor();
1939
+ var patch = require_patch();
1940
+ var prerelease = require_prerelease();
1941
+ var compare = require_compare();
1942
+ var rcompare = require_rcompare();
1943
+ var compareLoose = require_compare_loose();
1944
+ var compareBuild = require_compare_build();
1945
+ var sort = require_sort();
1946
+ var rsort = require_rsort();
1947
+ var gt = require_gt();
1948
+ var lt = require_lt();
1949
+ var eq = require_eq();
1950
+ var neq = require_neq();
1951
+ var gte = require_gte();
1952
+ var lte = require_lte();
1953
+ var cmp = require_cmp();
1954
+ var coerce = require_coerce();
1955
+ var truncate = require_truncate();
1956
+ var Comparator = require_comparator();
1957
+ var Range = require_range();
1958
+ var satisfies = require_satisfies();
1959
+ var toComparators = require_to_comparators();
1960
+ var maxSatisfying = require_max_satisfying();
1961
+ var minSatisfying = require_min_satisfying();
1962
+ var minVersion = require_min_version();
1963
+ var validRange2 = require_valid2();
1964
+ var outside = require_outside();
1965
+ var gtr = require_gtr();
1966
+ var ltr = require_ltr();
1967
+ var intersects = require_intersects();
1968
+ var simplifyRange = require_simplify();
1969
+ var subset = require_subset();
1970
+ module.exports = {
1971
+ parse,
1972
+ valid,
1973
+ clean,
1974
+ inc,
1975
+ diff,
1976
+ major,
1977
+ minor,
1978
+ patch,
1979
+ prerelease,
1980
+ compare,
1981
+ rcompare,
1982
+ compareLoose,
1983
+ compareBuild,
1984
+ sort,
1985
+ rsort,
1986
+ gt,
1987
+ lt,
1988
+ eq,
1989
+ neq,
1990
+ gte,
1991
+ lte,
1992
+ cmp,
1993
+ coerce,
1994
+ truncate,
1995
+ Comparator,
1996
+ Range,
1997
+ satisfies,
1998
+ toComparators,
1999
+ maxSatisfying,
2000
+ minSatisfying,
2001
+ minVersion,
2002
+ validRange: validRange2,
2003
+ outside,
2004
+ gtr,
2005
+ ltr,
2006
+ intersects,
2007
+ simplifyRange,
2008
+ subset,
2009
+ SemVer,
2010
+ re: internalRe.re,
2011
+ src: internalRe.src,
2012
+ tokens: internalRe.t,
2013
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
2014
+ RELEASE_TYPES: constants.RELEASE_TYPES,
2015
+ compareIdentifiers: identifiers.compareIdentifiers,
2016
+ rcompareIdentifiers: identifiers.rcompareIdentifiers
2017
+ };
2018
+ }
2019
+ });
2020
+
2021
+ // src/config.ts
2022
+ var workerNamePattern = /^[a-z](?:[a-z0-9-]{0,52}[a-z0-9])?$/;
2023
+ var accountIdPattern = /^[a-f0-9]{32}$/;
2024
+ var scopePattern = /^@[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/;
2025
+ var bindingPattern = /^[A-Z][A-Z0-9_]*$/;
2026
+ var hostnamePattern = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
2027
+ var reservedBindings = /* @__PURE__ */ new Set(["PKGFLARE_DB", "PKGFLARE_BUCKET", "PKGFLARE_CONFIG"]);
2028
+ function isObject(value) {
2029
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2030
+ }
2031
+ function normalizeConfig(value) {
2032
+ if (!isObject(value)) throw new Error("configuration must be an object");
2033
+ const { name, scopes: scopeValues, accountId, hostname, auth } = value;
2034
+ if (typeof name !== "string" || !workerNamePattern.test(name)) {
2035
+ throw new Error("name must be a lowercase Cloudflare resource name of at most 54 characters");
2036
+ }
2037
+ if (accountId !== void 0 && (typeof accountId !== "string" || !accountIdPattern.test(accountId))) {
2038
+ throw new Error("accountId must be a 32-character lowercase hexadecimal Cloudflare account ID");
2039
+ }
2040
+ if (!Array.isArray(scopeValues) || scopeValues.length === 0 || scopeValues.some((scope) => typeof scope !== "string")) {
2041
+ throw new Error("at least one package scope is required");
2042
+ }
2043
+ const scopes = [...new Set(scopeValues)];
2044
+ for (const scope of scopes) {
2045
+ if (!scopePattern.test(scope)) {
2046
+ throw new Error(`invalid package scope: ${scope}`);
2047
+ }
2048
+ }
2049
+ if (hostname !== void 0 && (typeof hostname !== "string" || !hostnamePattern.test(hostname))) {
2050
+ throw new Error("hostname must be a valid DNS hostname without a scheme or path");
2051
+ }
2052
+ if (!isObject(auth) || auth.provider !== "secrets") {
2053
+ throw new Error("unsupported authentication provider");
2054
+ }
2055
+ if (!Array.isArray(auth.tokens) || auth.tokens.length === 0) {
2056
+ throw new Error("at least one authentication token binding is required");
2057
+ }
2058
+ const seenBindings = /* @__PURE__ */ new Set();
2059
+ const tokens = auth.tokens.map((tokenValue) => {
2060
+ if (!isObject(tokenValue) || typeof tokenValue.binding !== "string") {
2061
+ throw new Error("authentication token binding must be an object with a binding name");
2062
+ }
2063
+ const { binding, permissions: permissionValues } = tokenValue;
2064
+ if (!bindingPattern.test(binding)) {
2065
+ throw new Error(`invalid secret binding: ${binding}`);
2066
+ }
2067
+ if (reservedBindings.has(binding)) {
2068
+ throw new Error(`secret binding is reserved by pkgflare: ${binding}`);
2069
+ }
2070
+ if (seenBindings.has(binding)) {
2071
+ throw new Error(`duplicate secret binding: ${binding}`);
2072
+ }
2073
+ seenBindings.add(binding);
2074
+ if (!Array.isArray(permissionValues) || permissionValues.length === 0 || permissionValues.some((permission) => permission !== "read" && permission !== "publish")) {
2075
+ throw new Error(`invalid permissions for ${binding}`);
2076
+ }
2077
+ const permissions = [...new Set(permissionValues)];
2078
+ return { binding, permissions };
2079
+ });
2080
+ return {
2081
+ name,
2082
+ scopes,
2083
+ ...accountId === void 0 ? {} : { accountId },
2084
+ ...hostname === void 0 ? {} : { hostname },
2085
+ auth: { provider: "secrets", tokens }
2086
+ };
2087
+ }
2088
+
2089
+ // src/runtime/response.ts
2090
+ function json(value, init = {}) {
2091
+ const headers = new Headers(init.headers);
2092
+ headers.set("content-type", "application/json; charset=utf-8");
2093
+ return new Response(JSON.stringify(value), { ...init, headers });
2094
+ }
2095
+ function npmError(status, error, reason) {
2096
+ const headers = new Headers({ "cache-control": "no-store" });
2097
+ if (status === 401) {
2098
+ headers.set("www-authenticate", 'Bearer realm="pkgflare"');
2099
+ }
2100
+ return json({ error, reason }, { status, headers });
2101
+ }
2102
+ function methodNotAllowed(allowed) {
2103
+ const response = npmError(405, "method_not_allowed", "method not allowed");
2104
+ response.headers.set("allow", allowed.join(", "));
2105
+ return response;
2106
+ }
2107
+
2108
+ // src/runtime/auth.ts
2109
+ function bearerToken(request) {
2110
+ const authorization = request.headers.get("authorization");
2111
+ if (authorization === null) return null;
2112
+ const match = /^Bearer[ \t]+([^\s]+)$/i.exec(authorization);
2113
+ return match?.[1] ?? null;
2114
+ }
2115
+ async function digest(value) {
2116
+ return new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
2117
+ }
2118
+ function equalDigest(left, right) {
2119
+ let difference = left.length ^ right.length;
2120
+ const length = Math.max(left.length, right.length);
2121
+ for (let index = 0; index < length; index += 1) {
2122
+ difference |= (left[index] ?? 0) ^ (right[index] ?? 0);
2123
+ }
2124
+ return difference === 0;
2125
+ }
2126
+ function grants(permissions, required) {
2127
+ return permissions.includes("publish") || permissions.includes(required);
2128
+ }
2129
+ async function authorize(request, context, required) {
2130
+ const candidate = bearerToken(request);
2131
+ if (candidate === null) {
2132
+ return npmError(401, "unauthorized", "authentication required");
2133
+ }
2134
+ const candidateDigest = await digest(candidate);
2135
+ let authorized = false;
2136
+ for (const token of context.config.auth.tokens) {
2137
+ const secret = context.env[token.binding];
2138
+ if (typeof secret !== "string" || secret.length === 0) continue;
2139
+ const matches = equalDigest(candidateDigest, await digest(secret));
2140
+ authorized ||= matches && grants(token.permissions, required);
2141
+ }
2142
+ return authorized ? null : npmError(403, "forbidden", `token does not grant ${required} access`);
2143
+ }
2144
+
2145
+ // src/runtime/diagnostics.ts
2146
+ function logRegistryError(requestId, operation, error) {
2147
+ console.error(
2148
+ JSON.stringify({
2149
+ level: "error",
2150
+ requestId,
2151
+ operation,
2152
+ errorType: error instanceof Error ? error.name : typeof error
2153
+ })
2154
+ );
2155
+ }
2156
+
2157
+ // src/runtime/dist-tags.ts
2158
+ var import_semver2 = __toESM(require_semver2(), 1);
2159
+
2160
+ // src/runtime/package-name.ts
2161
+ var import_semver = __toESM(require_semver2(), 1);
2162
+ var scopePart = "[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?";
2163
+ var packagePart = "[a-z0-9_-][a-z0-9._-]*";
2164
+ var packageNamePattern = new RegExp(`^@${scopePart}/${packagePart}$`);
2165
+ function parsePackageRoute(pathname) {
2166
+ let decoded;
2167
+ try {
2168
+ decoded = decodeURIComponent(pathname);
2169
+ } catch {
2170
+ return null;
2171
+ }
2172
+ const segments = decoded.split("/").filter(Boolean);
2173
+ const scope = segments[0];
2174
+ const name = segments[1];
2175
+ if (scope === void 0 || name === void 0 || !scope.startsWith("@")) return null;
2176
+ const packageName = `${scope}/${name}`;
2177
+ if (packageName.length > 214 || !packageNamePattern.test(packageName)) return null;
2178
+ return { packageName, remainder: segments.slice(2) };
2179
+ }
2180
+ function parseDistTagRoute(pathname) {
2181
+ let decoded;
2182
+ try {
2183
+ decoded = decodeURIComponent(pathname);
2184
+ } catch {
2185
+ return null;
2186
+ }
2187
+ const segments = decoded.split("/").filter(Boolean);
2188
+ if (segments[0] !== "-" || segments[1] !== "package" || segments[4] !== "dist-tags" || segments.length > 6) {
2189
+ return null;
2190
+ }
2191
+ const scope = segments[2];
2192
+ const name = segments[3];
2193
+ if (scope === void 0 || name === void 0) return null;
2194
+ const packageName = `${scope}/${name}`;
2195
+ if (packageName.length > 214 || !packageNamePattern.test(packageName)) return null;
2196
+ const tag = segments[5];
2197
+ return tag === void 0 ? { packageName } : { packageName, tag };
2198
+ }
2199
+ function isAllowedPackage(packageName, scopes) {
2200
+ const separator = packageName.indexOf("/");
2201
+ return separator > 0 && scopes.includes(packageName.slice(0, separator));
2202
+ }
2203
+ function isValidDistTag(tag) {
2204
+ return /^[a-z0-9][a-z0-9._-]*$/i.test(tag) && (0, import_semver.validRange)(tag, { loose: false }) === null;
2205
+ }
2206
+
2207
+ // src/runtime/dist-tags.ts
2208
+ var maximumDistTagBodyBytes = 256;
2209
+ async function readVersion(request) {
2210
+ if (request.body === null) throw new Error("missing body");
2211
+ const reader = request.body.getReader();
2212
+ const decoder = new TextDecoder("utf-8", { fatal: true });
2213
+ let bytesRead = 0;
2214
+ let contents = "";
2215
+ try {
2216
+ while (true) {
2217
+ const { done, value } = await reader.read();
2218
+ if (done) break;
2219
+ bytesRead += value.byteLength;
2220
+ if (bytesRead > maximumDistTagBodyBytes) {
2221
+ await reader.cancel();
2222
+ throw new PublishTagBodyError(413, "dist-tag request body exceeds 256 bytes");
2223
+ }
2224
+ contents += decoder.decode(value, { stream: true });
2225
+ }
2226
+ contents += decoder.decode();
2227
+ return JSON.parse(contents);
2228
+ } finally {
2229
+ reader.releaseLock();
2230
+ }
2231
+ }
2232
+ var PublishTagBodyError = class extends Error {
2233
+ constructor(status, message) {
2234
+ super(message);
2235
+ this.status = status;
2236
+ }
2237
+ status;
2238
+ };
2239
+ async function readDistTags(context, packageName) {
2240
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
2241
+ return npmError(404, "not_found", "package not found");
2242
+ }
2243
+ const result = await context.env.PKGFLARE_DB.prepare(
2244
+ "SELECT tag, version FROM dist_tags WHERE package_name = ?1 ORDER BY tag"
2245
+ ).bind(packageName).all();
2246
+ if (result.results.length === 0) {
2247
+ const packageRow = await context.env.PKGFLARE_DB.prepare(
2248
+ "SELECT 1 AS present FROM packages WHERE name = ?1"
2249
+ ).bind(packageName).first();
2250
+ if (packageRow === null) return npmError(404, "not_found", "package not found");
2251
+ }
2252
+ return json(Object.fromEntries(result.results.map((row) => [row.tag, row.version])), {
2253
+ headers: { "cache-control": "private, no-store" }
2254
+ });
2255
+ }
2256
+ async function setDistTag(request, context, packageName, tag) {
2257
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
2258
+ return npmError(404, "not_found", "package not found");
2259
+ }
2260
+ if (!isValidDistTag(tag)) return npmError(400, "bad_request", "dist-tag is invalid");
2261
+ let version;
2262
+ try {
2263
+ version = await readVersion(request);
2264
+ } catch (error) {
2265
+ if (error instanceof PublishTagBodyError) {
2266
+ return npmError(error.status, "payload_too_large", error.message);
2267
+ }
2268
+ return npmError(400, "bad_request", "dist-tag target must be a JSON version string");
2269
+ }
2270
+ if (typeof version !== "string" || (0, import_semver2.valid)(version, { loose: false }) !== version) {
2271
+ return npmError(400, "bad_request", "dist-tag target must be a valid strict semver version");
2272
+ }
2273
+ const result = await context.env.PKGFLARE_DB.prepare(
2274
+ "INSERT INTO dist_tags (package_name, tag, version) SELECT package_name, ?3, version FROM versions WHERE package_name = ?1 AND version = ?2 ON CONFLICT(package_name, tag) DO UPDATE SET version = excluded.version"
2275
+ ).bind(packageName, version, tag).run();
2276
+ if (result.meta.changes === 0) {
2277
+ return npmError(404, "not_found", "package version not found");
2278
+ }
2279
+ return json({ ok: true });
2280
+ }
2281
+ async function deleteDistTag(context, packageName, tag) {
2282
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
2283
+ return npmError(404, "not_found", "package not found");
2284
+ }
2285
+ if (!isValidDistTag(tag)) return npmError(400, "bad_request", "dist-tag is invalid");
2286
+ const result = await context.env.PKGFLARE_DB.prepare(
2287
+ "DELETE FROM dist_tags WHERE package_name = ?1 AND tag = ?2"
2288
+ ).bind(packageName, tag).run();
2289
+ return result.meta.changes === 0 ? npmError(404, "not_found", "dist-tag not found") : json({ ok: true });
2290
+ }
2291
+
2292
+ // src/runtime/publish.ts
2293
+ var import_semver3 = __toESM(require_semver2(), 1);
2294
+
2295
+ // src/runtime/publish-stream.ts
2296
+ var partSize = 5 * 1024 * 1024;
2297
+ var metadataLimit = 1024 * 1024;
2298
+ var maximumDepth = 128;
2299
+ var base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2300
+ var base64Values = new Int16Array(128).fill(-1);
2301
+ for (let index = 0; index < base64Alphabet.length; index += 1) {
2302
+ base64Values[base64Alphabet.charCodeAt(index)] = index;
2303
+ }
2304
+ var PublishStreamError = class extends Error {
2305
+ constructor(status, code, message) {
2306
+ super(message);
2307
+ this.status = status;
2308
+ this.code = code;
2309
+ }
2310
+ status;
2311
+ code;
2312
+ };
2313
+ function badJson(message = "request body must be valid JSON") {
2314
+ return new PublishStreamError(400, "bad_request", message);
2315
+ }
2316
+ function hex(bytes) {
2317
+ return [...new Uint8Array(bytes)].map((value) => value.toString(16).padStart(2, "0")).join("");
2318
+ }
2319
+ function base64(bytes) {
2320
+ let binary = "";
2321
+ for (const value of new Uint8Array(bytes)) binary += String.fromCharCode(value);
2322
+ return btoa(binary);
2323
+ }
2324
+ function digestStream(algorithm) {
2325
+ const constructor = crypto.DigestStream;
2326
+ return new constructor(algorithm);
2327
+ }
2328
+ var MultipartTarball = class _MultipartTarball {
2329
+ key;
2330
+ filename;
2331
+ #upload;
2332
+ #sha1 = digestStream("SHA-1");
2333
+ #sha512 = digestStream("SHA-512");
2334
+ #sha1Writer = this.#sha1.getWriter();
2335
+ #sha512Writer = this.#sha512.getWriter();
2336
+ #parts = [];
2337
+ #buffer = new Uint8Array(partSize);
2338
+ #bufferLength = 0;
2339
+ #quartet = [];
2340
+ #base64Ended = false;
2341
+ #finished = false;
2342
+ #aborted = false;
2343
+ #length = 0;
2344
+ #shasum;
2345
+ #integrity;
2346
+ constructor(upload, key, filename) {
2347
+ this.#upload = upload;
2348
+ this.key = key;
2349
+ this.filename = filename;
2350
+ }
2351
+ static async create(bucket, packageName, filename) {
2352
+ const key = `packages/${encodeURIComponent(packageName)}/${crypto.randomUUID()}.tgz`;
2353
+ const upload = await bucket.createMultipartUpload(key, {
2354
+ httpMetadata: { contentType: "application/octet-stream" }
2355
+ });
2356
+ return new _MultipartTarball(upload, key, filename);
2357
+ }
2358
+ get length() {
2359
+ this.#assertFinished();
2360
+ return this.#length;
2361
+ }
2362
+ get shasum() {
2363
+ this.#assertFinished();
2364
+ return this.#shasum ?? "";
2365
+ }
2366
+ get integrity() {
2367
+ this.#assertFinished();
2368
+ return this.#integrity ?? "";
2369
+ }
2370
+ async writeBase64(value) {
2371
+ if (this.#finished || this.#aborted) throw new Error("tarball upload is no longer writable");
2372
+ for (const character of value) {
2373
+ const characterCode = character.charCodeAt(0);
2374
+ if (characterCode === 9 || characterCode === 10 || characterCode === 13 || characterCode === 32) {
2375
+ continue;
2376
+ }
2377
+ if (this.#base64Ended) {
2378
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2379
+ }
2380
+ if (character === "=") {
2381
+ this.#quartet.push(-1);
2382
+ } else {
2383
+ const valueIndex = characterCode < base64Values.length ? base64Values[characterCode] ?? -1 : -1;
2384
+ if (valueIndex === -1) {
2385
+ throw new PublishStreamError(
2386
+ 400,
2387
+ "bad_request",
2388
+ "tarball attachment is not valid base64"
2389
+ );
2390
+ }
2391
+ this.#quartet.push(valueIndex);
2392
+ }
2393
+ if (this.#quartet.length === 4) {
2394
+ const decoded = this.#decodeQuartet(true);
2395
+ const pending = this.#writeBytes(decoded);
2396
+ if (pending !== void 0) await pending;
2397
+ }
2398
+ }
2399
+ }
2400
+ async finishBase64() {
2401
+ if (this.#finished) return;
2402
+ if (this.#quartet.length === 1 || this.#quartet.some((value) => value < 0)) {
2403
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2404
+ }
2405
+ if (this.#quartet.length > 0) {
2406
+ const decoded = this.#decodeQuartet(false);
2407
+ const pending = this.#writeBytes(decoded);
2408
+ if (pending !== void 0) await pending;
2409
+ }
2410
+ if (this.#bufferLength > 0) {
2411
+ await this.#uploadPart(this.#buffer.slice(0, this.#bufferLength));
2412
+ this.#bufferLength = 0;
2413
+ }
2414
+ if (this.#length === 0) {
2415
+ throw new PublishStreamError(400, "bad_request", "tarball attachment must not be empty");
2416
+ }
2417
+ await Promise.all([this.#sha1Writer.close(), this.#sha512Writer.close()]);
2418
+ const [sha1, sha512] = await Promise.all([this.#sha1.digest, this.#sha512.digest]);
2419
+ this.#shasum = hex(sha1);
2420
+ this.#integrity = `sha512-${base64(sha512)}`;
2421
+ this.#finished = true;
2422
+ }
2423
+ async complete() {
2424
+ this.#assertFinished();
2425
+ if (this.#aborted) throw new Error("tarball upload was aborted");
2426
+ return this.#upload.complete(this.#parts);
2427
+ }
2428
+ async abort() {
2429
+ if (this.#aborted) return;
2430
+ this.#aborted = true;
2431
+ const reason = new Error("tarball upload aborted");
2432
+ await Promise.allSettled([
2433
+ this.#upload.abort(),
2434
+ this.#sha1Writer.abort(reason),
2435
+ this.#sha512Writer.abort(reason),
2436
+ this.#sha1.digest,
2437
+ this.#sha512.digest
2438
+ ]);
2439
+ }
2440
+ #decodeQuartet(padded) {
2441
+ const [first, second, third = -1, fourth = -1] = this.#quartet;
2442
+ this.#quartet = [];
2443
+ if (first === void 0 || second === void 0 || first < 0 || second < 0) {
2444
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2445
+ }
2446
+ if (third < 0) {
2447
+ if (padded && fourth !== -1 || !padded && this.#base64Ended || (second & 15) !== 0) {
2448
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2449
+ }
2450
+ this.#base64Ended = true;
2451
+ return [first << 2 | second >> 4];
2452
+ }
2453
+ if (fourth < 0) {
2454
+ if ((third & 3) !== 0) {
2455
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2456
+ }
2457
+ const bytes = [first << 2 | second >> 4, (second & 15) << 4 | third >> 2];
2458
+ this.#base64Ended = true;
2459
+ return bytes;
2460
+ }
2461
+ return [
2462
+ first << 2 | second >> 4,
2463
+ (second & 15) << 4 | third >> 2,
2464
+ (third & 3) << 6 | fourth
2465
+ ];
2466
+ }
2467
+ #writeBytes(bytes) {
2468
+ let pending;
2469
+ for (const byte of bytes) {
2470
+ this.#buffer[this.#bufferLength] = byte;
2471
+ this.#bufferLength += 1;
2472
+ this.#length += 1;
2473
+ if (this.#bufferLength === partSize) {
2474
+ const fullPart = this.#buffer;
2475
+ this.#buffer = new Uint8Array(partSize);
2476
+ this.#bufferLength = 0;
2477
+ pending = this.#uploadPart(fullPart);
2478
+ }
2479
+ }
2480
+ return pending;
2481
+ }
2482
+ async #uploadPart(bytes) {
2483
+ await Promise.all([this.#sha1Writer.write(bytes), this.#sha512Writer.write(bytes)]);
2484
+ const part = await this.#upload.uploadPart(this.#parts.length + 1, bytes);
2485
+ this.#parts.push(part);
2486
+ }
2487
+ #assertFinished() {
2488
+ if (!this.#finished) throw new Error("tarball upload is not finished");
2489
+ }
2490
+ };
2491
+ var PublishJsonScanner = class {
2492
+ #decoder = new TextDecoder("utf-8", { fatal: true });
2493
+ #encoder = new TextEncoder();
2494
+ #bucket;
2495
+ #packageName;
2496
+ #frames = [];
2497
+ #metadataParts = [];
2498
+ #metadataPending = "";
2499
+ #metadataBytes = 0;
2500
+ #rootState = "value";
2501
+ #mode = "default";
2502
+ #stringRole = "value";
2503
+ #stringRaw = "";
2504
+ #stringPath = [];
2505
+ #stringIsAttachment = false;
2506
+ #escapeState = "none";
2507
+ #unicodeEscape = "";
2508
+ #primitive = "";
2509
+ #attachment;
2510
+ #attachmentText = "";
2511
+ constructor(bucket, packageName) {
2512
+ this.#bucket = bucket;
2513
+ this.#packageName = packageName;
2514
+ }
2515
+ async write(bytes) {
2516
+ let text;
2517
+ try {
2518
+ text = this.#decoder.decode(bytes, { stream: true });
2519
+ } catch {
2520
+ throw badJson("request body must be valid UTF-8 JSON");
2521
+ }
2522
+ await this.#consume(text);
2523
+ this.#flushMetadata();
2524
+ }
2525
+ async finish() {
2526
+ let tail;
2527
+ try {
2528
+ tail = this.#decoder.decode();
2529
+ } catch {
2530
+ throw badJson("request body must be valid UTF-8 JSON");
2531
+ }
2532
+ await this.#consume(tail);
2533
+ if (this.#mode === "primitive") this.#finishPrimitive();
2534
+ if (this.#mode !== "default" || this.#frames.length !== 0 || this.#rootState !== "done") {
2535
+ throw badJson();
2536
+ }
2537
+ this.#flushMetadata();
2538
+ await this.#flushAttachmentText();
2539
+ const attachment = this.#attachment;
2540
+ if (attachment === void 0) {
2541
+ throw new PublishStreamError(
2542
+ 400,
2543
+ "bad_request",
2544
+ "publish must contain one tarball attachment"
2545
+ );
2546
+ }
2547
+ await attachment.finishBase64();
2548
+ let document;
2549
+ try {
2550
+ document = JSON.parse(this.#metadataParts.join(""));
2551
+ } catch {
2552
+ throw badJson();
2553
+ }
2554
+ return { document, tarball: attachment };
2555
+ }
2556
+ async abort() {
2557
+ await this.#attachment?.abort();
2558
+ }
2559
+ async #consume(text) {
2560
+ for (const character of text) {
2561
+ let pending;
2562
+ if (this.#mode === "string") {
2563
+ pending = this.#consumeString(character);
2564
+ } else if (this.#mode === "primitive") {
2565
+ pending = this.#consumePrimitive(character);
2566
+ } else {
2567
+ pending = this.#consumeDefault(character);
2568
+ }
2569
+ if (pending !== void 0) await pending;
2570
+ }
2571
+ }
2572
+ #consumeDefault(character) {
2573
+ if (/\s/.test(character)) {
2574
+ this.#appendMetadata(character);
2575
+ return void 0;
2576
+ }
2577
+ if (character === '"') {
2578
+ const frame = this.#frames.at(-1);
2579
+ const isKey = frame?.type === "object" && (frame.state === "keyOrEnd" || frame.state === "key");
2580
+ if (!isKey && !this.#expectsValue()) throw badJson();
2581
+ this.#mode = "string";
2582
+ this.#stringRole = isKey ? "key" : "value";
2583
+ this.#stringPath = isKey ? [] : this.#currentValuePath();
2584
+ this.#stringIsAttachment = this.#isAttachmentPath(this.#stringPath);
2585
+ this.#stringRaw = '"';
2586
+ this.#escapeState = "none";
2587
+ this.#unicodeEscape = "";
2588
+ this.#appendMetadata('"');
2589
+ if (this.#stringIsAttachment) {
2590
+ if (this.#attachment !== void 0) {
2591
+ throw new PublishStreamError(
2592
+ 400,
2593
+ "bad_request",
2594
+ "publish must contain exactly one tarball attachment"
2595
+ );
2596
+ }
2597
+ const filename = this.#stringPath[1];
2598
+ if (typeof filename !== "string") throw badJson();
2599
+ return MultipartTarball.create(this.#bucket, this.#packageName, filename).then(
2600
+ (attachment) => {
2601
+ this.#attachment = attachment;
2602
+ }
2603
+ );
2604
+ }
2605
+ return void 0;
2606
+ }
2607
+ if (character === "{" || character === "[") {
2608
+ if (!this.#expectsValue()) throw badJson();
2609
+ if (this.#frames.length >= maximumDepth) {
2610
+ throw new PublishStreamError(400, "bad_request", "JSON nesting exceeds 128 levels");
2611
+ }
2612
+ const path = this.#currentValuePath();
2613
+ this.#appendMetadata(character);
2614
+ this.#frames.push(
2615
+ character === "{" ? { type: "object", path, state: "keyOrEnd", keys: /* @__PURE__ */ new Set() } : { type: "array", path, state: "valueOrEnd", index: 0 }
2616
+ );
2617
+ return void 0;
2618
+ }
2619
+ if (character === "}" || character === "]") {
2620
+ const frame = this.#frames.at(-1);
2621
+ const valid = character === "}" ? frame?.type === "object" && (frame.state === "keyOrEnd" || frame.state === "commaOrEnd") : frame?.type === "array" && (frame.state === "valueOrEnd" || frame.state === "commaOrEnd");
2622
+ if (!valid) throw badJson();
2623
+ this.#appendMetadata(character);
2624
+ this.#frames.pop();
2625
+ this.#completeValue();
2626
+ return void 0;
2627
+ }
2628
+ if (character === ":") {
2629
+ const frame = this.#frames.at(-1);
2630
+ if (frame?.type !== "object" || frame.state !== "colon") throw badJson();
2631
+ frame.state = "value";
2632
+ this.#appendMetadata(character);
2633
+ return void 0;
2634
+ }
2635
+ if (character === ",") {
2636
+ const frame = this.#frames.at(-1);
2637
+ if (frame?.state !== "commaOrEnd") throw badJson();
2638
+ if (frame.type === "object") {
2639
+ frame.state = "key";
2640
+ delete frame.currentKey;
2641
+ } else {
2642
+ frame.state = "value";
2643
+ frame.index += 1;
2644
+ }
2645
+ this.#appendMetadata(character);
2646
+ return void 0;
2647
+ }
2648
+ if (this.#expectsValue() && /[-0-9tfn]/.test(character)) {
2649
+ this.#mode = "primitive";
2650
+ this.#primitive = character;
2651
+ this.#appendMetadata(character);
2652
+ return void 0;
2653
+ }
2654
+ throw badJson();
2655
+ }
2656
+ #consumeString(character) {
2657
+ if (this.#escapeState === "unicode") {
2658
+ if (!/[0-9a-f]/i.test(character)) throw badJson();
2659
+ this.#unicodeEscape += character;
2660
+ if (!this.#stringIsAttachment) this.#appendStringRaw(character);
2661
+ if (this.#unicodeEscape.length === 4) {
2662
+ if (this.#stringIsAttachment) {
2663
+ const pending = this.#appendAttachmentCharacter(
2664
+ String.fromCharCode(Number.parseInt(this.#unicodeEscape, 16))
2665
+ );
2666
+ this.#escapeState = "none";
2667
+ return pending;
2668
+ }
2669
+ this.#escapeState = "none";
2670
+ }
2671
+ return void 0;
2672
+ }
2673
+ if (this.#escapeState === "escaped") {
2674
+ if (character === "u") {
2675
+ if (!this.#stringIsAttachment) this.#appendStringRaw(character);
2676
+ this.#unicodeEscape = "";
2677
+ this.#escapeState = "unicode";
2678
+ return void 0;
2679
+ }
2680
+ const escapedCharacters = {
2681
+ '"': '"',
2682
+ "\\": "\\",
2683
+ "/": "/",
2684
+ b: "\b",
2685
+ f: "\f",
2686
+ n: "\n",
2687
+ r: "\r",
2688
+ t: " "
2689
+ };
2690
+ const decoded = escapedCharacters[character];
2691
+ if (decoded === void 0) throw badJson();
2692
+ this.#escapeState = "none";
2693
+ if (this.#stringIsAttachment) return this.#appendAttachmentCharacter(decoded);
2694
+ this.#appendStringRaw(character);
2695
+ return void 0;
2696
+ }
2697
+ if (character === "\\") {
2698
+ if (!this.#stringIsAttachment) this.#appendStringRaw(character);
2699
+ this.#escapeState = "escaped";
2700
+ return void 0;
2701
+ }
2702
+ if (character === '"') {
2703
+ const pending = this.#flushAttachmentText();
2704
+ this.#appendMetadata('"');
2705
+ if (this.#stringRole === "key") this.#finishKey();
2706
+ else this.#completeValue();
2707
+ this.#mode = "default";
2708
+ return pending;
2709
+ }
2710
+ if (character.charCodeAt(0) < 32) throw badJson();
2711
+ if (this.#stringIsAttachment) return this.#appendAttachmentCharacter(character);
2712
+ this.#appendStringRaw(character);
2713
+ return void 0;
2714
+ }
2715
+ #consumePrimitive(character) {
2716
+ if (/\s/.test(character) || character === "," || character === "}" || character === "]") {
2717
+ this.#finishPrimitive();
2718
+ return this.#consumeDefault(character);
2719
+ }
2720
+ if (character === ":" || character === "{" || character === "[" || character === '"') {
2721
+ throw badJson();
2722
+ }
2723
+ this.#primitive += character;
2724
+ this.#appendMetadata(character);
2725
+ return void 0;
2726
+ }
2727
+ #finishPrimitive() {
2728
+ try {
2729
+ const parsed = JSON.parse(this.#primitive);
2730
+ if (typeof parsed !== "number" && typeof parsed !== "boolean" && parsed !== null)
2731
+ throw badJson();
2732
+ } catch {
2733
+ throw badJson();
2734
+ }
2735
+ this.#primitive = "";
2736
+ this.#mode = "default";
2737
+ this.#completeValue();
2738
+ }
2739
+ #finishKey() {
2740
+ const frame = this.#frames.at(-1);
2741
+ if (frame?.type !== "object") throw badJson();
2742
+ let key;
2743
+ try {
2744
+ key = JSON.parse(`${this.#stringRaw}"`);
2745
+ } catch {
2746
+ throw badJson();
2747
+ }
2748
+ if (frame.keys.has(key)) {
2749
+ throw new PublishStreamError(400, "bad_request", `duplicate JSON key: ${key}`);
2750
+ }
2751
+ frame.keys.add(key);
2752
+ frame.currentKey = key;
2753
+ frame.state = "colon";
2754
+ }
2755
+ #expectsValue() {
2756
+ const frame = this.#frames.at(-1);
2757
+ if (frame === void 0) return this.#rootState === "value";
2758
+ return frame.type === "object" ? frame.state === "value" : frame.state === "valueOrEnd" || frame.state === "value";
2759
+ }
2760
+ #currentValuePath() {
2761
+ const frame = this.#frames.at(-1);
2762
+ if (frame === void 0) return [];
2763
+ if (frame.type === "array") return [...frame.path, frame.index];
2764
+ if (frame.currentKey === void 0) throw badJson();
2765
+ return [...frame.path, frame.currentKey];
2766
+ }
2767
+ #completeValue() {
2768
+ const frame = this.#frames.at(-1);
2769
+ if (frame === void 0) {
2770
+ if (this.#rootState !== "value") throw badJson();
2771
+ this.#rootState = "done";
2772
+ return;
2773
+ }
2774
+ if (frame.type === "object") {
2775
+ if (frame.state !== "value") throw badJson();
2776
+ frame.state = "commaOrEnd";
2777
+ } else {
2778
+ if (frame.state !== "value" && frame.state !== "valueOrEnd") throw badJson();
2779
+ frame.state = "commaOrEnd";
2780
+ }
2781
+ }
2782
+ #isAttachmentPath(path) {
2783
+ return path.length === 3 && path[0] === "_attachments" && typeof path[1] === "string" && path[2] === "data";
2784
+ }
2785
+ #appendStringRaw(character) {
2786
+ if (this.#stringRole === "key") this.#stringRaw += character;
2787
+ this.#appendMetadata(character);
2788
+ }
2789
+ #appendAttachmentCharacter(character) {
2790
+ if (character.length !== 1 || character.charCodeAt(0) > 127) {
2791
+ throw new PublishStreamError(400, "bad_request", "tarball attachment is not valid base64");
2792
+ }
2793
+ this.#attachmentText += character;
2794
+ if (this.#attachmentText.length >= 8192) return this.#flushAttachmentText();
2795
+ return void 0;
2796
+ }
2797
+ #flushAttachmentText() {
2798
+ if (this.#attachmentText === "") return void 0;
2799
+ const value = this.#attachmentText;
2800
+ this.#attachmentText = "";
2801
+ return this.#attachment?.writeBase64(value);
2802
+ }
2803
+ #appendMetadata(value) {
2804
+ this.#metadataPending += value;
2805
+ if (this.#metadataPending.length >= 8192) this.#flushMetadata();
2806
+ }
2807
+ #flushMetadata() {
2808
+ if (this.#metadataPending === "") return;
2809
+ this.#metadataBytes += this.#encoder.encode(this.#metadataPending).byteLength;
2810
+ if (this.#metadataBytes > metadataLimit) {
2811
+ throw new PublishStreamError(413, "payload_too_large", "publish metadata exceeds 1 MiB");
2812
+ }
2813
+ this.#metadataParts.push(this.#metadataPending);
2814
+ this.#metadataPending = "";
2815
+ }
2816
+ };
2817
+ async function parsePublishRequest(request, bucket, packageName) {
2818
+ if (request.body === null) throw badJson();
2819
+ const scanner = new PublishJsonScanner(bucket, packageName);
2820
+ const reader = request.body.getReader();
2821
+ try {
2822
+ while (true) {
2823
+ const { done, value } = await reader.read();
2824
+ if (done) break;
2825
+ await scanner.write(value);
2826
+ }
2827
+ return await scanner.finish();
2828
+ } catch (error) {
2829
+ await reader.cancel().catch(() => void 0);
2830
+ await scanner.abort().catch(() => void 0);
2831
+ if (error instanceof PublishStreamError) throw error;
2832
+ throw error;
2833
+ } finally {
2834
+ reader.releaseLock();
2835
+ }
2836
+ }
2837
+
2838
+ // src/runtime/publish.ts
2839
+ var PublishError = class extends Error {
2840
+ constructor(status, code, message) {
2841
+ super(message);
2842
+ this.status = status;
2843
+ this.code = code;
2844
+ }
2845
+ status;
2846
+ code;
2847
+ };
2848
+ function object(value) {
2849
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2850
+ }
2851
+ function validateDocument(value, pathPackageName, scopes, tarball) {
2852
+ if (!object(value)) {
2853
+ throw new PublishError(400, "bad_request", "publish document must be an object");
2854
+ }
2855
+ const document = value;
2856
+ if (document.name !== pathPackageName || document._id !== void 0 && document._id !== pathPackageName) {
2857
+ throw new PublishError(400, "bad_request", "package name does not match request path");
2858
+ }
2859
+ if (!isAllowedPackage(pathPackageName, scopes)) {
2860
+ throw new PublishError(403, "forbidden", "package scope is not configured for this registry");
2861
+ }
2862
+ if (!object(document.versions) || Object.keys(document.versions).length !== 1) {
2863
+ throw new PublishError(400, "bad_request", "publish must contain exactly one version");
2864
+ }
2865
+ const [versionEntry] = Object.entries(document.versions);
2866
+ if (versionEntry === void 0 || (0, import_semver3.valid)(versionEntry[0], { loose: false }) !== versionEntry[0]) {
2867
+ throw new PublishError(400, "bad_request", "package version must be valid strict semver");
2868
+ }
2869
+ const [version, manifestValue] = versionEntry;
2870
+ if (!object(manifestValue) || manifestValue.name !== pathPackageName || manifestValue.version !== version) {
2871
+ throw new PublishError(
2872
+ 400,
2873
+ "bad_request",
2874
+ "manifest name and version must match the publish document"
2875
+ );
2876
+ }
2877
+ if (!object(document["dist-tags"]) || Object.keys(document["dist-tags"]).length === 0) {
2878
+ throw new PublishError(400, "bad_request", "at least one dist-tag is required");
2879
+ }
2880
+ const tags = {};
2881
+ for (const [tag, target] of Object.entries(document["dist-tags"])) {
2882
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(tag) || target !== version) {
2883
+ throw new PublishError(400, "bad_request", "dist-tags must reference the published version");
2884
+ }
2885
+ tags[tag] = version;
2886
+ }
2887
+ if (!object(document._attachments) || Object.keys(document._attachments).length !== 1) {
2888
+ throw new PublishError(
2889
+ 400,
2890
+ "bad_request",
2891
+ "publish must contain exactly one tarball attachment"
2892
+ );
2893
+ }
2894
+ const [attachmentEntry] = Object.entries(document._attachments);
2895
+ if (attachmentEntry === void 0 || !object(attachmentEntry[1])) {
2896
+ throw new PublishError(400, "bad_request", "tarball attachment is invalid");
2897
+ }
2898
+ const [attachmentName, attachment] = attachmentEntry;
2899
+ const packageBasename = pathPackageName.slice(pathPackageName.indexOf("/") + 1);
2900
+ const filename = `${packageBasename}-${version}.tgz`;
2901
+ const standardScopedName = `${pathPackageName}-${version}.tgz`;
2902
+ if (attachmentName !== filename && attachmentName !== standardScopedName || attachmentName !== tarball.filename || typeof attachment.data !== "string") {
2903
+ throw new PublishError(400, "bad_request", "tarball attachment is invalid");
2904
+ }
2905
+ if (attachment.content_type !== void 0 && attachment.content_type !== "application/octet-stream") {
2906
+ throw new PublishError(
2907
+ 400,
2908
+ "bad_request",
2909
+ "tarball attachment has an unsupported content type"
2910
+ );
2911
+ }
2912
+ if (attachment.length !== void 0 && attachment.length !== tarball.length) {
2913
+ throw new PublishError(400, "bad_request", "tarball attachment length does not match its data");
2914
+ }
2915
+ return {
2916
+ packageName: pathPackageName,
2917
+ version,
2918
+ manifest: manifestValue,
2919
+ tags,
2920
+ filename,
2921
+ tarball
2922
+ };
2923
+ }
2924
+ function verifyClientChecksums(manifest, shasum, integrity) {
2925
+ if (manifest.dist?.shasum !== void 0 && manifest.dist.shasum !== shasum) {
2926
+ throw new PublishError(400, "bad_request", "tarball SHA-1 does not match manifest");
2927
+ }
2928
+ if (manifest.dist?.integrity !== void 0 && manifest.dist.integrity !== integrity) {
2929
+ throw new PublishError(400, "bad_request", "tarball integrity does not match manifest");
2930
+ }
2931
+ }
2932
+ async function reconcileCommit(context, publish) {
2933
+ const { shasum, integrity } = publish.tarball;
2934
+ let committed;
2935
+ try {
2936
+ committed = await context.env.PKGFLARE_DB.prepare(
2937
+ "SELECT tarball_key, shasum, integrity FROM versions WHERE package_name = ?1 AND version = ?2"
2938
+ ).bind(publish.packageName, publish.version).first();
2939
+ } catch (error) {
2940
+ logRegistryError(context.requestId, "publish_d1_reconcile", error);
2941
+ return npmError(503, "storage_error", "publish outcome is unknown; retry the same version");
2942
+ }
2943
+ if (committed?.tarball_key === publish.tarball.key && committed.shasum === shasum && committed.integrity === integrity) {
2944
+ return json({ ok: true, id: publish.packageName, rev: publish.version }, { status: 201 });
2945
+ }
2946
+ if (committed !== null) {
2947
+ await context.env.PKGFLARE_BUCKET.delete(publish.tarball.key).catch((error) => {
2948
+ logRegistryError(context.requestId, "publish_r2_cleanup", error);
2949
+ });
2950
+ return npmError(409, "conflict", "package version already exists");
2951
+ }
2952
+ return npmError(503, "storage_error", "publish was not committed; retrying is safe");
2953
+ }
2954
+ async function publishPackage(request, context, packageName) {
2955
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
2956
+ return npmError(403, "forbidden", "package scope is not configured for this registry");
2957
+ }
2958
+ let parsed;
2959
+ try {
2960
+ parsed = await parsePublishRequest(request, context.env.PKGFLARE_BUCKET, packageName);
2961
+ } catch (error) {
2962
+ if (error instanceof PublishStreamError) {
2963
+ return npmError(error.status, error.code, error.message);
2964
+ }
2965
+ logRegistryError(context.requestId, "publish_parse", error);
2966
+ return npmError(503, "storage_error", "publish request could not be stored; retry is safe");
2967
+ }
2968
+ let completed = false;
2969
+ try {
2970
+ const publish = validateDocument(
2971
+ parsed.document,
2972
+ packageName,
2973
+ context.config.scopes,
2974
+ parsed.tarball
2975
+ );
2976
+ const existing = await context.env.PKGFLARE_DB.prepare(
2977
+ "SELECT 1 AS present FROM versions WHERE package_name = ?1 AND version = ?2"
2978
+ ).bind(publish.packageName, publish.version).first();
2979
+ if (existing !== null) {
2980
+ await publish.tarball.abort();
2981
+ return npmError(409, "conflict", "package version already exists");
2982
+ }
2983
+ const { shasum, integrity } = publish.tarball;
2984
+ verifyClientChecksums(publish.manifest, shasum, integrity);
2985
+ const stored = await publish.tarball.complete();
2986
+ completed = true;
2987
+ if (stored.size !== publish.tarball.length) {
2988
+ await context.env.PKGFLARE_BUCKET.delete(publish.tarball.key).catch(() => void 0);
2989
+ logRegistryError(context.requestId, "publish_r2_size", new Error("stored size mismatch"));
2990
+ return npmError(503, "storage_error", "tarball storage could not be verified");
2991
+ }
2992
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2993
+ const manifest = {
2994
+ ...publish.manifest,
2995
+ dist: {
2996
+ ...publish.manifest.dist,
2997
+ shasum,
2998
+ integrity
2999
+ }
3000
+ };
3001
+ const statements = [
3002
+ context.env.PKGFLARE_DB.prepare(
3003
+ "INSERT INTO packages (name, created_at, updated_at) VALUES (?1, ?2, ?2) ON CONFLICT(name) DO UPDATE SET updated_at = excluded.updated_at"
3004
+ ).bind(publish.packageName, now),
3005
+ context.env.PKGFLARE_DB.prepare(
3006
+ "INSERT INTO versions (package_name, version, manifest_json, tarball_key, tarball_file, shasum, integrity, tarball_size, published_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"
3007
+ ).bind(
3008
+ publish.packageName,
3009
+ publish.version,
3010
+ JSON.stringify(manifest),
3011
+ publish.tarball.key,
3012
+ publish.filename,
3013
+ shasum,
3014
+ integrity,
3015
+ publish.tarball.length,
3016
+ now
3017
+ ),
3018
+ ...Object.entries(publish.tags).map(
3019
+ ([tag, version]) => context.env.PKGFLARE_DB.prepare(
3020
+ "INSERT INTO dist_tags (package_name, tag, version) VALUES (?1, ?2, ?3) ON CONFLICT(package_name, tag) DO UPDATE SET version = excluded.version"
3021
+ ).bind(publish.packageName, tag, version)
3022
+ )
3023
+ ];
3024
+ try {
3025
+ await context.env.PKGFLARE_DB.batch(statements);
3026
+ return json({ ok: true, id: publish.packageName, rev: publish.version }, { status: 201 });
3027
+ } catch (error) {
3028
+ logRegistryError(context.requestId, "publish_d1_commit", error);
3029
+ return reconcileCommit(context, publish);
3030
+ }
3031
+ } catch (error) {
3032
+ if (!completed) await parsed.tarball.abort().catch(() => void 0);
3033
+ if (error instanceof PublishError) return npmError(error.status, error.code, error.message);
3034
+ logRegistryError(context.requestId, "publish", error);
3035
+ return npmError(503, "storage_error", "publish failed; retrying the same version is safe");
3036
+ }
3037
+ }
3038
+
3039
+ // src/runtime/read.ts
3040
+ function tarballUrl(request, packageName, filename) {
3041
+ const url = new URL(request.url);
3042
+ const packagePath = packageName.split("/").map(encodeURIComponent).join("/");
3043
+ return `${url.origin}/${packagePath}/-/${encodeURIComponent(filename)}`;
3044
+ }
3045
+ function publicManifest(request, packageName, row) {
3046
+ const manifest = JSON.parse(row.manifest_json);
3047
+ return {
3048
+ ...manifest,
3049
+ dist: {
3050
+ ...manifest.dist,
3051
+ tarball: tarballUrl(request, packageName, row.tarball_file),
3052
+ shasum: row.shasum,
3053
+ integrity: row.integrity
3054
+ }
3055
+ };
3056
+ }
3057
+ async function packageRows(context, packageName) {
3058
+ const [versionsResult, tagsResult] = await context.env.PKGFLARE_DB.batch([
3059
+ context.env.PKGFLARE_DB.prepare(
3060
+ "SELECT version, manifest_json, tarball_file, shasum, integrity, published_at FROM versions WHERE package_name = ?1 ORDER BY published_at"
3061
+ ).bind(packageName),
3062
+ context.env.PKGFLARE_DB.prepare(
3063
+ "SELECT tag, version FROM dist_tags WHERE package_name = ?1 ORDER BY tag"
3064
+ ).bind(packageName)
3065
+ ]);
3066
+ return { versions: versionsResult.results ?? [], tags: tagsResult.results ?? [] };
3067
+ }
3068
+ async function readPackage(request, context, packageName, selector) {
3069
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
3070
+ return npmError(404, "not_found", "package not found");
3071
+ }
3072
+ const { versions, tags } = await packageRows(context, packageName);
3073
+ if (versions.length === 0) return npmError(404, "not_found", "package not found");
3074
+ if (selector !== void 0) {
3075
+ const selectedVersion = tags.find((row2) => row2.tag === selector)?.version ?? selector;
3076
+ const row = versions.find((candidate) => candidate.version === selectedVersion);
3077
+ return row === void 0 ? npmError(404, "not_found", "package version or dist-tag not found") : json(publicManifest(request, packageName, row), {
3078
+ headers: { "cache-control": "private, no-store" }
3079
+ });
3080
+ }
3081
+ const manifests = Object.fromEntries(
3082
+ versions.map((row) => [row.version, publicManifest(request, packageName, row)])
3083
+ );
3084
+ const distTags = Object.fromEntries(tags.map((row) => [row.tag, row.version]));
3085
+ const publishedTimes = Object.fromEntries(versions.map((row) => [row.version, row.published_at]));
3086
+ return json(
3087
+ {
3088
+ _id: packageName,
3089
+ name: packageName,
3090
+ "dist-tags": distTags,
3091
+ versions: manifests,
3092
+ time: {
3093
+ created: versions[0]?.published_at,
3094
+ modified: versions.at(-1)?.published_at,
3095
+ ...publishedTimes
3096
+ }
3097
+ },
3098
+ { headers: { "cache-control": "private, no-store" } }
3099
+ );
3100
+ }
3101
+ function contentRange(object2) {
3102
+ if (object2.range === void 0) return null;
3103
+ if ("offset" in object2.range) {
3104
+ const length = object2.range.length ?? object2.size - object2.range.offset;
3105
+ return {
3106
+ header: `bytes ${String(object2.range.offset)}-${String(object2.range.offset + length - 1)}/${String(object2.size)}`,
3107
+ length
3108
+ };
3109
+ }
3110
+ if ("suffix" in object2.range) {
3111
+ return {
3112
+ header: `bytes ${String(object2.size - object2.range.suffix)}-${String(object2.size - 1)}/${String(object2.size)}`,
3113
+ length: object2.range.suffix
3114
+ };
3115
+ }
3116
+ return null;
3117
+ }
3118
+ async function readTarball(request, context, packageName, filename) {
3119
+ if (!isAllowedPackage(packageName, context.config.scopes)) {
3120
+ return npmError(404, "not_found", "tarball not found");
3121
+ }
3122
+ const row = await context.env.PKGFLARE_DB.prepare(
3123
+ "SELECT tarball_key, shasum, integrity, tarball_size FROM versions WHERE package_name = ?1 AND tarball_file = ?2"
3124
+ ).bind(packageName, filename).first();
3125
+ if (row === null) return npmError(404, "not_found", "tarball not found");
3126
+ const ifNoneMatch = request.headers.get("if-none-match");
3127
+ const range = request.headers.get("range");
3128
+ const object2 = request.method === "HEAD" ? await context.env.PKGFLARE_BUCKET.head(row.tarball_key) : await context.env.PKGFLARE_BUCKET.get(
3129
+ row.tarball_key,
3130
+ range === null ? {} : { range: request.headers }
3131
+ );
3132
+ if (object2 === null) {
3133
+ return npmError(503, "storage_inconsistent", "published tarball is temporarily unavailable");
3134
+ }
3135
+ const headers = new Headers({
3136
+ "accept-ranges": "bytes",
3137
+ "cache-control": "private, max-age=31536000, immutable",
3138
+ "content-type": "application/octet-stream",
3139
+ etag: object2.httpEtag,
3140
+ "x-pkgflare-integrity": row.integrity
3141
+ });
3142
+ if (ifNoneMatch === object2.httpEtag && range === null) {
3143
+ return new Response(null, { status: 304, headers });
3144
+ }
3145
+ if (request.method === "HEAD") {
3146
+ headers.set("content-length", String(row.tarball_size));
3147
+ return new Response(null, { status: 200, headers });
3148
+ }
3149
+ const body = object2;
3150
+ const rangeHeader = range === null ? null : contentRange(body);
3151
+ if (rangeHeader !== null) {
3152
+ headers.set("content-range", rangeHeader.header);
3153
+ headers.set("content-length", String(rangeHeader.length));
3154
+ } else {
3155
+ headers.set("content-length", String(row.tarball_size));
3156
+ }
3157
+ return new Response(body.body, { status: rangeHeader === null ? 200 : 206, headers });
3158
+ }
3159
+
3160
+ // src/worker.ts
3161
+ function contextFromEnv(env, requestId) {
3162
+ try {
3163
+ return {
3164
+ env,
3165
+ config: normalizeConfig(JSON.parse(env.PKGFLARE_CONFIG)),
3166
+ requestId
3167
+ };
3168
+ } catch {
3169
+ return npmError(500, "configuration_error", "registry configuration is invalid");
3170
+ }
3171
+ }
3172
+ async function handle(request, env, requestId) {
3173
+ const context = contextFromEnv(env, requestId);
3174
+ if (context instanceof Response) return context;
3175
+ const url = new URL(request.url);
3176
+ if (url.pathname === "/-/ping") {
3177
+ if (request.method !== "GET" && request.method !== "HEAD") {
3178
+ return methodNotAllowed(["GET", "HEAD"]);
3179
+ }
3180
+ const denied = await authorize(request, context, "read");
3181
+ if (denied !== null) return denied;
3182
+ const response = json({ ok: true, name: context.config.name });
3183
+ return request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response;
3184
+ }
3185
+ const distTagRoute = parseDistTagRoute(url.pathname);
3186
+ if (distTagRoute !== null) {
3187
+ if (distTagRoute.tag === void 0) {
3188
+ if (request.method !== "GET" && request.method !== "HEAD") {
3189
+ return methodNotAllowed(["GET", "HEAD"]);
3190
+ }
3191
+ const denied2 = await authorize(request, context, "read");
3192
+ if (denied2 !== null) return denied2;
3193
+ const response = await readDistTags(context, distTagRoute.packageName);
3194
+ return request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response;
3195
+ }
3196
+ if (request.method !== "PUT" && request.method !== "DELETE") {
3197
+ return methodNotAllowed(["PUT", "DELETE"]);
3198
+ }
3199
+ const denied = await authorize(request, context, "publish");
3200
+ if (denied !== null) return denied;
3201
+ return request.method === "PUT" ? setDistTag(request, context, distTagRoute.packageName, distTagRoute.tag) : deleteDistTag(context, distTagRoute.packageName, distTagRoute.tag);
3202
+ }
3203
+ const route = parsePackageRoute(url.pathname);
3204
+ if (route === null) return npmError(404, "not_found", "endpoint not found");
3205
+ if (route.remainder.length === 2 && route.remainder[0] === "-") {
3206
+ if (request.method !== "GET" && request.method !== "HEAD") {
3207
+ return methodNotAllowed(["GET", "HEAD"]);
3208
+ }
3209
+ const denied = await authorize(request, context, "read");
3210
+ if (denied !== null) return denied;
3211
+ return readTarball(request, context, route.packageName, route.remainder[1] ?? "");
3212
+ }
3213
+ if (route.remainder.length > 1) return npmError(404, "not_found", "endpoint not found");
3214
+ if (request.method === "PUT" && route.remainder.length === 0) {
3215
+ const denied = await authorize(request, context, "publish");
3216
+ if (denied !== null) return denied;
3217
+ return publishPackage(request, context, route.packageName);
3218
+ }
3219
+ if ((request.method === "GET" || request.method === "HEAD") && route.remainder.length <= 1) {
3220
+ const denied = await authorize(request, context, "read");
3221
+ if (denied !== null) return denied;
3222
+ const response = await readPackage(request, context, route.packageName, route.remainder[0]);
3223
+ return request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response;
3224
+ }
3225
+ return methodNotAllowed(["GET", "HEAD", "PUT"]);
3226
+ }
3227
+ var worker_default = {
3228
+ async fetch(request, env) {
3229
+ const requestId = crypto.randomUUID();
3230
+ try {
3231
+ const response = await handle(request, env, requestId);
3232
+ response.headers.set("x-pkgflare-request-id", requestId);
3233
+ return response;
3234
+ } catch (error) {
3235
+ logRegistryError(requestId, "request", error);
3236
+ const response = npmError(500, "internal_error", "unexpected registry error");
3237
+ response.headers.set("x-pkgflare-request-id", requestId);
3238
+ return response;
3239
+ }
3240
+ }
3241
+ };
3242
+ export {
3243
+ worker_default as default
3244
+ };
3245
+ //# sourceMappingURL=worker.js.map