index.cjs 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  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 __export = (target, all) => {
  11. for (var name in all)
  12. __defProp(target, name, { get: all[name], enumerable: true });
  13. };
  14. var __copyProps = (to, from, except, desc) => {
  15. if (from && typeof from === "object" || typeof from === "function") {
  16. for (let key of __getOwnPropNames(from))
  17. if (!__hasOwnProp.call(to, key) && key !== except)
  18. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  19. }
  20. return to;
  21. };
  22. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  23. // If the importer is in node compatibility mode or this is not an ESM
  24. // file that has been converted to a CommonJS file using a Babel-
  25. // compatible transform (i.e. "__esModule" has not been set), then set
  26. // "default" to the CommonJS "module.exports" for node compatibility.
  27. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  28. mod
  29. ));
  30. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  31. // node_modules/path-to-regexp/dist/index.js
  32. var require_dist = __commonJS({
  33. "node_modules/path-to-regexp/dist/index.js"(exports2) {
  34. "use strict";
  35. Object.defineProperty(exports2, "__esModule", { value: true });
  36. exports2.TokenData = void 0;
  37. exports2.parse = parse;
  38. exports2.compile = compile;
  39. exports2.match = match;
  40. exports2.pathToRegexp = pathToRegexp2;
  41. exports2.stringify = stringify;
  42. var DEFAULT_DELIMITER = "/";
  43. var NOOP_VALUE = (value) => value;
  44. var ID_START = /^[$_\p{ID_Start}]$/u;
  45. var ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
  46. var DEBUG_URL = "https://git.new/pathToRegexpError";
  47. var SIMPLE_TOKENS = {
  48. // Groups.
  49. "{": "{",
  50. "}": "}",
  51. // Reserved.
  52. "(": "(",
  53. ")": ")",
  54. "[": "[",
  55. "]": "]",
  56. "+": "+",
  57. "?": "?",
  58. "!": "!"
  59. };
  60. function escapeText(str) {
  61. return str.replace(/[{}()\[\]+?!:*]/g, "\\$&");
  62. }
  63. function escape(str) {
  64. return str.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
  65. }
  66. function* lexer(str) {
  67. const chars = [...str];
  68. let i = 0;
  69. function name() {
  70. let value = "";
  71. if (ID_START.test(chars[++i])) {
  72. value += chars[i];
  73. while (ID_CONTINUE.test(chars[++i])) {
  74. value += chars[i];
  75. }
  76. } else if (chars[i] === '"') {
  77. let pos = i;
  78. while (i < chars.length) {
  79. if (chars[++i] === '"') {
  80. i++;
  81. pos = 0;
  82. break;
  83. }
  84. if (chars[i] === "\\") {
  85. value += chars[++i];
  86. } else {
  87. value += chars[i];
  88. }
  89. }
  90. if (pos) {
  91. throw new TypeError(`Unterminated quote at ${pos}: ${DEBUG_URL}`);
  92. }
  93. }
  94. if (!value) {
  95. throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
  96. }
  97. return value;
  98. }
  99. while (i < chars.length) {
  100. const value = chars[i];
  101. const type = SIMPLE_TOKENS[value];
  102. if (type) {
  103. yield { type, index: i++, value };
  104. } else if (value === "\\") {
  105. yield { type: "ESCAPED", index: i++, value: chars[i++] };
  106. } else if (value === ":") {
  107. const value2 = name();
  108. yield { type: "PARAM", index: i, value: value2 };
  109. } else if (value === "*") {
  110. const value2 = name();
  111. yield { type: "WILDCARD", index: i, value: value2 };
  112. } else {
  113. yield { type: "CHAR", index: i, value: chars[i++] };
  114. }
  115. }
  116. return { type: "END", index: i, value: "" };
  117. }
  118. var Iter = class {
  119. constructor(tokens) {
  120. this.tokens = tokens;
  121. }
  122. peek() {
  123. if (!this._peek) {
  124. const next = this.tokens.next();
  125. this._peek = next.value;
  126. }
  127. return this._peek;
  128. }
  129. tryConsume(type) {
  130. const token = this.peek();
  131. if (token.type !== type)
  132. return;
  133. this._peek = void 0;
  134. return token.value;
  135. }
  136. consume(type) {
  137. const value = this.tryConsume(type);
  138. if (value !== void 0)
  139. return value;
  140. const { type: nextType, index } = this.peek();
  141. throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`);
  142. }
  143. text() {
  144. let result = "";
  145. let value;
  146. while (value = this.tryConsume("CHAR") || this.tryConsume("ESCAPED")) {
  147. result += value;
  148. }
  149. return result;
  150. }
  151. };
  152. var TokenData = class {
  153. constructor(tokens) {
  154. this.tokens = tokens;
  155. }
  156. };
  157. exports2.TokenData = TokenData;
  158. function parse(str, options = {}) {
  159. const { encodePath = NOOP_VALUE } = options;
  160. const it = new Iter(lexer(str));
  161. function consume(endType) {
  162. const tokens2 = [];
  163. while (true) {
  164. const path = it.text();
  165. if (path)
  166. tokens2.push({ type: "text", value: encodePath(path) });
  167. const param = it.tryConsume("PARAM");
  168. if (param) {
  169. tokens2.push({
  170. type: "param",
  171. name: param
  172. });
  173. continue;
  174. }
  175. const wildcard = it.tryConsume("WILDCARD");
  176. if (wildcard) {
  177. tokens2.push({
  178. type: "wildcard",
  179. name: wildcard
  180. });
  181. continue;
  182. }
  183. const open = it.tryConsume("{");
  184. if (open) {
  185. tokens2.push({
  186. type: "group",
  187. tokens: consume("}")
  188. });
  189. continue;
  190. }
  191. it.consume(endType);
  192. return tokens2;
  193. }
  194. }
  195. const tokens = consume("END");
  196. return new TokenData(tokens);
  197. }
  198. function compile(path, options = {}) {
  199. const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
  200. const data = path instanceof TokenData ? path : parse(path, options);
  201. const fn = tokensToFunction(data.tokens, delimiter, encode);
  202. return function path2(data2 = {}) {
  203. const [path3, ...missing] = fn(data2);
  204. if (missing.length) {
  205. throw new TypeError(`Missing parameters: ${missing.join(", ")}`);
  206. }
  207. return path3;
  208. };
  209. }
  210. function tokensToFunction(tokens, delimiter, encode) {
  211. const encoders = tokens.map((token) => tokenToFunction(token, delimiter, encode));
  212. return (data) => {
  213. const result = [""];
  214. for (const encoder of encoders) {
  215. const [value, ...extras] = encoder(data);
  216. result[0] += value;
  217. result.push(...extras);
  218. }
  219. return result;
  220. };
  221. }
  222. function tokenToFunction(token, delimiter, encode) {
  223. if (token.type === "text")
  224. return () => [token.value];
  225. if (token.type === "group") {
  226. const fn = tokensToFunction(token.tokens, delimiter, encode);
  227. return (data) => {
  228. const [value, ...missing] = fn(data);
  229. if (!missing.length)
  230. return [value];
  231. return [""];
  232. };
  233. }
  234. const encodeValue = encode || NOOP_VALUE;
  235. if (token.type === "wildcard" && encode !== false) {
  236. return (data) => {
  237. const value = data[token.name];
  238. if (value == null)
  239. return ["", token.name];
  240. if (!Array.isArray(value) || value.length === 0) {
  241. throw new TypeError(`Expected "${token.name}" to be a non-empty array`);
  242. }
  243. return [
  244. value.map((value2, index) => {
  245. if (typeof value2 !== "string") {
  246. throw new TypeError(`Expected "${token.name}/${index}" to be a string`);
  247. }
  248. return encodeValue(value2);
  249. }).join(delimiter)
  250. ];
  251. };
  252. }
  253. return (data) => {
  254. const value = data[token.name];
  255. if (value == null)
  256. return ["", token.name];
  257. if (typeof value !== "string") {
  258. throw new TypeError(`Expected "${token.name}" to be a string`);
  259. }
  260. return [encodeValue(value)];
  261. };
  262. }
  263. function match(path, options = {}) {
  264. const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
  265. const { regexp, keys } = pathToRegexp2(path, options);
  266. const decoders = keys.map((key) => {
  267. if (decode === false)
  268. return NOOP_VALUE;
  269. if (key.type === "param")
  270. return decode;
  271. return (value) => value.split(delimiter).map(decode);
  272. });
  273. return function match2(input) {
  274. const m = regexp.exec(input);
  275. if (!m)
  276. return false;
  277. const path2 = m[0];
  278. const params = /* @__PURE__ */ Object.create(null);
  279. for (let i = 1; i < m.length; i++) {
  280. if (m[i] === void 0)
  281. continue;
  282. const key = keys[i - 1];
  283. const decoder = decoders[i - 1];
  284. params[key.name] = decoder(m[i]);
  285. }
  286. return { path: path2, params };
  287. };
  288. }
  289. function pathToRegexp2(path, options = {}) {
  290. const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options;
  291. const keys = [];
  292. const sources = [];
  293. const flags = sensitive ? "" : "i";
  294. const paths = Array.isArray(path) ? path : [path];
  295. const items = paths.map((path2) => path2 instanceof TokenData ? path2 : parse(path2, options));
  296. for (const { tokens } of items) {
  297. for (const seq of flatten(tokens, 0, [])) {
  298. const regexp2 = sequenceToRegExp(seq, delimiter, keys);
  299. sources.push(regexp2);
  300. }
  301. }
  302. let pattern = `^(?:${sources.join("|")})`;
  303. if (trailing)
  304. pattern += `(?:${escape(delimiter)}$)?`;
  305. pattern += end ? "$" : `(?=${escape(delimiter)}|$)`;
  306. const regexp = new RegExp(pattern, flags);
  307. return { regexp, keys };
  308. }
  309. function* flatten(tokens, index, init) {
  310. if (index === tokens.length) {
  311. return yield init;
  312. }
  313. const token = tokens[index];
  314. if (token.type === "group") {
  315. const fork = init.slice();
  316. for (const seq of flatten(token.tokens, 0, fork)) {
  317. yield* flatten(tokens, index + 1, seq);
  318. }
  319. } else {
  320. init.push(token);
  321. }
  322. yield* flatten(tokens, index + 1, init);
  323. }
  324. function sequenceToRegExp(tokens, delimiter, keys) {
  325. let result = "";
  326. let backtrack = "";
  327. let isSafeSegmentParam = true;
  328. for (let i = 0; i < tokens.length; i++) {
  329. const token = tokens[i];
  330. if (token.type === "text") {
  331. result += escape(token.value);
  332. backtrack += token.value;
  333. isSafeSegmentParam || (isSafeSegmentParam = token.value.includes(delimiter));
  334. continue;
  335. }
  336. if (token.type === "param" || token.type === "wildcard") {
  337. if (!isSafeSegmentParam && !backtrack) {
  338. throw new TypeError(`Missing text after "${token.name}": ${DEBUG_URL}`);
  339. }
  340. if (token.type === "param") {
  341. result += `(${negate(delimiter, isSafeSegmentParam ? "" : backtrack)}+)`;
  342. } else {
  343. result += `([\\s\\S]+)`;
  344. }
  345. keys.push(token);
  346. backtrack = "";
  347. isSafeSegmentParam = false;
  348. continue;
  349. }
  350. }
  351. return result;
  352. }
  353. function negate(delimiter, backtrack) {
  354. if (backtrack.length < 2) {
  355. if (delimiter.length < 2)
  356. return `[^${escape(delimiter + backtrack)}]`;
  357. return `(?:(?!${escape(delimiter)})[^${escape(backtrack)}])`;
  358. }
  359. if (delimiter.length < 2) {
  360. return `(?:(?!${escape(backtrack)})[^${escape(delimiter)}])`;
  361. }
  362. return `(?:(?!${escape(backtrack)}|${escape(delimiter)})[\\s\\S])`;
  363. }
  364. function stringify(data) {
  365. return data.tokens.map(function stringifyToken(token, index, tokens) {
  366. if (token.type === "text")
  367. return escapeText(token.value);
  368. if (token.type === "group") {
  369. return `{${token.tokens.map(stringifyToken).join("")}}`;
  370. }
  371. const isSafe = isNameSafe(token.name) && isNextNameSafe(tokens[index + 1]);
  372. const key = isSafe ? token.name : JSON.stringify(token.name);
  373. if (token.type === "param")
  374. return `:${key}`;
  375. if (token.type === "wildcard")
  376. return `*${key}`;
  377. throw new TypeError(`Unexpected token: ${token}`);
  378. }).join("");
  379. }
  380. function isNameSafe(name) {
  381. const [first, ...rest] = name;
  382. if (!ID_START.test(first))
  383. return false;
  384. return rest.every((char) => ID_CONTINUE.test(char));
  385. }
  386. function isNextNameSafe(token) {
  387. if ((token === null || token === void 0 ? void 0 : token.type) !== "text")
  388. return true;
  389. return !ID_CONTINUE.test(token.value[0]);
  390. }
  391. }
  392. });
  393. // node_modules/ms/index.js
  394. var require_ms = __commonJS({
  395. "node_modules/ms/index.js"(exports2, module2) {
  396. var s = 1e3;
  397. var m = s * 60;
  398. var h = m * 60;
  399. var d = h * 24;
  400. var w = d * 7;
  401. var y = d * 365.25;
  402. module2.exports = function(val, options) {
  403. options = options || {};
  404. var type = typeof val;
  405. if (type === "string" && val.length > 0) {
  406. return parse(val);
  407. } else if (type === "number" && isFinite(val)) {
  408. return options.long ? fmtLong(val) : fmtShort(val);
  409. }
  410. throw new Error(
  411. "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
  412. );
  413. };
  414. function parse(str) {
  415. str = String(str);
  416. if (str.length > 100) {
  417. return;
  418. }
  419. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  420. str
  421. );
  422. if (!match) {
  423. return;
  424. }
  425. var n = parseFloat(match[1]);
  426. var type = (match[2] || "ms").toLowerCase();
  427. switch (type) {
  428. case "years":
  429. case "year":
  430. case "yrs":
  431. case "yr":
  432. case "y":
  433. return n * y;
  434. case "weeks":
  435. case "week":
  436. case "w":
  437. return n * w;
  438. case "days":
  439. case "day":
  440. case "d":
  441. return n * d;
  442. case "hours":
  443. case "hour":
  444. case "hrs":
  445. case "hr":
  446. case "h":
  447. return n * h;
  448. case "minutes":
  449. case "minute":
  450. case "mins":
  451. case "min":
  452. case "m":
  453. return n * m;
  454. case "seconds":
  455. case "second":
  456. case "secs":
  457. case "sec":
  458. case "s":
  459. return n * s;
  460. case "milliseconds":
  461. case "millisecond":
  462. case "msecs":
  463. case "msec":
  464. case "ms":
  465. return n;
  466. default:
  467. return void 0;
  468. }
  469. }
  470. function fmtShort(ms) {
  471. var msAbs = Math.abs(ms);
  472. if (msAbs >= d) {
  473. return Math.round(ms / d) + "d";
  474. }
  475. if (msAbs >= h) {
  476. return Math.round(ms / h) + "h";
  477. }
  478. if (msAbs >= m) {
  479. return Math.round(ms / m) + "m";
  480. }
  481. if (msAbs >= s) {
  482. return Math.round(ms / s) + "s";
  483. }
  484. return ms + "ms";
  485. }
  486. function fmtLong(ms) {
  487. var msAbs = Math.abs(ms);
  488. if (msAbs >= d) {
  489. return plural(ms, msAbs, d, "day");
  490. }
  491. if (msAbs >= h) {
  492. return plural(ms, msAbs, h, "hour");
  493. }
  494. if (msAbs >= m) {
  495. return plural(ms, msAbs, m, "minute");
  496. }
  497. if (msAbs >= s) {
  498. return plural(ms, msAbs, s, "second");
  499. }
  500. return ms + " ms";
  501. }
  502. function plural(ms, msAbs, n, name) {
  503. var isPlural = msAbs >= n * 1.5;
  504. return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
  505. }
  506. }
  507. });
  508. // node_modules/debug/src/common.js
  509. var require_common = __commonJS({
  510. "node_modules/debug/src/common.js"(exports2, module2) {
  511. function setup(env) {
  512. createDebug.debug = createDebug;
  513. createDebug.default = createDebug;
  514. createDebug.coerce = coerce;
  515. createDebug.disable = disable;
  516. createDebug.enable = enable;
  517. createDebug.enabled = enabled;
  518. createDebug.humanize = require_ms();
  519. createDebug.destroy = destroy;
  520. Object.keys(env).forEach((key) => {
  521. createDebug[key] = env[key];
  522. });
  523. createDebug.names = [];
  524. createDebug.skips = [];
  525. createDebug.formatters = {};
  526. function selectColor(namespace) {
  527. let hash = 0;
  528. for (let i = 0; i < namespace.length; i++) {
  529. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  530. hash |= 0;
  531. }
  532. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  533. }
  534. createDebug.selectColor = selectColor;
  535. function createDebug(namespace) {
  536. let prevTime;
  537. let enableOverride = null;
  538. let namespacesCache;
  539. let enabledCache;
  540. function debug2(...args) {
  541. if (!debug2.enabled) {
  542. return;
  543. }
  544. const self = debug2;
  545. const curr = Number(/* @__PURE__ */ new Date());
  546. const ms = curr - (prevTime || curr);
  547. self.diff = ms;
  548. self.prev = prevTime;
  549. self.curr = curr;
  550. prevTime = curr;
  551. args[0] = createDebug.coerce(args[0]);
  552. if (typeof args[0] !== "string") {
  553. args.unshift("%O");
  554. }
  555. let index = 0;
  556. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format2) => {
  557. if (match === "%%") {
  558. return "%";
  559. }
  560. index++;
  561. const formatter = createDebug.formatters[format2];
  562. if (typeof formatter === "function") {
  563. const val = args[index];
  564. match = formatter.call(self, val);
  565. args.splice(index, 1);
  566. index--;
  567. }
  568. return match;
  569. });
  570. createDebug.formatArgs.call(self, args);
  571. const logFn = self.log || createDebug.log;
  572. logFn.apply(self, args);
  573. }
  574. debug2.namespace = namespace;
  575. debug2.useColors = createDebug.useColors();
  576. debug2.color = createDebug.selectColor(namespace);
  577. debug2.extend = extend;
  578. debug2.destroy = createDebug.destroy;
  579. Object.defineProperty(debug2, "enabled", {
  580. enumerable: true,
  581. configurable: false,
  582. get: () => {
  583. if (enableOverride !== null) {
  584. return enableOverride;
  585. }
  586. if (namespacesCache !== createDebug.namespaces) {
  587. namespacesCache = createDebug.namespaces;
  588. enabledCache = createDebug.enabled(namespace);
  589. }
  590. return enabledCache;
  591. },
  592. set: (v) => {
  593. enableOverride = v;
  594. }
  595. });
  596. if (typeof createDebug.init === "function") {
  597. createDebug.init(debug2);
  598. }
  599. return debug2;
  600. }
  601. function extend(namespace, delimiter) {
  602. const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
  603. newDebug.log = this.log;
  604. return newDebug;
  605. }
  606. function enable(namespaces) {
  607. createDebug.save(namespaces);
  608. createDebug.namespaces = namespaces;
  609. createDebug.names = [];
  610. createDebug.skips = [];
  611. let i;
  612. const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
  613. const len = split.length;
  614. for (i = 0; i < len; i++) {
  615. if (!split[i]) {
  616. continue;
  617. }
  618. namespaces = split[i].replace(/\*/g, ".*?");
  619. if (namespaces[0] === "-") {
  620. createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
  621. } else {
  622. createDebug.names.push(new RegExp("^" + namespaces + "$"));
  623. }
  624. }
  625. }
  626. function disable() {
  627. const namespaces = [
  628. ...createDebug.names.map(toNamespace),
  629. ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
  630. ].join(",");
  631. createDebug.enable("");
  632. return namespaces;
  633. }
  634. function enabled(name) {
  635. if (name[name.length - 1] === "*") {
  636. return true;
  637. }
  638. let i;
  639. let len;
  640. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  641. if (createDebug.skips[i].test(name)) {
  642. return false;
  643. }
  644. }
  645. for (i = 0, len = createDebug.names.length; i < len; i++) {
  646. if (createDebug.names[i].test(name)) {
  647. return true;
  648. }
  649. }
  650. return false;
  651. }
  652. function toNamespace(regexp) {
  653. return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
  654. }
  655. function coerce(val) {
  656. if (val instanceof Error) {
  657. return val.stack || val.message;
  658. }
  659. return val;
  660. }
  661. function destroy() {
  662. console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
  663. }
  664. createDebug.enable(createDebug.load());
  665. return createDebug;
  666. }
  667. module2.exports = setup;
  668. }
  669. });
  670. // node_modules/debug/src/browser.js
  671. var require_browser = __commonJS({
  672. "node_modules/debug/src/browser.js"(exports2, module2) {
  673. exports2.formatArgs = formatArgs;
  674. exports2.save = save;
  675. exports2.load = load;
  676. exports2.useColors = useColors;
  677. exports2.storage = localstorage();
  678. exports2.destroy = /* @__PURE__ */ (() => {
  679. let warned = false;
  680. return () => {
  681. if (!warned) {
  682. warned = true;
  683. console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
  684. }
  685. };
  686. })();
  687. exports2.colors = [
  688. "#0000CC",
  689. "#0000FF",
  690. "#0033CC",
  691. "#0033FF",
  692. "#0066CC",
  693. "#0066FF",
  694. "#0099CC",
  695. "#0099FF",
  696. "#00CC00",
  697. "#00CC33",
  698. "#00CC66",
  699. "#00CC99",
  700. "#00CCCC",
  701. "#00CCFF",
  702. "#3300CC",
  703. "#3300FF",
  704. "#3333CC",
  705. "#3333FF",
  706. "#3366CC",
  707. "#3366FF",
  708. "#3399CC",
  709. "#3399FF",
  710. "#33CC00",
  711. "#33CC33",
  712. "#33CC66",
  713. "#33CC99",
  714. "#33CCCC",
  715. "#33CCFF",
  716. "#6600CC",
  717. "#6600FF",
  718. "#6633CC",
  719. "#6633FF",
  720. "#66CC00",
  721. "#66CC33",
  722. "#9900CC",
  723. "#9900FF",
  724. "#9933CC",
  725. "#9933FF",
  726. "#99CC00",
  727. "#99CC33",
  728. "#CC0000",
  729. "#CC0033",
  730. "#CC0066",
  731. "#CC0099",
  732. "#CC00CC",
  733. "#CC00FF",
  734. "#CC3300",
  735. "#CC3333",
  736. "#CC3366",
  737. "#CC3399",
  738. "#CC33CC",
  739. "#CC33FF",
  740. "#CC6600",
  741. "#CC6633",
  742. "#CC9900",
  743. "#CC9933",
  744. "#CCCC00",
  745. "#CCCC33",
  746. "#FF0000",
  747. "#FF0033",
  748. "#FF0066",
  749. "#FF0099",
  750. "#FF00CC",
  751. "#FF00FF",
  752. "#FF3300",
  753. "#FF3333",
  754. "#FF3366",
  755. "#FF3399",
  756. "#FF33CC",
  757. "#FF33FF",
  758. "#FF6600",
  759. "#FF6633",
  760. "#FF9900",
  761. "#FF9933",
  762. "#FFCC00",
  763. "#FFCC33"
  764. ];
  765. function useColors() {
  766. if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
  767. return true;
  768. }
  769. if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  770. return false;
  771. }
  772. let m;
  773. return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
  774. typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
  775. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  776. typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
  777. typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  778. }
  779. function formatArgs(args) {
  780. args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
  781. if (!this.useColors) {
  782. return;
  783. }
  784. const c = "color: " + this.color;
  785. args.splice(1, 0, c, "color: inherit");
  786. let index = 0;
  787. let lastC = 0;
  788. args[0].replace(/%[a-zA-Z%]/g, (match) => {
  789. if (match === "%%") {
  790. return;
  791. }
  792. index++;
  793. if (match === "%c") {
  794. lastC = index;
  795. }
  796. });
  797. args.splice(lastC, 0, c);
  798. }
  799. exports2.log = console.debug || console.log || (() => {
  800. });
  801. function save(namespaces) {
  802. try {
  803. if (namespaces) {
  804. exports2.storage.setItem("debug", namespaces);
  805. } else {
  806. exports2.storage.removeItem("debug");
  807. }
  808. } catch (error) {
  809. }
  810. }
  811. function load() {
  812. let r;
  813. try {
  814. r = exports2.storage.getItem("debug");
  815. } catch (error) {
  816. }
  817. if (!r && typeof process !== "undefined" && "env" in process) {
  818. r = process.env.DEBUG;
  819. }
  820. return r;
  821. }
  822. function localstorage() {
  823. try {
  824. return localStorage;
  825. } catch (error) {
  826. }
  827. }
  828. module2.exports = require_common()(exports2);
  829. var { formatters } = module2.exports;
  830. formatters.j = function(v) {
  831. try {
  832. return JSON.stringify(v);
  833. } catch (error) {
  834. return "[UnexpectedJSONParseError]: " + error.message;
  835. }
  836. };
  837. }
  838. });
  839. // node_modules/has-flag/index.js
  840. var require_has_flag = __commonJS({
  841. "node_modules/has-flag/index.js"(exports2, module2) {
  842. "use strict";
  843. module2.exports = (flag, argv = process.argv) => {
  844. const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
  845. const position = argv.indexOf(prefix + flag);
  846. const terminatorPosition = argv.indexOf("--");
  847. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  848. };
  849. }
  850. });
  851. // node_modules/supports-color/index.js
  852. var require_supports_color = __commonJS({
  853. "node_modules/supports-color/index.js"(exports2, module2) {
  854. "use strict";
  855. var os = require("os");
  856. var tty = require("tty");
  857. var hasFlag = require_has_flag();
  858. var { env } = process;
  859. var forceColor;
  860. if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
  861. forceColor = 0;
  862. } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
  863. forceColor = 1;
  864. }
  865. if ("FORCE_COLOR" in env) {
  866. if (env.FORCE_COLOR === "true") {
  867. forceColor = 1;
  868. } else if (env.FORCE_COLOR === "false") {
  869. forceColor = 0;
  870. } else {
  871. forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
  872. }
  873. }
  874. function translateLevel(level) {
  875. if (level === 0) {
  876. return false;
  877. }
  878. return {
  879. level,
  880. hasBasic: true,
  881. has256: level >= 2,
  882. has16m: level >= 3
  883. };
  884. }
  885. function supportsColor(haveStream, streamIsTTY) {
  886. if (forceColor === 0) {
  887. return 0;
  888. }
  889. if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
  890. return 3;
  891. }
  892. if (hasFlag("color=256")) {
  893. return 2;
  894. }
  895. if (haveStream && !streamIsTTY && forceColor === void 0) {
  896. return 0;
  897. }
  898. const min = forceColor || 0;
  899. if (env.TERM === "dumb") {
  900. return min;
  901. }
  902. if (process.platform === "win32") {
  903. const osRelease = os.release().split(".");
  904. if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  905. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  906. }
  907. return 1;
  908. }
  909. if ("CI" in env) {
  910. if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
  911. return 1;
  912. }
  913. return min;
  914. }
  915. if ("TEAMCITY_VERSION" in env) {
  916. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  917. }
  918. if (env.COLORTERM === "truecolor") {
  919. return 3;
  920. }
  921. if ("TERM_PROGRAM" in env) {
  922. const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
  923. switch (env.TERM_PROGRAM) {
  924. case "iTerm.app":
  925. return version >= 3 ? 3 : 2;
  926. case "Apple_Terminal":
  927. return 2;
  928. }
  929. }
  930. if (/-256(color)?$/i.test(env.TERM)) {
  931. return 2;
  932. }
  933. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  934. return 1;
  935. }
  936. if ("COLORTERM" in env) {
  937. return 1;
  938. }
  939. return min;
  940. }
  941. function getSupportLevel(stream) {
  942. const level = supportsColor(stream, stream && stream.isTTY);
  943. return translateLevel(level);
  944. }
  945. module2.exports = {
  946. supportsColor: getSupportLevel,
  947. stdout: translateLevel(supportsColor(true, tty.isatty(1))),
  948. stderr: translateLevel(supportsColor(true, tty.isatty(2)))
  949. };
  950. }
  951. });
  952. // node_modules/debug/src/node.js
  953. var require_node = __commonJS({
  954. "node_modules/debug/src/node.js"(exports2, module2) {
  955. var tty = require("tty");
  956. var util = require("util");
  957. exports2.init = init;
  958. exports2.log = log;
  959. exports2.formatArgs = formatArgs;
  960. exports2.save = save;
  961. exports2.load = load;
  962. exports2.useColors = useColors;
  963. exports2.destroy = util.deprecate(
  964. () => {
  965. },
  966. "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
  967. );
  968. exports2.colors = [6, 2, 3, 4, 5, 1];
  969. try {
  970. const supportsColor = require_supports_color();
  971. if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
  972. exports2.colors = [
  973. 20,
  974. 21,
  975. 26,
  976. 27,
  977. 32,
  978. 33,
  979. 38,
  980. 39,
  981. 40,
  982. 41,
  983. 42,
  984. 43,
  985. 44,
  986. 45,
  987. 56,
  988. 57,
  989. 62,
  990. 63,
  991. 68,
  992. 69,
  993. 74,
  994. 75,
  995. 76,
  996. 77,
  997. 78,
  998. 79,
  999. 80,
  1000. 81,
  1001. 92,
  1002. 93,
  1003. 98,
  1004. 99,
  1005. 112,
  1006. 113,
  1007. 128,
  1008. 129,
  1009. 134,
  1010. 135,
  1011. 148,
  1012. 149,
  1013. 160,
  1014. 161,
  1015. 162,
  1016. 163,
  1017. 164,
  1018. 165,
  1019. 166,
  1020. 167,
  1021. 168,
  1022. 169,
  1023. 170,
  1024. 171,
  1025. 172,
  1026. 173,
  1027. 178,
  1028. 179,
  1029. 184,
  1030. 185,
  1031. 196,
  1032. 197,
  1033. 198,
  1034. 199,
  1035. 200,
  1036. 201,
  1037. 202,
  1038. 203,
  1039. 204,
  1040. 205,
  1041. 206,
  1042. 207,
  1043. 208,
  1044. 209,
  1045. 214,
  1046. 215,
  1047. 220,
  1048. 221
  1049. ];
  1050. }
  1051. } catch (error) {
  1052. }
  1053. exports2.inspectOpts = Object.keys(process.env).filter((key) => {
  1054. return /^debug_/i.test(key);
  1055. }).reduce((obj, key) => {
  1056. const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
  1057. return k.toUpperCase();
  1058. });
  1059. let val = process.env[key];
  1060. if (/^(yes|on|true|enabled)$/i.test(val)) {
  1061. val = true;
  1062. } else if (/^(no|off|false|disabled)$/i.test(val)) {
  1063. val = false;
  1064. } else if (val === "null") {
  1065. val = null;
  1066. } else {
  1067. val = Number(val);
  1068. }
  1069. obj[prop] = val;
  1070. return obj;
  1071. }, {});
  1072. function useColors() {
  1073. return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
  1074. }
  1075. function formatArgs(args) {
  1076. const { namespace: name, useColors: useColors2 } = this;
  1077. if (useColors2) {
  1078. const c = this.color;
  1079. const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
  1080. const prefix = ` ${colorCode};1m${name} \x1B[0m`;
  1081. args[0] = prefix + args[0].split("\n").join("\n" + prefix);
  1082. args.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
  1083. } else {
  1084. args[0] = getDate() + name + " " + args[0];
  1085. }
  1086. }
  1087. function getDate() {
  1088. if (exports2.inspectOpts.hideDate) {
  1089. return "";
  1090. }
  1091. return (/* @__PURE__ */ new Date()).toISOString() + " ";
  1092. }
  1093. function log(...args) {
  1094. return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + "\n");
  1095. }
  1096. function save(namespaces) {
  1097. if (namespaces) {
  1098. process.env.DEBUG = namespaces;
  1099. } else {
  1100. delete process.env.DEBUG;
  1101. }
  1102. }
  1103. function load() {
  1104. return process.env.DEBUG;
  1105. }
  1106. function init(debug2) {
  1107. debug2.inspectOpts = {};
  1108. const keys = Object.keys(exports2.inspectOpts);
  1109. for (let i = 0; i < keys.length; i++) {
  1110. debug2.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
  1111. }
  1112. }
  1113. module2.exports = require_common()(exports2);
  1114. var { formatters } = module2.exports;
  1115. formatters.o = function(v) {
  1116. this.inspectOpts.colors = this.useColors;
  1117. return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
  1118. };
  1119. formatters.O = function(v) {
  1120. this.inspectOpts.colors = this.useColors;
  1121. return util.inspect(v, this.inspectOpts);
  1122. };
  1123. }
  1124. });
  1125. // node_modules/debug/src/index.js
  1126. var require_src = __commonJS({
  1127. "node_modules/debug/src/index.js"(exports2, module2) {
  1128. if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
  1129. module2.exports = require_browser();
  1130. } else {
  1131. module2.exports = require_node();
  1132. }
  1133. }
  1134. });
  1135. // src/index.js
  1136. var src_exports = {};
  1137. __export(src_exports, {
  1138. PathTrie: () => PathTrie
  1139. });
  1140. module.exports = __toCommonJS(src_exports);
  1141. // node_modules/@e22m4u/js-format/src/utils/is-class.js
  1142. function isClass(value) {
  1143. if (!value) return false;
  1144. return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
  1145. }
  1146. // node_modules/@e22m4u/js-format/src/value-to-string.js
  1147. var BASE_CTOR_NAMES = [
  1148. "String",
  1149. "Number",
  1150. "Boolean",
  1151. "Object",
  1152. "Array",
  1153. "Function",
  1154. "Symbol",
  1155. "Map",
  1156. "Set",
  1157. "Date"
  1158. ];
  1159. function valueToString(input) {
  1160. if (input == null) return String(input);
  1161. if (typeof input === "string") return `"${input}"`;
  1162. if (typeof input === "number" || typeof input === "boolean")
  1163. return String(input);
  1164. if (isClass(input)) return input.name ? input.name : "Class";
  1165. if (input.constructor && input.constructor.name)
  1166. return BASE_CTOR_NAMES.includes(input.constructor.name) ? input.constructor.name : `${input.constructor.name} (instance)`;
  1167. if (typeof input === "object" && input.constructor == null) return "Object";
  1168. return String(input);
  1169. }
  1170. // node_modules/@e22m4u/js-format/src/array-to-list.js
  1171. var SEPARATOR = ", ";
  1172. function arrayToList(input) {
  1173. if (Array.isArray(input) && input.length)
  1174. return input.map(valueToString).join(SEPARATOR);
  1175. return valueToString(input);
  1176. }
  1177. // node_modules/@e22m4u/js-format/src/format.js
  1178. function format(pattern) {
  1179. if (pattern instanceof Date) {
  1180. pattern = pattern.toISOString();
  1181. } else if (typeof pattern !== "string") {
  1182. pattern = String(pattern);
  1183. }
  1184. const re = /(%?)(%([sdjvl]))/g;
  1185. const args = Array.prototype.slice.call(arguments, 1);
  1186. if (args.length) {
  1187. pattern = pattern.replace(re, function(match, escaped, ptn, flag) {
  1188. let arg = args.shift();
  1189. switch (flag) {
  1190. case "s":
  1191. arg = String(arg);
  1192. break;
  1193. case "d":
  1194. arg = Number(arg);
  1195. break;
  1196. case "j":
  1197. arg = JSON.stringify(arg);
  1198. break;
  1199. case "v":
  1200. arg = valueToString(arg);
  1201. break;
  1202. case "l":
  1203. arg = arrayToList(arg);
  1204. break;
  1205. }
  1206. if (!escaped) return arg;
  1207. args.unshift(arg);
  1208. return match;
  1209. });
  1210. }
  1211. if (args.length) pattern += " " + args.join(" ");
  1212. pattern = pattern.replace(/%{2}/g, "%");
  1213. return "" + pattern;
  1214. }
  1215. // node_modules/@e22m4u/js-format/src/errorf.js
  1216. var Errorf = class extends Error {
  1217. /**
  1218. * Constructor.
  1219. *
  1220. * @param {string|undefined} pattern
  1221. * @param {any} args
  1222. */
  1223. constructor(pattern = void 0, ...args) {
  1224. const message = pattern != null ? format(pattern, ...args) : void 0;
  1225. super(message);
  1226. }
  1227. };
  1228. // src/path-trie.js
  1229. var import_path_to_regexp = __toESM(require_dist(), 1);
  1230. // src/utils/create-debugger.js
  1231. var import_debug = __toESM(require_src(), 1);
  1232. function createDebugger() {
  1233. const debug2 = (0, import_debug.default)(`jsPathTrie`);
  1234. return function(message, ...args) {
  1235. const interpolatedMessage = format(message, ...args);
  1236. return debug2(interpolatedMessage);
  1237. };
  1238. }
  1239. // src/path-trie.js
  1240. var debug = createDebugger();
  1241. var PathTrie = class {
  1242. /**
  1243. * Root node.
  1244. *
  1245. * @type {Node}
  1246. * @private
  1247. */
  1248. _root = {
  1249. token: "",
  1250. regexp: void 0,
  1251. names: [],
  1252. value: void 0,
  1253. children: {}
  1254. };
  1255. /**
  1256. * Add value.
  1257. *
  1258. * @param {string} pathTemplate
  1259. * @param {*} value
  1260. * @returns {this}
  1261. */
  1262. add(pathTemplate, value) {
  1263. if (typeof pathTemplate !== "string")
  1264. throw new Errorf(
  1265. "The first argument of PathTrie.add should be a String, but %v given.",
  1266. pathTemplate
  1267. );
  1268. if (value == null)
  1269. throw new Errorf(
  1270. "The second argument of PathTrie.add is required, but %v given.",
  1271. value
  1272. );
  1273. debug("Adding the value to %v.", pathTemplate);
  1274. const tokens = pathTemplate.split("/").filter(Boolean);
  1275. this._createNode(tokens, 0, value, this._root);
  1276. return this;
  1277. }
  1278. /**
  1279. * Match value.
  1280. *
  1281. * @param {string} path
  1282. * @returns {ResolvedValue|undefined}
  1283. */
  1284. match(path) {
  1285. if (typeof path !== "string")
  1286. throw new Errorf(
  1287. "The first argument of PathTrie.match should be a String, but %v given.",
  1288. path
  1289. );
  1290. debug("Matching a value with the path %v.", path);
  1291. const tokens = path.split("/").filter(Boolean);
  1292. const params = {};
  1293. const result = this._matchNode(tokens, 0, params, this._root);
  1294. if (!result || !result.node.value) return;
  1295. return { value: result.node.value, params };
  1296. }
  1297. /**
  1298. * Create node.
  1299. *
  1300. * @param {string[]} tokens
  1301. * @param {number} index
  1302. * @param {*} value
  1303. * @param {Node} parent
  1304. * @returns {Node}
  1305. * @private
  1306. */
  1307. _createNode(tokens, index, value, parent) {
  1308. if (tokens.length === 0 && index === 0) {
  1309. if (parent.value == null) {
  1310. parent.value = value;
  1311. } else if (parent.value !== value) {
  1312. throw new Errorf('The duplicate path "" has a different value.');
  1313. }
  1314. debug("The value has set to the root node.");
  1315. return parent;
  1316. }
  1317. const token = tokens[index];
  1318. if (token == null)
  1319. throw new Errorf(
  1320. "Invalid index %v has passed to the PathTrie._createNode.",
  1321. index
  1322. );
  1323. const isLast = tokens.length - 1 === index;
  1324. let child = parent.children[token];
  1325. if (isLast && child != null) {
  1326. debug("The node %v already exist.", token);
  1327. if (child.value == null) {
  1328. child.value = value;
  1329. } else if (child.value !== value) {
  1330. throw new Errorf(
  1331. "The duplicate path %v has a different value.",
  1332. "/" + tokens.join("/")
  1333. );
  1334. }
  1335. return child;
  1336. }
  1337. debug("The node %v does not exist.", token);
  1338. child = {
  1339. token,
  1340. regexp: void 0,
  1341. names: [],
  1342. value: void 0,
  1343. children: {}
  1344. };
  1345. if (isLast) {
  1346. debug("The node %v is last.", token);
  1347. child.value = value;
  1348. }
  1349. if (token.indexOf(":") > -1) {
  1350. debug("The node %v has parameters.", token);
  1351. const modifiers = /([?*+{}])/.exec(token);
  1352. if (modifiers)
  1353. throw new Errorf(
  1354. "The symbol %v is not supported in path %v.",
  1355. modifiers[0],
  1356. "/" + tokens.join("/")
  1357. );
  1358. let regexp, keys;
  1359. try {
  1360. const regexpAndKeys = (0, import_path_to_regexp.pathToRegexp)(token);
  1361. regexp = regexpAndKeys.regexp;
  1362. keys = regexpAndKeys.keys;
  1363. } catch (error) {
  1364. if (error.message.indexOf("Missing parameter") > -1)
  1365. throw new Errorf(
  1366. 'The symbol ":" should be used to define path parameters, but no parameters found in the path %v.',
  1367. "/" + tokens.join("/")
  1368. );
  1369. throw error;
  1370. }
  1371. if (Array.isArray(keys) && keys.length) {
  1372. child.names = keys.map((p) => `${p.name}`);
  1373. child.regexp = regexp;
  1374. } else {
  1375. throw new Errorf(
  1376. 'The symbol ":" should be used to define path parameters, but no parameters found in the path %v.',
  1377. "/" + tokens.join("/")
  1378. );
  1379. }
  1380. debug("Found parameters are %l.", child.names);
  1381. }
  1382. parent.children[token] = child;
  1383. debug("The node %v has created.", token);
  1384. if (isLast) return child;
  1385. return this._createNode(tokens, index + 1, value, child);
  1386. }
  1387. /**
  1388. * Match node.
  1389. *
  1390. * @param {string[]} tokens
  1391. * @param {number} index
  1392. * @param {object} params
  1393. * @param {Node} parent
  1394. * @returns {ResolvedNode|undefined}
  1395. * @private
  1396. */
  1397. _matchNode(tokens, index, params, parent) {
  1398. if (tokens.length === 0 && index === 0) {
  1399. if (parent.value) {
  1400. debug(
  1401. "The path %v matched with the root node.",
  1402. "/" + tokens.join("/")
  1403. );
  1404. return { node: parent, params };
  1405. }
  1406. return;
  1407. }
  1408. const token = tokens[index];
  1409. if (token == null)
  1410. throw new Errorf(
  1411. "Invalid index %v has passed to the PathTrie._matchNode.",
  1412. index
  1413. );
  1414. const resolvedNodes = this._matchChildrenNodes(token, parent);
  1415. debug("%v nodes matches the token %v.", resolvedNodes.length, token);
  1416. if (!resolvedNodes.length) return;
  1417. const isLast = tokens.length - 1 === index;
  1418. if (isLast) {
  1419. debug("The token %v is last.", token);
  1420. for (const child of resolvedNodes) {
  1421. debug("The node %v matches the token %v.", child.node.token, token);
  1422. if (child.node.value) {
  1423. debug("The node %v has a value.", child.node.token);
  1424. const paramNames = Object.keys(child.params);
  1425. if (paramNames.length) {
  1426. paramNames.forEach((name) => {
  1427. debug(
  1428. "The node %v has parameter %v with the value %v.",
  1429. child.node.token,
  1430. name,
  1431. child.params[name]
  1432. );
  1433. });
  1434. } else {
  1435. debug("The node %v has no parameters.", child.node.token);
  1436. }
  1437. Object.assign(params, child.params);
  1438. return { node: child.node, params };
  1439. }
  1440. }
  1441. } else {
  1442. for (const child of resolvedNodes) {
  1443. const result = this._matchNode(tokens, index + 1, params, child.node);
  1444. if (result) {
  1445. debug("A value has found for the path %v.", "/" + tokens.join("/"));
  1446. const paramNames = Object.keys(child.params);
  1447. if (paramNames.length) {
  1448. paramNames.forEach((name) => {
  1449. debug(
  1450. "The node %v has parameter %v with the value %v.",
  1451. child.node.token,
  1452. name,
  1453. child.params[name]
  1454. );
  1455. });
  1456. } else {
  1457. debug("The node %v has no parameters.", child.node.token);
  1458. }
  1459. Object.assign(params, child.params);
  1460. return result;
  1461. }
  1462. }
  1463. }
  1464. debug("No matched nodes with the path %v.", "/" + tokens.join("/"));
  1465. return void 0;
  1466. }
  1467. /**
  1468. * Match children nodes.
  1469. *
  1470. * @param {string} token
  1471. * @param {Node} parent
  1472. * @returns {ResolvedNode[]}
  1473. * @private
  1474. */
  1475. _matchChildrenNodes(token, parent) {
  1476. const resolvedNodes = [];
  1477. let child = parent.children[token];
  1478. if (child) {
  1479. resolvedNodes.push({ node: child, params: {} });
  1480. return resolvedNodes;
  1481. }
  1482. for (const key in parent.children) {
  1483. child = parent.children[key];
  1484. if (!child.names || !child.regexp) continue;
  1485. const match = child.regexp.exec(token);
  1486. if (match) {
  1487. const resolved = { node: child, params: {} };
  1488. let i = 0;
  1489. for (const name of child.names) {
  1490. const val = match[++i];
  1491. resolved.params[name] = decodeURIComponent(val);
  1492. }
  1493. resolvedNodes.push(resolved);
  1494. }
  1495. }
  1496. return resolvedNodes;
  1497. }
  1498. };
  1499. // Annotate the CommonJS export names for ESM import in node:
  1500. 0 && (module.exports = {
  1501. PathTrie
  1502. });