@zuplo/cli 6.70.40 → 6.70.42
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/node_modules/@protobufjs/eventemitter/CHANGELOG.md +8 -0
- package/node_modules/@protobufjs/eventemitter/index.d.ts +10 -8
- package/node_modules/@protobufjs/eventemitter/index.js +17 -7
- package/node_modules/@protobufjs/eventemitter/package.json +2 -2
- package/node_modules/@protobufjs/eventemitter/tests/index.js +39 -3
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/browser-login-idp-HQB254PW.js +26 -0
- package/node_modules/@zuplo/runtime/out/esm/browser-login-idp-HQB254PW.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/{chunk-2GVPMQ7M.js → chunk-A6TMPOZH.js} +52 -52
- package/node_modules/@zuplo/runtime/out/esm/chunk-A6TMPOZH.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/chunk-B6R5XTUK.js +30 -0
- package/node_modules/@zuplo/runtime/out/esm/chunk-B6R5XTUK.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +23 -3
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
- package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +164 -12
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/hono/dist/adapter/deno/websocket.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/deno/websocket.js +5 -1
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +21 -1
- package/node_modules/hono/dist/cjs/utils/compress.js +1 -1
- package/node_modules/hono/dist/cjs/utils/mime.js +15 -17
- package/node_modules/hono/dist/middleware/compress/index.js +21 -1
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +1 -1
- package/node_modules/hono/dist/types/middleware/compress/index.d.ts +2 -1
- package/node_modules/hono/dist/types/utils/mime.d.ts +11 -11
- package/node_modules/hono/dist/utils/compress.js +1 -1
- package/node_modules/hono/dist/utils/mime.js +15 -17
- package/node_modules/hono/package.json +3 -3
- package/node_modules/protobufjs/dist/light/protobuf.js +127 -69
- package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.js +62 -25
- package/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/dist/protobuf.js +148 -76
- package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/ext/descriptor/index.js +7 -2
- package/node_modules/protobufjs/index.d.ts +12 -3
- package/node_modules/protobufjs/package.json +2 -2
- package/node_modules/protobufjs/src/converter.js +8 -5
- package/node_modules/protobufjs/src/encoder.js +8 -5
- package/node_modules/protobufjs/src/enum.js +2 -2
- package/node_modules/protobufjs/src/field.js +1 -1
- package/node_modules/protobufjs/src/namespace.js +2 -0
- package/node_modules/protobufjs/src/object.js +6 -6
- package/node_modules/protobufjs/src/parse.js +19 -5
- package/node_modules/protobufjs/src/root.js +14 -8
- package/node_modules/protobufjs/src/type.js +8 -5
- package/node_modules/protobufjs/src/util/minimal.js +32 -7
- package/node_modules/protobufjs/src/util/patterns.js +0 -1
- package/node_modules/protobufjs/src/util.js +4 -3
- package/node_modules/protobufjs/src/wrappers.js +11 -7
- package/node_modules/protobufjs/src/writer.js +11 -9
- package/package.json +6 -6
- package/node_modules/@zuplo/runtime/out/esm/browser-login-idp-HWMCSYMR.js +0 -26
- package/node_modules/@zuplo/runtime/out/esm/browser-login-idp-HWMCSYMR.js.map +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-2GVPMQ7M.js.map +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-FYGTTP3G.js +0 -30
- package/node_modules/@zuplo/runtime/out/esm/chunk-FYGTTP3G.js.map +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-2GVPMQ7M.js.LEGAL.txt → chunk-A6TMPOZH.js.LEGAL.txt} +0 -0
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* MCP tool annotations to expose downstream.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
declare interface Annotations {
|
|
8
|
+
[k: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
declare interface ApiRuntimeConfig {
|
|
4
12
|
urls: UrlConfig | undefined;
|
|
5
13
|
}
|
|
@@ -1038,29 +1046,100 @@ export declare class McpCapabilityFilterInboundPolicy extends InboundPolicy<Vali
|
|
|
1038
1046
|
*/
|
|
1039
1047
|
export declare interface McpCapabilityFilterInboundPolicyOptions {
|
|
1040
1048
|
/**
|
|
1041
|
-
*
|
|
1049
|
+
* Tools to expose. Use a string for name-only filtering, or an object to expose and project tool description, annotations, and _meta. Omit to pass through all upstream tools; use an empty array to expose no tools.
|
|
1042
1050
|
*/
|
|
1043
|
-
tools?: string[];
|
|
1051
|
+
tools?: (string | ToolProjection)[];
|
|
1044
1052
|
/**
|
|
1045
|
-
*
|
|
1053
|
+
* Prompts to expose. Use a string for name-only filtering, or an object to expose and project prompt description and _meta. Omit to pass through all upstream prompts; use an empty array to expose no prompts.
|
|
1046
1054
|
*/
|
|
1047
|
-
prompts?: string[];
|
|
1055
|
+
prompts?: (string | PromptProjection)[];
|
|
1048
1056
|
/**
|
|
1049
|
-
*
|
|
1057
|
+
* Resources to expose. Use a string for URI-only filtering, or an object to expose and project resource name, description, MIME type, and _meta. Omit to pass through all upstream resources; use an empty array to expose no resources.
|
|
1050
1058
|
*/
|
|
1051
|
-
resources?: string[];
|
|
1059
|
+
resources?: (string | ResourceProjection)[];
|
|
1052
1060
|
/**
|
|
1053
|
-
* Resource
|
|
1061
|
+
* Resource templates to expose. Use a string for URI-template-only filtering, or an object to expose and project template name, description, MIME type, and _meta. Omit to pass through all upstream resource templates; use an empty array to expose no resource templates.
|
|
1054
1062
|
*/
|
|
1055
|
-
resourceTemplates?: string[];
|
|
1063
|
+
resourceTemplates?: (string | ResourceTemplateProjection)[];
|
|
1056
1064
|
}
|
|
1057
1065
|
|
|
1058
1066
|
declare const mcpCapabilityFilterOptionsSchema: z.ZodObject<
|
|
1059
1067
|
{
|
|
1060
|
-
tools: z.ZodOptional<
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1068
|
+
tools: z.ZodOptional<
|
|
1069
|
+
z.ZodArray<
|
|
1070
|
+
z.ZodUnion<
|
|
1071
|
+
readonly [
|
|
1072
|
+
z.ZodString,
|
|
1073
|
+
z.ZodObject<
|
|
1074
|
+
{
|
|
1075
|
+
name: z.ZodString;
|
|
1076
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1077
|
+
annotations: z.ZodOptional<
|
|
1078
|
+
z.ZodRecord<z.ZodString, z.ZodUnknown>
|
|
1079
|
+
>;
|
|
1080
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1081
|
+
},
|
|
1082
|
+
z.core.$strict
|
|
1083
|
+
>,
|
|
1084
|
+
]
|
|
1085
|
+
>
|
|
1086
|
+
>
|
|
1087
|
+
>;
|
|
1088
|
+
prompts: z.ZodOptional<
|
|
1089
|
+
z.ZodArray<
|
|
1090
|
+
z.ZodUnion<
|
|
1091
|
+
readonly [
|
|
1092
|
+
z.ZodString,
|
|
1093
|
+
z.ZodObject<
|
|
1094
|
+
{
|
|
1095
|
+
name: z.ZodString;
|
|
1096
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1097
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1098
|
+
},
|
|
1099
|
+
z.core.$strict
|
|
1100
|
+
>,
|
|
1101
|
+
]
|
|
1102
|
+
>
|
|
1103
|
+
>
|
|
1104
|
+
>;
|
|
1105
|
+
resources: z.ZodOptional<
|
|
1106
|
+
z.ZodArray<
|
|
1107
|
+
z.ZodUnion<
|
|
1108
|
+
readonly [
|
|
1109
|
+
z.ZodString,
|
|
1110
|
+
z.ZodObject<
|
|
1111
|
+
{
|
|
1112
|
+
uri: z.ZodString;
|
|
1113
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1114
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1115
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
1116
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1117
|
+
},
|
|
1118
|
+
z.core.$strict
|
|
1119
|
+
>,
|
|
1120
|
+
]
|
|
1121
|
+
>
|
|
1122
|
+
>
|
|
1123
|
+
>;
|
|
1124
|
+
resourceTemplates: z.ZodOptional<
|
|
1125
|
+
z.ZodArray<
|
|
1126
|
+
z.ZodUnion<
|
|
1127
|
+
readonly [
|
|
1128
|
+
z.ZodString,
|
|
1129
|
+
z.ZodObject<
|
|
1130
|
+
{
|
|
1131
|
+
uriTemplate: z.ZodString;
|
|
1132
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1133
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1134
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
1135
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1136
|
+
},
|
|
1137
|
+
z.core.$strict
|
|
1138
|
+
>,
|
|
1139
|
+
]
|
|
1140
|
+
>
|
|
1141
|
+
>
|
|
1142
|
+
>;
|
|
1064
1143
|
},
|
|
1065
1144
|
z.core.$strict
|
|
1066
1145
|
>;
|
|
@@ -1339,6 +1418,14 @@ export declare interface McpTokenExchangeInboundPolicyOptions {
|
|
|
1339
1418
|
};
|
|
1340
1419
|
}
|
|
1341
1420
|
|
|
1421
|
+
/**
|
|
1422
|
+
* Arbitrary MCP _meta fields to expose downstream.
|
|
1423
|
+
* @public
|
|
1424
|
+
*/
|
|
1425
|
+
declare interface Metadata {
|
|
1426
|
+
[k: string]: unknown;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1342
1429
|
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
1343
1430
|
|
|
1344
1431
|
declare interface NotFoundOptions {
|
|
@@ -2092,6 +2179,18 @@ declare interface ProblemResponseFormat {
|
|
|
2092
2179
|
): Promise<Response> | Response;
|
|
2093
2180
|
}
|
|
2094
2181
|
|
|
2182
|
+
declare interface PromptProjection {
|
|
2183
|
+
/**
|
|
2184
|
+
* Prompt name to expose.
|
|
2185
|
+
*/
|
|
2186
|
+
name: string;
|
|
2187
|
+
/**
|
|
2188
|
+
* Optional downstream-facing prompt description override.
|
|
2189
|
+
*/
|
|
2190
|
+
description?: string;
|
|
2191
|
+
_meta?: Metadata;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2095
2194
|
/**
|
|
2096
2195
|
* Generic type parameters for a request.
|
|
2097
2196
|
* Extends RequestInitGeneric and adds query parameter typing.
|
|
@@ -2153,6 +2252,46 @@ declare type ResolveRequestQuery<
|
|
|
2153
2252
|
declare type ResolveUserData<TUserData extends UserDataDefault | undefined> =
|
|
2154
2253
|
TUserData extends UserDataDefault ? TUserData : UserDataDefault;
|
|
2155
2254
|
|
|
2255
|
+
declare interface ResourceProjection {
|
|
2256
|
+
/**
|
|
2257
|
+
* Resource URI to expose.
|
|
2258
|
+
*/
|
|
2259
|
+
uri: string;
|
|
2260
|
+
/**
|
|
2261
|
+
* Optional downstream-facing resource name override.
|
|
2262
|
+
*/
|
|
2263
|
+
name?: string;
|
|
2264
|
+
/**
|
|
2265
|
+
* Optional downstream-facing resource description override.
|
|
2266
|
+
*/
|
|
2267
|
+
description?: string;
|
|
2268
|
+
/**
|
|
2269
|
+
* Optional downstream-facing resource MIME type override.
|
|
2270
|
+
*/
|
|
2271
|
+
mimeType?: string;
|
|
2272
|
+
_meta?: Metadata;
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
declare interface ResourceTemplateProjection {
|
|
2276
|
+
/**
|
|
2277
|
+
* Resource template URI template to expose.
|
|
2278
|
+
*/
|
|
2279
|
+
uriTemplate: string;
|
|
2280
|
+
/**
|
|
2281
|
+
* Optional downstream-facing resource template name override.
|
|
2282
|
+
*/
|
|
2283
|
+
name?: string;
|
|
2284
|
+
/**
|
|
2285
|
+
* Optional downstream-facing resource template description override.
|
|
2286
|
+
*/
|
|
2287
|
+
description?: string;
|
|
2288
|
+
/**
|
|
2289
|
+
* Optional downstream-facing resource template MIME type override.
|
|
2290
|
+
*/
|
|
2291
|
+
mimeType?: string;
|
|
2292
|
+
_meta?: Metadata;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2156
2295
|
/**
|
|
2157
2296
|
* Definition of responses for a route
|
|
2158
2297
|
* @public
|
|
@@ -2271,6 +2410,19 @@ declare abstract class SystemRuntimePlugin extends RuntimePlugin {
|
|
|
2271
2410
|
/* Excluded from this release type: registerRoutes */
|
|
2272
2411
|
}
|
|
2273
2412
|
|
|
2413
|
+
declare interface ToolProjection {
|
|
2414
|
+
/**
|
|
2415
|
+
* Tool name to expose.
|
|
2416
|
+
*/
|
|
2417
|
+
name: string;
|
|
2418
|
+
/**
|
|
2419
|
+
* Optional downstream-facing tool description override.
|
|
2420
|
+
*/
|
|
2421
|
+
description?: string;
|
|
2422
|
+
annotations?: Annotations;
|
|
2423
|
+
_meta?: Metadata;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2274
2426
|
declare type UpstreamTokenExchangePolicyOptions = z.infer<
|
|
2275
2427
|
typeof upstreamTokenExchangePolicyOptionsSchema
|
|
2276
2428
|
>;
|
|
@@ -4,7 +4,11 @@ var upgradeWebSocket = defineWebSocketHelper(async (c, events, options) => {
|
|
|
4
4
|
if (c.req.header("upgrade") !== "websocket") {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
const
|
|
7
|
+
const subprotocol = c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim();
|
|
8
|
+
const { response, socket } = Deno.upgradeWebSocket(c.req.raw, {
|
|
9
|
+
...subprotocol ? { protocol: subprotocol } : {},
|
|
10
|
+
...options
|
|
11
|
+
});
|
|
8
12
|
const wsContext = new WSContext({
|
|
9
13
|
close: (code, reason) => socket.close(code, reason),
|
|
10
14
|
get protocol() {
|
|
@@ -25,7 +25,11 @@ const upgradeWebSocket = (0, import_websocket.defineWebSocketHelper)(async (c, e
|
|
|
25
25
|
if (c.req.header("upgrade") !== "websocket") {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const subprotocol = c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim();
|
|
29
|
+
const { response, socket } = Deno.upgradeWebSocket(c.req.raw, {
|
|
30
|
+
...subprotocol ? { protocol: subprotocol } : {},
|
|
31
|
+
...options
|
|
32
|
+
});
|
|
29
33
|
const wsContext = new import_websocket.WSContext({
|
|
30
34
|
close: (code, reason) => socket.close(code, reason),
|
|
31
35
|
get protocol() {
|
|
@@ -20,11 +20,31 @@ __export(compress_exports, {
|
|
|
20
20
|
compress: () => compress
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(compress_exports);
|
|
23
|
+
var import_accept = require("../../utils/accept");
|
|
23
24
|
var import_compress = require("../../utils/compress");
|
|
24
25
|
const ENCODING_TYPES = ["gzip", "deflate"];
|
|
25
26
|
const cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i;
|
|
27
|
+
const selectEncoding = (header, candidates) => {
|
|
28
|
+
if (header === void 0) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
const accepts = (0, import_accept.parseAccept)(header);
|
|
32
|
+
const wildcardQ = accepts.find((a) => a.type === "*")?.q;
|
|
33
|
+
let best;
|
|
34
|
+
for (const enc of candidates) {
|
|
35
|
+
const explicit = accepts.find((a) => a.type.toLowerCase() === enc);
|
|
36
|
+
const q = explicit ? explicit.q : wildcardQ ?? 0;
|
|
37
|
+
if (q === 1) {
|
|
38
|
+
return enc;
|
|
39
|
+
} else if (q > 0 && (!best || q > best.q)) {
|
|
40
|
+
best = { encoding: enc, q };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return best?.encoding;
|
|
44
|
+
};
|
|
26
45
|
const compress = (options) => {
|
|
27
46
|
const threshold = options?.threshold ?? 1024;
|
|
47
|
+
const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
|
|
28
48
|
return async function compress2(ctx, next) {
|
|
29
49
|
await next();
|
|
30
50
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
@@ -37,7 +57,7 @@ const compress = (options) => {
|
|
|
37
57
|
return;
|
|
38
58
|
}
|
|
39
59
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
40
|
-
const encoding =
|
|
60
|
+
const encoding = selectEncoding(accepted, candidates);
|
|
41
61
|
if (!encoding || !ctx.res.body) {
|
|
42
62
|
return;
|
|
43
63
|
}
|
|
@@ -20,7 +20,7 @@ __export(compress_exports, {
|
|
|
20
20
|
COMPRESSIBLE_CONTENT_TYPE_REGEX: () => COMPRESSIBLE_CONTENT_TYPE_REGEX
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(compress_exports);
|
|
23
|
-
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
23
|
+
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i;
|
|
24
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
25
|
0 && (module.exports = {
|
|
26
26
|
COMPRESSIBLE_CONTENT_TYPE_REGEX
|
|
@@ -28,15 +28,13 @@ const getMimeType = (filename, mimes = baseMimes) => {
|
|
|
28
28
|
if (!match) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
if (mimeType && mimeType.startsWith("text")) {
|
|
33
|
-
mimeType += "; charset=utf-8";
|
|
34
|
-
}
|
|
35
|
-
return mimeType;
|
|
31
|
+
return mimes[match[1].toLowerCase()];
|
|
36
32
|
};
|
|
37
33
|
const getExtension = (mimeType) => {
|
|
34
|
+
const baseType = mimeType.split(";", 1)[0].trim();
|
|
38
35
|
for (const ext in baseMimes) {
|
|
39
|
-
|
|
36
|
+
const stored = baseMimes[ext];
|
|
37
|
+
if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) {
|
|
40
38
|
return ext;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -48,25 +46,25 @@ const _baseMimes = {
|
|
|
48
46
|
av1: "video/av1",
|
|
49
47
|
bin: "application/octet-stream",
|
|
50
48
|
bmp: "image/bmp",
|
|
51
|
-
css: "text/css",
|
|
52
|
-
csv: "text/csv",
|
|
49
|
+
css: "text/css; charset=utf-8",
|
|
50
|
+
csv: "text/csv; charset=utf-8",
|
|
53
51
|
eot: "application/vnd.ms-fontobject",
|
|
54
52
|
epub: "application/epub+zip",
|
|
55
53
|
gif: "image/gif",
|
|
56
54
|
gz: "application/gzip",
|
|
57
|
-
htm: "text/html",
|
|
58
|
-
html: "text/html",
|
|
55
|
+
htm: "text/html; charset=utf-8",
|
|
56
|
+
html: "text/html; charset=utf-8",
|
|
59
57
|
ico: "image/x-icon",
|
|
60
|
-
ics: "text/calendar",
|
|
58
|
+
ics: "text/calendar; charset=utf-8",
|
|
61
59
|
jpeg: "image/jpeg",
|
|
62
60
|
jpg: "image/jpeg",
|
|
63
|
-
js: "text/javascript",
|
|
61
|
+
js: "text/javascript; charset=utf-8",
|
|
64
62
|
json: "application/json",
|
|
65
63
|
jsonld: "application/ld+json",
|
|
66
64
|
map: "application/json",
|
|
67
65
|
mid: "audio/x-midi",
|
|
68
66
|
midi: "audio/x-midi",
|
|
69
|
-
mjs: "text/javascript",
|
|
67
|
+
mjs: "text/javascript; charset=utf-8",
|
|
70
68
|
mp3: "audio/mpeg",
|
|
71
69
|
mp4: "video/mp4",
|
|
72
70
|
mpeg: "video/mpeg",
|
|
@@ -78,12 +76,12 @@ const _baseMimes = {
|
|
|
78
76
|
pdf: "application/pdf",
|
|
79
77
|
png: "image/png",
|
|
80
78
|
rtf: "application/rtf",
|
|
81
|
-
svg: "image/svg+xml",
|
|
79
|
+
svg: "image/svg+xml; charset=utf-8",
|
|
82
80
|
tif: "image/tiff",
|
|
83
81
|
tiff: "image/tiff",
|
|
84
82
|
ts: "video/mp2t",
|
|
85
83
|
ttf: "font/ttf",
|
|
86
|
-
txt: "text/plain",
|
|
84
|
+
txt: "text/plain; charset=utf-8",
|
|
87
85
|
wasm: "application/wasm",
|
|
88
86
|
webm: "video/webm",
|
|
89
87
|
weba: "audio/webm",
|
|
@@ -91,8 +89,8 @@ const _baseMimes = {
|
|
|
91
89
|
webp: "image/webp",
|
|
92
90
|
woff: "font/woff",
|
|
93
91
|
woff2: "font/woff2",
|
|
94
|
-
xhtml: "application/xhtml+xml",
|
|
95
|
-
xml: "application/xml",
|
|
92
|
+
xhtml: "application/xhtml+xml; charset=utf-8",
|
|
93
|
+
xml: "application/xml; charset=utf-8",
|
|
96
94
|
zip: "application/zip",
|
|
97
95
|
"3gp": "video/3gpp",
|
|
98
96
|
"3g2": "video/3gpp2",
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
// src/middleware/compress/index.ts
|
|
2
|
+
import { parseAccept } from "../../utils/accept.js";
|
|
2
3
|
import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js";
|
|
3
4
|
var ENCODING_TYPES = ["gzip", "deflate"];
|
|
4
5
|
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i;
|
|
6
|
+
var selectEncoding = (header, candidates) => {
|
|
7
|
+
if (header === void 0) {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
const accepts = parseAccept(header);
|
|
11
|
+
const wildcardQ = accepts.find((a) => a.type === "*")?.q;
|
|
12
|
+
let best;
|
|
13
|
+
for (const enc of candidates) {
|
|
14
|
+
const explicit = accepts.find((a) => a.type.toLowerCase() === enc);
|
|
15
|
+
const q = explicit ? explicit.q : wildcardQ ?? 0;
|
|
16
|
+
if (q === 1) {
|
|
17
|
+
return enc;
|
|
18
|
+
} else if (q > 0 && (!best || q > best.q)) {
|
|
19
|
+
best = { encoding: enc, q };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return best?.encoding;
|
|
23
|
+
};
|
|
5
24
|
var compress = (options) => {
|
|
6
25
|
const threshold = options?.threshold ?? 1024;
|
|
26
|
+
const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
|
|
7
27
|
return async function compress2(ctx, next) {
|
|
8
28
|
await next();
|
|
9
29
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
@@ -16,7 +36,7 @@ var compress = (options) => {
|
|
|
16
36
|
return;
|
|
17
37
|
}
|
|
18
38
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
19
|
-
const encoding =
|
|
39
|
+
const encoding = selectEncoding(accepted, candidates);
|
|
20
40
|
if (!encoding || !ctx.res.body) {
|
|
21
41
|
return;
|
|
22
42
|
}
|