deep-roon-mcp 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/THIRD_PARTY_LICENSES.txt +76 -0
- package/dist/deep-roon-mcp.js +2656 -332
- package/package.json +1 -1
package/dist/deep-roon-mcp.js
CHANGED
|
@@ -459,11 +459,11 @@ var require_codegen = __commonJS({
|
|
|
459
459
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
460
460
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
461
461
|
}
|
|
462
|
-
optimizeNames(names2,
|
|
462
|
+
optimizeNames(names2, constants2) {
|
|
463
463
|
if (!names2[this.name.str])
|
|
464
464
|
return;
|
|
465
465
|
if (this.rhs)
|
|
466
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
466
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants2);
|
|
467
467
|
return this;
|
|
468
468
|
}
|
|
469
469
|
get names() {
|
|
@@ -483,10 +483,10 @@ var require_codegen = __commonJS({
|
|
|
483
483
|
render({ _n }) {
|
|
484
484
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
485
485
|
}
|
|
486
|
-
optimizeNames(names2,
|
|
486
|
+
optimizeNames(names2, constants2) {
|
|
487
487
|
if (this.lhs instanceof code_1.Name && !names2[this.lhs.str] && !this.sideEffects)
|
|
488
488
|
return;
|
|
489
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
489
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants2);
|
|
490
490
|
return this;
|
|
491
491
|
}
|
|
492
492
|
get names() {
|
|
@@ -562,8 +562,8 @@ var require_codegen = __commonJS({
|
|
|
562
562
|
optimizeNodes() {
|
|
563
563
|
return `${this.code}` ? this : void 0;
|
|
564
564
|
}
|
|
565
|
-
optimizeNames(names2,
|
|
566
|
-
this.code = optimizeExpr(this.code, names2,
|
|
565
|
+
optimizeNames(names2, constants2) {
|
|
566
|
+
this.code = optimizeExpr(this.code, names2, constants2);
|
|
567
567
|
return this;
|
|
568
568
|
}
|
|
569
569
|
get names() {
|
|
@@ -595,12 +595,12 @@ var require_codegen = __commonJS({
|
|
|
595
595
|
}
|
|
596
596
|
return nodes.length > 0 ? this : void 0;
|
|
597
597
|
}
|
|
598
|
-
optimizeNames(names2,
|
|
598
|
+
optimizeNames(names2, constants2) {
|
|
599
599
|
const { nodes } = this;
|
|
600
600
|
let i = nodes.length;
|
|
601
601
|
while (i--) {
|
|
602
602
|
const n = nodes[i];
|
|
603
|
-
if (n.optimizeNames(names2,
|
|
603
|
+
if (n.optimizeNames(names2, constants2))
|
|
604
604
|
continue;
|
|
605
605
|
subtractNames(names2, n.names);
|
|
606
606
|
nodes.splice(i, 1);
|
|
@@ -665,12 +665,12 @@ var require_codegen = __commonJS({
|
|
|
665
665
|
return void 0;
|
|
666
666
|
return this;
|
|
667
667
|
}
|
|
668
|
-
optimizeNames(names2,
|
|
668
|
+
optimizeNames(names2, constants2) {
|
|
669
669
|
var _a3;
|
|
670
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
671
|
-
if (!(super.optimizeNames(names2,
|
|
670
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
|
|
671
|
+
if (!(super.optimizeNames(names2, constants2) || this.else))
|
|
672
672
|
return;
|
|
673
|
-
this.condition = optimizeExpr(this.condition, names2,
|
|
673
|
+
this.condition = optimizeExpr(this.condition, names2, constants2);
|
|
674
674
|
return this;
|
|
675
675
|
}
|
|
676
676
|
get names() {
|
|
@@ -699,10 +699,10 @@ var require_codegen = __commonJS({
|
|
|
699
699
|
render(opts) {
|
|
700
700
|
return `for(${this.iteration})` + super.render(opts);
|
|
701
701
|
}
|
|
702
|
-
optimizeNames(names2,
|
|
703
|
-
if (!super.optimizeNames(names2,
|
|
702
|
+
optimizeNames(names2, constants2) {
|
|
703
|
+
if (!super.optimizeNames(names2, constants2))
|
|
704
704
|
return;
|
|
705
|
-
this.iteration = optimizeExpr(this.iteration, names2,
|
|
705
|
+
this.iteration = optimizeExpr(this.iteration, names2, constants2);
|
|
706
706
|
return this;
|
|
707
707
|
}
|
|
708
708
|
get names() {
|
|
@@ -744,10 +744,10 @@ var require_codegen = __commonJS({
|
|
|
744
744
|
render(opts) {
|
|
745
745
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
746
746
|
}
|
|
747
|
-
optimizeNames(names2,
|
|
748
|
-
if (!super.optimizeNames(names2,
|
|
747
|
+
optimizeNames(names2, constants2) {
|
|
748
|
+
if (!super.optimizeNames(names2, constants2))
|
|
749
749
|
return;
|
|
750
|
-
this.iterable = optimizeExpr(this.iterable, names2,
|
|
750
|
+
this.iterable = optimizeExpr(this.iterable, names2, constants2);
|
|
751
751
|
return this;
|
|
752
752
|
}
|
|
753
753
|
get names() {
|
|
@@ -798,11 +798,11 @@ var require_codegen = __commonJS({
|
|
|
798
798
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
799
799
|
return this;
|
|
800
800
|
}
|
|
801
|
-
optimizeNames(names2,
|
|
801
|
+
optimizeNames(names2, constants2) {
|
|
802
802
|
var _a3, _b;
|
|
803
|
-
super.optimizeNames(names2,
|
|
804
|
-
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
805
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2,
|
|
803
|
+
super.optimizeNames(names2, constants2);
|
|
804
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants2);
|
|
805
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants2);
|
|
806
806
|
return this;
|
|
807
807
|
}
|
|
808
808
|
get names() {
|
|
@@ -1114,7 +1114,7 @@ var require_codegen = __commonJS({
|
|
|
1114
1114
|
return from instanceof code_1._CodeOrName ? addNames(names2, from.names) : names2;
|
|
1115
1115
|
}
|
|
1116
1116
|
__name(addExprNames, "addExprNames");
|
|
1117
|
-
function optimizeExpr(expr, names2,
|
|
1117
|
+
function optimizeExpr(expr, names2, constants2) {
|
|
1118
1118
|
if (expr instanceof code_1.Name)
|
|
1119
1119
|
return replaceName(expr);
|
|
1120
1120
|
if (!canOptimize(expr))
|
|
@@ -1129,7 +1129,7 @@ var require_codegen = __commonJS({
|
|
|
1129
1129
|
return items2;
|
|
1130
1130
|
}, []));
|
|
1131
1131
|
function replaceName(n) {
|
|
1132
|
-
const c =
|
|
1132
|
+
const c = constants2[n.str];
|
|
1133
1133
|
if (c === void 0 || names2[n.str] !== 1)
|
|
1134
1134
|
return n;
|
|
1135
1135
|
delete names2[n.str];
|
|
@@ -1137,7 +1137,7 @@ var require_codegen = __commonJS({
|
|
|
1137
1137
|
}
|
|
1138
1138
|
__name(replaceName, "replaceName");
|
|
1139
1139
|
function canOptimize(e) {
|
|
1140
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 &&
|
|
1140
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 && constants2[c.str] !== void 0);
|
|
1141
1141
|
}
|
|
1142
1142
|
__name(canOptimize, "canOptimize");
|
|
1143
1143
|
}
|
|
@@ -4036,7 +4036,7 @@ var require_schemes = __commonJS({
|
|
|
4036
4036
|
return urnComponent;
|
|
4037
4037
|
}
|
|
4038
4038
|
__name(urnuuidSerialize, "urnuuidSerialize");
|
|
4039
|
-
var
|
|
4039
|
+
var http2 = (
|
|
4040
4040
|
/** @type {SchemeHandler} */
|
|
4041
4041
|
{
|
|
4042
4042
|
scheme: "http",
|
|
@@ -4049,7 +4049,7 @@ var require_schemes = __commonJS({
|
|
|
4049
4049
|
/** @type {SchemeHandler} */
|
|
4050
4050
|
{
|
|
4051
4051
|
scheme: "https",
|
|
4052
|
-
domainHost:
|
|
4052
|
+
domainHost: http2.domainHost,
|
|
4053
4053
|
parse: httpParse,
|
|
4054
4054
|
serialize: httpSerialize
|
|
4055
4055
|
}
|
|
@@ -4093,7 +4093,7 @@ var require_schemes = __commonJS({
|
|
|
4093
4093
|
var SCHEMES = (
|
|
4094
4094
|
/** @type {Record<SchemeName, SchemeHandler>} */
|
|
4095
4095
|
{
|
|
4096
|
-
http,
|
|
4096
|
+
http: http2,
|
|
4097
4097
|
https,
|
|
4098
4098
|
ws,
|
|
4099
4099
|
wss,
|
|
@@ -4879,8 +4879,8 @@ var require_core = __commonJS({
|
|
|
4879
4879
|
return this;
|
|
4880
4880
|
}
|
|
4881
4881
|
case "object": {
|
|
4882
|
-
const
|
|
4883
|
-
this._cache.delete(
|
|
4882
|
+
const cacheKey2 = schemaKeyRef;
|
|
4883
|
+
this._cache.delete(cacheKey2);
|
|
4884
4884
|
let id = schemaKeyRef[this.opts.schemaId];
|
|
4885
4885
|
if (id) {
|
|
4886
4886
|
id = (0, resolve_1.normalizeId)(id);
|
|
@@ -5340,7 +5340,7 @@ var require_core2 = __commonJS({
|
|
|
5340
5340
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5341
5341
|
var id_1 = require_id();
|
|
5342
5342
|
var ref_1 = require_ref();
|
|
5343
|
-
var
|
|
5343
|
+
var core2 = [
|
|
5344
5344
|
"$schema",
|
|
5345
5345
|
"$id",
|
|
5346
5346
|
"$defs",
|
|
@@ -5350,7 +5350,7 @@ var require_core2 = __commonJS({
|
|
|
5350
5350
|
id_1.default,
|
|
5351
5351
|
ref_1.default
|
|
5352
5352
|
];
|
|
5353
|
-
exports2.default =
|
|
5353
|
+
exports2.default = core2;
|
|
5354
5354
|
}
|
|
5355
5355
|
});
|
|
5356
5356
|
|
|
@@ -7624,13 +7624,122 @@ var require_dist = __commonJS({
|
|
|
7624
7624
|
}
|
|
7625
7625
|
});
|
|
7626
7626
|
|
|
7627
|
+
// node_modules/content-type/index.js
|
|
7628
|
+
var require_content_type = __commonJS({
|
|
7629
|
+
"node_modules/content-type/index.js"(exports2) {
|
|
7630
|
+
"use strict";
|
|
7631
|
+
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
|
|
7632
|
+
var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
|
|
7633
|
+
var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7634
|
+
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
|
|
7635
|
+
var QUOTE_REGEXP = /([\\"])/g;
|
|
7636
|
+
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7637
|
+
exports2.format = format;
|
|
7638
|
+
exports2.parse = parse4;
|
|
7639
|
+
function format(obj2) {
|
|
7640
|
+
if (!obj2 || typeof obj2 !== "object") {
|
|
7641
|
+
throw new TypeError("argument obj is required");
|
|
7642
|
+
}
|
|
7643
|
+
var parameters = obj2.parameters;
|
|
7644
|
+
var type = obj2.type;
|
|
7645
|
+
if (!type || !TYPE_REGEXP.test(type)) {
|
|
7646
|
+
throw new TypeError("invalid type");
|
|
7647
|
+
}
|
|
7648
|
+
var string4 = type;
|
|
7649
|
+
if (parameters && typeof parameters === "object") {
|
|
7650
|
+
var param;
|
|
7651
|
+
var params = Object.keys(parameters).sort();
|
|
7652
|
+
for (var i = 0; i < params.length; i++) {
|
|
7653
|
+
param = params[i];
|
|
7654
|
+
if (!TOKEN_REGEXP.test(param)) {
|
|
7655
|
+
throw new TypeError("invalid parameter name");
|
|
7656
|
+
}
|
|
7657
|
+
string4 += "; " + param + "=" + qstring(parameters[param]);
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7660
|
+
return string4;
|
|
7661
|
+
}
|
|
7662
|
+
__name(format, "format");
|
|
7663
|
+
function parse4(string4) {
|
|
7664
|
+
if (!string4) {
|
|
7665
|
+
throw new TypeError("argument string is required");
|
|
7666
|
+
}
|
|
7667
|
+
var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
|
|
7668
|
+
if (typeof header !== "string") {
|
|
7669
|
+
throw new TypeError("argument string is required to be a string");
|
|
7670
|
+
}
|
|
7671
|
+
var index = header.indexOf(";");
|
|
7672
|
+
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
7673
|
+
if (!TYPE_REGEXP.test(type)) {
|
|
7674
|
+
throw new TypeError("invalid media type");
|
|
7675
|
+
}
|
|
7676
|
+
var obj2 = new ContentType(type.toLowerCase());
|
|
7677
|
+
if (index !== -1) {
|
|
7678
|
+
var key;
|
|
7679
|
+
var match;
|
|
7680
|
+
var value;
|
|
7681
|
+
PARAM_REGEXP.lastIndex = index;
|
|
7682
|
+
while (match = PARAM_REGEXP.exec(header)) {
|
|
7683
|
+
if (match.index !== index) {
|
|
7684
|
+
throw new TypeError("invalid parameter format");
|
|
7685
|
+
}
|
|
7686
|
+
index += match[0].length;
|
|
7687
|
+
key = match[1].toLowerCase();
|
|
7688
|
+
value = match[2];
|
|
7689
|
+
if (value.charCodeAt(0) === 34) {
|
|
7690
|
+
value = value.slice(1, -1);
|
|
7691
|
+
if (value.indexOf("\\") !== -1) {
|
|
7692
|
+
value = value.replace(QESC_REGEXP, "$1");
|
|
7693
|
+
}
|
|
7694
|
+
}
|
|
7695
|
+
obj2.parameters[key] = value;
|
|
7696
|
+
}
|
|
7697
|
+
if (index !== header.length) {
|
|
7698
|
+
throw new TypeError("invalid parameter format");
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7701
|
+
return obj2;
|
|
7702
|
+
}
|
|
7703
|
+
__name(parse4, "parse");
|
|
7704
|
+
function getcontenttype(obj2) {
|
|
7705
|
+
var header;
|
|
7706
|
+
if (typeof obj2.getHeader === "function") {
|
|
7707
|
+
header = obj2.getHeader("content-type");
|
|
7708
|
+
} else if (typeof obj2.headers === "object") {
|
|
7709
|
+
header = obj2.headers && obj2.headers["content-type"];
|
|
7710
|
+
}
|
|
7711
|
+
if (typeof header !== "string") {
|
|
7712
|
+
throw new TypeError("content-type header is missing from object");
|
|
7713
|
+
}
|
|
7714
|
+
return header;
|
|
7715
|
+
}
|
|
7716
|
+
__name(getcontenttype, "getcontenttype");
|
|
7717
|
+
function qstring(val) {
|
|
7718
|
+
var str = String(val);
|
|
7719
|
+
if (TOKEN_REGEXP.test(str)) {
|
|
7720
|
+
return str;
|
|
7721
|
+
}
|
|
7722
|
+
if (str.length > 0 && !TEXT_REGEXP.test(str)) {
|
|
7723
|
+
throw new TypeError("invalid parameter value");
|
|
7724
|
+
}
|
|
7725
|
+
return '"' + str.replace(QUOTE_REGEXP, "\\$1") + '"';
|
|
7726
|
+
}
|
|
7727
|
+
__name(qstring, "qstring");
|
|
7728
|
+
function ContentType(type) {
|
|
7729
|
+
this.parameters = /* @__PURE__ */ Object.create(null);
|
|
7730
|
+
this.type = type;
|
|
7731
|
+
}
|
|
7732
|
+
__name(ContentType, "ContentType");
|
|
7733
|
+
}
|
|
7734
|
+
});
|
|
7735
|
+
|
|
7627
7736
|
// src/intern/proto/connection.ts
|
|
7628
|
-
var net,
|
|
7737
|
+
var net, crypto2, MAGIC, CONNECT_REQUEST_TEMPLATE, RoonConnection;
|
|
7629
7738
|
var init_connection = __esm({
|
|
7630
7739
|
"src/intern/proto/connection.ts"() {
|
|
7631
7740
|
"use strict";
|
|
7632
7741
|
net = __toESM(require("net"));
|
|
7633
|
-
|
|
7742
|
+
crypto2 = __toESM(require("crypto"));
|
|
7634
7743
|
MAGIC = Buffer.from("ROON");
|
|
7635
7744
|
CONNECT_REQUEST_TEMPLATE = "470181670000000100012c536f6f6c6f6f732e4d73672e446973747269627574656442726f6b65722e436f6e6e6563745265717565737424840e436c69656e7442726f6b65724964XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX228110436c69656e7442726f6b65724e616d650000000848512d30303435321b810f50726f746f636f6c56657273696f6e0000000232383e810c50726f746f636f6c48617368000000286161656464323265326536653435323233316537346464333039666662396432376139373531656420810c436c69656e744272616e63680000000a70726f64756374696f6e05030503";
|
|
7636
7745
|
RoonConnection = class {
|
|
@@ -7645,7 +7754,7 @@ var init_connection = __esm({
|
|
|
7645
7754
|
dataHandler = /* @__PURE__ */ __name(() => {
|
|
7646
7755
|
}, "dataHandler");
|
|
7647
7756
|
established = false;
|
|
7648
|
-
clientBrokerId =
|
|
7757
|
+
clientBrokerId = crypto2.randomBytes(16);
|
|
7649
7758
|
/**
|
|
7650
7759
|
* Fired when the socket closes for any reason (explicit close(), peer
|
|
7651
7760
|
* disconnect, error) so the remoting layer can fail in-flight requests
|
|
@@ -10028,13 +10137,13 @@ var require_buffer_util = __commonJS({
|
|
|
10028
10137
|
}
|
|
10029
10138
|
}
|
|
10030
10139
|
__name(_unmask, "_unmask");
|
|
10031
|
-
function
|
|
10140
|
+
function toArrayBuffer2(buf) {
|
|
10032
10141
|
if (buf.length === buf.buffer.byteLength) {
|
|
10033
10142
|
return buf.buffer;
|
|
10034
10143
|
}
|
|
10035
10144
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
10036
10145
|
}
|
|
10037
|
-
__name(
|
|
10146
|
+
__name(toArrayBuffer2, "toArrayBuffer");
|
|
10038
10147
|
function toBuffer(data) {
|
|
10039
10148
|
toBuffer.readOnly = true;
|
|
10040
10149
|
if (Buffer.isBuffer(data)) return data;
|
|
@@ -10053,7 +10162,7 @@ var require_buffer_util = __commonJS({
|
|
|
10053
10162
|
module2.exports = {
|
|
10054
10163
|
concat,
|
|
10055
10164
|
mask: _mask,
|
|
10056
|
-
toArrayBuffer,
|
|
10165
|
+
toArrayBuffer: toArrayBuffer2,
|
|
10057
10166
|
toBuffer,
|
|
10058
10167
|
unmask: _unmask
|
|
10059
10168
|
};
|
|
@@ -10732,7 +10841,7 @@ var require_receiver = __commonJS({
|
|
|
10732
10841
|
kStatusCode,
|
|
10733
10842
|
kWebSocket
|
|
10734
10843
|
} = require_constants();
|
|
10735
|
-
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
10844
|
+
var { concat, toArrayBuffer: toArrayBuffer2, unmask } = require_buffer_util();
|
|
10736
10845
|
var { isValidStatusCode, isValidUTF8 } = require_validation2();
|
|
10737
10846
|
var FastBuffer = Buffer[Symbol.species];
|
|
10738
10847
|
var GET_INFO = 0;
|
|
@@ -11214,7 +11323,7 @@ var require_receiver = __commonJS({
|
|
|
11214
11323
|
if (this._binaryType === "nodebuffer") {
|
|
11215
11324
|
data = concat(fragments, messageLength);
|
|
11216
11325
|
} else if (this._binaryType === "arraybuffer") {
|
|
11217
|
-
data =
|
|
11326
|
+
data = toArrayBuffer2(concat(fragments, messageLength));
|
|
11218
11327
|
} else if (this._binaryType === "blob") {
|
|
11219
11328
|
data = new Blob(fragments);
|
|
11220
11329
|
} else {
|
|
@@ -11857,7 +11966,7 @@ var require_event_target = __commonJS({
|
|
|
11857
11966
|
var kTarget = /* @__PURE__ */ Symbol("kTarget");
|
|
11858
11967
|
var kType = /* @__PURE__ */ Symbol("kType");
|
|
11859
11968
|
var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
|
|
11860
|
-
var
|
|
11969
|
+
var Event2 = class {
|
|
11861
11970
|
static {
|
|
11862
11971
|
__name(this, "Event");
|
|
11863
11972
|
}
|
|
@@ -11884,9 +11993,9 @@ var require_event_target = __commonJS({
|
|
|
11884
11993
|
return this[kType];
|
|
11885
11994
|
}
|
|
11886
11995
|
};
|
|
11887
|
-
Object.defineProperty(
|
|
11888
|
-
Object.defineProperty(
|
|
11889
|
-
var
|
|
11996
|
+
Object.defineProperty(Event2.prototype, "target", { enumerable: true });
|
|
11997
|
+
Object.defineProperty(Event2.prototype, "type", { enumerable: true });
|
|
11998
|
+
var CloseEvent2 = class extends Event2 {
|
|
11890
11999
|
static {
|
|
11891
12000
|
__name(this, "CloseEvent");
|
|
11892
12001
|
}
|
|
@@ -11928,10 +12037,10 @@ var require_event_target = __commonJS({
|
|
|
11928
12037
|
return this[kWasClean];
|
|
11929
12038
|
}
|
|
11930
12039
|
};
|
|
11931
|
-
Object.defineProperty(
|
|
11932
|
-
Object.defineProperty(
|
|
11933
|
-
Object.defineProperty(
|
|
11934
|
-
var
|
|
12040
|
+
Object.defineProperty(CloseEvent2.prototype, "code", { enumerable: true });
|
|
12041
|
+
Object.defineProperty(CloseEvent2.prototype, "reason", { enumerable: true });
|
|
12042
|
+
Object.defineProperty(CloseEvent2.prototype, "wasClean", { enumerable: true });
|
|
12043
|
+
var ErrorEvent2 = class extends Event2 {
|
|
11935
12044
|
static {
|
|
11936
12045
|
__name(this, "ErrorEvent");
|
|
11937
12046
|
}
|
|
@@ -11962,9 +12071,9 @@ var require_event_target = __commonJS({
|
|
|
11962
12071
|
return this[kMessage];
|
|
11963
12072
|
}
|
|
11964
12073
|
};
|
|
11965
|
-
Object.defineProperty(
|
|
11966
|
-
Object.defineProperty(
|
|
11967
|
-
var
|
|
12074
|
+
Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: true });
|
|
12075
|
+
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: true });
|
|
12076
|
+
var MessageEvent2 = class extends Event2 {
|
|
11968
12077
|
static {
|
|
11969
12078
|
__name(this, "MessageEvent");
|
|
11970
12079
|
}
|
|
@@ -11987,7 +12096,7 @@ var require_event_target = __commonJS({
|
|
|
11987
12096
|
return this[kData];
|
|
11988
12097
|
}
|
|
11989
12098
|
};
|
|
11990
|
-
Object.defineProperty(
|
|
12099
|
+
Object.defineProperty(MessageEvent2.prototype, "data", { enumerable: true });
|
|
11991
12100
|
var EventTarget = {
|
|
11992
12101
|
/**
|
|
11993
12102
|
* Register an event listener.
|
|
@@ -12010,7 +12119,7 @@ var require_event_target = __commonJS({
|
|
|
12010
12119
|
let wrapper;
|
|
12011
12120
|
if (type === "message") {
|
|
12012
12121
|
wrapper = /* @__PURE__ */ __name(function onMessage(data, isBinary) {
|
|
12013
|
-
const event = new
|
|
12122
|
+
const event = new MessageEvent2("message", {
|
|
12014
12123
|
data: isBinary ? data : data.toString()
|
|
12015
12124
|
});
|
|
12016
12125
|
event[kTarget] = this;
|
|
@@ -12018,7 +12127,7 @@ var require_event_target = __commonJS({
|
|
|
12018
12127
|
}, "onMessage");
|
|
12019
12128
|
} else if (type === "close") {
|
|
12020
12129
|
wrapper = /* @__PURE__ */ __name(function onClose(code, message) {
|
|
12021
|
-
const event = new
|
|
12130
|
+
const event = new CloseEvent2("close", {
|
|
12022
12131
|
code,
|
|
12023
12132
|
reason: message.toString(),
|
|
12024
12133
|
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
@@ -12028,7 +12137,7 @@ var require_event_target = __commonJS({
|
|
|
12028
12137
|
}, "onClose");
|
|
12029
12138
|
} else if (type === "error") {
|
|
12030
12139
|
wrapper = /* @__PURE__ */ __name(function onError(error62) {
|
|
12031
|
-
const event = new
|
|
12140
|
+
const event = new ErrorEvent2("error", {
|
|
12032
12141
|
error: error62,
|
|
12033
12142
|
message: error62.message
|
|
12034
12143
|
});
|
|
@@ -12037,7 +12146,7 @@ var require_event_target = __commonJS({
|
|
|
12037
12146
|
}, "onError");
|
|
12038
12147
|
} else if (type === "open") {
|
|
12039
12148
|
wrapper = /* @__PURE__ */ __name(function onOpen() {
|
|
12040
|
-
const event = new
|
|
12149
|
+
const event = new Event2("open");
|
|
12041
12150
|
event[kTarget] = this;
|
|
12042
12151
|
callListener(handler, this, event);
|
|
12043
12152
|
}, "onOpen");
|
|
@@ -12069,11 +12178,11 @@ var require_event_target = __commonJS({
|
|
|
12069
12178
|
}
|
|
12070
12179
|
};
|
|
12071
12180
|
module2.exports = {
|
|
12072
|
-
CloseEvent,
|
|
12073
|
-
ErrorEvent,
|
|
12074
|
-
Event,
|
|
12181
|
+
CloseEvent: CloseEvent2,
|
|
12182
|
+
ErrorEvent: ErrorEvent2,
|
|
12183
|
+
Event: Event2,
|
|
12075
12184
|
EventTarget,
|
|
12076
|
-
MessageEvent
|
|
12185
|
+
MessageEvent: MessageEvent2
|
|
12077
12186
|
};
|
|
12078
12187
|
function callListener(listener, thisArg, event) {
|
|
12079
12188
|
if (typeof listener === "object" && listener.handleEvent) {
|
|
@@ -12248,11 +12357,11 @@ var require_websocket = __commonJS({
|
|
|
12248
12357
|
"use strict";
|
|
12249
12358
|
var EventEmitter = require("events");
|
|
12250
12359
|
var https = require("https");
|
|
12251
|
-
var
|
|
12360
|
+
var http2 = require("http");
|
|
12252
12361
|
var net2 = require("net");
|
|
12253
12362
|
var tls = require("tls");
|
|
12254
12363
|
var { randomBytes: randomBytes2, createHash } = require("crypto");
|
|
12255
|
-
var { Duplex, Readable } = require("stream");
|
|
12364
|
+
var { Duplex, Readable: Readable2 } = require("stream");
|
|
12256
12365
|
var { URL: URL2 } = require("url");
|
|
12257
12366
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
12258
12367
|
var Receiver2 = require_receiver();
|
|
@@ -12806,7 +12915,7 @@ var require_websocket = __commonJS({
|
|
|
12806
12915
|
}
|
|
12807
12916
|
const defaultPort = isSecure ? 443 : 80;
|
|
12808
12917
|
const key = randomBytes2(16).toString("base64");
|
|
12809
|
-
const request = isSecure ? https.request :
|
|
12918
|
+
const request = isSecure ? https.request : http2.request;
|
|
12810
12919
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
12811
12920
|
let perMessageDeflate;
|
|
12812
12921
|
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
@@ -13239,7 +13348,7 @@ var require_stream = __commonJS({
|
|
|
13239
13348
|
};
|
|
13240
13349
|
duplex._final = function(callback) {
|
|
13241
13350
|
if (ws.readyState === ws.CONNECTING) {
|
|
13242
|
-
ws.once("open", /* @__PURE__ */ __name(function
|
|
13351
|
+
ws.once("open", /* @__PURE__ */ __name(function open4() {
|
|
13243
13352
|
duplex._final(callback);
|
|
13244
13353
|
}, "open"));
|
|
13245
13354
|
return;
|
|
@@ -13260,7 +13369,7 @@ var require_stream = __commonJS({
|
|
|
13260
13369
|
};
|
|
13261
13370
|
duplex._write = function(chunk, encoding, callback) {
|
|
13262
13371
|
if (ws.readyState === ws.CONNECTING) {
|
|
13263
|
-
ws.once("open", /* @__PURE__ */ __name(function
|
|
13372
|
+
ws.once("open", /* @__PURE__ */ __name(function open4() {
|
|
13264
13373
|
duplex._write(chunk, encoding, callback);
|
|
13265
13374
|
}, "open"));
|
|
13266
13375
|
return;
|
|
@@ -13327,7 +13436,7 @@ var require_websocket_server = __commonJS({
|
|
|
13327
13436
|
"node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
13328
13437
|
"use strict";
|
|
13329
13438
|
var EventEmitter = require("events");
|
|
13330
|
-
var
|
|
13439
|
+
var http2 = require("http");
|
|
13331
13440
|
var { Duplex } = require("stream");
|
|
13332
13441
|
var { createHash } = require("crypto");
|
|
13333
13442
|
var extension2 = require_extension();
|
|
@@ -13411,8 +13520,8 @@ var require_websocket_server = __commonJS({
|
|
|
13411
13520
|
);
|
|
13412
13521
|
}
|
|
13413
13522
|
if (options.port != null) {
|
|
13414
|
-
this._server =
|
|
13415
|
-
const body =
|
|
13523
|
+
this._server = http2.createServer((req, res) => {
|
|
13524
|
+
const body = http2.STATUS_CODES[426];
|
|
13416
13525
|
res.writeHead(426, {
|
|
13417
13526
|
"Content-Length": body.length,
|
|
13418
13527
|
"Content-Type": "text/plain"
|
|
@@ -13704,7 +13813,7 @@ var require_websocket_server = __commonJS({
|
|
|
13704
13813
|
}
|
|
13705
13814
|
__name(socketOnError, "socketOnError");
|
|
13706
13815
|
function abortHandshake(socket, code, message, headers) {
|
|
13707
|
-
message = message ||
|
|
13816
|
+
message = message || http2.STATUS_CODES[code];
|
|
13708
13817
|
headers = {
|
|
13709
13818
|
Connection: "close",
|
|
13710
13819
|
"Content-Type": "text/html",
|
|
@@ -13713,7 +13822,7 @@ var require_websocket_server = __commonJS({
|
|
|
13713
13822
|
};
|
|
13714
13823
|
socket.once("finish", socket.destroy);
|
|
13715
13824
|
socket.end(
|
|
13716
|
-
`HTTP/1.1 ${code} ${
|
|
13825
|
+
`HTTP/1.1 ${code} ${http2.STATUS_CODES[code]}\r
|
|
13717
13826
|
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
|
|
13718
13827
|
);
|
|
13719
13828
|
}
|
|
@@ -14112,11 +14221,11 @@ var require_moo = __commonJS({
|
|
|
14112
14221
|
this.logger.log("MOO: bad message; has Content-Length but not Content-Type: ", msg);
|
|
14113
14222
|
return void 0;
|
|
14114
14223
|
} else if (msg.content_type == "application/json") {
|
|
14115
|
-
var
|
|
14224
|
+
var json3 = buf.toString("utf8", e + 1, e + 1 + msg.content_length);
|
|
14116
14225
|
try {
|
|
14117
|
-
msg.body = JSON.parse(
|
|
14226
|
+
msg.body = JSON.parse(json3);
|
|
14118
14227
|
} catch (e2) {
|
|
14119
|
-
this.logger.log("MOO: bad json body: ",
|
|
14228
|
+
this.logger.log("MOO: bad json body: ", json3, msg);
|
|
14120
14229
|
return void 0;
|
|
14121
14230
|
}
|
|
14122
14231
|
} else {
|
|
@@ -14277,7 +14386,7 @@ var require_moomsg = __commonJS({
|
|
|
14277
14386
|
var require_core3 = __commonJS({
|
|
14278
14387
|
"node_modules/node-roon-api/core.js"(exports2, module2) {
|
|
14279
14388
|
"use strict";
|
|
14280
|
-
function Core(moo,
|
|
14389
|
+
function Core(moo, roon2, registration) {
|
|
14281
14390
|
this.moo = moo;
|
|
14282
14391
|
this.core_id = registration.core_id;
|
|
14283
14392
|
this.display_name = registration.display_name;
|
|
@@ -14285,8 +14394,8 @@ var require_core3 = __commonJS({
|
|
|
14285
14394
|
this.registration = registration;
|
|
14286
14395
|
this.services = {};
|
|
14287
14396
|
var svcs = {};
|
|
14288
|
-
|
|
14289
|
-
|
|
14397
|
+
roon2.services_opts.required_services.forEach((svcobj) => svcobj.services.forEach((svc) => svcs[svc.name] = svcobj));
|
|
14398
|
+
roon2.services_opts.optional_services.forEach((svcobj) => svcobj.services.forEach((svc) => svcs[svc.name] = svcobj));
|
|
14290
14399
|
registration.provided_services.forEach((e) => {
|
|
14291
14400
|
this.services[svcs[e].name] = new svcs[e](this);
|
|
14292
14401
|
});
|
|
@@ -14903,24 +15012,24 @@ var require_lib = __commonJS({
|
|
|
14903
15012
|
});
|
|
14904
15013
|
this.pairing_service_1 = {
|
|
14905
15014
|
services: [svc],
|
|
14906
|
-
found_core: /* @__PURE__ */ __name((
|
|
15015
|
+
found_core: /* @__PURE__ */ __name((core2) => {
|
|
14907
15016
|
if (!this.paired_core_id) {
|
|
14908
15017
|
let settings3 = this.get_persisted_state();
|
|
14909
|
-
settings3.paired_core_id =
|
|
15018
|
+
settings3.paired_core_id = core2.core_id;
|
|
14910
15019
|
this.set_persisted_state(settings3);
|
|
14911
|
-
this.paired_core_id =
|
|
14912
|
-
this.paired_core =
|
|
15020
|
+
this.paired_core_id = core2.core_id;
|
|
15021
|
+
this.paired_core = core2;
|
|
14913
15022
|
this.is_paired = true;
|
|
14914
15023
|
svc.send_continue_all("subscribe_pairing", "Changed", { paired_core_id: this.paired_core_id });
|
|
14915
15024
|
}
|
|
14916
|
-
if (
|
|
14917
|
-
if (this.extension_opts.core_paired) this.extension_opts.core_paired(
|
|
15025
|
+
if (core2.core_id == this.paired_core_id) {
|
|
15026
|
+
if (this.extension_opts.core_paired) this.extension_opts.core_paired(core2);
|
|
14918
15027
|
}
|
|
14919
15028
|
}, "found_core"),
|
|
14920
|
-
lost_core: /* @__PURE__ */ __name((
|
|
14921
|
-
if (
|
|
15029
|
+
lost_core: /* @__PURE__ */ __name((core2) => {
|
|
15030
|
+
if (core2.core_id == this.paired_core_id)
|
|
14922
15031
|
this.is_paired = false;
|
|
14923
|
-
if (this.extension_opts.core_unpaired) this.extension_opts.core_unpaired(
|
|
15032
|
+
if (this.extension_opts.core_unpaired) this.extension_opts.core_unpaired(core2);
|
|
14924
15033
|
}, "lost_core")
|
|
14925
15034
|
};
|
|
14926
15035
|
o.provided_services.push(this.pairing_service_1);
|
|
@@ -15113,8 +15222,8 @@ var require_lib2 = __commonJS({
|
|
|
15113
15222
|
return zo.zone_id;
|
|
15114
15223
|
}
|
|
15115
15224
|
__name(zoid, "zoid");
|
|
15116
|
-
function RoonApiTransport2(
|
|
15117
|
-
this.core =
|
|
15225
|
+
function RoonApiTransport2(core2) {
|
|
15226
|
+
this.core = core2;
|
|
15118
15227
|
this._queues = {};
|
|
15119
15228
|
}
|
|
15120
15229
|
__name(RoonApiTransport2, "RoonApiTransport");
|
|
@@ -15416,7 +15525,7 @@ var require_lib2 = __commonJS({
|
|
|
15416
15525
|
var version2;
|
|
15417
15526
|
var init_package = __esm({
|
|
15418
15527
|
"package.json"() {
|
|
15419
|
-
version2 = "0.
|
|
15528
|
+
version2 = "0.3.0";
|
|
15420
15529
|
}
|
|
15421
15530
|
});
|
|
15422
15531
|
|
|
@@ -15443,7 +15552,8 @@ function configDir() {
|
|
|
15443
15552
|
function startOfficial(target2) {
|
|
15444
15553
|
if (started) return;
|
|
15445
15554
|
started = true;
|
|
15446
|
-
|
|
15555
|
+
core = target2;
|
|
15556
|
+
roon = new import_node_roon_api.default({
|
|
15447
15557
|
extension_id: "nl.renebouwmeester.deep-roon-mcp",
|
|
15448
15558
|
display_name: "Deep Roon MCP",
|
|
15449
15559
|
display_version: version2,
|
|
@@ -15453,13 +15563,13 @@ function startOfficial(target2) {
|
|
|
15453
15563
|
log_level: "none",
|
|
15454
15564
|
get_persisted_state: readState,
|
|
15455
15565
|
set_persisted_state: writeState,
|
|
15456
|
-
core_paired(
|
|
15457
|
-
transport =
|
|
15566
|
+
core_paired(core2) {
|
|
15567
|
+
transport = core2.services.RoonApiTransport ?? Object.entries(core2.services ?? {}).find(([k]) => k.startsWith("RoonApiTransport"))?.[1];
|
|
15458
15568
|
if (!transport) {
|
|
15459
15569
|
log("paired, but the Core offers no transport service");
|
|
15460
15570
|
return;
|
|
15461
15571
|
}
|
|
15462
|
-
log(`paired with ${
|
|
15572
|
+
log(`paired with ${core2.display_name} (Roon \u203A Settings \u203A Extensions)`);
|
|
15463
15573
|
transport.subscribe_zones((cmd, data) => {
|
|
15464
15574
|
if (cmd === "Subscribed") {
|
|
15465
15575
|
zones.clear();
|
|
@@ -15490,25 +15600,26 @@ function startOfficial(target2) {
|
|
|
15490
15600
|
}
|
|
15491
15601
|
});
|
|
15492
15602
|
roon.init_services({ required_services: [import_node_roon_api_transport.default] });
|
|
15493
|
-
let tries = 0;
|
|
15494
|
-
const connect = /* @__PURE__ */ __name(() => {
|
|
15495
|
-
roon.ws_connect({
|
|
15496
|
-
host: target2.host,
|
|
15497
|
-
port: target2.port,
|
|
15498
|
-
onclose: /* @__PURE__ */ __name(() => {
|
|
15499
|
-
transport = null;
|
|
15500
|
-
zones.clear();
|
|
15501
|
-
zonesIn = false;
|
|
15502
|
-
const delay = [5, 15, 60][tries] ?? 300;
|
|
15503
|
-
tries += 1;
|
|
15504
|
-
setTimeout(connect, delay * 1e3).unref();
|
|
15505
|
-
}, "onclose")
|
|
15506
|
-
});
|
|
15507
|
-
}, "connect");
|
|
15508
15603
|
connect();
|
|
15509
15604
|
}
|
|
15605
|
+
function connect() {
|
|
15606
|
+
if (open2 || !roon || !core) return;
|
|
15607
|
+
open2 = true;
|
|
15608
|
+
roon.ws_connect({
|
|
15609
|
+
host: core.host,
|
|
15610
|
+
port: core.port,
|
|
15611
|
+
onclose: /* @__PURE__ */ __name(() => {
|
|
15612
|
+
open2 = false;
|
|
15613
|
+
transport = null;
|
|
15614
|
+
zones.clear();
|
|
15615
|
+
zonesIn = false;
|
|
15616
|
+
log("the extension connection closed (another copy of Deep Roon MCP may have taken it over) \u2014 it opens again when a tool needs it");
|
|
15617
|
+
}, "onclose")
|
|
15618
|
+
});
|
|
15619
|
+
}
|
|
15510
15620
|
async function paired(ms = 8e3) {
|
|
15511
15621
|
if (transport) return transport;
|
|
15622
|
+
connect();
|
|
15512
15623
|
await new Promise((resolve) => {
|
|
15513
15624
|
waiting.push(resolve);
|
|
15514
15625
|
setTimeout(resolve, ms).unref();
|
|
@@ -15547,7 +15658,7 @@ async function setVolume(name, change) {
|
|
|
15547
15658
|
}
|
|
15548
15659
|
return { zone: z2.display_name, outputs: outs.map((o) => ({ output: o.display_name, scale: `${o.volume.min}\u2013${o.volume.max}` })), volume: change.value, muted: change.mute };
|
|
15549
15660
|
}
|
|
15550
|
-
var import_fs, import_os, import_path, import_node_roon_api, import_node_roon_api_transport, STATE_FILE, readState, writeState, transport, zones, started, waiting, zonesIn, zoneWaiting, officialZones, isPaired;
|
|
15661
|
+
var import_fs, import_os, import_path, import_node_roon_api, import_node_roon_api_transport, STATE_FILE, readState, writeState, transport, zones, started, waiting, zonesIn, zoneWaiting, roon, core, open2, officialZones, isPaired;
|
|
15551
15662
|
var init_official = __esm({
|
|
15552
15663
|
"src/core/official.ts"() {
|
|
15553
15664
|
"use strict";
|
|
@@ -15578,7 +15689,11 @@ var init_official = __esm({
|
|
|
15578
15689
|
waiting = [];
|
|
15579
15690
|
zonesIn = false;
|
|
15580
15691
|
zoneWaiting = [];
|
|
15692
|
+
roon = null;
|
|
15693
|
+
core = null;
|
|
15694
|
+
open2 = false;
|
|
15581
15695
|
__name(startOfficial, "startOfficial");
|
|
15696
|
+
__name(connect, "connect");
|
|
15582
15697
|
__name(paired, "paired");
|
|
15583
15698
|
officialZones = /* @__PURE__ */ __name(() => [...zones.values()], "officialZones");
|
|
15584
15699
|
isPaired = /* @__PURE__ */ __name(() => !!transport, "isPaired");
|
|
@@ -15637,7 +15752,7 @@ function close(reason) {
|
|
|
15637
15752
|
log(`connection closed (${reason})`);
|
|
15638
15753
|
}
|
|
15639
15754
|
}
|
|
15640
|
-
async function
|
|
15755
|
+
async function open3() {
|
|
15641
15756
|
if (client) return client;
|
|
15642
15757
|
const t = await findTarget();
|
|
15643
15758
|
await paired();
|
|
@@ -15678,7 +15793,7 @@ function withCore(work2) {
|
|
|
15678
15793
|
idleTimer = null;
|
|
15679
15794
|
}
|
|
15680
15795
|
try {
|
|
15681
|
-
return await work2(await
|
|
15796
|
+
return await work2(await open3());
|
|
15682
15797
|
} catch (e) {
|
|
15683
15798
|
if (!(e instanceof RoonError && (e.kind === "not_found" || e.kind === "invalid"))) close("after an error");
|
|
15684
15799
|
throw e;
|
|
@@ -15692,7 +15807,7 @@ function withCore(work2) {
|
|
|
15692
15807
|
}
|
|
15693
15808
|
async function fresh() {
|
|
15694
15809
|
close("a fresh graph");
|
|
15695
|
-
return
|
|
15810
|
+
return open3();
|
|
15696
15811
|
}
|
|
15697
15812
|
function closeSoon(reason) {
|
|
15698
15813
|
close(reason);
|
|
@@ -15722,7 +15837,7 @@ var init_session = __esm({
|
|
|
15722
15837
|
__name(findTarget, "findTarget");
|
|
15723
15838
|
__name(locate, "locate");
|
|
15724
15839
|
__name(close, "close");
|
|
15725
|
-
__name(
|
|
15840
|
+
__name(open3, "open");
|
|
15726
15841
|
__name(withCore, "withCore");
|
|
15727
15842
|
__name(fresh, "fresh");
|
|
15728
15843
|
__name(closeSoon, "closeSoon");
|
|
@@ -16700,6 +16815,9 @@ var init_focus = __esm({
|
|
|
16700
16815
|
}
|
|
16701
16816
|
});
|
|
16702
16817
|
|
|
16818
|
+
// src/index.ts
|
|
16819
|
+
var import_http = __toESM(require("http"));
|
|
16820
|
+
|
|
16703
16821
|
// node_modules/zod/v3/helpers/util.js
|
|
16704
16822
|
var util;
|
|
16705
16823
|
(function(util2) {
|
|
@@ -36630,13 +36748,13 @@ function initializeContext(params) {
|
|
|
36630
36748
|
};
|
|
36631
36749
|
}
|
|
36632
36750
|
__name(initializeContext, "initializeContext");
|
|
36633
|
-
function handleUnrepresentable(schema, ctx,
|
|
36751
|
+
function handleUnrepresentable(schema, ctx, json3, params, message) {
|
|
36634
36752
|
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message }) : ctx.unrepresentable;
|
|
36635
36753
|
if (result === "any")
|
|
36636
36754
|
return false;
|
|
36637
36755
|
if (result === void 0 || result === "throw")
|
|
36638
36756
|
throw new Error(message);
|
|
36639
|
-
Object.assign(
|
|
36757
|
+
Object.assign(json3, result);
|
|
36640
36758
|
return true;
|
|
36641
36759
|
}
|
|
36642
36760
|
__name(handleUnrepresentable, "handleUnrepresentable");
|
|
@@ -36879,12 +36997,12 @@ function foldObjects(members2) {
|
|
|
36879
36997
|
return folded;
|
|
36880
36998
|
}
|
|
36881
36999
|
__name(foldObjects, "foldObjects");
|
|
36882
|
-
function foldIntersection(
|
|
36883
|
-
const allOf =
|
|
37000
|
+
function foldIntersection(json3) {
|
|
37001
|
+
const allOf = json3.allOf;
|
|
36884
37002
|
if (!Array.isArray(allOf) || allOf.length < 2)
|
|
36885
37003
|
return;
|
|
36886
37004
|
for (const key of FOLDABLE_KEYS)
|
|
36887
|
-
if (key in
|
|
37005
|
+
if (key in json3)
|
|
36888
37006
|
return;
|
|
36889
37007
|
const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
|
|
36890
37008
|
let folded = null;
|
|
@@ -36903,8 +37021,8 @@ function foldIntersection(json2) {
|
|
|
36903
37021
|
}
|
|
36904
37022
|
if (!folded)
|
|
36905
37023
|
return;
|
|
36906
|
-
delete
|
|
36907
|
-
assignProps(
|
|
37024
|
+
delete json3.allOf;
|
|
37025
|
+
assignProps(json3, folded);
|
|
36908
37026
|
}
|
|
36909
37027
|
__name(foldIntersection, "foldIntersection");
|
|
36910
37028
|
function finalize(ctx, schema) {
|
|
@@ -36987,20 +37105,20 @@ function finalize(ctx, schema) {
|
|
|
36987
37105
|
if (ctx.intersections.length) {
|
|
36988
37106
|
const carriers = /* @__PURE__ */ new Map();
|
|
36989
37107
|
for (const seen2 of ctx.seen.values()) {
|
|
36990
|
-
for (const
|
|
36991
|
-
const allOf =
|
|
37108
|
+
for (const json3 of [seen2.schema, seen2.def]) {
|
|
37109
|
+
const allOf = json3?.allOf;
|
|
36992
37110
|
if (!Array.isArray(allOf))
|
|
36993
37111
|
continue;
|
|
36994
37112
|
const existing = carriers.get(allOf);
|
|
36995
37113
|
if (existing)
|
|
36996
|
-
existing.push(
|
|
37114
|
+
existing.push(json3);
|
|
36997
37115
|
else
|
|
36998
|
-
carriers.set(allOf, [
|
|
37116
|
+
carriers.set(allOf, [json3]);
|
|
36999
37117
|
}
|
|
37000
37118
|
}
|
|
37001
37119
|
for (const allOf of ctx.intersections) {
|
|
37002
|
-
for (const
|
|
37003
|
-
foldIntersection(
|
|
37120
|
+
for (const json3 of carriers.get(allOf) ?? [])
|
|
37121
|
+
foldIntersection(json3);
|
|
37004
37122
|
}
|
|
37005
37123
|
}
|
|
37006
37124
|
}
|
|
@@ -37238,29 +37356,29 @@ var exactPatterns = /* @__PURE__ */ new Map([
|
|
|
37238
37356
|
]);
|
|
37239
37357
|
var exactPattern = /* @__PURE__ */ __name((p) => exactPatterns.get(p) ?? p, "exactPattern");
|
|
37240
37358
|
var stringProcessor = /* @__PURE__ */ __name((schema, ctx, _json, _params) => {
|
|
37241
|
-
const
|
|
37242
|
-
|
|
37359
|
+
const json3 = _json;
|
|
37360
|
+
json3.type = "string";
|
|
37243
37361
|
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
|
|
37244
37362
|
if (typeof minimum === "number")
|
|
37245
|
-
|
|
37363
|
+
json3.minLength = minimum;
|
|
37246
37364
|
if (typeof maximum === "number")
|
|
37247
|
-
|
|
37365
|
+
json3.maxLength = maximum;
|
|
37248
37366
|
if (format) {
|
|
37249
|
-
|
|
37250
|
-
if (
|
|
37251
|
-
delete
|
|
37367
|
+
json3.format = formatMap[format] ?? format;
|
|
37368
|
+
if (json3.format === "")
|
|
37369
|
+
delete json3.format;
|
|
37252
37370
|
if (format === "time" || laxFormat) {
|
|
37253
|
-
delete
|
|
37371
|
+
delete json3.format;
|
|
37254
37372
|
}
|
|
37255
37373
|
}
|
|
37256
37374
|
if (contentEncoding)
|
|
37257
|
-
|
|
37375
|
+
json3.contentEncoding = contentEncoding;
|
|
37258
37376
|
if (patterns && patterns.size > 0) {
|
|
37259
37377
|
const patternList = [...patterns].map(exactPattern);
|
|
37260
37378
|
if (patternList.length === 1)
|
|
37261
|
-
|
|
37379
|
+
json3.pattern = patternList[0].source;
|
|
37262
37380
|
else if (patternList.length > 1) {
|
|
37263
|
-
|
|
37381
|
+
json3.allOf = [
|
|
37264
37382
|
...patternList.map((regex) => ({
|
|
37265
37383
|
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
37266
37384
|
pattern: regex.source
|
|
@@ -37270,31 +37388,31 @@ var stringProcessor = /* @__PURE__ */ __name((schema, ctx, _json, _params) => {
|
|
|
37270
37388
|
}
|
|
37271
37389
|
}, "stringProcessor");
|
|
37272
37390
|
var numberProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37273
|
-
const
|
|
37391
|
+
const json3 = _json;
|
|
37274
37392
|
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } = aggregateChecks(schema);
|
|
37275
|
-
|
|
37393
|
+
json3.type = isInt ? "integer" : "number";
|
|
37276
37394
|
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
37277
37395
|
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
37278
37396
|
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
37279
37397
|
if (exMin) {
|
|
37280
37398
|
if (legacy) {
|
|
37281
|
-
|
|
37282
|
-
|
|
37399
|
+
json3.minimum = exclusiveMinimum;
|
|
37400
|
+
json3.exclusiveMinimum = true;
|
|
37283
37401
|
} else {
|
|
37284
|
-
|
|
37402
|
+
json3.exclusiveMinimum = exclusiveMinimum;
|
|
37285
37403
|
}
|
|
37286
37404
|
} else if (typeof minimum === "number") {
|
|
37287
|
-
|
|
37405
|
+
json3.minimum = minimum;
|
|
37288
37406
|
}
|
|
37289
37407
|
if (exMax) {
|
|
37290
37408
|
if (legacy) {
|
|
37291
|
-
|
|
37292
|
-
|
|
37409
|
+
json3.maximum = exclusiveMaximum;
|
|
37410
|
+
json3.exclusiveMaximum = true;
|
|
37293
37411
|
} else {
|
|
37294
|
-
|
|
37412
|
+
json3.exclusiveMaximum = exclusiveMaximum;
|
|
37295
37413
|
}
|
|
37296
37414
|
} else if (typeof maximum === "number") {
|
|
37297
|
-
|
|
37415
|
+
json3.maximum = maximum;
|
|
37298
37416
|
}
|
|
37299
37417
|
if (multipleOf) {
|
|
37300
37418
|
const divisors = /* @__PURE__ */ new Set();
|
|
@@ -37302,75 +37420,75 @@ var numberProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37302
37420
|
if (Number.isFinite(divisor) && divisor !== 0)
|
|
37303
37421
|
divisors.add(Math.abs(divisor));
|
|
37304
37422
|
else
|
|
37305
|
-
handleUnrepresentable(schema, ctx,
|
|
37423
|
+
handleUnrepresentable(schema, ctx, json3, params, `A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`);
|
|
37306
37424
|
}
|
|
37307
37425
|
const [first, ...rest] = divisors;
|
|
37308
37426
|
if (first !== void 0)
|
|
37309
|
-
|
|
37427
|
+
json3.multipleOf = first;
|
|
37310
37428
|
if (rest.length)
|
|
37311
|
-
|
|
37429
|
+
json3.allOf = [...json3.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
|
|
37312
37430
|
}
|
|
37313
37431
|
}, "numberProcessor");
|
|
37314
|
-
var booleanProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37315
|
-
|
|
37432
|
+
var booleanProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37433
|
+
json3.type = "boolean";
|
|
37316
37434
|
}, "booleanProcessor");
|
|
37317
|
-
var bigintProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37318
|
-
handleUnrepresentable(schema, ctx,
|
|
37435
|
+
var bigintProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37436
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt cannot be represented in JSON Schema");
|
|
37319
37437
|
}, "bigintProcessor");
|
|
37320
|
-
var symbolProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37321
|
-
handleUnrepresentable(schema, ctx,
|
|
37438
|
+
var symbolProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37439
|
+
handleUnrepresentable(schema, ctx, json3, params, "Symbols cannot be represented in JSON Schema");
|
|
37322
37440
|
}, "symbolProcessor");
|
|
37323
|
-
var nullProcessor = /* @__PURE__ */ __name((_schema, ctx,
|
|
37441
|
+
var nullProcessor = /* @__PURE__ */ __name((_schema, ctx, json3, _params) => {
|
|
37324
37442
|
if (ctx.target === "openapi-3.0") {
|
|
37325
|
-
|
|
37326
|
-
|
|
37327
|
-
|
|
37443
|
+
json3.type = "string";
|
|
37444
|
+
json3.nullable = true;
|
|
37445
|
+
json3.enum = [null];
|
|
37328
37446
|
} else {
|
|
37329
|
-
|
|
37447
|
+
json3.type = "null";
|
|
37330
37448
|
}
|
|
37331
37449
|
}, "nullProcessor");
|
|
37332
|
-
var undefinedProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37333
|
-
handleUnrepresentable(schema, ctx,
|
|
37450
|
+
var undefinedProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37451
|
+
handleUnrepresentable(schema, ctx, json3, params, "Undefined cannot be represented in JSON Schema");
|
|
37334
37452
|
}, "undefinedProcessor");
|
|
37335
|
-
var voidProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37336
|
-
handleUnrepresentable(schema, ctx,
|
|
37453
|
+
var voidProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37454
|
+
handleUnrepresentable(schema, ctx, json3, params, "Void cannot be represented in JSON Schema");
|
|
37337
37455
|
}, "voidProcessor");
|
|
37338
|
-
var neverProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37339
|
-
|
|
37456
|
+
var neverProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37457
|
+
json3.not = {};
|
|
37340
37458
|
}, "neverProcessor");
|
|
37341
37459
|
var anyProcessor = /* @__PURE__ */ __name((_schema, _ctx, _json, _params) => {
|
|
37342
37460
|
}, "anyProcessor");
|
|
37343
37461
|
var unknownProcessor = /* @__PURE__ */ __name((_schema, _ctx, _json, _params) => {
|
|
37344
37462
|
}, "unknownProcessor");
|
|
37345
|
-
var dateProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37346
|
-
handleUnrepresentable(schema, ctx,
|
|
37463
|
+
var dateProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37464
|
+
handleUnrepresentable(schema, ctx, json3, params, "Date cannot be represented in JSON Schema");
|
|
37347
37465
|
}, "dateProcessor");
|
|
37348
|
-
var enumProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37466
|
+
var enumProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37349
37467
|
const def = schema._zod.def;
|
|
37350
37468
|
const values = getEnumValues(def.entries);
|
|
37351
37469
|
if (values.length === 0) {
|
|
37352
|
-
|
|
37470
|
+
json3.not = {};
|
|
37353
37471
|
return;
|
|
37354
37472
|
}
|
|
37355
37473
|
if (values.every((v) => typeof v === "number"))
|
|
37356
|
-
|
|
37474
|
+
json3.type = "number";
|
|
37357
37475
|
if (values.every((v) => typeof v === "string"))
|
|
37358
|
-
|
|
37359
|
-
|
|
37476
|
+
json3.type = "string";
|
|
37477
|
+
json3.enum = values;
|
|
37360
37478
|
}, "enumProcessor");
|
|
37361
|
-
var literalProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37479
|
+
var literalProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37362
37480
|
const def = schema._zod.def;
|
|
37363
37481
|
if (def.values.length === 0) {
|
|
37364
|
-
|
|
37482
|
+
json3.not = {};
|
|
37365
37483
|
return;
|
|
37366
37484
|
}
|
|
37367
37485
|
const vals = [];
|
|
37368
37486
|
for (const val of def.values) {
|
|
37369
37487
|
if (val === void 0) {
|
|
37370
|
-
if (handleUnrepresentable(schema, ctx,
|
|
37488
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "Literal `undefined` cannot be represented in JSON Schema"))
|
|
37371
37489
|
return;
|
|
37372
37490
|
} else if (typeof val === "bigint") {
|
|
37373
|
-
if (handleUnrepresentable(schema, ctx,
|
|
37491
|
+
if (handleUnrepresentable(schema, ctx, json3, params, "BigInt literals cannot be represented in JSON Schema"))
|
|
37374
37492
|
return;
|
|
37375
37493
|
vals.push(Number(val));
|
|
37376
37494
|
} else {
|
|
@@ -37380,37 +37498,37 @@ var literalProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37380
37498
|
if (vals.length === 0) {
|
|
37381
37499
|
} else if (vals.length === 1) {
|
|
37382
37500
|
const val = vals[0];
|
|
37383
|
-
|
|
37501
|
+
json3.type = val === null ? "null" : typeof val;
|
|
37384
37502
|
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
37385
|
-
|
|
37503
|
+
json3.enum = [val];
|
|
37386
37504
|
} else {
|
|
37387
|
-
|
|
37505
|
+
json3.const = val;
|
|
37388
37506
|
}
|
|
37389
37507
|
} else {
|
|
37390
37508
|
if (vals.every((v) => typeof v === "number"))
|
|
37391
|
-
|
|
37509
|
+
json3.type = "number";
|
|
37392
37510
|
if (vals.every((v) => typeof v === "string"))
|
|
37393
|
-
|
|
37511
|
+
json3.type = "string";
|
|
37394
37512
|
if (vals.every((v) => typeof v === "boolean"))
|
|
37395
|
-
|
|
37513
|
+
json3.type = "boolean";
|
|
37396
37514
|
if (vals.every((v) => v === null))
|
|
37397
|
-
|
|
37398
|
-
|
|
37515
|
+
json3.type = "null";
|
|
37516
|
+
json3.enum = vals;
|
|
37399
37517
|
}
|
|
37400
37518
|
}, "literalProcessor");
|
|
37401
|
-
var nanProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37402
|
-
handleUnrepresentable(schema, ctx,
|
|
37519
|
+
var nanProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37520
|
+
handleUnrepresentable(schema, ctx, json3, params, "NaN cannot be represented in JSON Schema");
|
|
37403
37521
|
}, "nanProcessor");
|
|
37404
|
-
var templateLiteralProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37405
|
-
const _json =
|
|
37522
|
+
var templateLiteralProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37523
|
+
const _json = json3;
|
|
37406
37524
|
const pattern = schema._zod.pattern;
|
|
37407
37525
|
if (!pattern)
|
|
37408
37526
|
throw new Error("Pattern not found in template literal");
|
|
37409
37527
|
_json.type = "string";
|
|
37410
37528
|
_json.pattern = pattern.source;
|
|
37411
37529
|
}, "templateLiteralProcessor");
|
|
37412
|
-
var fileProcessor = /* @__PURE__ */ __name((schema, _ctx,
|
|
37413
|
-
const _json =
|
|
37530
|
+
var fileProcessor = /* @__PURE__ */ __name((schema, _ctx, json3, _params) => {
|
|
37531
|
+
const _json = json3;
|
|
37414
37532
|
_json.type = "string";
|
|
37415
37533
|
_json.format = "binary";
|
|
37416
37534
|
_json.contentEncoding = "binary";
|
|
@@ -37428,34 +37546,34 @@ var fileProcessor = /* @__PURE__ */ __name((schema, _ctx, json2, _params) => {
|
|
|
37428
37546
|
else
|
|
37429
37547
|
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
37430
37548
|
}, "fileProcessor");
|
|
37431
|
-
var successProcessor = /* @__PURE__ */ __name((_schema, _ctx,
|
|
37432
|
-
|
|
37549
|
+
var successProcessor = /* @__PURE__ */ __name((_schema, _ctx, json3, _params) => {
|
|
37550
|
+
json3.type = "boolean";
|
|
37433
37551
|
}, "successProcessor");
|
|
37434
|
-
var customProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37435
|
-
handleUnrepresentable(schema, ctx,
|
|
37552
|
+
var customProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37553
|
+
handleUnrepresentable(schema, ctx, json3, params, "Custom types cannot be represented in JSON Schema");
|
|
37436
37554
|
}, "customProcessor");
|
|
37437
|
-
var functionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37438
|
-
handleUnrepresentable(schema, ctx,
|
|
37555
|
+
var functionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37556
|
+
handleUnrepresentable(schema, ctx, json3, params, "Function types cannot be represented in JSON Schema");
|
|
37439
37557
|
}, "functionProcessor");
|
|
37440
|
-
var transformProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37441
|
-
handleUnrepresentable(schema, ctx,
|
|
37558
|
+
var transformProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37559
|
+
handleUnrepresentable(schema, ctx, json3, params, "Transforms cannot be represented in JSON Schema");
|
|
37442
37560
|
}, "transformProcessor");
|
|
37443
|
-
var mapProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37444
|
-
handleUnrepresentable(schema, ctx,
|
|
37561
|
+
var mapProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37562
|
+
handleUnrepresentable(schema, ctx, json3, params, "Map cannot be represented in JSON Schema");
|
|
37445
37563
|
}, "mapProcessor");
|
|
37446
|
-
var setProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37447
|
-
handleUnrepresentable(schema, ctx,
|
|
37564
|
+
var setProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37565
|
+
handleUnrepresentable(schema, ctx, json3, params, "Set cannot be represented in JSON Schema");
|
|
37448
37566
|
}, "setProcessor");
|
|
37449
37567
|
var arrayProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37450
|
-
const
|
|
37568
|
+
const json3 = _json;
|
|
37451
37569
|
const def = schema._zod.def;
|
|
37452
37570
|
const { minimum, maximum } = aggregateChecks(schema);
|
|
37453
37571
|
if (typeof minimum === "number")
|
|
37454
|
-
|
|
37572
|
+
json3.minItems = minimum;
|
|
37455
37573
|
if (typeof maximum === "number")
|
|
37456
|
-
|
|
37457
|
-
|
|
37458
|
-
|
|
37574
|
+
json3.maxItems = maximum;
|
|
37575
|
+
json3.type = "array";
|
|
37576
|
+
json3.items = processSchema(def.element, ctx, {
|
|
37459
37577
|
...params,
|
|
37460
37578
|
path: [...params.path, "items"]
|
|
37461
37579
|
});
|
|
@@ -37472,17 +37590,17 @@ function inputOptin(schema) {
|
|
|
37472
37590
|
}
|
|
37473
37591
|
__name(inputOptin, "inputOptin");
|
|
37474
37592
|
var objectProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37475
|
-
const
|
|
37593
|
+
const json3 = _json;
|
|
37476
37594
|
const def = schema._zod.def;
|
|
37477
37595
|
const shape = def.shape;
|
|
37478
37596
|
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
37479
|
-
if (symbolKeys.length && handleUnrepresentable(schema, ctx,
|
|
37597
|
+
if (symbolKeys.length && handleUnrepresentable(schema, ctx, json3, params, "Symbol keys cannot be represented in JSON Schema")) {
|
|
37480
37598
|
return;
|
|
37481
37599
|
}
|
|
37482
|
-
|
|
37483
|
-
|
|
37600
|
+
json3.type = "object";
|
|
37601
|
+
json3.properties = {};
|
|
37484
37602
|
for (const key in shape) {
|
|
37485
|
-
assignProp(
|
|
37603
|
+
assignProp(json3.properties, key, processSchema(shape[key], ctx, {
|
|
37486
37604
|
...params,
|
|
37487
37605
|
path: [...params.path, "properties", key]
|
|
37488
37606
|
}));
|
|
@@ -37495,21 +37613,21 @@ var objectProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37495
37613
|
}
|
|
37496
37614
|
}
|
|
37497
37615
|
if (requiredKeys.length > 0) {
|
|
37498
|
-
|
|
37616
|
+
json3.required = requiredKeys;
|
|
37499
37617
|
}
|
|
37500
37618
|
if (def.catchall?._zod.def.type === "never") {
|
|
37501
|
-
|
|
37619
|
+
json3.additionalProperties = false;
|
|
37502
37620
|
} else if (!def.catchall) {
|
|
37503
37621
|
if (ctx.io === "output")
|
|
37504
|
-
|
|
37622
|
+
json3.additionalProperties = false;
|
|
37505
37623
|
} else if (def.catchall) {
|
|
37506
|
-
|
|
37624
|
+
json3.additionalProperties = processSchema(def.catchall, ctx, {
|
|
37507
37625
|
...params,
|
|
37508
37626
|
path: [...params.path, "additionalProperties"]
|
|
37509
37627
|
});
|
|
37510
37628
|
}
|
|
37511
37629
|
}, "objectProcessor");
|
|
37512
|
-
var unionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37630
|
+
var unionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37513
37631
|
const def = schema._zod.def;
|
|
37514
37632
|
const isExclusive = def.inclusive === false;
|
|
37515
37633
|
const options = def.options.map((x, i) => processSchema(x, ctx, {
|
|
@@ -37517,12 +37635,12 @@ var unionProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37517
37635
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
37518
37636
|
}));
|
|
37519
37637
|
if (isExclusive) {
|
|
37520
|
-
|
|
37638
|
+
json3.oneOf = options;
|
|
37521
37639
|
} else {
|
|
37522
|
-
|
|
37640
|
+
json3.anyOf = options;
|
|
37523
37641
|
}
|
|
37524
37642
|
}, "unionProcessor");
|
|
37525
|
-
var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37643
|
+
var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37526
37644
|
const def = schema._zod.def;
|
|
37527
37645
|
const a = processSchema(def.left, ctx, {
|
|
37528
37646
|
...params,
|
|
@@ -37537,13 +37655,13 @@ var intersectionProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params)
|
|
|
37537
37655
|
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
37538
37656
|
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
37539
37657
|
];
|
|
37540
|
-
|
|
37658
|
+
json3.allOf = allOf;
|
|
37541
37659
|
ctx.intersections.push(allOf);
|
|
37542
37660
|
}, "intersectionProcessor");
|
|
37543
37661
|
var tupleProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37544
|
-
const
|
|
37662
|
+
const json3 = _json;
|
|
37545
37663
|
const def = schema._zod.def;
|
|
37546
|
-
|
|
37664
|
+
json3.type = "array";
|
|
37547
37665
|
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
37548
37666
|
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
37549
37667
|
const prefixItems = def.items.map((x, i) => processSchema(x, ctx, {
|
|
@@ -37565,70 +37683,70 @@ var tupleProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37565
37683
|
const maxItems = def.items.length;
|
|
37566
37684
|
const isClosed = !def.rest;
|
|
37567
37685
|
if (ctx.target === "draft-2020-12") {
|
|
37568
|
-
|
|
37686
|
+
json3.prefixItems = prefixItems;
|
|
37569
37687
|
if (isClosed) {
|
|
37570
|
-
|
|
37688
|
+
json3.items = false;
|
|
37571
37689
|
} else if (rest) {
|
|
37572
|
-
|
|
37690
|
+
json3.items = rest;
|
|
37573
37691
|
}
|
|
37574
37692
|
if (minItems > 0)
|
|
37575
|
-
|
|
37693
|
+
json3.minItems = minItems;
|
|
37576
37694
|
if (isClosed)
|
|
37577
|
-
|
|
37695
|
+
json3.maxItems = maxItems;
|
|
37578
37696
|
} else if (ctx.target === "openapi-3.0") {
|
|
37579
|
-
|
|
37697
|
+
json3.items = {
|
|
37580
37698
|
anyOf: prefixItems
|
|
37581
37699
|
};
|
|
37582
37700
|
if (rest) {
|
|
37583
|
-
|
|
37701
|
+
json3.items.anyOf.push(rest);
|
|
37584
37702
|
}
|
|
37585
37703
|
if (minItems > 0)
|
|
37586
|
-
|
|
37704
|
+
json3.minItems = minItems;
|
|
37587
37705
|
if (isClosed)
|
|
37588
|
-
|
|
37706
|
+
json3.maxItems = maxItems;
|
|
37589
37707
|
} else {
|
|
37590
|
-
|
|
37708
|
+
json3.items = prefixItems;
|
|
37591
37709
|
if (isClosed) {
|
|
37592
|
-
|
|
37710
|
+
json3.additionalItems = false;
|
|
37593
37711
|
} else if (rest) {
|
|
37594
|
-
|
|
37712
|
+
json3.additionalItems = rest;
|
|
37595
37713
|
}
|
|
37596
37714
|
if (minItems > 0)
|
|
37597
|
-
|
|
37715
|
+
json3.minItems = minItems;
|
|
37598
37716
|
if (isClosed)
|
|
37599
|
-
|
|
37717
|
+
json3.maxItems = maxItems;
|
|
37600
37718
|
}
|
|
37601
37719
|
const { minimum, maximum } = aggregateChecks(schema);
|
|
37602
37720
|
if (typeof minimum === "number")
|
|
37603
|
-
|
|
37721
|
+
json3.minItems = minimum;
|
|
37604
37722
|
if (typeof maximum === "number")
|
|
37605
|
-
|
|
37723
|
+
json3.maxItems = maximum;
|
|
37606
37724
|
}, "tupleProcessor");
|
|
37607
|
-
function stringifyKeyNames(bySchema,
|
|
37608
|
-
if (
|
|
37609
|
-
if (visited.has(
|
|
37610
|
-
return
|
|
37611
|
-
visited.add(
|
|
37612
|
-
const def = bySchema.get(
|
|
37725
|
+
function stringifyKeyNames(bySchema, json3, visited) {
|
|
37726
|
+
if (json3.$ref) {
|
|
37727
|
+
if (visited.has(json3))
|
|
37728
|
+
return json3;
|
|
37729
|
+
visited.add(json3);
|
|
37730
|
+
const def = bySchema.get(json3)?.def;
|
|
37613
37731
|
if (!def)
|
|
37614
|
-
return
|
|
37732
|
+
return json3;
|
|
37615
37733
|
const inlined = stringifyKeyNames(bySchema, def, visited);
|
|
37616
|
-
return inlined === def ?
|
|
37734
|
+
return inlined === def ? json3 : inlined;
|
|
37617
37735
|
}
|
|
37618
37736
|
for (const keyword of ["anyOf", "oneOf"]) {
|
|
37619
|
-
const branches =
|
|
37737
|
+
const branches = json3[keyword];
|
|
37620
37738
|
if (!Array.isArray(branches))
|
|
37621
37739
|
continue;
|
|
37622
37740
|
const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
|
|
37623
37741
|
if (mapped.some((branch, i) => branch !== branches[i]))
|
|
37624
|
-
|
|
37742
|
+
json3 = { ...json3, [keyword]: mapped };
|
|
37625
37743
|
}
|
|
37626
|
-
const types = Array.isArray(
|
|
37744
|
+
const types = Array.isArray(json3.type) ? json3.type : [json3.type];
|
|
37627
37745
|
const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
|
|
37628
|
-
const values =
|
|
37746
|
+
const values = json3.enum ?? (json3.const !== void 0 ? [json3.const] : void 0);
|
|
37629
37747
|
if (!numericType && !values?.some((v) => typeof v === "number"))
|
|
37630
|
-
return
|
|
37631
|
-
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } =
|
|
37748
|
+
return json3;
|
|
37749
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json3;
|
|
37632
37750
|
if (rest.enum)
|
|
37633
37751
|
rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
|
|
37634
37752
|
else if (typeof rest.const === "number")
|
|
@@ -37670,9 +37788,9 @@ function rewriteKeyNames(ctx) {
|
|
|
37670
37788
|
}
|
|
37671
37789
|
__name(rewriteKeyNames, "rewriteKeyNames");
|
|
37672
37790
|
var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37673
|
-
const
|
|
37791
|
+
const json3 = _json;
|
|
37674
37792
|
const def = schema._zod.def;
|
|
37675
|
-
|
|
37793
|
+
json3.type = "object";
|
|
37676
37794
|
const keyType = def.keyType;
|
|
37677
37795
|
const patterns = aggregateChecks(keyType).patterns;
|
|
37678
37796
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
@@ -37680,13 +37798,13 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37680
37798
|
...params,
|
|
37681
37799
|
path: [...params.path, "patternProperties", "*"]
|
|
37682
37800
|
});
|
|
37683
|
-
|
|
37801
|
+
json3.patternProperties = {};
|
|
37684
37802
|
for (const pattern of patterns) {
|
|
37685
|
-
assignProp(
|
|
37803
|
+
assignProp(json3.patternProperties, exactPattern(pattern).source, valueSchema);
|
|
37686
37804
|
}
|
|
37687
37805
|
} else {
|
|
37688
37806
|
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
37689
|
-
|
|
37807
|
+
json3.propertyNames = processSchema(def.keyType, ctx, {
|
|
37690
37808
|
...params,
|
|
37691
37809
|
path: [...params.path, "propertyNames"]
|
|
37692
37810
|
});
|
|
@@ -37698,7 +37816,7 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37698
37816
|
}
|
|
37699
37817
|
pending.push(schema);
|
|
37700
37818
|
}
|
|
37701
|
-
|
|
37819
|
+
json3.additionalProperties = processSchema(def.valueType, ctx, {
|
|
37702
37820
|
...params,
|
|
37703
37821
|
path: [...params.path, "additionalProperties"]
|
|
37704
37822
|
});
|
|
@@ -37708,19 +37826,19 @@ var recordProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37708
37826
|
if (keyValues && !def.partial && !omittableOnInput) {
|
|
37709
37827
|
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
37710
37828
|
if (validKeyValues.length > 0) {
|
|
37711
|
-
|
|
37829
|
+
json3.required = validKeyValues.map(String);
|
|
37712
37830
|
}
|
|
37713
37831
|
}
|
|
37714
37832
|
}, "recordProcessor");
|
|
37715
|
-
var nullableProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37833
|
+
var nullableProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37716
37834
|
const def = schema._zod.def;
|
|
37717
37835
|
const inner = processSchema(def.innerType, ctx, params);
|
|
37718
37836
|
const seen2 = ctx.seen.get(schema);
|
|
37719
37837
|
if (ctx.target === "openapi-3.0") {
|
|
37720
37838
|
seen2.ref = def.innerType;
|
|
37721
|
-
|
|
37839
|
+
json3.nullable = true;
|
|
37722
37840
|
} else {
|
|
37723
|
-
|
|
37841
|
+
json3.anyOf = [inner, { type: "null" }];
|
|
37724
37842
|
}
|
|
37725
37843
|
}, "nullableProcessor");
|
|
37726
37844
|
var nonoptionalProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
@@ -37730,7 +37848,7 @@ var nonoptionalProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) =
|
|
|
37730
37848
|
seen2.ref = def.innerType;
|
|
37731
37849
|
}, "nonoptionalProcessor");
|
|
37732
37850
|
var UNREPRESENTABLE_DEFAULT = /* @__PURE__ */ Symbol();
|
|
37733
|
-
function serializeDefaultValue(value, schema, ctx,
|
|
37851
|
+
function serializeDefaultValue(value, schema, ctx, json3, params) {
|
|
37734
37852
|
let unrepresentable = false;
|
|
37735
37853
|
const serialized = JSON.stringify(value, (_, val) => {
|
|
37736
37854
|
if (typeof val !== "bigint")
|
|
@@ -37740,31 +37858,31 @@ function serializeDefaultValue(value, schema, ctx, json2, params) {
|
|
|
37740
37858
|
});
|
|
37741
37859
|
if (!unrepresentable)
|
|
37742
37860
|
return JSON.parse(serialized);
|
|
37743
|
-
handleUnrepresentable(schema, ctx,
|
|
37861
|
+
handleUnrepresentable(schema, ctx, json3, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
37744
37862
|
return UNREPRESENTABLE_DEFAULT;
|
|
37745
37863
|
}
|
|
37746
37864
|
__name(serializeDefaultValue, "serializeDefaultValue");
|
|
37747
|
-
var defaultProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37865
|
+
var defaultProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37748
37866
|
const def = schema._zod.def;
|
|
37749
37867
|
processSchema(def.innerType, ctx, params);
|
|
37750
37868
|
const seen2 = ctx.seen.get(schema);
|
|
37751
37869
|
seen2.ref = def.innerType;
|
|
37752
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
37870
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
37753
37871
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
37754
|
-
|
|
37872
|
+
json3.default = value;
|
|
37755
37873
|
}, "defaultProcessor");
|
|
37756
|
-
var prefaultProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37874
|
+
var prefaultProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37757
37875
|
const def = schema._zod.def;
|
|
37758
37876
|
processSchema(def.innerType, ctx, params);
|
|
37759
37877
|
const seen2 = ctx.seen.get(schema);
|
|
37760
37878
|
seen2.ref = def.innerType;
|
|
37761
37879
|
if (ctx.io !== "input")
|
|
37762
37880
|
return;
|
|
37763
|
-
const value = serializeDefaultValue(def.defaultValue, schema, ctx,
|
|
37881
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json3, params);
|
|
37764
37882
|
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
37765
|
-
|
|
37883
|
+
json3._prefault = value;
|
|
37766
37884
|
}, "prefaultProcessor");
|
|
37767
|
-
var catchProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37885
|
+
var catchProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37768
37886
|
const def = schema._zod.def;
|
|
37769
37887
|
processSchema(def.innerType, ctx, params);
|
|
37770
37888
|
const seen2 = ctx.seen.get(schema);
|
|
@@ -37773,10 +37891,10 @@ var catchProcessor = /* @__PURE__ */ __name((schema, ctx, json2, params) => {
|
|
|
37773
37891
|
try {
|
|
37774
37892
|
catchValue = def.catchValue(void 0);
|
|
37775
37893
|
} catch {
|
|
37776
|
-
handleUnrepresentable(schema, ctx,
|
|
37894
|
+
handleUnrepresentable(schema, ctx, json3, params, "Dynamic catch values are not supported in JSON Schema");
|
|
37777
37895
|
return;
|
|
37778
37896
|
}
|
|
37779
|
-
|
|
37897
|
+
json3.default = catchValue;
|
|
37780
37898
|
}, "catchProcessor");
|
|
37781
37899
|
var pipeProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37782
37900
|
const def = schema._zod.def;
|
|
@@ -37786,12 +37904,12 @@ var pipeProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
|
37786
37904
|
const seen2 = ctx.seen.get(schema);
|
|
37787
37905
|
seen2.ref = innerType;
|
|
37788
37906
|
}, "pipeProcessor");
|
|
37789
|
-
var readonlyProcessor = /* @__PURE__ */ __name((schema, ctx,
|
|
37907
|
+
var readonlyProcessor = /* @__PURE__ */ __name((schema, ctx, json3, params) => {
|
|
37790
37908
|
const def = schema._zod.def;
|
|
37791
37909
|
processSchema(def.innerType, ctx, params);
|
|
37792
37910
|
const seen2 = ctx.seen.get(schema);
|
|
37793
37911
|
seen2.ref = def.innerType;
|
|
37794
|
-
|
|
37912
|
+
json3.readOnly = true;
|
|
37795
37913
|
}, "readonlyProcessor");
|
|
37796
37914
|
var promiseProcessor = /* @__PURE__ */ __name((schema, ctx, _json, params) => {
|
|
37797
37915
|
const def = schema._zod.def;
|
|
@@ -39099,7 +39217,7 @@ var _ZodString = /* @__PURE__ */ $constructor(
|
|
|
39099
39217
|
(inst, def) => {
|
|
39100
39218
|
$ZodString.init(inst, def);
|
|
39101
39219
|
ZodType2.init(inst, def);
|
|
39102
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39220
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => stringProcessor(inst, ctx, json3, params);
|
|
39103
39221
|
},
|
|
39104
39222
|
/* @__PURE__ */ util_exports.derived({
|
|
39105
39223
|
format: /* @__PURE__ */ __name((inst) => aggregateChecks(inst).format ?? null, "format"),
|
|
@@ -39490,7 +39608,7 @@ var ZodNumber2 = /* @__PURE__ */ $constructor(
|
|
|
39490
39608
|
(inst, def) => {
|
|
39491
39609
|
$ZodNumber.init(inst, def);
|
|
39492
39610
|
ZodType2.init(inst, def);
|
|
39493
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39611
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => numberProcessor(inst, ctx, json3, params);
|
|
39494
39612
|
inst.isFinite = true;
|
|
39495
39613
|
},
|
|
39496
39614
|
/* @__PURE__ */ util_exports.derived({
|
|
@@ -39586,7 +39704,7 @@ __name(uint32, "uint32");
|
|
|
39586
39704
|
var ZodBoolean2 = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
39587
39705
|
$ZodBoolean.init(inst, def);
|
|
39588
39706
|
ZodType2.init(inst, def);
|
|
39589
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39707
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => booleanProcessor(inst, ctx, json3, params);
|
|
39590
39708
|
});
|
|
39591
39709
|
function boolean2(params) {
|
|
39592
39710
|
return _boolean(ZodBoolean2, params);
|
|
@@ -39597,7 +39715,7 @@ var ZodBigInt2 = /* @__PURE__ */ $constructor(
|
|
|
39597
39715
|
(inst, def) => {
|
|
39598
39716
|
$ZodBigInt.init(inst, def);
|
|
39599
39717
|
ZodType2.init(inst, def);
|
|
39600
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39718
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => bigintProcessor(inst, ctx, json3, params);
|
|
39601
39719
|
},
|
|
39602
39720
|
/* @__PURE__ */ util_exports.derived({
|
|
39603
39721
|
minValue: /* @__PURE__ */ __name((inst) => aggregateChecks(inst).minimum ?? null, "minValue"),
|
|
@@ -39658,7 +39776,7 @@ __name(uint64, "uint64");
|
|
|
39658
39776
|
var ZodSymbol2 = /* @__PURE__ */ $constructor("ZodSymbol", (inst, def) => {
|
|
39659
39777
|
$ZodSymbol.init(inst, def);
|
|
39660
39778
|
ZodType2.init(inst, def);
|
|
39661
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39779
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => symbolProcessor(inst, ctx, json3, params);
|
|
39662
39780
|
});
|
|
39663
39781
|
function symbol(params) {
|
|
39664
39782
|
return _symbol(ZodSymbol2, params);
|
|
@@ -39667,7 +39785,7 @@ __name(symbol, "symbol");
|
|
|
39667
39785
|
var ZodUndefined2 = /* @__PURE__ */ $constructor("ZodUndefined", (inst, def) => {
|
|
39668
39786
|
$ZodUndefined.init(inst, def);
|
|
39669
39787
|
ZodType2.init(inst, def);
|
|
39670
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39788
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => undefinedProcessor(inst, ctx, json3, params);
|
|
39671
39789
|
});
|
|
39672
39790
|
function _undefined3(params) {
|
|
39673
39791
|
return _undefined2(ZodUndefined2, params);
|
|
@@ -39676,7 +39794,7 @@ __name(_undefined3, "_undefined");
|
|
|
39676
39794
|
var ZodNull2 = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
|
|
39677
39795
|
$ZodNull.init(inst, def);
|
|
39678
39796
|
ZodType2.init(inst, def);
|
|
39679
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39797
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullProcessor(inst, ctx, json3, params);
|
|
39680
39798
|
});
|
|
39681
39799
|
function _null3(params) {
|
|
39682
39800
|
return _null2(ZodNull2, params);
|
|
@@ -39685,7 +39803,7 @@ __name(_null3, "_null");
|
|
|
39685
39803
|
var ZodAny2 = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
39686
39804
|
$ZodAny.init(inst, def);
|
|
39687
39805
|
ZodType2.init(inst, def);
|
|
39688
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39806
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => anyProcessor(inst, ctx, json3, params);
|
|
39689
39807
|
});
|
|
39690
39808
|
function any() {
|
|
39691
39809
|
return _any(ZodAny2);
|
|
@@ -39694,7 +39812,7 @@ __name(any, "any");
|
|
|
39694
39812
|
var ZodUnknown2 = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
39695
39813
|
$ZodUnknown.init(inst, def);
|
|
39696
39814
|
ZodType2.init(inst, def);
|
|
39697
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39815
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unknownProcessor(inst, ctx, json3, params);
|
|
39698
39816
|
});
|
|
39699
39817
|
function unknown() {
|
|
39700
39818
|
return _unknown(ZodUnknown2);
|
|
@@ -39703,7 +39821,7 @@ __name(unknown, "unknown");
|
|
|
39703
39821
|
var ZodNever2 = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
39704
39822
|
$ZodNever.init(inst, def);
|
|
39705
39823
|
ZodType2.init(inst, def);
|
|
39706
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39824
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => neverProcessor(inst, ctx, json3, params);
|
|
39707
39825
|
});
|
|
39708
39826
|
function never(params) {
|
|
39709
39827
|
return _never(ZodNever2, params);
|
|
@@ -39712,7 +39830,7 @@ __name(never, "never");
|
|
|
39712
39830
|
var ZodVoid2 = /* @__PURE__ */ $constructor("ZodVoid", (inst, def) => {
|
|
39713
39831
|
$ZodVoid.init(inst, def);
|
|
39714
39832
|
ZodType2.init(inst, def);
|
|
39715
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39833
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => voidProcessor(inst, ctx, json3, params);
|
|
39716
39834
|
});
|
|
39717
39835
|
function _void2(params) {
|
|
39718
39836
|
return _void(ZodVoid2, params);
|
|
@@ -39723,7 +39841,7 @@ var ZodDate2 = /* @__PURE__ */ $constructor(
|
|
|
39723
39841
|
(inst, def) => {
|
|
39724
39842
|
$ZodDate.init(inst, def);
|
|
39725
39843
|
ZodType2.init(inst, def);
|
|
39726
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39844
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => dateProcessor(inst, ctx, json3, params);
|
|
39727
39845
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
39728
39846
|
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
39729
39847
|
},
|
|
@@ -39746,7 +39864,7 @@ var ZodArray2 = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
|
39746
39864
|
_ensureDefaultMemoizer();
|
|
39747
39865
|
$ZodArray.init(inst, def);
|
|
39748
39866
|
ZodType2.init(inst, def);
|
|
39749
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39867
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => arrayProcessor(inst, ctx, json3, params);
|
|
39750
39868
|
inst.element = def.element;
|
|
39751
39869
|
}, {
|
|
39752
39870
|
min(n, params) {
|
|
@@ -39778,7 +39896,7 @@ var ZodObject2 = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
|
39778
39896
|
_ensureDefaultMemoizer();
|
|
39779
39897
|
$ZodObjectJIT.init(inst, def);
|
|
39780
39898
|
ZodType2.init(inst, def);
|
|
39781
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39899
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => objectProcessor(inst, ctx, json3, params);
|
|
39782
39900
|
util_exports.installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
|
|
39783
39901
|
}, {
|
|
39784
39902
|
keyof() {
|
|
@@ -39854,7 +39972,7 @@ __name(looseObject, "looseObject");
|
|
|
39854
39972
|
var ZodUnion2 = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
39855
39973
|
$ZodUnion.init(inst, def);
|
|
39856
39974
|
ZodType2.init(inst, def);
|
|
39857
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39975
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
|
|
39858
39976
|
inst.options = def.options;
|
|
39859
39977
|
});
|
|
39860
39978
|
function union(options, params) {
|
|
@@ -39868,7 +39986,7 @@ __name(union, "union");
|
|
|
39868
39986
|
var ZodXor = /* @__PURE__ */ $constructor("ZodXor", (inst, def) => {
|
|
39869
39987
|
ZodUnion2.init(inst, def);
|
|
39870
39988
|
$ZodXor.init(inst, def);
|
|
39871
|
-
inst._zod.processJSONSchema = (ctx,
|
|
39989
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => unionProcessor(inst, ctx, json3, params);
|
|
39872
39990
|
inst.options = def.options;
|
|
39873
39991
|
});
|
|
39874
39992
|
function xor(options, params) {
|
|
@@ -39896,7 +40014,7 @@ __name(discriminatedUnion, "discriminatedUnion");
|
|
|
39896
40014
|
var ZodIntersection2 = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
39897
40015
|
$ZodIntersection.init(inst, def);
|
|
39898
40016
|
ZodType2.init(inst, def);
|
|
39899
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40017
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => intersectionProcessor(inst, ctx, json3, params);
|
|
39900
40018
|
});
|
|
39901
40019
|
function intersection(left, right) {
|
|
39902
40020
|
return new ZodIntersection2({
|
|
@@ -39910,7 +40028,7 @@ var ZodTuple2 = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
|
39910
40028
|
_ensureDefaultMemoizer();
|
|
39911
40029
|
$ZodTuple.init(inst, def);
|
|
39912
40030
|
ZodType2.init(inst, def);
|
|
39913
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40031
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => tupleProcessor(inst, ctx, json3, params);
|
|
39914
40032
|
}, {
|
|
39915
40033
|
rest(rest) {
|
|
39916
40034
|
return this.clone({
|
|
@@ -39944,7 +40062,7 @@ var ZodRecord2 = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
|
39944
40062
|
_ensureDefaultMemoizer();
|
|
39945
40063
|
$ZodRecord.init(inst, def);
|
|
39946
40064
|
ZodType2.init(inst, def);
|
|
39947
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40065
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => recordProcessor(inst, ctx, json3, params);
|
|
39948
40066
|
inst.keyType = def.keyType;
|
|
39949
40067
|
inst.valueType = def.valueType;
|
|
39950
40068
|
});
|
|
@@ -39989,7 +40107,7 @@ var ZodMap2 = /* @__PURE__ */ $constructor("ZodMap", (inst, def) => {
|
|
|
39989
40107
|
_ensureDefaultMemoizer();
|
|
39990
40108
|
$ZodMap.init(inst, def);
|
|
39991
40109
|
ZodType2.init(inst, def);
|
|
39992
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40110
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => mapProcessor(inst, ctx, json3, params);
|
|
39993
40111
|
inst.keyType = def.keyType;
|
|
39994
40112
|
inst.valueType = def.valueType;
|
|
39995
40113
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
@@ -40010,7 +40128,7 @@ var ZodSet2 = /* @__PURE__ */ $constructor("ZodSet", (inst, def) => {
|
|
|
40010
40128
|
_ensureDefaultMemoizer();
|
|
40011
40129
|
$ZodSet.init(inst, def);
|
|
40012
40130
|
ZodType2.init(inst, def);
|
|
40013
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40131
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => setProcessor(inst, ctx, json3, params);
|
|
40014
40132
|
inst.min = (...args) => inst.check(_minSize(...args));
|
|
40015
40133
|
inst.nonempty = (params) => inst.check(_minSize(1, params));
|
|
40016
40134
|
inst.max = (...args) => inst.check(_maxSize(...args));
|
|
@@ -40027,7 +40145,7 @@ __name(set, "set");
|
|
|
40027
40145
|
var ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
40028
40146
|
$ZodEnum.init(inst, def);
|
|
40029
40147
|
ZodType2.init(inst, def);
|
|
40030
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40148
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => enumProcessor(inst, ctx, json3, params);
|
|
40031
40149
|
inst.enum = def.entries;
|
|
40032
40150
|
inst.options = [...inst._zod.values];
|
|
40033
40151
|
const keys = new Set(Object.keys(def.entries));
|
|
@@ -40082,7 +40200,7 @@ __name(nativeEnum, "nativeEnum");
|
|
|
40082
40200
|
var ZodLiteral2 = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
|
|
40083
40201
|
$ZodLiteral.init(inst, def);
|
|
40084
40202
|
ZodType2.init(inst, def);
|
|
40085
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40203
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => literalProcessor(inst, ctx, json3, params);
|
|
40086
40204
|
inst.values = new Set(def.values);
|
|
40087
40205
|
Object.defineProperty(inst, "value", {
|
|
40088
40206
|
get() {
|
|
@@ -40104,7 +40222,7 @@ __name(literal, "literal");
|
|
|
40104
40222
|
var ZodFile = /* @__PURE__ */ $constructor("ZodFile", (inst, def) => {
|
|
40105
40223
|
$ZodFile.init(inst, def);
|
|
40106
40224
|
ZodType2.init(inst, def);
|
|
40107
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40225
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => fileProcessor(inst, ctx, json3, params);
|
|
40108
40226
|
inst.min = (size, params) => inst.check(_minSize(size, params));
|
|
40109
40227
|
inst.max = (size, params) => inst.check(_maxSize(size, params));
|
|
40110
40228
|
inst.mime = (types, params) => inst.check(_mime(Array.isArray(types) ? types : [types], params));
|
|
@@ -40117,7 +40235,7 @@ var ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
|
40117
40235
|
_ensureDefaultMemoizer();
|
|
40118
40236
|
$ZodTransform.init(inst, def);
|
|
40119
40237
|
ZodType2.init(inst, def);
|
|
40120
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40238
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => transformProcessor(inst, ctx, json3, params);
|
|
40121
40239
|
inst._zod.parse = (payload, _ctx) => {
|
|
40122
40240
|
if (_ctx.direction === "backward") {
|
|
40123
40241
|
throw new $ZodEncodeError(inst.constructor.name);
|
|
@@ -40157,7 +40275,7 @@ __name(transform, "transform");
|
|
|
40157
40275
|
var ZodOptional2 = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
40158
40276
|
$ZodOptional.init(inst, def);
|
|
40159
40277
|
ZodType2.init(inst, def);
|
|
40160
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40278
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
40161
40279
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40162
40280
|
});
|
|
40163
40281
|
function optional(innerType) {
|
|
@@ -40170,7 +40288,7 @@ __name(optional, "optional");
|
|
|
40170
40288
|
var ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
40171
40289
|
$ZodExactOptional.init(inst, def);
|
|
40172
40290
|
ZodType2.init(inst, def);
|
|
40173
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40291
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => optionalProcessor(inst, ctx, json3, params);
|
|
40174
40292
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40175
40293
|
});
|
|
40176
40294
|
function exactOptional(innerType) {
|
|
@@ -40183,7 +40301,7 @@ __name(exactOptional, "exactOptional");
|
|
|
40183
40301
|
var ZodNullable2 = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
40184
40302
|
$ZodNullable.init(inst, def);
|
|
40185
40303
|
ZodType2.init(inst, def);
|
|
40186
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40304
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nullableProcessor(inst, ctx, json3, params);
|
|
40187
40305
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40188
40306
|
});
|
|
40189
40307
|
function nullable(innerType) {
|
|
@@ -40200,7 +40318,7 @@ __name(nullish2, "nullish");
|
|
|
40200
40318
|
var ZodDefault2 = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
40201
40319
|
$ZodDefault.init(inst, def);
|
|
40202
40320
|
ZodType2.init(inst, def);
|
|
40203
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40321
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => defaultProcessor(inst, ctx, json3, params);
|
|
40204
40322
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40205
40323
|
inst.removeDefault = inst.unwrap;
|
|
40206
40324
|
});
|
|
@@ -40217,7 +40335,7 @@ __name(_default2, "_default");
|
|
|
40217
40335
|
var ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
40218
40336
|
$ZodPrefault.init(inst, def);
|
|
40219
40337
|
ZodType2.init(inst, def);
|
|
40220
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40338
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => prefaultProcessor(inst, ctx, json3, params);
|
|
40221
40339
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40222
40340
|
});
|
|
40223
40341
|
function prefault(innerType, defaultValue) {
|
|
@@ -40233,7 +40351,7 @@ __name(prefault, "prefault");
|
|
|
40233
40351
|
var ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
40234
40352
|
$ZodNonOptional.init(inst, def);
|
|
40235
40353
|
ZodType2.init(inst, def);
|
|
40236
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40354
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nonoptionalProcessor(inst, ctx, json3, params);
|
|
40237
40355
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40238
40356
|
});
|
|
40239
40357
|
function nonoptional(innerType, params) {
|
|
@@ -40247,7 +40365,7 @@ __name(nonoptional, "nonoptional");
|
|
|
40247
40365
|
var ZodSuccess = /* @__PURE__ */ $constructor("ZodSuccess", (inst, def) => {
|
|
40248
40366
|
$ZodSuccess.init(inst, def);
|
|
40249
40367
|
ZodType2.init(inst, def);
|
|
40250
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40368
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => successProcessor(inst, ctx, json3, params);
|
|
40251
40369
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40252
40370
|
});
|
|
40253
40371
|
function success(innerType) {
|
|
@@ -40260,7 +40378,7 @@ __name(success, "success");
|
|
|
40260
40378
|
var ZodCatch2 = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
40261
40379
|
$ZodCatch.init(inst, def);
|
|
40262
40380
|
ZodType2.init(inst, def);
|
|
40263
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40381
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => catchProcessor(inst, ctx, json3, params);
|
|
40264
40382
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40265
40383
|
inst.removeCatch = inst.unwrap;
|
|
40266
40384
|
});
|
|
@@ -40275,7 +40393,7 @@ __name(_catch2, "_catch");
|
|
|
40275
40393
|
var ZodNaN2 = /* @__PURE__ */ $constructor("ZodNaN", (inst, def) => {
|
|
40276
40394
|
$ZodNaN.init(inst, def);
|
|
40277
40395
|
ZodType2.init(inst, def);
|
|
40278
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40396
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => nanProcessor(inst, ctx, json3, params);
|
|
40279
40397
|
});
|
|
40280
40398
|
function nan(params) {
|
|
40281
40399
|
return _nan(ZodNaN2, params);
|
|
@@ -40284,7 +40402,7 @@ __name(nan, "nan");
|
|
|
40284
40402
|
var ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
40285
40403
|
$ZodPipe.init(inst, def);
|
|
40286
40404
|
ZodType2.init(inst, def);
|
|
40287
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40405
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => pipeProcessor(inst, ctx, json3, params);
|
|
40288
40406
|
inst.in = def.in;
|
|
40289
40407
|
inst.out = def.out;
|
|
40290
40408
|
});
|
|
@@ -40329,7 +40447,7 @@ var ZodPreprocess = /* @__PURE__ */ $constructor("ZodPreprocess", (inst, def) =>
|
|
|
40329
40447
|
var ZodReadonly2 = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
40330
40448
|
$ZodReadonly.init(inst, def);
|
|
40331
40449
|
ZodType2.init(inst, def);
|
|
40332
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40450
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => readonlyProcessor(inst, ctx, json3, params);
|
|
40333
40451
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40334
40452
|
});
|
|
40335
40453
|
function readonly(innerType) {
|
|
@@ -40342,7 +40460,7 @@ __name(readonly, "readonly");
|
|
|
40342
40460
|
var ZodTemplateLiteral = /* @__PURE__ */ $constructor("ZodTemplateLiteral", (inst, def) => {
|
|
40343
40461
|
$ZodTemplateLiteral.init(inst, def);
|
|
40344
40462
|
ZodType2.init(inst, def);
|
|
40345
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40463
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => templateLiteralProcessor(inst, ctx, json3, params);
|
|
40346
40464
|
});
|
|
40347
40465
|
function templateLiteral(parts, params) {
|
|
40348
40466
|
return new ZodTemplateLiteral({
|
|
@@ -40355,7 +40473,7 @@ __name(templateLiteral, "templateLiteral");
|
|
|
40355
40473
|
var ZodLazy2 = /* @__PURE__ */ $constructor("ZodLazy", (inst, def) => {
|
|
40356
40474
|
$ZodLazy.init(inst, def);
|
|
40357
40475
|
ZodType2.init(inst, def);
|
|
40358
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40476
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => lazyProcessor(inst, ctx, json3, params);
|
|
40359
40477
|
inst.unwrap = () => inst._zod.def.getter();
|
|
40360
40478
|
});
|
|
40361
40479
|
function lazy(getter) {
|
|
@@ -40368,7 +40486,7 @@ __name(lazy, "lazy");
|
|
|
40368
40486
|
var ZodPromise2 = /* @__PURE__ */ $constructor("ZodPromise", (inst, def) => {
|
|
40369
40487
|
$ZodPromise.init(inst, def);
|
|
40370
40488
|
ZodType2.init(inst, def);
|
|
40371
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40489
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => promiseProcessor(inst, ctx, json3, params);
|
|
40372
40490
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
40373
40491
|
});
|
|
40374
40492
|
function promise(innerType) {
|
|
@@ -40381,7 +40499,7 @@ __name(promise, "promise");
|
|
|
40381
40499
|
var ZodFunction2 = /* @__PURE__ */ $constructor("ZodFunction", (inst, def) => {
|
|
40382
40500
|
$ZodFunction.init(inst, def);
|
|
40383
40501
|
ZodType2.init(inst, def);
|
|
40384
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40502
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => functionProcessor(inst, ctx, json3, params);
|
|
40385
40503
|
});
|
|
40386
40504
|
function _function(params) {
|
|
40387
40505
|
return new ZodFunction2({
|
|
@@ -40394,7 +40512,7 @@ __name(_function, "_function");
|
|
|
40394
40512
|
var ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
40395
40513
|
$ZodCustom.init(inst, def);
|
|
40396
40514
|
ZodType2.init(inst, def);
|
|
40397
|
-
inst._zod.processJSONSchema = (ctx,
|
|
40515
|
+
inst._zod.processJSONSchema = (ctx, json3, params) => customProcessor(inst, ctx, json3, params);
|
|
40398
40516
|
});
|
|
40399
40517
|
function check(fn) {
|
|
40400
40518
|
const ch = new $ZodCheck({
|
|
@@ -41353,6 +41471,7 @@ __name(date4, "date");
|
|
|
41353
41471
|
|
|
41354
41472
|
// node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
41355
41473
|
var LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
41474
|
+
var DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
|
|
41356
41475
|
var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
41357
41476
|
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
41358
41477
|
var JSONRPC_VERSION = "2.0";
|
|
@@ -41681,6 +41800,7 @@ var InitializeRequestSchema = RequestSchema.extend({
|
|
|
41681
41800
|
method: literal("initialize"),
|
|
41682
41801
|
params: InitializeRequestParamsSchema
|
|
41683
41802
|
});
|
|
41803
|
+
var isInitializeRequest = /* @__PURE__ */ __name((value) => InitializeRequestSchema.safeParse(value).success, "isInitializeRequest");
|
|
41684
41804
|
var ServerCapabilitiesSchema = object2({
|
|
41685
41805
|
/**
|
|
41686
41806
|
* Experimental, non-standard capabilities that the server supports.
|
|
@@ -46987,8 +47107,8 @@ var StdioServerTransport = class {
|
|
|
46987
47107
|
}
|
|
46988
47108
|
send(message) {
|
|
46989
47109
|
return new Promise((resolve) => {
|
|
46990
|
-
const
|
|
46991
|
-
if (this._stdout.write(
|
|
47110
|
+
const json3 = serializeMessage(message);
|
|
47111
|
+
if (this._stdout.write(json3)) {
|
|
46992
47112
|
resolve();
|
|
46993
47113
|
} else {
|
|
46994
47114
|
this._stdout.once("drain", resolve);
|
|
@@ -46997,6 +47117,2156 @@ var StdioServerTransport = class {
|
|
|
46997
47117
|
}
|
|
46998
47118
|
};
|
|
46999
47119
|
|
|
47120
|
+
// node_modules/@hono/node-server/dist/constants-BLSFu_RU.mjs
|
|
47121
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
47122
|
+
|
|
47123
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
47124
|
+
var import_node_http = require("node:http");
|
|
47125
|
+
var import_node_http2 = require("node:http2");
|
|
47126
|
+
var import_node_stream = require("node:stream");
|
|
47127
|
+
|
|
47128
|
+
// node_modules/hono/dist/helper/websocket/index.js
|
|
47129
|
+
var defineWebSocketHelper = /* @__PURE__ */ __name((handler) => {
|
|
47130
|
+
return ((...args) => {
|
|
47131
|
+
if (typeof args[0] === "function") {
|
|
47132
|
+
const [createEvents, options] = args;
|
|
47133
|
+
return /* @__PURE__ */ __name(async function upgradeWebSocket2(c, next) {
|
|
47134
|
+
const result = await handler(c, await createEvents(c), options);
|
|
47135
|
+
if (result) return result;
|
|
47136
|
+
await next();
|
|
47137
|
+
}, "upgradeWebSocket");
|
|
47138
|
+
} else {
|
|
47139
|
+
const [c, events, options] = args;
|
|
47140
|
+
return (async () => {
|
|
47141
|
+
const upgraded = await handler(c, events, options);
|
|
47142
|
+
if (!upgraded) throw new Error("Failed to upgrade WebSocket");
|
|
47143
|
+
return upgraded;
|
|
47144
|
+
})();
|
|
47145
|
+
}
|
|
47146
|
+
});
|
|
47147
|
+
}, "defineWebSocketHelper");
|
|
47148
|
+
|
|
47149
|
+
// node_modules/@hono/node-server/dist/index.mjs
|
|
47150
|
+
var RequestError = class extends Error {
|
|
47151
|
+
static {
|
|
47152
|
+
__name(this, "RequestError");
|
|
47153
|
+
}
|
|
47154
|
+
constructor(message, options) {
|
|
47155
|
+
super(message, options);
|
|
47156
|
+
this.name = "RequestError";
|
|
47157
|
+
}
|
|
47158
|
+
};
|
|
47159
|
+
var nonJoinedHeaders = /* @__PURE__ */ new Set([
|
|
47160
|
+
"age",
|
|
47161
|
+
"authorization",
|
|
47162
|
+
"content-length",
|
|
47163
|
+
"content-type",
|
|
47164
|
+
"etag",
|
|
47165
|
+
"expires",
|
|
47166
|
+
"from",
|
|
47167
|
+
"host",
|
|
47168
|
+
"if-modified-since",
|
|
47169
|
+
"if-unmodified-since",
|
|
47170
|
+
"last-modified",
|
|
47171
|
+
"location",
|
|
47172
|
+
"max-forwards",
|
|
47173
|
+
"proxy-authorization",
|
|
47174
|
+
"referer",
|
|
47175
|
+
"retry-after",
|
|
47176
|
+
"server",
|
|
47177
|
+
"user-agent"
|
|
47178
|
+
]);
|
|
47179
|
+
var validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
|
|
47180
|
+
var isHttpWhitespace = /* @__PURE__ */ __name((code) => code === 9 || code === 10 || code === 13 || code === 32, "isHttpWhitespace");
|
|
47181
|
+
var normalizeHeaderValue = /* @__PURE__ */ __name((value) => {
|
|
47182
|
+
if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1))) return value;
|
|
47183
|
+
let start = 0;
|
|
47184
|
+
let end = value.length;
|
|
47185
|
+
while (start < end && isHttpWhitespace(value.charCodeAt(start))) start++;
|
|
47186
|
+
while (end > start && isHttpWhitespace(value.charCodeAt(end - 1))) end--;
|
|
47187
|
+
return value.slice(start, end);
|
|
47188
|
+
}, "normalizeHeaderValue");
|
|
47189
|
+
var forbiddenHeaderValue = /[\0\r\n]/;
|
|
47190
|
+
var GlobalHeaders = globalThis.Headers;
|
|
47191
|
+
var materializeHeaders = /* @__PURE__ */ __name((rawHeaders, HeadersCtor = GlobalHeaders) => {
|
|
47192
|
+
const headers = new HeadersCtor();
|
|
47193
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
47194
|
+
const name = rawHeaders[i];
|
|
47195
|
+
if (!name.startsWith(":")) headers.append(name, rawHeaders[i + 1]);
|
|
47196
|
+
}
|
|
47197
|
+
return headers;
|
|
47198
|
+
}, "materializeHeaders");
|
|
47199
|
+
var RequestHeaders = class {
|
|
47200
|
+
static {
|
|
47201
|
+
__name(this, "RequestHeaders");
|
|
47202
|
+
}
|
|
47203
|
+
#incoming;
|
|
47204
|
+
#rawHeaders;
|
|
47205
|
+
#headers;
|
|
47206
|
+
#invalidValue;
|
|
47207
|
+
constructor(incoming) {
|
|
47208
|
+
this.#incoming = incoming;
|
|
47209
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) this.#rawHeaders = incoming.rawHeaders.slice();
|
|
47210
|
+
}
|
|
47211
|
+
get #lazyRawHeaders() {
|
|
47212
|
+
return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
|
|
47213
|
+
}
|
|
47214
|
+
get #native() {
|
|
47215
|
+
if (!this.#headers) {
|
|
47216
|
+
this.#headers = materializeHeaders(this.#lazyRawHeaders);
|
|
47217
|
+
this.#rawHeaders = void 0;
|
|
47218
|
+
}
|
|
47219
|
+
return this.#headers;
|
|
47220
|
+
}
|
|
47221
|
+
#normalizedName(name) {
|
|
47222
|
+
if (typeof name !== "string") return;
|
|
47223
|
+
if (!validHeaderName.test(name)) throw new TypeError(`Invalid header name: ${name}`);
|
|
47224
|
+
return name.toLowerCase();
|
|
47225
|
+
}
|
|
47226
|
+
#lookupHttp1(lowerName) {
|
|
47227
|
+
const headers = this.#incoming instanceof import_node_http2.Http2ServerRequest ? void 0 : this.#incoming.headers;
|
|
47228
|
+
if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__") return;
|
|
47229
|
+
if (!Object.hasOwn(headers, lowerName)) return null;
|
|
47230
|
+
const rawValue = headers[lowerName];
|
|
47231
|
+
if (typeof rawValue === "string") {
|
|
47232
|
+
const value = normalizeHeaderValue(rawValue);
|
|
47233
|
+
return forbiddenHeaderValue.test(value) ? void 0 : value;
|
|
47234
|
+
}
|
|
47235
|
+
}
|
|
47236
|
+
#lookup(rawHeaders, lowerName) {
|
|
47237
|
+
const separator = lowerName === "cookie" ? "; " : ", ";
|
|
47238
|
+
let value = null;
|
|
47239
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
47240
|
+
const rawName = rawHeaders[i];
|
|
47241
|
+
if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
|
|
47242
|
+
const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
|
|
47243
|
+
if (forbiddenHeaderValue.test(rawValue)) {
|
|
47244
|
+
this.#invalidValue = true;
|
|
47245
|
+
return;
|
|
47246
|
+
}
|
|
47247
|
+
value = value === null ? rawValue : value + separator + rawValue;
|
|
47248
|
+
}
|
|
47249
|
+
}
|
|
47250
|
+
return value;
|
|
47251
|
+
}
|
|
47252
|
+
append(name, value) {
|
|
47253
|
+
this.#native.append(name, value);
|
|
47254
|
+
}
|
|
47255
|
+
delete(name) {
|
|
47256
|
+
this.#native.delete(name);
|
|
47257
|
+
}
|
|
47258
|
+
get(name) {
|
|
47259
|
+
const lowerName = this.#normalizedName(name);
|
|
47260
|
+
if (lowerName && !this.#headers && !this.#invalidValue) {
|
|
47261
|
+
const http1Value = this.#lookupHttp1(lowerName);
|
|
47262
|
+
if (http1Value !== void 0) return http1Value;
|
|
47263
|
+
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
|
|
47264
|
+
if (value !== void 0) return value;
|
|
47265
|
+
}
|
|
47266
|
+
return this.#native.get(name);
|
|
47267
|
+
}
|
|
47268
|
+
has(name) {
|
|
47269
|
+
const lowerName = this.#normalizedName(name);
|
|
47270
|
+
if (lowerName && !this.#headers && !this.#invalidValue) {
|
|
47271
|
+
const http1Value = this.#lookupHttp1(lowerName);
|
|
47272
|
+
if (http1Value !== void 0) return http1Value !== null;
|
|
47273
|
+
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
|
|
47274
|
+
if (value !== void 0) return value !== null;
|
|
47275
|
+
}
|
|
47276
|
+
return this.#native.has(name);
|
|
47277
|
+
}
|
|
47278
|
+
set(name, value) {
|
|
47279
|
+
this.#native.set(name, value);
|
|
47280
|
+
}
|
|
47281
|
+
getSetCookie() {
|
|
47282
|
+
return this.#native.getSetCookie();
|
|
47283
|
+
}
|
|
47284
|
+
keys() {
|
|
47285
|
+
return this.#native.keys();
|
|
47286
|
+
}
|
|
47287
|
+
values() {
|
|
47288
|
+
return this.#native.values();
|
|
47289
|
+
}
|
|
47290
|
+
entries() {
|
|
47291
|
+
return this.#native.entries();
|
|
47292
|
+
}
|
|
47293
|
+
forEach(callback, thisArg) {
|
|
47294
|
+
this.#native.forEach((value, key) => {
|
|
47295
|
+
callback.call(thisArg, value, key, this);
|
|
47296
|
+
});
|
|
47297
|
+
}
|
|
47298
|
+
[Symbol.iterator]() {
|
|
47299
|
+
return this.entries();
|
|
47300
|
+
}
|
|
47301
|
+
};
|
|
47302
|
+
Object.defineProperty(RequestHeaders.prototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47303
|
+
return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
|
|
47304
|
+
...options,
|
|
47305
|
+
depth: depth == null ? null : depth - 1
|
|
47306
|
+
})}`;
|
|
47307
|
+
}, "value") });
|
|
47308
|
+
Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
|
|
47309
|
+
var newHeadersFromIncoming = /* @__PURE__ */ __name((incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers), "newHeadersFromIncoming");
|
|
47310
|
+
var reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
|
|
47311
|
+
var reDotSegment = /\/\.\.?(?:[/?#]|$)/;
|
|
47312
|
+
var reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
|
|
47313
|
+
var buildUrl = /* @__PURE__ */ __name((scheme, host, incomingUrl) => {
|
|
47314
|
+
const url2 = `${scheme}://${host}${incomingUrl}`;
|
|
47315
|
+
if (!reValidHost.test(host)) {
|
|
47316
|
+
const urlObj = new URL(url2);
|
|
47317
|
+
if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
|
|
47318
|
+
return urlObj.href;
|
|
47319
|
+
} else if (incomingUrl.length === 0) return url2 + "/";
|
|
47320
|
+
else {
|
|
47321
|
+
if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
|
|
47322
|
+
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) return new URL(url2).href;
|
|
47323
|
+
return url2;
|
|
47324
|
+
}
|
|
47325
|
+
}, "buildUrl");
|
|
47326
|
+
var toRequestError = /* @__PURE__ */ __name((e) => {
|
|
47327
|
+
if (e instanceof RequestError) return e;
|
|
47328
|
+
return new RequestError(e.message, { cause: e });
|
|
47329
|
+
}, "toRequestError");
|
|
47330
|
+
var GlobalRequest = global.Request;
|
|
47331
|
+
var Request$1 = class extends GlobalRequest {
|
|
47332
|
+
static {
|
|
47333
|
+
__name(this, "Request$1");
|
|
47334
|
+
}
|
|
47335
|
+
constructor(input2, options) {
|
|
47336
|
+
if (typeof input2 === "object" && getRequestCache in input2) {
|
|
47337
|
+
const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
|
|
47338
|
+
if (input2[bodyConsumedDirectlyKey] && !hasReplacementBody) throw new TypeError("Cannot construct a Request with a Request object that has already been used.");
|
|
47339
|
+
input2 = input2[getRequestCache]();
|
|
47340
|
+
}
|
|
47341
|
+
if (typeof options?.body?.getReader !== "undefined") options.duplex ??= "half";
|
|
47342
|
+
super(input2, options);
|
|
47343
|
+
}
|
|
47344
|
+
};
|
|
47345
|
+
var wrapBodyStream = /* @__PURE__ */ Symbol("wrapBodyStream");
|
|
47346
|
+
var byteExactEncodings = /* @__PURE__ */ new Set([
|
|
47347
|
+
"latin1",
|
|
47348
|
+
"binary",
|
|
47349
|
+
"hex",
|
|
47350
|
+
"base64",
|
|
47351
|
+
"base64url"
|
|
47352
|
+
]);
|
|
47353
|
+
var isByteExactEncoding = /* @__PURE__ */ __name((encoding) => encoding === null || byteExactEncodings.has(encoding), "isByteExactEncoding");
|
|
47354
|
+
var bodyBufferedBeforeDisconnectKey = /* @__PURE__ */ Symbol("bodyBufferedBeforeDisconnect");
|
|
47355
|
+
var bodyBufferedLengthBeforeDisconnectKey = /* @__PURE__ */ Symbol("bodyBufferedLengthBeforeDisconnect");
|
|
47356
|
+
var toBufferChunk = /* @__PURE__ */ __name((chunk, encoding) => Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding ?? "utf8"), "toBufferChunk");
|
|
47357
|
+
var isRecoverableDisconnectedIncoming = /* @__PURE__ */ __name((incoming) => !(incoming instanceof import_node_http2.Http2ServerRequest) && !!incoming.complete && !!incoming.readableAborted && typeof incoming.read === "function" && isByteExactEncoding(incoming.readableEncoding), "isRecoverableDisconnectedIncoming");
|
|
47358
|
+
var recordBodyBufferedBeforeDisconnect = /* @__PURE__ */ __name((incoming) => {
|
|
47359
|
+
if (incoming.readableDidRead || !isRecoverableDisconnectedIncoming(incoming)) return;
|
|
47360
|
+
const incomingWithRecovery = incoming;
|
|
47361
|
+
incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] ??= incoming.readableLength;
|
|
47362
|
+
}, "recordBodyBufferedBeforeDisconnect");
|
|
47363
|
+
var readBodyBufferedBeforeDisconnect = /* @__PURE__ */ __name((incoming, chunks) => {
|
|
47364
|
+
if (incoming.readableDidRead && !chunks || !isRecoverableDisconnectedIncoming(incoming)) return;
|
|
47365
|
+
const incomingWithRecovery = incoming;
|
|
47366
|
+
if (incomingWithRecovery[bodyBufferedBeforeDisconnectKey] !== void 0) return incomingWithRecovery[bodyBufferedBeforeDisconnectKey];
|
|
47367
|
+
let result;
|
|
47368
|
+
const errored = incoming.errored;
|
|
47369
|
+
if (errored && errored.code !== "ECONNRESET") result = errored;
|
|
47370
|
+
else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== void 0 && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey]) result = newBodyUnusableError();
|
|
47371
|
+
else {
|
|
47372
|
+
const bodyChunks = chunks ?? [];
|
|
47373
|
+
const chunk = incoming.read();
|
|
47374
|
+
if (chunk !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
47375
|
+
const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
|
|
47376
|
+
result = buffer;
|
|
47377
|
+
const contentLength = incoming.headers["content-length"];
|
|
47378
|
+
if (typeof contentLength === "string" && /^\d+$/.test(contentLength)) {
|
|
47379
|
+
const expectedLength = Number(contentLength);
|
|
47380
|
+
if (Number.isSafeInteger(expectedLength) && buffer.length !== expectedLength) result = newBodyUnusableError();
|
|
47381
|
+
}
|
|
47382
|
+
}
|
|
47383
|
+
incomingWithRecovery[bodyBufferedBeforeDisconnectKey] = result;
|
|
47384
|
+
return result;
|
|
47385
|
+
}, "readBodyBufferedBeforeDisconnect");
|
|
47386
|
+
var enqueueBufferedBody = /* @__PURE__ */ __name((controller, buffered) => {
|
|
47387
|
+
if (buffered instanceof Error) {
|
|
47388
|
+
controller.error(buffered);
|
|
47389
|
+
return;
|
|
47390
|
+
}
|
|
47391
|
+
if (buffered.length > 0) controller.enqueue(buffered);
|
|
47392
|
+
controller.close();
|
|
47393
|
+
}, "enqueueBufferedBody");
|
|
47394
|
+
var newRequestFromIncoming = /* @__PURE__ */ __name((method, url2, headers, incoming, abortController) => {
|
|
47395
|
+
const init = {
|
|
47396
|
+
method,
|
|
47397
|
+
headers,
|
|
47398
|
+
signal: abortController.signal
|
|
47399
|
+
};
|
|
47400
|
+
if (method === "TRACE") {
|
|
47401
|
+
init.method = "GET";
|
|
47402
|
+
const req = new Request$1(url2, init);
|
|
47403
|
+
Object.defineProperty(req, "method", { get() {
|
|
47404
|
+
return "TRACE";
|
|
47405
|
+
} });
|
|
47406
|
+
return req;
|
|
47407
|
+
}
|
|
47408
|
+
if (!(method === "GET" || method === "HEAD")) if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) init.body = new ReadableStream({ start(controller) {
|
|
47409
|
+
controller.enqueue(incoming.rawBody);
|
|
47410
|
+
controller.close();
|
|
47411
|
+
} });
|
|
47412
|
+
else if (incoming[wrapBodyStream]) {
|
|
47413
|
+
let reader;
|
|
47414
|
+
init.body = new ReadableStream({ async pull(controller) {
|
|
47415
|
+
try {
|
|
47416
|
+
if (!reader) {
|
|
47417
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47418
|
+
if (buffered !== void 0) {
|
|
47419
|
+
enqueueBufferedBody(controller, buffered);
|
|
47420
|
+
return;
|
|
47421
|
+
}
|
|
47422
|
+
}
|
|
47423
|
+
reader ||= import_node_stream.Readable.toWeb(incoming).getReader();
|
|
47424
|
+
const { done, value } = await reader.read();
|
|
47425
|
+
if (done) controller.close();
|
|
47426
|
+
else controller.enqueue(value);
|
|
47427
|
+
} catch (error62) {
|
|
47428
|
+
controller.error(error62);
|
|
47429
|
+
}
|
|
47430
|
+
} });
|
|
47431
|
+
} else {
|
|
47432
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47433
|
+
if (buffered !== void 0) init.body = new ReadableStream({ start(controller) {
|
|
47434
|
+
enqueueBufferedBody(controller, buffered);
|
|
47435
|
+
} });
|
|
47436
|
+
else init.body = import_node_stream.Readable.toWeb(incoming);
|
|
47437
|
+
}
|
|
47438
|
+
return new Request$1(url2, init);
|
|
47439
|
+
}, "newRequestFromIncoming");
|
|
47440
|
+
var getRequestCache = /* @__PURE__ */ Symbol("getRequestCache");
|
|
47441
|
+
var requestCache = /* @__PURE__ */ Symbol("requestCache");
|
|
47442
|
+
var incomingKey = /* @__PURE__ */ Symbol("incomingKey");
|
|
47443
|
+
var urlKey = /* @__PURE__ */ Symbol("urlKey");
|
|
47444
|
+
var methodKey = /* @__PURE__ */ Symbol("methodKey");
|
|
47445
|
+
var headersKey = /* @__PURE__ */ Symbol("headersKey");
|
|
47446
|
+
var abortControllerKey = /* @__PURE__ */ Symbol("abortControllerKey");
|
|
47447
|
+
var getAbortController = /* @__PURE__ */ Symbol("getAbortController");
|
|
47448
|
+
var abortRequest = /* @__PURE__ */ Symbol("abortRequest");
|
|
47449
|
+
var bodyBufferKey = /* @__PURE__ */ Symbol("bodyBuffer");
|
|
47450
|
+
var bodyReadPromiseKey = /* @__PURE__ */ Symbol("bodyReadPromise");
|
|
47451
|
+
var bodyConsumedDirectlyKey = /* @__PURE__ */ Symbol("bodyConsumedDirectly");
|
|
47452
|
+
var bodyLockReaderKey = /* @__PURE__ */ Symbol("bodyLockReader");
|
|
47453
|
+
var abortReasonKey = /* @__PURE__ */ Symbol("abortReason");
|
|
47454
|
+
var newBodyUnusableError = /* @__PURE__ */ __name(() => {
|
|
47455
|
+
return /* @__PURE__ */ new TypeError("Body is unusable");
|
|
47456
|
+
}, "newBodyUnusableError");
|
|
47457
|
+
var rejectBodyUnusable = /* @__PURE__ */ __name(() => {
|
|
47458
|
+
return Promise.reject(newBodyUnusableError());
|
|
47459
|
+
}, "rejectBodyUnusable");
|
|
47460
|
+
var textDecoder = new TextDecoder();
|
|
47461
|
+
var consumeBodyDirectOnce = /* @__PURE__ */ __name((request) => {
|
|
47462
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47463
|
+
request[bodyConsumedDirectlyKey] = true;
|
|
47464
|
+
}, "consumeBodyDirectOnce");
|
|
47465
|
+
var toArrayBuffer = /* @__PURE__ */ __name((buf) => {
|
|
47466
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
47467
|
+
}, "toArrayBuffer");
|
|
47468
|
+
var contentType = /* @__PURE__ */ __name((request) => {
|
|
47469
|
+
return (request[headersKey] ||= newHeadersFromIncoming(request[incomingKey])).get("content-type") || "";
|
|
47470
|
+
}, "contentType");
|
|
47471
|
+
var methodTokenRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
47472
|
+
var normalizeIncomingMethod = /* @__PURE__ */ __name((method) => {
|
|
47473
|
+
if (typeof method !== "string" || method.length === 0) return "GET";
|
|
47474
|
+
switch (method) {
|
|
47475
|
+
case "DELETE":
|
|
47476
|
+
case "GET":
|
|
47477
|
+
case "HEAD":
|
|
47478
|
+
case "OPTIONS":
|
|
47479
|
+
case "PATCH":
|
|
47480
|
+
case "POST":
|
|
47481
|
+
case "PUT":
|
|
47482
|
+
case "QUERY":
|
|
47483
|
+
return method;
|
|
47484
|
+
}
|
|
47485
|
+
const upper = method.toUpperCase();
|
|
47486
|
+
switch (upper) {
|
|
47487
|
+
case "DELETE":
|
|
47488
|
+
case "GET":
|
|
47489
|
+
case "HEAD":
|
|
47490
|
+
case "OPTIONS":
|
|
47491
|
+
case "POST":
|
|
47492
|
+
case "PUT":
|
|
47493
|
+
return upper;
|
|
47494
|
+
default:
|
|
47495
|
+
return method;
|
|
47496
|
+
}
|
|
47497
|
+
}, "normalizeIncomingMethod");
|
|
47498
|
+
var validateDirectReadMethod = /* @__PURE__ */ __name((method) => {
|
|
47499
|
+
if (!methodTokenRegExp.test(method)) return /* @__PURE__ */ new TypeError(`'${method}' is not a valid HTTP method.`);
|
|
47500
|
+
const normalized = method.toUpperCase();
|
|
47501
|
+
if (normalized === "CONNECT" || normalized === "TRACK" || normalized === "TRACE" && method !== "TRACE") return /* @__PURE__ */ new TypeError(`'${method}' HTTP method is unsupported.`);
|
|
47502
|
+
}, "validateDirectReadMethod");
|
|
47503
|
+
var readBodyWithFastPath = /* @__PURE__ */ __name((request, method, fromBuffer) => {
|
|
47504
|
+
if (request[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47505
|
+
const methodName = request.method;
|
|
47506
|
+
if (methodName === "GET" || methodName === "HEAD") return request[getRequestCache]()[method]();
|
|
47507
|
+
const methodValidationError = validateDirectReadMethod(methodName);
|
|
47508
|
+
if (methodValidationError) return Promise.reject(methodValidationError);
|
|
47509
|
+
if (request[requestCache]) {
|
|
47510
|
+
if (methodName !== "TRACE") return request[requestCache][method]();
|
|
47511
|
+
}
|
|
47512
|
+
const alreadyUsedError = consumeBodyDirectOnce(request);
|
|
47513
|
+
if (alreadyUsedError) return alreadyUsedError;
|
|
47514
|
+
const raw = readRawBodyIfAvailable(request);
|
|
47515
|
+
if (raw) {
|
|
47516
|
+
const result = Promise.resolve(fromBuffer(raw, request));
|
|
47517
|
+
request[bodyBufferKey] = void 0;
|
|
47518
|
+
return result;
|
|
47519
|
+
}
|
|
47520
|
+
return readBodyDirect(request).then((buf) => {
|
|
47521
|
+
const result = fromBuffer(buf, request);
|
|
47522
|
+
request[bodyBufferKey] = void 0;
|
|
47523
|
+
return result;
|
|
47524
|
+
});
|
|
47525
|
+
}, "readBodyWithFastPath");
|
|
47526
|
+
var readRawBodyIfAvailable = /* @__PURE__ */ __name((request) => {
|
|
47527
|
+
const incoming = request[incomingKey];
|
|
47528
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) return incoming.rawBody;
|
|
47529
|
+
}, "readRawBodyIfAvailable");
|
|
47530
|
+
var normalizeAbortError = /* @__PURE__ */ __name((request, incoming) => {
|
|
47531
|
+
if (incoming.errored) return incoming.errored;
|
|
47532
|
+
const reason = request[abortReasonKey];
|
|
47533
|
+
if (reason !== void 0) return reason instanceof Error ? reason : new Error(String(reason));
|
|
47534
|
+
return /* @__PURE__ */ new Error("Client connection prematurely closed.");
|
|
47535
|
+
}, "normalizeAbortError");
|
|
47536
|
+
var readBodyDirect = /* @__PURE__ */ __name((request) => {
|
|
47537
|
+
if (request[bodyBufferKey]) return Promise.resolve(request[bodyBufferKey]);
|
|
47538
|
+
if (request[bodyReadPromiseKey]) return request[bodyReadPromiseKey];
|
|
47539
|
+
const incoming = request[incomingKey];
|
|
47540
|
+
if (incoming.readableDidRead) return rejectBodyUnusable();
|
|
47541
|
+
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
47542
|
+
if (buffered !== void 0) {
|
|
47543
|
+
if (buffered instanceof Error) return Promise.reject(buffered);
|
|
47544
|
+
request[bodyBufferKey] = buffered;
|
|
47545
|
+
return Promise.resolve(buffered);
|
|
47546
|
+
}
|
|
47547
|
+
const promise2 = new Promise((resolve, reject) => {
|
|
47548
|
+
const chunks = [];
|
|
47549
|
+
let settled = false;
|
|
47550
|
+
const finish = /* @__PURE__ */ __name((callback) => {
|
|
47551
|
+
if (settled) return;
|
|
47552
|
+
settled = true;
|
|
47553
|
+
cleanup();
|
|
47554
|
+
callback();
|
|
47555
|
+
}, "finish");
|
|
47556
|
+
const recoverCompleteBodyAfterDisconnect = /* @__PURE__ */ __name((error62) => {
|
|
47557
|
+
const streamError = incoming.errored ?? error62;
|
|
47558
|
+
if (!isRecoverableDisconnectedIncoming(incoming) || streamError && streamError.code !== "ECONNRESET") return false;
|
|
47559
|
+
finish(() => {
|
|
47560
|
+
const recovered = readBodyBufferedBeforeDisconnect(incoming, chunks);
|
|
47561
|
+
if (recovered instanceof Error) reject(recovered);
|
|
47562
|
+
else if (recovered === void 0) reject(error62 ?? normalizeAbortError(request, incoming));
|
|
47563
|
+
else {
|
|
47564
|
+
request[bodyBufferKey] = recovered;
|
|
47565
|
+
resolve(recovered);
|
|
47566
|
+
}
|
|
47567
|
+
});
|
|
47568
|
+
return true;
|
|
47569
|
+
}, "recoverCompleteBodyAfterDisconnect");
|
|
47570
|
+
const onData = /* @__PURE__ */ __name((chunk) => {
|
|
47571
|
+
chunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
47572
|
+
}, "onData");
|
|
47573
|
+
const onEnd = /* @__PURE__ */ __name(() => {
|
|
47574
|
+
finish(() => {
|
|
47575
|
+
const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);
|
|
47576
|
+
request[bodyBufferKey] = buffer;
|
|
47577
|
+
resolve(buffer);
|
|
47578
|
+
});
|
|
47579
|
+
}, "onEnd");
|
|
47580
|
+
const onError = /* @__PURE__ */ __name((error62) => {
|
|
47581
|
+
if (recoverCompleteBodyAfterDisconnect(error62)) return;
|
|
47582
|
+
finish(() => {
|
|
47583
|
+
reject(error62);
|
|
47584
|
+
});
|
|
47585
|
+
}, "onError");
|
|
47586
|
+
const onClose = /* @__PURE__ */ __name(() => {
|
|
47587
|
+
if (incoming.readableEnded) {
|
|
47588
|
+
onEnd();
|
|
47589
|
+
return;
|
|
47590
|
+
}
|
|
47591
|
+
if (recoverCompleteBodyAfterDisconnect()) return;
|
|
47592
|
+
finish(() => {
|
|
47593
|
+
reject(normalizeAbortError(request, incoming));
|
|
47594
|
+
});
|
|
47595
|
+
}, "onClose");
|
|
47596
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
47597
|
+
incoming.off("data", onData);
|
|
47598
|
+
incoming.off("end", onEnd);
|
|
47599
|
+
incoming.off("error", onError);
|
|
47600
|
+
incoming.off("close", onClose);
|
|
47601
|
+
request[bodyReadPromiseKey] = void 0;
|
|
47602
|
+
}, "cleanup");
|
|
47603
|
+
incoming.on("data", onData);
|
|
47604
|
+
incoming.on("end", onEnd);
|
|
47605
|
+
incoming.on("error", onError);
|
|
47606
|
+
incoming.on("close", onClose);
|
|
47607
|
+
queueMicrotask(() => {
|
|
47608
|
+
if (settled) return;
|
|
47609
|
+
if (incoming.readableEnded) onEnd();
|
|
47610
|
+
else if (incoming.errored) onError(incoming.errored);
|
|
47611
|
+
else if (incoming.destroyed) onClose();
|
|
47612
|
+
});
|
|
47613
|
+
});
|
|
47614
|
+
request[bodyReadPromiseKey] = promise2;
|
|
47615
|
+
return promise2;
|
|
47616
|
+
}, "readBodyDirect");
|
|
47617
|
+
var requestPrototype = {
|
|
47618
|
+
get method() {
|
|
47619
|
+
return this[methodKey];
|
|
47620
|
+
},
|
|
47621
|
+
get url() {
|
|
47622
|
+
return this[urlKey];
|
|
47623
|
+
},
|
|
47624
|
+
get headers() {
|
|
47625
|
+
return this[headersKey] ||= newHeadersFromIncoming(this[incomingKey]);
|
|
47626
|
+
},
|
|
47627
|
+
[abortRequest](reason) {
|
|
47628
|
+
if (this[abortReasonKey] === void 0) this[abortReasonKey] = reason;
|
|
47629
|
+
const abortController = this[abortControllerKey];
|
|
47630
|
+
if (abortController && !abortController.signal.aborted) abortController.abort(reason);
|
|
47631
|
+
},
|
|
47632
|
+
[getAbortController]() {
|
|
47633
|
+
this[abortControllerKey] ||= new AbortController();
|
|
47634
|
+
if (this[abortReasonKey] !== void 0 && !this[abortControllerKey].signal.aborted) this[abortControllerKey].abort(this[abortReasonKey]);
|
|
47635
|
+
return this[abortControllerKey];
|
|
47636
|
+
},
|
|
47637
|
+
[getRequestCache]() {
|
|
47638
|
+
const abortController = this[getAbortController]();
|
|
47639
|
+
if (this[requestCache]) return this[requestCache];
|
|
47640
|
+
const method = this.method;
|
|
47641
|
+
if (this[bodyConsumedDirectlyKey] && !(method === "GET" || method === "HEAD")) {
|
|
47642
|
+
this[bodyBufferKey] = void 0;
|
|
47643
|
+
const init = {
|
|
47644
|
+
method: method === "TRACE" ? "GET" : method,
|
|
47645
|
+
headers: this.headers,
|
|
47646
|
+
signal: abortController.signal
|
|
47647
|
+
};
|
|
47648
|
+
if (method !== "TRACE") {
|
|
47649
|
+
init.body = new ReadableStream({ start(c) {
|
|
47650
|
+
c.close();
|
|
47651
|
+
} });
|
|
47652
|
+
init.duplex = "half";
|
|
47653
|
+
}
|
|
47654
|
+
const req = new Request$1(this[urlKey], init);
|
|
47655
|
+
if (method === "TRACE") Object.defineProperty(req, "method", { get() {
|
|
47656
|
+
return "TRACE";
|
|
47657
|
+
} });
|
|
47658
|
+
return this[requestCache] = req;
|
|
47659
|
+
}
|
|
47660
|
+
return this[requestCache] = newRequestFromIncoming(this.method, this[urlKey], this.headers, this[incomingKey], abortController);
|
|
47661
|
+
},
|
|
47662
|
+
get body() {
|
|
47663
|
+
if (!this[bodyConsumedDirectlyKey]) return this[getRequestCache]().body;
|
|
47664
|
+
const request = this[getRequestCache]();
|
|
47665
|
+
if (!this[bodyLockReaderKey] && request.body) this[bodyLockReaderKey] = request.body.getReader();
|
|
47666
|
+
return request.body;
|
|
47667
|
+
},
|
|
47668
|
+
get bodyUsed() {
|
|
47669
|
+
if (this[bodyConsumedDirectlyKey]) return true;
|
|
47670
|
+
if (this[requestCache]) return this[requestCache].bodyUsed;
|
|
47671
|
+
return false;
|
|
47672
|
+
}
|
|
47673
|
+
};
|
|
47674
|
+
Object.defineProperty(requestPrototype, "signal", { get() {
|
|
47675
|
+
return this[getAbortController]().signal;
|
|
47676
|
+
} });
|
|
47677
|
+
[
|
|
47678
|
+
"cache",
|
|
47679
|
+
"credentials",
|
|
47680
|
+
"destination",
|
|
47681
|
+
"integrity",
|
|
47682
|
+
"mode",
|
|
47683
|
+
"redirect",
|
|
47684
|
+
"referrer",
|
|
47685
|
+
"referrerPolicy",
|
|
47686
|
+
"keepalive"
|
|
47687
|
+
].forEach((k) => {
|
|
47688
|
+
Object.defineProperty(requestPrototype, k, { get() {
|
|
47689
|
+
return this[getRequestCache]()[k];
|
|
47690
|
+
} });
|
|
47691
|
+
});
|
|
47692
|
+
["clone", "formData"].forEach((k) => {
|
|
47693
|
+
Object.defineProperty(requestPrototype, k, { value: /* @__PURE__ */ __name(function() {
|
|
47694
|
+
if (this[bodyConsumedDirectlyKey]) {
|
|
47695
|
+
if (k === "clone") throw newBodyUnusableError();
|
|
47696
|
+
return rejectBodyUnusable();
|
|
47697
|
+
}
|
|
47698
|
+
return this[getRequestCache]()[k]();
|
|
47699
|
+
}, "value") });
|
|
47700
|
+
});
|
|
47701
|
+
Object.defineProperty(requestPrototype, "text", { value: /* @__PURE__ */ __name(function() {
|
|
47702
|
+
return readBodyWithFastPath(this, "text", (buf) => textDecoder.decode(buf));
|
|
47703
|
+
}, "value") });
|
|
47704
|
+
Object.defineProperty(requestPrototype, "arrayBuffer", { value: /* @__PURE__ */ __name(function() {
|
|
47705
|
+
return readBodyWithFastPath(this, "arrayBuffer", (buf) => toArrayBuffer(buf));
|
|
47706
|
+
}, "value") });
|
|
47707
|
+
Object.defineProperty(requestPrototype, "blob", { value: /* @__PURE__ */ __name(function() {
|
|
47708
|
+
return readBodyWithFastPath(this, "blob", (buf, request) => {
|
|
47709
|
+
const type = contentType(request);
|
|
47710
|
+
const init = type ? { headers: { "content-type": type } } : void 0;
|
|
47711
|
+
return new Response(buf, init).blob();
|
|
47712
|
+
});
|
|
47713
|
+
}, "value") });
|
|
47714
|
+
Object.defineProperty(requestPrototype, "json", { value: /* @__PURE__ */ __name(function() {
|
|
47715
|
+
if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
47716
|
+
return this.text().then(JSON.parse);
|
|
47717
|
+
}, "value") });
|
|
47718
|
+
Object.defineProperty(requestPrototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47719
|
+
return `Request (lightweight) ${inspectFn({
|
|
47720
|
+
method: this.method,
|
|
47721
|
+
url: this.url,
|
|
47722
|
+
headers: this.headers,
|
|
47723
|
+
nativeRequest: this[requestCache]
|
|
47724
|
+
}, {
|
|
47725
|
+
...options,
|
|
47726
|
+
depth: depth == null ? null : depth - 1
|
|
47727
|
+
})}`;
|
|
47728
|
+
}, "value") });
|
|
47729
|
+
Object.setPrototypeOf(requestPrototype, Request$1.prototype);
|
|
47730
|
+
var newRequest = /* @__PURE__ */ __name((incoming, defaultHostname) => {
|
|
47731
|
+
const req = Object.create(requestPrototype);
|
|
47732
|
+
req[incomingKey] = incoming;
|
|
47733
|
+
req[methodKey] = normalizeIncomingMethod(incoming.method);
|
|
47734
|
+
const incomingUrl = incoming.url || "";
|
|
47735
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
47736
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
47737
|
+
try {
|
|
47738
|
+
req[urlKey] = new URL(incomingUrl).href;
|
|
47739
|
+
} catch (e) {
|
|
47740
|
+
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
47741
|
+
}
|
|
47742
|
+
return req;
|
|
47743
|
+
}
|
|
47744
|
+
const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
47745
|
+
if (!host) throw new RequestError("Missing host header");
|
|
47746
|
+
let scheme;
|
|
47747
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) {
|
|
47748
|
+
scheme = incoming.scheme;
|
|
47749
|
+
if (!(scheme === "http" || scheme === "https")) throw new RequestError("Unsupported scheme");
|
|
47750
|
+
} else scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
|
|
47751
|
+
try {
|
|
47752
|
+
req[urlKey] = buildUrl(scheme, host, incomingUrl);
|
|
47753
|
+
} catch (e) {
|
|
47754
|
+
if (e instanceof RequestError) throw e;
|
|
47755
|
+
else throw new RequestError("Invalid URL", { cause: e });
|
|
47756
|
+
}
|
|
47757
|
+
return req;
|
|
47758
|
+
}, "newRequest");
|
|
47759
|
+
var defaultContentType = "text/plain; charset=UTF-8";
|
|
47760
|
+
var responseCache = /* @__PURE__ */ Symbol("responseCache");
|
|
47761
|
+
var getResponseCache = /* @__PURE__ */ Symbol("getResponseCache");
|
|
47762
|
+
var cacheKey = /* @__PURE__ */ Symbol("cache");
|
|
47763
|
+
var GlobalResponse = global.Response;
|
|
47764
|
+
var Response$1 = class Response$12 {
|
|
47765
|
+
static {
|
|
47766
|
+
__name(this, "Response$1");
|
|
47767
|
+
}
|
|
47768
|
+
#body;
|
|
47769
|
+
#init;
|
|
47770
|
+
[getResponseCache]() {
|
|
47771
|
+
const cache = this[cacheKey];
|
|
47772
|
+
const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
|
|
47773
|
+
delete this[cacheKey];
|
|
47774
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, liveHeaders ? {
|
|
47775
|
+
status: this.#init?.status,
|
|
47776
|
+
statusText: this.#init?.statusText,
|
|
47777
|
+
headers: liveHeaders
|
|
47778
|
+
} : this.#init);
|
|
47779
|
+
}
|
|
47780
|
+
constructor(body, init) {
|
|
47781
|
+
let headers;
|
|
47782
|
+
this.#body = body;
|
|
47783
|
+
if (init instanceof GlobalResponse) {
|
|
47784
|
+
const cachedGlobalResponse = init[responseCache];
|
|
47785
|
+
if (cachedGlobalResponse) {
|
|
47786
|
+
this.#init = cachedGlobalResponse;
|
|
47787
|
+
this[getResponseCache]();
|
|
47788
|
+
return;
|
|
47789
|
+
}
|
|
47790
|
+
this.#init = init instanceof Response$12 ? init.#init : init;
|
|
47791
|
+
headers = new Headers(init.headers);
|
|
47792
|
+
} else this.#init = init;
|
|
47793
|
+
if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
47794
|
+
init?.status || 200,
|
|
47795
|
+
body ?? null,
|
|
47796
|
+
headers || init?.headers
|
|
47797
|
+
];
|
|
47798
|
+
}
|
|
47799
|
+
get headers() {
|
|
47800
|
+
const cache = this[cacheKey];
|
|
47801
|
+
if (cache) {
|
|
47802
|
+
if (!(cache[2] instanceof Headers)) cache[2] = new Headers(cache[2] || (cache[1] === null ? void 0 : { "content-type": defaultContentType }));
|
|
47803
|
+
return cache[2];
|
|
47804
|
+
}
|
|
47805
|
+
return this[getResponseCache]().headers;
|
|
47806
|
+
}
|
|
47807
|
+
get status() {
|
|
47808
|
+
return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
|
|
47809
|
+
}
|
|
47810
|
+
get ok() {
|
|
47811
|
+
const status = this.status;
|
|
47812
|
+
return status >= 200 && status < 300;
|
|
47813
|
+
}
|
|
47814
|
+
};
|
|
47815
|
+
[
|
|
47816
|
+
"body",
|
|
47817
|
+
"bodyUsed",
|
|
47818
|
+
"redirected",
|
|
47819
|
+
"statusText",
|
|
47820
|
+
"trailers",
|
|
47821
|
+
"type",
|
|
47822
|
+
"url"
|
|
47823
|
+
].forEach((k) => {
|
|
47824
|
+
Object.defineProperty(Response$1.prototype, k, { get() {
|
|
47825
|
+
return this[getResponseCache]()[k];
|
|
47826
|
+
} });
|
|
47827
|
+
});
|
|
47828
|
+
[
|
|
47829
|
+
"arrayBuffer",
|
|
47830
|
+
"blob",
|
|
47831
|
+
"clone",
|
|
47832
|
+
"formData",
|
|
47833
|
+
"json",
|
|
47834
|
+
"text"
|
|
47835
|
+
].forEach((k) => {
|
|
47836
|
+
Object.defineProperty(Response$1.prototype, k, { value: /* @__PURE__ */ __name(function() {
|
|
47837
|
+
return this[getResponseCache]()[k]();
|
|
47838
|
+
}, "value") });
|
|
47839
|
+
});
|
|
47840
|
+
Object.defineProperty(Response$1.prototype, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), { value: /* @__PURE__ */ __name(function(depth, options, inspectFn) {
|
|
47841
|
+
return `Response (lightweight) ${inspectFn({
|
|
47842
|
+
status: this.status,
|
|
47843
|
+
headers: this.headers,
|
|
47844
|
+
ok: this.ok,
|
|
47845
|
+
nativeResponse: this[responseCache]
|
|
47846
|
+
}, {
|
|
47847
|
+
...options,
|
|
47848
|
+
depth: depth == null ? null : depth - 1
|
|
47849
|
+
})}`;
|
|
47850
|
+
}, "value") });
|
|
47851
|
+
Object.setPrototypeOf(Response$1, GlobalResponse);
|
|
47852
|
+
Object.setPrototypeOf(Response$1.prototype, GlobalResponse.prototype);
|
|
47853
|
+
var validRedirectUrl = /^https?:\/\/[!#-;=?-[\]_a-z~A-Z]+$/;
|
|
47854
|
+
var parseRedirectUrl = /* @__PURE__ */ __name((url2) => {
|
|
47855
|
+
if (url2 instanceof URL) return url2.href;
|
|
47856
|
+
if (validRedirectUrl.test(url2)) return url2;
|
|
47857
|
+
return new URL(url2).href;
|
|
47858
|
+
}, "parseRedirectUrl");
|
|
47859
|
+
var validRedirectStatuses = /* @__PURE__ */ new Set([
|
|
47860
|
+
301,
|
|
47861
|
+
302,
|
|
47862
|
+
303,
|
|
47863
|
+
307,
|
|
47864
|
+
308
|
|
47865
|
+
]);
|
|
47866
|
+
Object.defineProperty(Response$1, "redirect", {
|
|
47867
|
+
value: /* @__PURE__ */ __name(function redirect(url2, status = 302) {
|
|
47868
|
+
if (!validRedirectStatuses.has(status)) throw new RangeError("Invalid status code");
|
|
47869
|
+
return new Response$1(null, {
|
|
47870
|
+
status,
|
|
47871
|
+
headers: { location: parseRedirectUrl(url2) }
|
|
47872
|
+
});
|
|
47873
|
+
}, "redirect"),
|
|
47874
|
+
writable: true,
|
|
47875
|
+
configurable: true
|
|
47876
|
+
});
|
|
47877
|
+
Object.defineProperty(Response$1, "json", {
|
|
47878
|
+
value: /* @__PURE__ */ __name(function json2(data, init) {
|
|
47879
|
+
const body = JSON.stringify(data);
|
|
47880
|
+
if (body === void 0) throw new TypeError("The data is not JSON serializable");
|
|
47881
|
+
const initHeaders = init?.headers;
|
|
47882
|
+
let headers;
|
|
47883
|
+
if (initHeaders) {
|
|
47884
|
+
headers = new Headers(initHeaders);
|
|
47885
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
47886
|
+
} else headers = { "content-type": "application/json" };
|
|
47887
|
+
return new Response$1(body, {
|
|
47888
|
+
status: init?.status ?? 200,
|
|
47889
|
+
statusText: init?.statusText,
|
|
47890
|
+
headers
|
|
47891
|
+
});
|
|
47892
|
+
}, "json"),
|
|
47893
|
+
writable: true,
|
|
47894
|
+
configurable: true
|
|
47895
|
+
});
|
|
47896
|
+
async function readWithoutBlocking(readPromise) {
|
|
47897
|
+
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
47898
|
+
}
|
|
47899
|
+
__name(readWithoutBlocking, "readWithoutBlocking");
|
|
47900
|
+
function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromise) {
|
|
47901
|
+
const cancel = /* @__PURE__ */ __name((error62) => {
|
|
47902
|
+
reader.cancel(error62).catch(() => {
|
|
47903
|
+
});
|
|
47904
|
+
}, "cancel");
|
|
47905
|
+
writable.on("close", cancel);
|
|
47906
|
+
writable.on("error", cancel);
|
|
47907
|
+
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
47908
|
+
return reader.closed.finally(() => {
|
|
47909
|
+
writable.off("close", cancel);
|
|
47910
|
+
writable.off("error", cancel);
|
|
47911
|
+
});
|
|
47912
|
+
function handleStreamError(error62) {
|
|
47913
|
+
if (error62) writable.destroy(error62);
|
|
47914
|
+
}
|
|
47915
|
+
__name(handleStreamError, "handleStreamError");
|
|
47916
|
+
function onDrain() {
|
|
47917
|
+
reader.read().then(flow, handleStreamError);
|
|
47918
|
+
}
|
|
47919
|
+
__name(onDrain, "onDrain");
|
|
47920
|
+
function flow({ done, value }) {
|
|
47921
|
+
try {
|
|
47922
|
+
if (done) writable.end();
|
|
47923
|
+
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
47924
|
+
else return reader.read().then(flow, handleStreamError);
|
|
47925
|
+
} catch (e) {
|
|
47926
|
+
handleStreamError(e);
|
|
47927
|
+
}
|
|
47928
|
+
}
|
|
47929
|
+
__name(flow, "flow");
|
|
47930
|
+
}
|
|
47931
|
+
__name(writeFromReadableStreamDefaultReader, "writeFromReadableStreamDefaultReader");
|
|
47932
|
+
function writeFromReadableStream(stream, writable) {
|
|
47933
|
+
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
47934
|
+
else if (writable.destroyed) return;
|
|
47935
|
+
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
47936
|
+
}
|
|
47937
|
+
__name(writeFromReadableStream, "writeFromReadableStream");
|
|
47938
|
+
var buildOutgoingHttpHeaders = /* @__PURE__ */ __name((headers, defaultContentType2) => {
|
|
47939
|
+
const res = {};
|
|
47940
|
+
if (!(headers instanceof Headers)) headers = new Headers(headers ?? void 0);
|
|
47941
|
+
if (headers.has("set-cookie")) {
|
|
47942
|
+
const cookies = [];
|
|
47943
|
+
for (const [k, v] of headers) if (k === "set-cookie") cookies.push(v);
|
|
47944
|
+
else res[k] = v;
|
|
47945
|
+
if (cookies.length > 0) res["set-cookie"] = cookies;
|
|
47946
|
+
} else for (const [k, v] of headers) res[k] = v;
|
|
47947
|
+
if (defaultContentType2) res["content-type"] ??= defaultContentType2;
|
|
47948
|
+
return res;
|
|
47949
|
+
}, "buildOutgoingHttpHeaders");
|
|
47950
|
+
var outgoingEnded = /* @__PURE__ */ Symbol("outgoingEnded");
|
|
47951
|
+
var incomingDraining = /* @__PURE__ */ Symbol("incomingDraining");
|
|
47952
|
+
var DRAIN_TIMEOUT_MS = 500;
|
|
47953
|
+
var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
|
|
47954
|
+
var drainIncoming = /* @__PURE__ */ __name((incoming) => {
|
|
47955
|
+
const incomingWithDrainState = incoming;
|
|
47956
|
+
if (incoming.destroyed || incomingWithDrainState[incomingDraining]) return;
|
|
47957
|
+
incomingWithDrainState[incomingDraining] = true;
|
|
47958
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) {
|
|
47959
|
+
try {
|
|
47960
|
+
incoming.stream?.close?.(import_node_http2.constants.NGHTTP2_NO_ERROR);
|
|
47961
|
+
} catch {
|
|
47962
|
+
}
|
|
47963
|
+
return;
|
|
47964
|
+
}
|
|
47965
|
+
let bytesRead = 0;
|
|
47966
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
47967
|
+
clearTimeout(timer);
|
|
47968
|
+
incoming.off("data", onData);
|
|
47969
|
+
incoming.off("end", cleanup);
|
|
47970
|
+
incoming.off("error", cleanup);
|
|
47971
|
+
}, "cleanup");
|
|
47972
|
+
const forceClose = /* @__PURE__ */ __name(() => {
|
|
47973
|
+
cleanup();
|
|
47974
|
+
const socket = incoming.socket;
|
|
47975
|
+
if (socket && !socket.destroyed) {
|
|
47976
|
+
if (typeof socket.destroySoon === "function") socket.destroySoon();
|
|
47977
|
+
else if (typeof socket.destroy === "function") socket.destroy();
|
|
47978
|
+
}
|
|
47979
|
+
}, "forceClose");
|
|
47980
|
+
const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
|
|
47981
|
+
timer.unref?.();
|
|
47982
|
+
const onData = /* @__PURE__ */ __name((chunk) => {
|
|
47983
|
+
bytesRead += chunk.length;
|
|
47984
|
+
if (bytesRead > MAX_DRAIN_BYTES) forceClose();
|
|
47985
|
+
}, "onData");
|
|
47986
|
+
incoming.on("data", onData);
|
|
47987
|
+
incoming.on("end", cleanup);
|
|
47988
|
+
incoming.on("error", cleanup);
|
|
47989
|
+
incoming.resume();
|
|
47990
|
+
}, "drainIncoming");
|
|
47991
|
+
var makeCloseHandler = /* @__PURE__ */ __name((req, incoming, outgoing, needsBodyCleanup) => () => {
|
|
47992
|
+
if (incoming.errored) {
|
|
47993
|
+
recordBodyBufferedBeforeDisconnect(incoming);
|
|
47994
|
+
req[abortRequest](incoming.errored.toString());
|
|
47995
|
+
} else if (!outgoing.writableFinished) {
|
|
47996
|
+
recordBodyBufferedBeforeDisconnect(incoming);
|
|
47997
|
+
req[abortRequest]("Client connection prematurely closed.");
|
|
47998
|
+
}
|
|
47999
|
+
if (needsBodyCleanup && !incoming.readableEnded) setTimeout(() => {
|
|
48000
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48001
|
+
drainIncoming(incoming);
|
|
48002
|
+
});
|
|
48003
|
+
});
|
|
48004
|
+
}, "makeCloseHandler");
|
|
48005
|
+
var isImmediateCacheableResponse = /* @__PURE__ */ __name((res) => {
|
|
48006
|
+
if (!(cacheKey in res)) return false;
|
|
48007
|
+
const body = res[cacheKey][1];
|
|
48008
|
+
return body === null || typeof body === "string" || body instanceof Uint8Array;
|
|
48009
|
+
}, "isImmediateCacheableResponse");
|
|
48010
|
+
var handleRequestError = /* @__PURE__ */ __name(() => new Response(null, { status: 400 }), "handleRequestError");
|
|
48011
|
+
var handleFetchError = /* @__PURE__ */ __name((e) => new Response(null, { status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500 }), "handleFetchError");
|
|
48012
|
+
var handleResponseError = /* @__PURE__ */ __name((e, outgoing) => {
|
|
48013
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
48014
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
|
|
48015
|
+
else {
|
|
48016
|
+
console.error(e);
|
|
48017
|
+
if (!outgoing.headersSent) {
|
|
48018
|
+
if (outgoing instanceof import_node_http.ServerResponse) outgoing._contentLength = null;
|
|
48019
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
48020
|
+
}
|
|
48021
|
+
outgoing.end(`Error: ${err.message}`);
|
|
48022
|
+
outgoing.destroy(err);
|
|
48023
|
+
}
|
|
48024
|
+
}, "handleResponseError");
|
|
48025
|
+
var flushHeaders = /* @__PURE__ */ __name((outgoing) => {
|
|
48026
|
+
if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
|
|
48027
|
+
}, "flushHeaders");
|
|
48028
|
+
var trySetContentLength = /* @__PURE__ */ __name((outgoing, status, length) => {
|
|
48029
|
+
const http1 = outgoing;
|
|
48030
|
+
if (http1._contentLength === null && http1._hasBody && http1.useChunkedEncodingByDefault && !http1._removedContLen && status >= 200 && status !== 204 && status !== 304 && !outgoing.hasHeader("content-length") && !outgoing.hasHeader("transfer-encoding") && !outgoing.hasHeader("trailer")) {
|
|
48031
|
+
http1._contentLength = length;
|
|
48032
|
+
return true;
|
|
48033
|
+
}
|
|
48034
|
+
return false;
|
|
48035
|
+
}, "trySetContentLength");
|
|
48036
|
+
var writeDefaultHeaders = /* @__PURE__ */ __name((outgoing, status, length) => {
|
|
48037
|
+
if (trySetContentLength(outgoing, status, length)) outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
48038
|
+
else outgoing.writeHead(status, {
|
|
48039
|
+
"Content-Type": defaultContentType,
|
|
48040
|
+
"Content-Length": length
|
|
48041
|
+
});
|
|
48042
|
+
}, "writeDefaultHeaders");
|
|
48043
|
+
var responseViaCache = /* @__PURE__ */ __name(async (res, outgoing) => {
|
|
48044
|
+
let [status, body, header] = res[cacheKey];
|
|
48045
|
+
if (!header) {
|
|
48046
|
+
if (body === null) {
|
|
48047
|
+
outgoing.writeHead(status);
|
|
48048
|
+
outgoing.end();
|
|
48049
|
+
} else if (typeof body === "string") {
|
|
48050
|
+
writeDefaultHeaders(outgoing, status, Buffer.byteLength(body));
|
|
48051
|
+
outgoing.end(body);
|
|
48052
|
+
} else if (body instanceof Uint8Array) {
|
|
48053
|
+
writeDefaultHeaders(outgoing, status, body.byteLength);
|
|
48054
|
+
outgoing.end(body);
|
|
48055
|
+
} else if (body instanceof Blob) {
|
|
48056
|
+
writeDefaultHeaders(outgoing, status, body.size);
|
|
48057
|
+
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
48058
|
+
} else {
|
|
48059
|
+
outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
48060
|
+
flushHeaders(outgoing);
|
|
48061
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
48062
|
+
}
|
|
48063
|
+
outgoing[outgoingEnded]?.();
|
|
48064
|
+
return;
|
|
48065
|
+
}
|
|
48066
|
+
let hasContentLength = false;
|
|
48067
|
+
let plainHeaders = false;
|
|
48068
|
+
let canAutoLength = true;
|
|
48069
|
+
if (header instanceof Headers) {
|
|
48070
|
+
hasContentLength = header.has("content-length");
|
|
48071
|
+
header = buildOutgoingHttpHeaders(header, body === null ? void 0 : defaultContentType);
|
|
48072
|
+
} else if (Array.isArray(header)) {
|
|
48073
|
+
const headerObj = new Headers(header);
|
|
48074
|
+
hasContentLength = headerObj.has("content-length");
|
|
48075
|
+
header = buildOutgoingHttpHeaders(headerObj, body === null ? void 0 : defaultContentType);
|
|
48076
|
+
} else {
|
|
48077
|
+
plainHeaders = true;
|
|
48078
|
+
for (const key in header) {
|
|
48079
|
+
if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
48080
|
+
hasContentLength = true;
|
|
48081
|
+
break;
|
|
48082
|
+
}
|
|
48083
|
+
if (key.length === 17 && key.toLowerCase() === "transfer-encoding" || key.length === 7 && key.toLowerCase() === "trailer") canAutoLength = false;
|
|
48084
|
+
}
|
|
48085
|
+
}
|
|
48086
|
+
if (!hasContentLength) {
|
|
48087
|
+
let length;
|
|
48088
|
+
if (typeof body === "string") length = Buffer.byteLength(body);
|
|
48089
|
+
else if (body instanceof Uint8Array) length = body.byteLength;
|
|
48090
|
+
else if (body instanceof Blob) length = body.size;
|
|
48091
|
+
if (length !== void 0 && (!plainHeaders || !canAutoLength || !trySetContentLength(outgoing, status, length))) {
|
|
48092
|
+
if (plainHeaders) header = { ...header };
|
|
48093
|
+
header["Content-Length"] = length;
|
|
48094
|
+
}
|
|
48095
|
+
}
|
|
48096
|
+
outgoing.writeHead(status, header);
|
|
48097
|
+
if (body == null) outgoing.end();
|
|
48098
|
+
else if (typeof body === "string" || body instanceof Uint8Array) outgoing.end(body);
|
|
48099
|
+
else if (body instanceof Blob) outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
48100
|
+
else {
|
|
48101
|
+
flushHeaders(outgoing);
|
|
48102
|
+
await writeFromReadableStream(body, outgoing)?.catch((e) => handleResponseError(e, outgoing));
|
|
48103
|
+
}
|
|
48104
|
+
outgoing[outgoingEnded]?.();
|
|
48105
|
+
}, "responseViaCache");
|
|
48106
|
+
var isPromise = /* @__PURE__ */ __name((res) => typeof res.then === "function", "isPromise");
|
|
48107
|
+
var responseViaResponseObject = /* @__PURE__ */ __name(async (res, outgoing, options = {}) => {
|
|
48108
|
+
if (isPromise(res)) if (options.errorHandler) try {
|
|
48109
|
+
res = await res;
|
|
48110
|
+
} catch (err) {
|
|
48111
|
+
const errRes = await options.errorHandler(err);
|
|
48112
|
+
if (!errRes) return;
|
|
48113
|
+
res = errRes;
|
|
48114
|
+
}
|
|
48115
|
+
else res = await res.catch(handleFetchError);
|
|
48116
|
+
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
48117
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers, res.body === null ? void 0 : defaultContentType);
|
|
48118
|
+
if (res.body) {
|
|
48119
|
+
const reader = res.body.getReader();
|
|
48120
|
+
const values = [];
|
|
48121
|
+
let done = false;
|
|
48122
|
+
let currentReadPromise = void 0;
|
|
48123
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
48124
|
+
let maxReadCount = 2;
|
|
48125
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
48126
|
+
currentReadPromise ||= reader.read();
|
|
48127
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
48128
|
+
console.error(e);
|
|
48129
|
+
done = true;
|
|
48130
|
+
});
|
|
48131
|
+
if (!chunk) {
|
|
48132
|
+
if (i === 1) {
|
|
48133
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
48134
|
+
maxReadCount = 3;
|
|
48135
|
+
continue;
|
|
48136
|
+
}
|
|
48137
|
+
break;
|
|
48138
|
+
}
|
|
48139
|
+
currentReadPromise = void 0;
|
|
48140
|
+
if (chunk.value) values.push(chunk.value);
|
|
48141
|
+
if (chunk.done) {
|
|
48142
|
+
done = true;
|
|
48143
|
+
break;
|
|
48144
|
+
}
|
|
48145
|
+
}
|
|
48146
|
+
if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
48147
|
+
}
|
|
48148
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
48149
|
+
values.forEach((value) => {
|
|
48150
|
+
outgoing.write(value);
|
|
48151
|
+
});
|
|
48152
|
+
if (done) outgoing.end();
|
|
48153
|
+
else {
|
|
48154
|
+
if (values.length === 0) flushHeaders(outgoing);
|
|
48155
|
+
await writeFromReadableStreamDefaultReader(reader, outgoing, currentReadPromise);
|
|
48156
|
+
}
|
|
48157
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {
|
|
48158
|
+
} else {
|
|
48159
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
48160
|
+
outgoing.end();
|
|
48161
|
+
}
|
|
48162
|
+
outgoing[outgoingEnded]?.();
|
|
48163
|
+
}, "responseViaResponseObject");
|
|
48164
|
+
var getRequestListener = /* @__PURE__ */ __name((fetchCallback, options = {}) => {
|
|
48165
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
48166
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request$1) {
|
|
48167
|
+
Object.defineProperty(global, "Request", { value: Request$1 });
|
|
48168
|
+
Object.defineProperty(global, "Response", { value: Response$1 });
|
|
48169
|
+
}
|
|
48170
|
+
return async (incoming, outgoing) => {
|
|
48171
|
+
let res, req;
|
|
48172
|
+
let needsBodyCleanup = false;
|
|
48173
|
+
let closeHandlerAttached = false;
|
|
48174
|
+
const ensureCloseHandler = /* @__PURE__ */ __name(() => {
|
|
48175
|
+
if (!req || closeHandlerAttached) return;
|
|
48176
|
+
closeHandlerAttached = true;
|
|
48177
|
+
outgoing.on("close", makeCloseHandler(req, incoming, outgoing, needsBodyCleanup));
|
|
48178
|
+
}, "ensureCloseHandler");
|
|
48179
|
+
try {
|
|
48180
|
+
req = newRequest(incoming, options.hostname);
|
|
48181
|
+
needsBodyCleanup = autoCleanupIncoming && !(incoming.method === "GET" || incoming.method === "HEAD");
|
|
48182
|
+
if (needsBodyCleanup) {
|
|
48183
|
+
incoming[wrapBodyStream] = true;
|
|
48184
|
+
if (incoming instanceof import_node_http2.Http2ServerRequest) outgoing[outgoingEnded] = () => {
|
|
48185
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48186
|
+
if (!incoming.readableEnded) setTimeout(() => {
|
|
48187
|
+
incoming.destroy();
|
|
48188
|
+
outgoing.destroy();
|
|
48189
|
+
});
|
|
48190
|
+
});
|
|
48191
|
+
};
|
|
48192
|
+
}
|
|
48193
|
+
res = fetchCallback(req, {
|
|
48194
|
+
incoming,
|
|
48195
|
+
outgoing
|
|
48196
|
+
});
|
|
48197
|
+
if (!isPromise(res) && isImmediateCacheableResponse(res)) {
|
|
48198
|
+
if (needsBodyCleanup && !incoming.readableEnded) outgoing.once("finish", () => {
|
|
48199
|
+
if (!incoming.readableEnded) drainIncoming(incoming);
|
|
48200
|
+
});
|
|
48201
|
+
return responseViaCache(res, outgoing);
|
|
48202
|
+
}
|
|
48203
|
+
ensureCloseHandler();
|
|
48204
|
+
} catch (e) {
|
|
48205
|
+
if (!res) if (options.errorHandler) {
|
|
48206
|
+
ensureCloseHandler();
|
|
48207
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
48208
|
+
if (!res) return;
|
|
48209
|
+
} else if (!req) res = handleRequestError();
|
|
48210
|
+
else res = handleFetchError(e);
|
|
48211
|
+
else return handleResponseError(e, outgoing);
|
|
48212
|
+
}
|
|
48213
|
+
try {
|
|
48214
|
+
return await responseViaResponseObject(res, outgoing, options);
|
|
48215
|
+
} catch (e) {
|
|
48216
|
+
return handleResponseError(e, outgoing);
|
|
48217
|
+
}
|
|
48218
|
+
};
|
|
48219
|
+
}, "getRequestListener");
|
|
48220
|
+
var CloseEvent = globalThis.CloseEvent ?? class extends Event {
|
|
48221
|
+
#eventInitDict;
|
|
48222
|
+
constructor(type, eventInitDict = {}) {
|
|
48223
|
+
super(type, eventInitDict);
|
|
48224
|
+
this.#eventInitDict = eventInitDict;
|
|
48225
|
+
}
|
|
48226
|
+
get wasClean() {
|
|
48227
|
+
return this.#eventInitDict.wasClean ?? false;
|
|
48228
|
+
}
|
|
48229
|
+
get code() {
|
|
48230
|
+
return this.#eventInitDict.code ?? 0;
|
|
48231
|
+
}
|
|
48232
|
+
get reason() {
|
|
48233
|
+
return this.#eventInitDict.reason ?? "";
|
|
48234
|
+
}
|
|
48235
|
+
};
|
|
48236
|
+
var ErrorEvent = globalThis.ErrorEvent ?? class extends Event {
|
|
48237
|
+
#eventInitDict;
|
|
48238
|
+
constructor(type, eventInitDict = {}) {
|
|
48239
|
+
super(type, eventInitDict);
|
|
48240
|
+
this.#eventInitDict = eventInitDict;
|
|
48241
|
+
}
|
|
48242
|
+
get message() {
|
|
48243
|
+
return this.#eventInitDict.message ?? "";
|
|
48244
|
+
}
|
|
48245
|
+
get filename() {
|
|
48246
|
+
return this.#eventInitDict.filename ?? "";
|
|
48247
|
+
}
|
|
48248
|
+
get lineno() {
|
|
48249
|
+
return this.#eventInitDict.lineno ?? 0;
|
|
48250
|
+
}
|
|
48251
|
+
get colno() {
|
|
48252
|
+
return this.#eventInitDict.colno ?? 0;
|
|
48253
|
+
}
|
|
48254
|
+
get error() {
|
|
48255
|
+
return this.#eventInitDict.error ?? null;
|
|
48256
|
+
}
|
|
48257
|
+
};
|
|
48258
|
+
var generateConnectionSymbol = /* @__PURE__ */ __name(() => /* @__PURE__ */ Symbol("connection"), "generateConnectionSymbol");
|
|
48259
|
+
var CONNECTION_SYMBOL_KEY = /* @__PURE__ */ Symbol("CONNECTION_SYMBOL_KEY");
|
|
48260
|
+
var WAIT_FOR_WEBSOCKET_SYMBOL = /* @__PURE__ */ Symbol("WAIT_FOR_WEBSOCKET_SYMBOL");
|
|
48261
|
+
var upgradeWebSocket = defineWebSocketHelper(async (c, events, options) => {
|
|
48262
|
+
if (c.req.header("upgrade")?.toLowerCase() !== "websocket") return;
|
|
48263
|
+
const env = c.env;
|
|
48264
|
+
const waitForWebSocket = env[WAIT_FOR_WEBSOCKET_SYMBOL];
|
|
48265
|
+
if (!waitForWebSocket || !env.incoming) return new Response(null, { status: 500 });
|
|
48266
|
+
const connectionSymbol = generateConnectionSymbol();
|
|
48267
|
+
env[CONNECTION_SYMBOL_KEY] = connectionSymbol;
|
|
48268
|
+
(async () => {
|
|
48269
|
+
let ws;
|
|
48270
|
+
try {
|
|
48271
|
+
ws = await waitForWebSocket(env.incoming, connectionSymbol);
|
|
48272
|
+
} catch {
|
|
48273
|
+
return;
|
|
48274
|
+
}
|
|
48275
|
+
const messagesReceivedInStarting = [];
|
|
48276
|
+
const bufferMessage = /* @__PURE__ */ __name((data, isBinary) => {
|
|
48277
|
+
messagesReceivedInStarting.push([data, isBinary]);
|
|
48278
|
+
}, "bufferMessage");
|
|
48279
|
+
ws.on("message", bufferMessage);
|
|
48280
|
+
const ctx = {
|
|
48281
|
+
binaryType: "arraybuffer",
|
|
48282
|
+
close(code, reason) {
|
|
48283
|
+
ws.close(code, reason);
|
|
48284
|
+
},
|
|
48285
|
+
protocol: ws.protocol,
|
|
48286
|
+
raw: ws,
|
|
48287
|
+
get readyState() {
|
|
48288
|
+
return ws.readyState;
|
|
48289
|
+
},
|
|
48290
|
+
send(source, opts) {
|
|
48291
|
+
ws.send(source, { compress: opts?.compress });
|
|
48292
|
+
},
|
|
48293
|
+
url: new URL(c.req.url)
|
|
48294
|
+
};
|
|
48295
|
+
try {
|
|
48296
|
+
events?.onOpen?.(new Event("open"), ctx);
|
|
48297
|
+
} catch (e) {
|
|
48298
|
+
(options?.onError ?? console.error)(e);
|
|
48299
|
+
}
|
|
48300
|
+
const handleMessage = /* @__PURE__ */ __name((data, isBinary) => {
|
|
48301
|
+
const datas = Array.isArray(data) ? data : [data];
|
|
48302
|
+
for (const data2 of datas) try {
|
|
48303
|
+
events?.onMessage?.(new MessageEvent("message", { data: isBinary ? data2 instanceof ArrayBuffer ? data2 : data2.buffer.slice(data2.byteOffset, data2.byteOffset + data2.byteLength) : typeof data2 === "string" ? data2 : Buffer.from(data2).toString("utf-8") }), ctx);
|
|
48304
|
+
} catch (e) {
|
|
48305
|
+
(options?.onError ?? console.error)(e);
|
|
48306
|
+
}
|
|
48307
|
+
}, "handleMessage");
|
|
48308
|
+
ws.off("message", bufferMessage);
|
|
48309
|
+
for (const message of messagesReceivedInStarting) handleMessage(...message);
|
|
48310
|
+
ws.on("message", (data, isBinary) => {
|
|
48311
|
+
handleMessage(data, isBinary);
|
|
48312
|
+
});
|
|
48313
|
+
ws.on("close", (code, reason) => {
|
|
48314
|
+
try {
|
|
48315
|
+
events?.onClose?.(new CloseEvent("close", {
|
|
48316
|
+
code,
|
|
48317
|
+
reason: reason.toString()
|
|
48318
|
+
}), ctx);
|
|
48319
|
+
} catch (e) {
|
|
48320
|
+
(options?.onError ?? console.error)(e);
|
|
48321
|
+
}
|
|
48322
|
+
});
|
|
48323
|
+
ws.on("error", (error62) => {
|
|
48324
|
+
try {
|
|
48325
|
+
events?.onError?.(new ErrorEvent("error", { error: error62 }), ctx);
|
|
48326
|
+
} catch (e) {
|
|
48327
|
+
(options?.onError ?? console.error)(e);
|
|
48328
|
+
}
|
|
48329
|
+
});
|
|
48330
|
+
})();
|
|
48331
|
+
return new Response();
|
|
48332
|
+
});
|
|
48333
|
+
|
|
48334
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
|
|
48335
|
+
var import_content_type = __toESM(require_content_type(), 1);
|
|
48336
|
+
function mediaTypeEssence(header) {
|
|
48337
|
+
if (!header) {
|
|
48338
|
+
return void 0;
|
|
48339
|
+
}
|
|
48340
|
+
try {
|
|
48341
|
+
return import_content_type.default.parse(header).type;
|
|
48342
|
+
} catch {
|
|
48343
|
+
const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
|
|
48344
|
+
if (essence === "" || header.slice(essence.length).includes(",")) {
|
|
48345
|
+
return void 0;
|
|
48346
|
+
}
|
|
48347
|
+
return essence;
|
|
48348
|
+
}
|
|
48349
|
+
}
|
|
48350
|
+
__name(mediaTypeEssence, "mediaTypeEssence");
|
|
48351
|
+
function isJsonContentType(header) {
|
|
48352
|
+
if (header === "application/json") {
|
|
48353
|
+
return true;
|
|
48354
|
+
}
|
|
48355
|
+
return mediaTypeEssence(header) === "application/json";
|
|
48356
|
+
}
|
|
48357
|
+
__name(isJsonContentType, "isJsonContentType");
|
|
48358
|
+
|
|
48359
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js
|
|
48360
|
+
var DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024 * 1024;
|
|
48361
|
+
var MAX_BATCH_SIZE = 100;
|
|
48362
|
+
function requestBodyTooLargeMessage(maxBytes) {
|
|
48363
|
+
return `Payload Too Large: Request body must not exceed ${maxBytes} bytes`;
|
|
48364
|
+
}
|
|
48365
|
+
__name(requestBodyTooLargeMessage, "requestBodyTooLargeMessage");
|
|
48366
|
+
function resolveMaxRequestBodySize(value) {
|
|
48367
|
+
if (value === void 0) {
|
|
48368
|
+
return DEFAULT_MAX_REQUEST_BODY_SIZE;
|
|
48369
|
+
}
|
|
48370
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
48371
|
+
throw new RangeError(`maxRequestBodySize must be a positive number of bytes, got ${String(value)}`);
|
|
48372
|
+
}
|
|
48373
|
+
return value;
|
|
48374
|
+
}
|
|
48375
|
+
__name(resolveMaxRequestBodySize, "resolveMaxRequestBodySize");
|
|
48376
|
+
async function readRequestBody(request, maxBytes = DEFAULT_MAX_REQUEST_BODY_SIZE) {
|
|
48377
|
+
if (Number(request.headers.get("content-length")) > maxBytes) {
|
|
48378
|
+
return { tooLarge: true };
|
|
48379
|
+
}
|
|
48380
|
+
if (request.body === null) {
|
|
48381
|
+
return { tooLarge: false, text: "" };
|
|
48382
|
+
}
|
|
48383
|
+
const reader = request.body.getReader();
|
|
48384
|
+
const decoder = new TextDecoder();
|
|
48385
|
+
let received = 0;
|
|
48386
|
+
let text2 = "";
|
|
48387
|
+
try {
|
|
48388
|
+
for (; ; ) {
|
|
48389
|
+
const { done, value } = await reader.read();
|
|
48390
|
+
if (done) {
|
|
48391
|
+
break;
|
|
48392
|
+
}
|
|
48393
|
+
received += value.byteLength;
|
|
48394
|
+
if (received > maxBytes) {
|
|
48395
|
+
return { tooLarge: true };
|
|
48396
|
+
}
|
|
48397
|
+
text2 += decoder.decode(value, { stream: true });
|
|
48398
|
+
}
|
|
48399
|
+
} finally {
|
|
48400
|
+
reader.releaseLock();
|
|
48401
|
+
}
|
|
48402
|
+
return { tooLarge: false, text: text2 + decoder.decode() };
|
|
48403
|
+
}
|
|
48404
|
+
__name(readRequestBody, "readRequestBody");
|
|
48405
|
+
|
|
48406
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js
|
|
48407
|
+
var DEFAULT_SSE_KEEP_ALIVE_MS = 15e3;
|
|
48408
|
+
var MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
48409
|
+
function armSseKeepAlive(intervalMs, onTick) {
|
|
48410
|
+
if (!Number.isFinite(intervalMs) || intervalMs < 1) {
|
|
48411
|
+
return void 0;
|
|
48412
|
+
}
|
|
48413
|
+
const timer = setInterval(onTick, Math.min(intervalMs, MAX_TIMER_DELAY_MS));
|
|
48414
|
+
timer.unref?.();
|
|
48415
|
+
return timer;
|
|
48416
|
+
}
|
|
48417
|
+
__name(armSseKeepAlive, "armSseKeepAlive");
|
|
48418
|
+
|
|
48419
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js
|
|
48420
|
+
var WebStandardStreamableHTTPServerTransport = class {
|
|
48421
|
+
static {
|
|
48422
|
+
__name(this, "WebStandardStreamableHTTPServerTransport");
|
|
48423
|
+
}
|
|
48424
|
+
constructor(options = {}) {
|
|
48425
|
+
this._started = false;
|
|
48426
|
+
this._hasHandledRequest = false;
|
|
48427
|
+
this._streamMapping = /* @__PURE__ */ new Map();
|
|
48428
|
+
this._requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
48429
|
+
this._resumableStreams = /* @__PURE__ */ new Set();
|
|
48430
|
+
this._requestResponseMap = /* @__PURE__ */ new Map();
|
|
48431
|
+
this._initialized = false;
|
|
48432
|
+
this._enableJsonResponse = false;
|
|
48433
|
+
this._standaloneSseStreamId = "_GET_stream";
|
|
48434
|
+
this._closed = false;
|
|
48435
|
+
this.sessionIdGenerator = options.sessionIdGenerator;
|
|
48436
|
+
this._enableJsonResponse = options.enableJsonResponse ?? false;
|
|
48437
|
+
this._eventStore = options.eventStore;
|
|
48438
|
+
this._onsessioninitialized = options.onsessioninitialized;
|
|
48439
|
+
this._onsessionclosed = options.onsessionclosed;
|
|
48440
|
+
this._allowedHosts = options.allowedHosts;
|
|
48441
|
+
this._allowedOrigins = options.allowedOrigins;
|
|
48442
|
+
this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
|
|
48443
|
+
this._retryInterval = options.retryInterval;
|
|
48444
|
+
this._keepAliveMs = options.keepAliveMs ?? DEFAULT_SSE_KEEP_ALIVE_MS;
|
|
48445
|
+
this._maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
|
|
48446
|
+
}
|
|
48447
|
+
/**
|
|
48448
|
+
* Arms a keep-alive interval for an SSE stream that periodically writes an SSE
|
|
48449
|
+
* comment frame so intermediaries and idle timeouts don't kill the connection.
|
|
48450
|
+
* The returned timer is owned by the stream it was armed for: the stream's
|
|
48451
|
+
* cancel/cleanup callbacks must clear it. The interval clears itself if a
|
|
48452
|
+
* write fails (stream already closed/cancelled).
|
|
48453
|
+
*/
|
|
48454
|
+
startKeepAlive(controller, encoder) {
|
|
48455
|
+
if (this._closed)
|
|
48456
|
+
return void 0;
|
|
48457
|
+
const timer = armSseKeepAlive(this._keepAliveMs, () => {
|
|
48458
|
+
try {
|
|
48459
|
+
controller.enqueue(encoder.encode(": keepalive\n\n"));
|
|
48460
|
+
} catch {
|
|
48461
|
+
if (timer !== void 0)
|
|
48462
|
+
clearInterval(timer);
|
|
48463
|
+
}
|
|
48464
|
+
});
|
|
48465
|
+
return timer;
|
|
48466
|
+
}
|
|
48467
|
+
/**
|
|
48468
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
48469
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
48470
|
+
*/
|
|
48471
|
+
async start() {
|
|
48472
|
+
if (this._started) {
|
|
48473
|
+
throw new Error("Transport already started");
|
|
48474
|
+
}
|
|
48475
|
+
this._started = true;
|
|
48476
|
+
}
|
|
48477
|
+
/**
|
|
48478
|
+
* Helper to create a JSON error response
|
|
48479
|
+
*/
|
|
48480
|
+
createJsonErrorResponse(status, code, message, options) {
|
|
48481
|
+
const error62 = { code, message };
|
|
48482
|
+
if (options?.data !== void 0) {
|
|
48483
|
+
error62.data = options.data;
|
|
48484
|
+
}
|
|
48485
|
+
return new Response(JSON.stringify({
|
|
48486
|
+
jsonrpc: "2.0",
|
|
48487
|
+
error: error62,
|
|
48488
|
+
id: null
|
|
48489
|
+
}), {
|
|
48490
|
+
status,
|
|
48491
|
+
headers: {
|
|
48492
|
+
"Content-Type": "application/json",
|
|
48493
|
+
...options?.headers
|
|
48494
|
+
}
|
|
48495
|
+
});
|
|
48496
|
+
}
|
|
48497
|
+
/**
|
|
48498
|
+
* Validates request headers for DNS rebinding protection.
|
|
48499
|
+
* @returns Error response if validation fails, undefined if validation passes.
|
|
48500
|
+
*/
|
|
48501
|
+
validateRequestHeaders(req) {
|
|
48502
|
+
if (!this._enableDnsRebindingProtection) {
|
|
48503
|
+
return void 0;
|
|
48504
|
+
}
|
|
48505
|
+
if (this._allowedHosts && this._allowedHosts.length > 0) {
|
|
48506
|
+
const hostHeader = req.headers.get("host");
|
|
48507
|
+
if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
|
|
48508
|
+
const error62 = `Invalid Host header: ${hostHeader}`;
|
|
48509
|
+
this.onerror?.(new Error(error62));
|
|
48510
|
+
return this.createJsonErrorResponse(403, -32e3, error62);
|
|
48511
|
+
}
|
|
48512
|
+
}
|
|
48513
|
+
if (this._allowedOrigins && this._allowedOrigins.length > 0) {
|
|
48514
|
+
const originHeader = req.headers.get("origin");
|
|
48515
|
+
if (originHeader && !this._allowedOrigins.includes(originHeader)) {
|
|
48516
|
+
const error62 = `Invalid Origin header: ${originHeader}`;
|
|
48517
|
+
this.onerror?.(new Error(error62));
|
|
48518
|
+
return this.createJsonErrorResponse(403, -32e3, error62);
|
|
48519
|
+
}
|
|
48520
|
+
}
|
|
48521
|
+
return void 0;
|
|
48522
|
+
}
|
|
48523
|
+
/**
|
|
48524
|
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
|
48525
|
+
* Returns a Response object (Web Standard)
|
|
48526
|
+
*/
|
|
48527
|
+
async handleRequest(req, options) {
|
|
48528
|
+
if (this._closed) {
|
|
48529
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48530
|
+
}
|
|
48531
|
+
if (!this.sessionIdGenerator && this._hasHandledRequest) {
|
|
48532
|
+
throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
|
|
48533
|
+
}
|
|
48534
|
+
this._hasHandledRequest = true;
|
|
48535
|
+
const validationError = this.validateRequestHeaders(req);
|
|
48536
|
+
if (validationError) {
|
|
48537
|
+
return validationError;
|
|
48538
|
+
}
|
|
48539
|
+
switch (req.method) {
|
|
48540
|
+
case "POST":
|
|
48541
|
+
return this.handlePostRequest(req, options);
|
|
48542
|
+
case "GET":
|
|
48543
|
+
return this.handleGetRequest(req);
|
|
48544
|
+
case "DELETE":
|
|
48545
|
+
return this.handleDeleteRequest(req);
|
|
48546
|
+
default:
|
|
48547
|
+
return this.handleUnsupportedRequest();
|
|
48548
|
+
}
|
|
48549
|
+
}
|
|
48550
|
+
/**
|
|
48551
|
+
* Writes a priming event to establish resumption capability.
|
|
48552
|
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
|
48553
|
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
|
48554
|
+
*/
|
|
48555
|
+
async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
|
|
48556
|
+
if (!this._eventStore) {
|
|
48557
|
+
return;
|
|
48558
|
+
}
|
|
48559
|
+
if (protocolVersion < "2025-11-25") {
|
|
48560
|
+
return;
|
|
48561
|
+
}
|
|
48562
|
+
const primingEventId = await this._eventStore.storeEvent(streamId, {});
|
|
48563
|
+
let primingEvent = `id: ${primingEventId}
|
|
48564
|
+
data:
|
|
48565
|
+
|
|
48566
|
+
`;
|
|
48567
|
+
if (this._retryInterval !== void 0) {
|
|
48568
|
+
primingEvent = `id: ${primingEventId}
|
|
48569
|
+
retry: ${this._retryInterval}
|
|
48570
|
+
data:
|
|
48571
|
+
|
|
48572
|
+
`;
|
|
48573
|
+
}
|
|
48574
|
+
controller.enqueue(encoder.encode(primingEvent));
|
|
48575
|
+
this._resumableStreams.add(streamId);
|
|
48576
|
+
}
|
|
48577
|
+
/**
|
|
48578
|
+
* Handles GET requests for SSE stream
|
|
48579
|
+
*/
|
|
48580
|
+
async handleGetRequest(req) {
|
|
48581
|
+
const acceptHeader = req.headers.get("accept");
|
|
48582
|
+
if (!acceptHeader?.includes("text/event-stream")) {
|
|
48583
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept text/event-stream"));
|
|
48584
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
|
|
48585
|
+
}
|
|
48586
|
+
const sessionError = this.validateSession(req);
|
|
48587
|
+
if (sessionError) {
|
|
48588
|
+
return sessionError;
|
|
48589
|
+
}
|
|
48590
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48591
|
+
if (protocolError) {
|
|
48592
|
+
return protocolError;
|
|
48593
|
+
}
|
|
48594
|
+
if (this._eventStore) {
|
|
48595
|
+
const lastEventId = req.headers.get("last-event-id");
|
|
48596
|
+
if (lastEventId) {
|
|
48597
|
+
return this.replayEvents(lastEventId);
|
|
48598
|
+
}
|
|
48599
|
+
}
|
|
48600
|
+
if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
|
|
48601
|
+
this.onerror?.(new Error("Conflict: Only one SSE stream is allowed per session"));
|
|
48602
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
|
|
48603
|
+
}
|
|
48604
|
+
const encoder = new TextEncoder();
|
|
48605
|
+
let streamController;
|
|
48606
|
+
let keepAliveTimer = void 0;
|
|
48607
|
+
const readable = new ReadableStream({
|
|
48608
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48609
|
+
streamController = controller;
|
|
48610
|
+
}, "start"),
|
|
48611
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48612
|
+
if (keepAliveTimer !== void 0) {
|
|
48613
|
+
clearInterval(keepAliveTimer);
|
|
48614
|
+
}
|
|
48615
|
+
if (this._streamMapping.get(this._standaloneSseStreamId)?.controller === streamController) {
|
|
48616
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
48617
|
+
}
|
|
48618
|
+
}, "cancel")
|
|
48619
|
+
});
|
|
48620
|
+
const headers = {
|
|
48621
|
+
"Content-Type": "text/event-stream",
|
|
48622
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48623
|
+
Connection: "keep-alive",
|
|
48624
|
+
"X-Accel-Buffering": "no"
|
|
48625
|
+
};
|
|
48626
|
+
if (this.sessionId !== void 0) {
|
|
48627
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48628
|
+
}
|
|
48629
|
+
this._streamMapping.set(this._standaloneSseStreamId, {
|
|
48630
|
+
controller: streamController,
|
|
48631
|
+
encoder,
|
|
48632
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48633
|
+
if (keepAliveTimer !== void 0) {
|
|
48634
|
+
clearInterval(keepAliveTimer);
|
|
48635
|
+
}
|
|
48636
|
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
|
48637
|
+
try {
|
|
48638
|
+
streamController.close();
|
|
48639
|
+
} catch {
|
|
48640
|
+
}
|
|
48641
|
+
}, "cleanup")
|
|
48642
|
+
});
|
|
48643
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48644
|
+
return new Response(readable, { headers });
|
|
48645
|
+
}
|
|
48646
|
+
/**
|
|
48647
|
+
* Replays events that would have been sent after the specified event ID
|
|
48648
|
+
* Only used when resumability is enabled
|
|
48649
|
+
*/
|
|
48650
|
+
async replayEvents(lastEventId) {
|
|
48651
|
+
if (!this._eventStore) {
|
|
48652
|
+
this.onerror?.(new Error("Event store not configured"));
|
|
48653
|
+
return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
|
|
48654
|
+
}
|
|
48655
|
+
try {
|
|
48656
|
+
let streamId;
|
|
48657
|
+
if (this._eventStore.getStreamIdForEventId) {
|
|
48658
|
+
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
|
48659
|
+
if (!streamId) {
|
|
48660
|
+
this.onerror?.(new Error("Invalid event ID format"));
|
|
48661
|
+
return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
|
|
48662
|
+
}
|
|
48663
|
+
if (this._streamMapping.get(streamId) !== void 0) {
|
|
48664
|
+
this.onerror?.(new Error("Conflict: Stream already has an active connection"));
|
|
48665
|
+
return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
|
|
48666
|
+
}
|
|
48667
|
+
}
|
|
48668
|
+
const headers = {
|
|
48669
|
+
"Content-Type": "text/event-stream",
|
|
48670
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48671
|
+
Connection: "keep-alive",
|
|
48672
|
+
"X-Accel-Buffering": "no"
|
|
48673
|
+
};
|
|
48674
|
+
if (this.sessionId !== void 0) {
|
|
48675
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48676
|
+
}
|
|
48677
|
+
const encoder = new TextEncoder();
|
|
48678
|
+
let streamController;
|
|
48679
|
+
let keepAliveTimer = void 0;
|
|
48680
|
+
let replayedStreamId = void 0;
|
|
48681
|
+
let cancelled = false;
|
|
48682
|
+
const readable = new ReadableStream({
|
|
48683
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48684
|
+
streamController = controller;
|
|
48685
|
+
}, "start"),
|
|
48686
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48687
|
+
cancelled = true;
|
|
48688
|
+
if (keepAliveTimer !== void 0) {
|
|
48689
|
+
clearInterval(keepAliveTimer);
|
|
48690
|
+
}
|
|
48691
|
+
if (replayedStreamId !== void 0 && this._streamMapping.get(replayedStreamId)?.controller === streamController) {
|
|
48692
|
+
this._streamMapping.delete(replayedStreamId);
|
|
48693
|
+
}
|
|
48694
|
+
}, "cancel")
|
|
48695
|
+
});
|
|
48696
|
+
const replayedEventIds = /* @__PURE__ */ new Set();
|
|
48697
|
+
replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
|
|
48698
|
+
send: /* @__PURE__ */ __name(async (eventId, message) => {
|
|
48699
|
+
const success2 = this.writeSSEEvent(streamController, encoder, message, eventId);
|
|
48700
|
+
if (!success2) {
|
|
48701
|
+
this.onerror?.(new Error("Failed replay events"));
|
|
48702
|
+
try {
|
|
48703
|
+
streamController.close();
|
|
48704
|
+
} catch {
|
|
48705
|
+
}
|
|
48706
|
+
} else {
|
|
48707
|
+
replayedEventIds.add(eventId);
|
|
48708
|
+
}
|
|
48709
|
+
}, "send")
|
|
48710
|
+
});
|
|
48711
|
+
if (this._closed || cancelled) {
|
|
48712
|
+
try {
|
|
48713
|
+
streamController.close();
|
|
48714
|
+
} catch {
|
|
48715
|
+
}
|
|
48716
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48717
|
+
}
|
|
48718
|
+
this._streamMapping.get(replayedStreamId)?.cleanup();
|
|
48719
|
+
this._streamMapping.set(replayedStreamId, {
|
|
48720
|
+
controller: streamController,
|
|
48721
|
+
encoder,
|
|
48722
|
+
replayedEventIds,
|
|
48723
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48724
|
+
if (keepAliveTimer !== void 0) {
|
|
48725
|
+
clearInterval(keepAliveTimer);
|
|
48726
|
+
}
|
|
48727
|
+
this._streamMapping.delete(replayedStreamId);
|
|
48728
|
+
try {
|
|
48729
|
+
streamController.close();
|
|
48730
|
+
} catch {
|
|
48731
|
+
}
|
|
48732
|
+
}, "cleanup")
|
|
48733
|
+
});
|
|
48734
|
+
this._resumableStreams.add(replayedStreamId);
|
|
48735
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48736
|
+
return new Response(readable, { headers });
|
|
48737
|
+
} catch (error62) {
|
|
48738
|
+
this.onerror?.(error62);
|
|
48739
|
+
return this.createJsonErrorResponse(500, -32e3, "Error replaying events");
|
|
48740
|
+
}
|
|
48741
|
+
}
|
|
48742
|
+
/**
|
|
48743
|
+
* Writes an event to an SSE stream via controller with proper formatting
|
|
48744
|
+
*/
|
|
48745
|
+
writeSSEEvent(controller, encoder, message, eventId) {
|
|
48746
|
+
try {
|
|
48747
|
+
let eventData = `event: message
|
|
48748
|
+
`;
|
|
48749
|
+
if (eventId) {
|
|
48750
|
+
eventData += `id: ${eventId}
|
|
48751
|
+
`;
|
|
48752
|
+
}
|
|
48753
|
+
eventData += `data: ${JSON.stringify(message)}
|
|
48754
|
+
|
|
48755
|
+
`;
|
|
48756
|
+
controller.enqueue(encoder.encode(eventData));
|
|
48757
|
+
return true;
|
|
48758
|
+
} catch (error62) {
|
|
48759
|
+
this.onerror?.(error62);
|
|
48760
|
+
return false;
|
|
48761
|
+
}
|
|
48762
|
+
}
|
|
48763
|
+
/**
|
|
48764
|
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
|
48765
|
+
*/
|
|
48766
|
+
handleUnsupportedRequest() {
|
|
48767
|
+
this.onerror?.(new Error("Method not allowed."));
|
|
48768
|
+
return new Response(JSON.stringify({
|
|
48769
|
+
jsonrpc: "2.0",
|
|
48770
|
+
error: {
|
|
48771
|
+
code: -32e3,
|
|
48772
|
+
message: "Method not allowed."
|
|
48773
|
+
},
|
|
48774
|
+
id: null
|
|
48775
|
+
}), {
|
|
48776
|
+
status: 405,
|
|
48777
|
+
headers: {
|
|
48778
|
+
Allow: "GET, POST, DELETE",
|
|
48779
|
+
"Content-Type": "application/json"
|
|
48780
|
+
}
|
|
48781
|
+
});
|
|
48782
|
+
}
|
|
48783
|
+
/**
|
|
48784
|
+
* Handles POST requests containing JSON-RPC messages
|
|
48785
|
+
*/
|
|
48786
|
+
async handlePostRequest(req, options) {
|
|
48787
|
+
try {
|
|
48788
|
+
const acceptHeader = req.headers.get("accept");
|
|
48789
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
48790
|
+
this.onerror?.(new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
|
|
48791
|
+
return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
|
|
48792
|
+
}
|
|
48793
|
+
const ct = req.headers.get("content-type");
|
|
48794
|
+
if (!isJsonContentType(ct)) {
|
|
48795
|
+
this.onerror?.(new Error("Unsupported Media Type: Content-Type must be application/json"));
|
|
48796
|
+
return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
|
|
48797
|
+
}
|
|
48798
|
+
const requestInfo = {
|
|
48799
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
48800
|
+
url: new URL(req.url)
|
|
48801
|
+
};
|
|
48802
|
+
let rawMessage;
|
|
48803
|
+
if (options?.parsedBody !== void 0) {
|
|
48804
|
+
rawMessage = options.parsedBody;
|
|
48805
|
+
} else {
|
|
48806
|
+
try {
|
|
48807
|
+
const body = await readRequestBody(req, this._maxRequestBodySize);
|
|
48808
|
+
if (body.tooLarge) {
|
|
48809
|
+
const message = requestBodyTooLargeMessage(this._maxRequestBodySize);
|
|
48810
|
+
this.onerror?.(new Error(message));
|
|
48811
|
+
return this.createJsonErrorResponse(413, -32e3, message);
|
|
48812
|
+
}
|
|
48813
|
+
rawMessage = JSON.parse(body.text);
|
|
48814
|
+
} catch {
|
|
48815
|
+
this.onerror?.(new Error("Parse error: Invalid JSON"));
|
|
48816
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
|
|
48817
|
+
}
|
|
48818
|
+
}
|
|
48819
|
+
if (Array.isArray(rawMessage) && rawMessage.length > MAX_BATCH_SIZE) {
|
|
48820
|
+
this.onerror?.(new Error(`Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`));
|
|
48821
|
+
return this.createJsonErrorResponse(400, -32600, `Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`);
|
|
48822
|
+
}
|
|
48823
|
+
let messages;
|
|
48824
|
+
try {
|
|
48825
|
+
if (Array.isArray(rawMessage)) {
|
|
48826
|
+
messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
48827
|
+
} else {
|
|
48828
|
+
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
48829
|
+
}
|
|
48830
|
+
} catch {
|
|
48831
|
+
this.onerror?.(new Error("Parse error: Invalid JSON-RPC message"));
|
|
48832
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
|
|
48833
|
+
}
|
|
48834
|
+
if (this._closed) {
|
|
48835
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48836
|
+
}
|
|
48837
|
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
48838
|
+
if (isInitializationRequest) {
|
|
48839
|
+
if (this._initialized && this.sessionId !== void 0) {
|
|
48840
|
+
this.onerror?.(new Error("Invalid Request: Server already initialized"));
|
|
48841
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
|
|
48842
|
+
}
|
|
48843
|
+
if (messages.length > 1) {
|
|
48844
|
+
this.onerror?.(new Error("Invalid Request: Only one initialization request is allowed"));
|
|
48845
|
+
return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
|
|
48846
|
+
}
|
|
48847
|
+
this.sessionId = this.sessionIdGenerator?.();
|
|
48848
|
+
this._initialized = true;
|
|
48849
|
+
if (this.sessionId && this._onsessioninitialized) {
|
|
48850
|
+
await Promise.resolve(this._onsessioninitialized(this.sessionId));
|
|
48851
|
+
}
|
|
48852
|
+
}
|
|
48853
|
+
if (!isInitializationRequest) {
|
|
48854
|
+
const sessionError = this.validateSession(req);
|
|
48855
|
+
if (sessionError) {
|
|
48856
|
+
return sessionError;
|
|
48857
|
+
}
|
|
48858
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48859
|
+
if (protocolError) {
|
|
48860
|
+
return protocolError;
|
|
48861
|
+
}
|
|
48862
|
+
}
|
|
48863
|
+
if (this._closed) {
|
|
48864
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
48865
|
+
}
|
|
48866
|
+
const hasRequests = messages.some(isJSONRPCRequest);
|
|
48867
|
+
if (!hasRequests) {
|
|
48868
|
+
for (const message of messages) {
|
|
48869
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
|
48870
|
+
}
|
|
48871
|
+
return new Response(null, { status: 202 });
|
|
48872
|
+
}
|
|
48873
|
+
const streamId = crypto.randomUUID();
|
|
48874
|
+
const initRequest = messages.find((m) => isInitializeRequest(m));
|
|
48875
|
+
const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
|
|
48876
|
+
if (this._enableJsonResponse) {
|
|
48877
|
+
return new Promise((resolve) => {
|
|
48878
|
+
this._streamMapping.set(streamId, {
|
|
48879
|
+
resolveJson: resolve,
|
|
48880
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48881
|
+
this._streamMapping.delete(streamId);
|
|
48882
|
+
}, "cleanup")
|
|
48883
|
+
});
|
|
48884
|
+
for (const message of messages) {
|
|
48885
|
+
if (isJSONRPCRequest(message)) {
|
|
48886
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
48887
|
+
}
|
|
48888
|
+
}
|
|
48889
|
+
for (const message of messages) {
|
|
48890
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
|
48891
|
+
}
|
|
48892
|
+
});
|
|
48893
|
+
}
|
|
48894
|
+
const encoder = new TextEncoder();
|
|
48895
|
+
let streamController;
|
|
48896
|
+
let keepAliveTimer = void 0;
|
|
48897
|
+
const readable = new ReadableStream({
|
|
48898
|
+
start: /* @__PURE__ */ __name((controller) => {
|
|
48899
|
+
streamController = controller;
|
|
48900
|
+
}, "start"),
|
|
48901
|
+
cancel: /* @__PURE__ */ __name(() => {
|
|
48902
|
+
if (keepAliveTimer !== void 0) {
|
|
48903
|
+
clearInterval(keepAliveTimer);
|
|
48904
|
+
}
|
|
48905
|
+
if (this._streamMapping.get(streamId)?.controller === streamController) {
|
|
48906
|
+
this._streamMapping.delete(streamId);
|
|
48907
|
+
}
|
|
48908
|
+
}, "cancel")
|
|
48909
|
+
});
|
|
48910
|
+
const headers = {
|
|
48911
|
+
"Content-Type": "text/event-stream",
|
|
48912
|
+
"Cache-Control": "no-cache, no-transform",
|
|
48913
|
+
Connection: "keep-alive",
|
|
48914
|
+
"X-Accel-Buffering": "no"
|
|
48915
|
+
};
|
|
48916
|
+
if (this.sessionId !== void 0) {
|
|
48917
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
48918
|
+
}
|
|
48919
|
+
for (const message of messages) {
|
|
48920
|
+
if (isJSONRPCRequest(message)) {
|
|
48921
|
+
this._streamMapping.set(streamId, {
|
|
48922
|
+
controller: streamController,
|
|
48923
|
+
encoder,
|
|
48924
|
+
cleanup: /* @__PURE__ */ __name(() => {
|
|
48925
|
+
if (keepAliveTimer !== void 0) {
|
|
48926
|
+
clearInterval(keepAliveTimer);
|
|
48927
|
+
}
|
|
48928
|
+
this._streamMapping.delete(streamId);
|
|
48929
|
+
try {
|
|
48930
|
+
streamController.close();
|
|
48931
|
+
} catch {
|
|
48932
|
+
}
|
|
48933
|
+
}, "cleanup")
|
|
48934
|
+
});
|
|
48935
|
+
this._requestToStreamMapping.set(message.id, streamId);
|
|
48936
|
+
}
|
|
48937
|
+
}
|
|
48938
|
+
try {
|
|
48939
|
+
await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
|
|
48940
|
+
for (const message of messages) {
|
|
48941
|
+
let closeSSEStream;
|
|
48942
|
+
let closeStandaloneSSEStream;
|
|
48943
|
+
if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= "2025-11-25") {
|
|
48944
|
+
closeSSEStream = /* @__PURE__ */ __name(() => {
|
|
48945
|
+
this.closeSSEStream(message.id);
|
|
48946
|
+
}, "closeSSEStream");
|
|
48947
|
+
closeStandaloneSSEStream = /* @__PURE__ */ __name(() => {
|
|
48948
|
+
this.closeStandaloneSSEStream();
|
|
48949
|
+
}, "closeStandaloneSSEStream");
|
|
48950
|
+
}
|
|
48951
|
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
|
|
48952
|
+
}
|
|
48953
|
+
} catch (error62) {
|
|
48954
|
+
this._streamMapping.get(streamId)?.cleanup();
|
|
48955
|
+
this._resumableStreams.delete(streamId);
|
|
48956
|
+
for (const message of messages) {
|
|
48957
|
+
if (isJSONRPCRequest(message)) {
|
|
48958
|
+
this._requestToStreamMapping.delete(message.id);
|
|
48959
|
+
}
|
|
48960
|
+
}
|
|
48961
|
+
throw error62;
|
|
48962
|
+
}
|
|
48963
|
+
if (this._streamMapping.get(streamId)?.controller === streamController) {
|
|
48964
|
+
keepAliveTimer = this.startKeepAlive(streamController, encoder);
|
|
48965
|
+
}
|
|
48966
|
+
return new Response(readable, { status: 200, headers });
|
|
48967
|
+
} catch (error62) {
|
|
48968
|
+
this.onerror?.(error62);
|
|
48969
|
+
return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error62) });
|
|
48970
|
+
}
|
|
48971
|
+
}
|
|
48972
|
+
/**
|
|
48973
|
+
* Handles DELETE requests to terminate sessions
|
|
48974
|
+
*/
|
|
48975
|
+
async handleDeleteRequest(req) {
|
|
48976
|
+
const sessionError = this.validateSession(req);
|
|
48977
|
+
if (sessionError) {
|
|
48978
|
+
return sessionError;
|
|
48979
|
+
}
|
|
48980
|
+
const protocolError = this.validateProtocolVersion(req);
|
|
48981
|
+
if (protocolError) {
|
|
48982
|
+
return protocolError;
|
|
48983
|
+
}
|
|
48984
|
+
try {
|
|
48985
|
+
await Promise.resolve(this._onsessionclosed?.(this.sessionId));
|
|
48986
|
+
return new Response(null, { status: 200 });
|
|
48987
|
+
} finally {
|
|
48988
|
+
await this.close();
|
|
48989
|
+
}
|
|
48990
|
+
}
|
|
48991
|
+
/**
|
|
48992
|
+
* Validates session ID for non-initialization requests.
|
|
48993
|
+
* Returns Response error if invalid, undefined otherwise
|
|
48994
|
+
*/
|
|
48995
|
+
validateSession(req) {
|
|
48996
|
+
if (this.sessionIdGenerator === void 0) {
|
|
48997
|
+
return void 0;
|
|
48998
|
+
}
|
|
48999
|
+
if (!this._initialized) {
|
|
49000
|
+
this.onerror?.(new Error("Bad Request: Server not initialized"));
|
|
49001
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
|
|
49002
|
+
}
|
|
49003
|
+
const sessionId = req.headers.get("mcp-session-id");
|
|
49004
|
+
if (!sessionId) {
|
|
49005
|
+
this.onerror?.(new Error("Bad Request: Mcp-Session-Id header is required"));
|
|
49006
|
+
return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
|
|
49007
|
+
}
|
|
49008
|
+
if (sessionId !== this.sessionId) {
|
|
49009
|
+
this.onerror?.(new Error("Session not found"));
|
|
49010
|
+
return this.createJsonErrorResponse(404, -32001, "Session not found");
|
|
49011
|
+
}
|
|
49012
|
+
return void 0;
|
|
49013
|
+
}
|
|
49014
|
+
/**
|
|
49015
|
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
|
49016
|
+
*
|
|
49017
|
+
* For initialization: Version negotiation handles unknown versions gracefully
|
|
49018
|
+
* (server responds with its supported version).
|
|
49019
|
+
*
|
|
49020
|
+
* For subsequent requests with MCP-Protocol-Version header:
|
|
49021
|
+
* - Accept if in supported list
|
|
49022
|
+
* - 400 if unsupported
|
|
49023
|
+
*
|
|
49024
|
+
* For HTTP requests without the MCP-Protocol-Version header:
|
|
49025
|
+
* - Accept and default to the version negotiated at initialization
|
|
49026
|
+
*/
|
|
49027
|
+
validateProtocolVersion(req) {
|
|
49028
|
+
const protocolVersion = req.headers.get("mcp-protocol-version");
|
|
49029
|
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
|
49030
|
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`));
|
|
49031
|
+
return this.createJsonErrorResponse(400, -32e3, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`);
|
|
49032
|
+
}
|
|
49033
|
+
return void 0;
|
|
49034
|
+
}
|
|
49035
|
+
async close() {
|
|
49036
|
+
if (this._closed) {
|
|
49037
|
+
return;
|
|
49038
|
+
}
|
|
49039
|
+
this._closed = true;
|
|
49040
|
+
this._streamMapping.forEach(({ cleanup }) => {
|
|
49041
|
+
cleanup();
|
|
49042
|
+
});
|
|
49043
|
+
this._streamMapping.clear();
|
|
49044
|
+
this._requestResponseMap.clear();
|
|
49045
|
+
this._resumableStreams.clear();
|
|
49046
|
+
this.onclose?.();
|
|
49047
|
+
}
|
|
49048
|
+
/**
|
|
49049
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
49050
|
+
* Use this to implement polling behavior during long-running operations -
|
|
49051
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
49052
|
+
*/
|
|
49053
|
+
closeSSEStream(requestId) {
|
|
49054
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
49055
|
+
if (!streamId)
|
|
49056
|
+
return;
|
|
49057
|
+
const stream = this._streamMapping.get(streamId);
|
|
49058
|
+
if (stream) {
|
|
49059
|
+
stream.cleanup();
|
|
49060
|
+
}
|
|
49061
|
+
}
|
|
49062
|
+
/**
|
|
49063
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
49064
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
49065
|
+
*/
|
|
49066
|
+
closeStandaloneSSEStream() {
|
|
49067
|
+
const stream = this._streamMapping.get(this._standaloneSseStreamId);
|
|
49068
|
+
if (stream) {
|
|
49069
|
+
stream.cleanup();
|
|
49070
|
+
}
|
|
49071
|
+
}
|
|
49072
|
+
async send(message, options) {
|
|
49073
|
+
let requestId = options?.relatedRequestId;
|
|
49074
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49075
|
+
requestId = message.id;
|
|
49076
|
+
}
|
|
49077
|
+
if (requestId === void 0) {
|
|
49078
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49079
|
+
throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
49080
|
+
}
|
|
49081
|
+
let eventId;
|
|
49082
|
+
if (this._eventStore) {
|
|
49083
|
+
eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
|
|
49084
|
+
}
|
|
49085
|
+
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
|
|
49086
|
+
if (standaloneSse === void 0) {
|
|
49087
|
+
return;
|
|
49088
|
+
}
|
|
49089
|
+
if (standaloneSse.controller && standaloneSse.encoder && (eventId === void 0 || !standaloneSse.replayedEventIds?.has(eventId))) {
|
|
49090
|
+
this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
|
|
49091
|
+
}
|
|
49092
|
+
return;
|
|
49093
|
+
}
|
|
49094
|
+
const streamId = this._requestToStreamMapping.get(requestId);
|
|
49095
|
+
if (!streamId) {
|
|
49096
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
49097
|
+
}
|
|
49098
|
+
let stream = this._streamMapping.get(streamId);
|
|
49099
|
+
if (!this._enableJsonResponse) {
|
|
49100
|
+
let eventId;
|
|
49101
|
+
if (this._eventStore) {
|
|
49102
|
+
eventId = await this._eventStore.storeEvent(streamId, message);
|
|
49103
|
+
stream = this._streamMapping.get(streamId);
|
|
49104
|
+
}
|
|
49105
|
+
if (stream?.controller && stream?.encoder && (eventId === void 0 || !stream.replayedEventIds?.has(eventId))) {
|
|
49106
|
+
const written = this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
|
|
49107
|
+
if (written && eventId !== void 0) {
|
|
49108
|
+
this._resumableStreams.add(streamId);
|
|
49109
|
+
}
|
|
49110
|
+
}
|
|
49111
|
+
}
|
|
49112
|
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
|
49113
|
+
this._requestResponseMap.set(requestId, message);
|
|
49114
|
+
const relatedIds = Array.from(this._requestToStreamMapping.entries()).filter(([_, sid]) => sid === streamId).map(([id]) => id);
|
|
49115
|
+
const allResponsesReady = relatedIds.every((id) => this._requestResponseMap.has(id));
|
|
49116
|
+
if (allResponsesReady) {
|
|
49117
|
+
if (!stream) {
|
|
49118
|
+
if (this._closed) {
|
|
49119
|
+
for (const id of relatedIds) {
|
|
49120
|
+
this._requestResponseMap.delete(id);
|
|
49121
|
+
this._requestToStreamMapping.delete(id);
|
|
49122
|
+
}
|
|
49123
|
+
return;
|
|
49124
|
+
}
|
|
49125
|
+
if (!this._enableJsonResponse && this._eventStore && this._resumableStreams.has(streamId)) {
|
|
49126
|
+
for (const id of relatedIds) {
|
|
49127
|
+
this._requestResponseMap.delete(id);
|
|
49128
|
+
this._requestToStreamMapping.delete(id);
|
|
49129
|
+
}
|
|
49130
|
+
this._resumableStreams.delete(streamId);
|
|
49131
|
+
return;
|
|
49132
|
+
}
|
|
49133
|
+
for (const id of relatedIds) {
|
|
49134
|
+
this._requestResponseMap.delete(id);
|
|
49135
|
+
this._requestToStreamMapping.delete(id);
|
|
49136
|
+
}
|
|
49137
|
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
49138
|
+
}
|
|
49139
|
+
if (this._enableJsonResponse && stream.resolveJson) {
|
|
49140
|
+
const headers = {
|
|
49141
|
+
"Content-Type": "application/json"
|
|
49142
|
+
};
|
|
49143
|
+
if (this.sessionId !== void 0) {
|
|
49144
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
49145
|
+
}
|
|
49146
|
+
const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
|
|
49147
|
+
if (responses.length === 1) {
|
|
49148
|
+
stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
|
|
49149
|
+
} else {
|
|
49150
|
+
stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
|
|
49151
|
+
}
|
|
49152
|
+
} else {
|
|
49153
|
+
stream.cleanup();
|
|
49154
|
+
}
|
|
49155
|
+
for (const id of relatedIds) {
|
|
49156
|
+
this._requestResponseMap.delete(id);
|
|
49157
|
+
this._requestToStreamMapping.delete(id);
|
|
49158
|
+
}
|
|
49159
|
+
this._resumableStreams.delete(streamId);
|
|
49160
|
+
}
|
|
49161
|
+
}
|
|
49162
|
+
}
|
|
49163
|
+
};
|
|
49164
|
+
|
|
49165
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js
|
|
49166
|
+
var StreamableHTTPServerTransport = class {
|
|
49167
|
+
static {
|
|
49168
|
+
__name(this, "StreamableHTTPServerTransport");
|
|
49169
|
+
}
|
|
49170
|
+
constructor(options = {}) {
|
|
49171
|
+
this._requestContext = /* @__PURE__ */ new WeakMap();
|
|
49172
|
+
this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options);
|
|
49173
|
+
this._requestListener = getRequestListener(async (webRequest) => {
|
|
49174
|
+
const context = this._requestContext.get(webRequest);
|
|
49175
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
49176
|
+
authInfo: context?.authInfo,
|
|
49177
|
+
parsedBody: context?.parsedBody
|
|
49178
|
+
});
|
|
49179
|
+
}, { overrideGlobalObjects: false });
|
|
49180
|
+
}
|
|
49181
|
+
/**
|
|
49182
|
+
* Gets the session ID for this transport instance.
|
|
49183
|
+
*/
|
|
49184
|
+
get sessionId() {
|
|
49185
|
+
return this._webStandardTransport.sessionId;
|
|
49186
|
+
}
|
|
49187
|
+
/**
|
|
49188
|
+
* Sets callback for when the transport is closed.
|
|
49189
|
+
*/
|
|
49190
|
+
set onclose(handler) {
|
|
49191
|
+
this._webStandardTransport.onclose = handler;
|
|
49192
|
+
}
|
|
49193
|
+
get onclose() {
|
|
49194
|
+
return this._webStandardTransport.onclose;
|
|
49195
|
+
}
|
|
49196
|
+
/**
|
|
49197
|
+
* Sets callback for transport errors.
|
|
49198
|
+
*/
|
|
49199
|
+
set onerror(handler) {
|
|
49200
|
+
this._webStandardTransport.onerror = handler;
|
|
49201
|
+
}
|
|
49202
|
+
get onerror() {
|
|
49203
|
+
return this._webStandardTransport.onerror;
|
|
49204
|
+
}
|
|
49205
|
+
/**
|
|
49206
|
+
* Sets callback for incoming messages.
|
|
49207
|
+
*/
|
|
49208
|
+
set onmessage(handler) {
|
|
49209
|
+
this._webStandardTransport.onmessage = handler;
|
|
49210
|
+
}
|
|
49211
|
+
get onmessage() {
|
|
49212
|
+
return this._webStandardTransport.onmessage;
|
|
49213
|
+
}
|
|
49214
|
+
/**
|
|
49215
|
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
|
49216
|
+
* for the Streamable HTTP transport as connections are managed per-request.
|
|
49217
|
+
*/
|
|
49218
|
+
async start() {
|
|
49219
|
+
return this._webStandardTransport.start();
|
|
49220
|
+
}
|
|
49221
|
+
/**
|
|
49222
|
+
* Closes the transport and all active connections.
|
|
49223
|
+
*/
|
|
49224
|
+
async close() {
|
|
49225
|
+
return this._webStandardTransport.close();
|
|
49226
|
+
}
|
|
49227
|
+
/**
|
|
49228
|
+
* Sends a JSON-RPC message through the transport.
|
|
49229
|
+
*/
|
|
49230
|
+
async send(message, options) {
|
|
49231
|
+
return this._webStandardTransport.send(message, options);
|
|
49232
|
+
}
|
|
49233
|
+
/**
|
|
49234
|
+
* Handles an incoming HTTP request, whether GET or POST.
|
|
49235
|
+
*
|
|
49236
|
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
|
49237
|
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
|
49238
|
+
*
|
|
49239
|
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
|
49240
|
+
* @param res - Node.js ServerResponse
|
|
49241
|
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
|
49242
|
+
*/
|
|
49243
|
+
async handleRequest(req, res, parsedBody) {
|
|
49244
|
+
const authInfo = req.auth;
|
|
49245
|
+
const handler = getRequestListener(async (webRequest) => {
|
|
49246
|
+
return this._webStandardTransport.handleRequest(webRequest, {
|
|
49247
|
+
authInfo,
|
|
49248
|
+
parsedBody
|
|
49249
|
+
});
|
|
49250
|
+
}, { overrideGlobalObjects: false });
|
|
49251
|
+
await handler(req, res);
|
|
49252
|
+
}
|
|
49253
|
+
/**
|
|
49254
|
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
|
49255
|
+
* Use this to implement polling behavior during long-running operations -
|
|
49256
|
+
* client will reconnect after the retry interval specified in the priming event.
|
|
49257
|
+
*/
|
|
49258
|
+
closeSSEStream(requestId) {
|
|
49259
|
+
this._webStandardTransport.closeSSEStream(requestId);
|
|
49260
|
+
}
|
|
49261
|
+
/**
|
|
49262
|
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
|
49263
|
+
* Use this to implement polling behavior for server-initiated notifications.
|
|
49264
|
+
*/
|
|
49265
|
+
closeStandaloneSSEStream() {
|
|
49266
|
+
this._webStandardTransport.closeStandaloneSSEStream();
|
|
49267
|
+
}
|
|
49268
|
+
};
|
|
49269
|
+
|
|
47000
49270
|
// src/tools/read.ts
|
|
47001
49271
|
init_library();
|
|
47002
49272
|
|
|
@@ -48972,7 +51242,7 @@ function registerStatusTool(server, internal) {
|
|
|
48972
51242
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
48973
51243
|
}, () => run(async () => {
|
|
48974
51244
|
const t = await findTarget().catch((e) => ({ error: e.message }));
|
|
48975
|
-
const
|
|
51245
|
+
const core2 = "error" in t ? { error: t.error } : { name: t.info.name, version: t.info.version, address: t.host };
|
|
48976
51246
|
if (!("error" in t)) await paired(5e3).catch(() => null);
|
|
48977
51247
|
const paired2 = isPaired();
|
|
48978
51248
|
if (internal && paired2 && !selfTestResults()) await selfTest(runSelfTest);
|
|
@@ -48980,7 +51250,7 @@ function registerStatusTool(server, internal) {
|
|
|
48980
51250
|
return {
|
|
48981
51251
|
deep_roon_mcp: version2,
|
|
48982
51252
|
newer_version: updateInfo() ?? void 0,
|
|
48983
|
-
core,
|
|
51253
|
+
core: core2,
|
|
48984
51254
|
enabled_in_roon: paired2 || 'not yet: Roon \u203A Settings \u203A Extensions \u203A Enable next to "Deep Roon MCP"',
|
|
48985
51255
|
internal_protocol: internal ? checks2 ? checks2.every((c) => c.ok) ? "works" : "partly broken \u2014 see self_test" : "not tested yet" : "switched off (only the official API)",
|
|
48986
51256
|
self_test: checks2 ?? void 0
|
|
@@ -49000,10 +51270,8 @@ var INSTRUCTIONS = `Deep Roon MCP connects to the user's own Roon Core (music pl
|
|
|
49000
51270
|
- What plays changes all the time: read roon_now_playing afresh before describing it.
|
|
49001
51271
|
- "Daily Mixes" are Roon's own (roon_mixes); the user's TIDAL mixes (My Mix 1 \u2026, My Daily Discovery) are roon_tidal_playlists with shelf my_mixes, and their tracks can be read with roon_playlist.
|
|
49002
51272
|
- Unofficial: this uses Roon's internal protocol, which a Roon update can change; if a tool says so, tell the user to check for an update.`;
|
|
49003
|
-
|
|
51273
|
+
function buildServer(internal, essentials) {
|
|
49004
51274
|
const server = new McpServer({ name: "deep-roon-mcp", title: "Deep Roon MCP", version: version2, websiteUrl: "https://github.com/renebouwmeester/deep-roon-mcp" }, { instructions: INSTRUCTIONS });
|
|
49005
|
-
const internal = !/^(off|false|0|no)$/i.test(process.env.DEEP_ROON_INTERNAL ?? "");
|
|
49006
|
-
const essentials = /^(essentials|true|1|yes)$/i.test(process.env.DEEP_ROON_TOOLS ?? process.env.DEEP_ROON_ESSENTIALS ?? "");
|
|
49007
51275
|
if (essentials) {
|
|
49008
51276
|
const keep = /* @__PURE__ */ new Set([
|
|
49009
51277
|
"roon_status",
|
|
@@ -49030,15 +51298,71 @@ async function main() {
|
|
|
49030
51298
|
registerStatusTool(server, internal);
|
|
49031
51299
|
registerReadTools(server, internal);
|
|
49032
51300
|
registerControlTools(server, internal);
|
|
49033
|
-
if (internal)
|
|
49034
|
-
|
|
49035
|
-
|
|
49036
|
-
|
|
51301
|
+
if (internal) registerLibraryTools(server);
|
|
51302
|
+
return server;
|
|
51303
|
+
}
|
|
51304
|
+
__name(buildServer, "buildServer");
|
|
51305
|
+
function serveHttp(spec, internal, essentials) {
|
|
51306
|
+
const m = /^(?:(.+):)?(\d+)$/.exec(spec.trim());
|
|
51307
|
+
if (!m) {
|
|
51308
|
+
log(`DEEP_ROON_HTTP should be [host:]port, not "${spec}"`);
|
|
51309
|
+
process.exit(1);
|
|
51310
|
+
}
|
|
51311
|
+
const host = m[1] || "127.0.0.1", port = Number(m[2]);
|
|
51312
|
+
const web = import_http.default.createServer(async (req, res) => {
|
|
51313
|
+
if (req.url?.split("?")[0] !== "/mcp") {
|
|
51314
|
+
res.writeHead(404).end();
|
|
51315
|
+
return;
|
|
51316
|
+
}
|
|
51317
|
+
if (req.method !== "POST") {
|
|
51318
|
+
res.writeHead(405, { allow: "POST" }).end();
|
|
51319
|
+
return;
|
|
51320
|
+
}
|
|
51321
|
+
const chunks = [];
|
|
51322
|
+
for await (const c of req) chunks.push(c);
|
|
51323
|
+
let body;
|
|
51324
|
+
try {
|
|
51325
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
51326
|
+
} catch {
|
|
51327
|
+
res.writeHead(400).end("Parse error");
|
|
51328
|
+
return;
|
|
51329
|
+
}
|
|
51330
|
+
const server = buildServer(internal, essentials);
|
|
51331
|
+
const transport2 = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0, enableJsonResponse: true });
|
|
51332
|
+
res.on("close", () => {
|
|
51333
|
+
transport2.close().catch(() => {
|
|
51334
|
+
});
|
|
51335
|
+
server.close().catch(() => {
|
|
51336
|
+
});
|
|
51337
|
+
});
|
|
51338
|
+
try {
|
|
51339
|
+
await server.connect(transport2);
|
|
51340
|
+
await transport2.handleRequest(req, res, body);
|
|
51341
|
+
} catch (e) {
|
|
51342
|
+
log(`http: ${e.message}`);
|
|
51343
|
+
if (!res.headersSent) res.writeHead(500).end();
|
|
51344
|
+
}
|
|
51345
|
+
});
|
|
51346
|
+
web.listen(port, host, () => log(`${version2} ready (http://${host}:${port}/mcp)`));
|
|
51347
|
+
}
|
|
51348
|
+
__name(serveHttp, "serveHttp");
|
|
51349
|
+
async function main() {
|
|
51350
|
+
const internal = !/^(off|false|0|no)$/i.test(process.env.DEEP_ROON_INTERNAL ?? "");
|
|
51351
|
+
const essentials = /^(essentials|true|1|yes)$/i.test(process.env.DEEP_ROON_TOOLS ?? process.env.DEEP_ROON_ESSENTIALS ?? "");
|
|
51352
|
+
if (internal) afterFirstConnect(() => selfTest(runSelfTest));
|
|
49037
51353
|
checkForUpdate().catch(() => {
|
|
49038
51354
|
});
|
|
49039
51355
|
log(`${internal ? "internal protocol on" : "internal protocol OFF \u2014 official API only"}${essentials ? ", essentials" : ""}`);
|
|
49040
|
-
|
|
49041
|
-
|
|
51356
|
+
const httpSpec = process.env.DEEP_ROON_HTTP;
|
|
51357
|
+
if (httpSpec) serveHttp(httpSpec, internal, essentials);
|
|
51358
|
+
else {
|
|
51359
|
+
await buildServer(internal, essentials).connect(new StdioServerTransport());
|
|
51360
|
+
log(`${version2} ready (stdio)`);
|
|
51361
|
+
process.stdin.on("close", () => {
|
|
51362
|
+
shutdown();
|
|
51363
|
+
process.exit(0);
|
|
51364
|
+
});
|
|
51365
|
+
}
|
|
49042
51366
|
findTarget().catch((e) => log(`no Roon Core yet: ${e.message}`));
|
|
49043
51367
|
const stop = /* @__PURE__ */ __name(() => {
|
|
49044
51368
|
shutdown();
|
|
@@ -49046,10 +51370,10 @@ async function main() {
|
|
|
49046
51370
|
}, "stop");
|
|
49047
51371
|
process.on("SIGINT", stop);
|
|
49048
51372
|
process.on("SIGTERM", stop);
|
|
49049
|
-
process.stdin.on("close", stop);
|
|
49050
51373
|
}
|
|
49051
51374
|
__name(main, "main");
|
|
49052
51375
|
main().catch((e) => {
|
|
49053
51376
|
log(`fatal: ${e.message}`);
|
|
49054
51377
|
process.exit(1);
|
|
49055
51378
|
});
|
|
51379
|
+
/*! For license information please see deep-roon-mcp.js.LEGAL.txt */
|