@dhaneshpurohit/mockstar 0.4.0 → 0.4.1
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/CHANGELOG.md +7 -0
- package/README.md +43 -4
- package/dist/cli.js +626 -707
- package/dist/index.js +622 -703
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -7644,130 +7644,117 @@ function preflight(bunVersion = detectBunVersion()) {
|
|
|
7644
7644
|
};
|
|
7645
7645
|
}
|
|
7646
7646
|
|
|
7647
|
-
// node_modules/hono/dist/
|
|
7648
|
-
var
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
handler = i === middleware.length && next || undefined;
|
|
7665
|
-
}
|
|
7666
|
-
if (handler) {
|
|
7667
|
-
try {
|
|
7668
|
-
res = await handler(context, () => dispatch(i + 1));
|
|
7669
|
-
} catch (err) {
|
|
7670
|
-
if (err instanceof Error && onError) {
|
|
7671
|
-
context.error = err;
|
|
7672
|
-
res = await onError(err, context);
|
|
7673
|
-
isError = true;
|
|
7674
|
-
} else {
|
|
7675
|
-
throw err;
|
|
7676
|
-
}
|
|
7677
|
-
}
|
|
7678
|
-
} else {
|
|
7679
|
-
if (context.finalized === false && onNotFound) {
|
|
7680
|
-
res = await onNotFound(context);
|
|
7681
|
-
}
|
|
7682
|
-
}
|
|
7683
|
-
if (res && (context.finalized === false || isError)) {
|
|
7684
|
-
context.res = res;
|
|
7685
|
-
}
|
|
7686
|
-
return context;
|
|
7687
|
-
}
|
|
7688
|
-
};
|
|
7647
|
+
// node_modules/hono/dist/http-exception.js
|
|
7648
|
+
var HTTPException = class extends Error {
|
|
7649
|
+
res;
|
|
7650
|
+
status;
|
|
7651
|
+
constructor(status = 500, options) {
|
|
7652
|
+
super(options?.message, { cause: options?.cause });
|
|
7653
|
+
this.res = options?.res;
|
|
7654
|
+
this.status = status;
|
|
7655
|
+
}
|
|
7656
|
+
getResponse() {
|
|
7657
|
+
if (this.res)
|
|
7658
|
+
return new Response(this.res.body, {
|
|
7659
|
+
status: this.status,
|
|
7660
|
+
headers: this.res.headers
|
|
7661
|
+
});
|
|
7662
|
+
return new Response(this.message, { status: this.status });
|
|
7663
|
+
}
|
|
7689
7664
|
};
|
|
7690
7665
|
|
|
7691
7666
|
// node_modules/hono/dist/request/constants.js
|
|
7692
|
-
var GET_MATCH_RESULT =
|
|
7667
|
+
var GET_MATCH_RESULT = Symbol();
|
|
7668
|
+
|
|
7669
|
+
// node_modules/hono/dist/utils/buffer.js
|
|
7670
|
+
var bufferToFormData = (arrayBuffer, contentType) => {
|
|
7671
|
+
return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
|
|
7672
|
+
};
|
|
7693
7673
|
|
|
7694
7674
|
// node_modules/hono/dist/utils/body.js
|
|
7695
|
-
var
|
|
7675
|
+
var MAX_NESTED_OBJECTS = 1e4;
|
|
7676
|
+
var isRawRequest = (request) => ("headers" in request);
|
|
7677
|
+
var parseBody = async (request, options = Object.create(null)) => {
|
|
7696
7678
|
const { all = false, dot = false } = options;
|
|
7697
|
-
const
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7679
|
+
const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
7680
|
+
if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded")
|
|
7681
|
+
return parseFormData(request, {
|
|
7682
|
+
all,
|
|
7683
|
+
dot
|
|
7684
|
+
});
|
|
7702
7685
|
return {};
|
|
7703
7686
|
};
|
|
7704
7687
|
async function parseFormData(request, options) {
|
|
7705
|
-
|
|
7706
|
-
|
|
7688
|
+
if (!isRawRequest(request) && request.bodyCache.formData)
|
|
7689
|
+
return convertFormDataToBodyData(await request.bodyCache.formData, options);
|
|
7690
|
+
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
7691
|
+
const arrayBuffer = await request.arrayBuffer();
|
|
7692
|
+
const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
|
|
7693
|
+
if (!isRawRequest(request))
|
|
7694
|
+
request.bodyCache.formData = formDataPromise;
|
|
7695
|
+
const formData = await formDataPromise;
|
|
7696
|
+
if (formData)
|
|
7707
7697
|
return convertFormDataToBodyData(formData, options);
|
|
7708
|
-
}
|
|
7709
7698
|
return {};
|
|
7710
7699
|
}
|
|
7711
7700
|
function convertFormDataToBodyData(formData, options) {
|
|
7712
|
-
const form =
|
|
7701
|
+
const form = Object.create(null);
|
|
7702
|
+
const nestingState = { count: 0 };
|
|
7713
7703
|
formData.forEach((value, key) => {
|
|
7714
|
-
|
|
7715
|
-
if (!shouldParseAllValues) {
|
|
7704
|
+
if (!(options.all || key.endsWith("[]")))
|
|
7716
7705
|
form[key] = value;
|
|
7717
|
-
|
|
7706
|
+
else
|
|
7718
7707
|
handleParsingAllValues(form, key, value);
|
|
7719
|
-
}
|
|
7720
7708
|
});
|
|
7721
|
-
if (options.dot)
|
|
7709
|
+
if (options.dot)
|
|
7722
7710
|
Object.entries(form).forEach(([key, value]) => {
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
handleParsingNestedValues(form, key, value);
|
|
7711
|
+
if (key.includes(".")) {
|
|
7712
|
+
handleParsingNestedValues(form, key, value, nestingState);
|
|
7726
7713
|
delete form[key];
|
|
7727
7714
|
}
|
|
7728
7715
|
});
|
|
7729
|
-
}
|
|
7730
7716
|
return form;
|
|
7731
7717
|
}
|
|
7732
7718
|
var handleParsingAllValues = (form, key, value) => {
|
|
7733
7719
|
if (form[key] !== undefined) {
|
|
7734
|
-
if (Array.isArray(form[key]))
|
|
7720
|
+
if (Array.isArray(form[key]))
|
|
7735
7721
|
form[key].push(value);
|
|
7736
|
-
|
|
7722
|
+
else
|
|
7737
7723
|
form[key] = [form[key], value];
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
} else {
|
|
7743
|
-
form[key] = [value];
|
|
7744
|
-
}
|
|
7745
|
-
}
|
|
7724
|
+
} else if (!key.endsWith("[]"))
|
|
7725
|
+
form[key] = value;
|
|
7726
|
+
else
|
|
7727
|
+
form[key] = [value];
|
|
7746
7728
|
};
|
|
7747
|
-
var handleParsingNestedValues = (form, key, value) => {
|
|
7748
|
-
if (/(?:^|\.)__proto__\./.test(key))
|
|
7729
|
+
var handleParsingNestedValues = (form, key, value, state) => {
|
|
7730
|
+
if (/(?:^|\.)__proto__\./.test(key))
|
|
7749
7731
|
return;
|
|
7750
|
-
}
|
|
7751
7732
|
let nestedForm = form;
|
|
7752
|
-
const keys = key.split(".");
|
|
7733
|
+
const keys = key.split(".", 34);
|
|
7734
|
+
if (keys.length > 33)
|
|
7735
|
+
throwNestingLimitExceeded();
|
|
7753
7736
|
keys.forEach((key2, index2) => {
|
|
7754
|
-
if (index2 === keys.length - 1)
|
|
7737
|
+
if (index2 === keys.length - 1)
|
|
7755
7738
|
nestedForm[key2] = value;
|
|
7756
|
-
|
|
7739
|
+
else {
|
|
7757
7740
|
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
7758
|
-
|
|
7741
|
+
if (state.count++ >= MAX_NESTED_OBJECTS)
|
|
7742
|
+
throwNestingLimitExceeded();
|
|
7743
|
+
nestedForm[key2] = Object.create(null);
|
|
7759
7744
|
}
|
|
7760
7745
|
nestedForm = nestedForm[key2];
|
|
7761
7746
|
}
|
|
7762
7747
|
});
|
|
7763
7748
|
};
|
|
7749
|
+
var throwNestingLimitExceeded = () => {
|
|
7750
|
+
throw new Error("Nesting limit exceeded");
|
|
7751
|
+
};
|
|
7764
7752
|
|
|
7765
7753
|
// node_modules/hono/dist/utils/url.js
|
|
7766
7754
|
var splitPath2 = (path) => {
|
|
7767
7755
|
const paths = path.split("/");
|
|
7768
|
-
if (paths[0] === "")
|
|
7756
|
+
if (paths[0] === "")
|
|
7769
7757
|
paths.shift();
|
|
7770
|
-
}
|
|
7771
7758
|
return paths;
|
|
7772
7759
|
};
|
|
7773
7760
|
var splitRoutingPath = (routePath) => {
|
|
@@ -7782,34 +7769,46 @@ var extractGroupsFromPath = (path) => {
|
|
|
7782
7769
|
groups.push([mark, match]);
|
|
7783
7770
|
return mark;
|
|
7784
7771
|
});
|
|
7785
|
-
return {
|
|
7772
|
+
return {
|
|
7773
|
+
groups,
|
|
7774
|
+
path
|
|
7775
|
+
};
|
|
7786
7776
|
};
|
|
7787
7777
|
var replaceGroupMarks = (paths, groups) => {
|
|
7788
7778
|
for (let i = groups.length - 1;i >= 0; i--) {
|
|
7789
7779
|
const [mark] = groups[i];
|
|
7790
|
-
for (let j = paths.length - 1;j >= 0; j--)
|
|
7780
|
+
for (let j = paths.length - 1;j >= 0; j--)
|
|
7791
7781
|
if (paths[j].includes(mark)) {
|
|
7792
7782
|
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
7793
7783
|
break;
|
|
7794
7784
|
}
|
|
7795
|
-
}
|
|
7796
7785
|
}
|
|
7797
7786
|
return paths;
|
|
7798
7787
|
};
|
|
7799
7788
|
var patternCache = {};
|
|
7800
7789
|
var getPattern = (label, next) => {
|
|
7801
|
-
if (label === "*")
|
|
7790
|
+
if (label === "*")
|
|
7802
7791
|
return "*";
|
|
7803
|
-
}
|
|
7804
7792
|
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
7805
7793
|
if (match) {
|
|
7806
7794
|
const cacheKey = `${label}#${next}`;
|
|
7807
7795
|
if (!patternCache[cacheKey]) {
|
|
7808
|
-
if (match[2])
|
|
7809
|
-
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7796
|
+
if (match[2])
|
|
7797
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
7798
|
+
cacheKey,
|
|
7799
|
+
match[1],
|
|
7800
|
+
new RegExp(`^${match[2]}(?=/${next})`)
|
|
7801
|
+
] : [
|
|
7802
|
+
label,
|
|
7803
|
+
match[1],
|
|
7804
|
+
new RegExp(`^${match[2]}$`)
|
|
7805
|
+
];
|
|
7806
|
+
else
|
|
7807
|
+
patternCache[cacheKey] = [
|
|
7808
|
+
label,
|
|
7809
|
+
match[1],
|
|
7810
|
+
true
|
|
7811
|
+
];
|
|
7813
7812
|
}
|
|
7814
7813
|
return patternCache[cacheKey];
|
|
7815
7814
|
}
|
|
@@ -7828,7 +7827,7 @@ var tryDecode = (str, decoder) => {
|
|
|
7828
7827
|
});
|
|
7829
7828
|
}
|
|
7830
7829
|
};
|
|
7831
|
-
var
|
|
7830
|
+
var decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
|
|
7832
7831
|
var getPath = (request) => {
|
|
7833
7832
|
const url = request.url;
|
|
7834
7833
|
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
@@ -7840,10 +7839,16 @@ var getPath = (request) => {
|
|
|
7840
7839
|
const hashIndex = url.indexOf("#", i);
|
|
7841
7840
|
const end = queryIndex === -1 ? hashIndex === -1 ? undefined : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
7842
7841
|
const path = url.slice(start, end);
|
|
7843
|
-
|
|
7844
|
-
|
|
7842
|
+
const decoded = tryDecode(path, decodeURIWithPreservedPercent);
|
|
7843
|
+
if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
|
|
7844
|
+
const rewritten = new URL("http://localhost");
|
|
7845
|
+
rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
7846
|
+
if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded)
|
|
7847
|
+
return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
|
|
7848
|
+
}
|
|
7849
|
+
return decoded;
|
|
7850
|
+
} else if (charCode === 63 || charCode === 35)
|
|
7845
7851
|
break;
|
|
7846
|
-
}
|
|
7847
7852
|
}
|
|
7848
7853
|
return url.slice(start, i);
|
|
7849
7854
|
};
|
|
@@ -7852,107 +7857,98 @@ var getPathNoStrict = (request) => {
|
|
|
7852
7857
|
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
7853
7858
|
};
|
|
7854
7859
|
var mergePath = (base, sub, ...rest) => {
|
|
7855
|
-
if (rest.length)
|
|
7860
|
+
if (rest.length)
|
|
7856
7861
|
sub = mergePath(sub, ...rest);
|
|
7857
|
-
}
|
|
7858
7862
|
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
7859
7863
|
};
|
|
7860
7864
|
var checkOptionalParameter = (path) => {
|
|
7861
|
-
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":"))
|
|
7865
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":"))
|
|
7862
7866
|
return null;
|
|
7863
|
-
}
|
|
7864
7867
|
const segments = path.split("/");
|
|
7865
7868
|
const results = [];
|
|
7866
7869
|
let basePath = "";
|
|
7867
7870
|
segments.forEach((segment) => {
|
|
7868
|
-
if (segment !== "" && !/\:/.test(segment))
|
|
7871
|
+
if (segment !== "" && !/\:/.test(segment))
|
|
7869
7872
|
basePath += "/" + segment;
|
|
7870
|
-
|
|
7871
|
-
if (
|
|
7872
|
-
if (results.length === 0 && basePath === "")
|
|
7873
|
+
else if (/\:/.test(segment)) {
|
|
7874
|
+
if (segment.charCodeAt(segment.length - 1) === 63) {
|
|
7875
|
+
if (results.length === 0 && basePath === "")
|
|
7873
7876
|
results.push("/");
|
|
7874
|
-
|
|
7877
|
+
else
|
|
7875
7878
|
results.push(basePath);
|
|
7876
|
-
|
|
7877
|
-
const optionalSegment = segment.replace("?", "");
|
|
7879
|
+
const optionalSegment = segment.slice(0, -1);
|
|
7878
7880
|
basePath += "/" + optionalSegment;
|
|
7879
7881
|
results.push(basePath);
|
|
7880
|
-
} else
|
|
7882
|
+
} else
|
|
7881
7883
|
basePath += "/" + segment;
|
|
7882
|
-
}
|
|
7883
7884
|
}
|
|
7884
7885
|
});
|
|
7885
7886
|
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
7886
7887
|
};
|
|
7888
|
+
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
|
|
7887
7889
|
var _decodeURI = (value) => {
|
|
7888
|
-
if (
|
|
7889
|
-
return value;
|
|
7890
|
-
}
|
|
7891
|
-
if (value.indexOf("+") !== -1) {
|
|
7890
|
+
if (value.indexOf("+") !== -1)
|
|
7892
7891
|
value = value.replace(/\+/g, " ");
|
|
7893
|
-
|
|
7894
|
-
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
7892
|
+
return tryDecodeURIComponent(value);
|
|
7895
7893
|
};
|
|
7896
7894
|
var _getQueryParam = (url, key, multiple) => {
|
|
7895
|
+
const hashIndex = url.indexOf("#", 8);
|
|
7896
|
+
if (hashIndex !== -1)
|
|
7897
|
+
url = url.slice(0, hashIndex);
|
|
7897
7898
|
let encoded;
|
|
7898
|
-
if (!multiple && key && !/[
|
|
7899
|
-
|
|
7900
|
-
|
|
7899
|
+
if (!multiple && key && !/[%+&=]/.test(key)) {
|
|
7900
|
+
const queryIndex = url.indexOf("?", 8);
|
|
7901
|
+
let keyIndex2 = queryIndex;
|
|
7902
|
+
if (keyIndex2 === -1)
|
|
7901
7903
|
return;
|
|
7902
|
-
|
|
7903
|
-
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
7904
|
+
if (!url.startsWith(key, keyIndex2 + 1))
|
|
7904
7905
|
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
7905
|
-
}
|
|
7906
7906
|
while (keyIndex2 !== -1) {
|
|
7907
7907
|
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
7908
|
-
if (trailingKeyCode === 61) {
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7908
|
+
if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
|
|
7909
|
+
if (keyIndex2 > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex2)))
|
|
7910
|
+
break;
|
|
7911
|
+
if (trailingKeyCode === 61) {
|
|
7912
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
7913
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
7914
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
|
|
7915
|
+
}
|
|
7913
7916
|
return "";
|
|
7914
7917
|
}
|
|
7915
7918
|
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
7916
7919
|
}
|
|
7917
7920
|
encoded = /[%+]/.test(url);
|
|
7918
|
-
if (!encoded)
|
|
7921
|
+
if (!encoded)
|
|
7919
7922
|
return;
|
|
7920
|
-
}
|
|
7921
7923
|
}
|
|
7922
|
-
const results =
|
|
7924
|
+
const results = Object.create(null);
|
|
7923
7925
|
encoded ??= /[%+]/.test(url);
|
|
7924
7926
|
let keyIndex = url.indexOf("?", 8);
|
|
7925
7927
|
while (keyIndex !== -1) {
|
|
7926
7928
|
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
7927
7929
|
let valueIndex = url.indexOf("=", keyIndex);
|
|
7928
|
-
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1)
|
|
7930
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1)
|
|
7929
7931
|
valueIndex = -1;
|
|
7930
|
-
}
|
|
7931
7932
|
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? undefined : nextKeyIndex : valueIndex);
|
|
7932
|
-
if (encoded)
|
|
7933
|
+
if (encoded)
|
|
7933
7934
|
name = _decodeURI(name);
|
|
7934
|
-
}
|
|
7935
7935
|
keyIndex = nextKeyIndex;
|
|
7936
|
-
if (name === "")
|
|
7936
|
+
if (name === "")
|
|
7937
7937
|
continue;
|
|
7938
|
-
}
|
|
7939
7938
|
let value;
|
|
7940
|
-
if (valueIndex === -1)
|
|
7939
|
+
if (valueIndex === -1)
|
|
7941
7940
|
value = "";
|
|
7942
|
-
|
|
7941
|
+
else {
|
|
7943
7942
|
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex);
|
|
7944
|
-
if (encoded)
|
|
7943
|
+
if (encoded)
|
|
7945
7944
|
value = _decodeURI(value);
|
|
7946
|
-
}
|
|
7947
7945
|
}
|
|
7948
7946
|
if (multiple) {
|
|
7949
|
-
if (!(results[name] && Array.isArray(results[name])))
|
|
7947
|
+
if (!(results[name] && Array.isArray(results[name])))
|
|
7950
7948
|
results[name] = [];
|
|
7951
|
-
}
|
|
7952
7949
|
results[name].push(value);
|
|
7953
|
-
} else
|
|
7950
|
+
} else
|
|
7954
7951
|
results[name] ??= value;
|
|
7955
|
-
}
|
|
7956
7952
|
}
|
|
7957
7953
|
return key ? results[key] : results;
|
|
7958
7954
|
};
|
|
@@ -7963,7 +7959,6 @@ var getQueryParams = (url, key) => {
|
|
|
7963
7959
|
var decodeURIComponent_ = decodeURIComponent;
|
|
7964
7960
|
|
|
7965
7961
|
// node_modules/hono/dist/request.js
|
|
7966
|
-
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
7967
7962
|
var HonoRequest = class {
|
|
7968
7963
|
raw;
|
|
7969
7964
|
#validatedData;
|
|
@@ -7975,24 +7970,22 @@ var HonoRequest = class {
|
|
|
7975
7970
|
this.raw = request;
|
|
7976
7971
|
this.path = path;
|
|
7977
7972
|
this.#matchResult = matchResult;
|
|
7978
|
-
this.#validatedData = {};
|
|
7979
7973
|
}
|
|
7980
7974
|
param(key) {
|
|
7981
7975
|
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
7982
7976
|
}
|
|
7983
7977
|
#getDecodedParam(key) {
|
|
7984
|
-
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
7978
|
+
const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
|
|
7985
7979
|
const param = this.#getParamValue(paramKey);
|
|
7986
|
-
return param &&
|
|
7980
|
+
return param && tryDecodeURIComponent(param);
|
|
7987
7981
|
}
|
|
7988
7982
|
#getAllDecodedParams() {
|
|
7989
7983
|
const decoded = {};
|
|
7990
|
-
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
7984
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
|
|
7991
7985
|
for (const key of keys) {
|
|
7992
7986
|
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
7993
|
-
if (value !== undefined)
|
|
7994
|
-
decoded[key] =
|
|
7995
|
-
}
|
|
7987
|
+
if (value !== undefined)
|
|
7988
|
+
decoded[key] = tryDecodeURIComponent(value);
|
|
7996
7989
|
}
|
|
7997
7990
|
return decoded;
|
|
7998
7991
|
}
|
|
@@ -8006,10 +7999,9 @@ var HonoRequest = class {
|
|
|
8006
7999
|
return getQueryParams(this.url, key);
|
|
8007
8000
|
}
|
|
8008
8001
|
header(name) {
|
|
8009
|
-
if (name)
|
|
8002
|
+
if (name)
|
|
8010
8003
|
return this.raw.headers.get(name) ?? undefined;
|
|
8011
|
-
|
|
8012
|
-
const headerData = {};
|
|
8004
|
+
const headerData = Object.create(null);
|
|
8013
8005
|
this.raw.headers.forEach((value, key) => {
|
|
8014
8006
|
headerData[key] = value;
|
|
8015
8007
|
});
|
|
@@ -8021,18 +8013,15 @@ var HonoRequest = class {
|
|
|
8021
8013
|
#cachedBody = (key) => {
|
|
8022
8014
|
const { bodyCache, raw } = this;
|
|
8023
8015
|
const cachedBody = bodyCache[key];
|
|
8024
|
-
if (cachedBody)
|
|
8016
|
+
if (cachedBody)
|
|
8025
8017
|
return cachedBody;
|
|
8026
|
-
|
|
8027
|
-
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
8028
|
-
if (anyCachedKey) {
|
|
8018
|
+
for (const anyCachedKey in bodyCache)
|
|
8029
8019
|
return bodyCache[anyCachedKey].then((body) => {
|
|
8030
|
-
if (anyCachedKey === "json")
|
|
8020
|
+
if (anyCachedKey === "json")
|
|
8031
8021
|
body = JSON.stringify(body);
|
|
8032
|
-
|
|
8033
|
-
return new Response(body)[key]();
|
|
8022
|
+
const contentType = anyCachedKey === "formData" ? undefined : raw.headers.get("content-type");
|
|
8023
|
+
return new Response(body, { headers: contentType ? { "Content-Type": contentType } : undefined })[key]();
|
|
8034
8024
|
});
|
|
8035
|
-
}
|
|
8036
8025
|
return bodyCache[key] = raw[key]();
|
|
8037
8026
|
};
|
|
8038
8027
|
json() {
|
|
@@ -8044,6 +8033,9 @@ var HonoRequest = class {
|
|
|
8044
8033
|
arrayBuffer() {
|
|
8045
8034
|
return this.#cachedBody("arrayBuffer");
|
|
8046
8035
|
}
|
|
8036
|
+
bytes() {
|
|
8037
|
+
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
8038
|
+
}
|
|
8047
8039
|
blob() {
|
|
8048
8040
|
return this.#cachedBody("blob");
|
|
8049
8041
|
}
|
|
@@ -8051,10 +8043,10 @@ var HonoRequest = class {
|
|
|
8051
8043
|
return this.#cachedBody("formData");
|
|
8052
8044
|
}
|
|
8053
8045
|
addValidatedData(target, data) {
|
|
8054
|
-
this.#validatedData[target] = data;
|
|
8046
|
+
(this.#validatedData ??= {})[target] = data;
|
|
8055
8047
|
}
|
|
8056
8048
|
valid(target) {
|
|
8057
|
-
return this.#validatedData[target];
|
|
8049
|
+
return this.#validatedData?.[target];
|
|
8058
8050
|
}
|
|
8059
8051
|
get url() {
|
|
8060
8052
|
return this.raw.url;
|
|
@@ -8087,28 +8079,27 @@ var raw = (value, callbacks) => {
|
|
|
8087
8079
|
};
|
|
8088
8080
|
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
8089
8081
|
if (typeof str === "object" && !(str instanceof String)) {
|
|
8090
|
-
if (!(str instanceof Promise))
|
|
8082
|
+
if (!(str instanceof Promise))
|
|
8091
8083
|
str = str.toString();
|
|
8092
|
-
|
|
8093
|
-
if (str instanceof Promise) {
|
|
8084
|
+
if (str instanceof Promise)
|
|
8094
8085
|
str = await str;
|
|
8095
|
-
}
|
|
8096
8086
|
}
|
|
8097
8087
|
const callbacks = str.callbacks;
|
|
8098
|
-
if (!callbacks?.length)
|
|
8088
|
+
if (!callbacks?.length)
|
|
8099
8089
|
return Promise.resolve(str);
|
|
8100
|
-
|
|
8101
|
-
if (buffer) {
|
|
8090
|
+
if (buffer)
|
|
8102
8091
|
buffer[0] += str;
|
|
8103
|
-
|
|
8092
|
+
else
|
|
8104
8093
|
buffer = [str];
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8094
|
+
const resStr = Promise.all(callbacks.map((c) => c({
|
|
8095
|
+
phase,
|
|
8096
|
+
buffer,
|
|
8097
|
+
context
|
|
8098
|
+
}))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
|
|
8099
|
+
if (preserveCallbacks)
|
|
8108
8100
|
return raw(await resStr, callbacks);
|
|
8109
|
-
|
|
8101
|
+
else
|
|
8110
8102
|
return resStr;
|
|
8111
|
-
}
|
|
8112
8103
|
};
|
|
8113
8104
|
|
|
8114
8105
|
// node_modules/hono/dist/context.js
|
|
@@ -8151,40 +8142,33 @@ var Context = class {
|
|
|
8151
8142
|
return this.#req;
|
|
8152
8143
|
}
|
|
8153
8144
|
get event() {
|
|
8154
|
-
if (this.#executionCtx && "respondWith" in this.#executionCtx)
|
|
8145
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx)
|
|
8155
8146
|
return this.#executionCtx;
|
|
8156
|
-
|
|
8147
|
+
else
|
|
8157
8148
|
throw Error("This context has no FetchEvent");
|
|
8158
|
-
}
|
|
8159
8149
|
}
|
|
8160
8150
|
get executionCtx() {
|
|
8161
|
-
if (this.#executionCtx)
|
|
8151
|
+
if (this.#executionCtx)
|
|
8162
8152
|
return this.#executionCtx;
|
|
8163
|
-
|
|
8153
|
+
else
|
|
8164
8154
|
throw Error("This context has no ExecutionContext");
|
|
8165
|
-
}
|
|
8166
8155
|
}
|
|
8167
8156
|
get res() {
|
|
8168
|
-
return this.#res ||= createResponseInstance(null, {
|
|
8169
|
-
headers: this.#preparedHeaders ??= new Headers
|
|
8170
|
-
});
|
|
8157
|
+
return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers });
|
|
8171
8158
|
}
|
|
8172
8159
|
set res(_res) {
|
|
8173
8160
|
if (this.#res && _res) {
|
|
8174
8161
|
_res = createResponseInstance(_res.body, _res);
|
|
8175
8162
|
for (const [k, v] of this.#res.headers.entries()) {
|
|
8176
|
-
if (k === "content-type")
|
|
8163
|
+
if (k === "content-type")
|
|
8177
8164
|
continue;
|
|
8178
|
-
}
|
|
8179
8165
|
if (k === "set-cookie") {
|
|
8180
8166
|
const cookies = this.#res.headers.getSetCookie();
|
|
8181
8167
|
_res.headers.delete("set-cookie");
|
|
8182
|
-
for (const cookie of cookies)
|
|
8168
|
+
for (const cookie of cookies)
|
|
8183
8169
|
_res.headers.append("set-cookie", cookie);
|
|
8184
|
-
|
|
8185
|
-
} else {
|
|
8170
|
+
} else
|
|
8186
8171
|
_res.headers.set(k, v);
|
|
8187
|
-
}
|
|
8188
8172
|
}
|
|
8189
8173
|
}
|
|
8190
8174
|
this.#res = _res;
|
|
@@ -8200,17 +8184,15 @@ var Context = class {
|
|
|
8200
8184
|
this.#renderer = renderer;
|
|
8201
8185
|
};
|
|
8202
8186
|
header = (name, value, options) => {
|
|
8203
|
-
if (this.finalized)
|
|
8187
|
+
if (this.finalized && !this.#res.bodyUsed)
|
|
8204
8188
|
this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
8205
|
-
}
|
|
8206
8189
|
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers;
|
|
8207
|
-
if (value === undefined)
|
|
8190
|
+
if (value === undefined)
|
|
8208
8191
|
headers.delete(name);
|
|
8209
|
-
|
|
8192
|
+
else if (options?.append)
|
|
8210
8193
|
headers.append(name, value);
|
|
8211
|
-
|
|
8194
|
+
else
|
|
8212
8195
|
headers.set(name, value);
|
|
8213
|
-
}
|
|
8214
8196
|
};
|
|
8215
8197
|
status = (status) => {
|
|
8216
8198
|
this.#status = status;
|
|
@@ -8223,37 +8205,46 @@ var Context = class {
|
|
|
8223
8205
|
return this.#var ? this.#var.get(key) : undefined;
|
|
8224
8206
|
};
|
|
8225
8207
|
get var() {
|
|
8226
|
-
if (!this.#var)
|
|
8208
|
+
if (!this.#var)
|
|
8227
8209
|
return {};
|
|
8228
|
-
}
|
|
8229
8210
|
return Object.fromEntries(this.#var);
|
|
8230
8211
|
}
|
|
8231
8212
|
#newResponse(data, arg, headers) {
|
|
8232
|
-
|
|
8233
|
-
if (typeof arg === "object" &&
|
|
8234
|
-
|
|
8235
|
-
for (const [key, value] of
|
|
8236
|
-
if (key
|
|
8213
|
+
let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
|
|
8214
|
+
if (typeof arg === "object" && arg.headers) {
|
|
8215
|
+
responseHeaders ??= new Headers;
|
|
8216
|
+
for (const [key, value] of new Headers(arg.headers))
|
|
8217
|
+
if (key === "set-cookie")
|
|
8237
8218
|
responseHeaders.append(key, value);
|
|
8238
|
-
|
|
8219
|
+
else
|
|
8239
8220
|
responseHeaders.set(key, value);
|
|
8240
|
-
}
|
|
8241
|
-
}
|
|
8242
8221
|
}
|
|
8243
8222
|
if (headers) {
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
responseHeaders.append(k, v2);
|
|
8223
|
+
if (!responseHeaders) {
|
|
8224
|
+
let count = 0;
|
|
8225
|
+
for (const k in headers)
|
|
8226
|
+
if (++count > 1 || typeof headers[k] !== "string") {
|
|
8227
|
+
responseHeaders = new Headers;
|
|
8228
|
+
break;
|
|
8251
8229
|
}
|
|
8252
|
-
}
|
|
8253
8230
|
}
|
|
8231
|
+
if (responseHeaders)
|
|
8232
|
+
for (const k in headers) {
|
|
8233
|
+
const v = headers[k];
|
|
8234
|
+
if (typeof v === "string")
|
|
8235
|
+
responseHeaders.set(k, v);
|
|
8236
|
+
else {
|
|
8237
|
+
responseHeaders.delete(k);
|
|
8238
|
+
for (const v2 of v)
|
|
8239
|
+
responseHeaders.append(k, v2);
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8254
8242
|
}
|
|
8255
8243
|
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
8256
|
-
return createResponseInstance(data, {
|
|
8244
|
+
return createResponseInstance(data, {
|
|
8245
|
+
status,
|
|
8246
|
+
headers: responseHeaders ?? headers
|
|
8247
|
+
});
|
|
8257
8248
|
}
|
|
8258
8249
|
newResponse = (...args) => this.#newResponse(...args);
|
|
8259
8250
|
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
@@ -8278,10 +8269,57 @@ var Context = class {
|
|
|
8278
8269
|
};
|
|
8279
8270
|
};
|
|
8280
8271
|
|
|
8272
|
+
// node_modules/hono/dist/compose.js
|
|
8273
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
8274
|
+
return (context, next) => {
|
|
8275
|
+
let index2 = -1;
|
|
8276
|
+
return dispatch(0);
|
|
8277
|
+
async function dispatch(i) {
|
|
8278
|
+
if (i <= index2)
|
|
8279
|
+
throw new Error("next() called multiple times");
|
|
8280
|
+
index2 = i;
|
|
8281
|
+
let res;
|
|
8282
|
+
let isError = false;
|
|
8283
|
+
let handler;
|
|
8284
|
+
if (middleware[i]) {
|
|
8285
|
+
handler = middleware[i][0][0];
|
|
8286
|
+
context.req.routeIndex = i;
|
|
8287
|
+
} else
|
|
8288
|
+
handler = i === middleware.length && next || undefined;
|
|
8289
|
+
if (handler)
|
|
8290
|
+
try {
|
|
8291
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
8292
|
+
} catch (err) {
|
|
8293
|
+
if (err instanceof Error && onError) {
|
|
8294
|
+
context.error = err;
|
|
8295
|
+
res = await onError(err, context);
|
|
8296
|
+
isError = true;
|
|
8297
|
+
} else
|
|
8298
|
+
throw err;
|
|
8299
|
+
}
|
|
8300
|
+
else if (context.finalized === false && onNotFound)
|
|
8301
|
+
res = await onNotFound(context);
|
|
8302
|
+
if (res && (context.finalized === false || isError))
|
|
8303
|
+
context.res = res;
|
|
8304
|
+
return context;
|
|
8305
|
+
}
|
|
8306
|
+
};
|
|
8307
|
+
};
|
|
8308
|
+
|
|
8309
|
+
// node_modules/hono/dist/helper/route/index.js
|
|
8310
|
+
var matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
|
|
8311
|
+
var routePath = (c, index2) => matchedRoutes(c).at(index2 ?? c.req.routeIndex)?.path ?? "";
|
|
8312
|
+
|
|
8281
8313
|
// node_modules/hono/dist/router.js
|
|
8282
|
-
var
|
|
8283
|
-
|
|
8284
|
-
|
|
8314
|
+
var METHODS = [
|
|
8315
|
+
"get",
|
|
8316
|
+
"post",
|
|
8317
|
+
"put",
|
|
8318
|
+
"delete",
|
|
8319
|
+
"options",
|
|
8320
|
+
"patch",
|
|
8321
|
+
"query"
|
|
8322
|
+
];
|
|
8285
8323
|
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
8286
8324
|
var UnsupportedPathError = class extends Error {
|
|
8287
8325
|
};
|
|
@@ -8289,6 +8327,61 @@ var UnsupportedPathError = class extends Error {
|
|
|
8289
8327
|
// node_modules/hono/dist/utils/constants.js
|
|
8290
8328
|
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
8291
8329
|
|
|
8330
|
+
// node_modules/hono/dist/utils/mount.js
|
|
8331
|
+
var countTrailingSlashes = (path) => {
|
|
8332
|
+
let index2 = path.length;
|
|
8333
|
+
while (index2 > 0 && path.charCodeAt(index2 - 1) === 47)
|
|
8334
|
+
index2--;
|
|
8335
|
+
return path.length - index2;
|
|
8336
|
+
};
|
|
8337
|
+
var getPathPrefixLength = (c, pathPrefix, routePath2) => {
|
|
8338
|
+
if (!/[:*]/.test(pathPrefix))
|
|
8339
|
+
return pathPrefix.length;
|
|
8340
|
+
const path = c.req.path;
|
|
8341
|
+
const matchResult = c.req[GET_MATCH_RESULT];
|
|
8342
|
+
const paramNames = /* @__PURE__ */ new Set;
|
|
8343
|
+
let length = 0;
|
|
8344
|
+
for (const part of splitRoutingPath(pathPrefix)) {
|
|
8345
|
+
if (part[0] === ":" && part.endsWith("}?"))
|
|
8346
|
+
throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath2}".`);
|
|
8347
|
+
const pattern = getPattern(part);
|
|
8348
|
+
if (pattern && pattern !== "*") {
|
|
8349
|
+
const name = pattern[1];
|
|
8350
|
+
if (paramNames.has(name))
|
|
8351
|
+
throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath2}".`);
|
|
8352
|
+
paramNames.add(name);
|
|
8353
|
+
}
|
|
8354
|
+
if (pattern && pattern !== "*" && pattern[2] !== true) {
|
|
8355
|
+
const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
|
|
8356
|
+
length += value.length + 1;
|
|
8357
|
+
} else if (pattern || part.endsWith("*")) {
|
|
8358
|
+
const end = path.indexOf("/", length + 1);
|
|
8359
|
+
length = end === -1 ? path.length : end;
|
|
8360
|
+
} else
|
|
8361
|
+
length += part.length + 1;
|
|
8362
|
+
}
|
|
8363
|
+
return length;
|
|
8364
|
+
};
|
|
8365
|
+
var createMountedRequest = (c, pathPrefix, routePath2) => {
|
|
8366
|
+
if (/[^/]\*$/.test(routePath2))
|
|
8367
|
+
throw new Error(`mount(): Wildcard must follow "/" in "${routePath2}".`);
|
|
8368
|
+
const prefixLength = getPathPrefixLength(c, pathPrefix, routePath2);
|
|
8369
|
+
const path = c.req.path.slice(prefixLength) || "/";
|
|
8370
|
+
if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path))
|
|
8371
|
+
throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
8372
|
+
const rawUrl = c.req.raw.url;
|
|
8373
|
+
if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl))
|
|
8374
|
+
throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
8375
|
+
const rawPathEnd = rawUrl.search(/[?#]/);
|
|
8376
|
+
const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
|
|
8377
|
+
if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1)
|
|
8378
|
+
throw new HTTPException(400, { message: "Invalid mounted path" });
|
|
8379
|
+
const url = new URL(rawUrl);
|
|
8380
|
+
url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
8381
|
+
if (path.includes("%")) {}
|
|
8382
|
+
return new Request(url, c.req.raw);
|
|
8383
|
+
};
|
|
8384
|
+
|
|
8292
8385
|
// node_modules/hono/dist/hono-base.js
|
|
8293
8386
|
var notFoundHandler = (c) => {
|
|
8294
8387
|
return c.text("404 Not Found", 404);
|
|
@@ -8301,13 +8394,14 @@ var errorHandler = (err, c) => {
|
|
|
8301
8394
|
console.error(err);
|
|
8302
8395
|
return c.text("Internal Server Error", 500);
|
|
8303
8396
|
};
|
|
8304
|
-
var Hono = class
|
|
8397
|
+
var Hono = class Hono2 {
|
|
8305
8398
|
get;
|
|
8306
8399
|
post;
|
|
8307
8400
|
put;
|
|
8308
8401
|
delete;
|
|
8309
8402
|
options;
|
|
8310
8403
|
patch;
|
|
8404
|
+
query;
|
|
8311
8405
|
all;
|
|
8312
8406
|
on;
|
|
8313
8407
|
use;
|
|
@@ -8317,16 +8411,15 @@ var Hono = class _Hono {
|
|
|
8317
8411
|
#path = "/";
|
|
8318
8412
|
routes = [];
|
|
8319
8413
|
constructor(options = {}) {
|
|
8320
|
-
|
|
8321
|
-
allMethods.forEach((method) => {
|
|
8414
|
+
[...METHODS, "all"].forEach((method) => {
|
|
8322
8415
|
this[method] = (args1, ...args) => {
|
|
8323
|
-
|
|
8416
|
+
const methodName = method.toUpperCase();
|
|
8417
|
+
if (typeof args1 === "string")
|
|
8324
8418
|
this.#path = args1;
|
|
8325
|
-
|
|
8326
|
-
this.#addRoute(
|
|
8327
|
-
}
|
|
8419
|
+
else
|
|
8420
|
+
this.#addRoute(methodName, this.#path, args1);
|
|
8328
8421
|
args.forEach((handler) => {
|
|
8329
|
-
this.#addRoute(
|
|
8422
|
+
this.#addRoute(methodName, this.#path, handler);
|
|
8330
8423
|
});
|
|
8331
8424
|
return this;
|
|
8332
8425
|
};
|
|
@@ -8335,22 +8428,22 @@ var Hono = class _Hono {
|
|
|
8335
8428
|
for (const p of [path].flat()) {
|
|
8336
8429
|
this.#path = p;
|
|
8337
8430
|
for (const m of [method].flat()) {
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8431
|
+
const methodName = m.toUpperCase();
|
|
8432
|
+
for (const handler of handlers)
|
|
8433
|
+
this.#addRoute(methodName, this.#path, handler);
|
|
8341
8434
|
}
|
|
8342
8435
|
}
|
|
8343
8436
|
return this;
|
|
8344
8437
|
};
|
|
8345
8438
|
this.use = (arg1, ...handlers) => {
|
|
8346
|
-
if (typeof arg1 === "string")
|
|
8439
|
+
if (typeof arg1 === "string")
|
|
8347
8440
|
this.#path = arg1;
|
|
8348
|
-
|
|
8441
|
+
else {
|
|
8349
8442
|
this.#path = "*";
|
|
8350
8443
|
handlers.unshift(arg1);
|
|
8351
8444
|
}
|
|
8352
8445
|
handlers.forEach((handler) => {
|
|
8353
|
-
this.#addRoute(
|
|
8446
|
+
this.#addRoute("ALL", this.#path, handler);
|
|
8354
8447
|
});
|
|
8355
8448
|
return this;
|
|
8356
8449
|
};
|
|
@@ -8359,7 +8452,7 @@ var Hono = class _Hono {
|
|
|
8359
8452
|
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
8360
8453
|
}
|
|
8361
8454
|
#clone() {
|
|
8362
|
-
const clone = new
|
|
8455
|
+
const clone = new Hono2({
|
|
8363
8456
|
router: this.router,
|
|
8364
8457
|
getPath: this.getPath
|
|
8365
8458
|
});
|
|
@@ -8374,13 +8467,13 @@ var Hono = class _Hono {
|
|
|
8374
8467
|
const subApp = this.basePath(path);
|
|
8375
8468
|
app.routes.map((r) => {
|
|
8376
8469
|
let handler;
|
|
8377
|
-
if (app.errorHandler === errorHandler)
|
|
8470
|
+
if (app.errorHandler === errorHandler)
|
|
8378
8471
|
handler = r.handler;
|
|
8379
|
-
|
|
8472
|
+
else {
|
|
8380
8473
|
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
8381
8474
|
handler[COMPOSED_HANDLER] = r.handler;
|
|
8382
8475
|
}
|
|
8383
|
-
subApp.#addRoute(r.method, r.path, handler);
|
|
8476
|
+
subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
8384
8477
|
});
|
|
8385
8478
|
return this;
|
|
8386
8479
|
}
|
|
@@ -8401,15 +8494,14 @@ var Hono = class _Hono {
|
|
|
8401
8494
|
let replaceRequest;
|
|
8402
8495
|
let optionHandler;
|
|
8403
8496
|
if (options) {
|
|
8404
|
-
if (typeof options === "function")
|
|
8497
|
+
if (typeof options === "function")
|
|
8405
8498
|
optionHandler = options;
|
|
8406
|
-
|
|
8499
|
+
else {
|
|
8407
8500
|
optionHandler = options.optionHandler;
|
|
8408
|
-
if (options.replaceRequest === false)
|
|
8501
|
+
if (options.replaceRequest === false)
|
|
8409
8502
|
replaceRequest = (request) => request;
|
|
8410
|
-
|
|
8503
|
+
else
|
|
8411
8504
|
replaceRequest = options.replaceRequest;
|
|
8412
|
-
}
|
|
8413
8505
|
}
|
|
8414
8506
|
}
|
|
8415
8507
|
const getOptions = optionHandler ? (c) => {
|
|
@@ -8422,42 +8514,38 @@ var Hono = class _Hono {
|
|
|
8422
8514
|
} catch {}
|
|
8423
8515
|
return [c.env, executionContext];
|
|
8424
8516
|
};
|
|
8425
|
-
|
|
8426
|
-
const
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
const url = new URL(request.url);
|
|
8430
|
-
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
8431
|
-
return new Request(url, request);
|
|
8432
|
-
};
|
|
8433
|
-
})();
|
|
8517
|
+
const defaultReplaceRequest = (c) => {
|
|
8518
|
+
const mountedRoutePath = routePath(c);
|
|
8519
|
+
return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
|
|
8520
|
+
};
|
|
8434
8521
|
const handler = async (c, next) => {
|
|
8435
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
8436
|
-
if (res)
|
|
8522
|
+
const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
8523
|
+
if (res)
|
|
8437
8524
|
return res;
|
|
8438
|
-
}
|
|
8439
8525
|
await next();
|
|
8440
8526
|
};
|
|
8441
|
-
this.#addRoute(
|
|
8527
|
+
this.#addRoute("ALL", mergePath(path, "*"), handler);
|
|
8442
8528
|
return this;
|
|
8443
8529
|
}
|
|
8444
|
-
#addRoute(method, path, handler) {
|
|
8445
|
-
method = method.toUpperCase();
|
|
8530
|
+
#addRoute(method, path, handler, baseRoutePath) {
|
|
8446
8531
|
path = mergePath(this._basePath, path);
|
|
8447
|
-
const r = {
|
|
8532
|
+
const r = {
|
|
8533
|
+
basePath: baseRoutePath !== undefined ? mergePath(this._basePath, baseRoutePath) : this._basePath,
|
|
8534
|
+
path,
|
|
8535
|
+
method,
|
|
8536
|
+
handler
|
|
8537
|
+
};
|
|
8448
8538
|
this.router.add(method, path, [handler, r]);
|
|
8449
8539
|
this.routes.push(r);
|
|
8450
8540
|
}
|
|
8451
8541
|
#handleError(err, c) {
|
|
8452
|
-
if (err instanceof Error)
|
|
8542
|
+
if (err instanceof Error)
|
|
8453
8543
|
return this.errorHandler(err, c);
|
|
8454
|
-
}
|
|
8455
8544
|
throw err;
|
|
8456
8545
|
}
|
|
8457
8546
|
#dispatch(request, executionCtx, env, method) {
|
|
8458
|
-
if (method === "HEAD")
|
|
8547
|
+
if (method === "HEAD")
|
|
8459
8548
|
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
8460
|
-
}
|
|
8461
8549
|
const path = this.getPath(request, { env });
|
|
8462
8550
|
const matchResult = this.router.match(method, path);
|
|
8463
8551
|
const c = new Context(request, {
|
|
@@ -8482,9 +8570,8 @@ var Hono = class _Hono {
|
|
|
8482
8570
|
return (async () => {
|
|
8483
8571
|
try {
|
|
8484
8572
|
const context = await composed(c);
|
|
8485
|
-
if (!context.finalized)
|
|
8573
|
+
if (!context.finalized)
|
|
8486
8574
|
throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
8487
|
-
}
|
|
8488
8575
|
return context.res;
|
|
8489
8576
|
} catch (err) {
|
|
8490
8577
|
return this.#handleError(err, c);
|
|
@@ -8495,9 +8582,8 @@ var Hono = class _Hono {
|
|
|
8495
8582
|
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
8496
8583
|
};
|
|
8497
8584
|
request = (input, requestInit, Env, executionCtx) => {
|
|
8498
|
-
if (input instanceof Request)
|
|
8585
|
+
if (input instanceof Request)
|
|
8499
8586
|
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
8500
|
-
}
|
|
8501
8587
|
input = input.toString();
|
|
8502
8588
|
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
8503
8589
|
};
|
|
@@ -8508,20 +8594,21 @@ var Hono = class _Hono {
|
|
|
8508
8594
|
};
|
|
8509
8595
|
};
|
|
8510
8596
|
|
|
8597
|
+
// node_modules/hono/dist/router/utils.js
|
|
8598
|
+
var createNullObject = () => Object.create(null);
|
|
8599
|
+
|
|
8511
8600
|
// node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
8512
8601
|
var emptyParam = [];
|
|
8513
8602
|
function match(method, path) {
|
|
8514
8603
|
const matchers = this.buildAllMatchers();
|
|
8515
8604
|
const match2 = (method2, path2) => {
|
|
8516
|
-
const matcher = matchers[method2] || matchers[
|
|
8605
|
+
const matcher = matchers[method2] || matchers["ALL"];
|
|
8517
8606
|
const staticMatch = matcher[2][path2];
|
|
8518
|
-
if (staticMatch)
|
|
8607
|
+
if (staticMatch)
|
|
8519
8608
|
return staticMatch;
|
|
8520
|
-
}
|
|
8521
8609
|
const match3 = path2.match(matcher[0]);
|
|
8522
|
-
if (!match3)
|
|
8610
|
+
if (!match3)
|
|
8523
8611
|
return [[], emptyParam];
|
|
8524
|
-
}
|
|
8525
8612
|
const index2 = match3.indexOf("", 1);
|
|
8526
8613
|
return [matcher[1][index2], match3];
|
|
8527
8614
|
};
|
|
@@ -8531,104 +8618,101 @@ function match(method, path) {
|
|
|
8531
8618
|
|
|
8532
8619
|
// node_modules/hono/dist/router/reg-exp-router/node.js
|
|
8533
8620
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
8534
|
-
var ONLY_WILDCARD_REG_EXP_STR = "
|
|
8535
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(
|
|
8536
|
-
var PATH_ERROR =
|
|
8537
|
-
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
8621
|
+
var ONLY_WILDCARD_REG_EXP_STR = "[^]*";
|
|
8622
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/[^]*)";
|
|
8623
|
+
var PATH_ERROR = Symbol();
|
|
8624
|
+
var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
8538
8625
|
function compareKey(a, b) {
|
|
8539
|
-
if (a.length === 1)
|
|
8626
|
+
if (a.length === 1)
|
|
8540
8627
|
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
8541
|
-
|
|
8542
|
-
if (b.length === 1) {
|
|
8543
|
-
return 1;
|
|
8544
|
-
}
|
|
8545
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
8628
|
+
if (b.length === 1)
|
|
8546
8629
|
return 1;
|
|
8547
|
-
|
|
8630
|
+
if (a === "[^]*" || a === "(?:|/[^]*)")
|
|
8631
|
+
return b === "[^]*" ? -1 : 1;
|
|
8632
|
+
else if (b === "[^]*" || b === "(?:|/[^]*)")
|
|
8548
8633
|
return -1;
|
|
8549
|
-
|
|
8550
|
-
if (a === LABEL_REG_EXP_STR) {
|
|
8634
|
+
if (a === "[^/]+")
|
|
8551
8635
|
return 1;
|
|
8552
|
-
|
|
8636
|
+
else if (b === "[^/]+")
|
|
8553
8637
|
return -1;
|
|
8554
|
-
}
|
|
8555
8638
|
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
8556
8639
|
}
|
|
8557
|
-
var Node = class
|
|
8640
|
+
var Node = class Node2 {
|
|
8558
8641
|
#index;
|
|
8559
8642
|
#varIndex;
|
|
8560
|
-
#children =
|
|
8561
|
-
insert(tokens, index2, paramMap, context,
|
|
8562
|
-
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8592
|
-
|
|
8593
|
-
|
|
8643
|
+
#children = createNullObject();
|
|
8644
|
+
insert(tokens, index2, paramMap, context, keys) {
|
|
8645
|
+
let node = this;
|
|
8646
|
+
for (let i = 0, len = tokens.length;i < len; i++) {
|
|
8647
|
+
const token = tokens[i];
|
|
8648
|
+
const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
|
|
8649
|
+
"",
|
|
8650
|
+
"",
|
|
8651
|
+
ONLY_WILDCARD_REG_EXP_STR
|
|
8652
|
+
] : [
|
|
8653
|
+
"",
|
|
8654
|
+
"",
|
|
8655
|
+
LABEL_REG_EXP_STR
|
|
8656
|
+
] : null : token === "/*" ? [
|
|
8657
|
+
"",
|
|
8658
|
+
"",
|
|
8659
|
+
TAIL_WILDCARD_REG_EXP_STR
|
|
8660
|
+
] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
8661
|
+
let nextNode;
|
|
8662
|
+
if (pattern) {
|
|
8663
|
+
const name = pattern[1];
|
|
8664
|
+
let regexpStr = pattern[2] || "[^/]+";
|
|
8665
|
+
if (name && pattern[2]) {
|
|
8666
|
+
if (new RegExp(regexpStr).test(""))
|
|
8667
|
+
throw PATH_ERROR;
|
|
8668
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
8669
|
+
if (/\((?!\?:)/.test(regexpStr))
|
|
8670
|
+
throw PATH_ERROR;
|
|
8671
|
+
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr))
|
|
8672
|
+
throw PATH_ERROR;
|
|
8673
|
+
}
|
|
8674
|
+
keys.push(regexpStr);
|
|
8675
|
+
nextNode = node.#children[regexpStr];
|
|
8676
|
+
if (!nextNode) {
|
|
8677
|
+
if (regexpStr !== "[^]*" && regexpStr !== "(?:|/[^]*)") {
|
|
8678
|
+
for (const k in node.#children)
|
|
8679
|
+
if ((regexpStr.length > 1 || k.length > 1) && k !== "[^]*" && k !== "(?:|/[^]*)")
|
|
8680
|
+
throw PATH_ERROR;
|
|
8681
|
+
}
|
|
8682
|
+
nextNode = node.#children[regexpStr] = new Node2;
|
|
8594
8683
|
}
|
|
8595
|
-
node = this.#children[regexpStr] = new _Node;
|
|
8596
8684
|
if (name !== "") {
|
|
8597
|
-
|
|
8685
|
+
nextNode.#varIndex ??= context.varIndex++;
|
|
8686
|
+
paramMap.push([name, nextNode.#varIndex]);
|
|
8598
8687
|
}
|
|
8599
|
-
}
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8604
|
-
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
throw PATH_ERROR;
|
|
8608
|
-
}
|
|
8609
|
-
if (pathErrorCheckOnly) {
|
|
8610
|
-
return;
|
|
8688
|
+
} else {
|
|
8689
|
+
keys.push(token);
|
|
8690
|
+
nextNode = node.#children[token];
|
|
8691
|
+
if (!nextNode) {
|
|
8692
|
+
for (const k in node.#children)
|
|
8693
|
+
if (k.length > 1 && k !== "[^]*" && k !== "(?:|/[^]*)")
|
|
8694
|
+
throw PATH_ERROR;
|
|
8695
|
+
nextNode = node.#children[token] = new Node2;
|
|
8611
8696
|
}
|
|
8612
|
-
node = this.#children[token] = new _Node;
|
|
8613
8697
|
}
|
|
8698
|
+
node = nextNode;
|
|
8614
8699
|
}
|
|
8615
|
-
node
|
|
8700
|
+
if (node.#index !== undefined)
|
|
8701
|
+
throw PATH_ERROR;
|
|
8702
|
+
node.#index = index2;
|
|
8616
8703
|
}
|
|
8617
8704
|
buildRegExpStr() {
|
|
8618
|
-
const
|
|
8619
|
-
const strList = childKeys.map((k) => {
|
|
8705
|
+
const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
|
|
8620
8706
|
const c = this.#children[k];
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8707
|
+
const childStr = c.buildRegExpStr();
|
|
8708
|
+
return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
|
|
8709
|
+
}).filter(Boolean);
|
|
8710
|
+
if (typeof this.#index === "number" && this.#index !== -1)
|
|
8624
8711
|
strList.unshift(`#${this.#index}`);
|
|
8625
|
-
|
|
8626
|
-
if (strList.length === 0) {
|
|
8712
|
+
if (strList.length === 0)
|
|
8627
8713
|
return "";
|
|
8628
|
-
|
|
8629
|
-
if (strList.length === 1) {
|
|
8714
|
+
if (strList.length === 1)
|
|
8630
8715
|
return strList[0];
|
|
8631
|
-
}
|
|
8632
8716
|
return "(?:" + strList.join("|") + ")";
|
|
8633
8717
|
}
|
|
8634
8718
|
};
|
|
@@ -8637,40 +8721,58 @@ var Node = class _Node {
|
|
|
8637
8721
|
var Trie = class {
|
|
8638
8722
|
#context = { varIndex: 0 };
|
|
8639
8723
|
#root = new Node;
|
|
8640
|
-
|
|
8724
|
+
#index = 0;
|
|
8725
|
+
paths = createNullObject();
|
|
8726
|
+
insert(path, isStatic) {
|
|
8727
|
+
const keys = [];
|
|
8728
|
+
if (isStatic) {
|
|
8729
|
+
this.#root.insert(path.split(""), -1, [], this.#context, keys);
|
|
8730
|
+
this.paths[path] = [
|
|
8731
|
+
-1,
|
|
8732
|
+
[],
|
|
8733
|
+
keys
|
|
8734
|
+
];
|
|
8735
|
+
return;
|
|
8736
|
+
}
|
|
8641
8737
|
const paramAssoc = [];
|
|
8642
8738
|
const groups = [];
|
|
8739
|
+
let markedPath = path;
|
|
8643
8740
|
for (let i = 0;; ) {
|
|
8644
8741
|
let replaced = false;
|
|
8645
|
-
|
|
8742
|
+
markedPath = markedPath.replace(/\{(?:\{[\d,]+\}|[^}])+\}/g, (m) => {
|
|
8646
8743
|
const mark = `@\\${i}`;
|
|
8647
8744
|
groups[i] = [mark, m];
|
|
8648
8745
|
i++;
|
|
8649
8746
|
replaced = true;
|
|
8650
8747
|
return mark;
|
|
8651
8748
|
});
|
|
8652
|
-
if (!replaced)
|
|
8749
|
+
if (!replaced)
|
|
8653
8750
|
break;
|
|
8654
|
-
}
|
|
8655
8751
|
}
|
|
8656
|
-
const tokens =
|
|
8752
|
+
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./gs) || [];
|
|
8657
8753
|
for (let i = groups.length - 1;i >= 0; i--) {
|
|
8658
8754
|
const [mark] = groups[i];
|
|
8659
|
-
for (let j = tokens.length - 1;j >= 0; j--)
|
|
8755
|
+
for (let j = tokens.length - 1;j >= 0; j--)
|
|
8660
8756
|
if (tokens[j].indexOf(mark) !== -1) {
|
|
8661
8757
|
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
8662
8758
|
break;
|
|
8663
8759
|
}
|
|
8664
|
-
}
|
|
8665
8760
|
}
|
|
8666
|
-
this.#root.insert(tokens,
|
|
8667
|
-
|
|
8761
|
+
this.#root.insert(tokens, this.#index, paramAssoc, this.#context, keys);
|
|
8762
|
+
this.paths[path] = [
|
|
8763
|
+
this.#index++,
|
|
8764
|
+
paramAssoc,
|
|
8765
|
+
keys
|
|
8766
|
+
];
|
|
8668
8767
|
}
|
|
8669
8768
|
buildRegExp() {
|
|
8670
8769
|
let regexp = this.#root.buildRegExpStr();
|
|
8671
|
-
if (regexp === "")
|
|
8672
|
-
return [
|
|
8673
|
-
|
|
8770
|
+
if (regexp === "")
|
|
8771
|
+
return [
|
|
8772
|
+
/^$/,
|
|
8773
|
+
[],
|
|
8774
|
+
[]
|
|
8775
|
+
];
|
|
8674
8776
|
let captureIndex = 0;
|
|
8675
8777
|
const indexReplacementMap = [];
|
|
8676
8778
|
const paramReplacementMap = [];
|
|
@@ -8685,247 +8787,107 @@ var Trie = class {
|
|
|
8685
8787
|
}
|
|
8686
8788
|
return "";
|
|
8687
8789
|
});
|
|
8688
|
-
return [
|
|
8790
|
+
return [
|
|
8791
|
+
new RegExp(`^${regexp}`),
|
|
8792
|
+
indexReplacementMap,
|
|
8793
|
+
paramReplacementMap
|
|
8794
|
+
];
|
|
8689
8795
|
}
|
|
8690
8796
|
};
|
|
8691
8797
|
|
|
8692
8798
|
// node_modules/hono/dist/router/reg-exp-router/router.js
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
const handlerData = [];
|
|
8704
|
-
if (routes.length === 0) {
|
|
8705
|
-
return nullMatcher;
|
|
8706
|
-
}
|
|
8707
|
-
const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
|
|
8708
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
8709
|
-
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length;i < len; i++) {
|
|
8710
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
8711
|
-
if (pathErrorCheckOnly) {
|
|
8712
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
8713
|
-
} else {
|
|
8714
|
-
j++;
|
|
8715
|
-
}
|
|
8716
|
-
let paramAssoc;
|
|
8717
|
-
try {
|
|
8718
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
8719
|
-
} catch (e) {
|
|
8720
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
8721
|
-
}
|
|
8722
|
-
if (pathErrorCheckOnly) {
|
|
8723
|
-
continue;
|
|
8724
|
-
}
|
|
8725
|
-
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
8726
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
8727
|
-
paramCount -= 1;
|
|
8728
|
-
for (;paramCount >= 0; paramCount--) {
|
|
8729
|
-
const [key, value] = paramAssoc[paramCount];
|
|
8730
|
-
paramIndexMap[key] = value;
|
|
8731
|
-
}
|
|
8732
|
-
return [h, paramIndexMap];
|
|
8733
|
-
});
|
|
8734
|
-
}
|
|
8735
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
8736
|
-
for (let i = 0, len = handlerData.length;i < len; i++) {
|
|
8737
|
-
for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
|
|
8738
|
-
const map = handlerData[i][j]?.[1];
|
|
8739
|
-
if (!map) {
|
|
8740
|
-
continue;
|
|
8741
|
-
}
|
|
8742
|
-
const keys = Object.keys(map);
|
|
8743
|
-
for (let k = 0, len3 = keys.length;k < len3; k++) {
|
|
8744
|
-
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
8745
|
-
}
|
|
8746
|
-
}
|
|
8747
|
-
}
|
|
8748
|
-
const handlerMap = [];
|
|
8749
|
-
for (const i in indexReplacementMap) {
|
|
8750
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
8751
|
-
}
|
|
8752
|
-
return [regexp, handlerMap, staticMap];
|
|
8753
|
-
}
|
|
8754
|
-
function findMiddleware(middleware, path) {
|
|
8755
|
-
if (!middleware) {
|
|
8756
|
-
return;
|
|
8757
|
-
}
|
|
8758
|
-
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
8759
|
-
if (buildWildcardRegExp(k).test(path)) {
|
|
8760
|
-
return [...middleware[k]];
|
|
8761
|
-
}
|
|
8762
|
-
}
|
|
8763
|
-
return;
|
|
8799
|
+
function endsWithWildcard(keys) {
|
|
8800
|
+
const tail = keys[keys.length - 1];
|
|
8801
|
+
return tail === "[^]*" || tail === "(?:|/[^]*)";
|
|
8802
|
+
}
|
|
8803
|
+
function covers(wildcard, target) {
|
|
8804
|
+
const last = wildcard.length - 1;
|
|
8805
|
+
for (let i = 0;i < last; i++)
|
|
8806
|
+
if (wildcard[i] !== target[i])
|
|
8807
|
+
return false;
|
|
8808
|
+
return wildcard[last] === "[^]*" || target.length === last || target[last] === "/";
|
|
8764
8809
|
}
|
|
8765
8810
|
var RegExpRouter = class {
|
|
8766
8811
|
name = "RegExpRouter";
|
|
8767
|
-
#
|
|
8768
|
-
#
|
|
8812
|
+
#handlers;
|
|
8813
|
+
#tries;
|
|
8769
8814
|
constructor() {
|
|
8770
|
-
this.#
|
|
8771
|
-
this.#
|
|
8815
|
+
this.#handlers = { ["ALL"]: [] };
|
|
8816
|
+
this.#tries = { ["ALL"]: new Trie };
|
|
8817
|
+
}
|
|
8818
|
+
#insertPath(method, path) {
|
|
8819
|
+
try {
|
|
8820
|
+
this.#tries[method].insert(path, !/\*|\/:/.test(path));
|
|
8821
|
+
} catch (e) {
|
|
8822
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
8823
|
+
}
|
|
8772
8824
|
}
|
|
8773
8825
|
add(method, path, handler) {
|
|
8774
|
-
const
|
|
8775
|
-
|
|
8776
|
-
if (!middleware || !routes) {
|
|
8826
|
+
const handlers = this.#handlers;
|
|
8827
|
+
if (!handlers)
|
|
8777
8828
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
8778
|
-
|
|
8779
|
-
if (!
|
|
8780
|
-
[
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
}
|
|
8787
|
-
if (path === "/*") {
|
|
8829
|
+
const tries = this.#tries;
|
|
8830
|
+
if (!handlers[method]) {
|
|
8831
|
+
tries[method] = new Trie;
|
|
8832
|
+
handlers[method] = [...handlers["ALL"]];
|
|
8833
|
+
for (const p in tries["ALL"].paths)
|
|
8834
|
+
this.#insertPath(method, p);
|
|
8835
|
+
}
|
|
8836
|
+
if (path === "/*")
|
|
8788
8837
|
path = "*";
|
|
8789
|
-
|
|
8790
|
-
const paramCount = (path.match(/\/:/g) || []).length;
|
|
8791
|
-
if (/\*$/.test(path)) {
|
|
8792
|
-
const re = buildWildcardRegExp(path);
|
|
8793
|
-
if (method === METHOD_NAME_ALL) {
|
|
8794
|
-
Object.keys(middleware).forEach((m) => {
|
|
8795
|
-
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
8796
|
-
});
|
|
8797
|
-
} else {
|
|
8798
|
-
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
8799
|
-
}
|
|
8800
|
-
Object.keys(middleware).forEach((m) => {
|
|
8801
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
8802
|
-
Object.keys(middleware[m]).forEach((p) => {
|
|
8803
|
-
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
8804
|
-
});
|
|
8805
|
-
}
|
|
8806
|
-
});
|
|
8807
|
-
Object.keys(routes).forEach((m) => {
|
|
8808
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
8809
|
-
Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
|
|
8810
|
-
}
|
|
8811
|
-
});
|
|
8812
|
-
return;
|
|
8813
|
-
}
|
|
8838
|
+
const methods = method === "ALL" ? Object.keys(handlers) : [method];
|
|
8814
8839
|
const paths = checkOptionalParameter(path) || [path];
|
|
8815
|
-
for (
|
|
8816
|
-
const
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
];
|
|
8822
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
8823
|
-
}
|
|
8824
|
-
});
|
|
8825
|
-
}
|
|
8840
|
+
for (const path2 of paths)
|
|
8841
|
+
for (const m of methods) {
|
|
8842
|
+
if (!tries[m].paths[path2])
|
|
8843
|
+
this.#insertPath(m, path2);
|
|
8844
|
+
handlers[m].push([handler, path2]);
|
|
8845
|
+
}
|
|
8826
8846
|
}
|
|
8827
8847
|
match = match;
|
|
8828
8848
|
buildAllMatchers() {
|
|
8829
|
-
const matchers =
|
|
8830
|
-
|
|
8831
|
-
matchers[method]
|
|
8832
|
-
|
|
8833
|
-
this.#middleware = this.#routes = undefined;
|
|
8834
|
-
clearWildcardRegExpCache();
|
|
8849
|
+
const matchers = createNullObject();
|
|
8850
|
+
for (const method of Object.keys(this.#handlers))
|
|
8851
|
+
matchers[method] = this.#buildMatcher(method);
|
|
8852
|
+
this.#handlers = this.#tries = undefined;
|
|
8835
8853
|
return matchers;
|
|
8836
8854
|
}
|
|
8837
8855
|
#buildMatcher(method) {
|
|
8838
|
-
const
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8856
|
+
const handlers = this.#handlers[method];
|
|
8857
|
+
const trie = this.#tries[method];
|
|
8858
|
+
const staticMap = createNullObject();
|
|
8859
|
+
const handlerData = [];
|
|
8860
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
8861
|
+
const own = createNullObject();
|
|
8862
|
+
const entries = handlers.map(([h, p], i) => {
|
|
8863
|
+
(own[p] ??= []).push(i);
|
|
8864
|
+
return [h, trie.paths[p][1].reduceRight((map, [key, varIndex]) => {
|
|
8865
|
+
map[key] = paramReplacementMap[varIndex];
|
|
8866
|
+
return map;
|
|
8867
|
+
}, createNullObject())];
|
|
8868
|
+
});
|
|
8869
|
+
const wildcards = Object.keys(own).filter((p) => endsWithWildcard(trie.paths[p][2]));
|
|
8870
|
+
for (const path in trie.paths) {
|
|
8871
|
+
const [index2, , keys] = trie.paths[path];
|
|
8872
|
+
const indexes = [...own[path]];
|
|
8873
|
+
for (const p of wildcards)
|
|
8874
|
+
if (p !== path && covers(trie.paths[p][2], keys))
|
|
8875
|
+
indexes.push(...own[p]);
|
|
8876
|
+
const data = indexes.sort((a, b) => a - b).map((i) => entries[i]);
|
|
8877
|
+
if (index2 === -1) {
|
|
8878
|
+
const last = Math.max(-1, ...data.flatMap(([, map]) => Object.values(map)));
|
|
8879
|
+
staticMap[path] = [data, last === -1 ? emptyParam : path.match(regexp).slice(0, last + 1)];
|
|
8880
|
+
} else
|
|
8881
|
+
handlerData[index2] = data;
|
|
8882
|
+
}
|
|
8883
|
+
return [
|
|
8884
|
+
regexp,
|
|
8885
|
+
indexReplacementMap.map((i) => handlerData[i]),
|
|
8886
|
+
staticMap
|
|
8887
|
+
];
|
|
8854
8888
|
}
|
|
8855
8889
|
};
|
|
8856
8890
|
|
|
8857
|
-
// node_modules/hono/dist/router/reg-exp-router/prepared-router.js
|
|
8858
|
-
var PreparedRegExpRouter = class {
|
|
8859
|
-
name = "PreparedRegExpRouter";
|
|
8860
|
-
#matchers;
|
|
8861
|
-
#relocateMap;
|
|
8862
|
-
constructor(matchers, relocateMap) {
|
|
8863
|
-
this.#matchers = matchers;
|
|
8864
|
-
this.#relocateMap = relocateMap;
|
|
8865
|
-
}
|
|
8866
|
-
#addWildcard(method, handlerData) {
|
|
8867
|
-
const matcher = this.#matchers[method];
|
|
8868
|
-
matcher[1].forEach((list) => list && list.push(handlerData));
|
|
8869
|
-
Object.values(matcher[2]).forEach((list) => list[0].push(handlerData));
|
|
8870
|
-
}
|
|
8871
|
-
#addPath(method, path, handler, indexes, map) {
|
|
8872
|
-
const matcher = this.#matchers[method];
|
|
8873
|
-
if (!map) {
|
|
8874
|
-
matcher[2][path][0].push([handler, {}]);
|
|
8875
|
-
} else {
|
|
8876
|
-
indexes.forEach((index2) => {
|
|
8877
|
-
if (typeof index2 === "number") {
|
|
8878
|
-
matcher[1][index2].push([handler, map]);
|
|
8879
|
-
} else {
|
|
8880
|
-
matcher[2][index2 || path][0].push([handler, map]);
|
|
8881
|
-
}
|
|
8882
|
-
});
|
|
8883
|
-
}
|
|
8884
|
-
}
|
|
8885
|
-
add(method, path, handler) {
|
|
8886
|
-
if (!this.#matchers[method]) {
|
|
8887
|
-
const all = this.#matchers[METHOD_NAME_ALL];
|
|
8888
|
-
const staticMap = {};
|
|
8889
|
-
for (const key in all[2]) {
|
|
8890
|
-
staticMap[key] = [all[2][key][0].slice(), emptyParam];
|
|
8891
|
-
}
|
|
8892
|
-
this.#matchers[method] = [
|
|
8893
|
-
all[0],
|
|
8894
|
-
all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
|
|
8895
|
-
staticMap
|
|
8896
|
-
];
|
|
8897
|
-
}
|
|
8898
|
-
if (path === "/*" || path === "*") {
|
|
8899
|
-
const handlerData = [handler, {}];
|
|
8900
|
-
if (method === METHOD_NAME_ALL) {
|
|
8901
|
-
for (const m in this.#matchers) {
|
|
8902
|
-
this.#addWildcard(m, handlerData);
|
|
8903
|
-
}
|
|
8904
|
-
} else {
|
|
8905
|
-
this.#addWildcard(method, handlerData);
|
|
8906
|
-
}
|
|
8907
|
-
return;
|
|
8908
|
-
}
|
|
8909
|
-
const data = this.#relocateMap[path];
|
|
8910
|
-
if (!data) {
|
|
8911
|
-
throw new Error(`Path ${path} is not registered`);
|
|
8912
|
-
}
|
|
8913
|
-
for (const [indexes, map] of data) {
|
|
8914
|
-
if (method === METHOD_NAME_ALL) {
|
|
8915
|
-
for (const m in this.#matchers) {
|
|
8916
|
-
this.#addPath(m, path, handler, indexes, map);
|
|
8917
|
-
}
|
|
8918
|
-
} else {
|
|
8919
|
-
this.#addPath(method, path, handler, indexes, map);
|
|
8920
|
-
}
|
|
8921
|
-
}
|
|
8922
|
-
}
|
|
8923
|
-
buildAllMatchers() {
|
|
8924
|
-
return this.#matchers;
|
|
8925
|
-
}
|
|
8926
|
-
match = match;
|
|
8927
|
-
};
|
|
8928
|
-
|
|
8929
8891
|
// node_modules/hono/dist/router/smart-router/router.js
|
|
8930
8892
|
var SmartRouter = class {
|
|
8931
8893
|
name = "SmartRouter";
|
|
@@ -8935,15 +8897,17 @@ var SmartRouter = class {
|
|
|
8935
8897
|
this.#routers = init.routers;
|
|
8936
8898
|
}
|
|
8937
8899
|
add(method, path, handler) {
|
|
8938
|
-
if (!this.#routes)
|
|
8900
|
+
if (!this.#routes)
|
|
8939
8901
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
8940
|
-
|
|
8941
|
-
|
|
8902
|
+
this.#routes.push([
|
|
8903
|
+
method,
|
|
8904
|
+
path,
|
|
8905
|
+
handler
|
|
8906
|
+
]);
|
|
8942
8907
|
}
|
|
8943
8908
|
match(method, path) {
|
|
8944
|
-
if (!this.#routes)
|
|
8909
|
+
if (!this.#routes)
|
|
8945
8910
|
throw new Error("Fatal error");
|
|
8946
|
-
}
|
|
8947
8911
|
const routers = this.#routers;
|
|
8948
8912
|
const routes = this.#routes;
|
|
8949
8913
|
const len = routers.length;
|
|
@@ -8952,14 +8916,12 @@ var SmartRouter = class {
|
|
|
8952
8916
|
for (;i < len; i++) {
|
|
8953
8917
|
const router = routers[i];
|
|
8954
8918
|
try {
|
|
8955
|
-
for (let i2 = 0, len2 = routes.length;i2 < len2; i2++)
|
|
8919
|
+
for (let i2 = 0, len2 = routes.length;i2 < len2; i2++)
|
|
8956
8920
|
router.add(...routes[i2]);
|
|
8957
|
-
}
|
|
8958
8921
|
res = router.match(method, path);
|
|
8959
8922
|
} catch (e) {
|
|
8960
|
-
if (e instanceof UnsupportedPathError)
|
|
8923
|
+
if (e instanceof UnsupportedPathError)
|
|
8961
8924
|
continue;
|
|
8962
|
-
}
|
|
8963
8925
|
throw e;
|
|
8964
8926
|
}
|
|
8965
8927
|
this.match = router.match.bind(router);
|
|
@@ -8967,92 +8929,62 @@ var SmartRouter = class {
|
|
|
8967
8929
|
this.#routes = undefined;
|
|
8968
8930
|
break;
|
|
8969
8931
|
}
|
|
8970
|
-
if (i === len)
|
|
8932
|
+
if (i === len)
|
|
8971
8933
|
throw new Error("Fatal error");
|
|
8972
|
-
}
|
|
8973
8934
|
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
8974
8935
|
return res;
|
|
8975
8936
|
}
|
|
8976
8937
|
get activeRouter() {
|
|
8977
|
-
if (this.#routes || this.#routers.length !== 1)
|
|
8938
|
+
if (this.#routes || this.#routers.length !== 1)
|
|
8978
8939
|
throw new Error("No active router has been determined yet.");
|
|
8979
|
-
}
|
|
8980
8940
|
return this.#routers[0];
|
|
8981
8941
|
}
|
|
8982
8942
|
};
|
|
8983
8943
|
|
|
8984
8944
|
// node_modules/hono/dist/router/trie-router/node.js
|
|
8985
|
-
var emptyParams =
|
|
8986
|
-
var
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
var Node2 = class _Node2 {
|
|
8993
|
-
#methods;
|
|
8994
|
-
#children;
|
|
8995
|
-
#patterns;
|
|
8996
|
-
#order = 0;
|
|
8945
|
+
var emptyParams = createNullObject();
|
|
8946
|
+
var order = 0;
|
|
8947
|
+
var Node3 = class Node4 {
|
|
8948
|
+
#methods = [];
|
|
8949
|
+
#children = createNullObject();
|
|
8950
|
+
#patterns = [];
|
|
8951
|
+
#pattern;
|
|
8997
8952
|
#params = emptyParams;
|
|
8998
|
-
constructor(method, handler, children) {
|
|
8999
|
-
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
9000
|
-
this.#methods = [];
|
|
9001
|
-
if (method && handler) {
|
|
9002
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
9003
|
-
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
9004
|
-
this.#methods = [m];
|
|
9005
|
-
}
|
|
9006
|
-
this.#patterns = [];
|
|
9007
|
-
}
|
|
9008
8953
|
insert(method, path, handler) {
|
|
9009
|
-
this.#order = ++this.#order;
|
|
9010
8954
|
let curNode = this;
|
|
9011
8955
|
const parts = splitRoutingPath(path);
|
|
9012
|
-
const possibleKeys =
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
const nextP = parts[i
|
|
9016
|
-
const pattern = getPattern(p, nextP);
|
|
9017
|
-
const
|
|
9018
|
-
|
|
9019
|
-
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
[method]: {
|
|
9034
|
-
handler,
|
|
9035
|
-
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
9036
|
-
score: this.#order
|
|
9037
|
-
}
|
|
9038
|
-
});
|
|
9039
|
-
return curNode;
|
|
8956
|
+
const possibleKeys = /* @__PURE__ */ new Set;
|
|
8957
|
+
let i = 0;
|
|
8958
|
+
for (const p of parts) {
|
|
8959
|
+
const nextP = parts[++i];
|
|
8960
|
+
const pattern = getPattern(p, nextP) || (nextP === undefined && p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
8961
|
+
const isParam = Array.isArray(pattern);
|
|
8962
|
+
const key = isParam ? pattern[0] : pattern || p;
|
|
8963
|
+
const child = curNode.#children[key] ||= new Node4;
|
|
8964
|
+
if (pattern && !child.#pattern) {
|
|
8965
|
+
child.#pattern = pattern;
|
|
8966
|
+
curNode.#patterns.push(child);
|
|
8967
|
+
}
|
|
8968
|
+
curNode = child;
|
|
8969
|
+
if (isParam)
|
|
8970
|
+
possibleKeys.add(pattern[1]);
|
|
8971
|
+
}
|
|
8972
|
+
curNode.#methods.push({ [method]: {
|
|
8973
|
+
handler,
|
|
8974
|
+
possibleKeys: [...possibleKeys],
|
|
8975
|
+
score: ++order
|
|
8976
|
+
} });
|
|
9040
8977
|
}
|
|
9041
8978
|
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
9042
8979
|
for (let i = 0, len = node.#methods.length;i < len; i++) {
|
|
9043
8980
|
const m = node.#methods[i];
|
|
9044
|
-
const handlerSet = m[method] || m[
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
8981
|
+
const handlerSet = m[method] || m["ALL"];
|
|
8982
|
+
if (handlerSet) {
|
|
8983
|
+
handlerSet.params = createNullObject();
|
|
9048
8984
|
handlerSets.push(handlerSet);
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
const processed = processedSet[handlerSet.score];
|
|
9053
|
-
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
9054
|
-
processedSet[handlerSet.score] = true;
|
|
9055
|
-
}
|
|
8985
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length;i2 < len2; i2++) {
|
|
8986
|
+
const key = handlerSet.possibleKeys[i2];
|
|
8987
|
+
handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
|
|
9056
8988
|
}
|
|
9057
8989
|
}
|
|
9058
8990
|
}
|
|
@@ -9060,8 +8992,7 @@ var Node2 = class _Node2 {
|
|
|
9060
8992
|
search(method, path) {
|
|
9061
8993
|
const handlerSets = [];
|
|
9062
8994
|
this.#params = emptyParams;
|
|
9063
|
-
|
|
9064
|
-
let curNodes = [curNode];
|
|
8995
|
+
let curNodes = [this];
|
|
9065
8996
|
const parts = splitPath2(path);
|
|
9066
8997
|
const curNodesQueue = [];
|
|
9067
8998
|
const len = parts.length;
|
|
@@ -9076,61 +9007,61 @@ var Node2 = class _Node2 {
|
|
|
9076
9007
|
if (nextNode) {
|
|
9077
9008
|
nextNode.#params = node.#params;
|
|
9078
9009
|
if (isLast) {
|
|
9079
|
-
if (nextNode.#children["*"])
|
|
9010
|
+
if (nextNode.#children["*"])
|
|
9080
9011
|
this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
|
9081
|
-
}
|
|
9082
9012
|
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
|
9083
|
-
} else
|
|
9013
|
+
} else
|
|
9084
9014
|
tempNodes.push(nextNode);
|
|
9085
|
-
}
|
|
9086
9015
|
}
|
|
9087
|
-
for (
|
|
9088
|
-
const pattern =
|
|
9016
|
+
for (const child of node.#patterns) {
|
|
9017
|
+
const pattern = child.#pattern;
|
|
9089
9018
|
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
9090
|
-
if (pattern === "
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9019
|
+
if (typeof pattern === "string") {
|
|
9020
|
+
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
9021
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
9022
|
+
if (pattern === "*") {
|
|
9023
|
+
child.#params = params;
|
|
9024
|
+
tempNodes.push(child);
|
|
9025
|
+
}
|
|
9096
9026
|
}
|
|
9097
9027
|
continue;
|
|
9098
9028
|
}
|
|
9099
|
-
const [
|
|
9100
|
-
if (!part &&
|
|
9029
|
+
const [, name, matcher] = pattern;
|
|
9030
|
+
if (!part && matcher === true)
|
|
9101
9031
|
continue;
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
if (partOffsets === null) {
|
|
9106
|
-
partOffsets = new Array(len);
|
|
9032
|
+
if (matcher !== true) {
|
|
9033
|
+
if (!partOffsets) {
|
|
9034
|
+
partOffsets = [];
|
|
9107
9035
|
let offset = path[0] === "/" ? 1 : 0;
|
|
9108
9036
|
for (let p = 0;p < len; p++) {
|
|
9109
9037
|
partOffsets[p] = offset;
|
|
9110
9038
|
offset += parts[p].length + 1;
|
|
9111
9039
|
}
|
|
9112
9040
|
}
|
|
9113
|
-
const restPathString = path.
|
|
9041
|
+
const restPathString = path.slice(partOffsets[i]);
|
|
9114
9042
|
const m = matcher.exec(restPathString);
|
|
9115
9043
|
if (m) {
|
|
9116
|
-
params
|
|
9044
|
+
if (!Object.hasOwn(params, name))
|
|
9045
|
+
params[name] = m[0];
|
|
9117
9046
|
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
9118
|
-
if (
|
|
9047
|
+
if (m[0].length === restPathString.length && child.#children["*"])
|
|
9048
|
+
this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
|
|
9049
|
+
for (const _ in child.#children) {
|
|
9119
9050
|
child.#params = params;
|
|
9120
|
-
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
9121
|
-
|
|
9122
|
-
|
|
9051
|
+
const componentCount = m[0].match(/\//g)?.length ?? 0;
|
|
9052
|
+
(curNodesQueue[componentCount] ||= []).push(child);
|
|
9053
|
+
break;
|
|
9123
9054
|
}
|
|
9124
9055
|
continue;
|
|
9125
9056
|
}
|
|
9126
9057
|
}
|
|
9127
9058
|
if (matcher === true || matcher.test(part)) {
|
|
9128
|
-
params
|
|
9059
|
+
if (!Object.hasOwn(params, name))
|
|
9060
|
+
params[name] = part;
|
|
9129
9061
|
if (isLast) {
|
|
9130
9062
|
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
|
9131
|
-
if (child.#children["*"])
|
|
9063
|
+
if (child.#children["*"])
|
|
9132
9064
|
this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
|
|
9133
|
-
}
|
|
9134
9065
|
} else {
|
|
9135
9066
|
child.#params = params;
|
|
9136
9067
|
tempNodes.push(child);
|
|
@@ -9141,11 +9072,10 @@ var Node2 = class _Node2 {
|
|
|
9141
9072
|
const shifted = curNodesQueue.shift();
|
|
9142
9073
|
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
9143
9074
|
}
|
|
9144
|
-
if (handlerSets
|
|
9075
|
+
if (handlerSets[1])
|
|
9145
9076
|
handlerSets.sort((a, b) => {
|
|
9146
9077
|
return a.score - b.score;
|
|
9147
9078
|
});
|
|
9148
|
-
}
|
|
9149
9079
|
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
9150
9080
|
}
|
|
9151
9081
|
};
|
|
@@ -9153,19 +9083,10 @@ var Node2 = class _Node2 {
|
|
|
9153
9083
|
// node_modules/hono/dist/router/trie-router/router.js
|
|
9154
9084
|
var TrieRouter = class {
|
|
9155
9085
|
name = "TrieRouter";
|
|
9156
|
-
#node;
|
|
9157
|
-
constructor() {
|
|
9158
|
-
this.#node = new Node2;
|
|
9159
|
-
}
|
|
9086
|
+
#node = new Node3;
|
|
9160
9087
|
add(method, path, handler) {
|
|
9161
|
-
const
|
|
9162
|
-
|
|
9163
|
-
for (let i = 0, len = results.length;i < len; i++) {
|
|
9164
|
-
this.#node.insert(method, results[i], handler);
|
|
9165
|
-
}
|
|
9166
|
-
return;
|
|
9167
|
-
}
|
|
9168
|
-
this.#node.insert(method, path, handler);
|
|
9088
|
+
for (const result of checkOptionalParameter(path) || [path])
|
|
9089
|
+
this.#node.insert(method, result, handler);
|
|
9169
9090
|
}
|
|
9170
9091
|
match(method, path) {
|
|
9171
9092
|
return this.#node.search(method, path);
|
|
@@ -9173,12 +9094,10 @@ var TrieRouter = class {
|
|
|
9173
9094
|
};
|
|
9174
9095
|
|
|
9175
9096
|
// node_modules/hono/dist/hono.js
|
|
9176
|
-
var
|
|
9097
|
+
var Hono3 = class extends Hono {
|
|
9177
9098
|
constructor(options = {}) {
|
|
9178
9099
|
super(options);
|
|
9179
|
-
this.router = options.router ?? new SmartRouter({
|
|
9180
|
-
routers: [new RegExpRouter, new TrieRouter]
|
|
9181
|
-
});
|
|
9100
|
+
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter, new TrieRouter] });
|
|
9182
9101
|
}
|
|
9183
9102
|
};
|
|
9184
9103
|
|
|
@@ -11730,7 +11649,7 @@ function constantTimeEquals(a2, b2) {
|
|
|
11730
11649
|
|
|
11731
11650
|
// src/features/admin/endpoints.ts
|
|
11732
11651
|
function adminRouter(deps) {
|
|
11733
|
-
const app = new
|
|
11652
|
+
const app = new Hono3;
|
|
11734
11653
|
app.get("/health", (ctx) => ctx.json({ status: "ok" }));
|
|
11735
11654
|
app.get("/ready", (ctx) => {
|
|
11736
11655
|
const ready = deps.ready.current();
|
|
@@ -13333,7 +13252,7 @@ function createServer(opts) {
|
|
|
13333
13252
|
const clock = createClock({ deterministic: opts.deterministic ?? false });
|
|
13334
13253
|
const handlerTimeoutMs = opts.handlerTimeoutMs ?? 5000;
|
|
13335
13254
|
const genRequestId = createRequestIdGenerator(opts.deterministic ?? false);
|
|
13336
|
-
const app = new
|
|
13255
|
+
const app = new Hono3;
|
|
13337
13256
|
const replayWebhook = (tenant, deliveryId) => {
|
|
13338
13257
|
const snap = opts.holder.get();
|
|
13339
13258
|
const tenantSnap = snap.tenants.get(tenant);
|
|
@@ -15083,7 +15002,7 @@ async function appendStep(path, step) {
|
|
|
15083
15002
|
action: full.action,
|
|
15084
15003
|
reverseCommand: full.reverseCommand
|
|
15085
15004
|
});
|
|
15086
|
-
const withChecksum = { ...full, checksum:
|
|
15005
|
+
const withChecksum = { ...full, checksum: sha2562(payload) };
|
|
15087
15006
|
const line = `${JSON.stringify(withChecksum)}
|
|
15088
15007
|
`;
|
|
15089
15008
|
await appendFile2(path, line, { encoding: "utf8" });
|
|
@@ -15220,7 +15139,7 @@ async function readAll(path) {
|
|
|
15220
15139
|
action: parsed.action,
|
|
15221
15140
|
reverseCommand: parsed.reverseCommand
|
|
15222
15141
|
});
|
|
15223
|
-
const expected =
|
|
15142
|
+
const expected = sha2562(payload);
|
|
15224
15143
|
if (expected !== parsed.checksum) {
|
|
15225
15144
|
throw new ProxyError(`Install journal corruption: checksum mismatch at step ${parsed.step}`, "journal_checksum_mismatch", "Manual recovery: see docs/PROXY-RECOVERY.md");
|
|
15226
15145
|
}
|
|
@@ -15228,7 +15147,7 @@ async function readAll(path) {
|
|
|
15228
15147
|
}
|
|
15229
15148
|
return out;
|
|
15230
15149
|
}
|
|
15231
|
-
function
|
|
15150
|
+
function sha2562(s2) {
|
|
15232
15151
|
return createHash("sha256").update(s2, "utf8").digest("hex");
|
|
15233
15152
|
}
|
|
15234
15153
|
|
|
@@ -15522,7 +15441,7 @@ function proxyHelp() {
|
|
|
15522
15441
|
}
|
|
15523
15442
|
|
|
15524
15443
|
// src/version.ts
|
|
15525
|
-
var MOCKSTAR_VERSION = "0.4.
|
|
15444
|
+
var MOCKSTAR_VERSION = "0.4.1";
|
|
15526
15445
|
|
|
15527
15446
|
// src/cli.ts
|
|
15528
15447
|
function parseArgs(argv) {
|