@cudenix/cudenix 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ecosystem/modules/compress/index.d.ts +1 -2
- package/dist/ecosystem/modules/compress/index.d.ts.map +1 -1
- package/dist/ecosystem/modules/compress/index.js +28 -26
- package/dist/ecosystem/modules/compress/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/ecosystem/modules/compress/compression-stream.d.ts +0 -16
- package/dist/ecosystem/modules/compress/compression-stream.d.ts.map +0 -1
- package/dist/ecosystem/modules/compress/compression-stream.js +0 -18
- package/dist/ecosystem/modules/compress/compression-stream.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export interface CompressOptions {
|
|
2
2
|
threshold?: number;
|
|
3
|
-
level?: Bun.ZlibCompressionOptions["level"];
|
|
4
3
|
}
|
|
5
|
-
export declare const compress: ({ threshold
|
|
4
|
+
export declare const compress: ({ threshold }?: CompressOptions) => import("../../../core/index.js").Module<import("../../../core/index.js").MergeErrors<{}, import("../../../core/index.js").TransformError<never>>, "/", {}, {}, import("../../../core/index.js").MergeSuccesses<{}, import("../../../core/index.js").TransformSuccess<never>>, {
|
|
6
5
|
inputs: NonNullable<unknown>;
|
|
7
6
|
outputs: NonNullable<unknown>;
|
|
8
7
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD,eAAO,MAAM,QAAQ,GACpB,gBAAsB,eAA6B;;;EAqGnD,CAAC"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { constants } from "node:zlib";
|
|
2
1
|
import { module, processResponse, success } from "../../../core/index.js";
|
|
3
|
-
import { CompressionStream } from "../../../ecosystem/modules/compress/compression-stream.js";
|
|
4
2
|
import { Empty } from "../../../utils/index.js";
|
|
5
|
-
const compressibleRegexp = /^\s*(?:text\/
|
|
3
|
+
const compressibleRegexp = /^\s*(?:text\/[^;\s]+|application\/(?:json|javascript|xml|x-www-form-urlencoded)|[^;\s]+\/[^;\s]+\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
6
4
|
const noTransformRegexp = /\bno-transform\b/i;
|
|
7
|
-
export const compress = ({ threshold = 1024
|
|
8
|
-
const encodings =
|
|
5
|
+
export const compress = ({ threshold = 1024 } = new Empty()) => {
|
|
6
|
+
const encodings = {
|
|
7
|
+
br: "brotli",
|
|
8
|
+
deflate: "deflate",
|
|
9
|
+
gzip: "gzip",
|
|
10
|
+
zstd: "zstd",
|
|
11
|
+
};
|
|
9
12
|
return module().middleware(async ({ request: { raw }, response }, next) => {
|
|
10
13
|
await next();
|
|
11
14
|
const contentLength = response.headers.get("Content-Length");
|
|
@@ -19,20 +22,26 @@ export const compress = ({ threshold = 1024, level } = new Empty()) => {
|
|
|
19
22
|
(contentLength && Number(contentLength) < threshold)) {
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
|
-
const accepted =
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
+
const accepted = [
|
|
26
|
+
...new Set(raw.headers
|
|
27
|
+
.get("Accept-Encoding")
|
|
28
|
+
?.split(",")
|
|
29
|
+
.map((encoding) => {
|
|
30
|
+
return encoding.trim().toLowerCase().split(";")[0];
|
|
31
|
+
})
|
|
32
|
+
.filter((encoding) => {
|
|
33
|
+
return !!encoding;
|
|
34
|
+
})),
|
|
35
|
+
];
|
|
36
|
+
if (accepted.length === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const encoding = accepted
|
|
25
40
|
.map((encoding) => {
|
|
26
|
-
return encoding
|
|
41
|
+
return encodings[encoding];
|
|
27
42
|
})
|
|
28
|
-
.
|
|
43
|
+
.find((encoding) => {
|
|
29
44
|
return !!encoding;
|
|
30
|
-
}));
|
|
31
|
-
if (accepted.size === 0) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const encoding = encodings.find((encoding) => {
|
|
35
|
-
return accepted.has(encoding);
|
|
36
45
|
});
|
|
37
46
|
if (!encoding) {
|
|
38
47
|
return;
|
|
@@ -56,16 +65,9 @@ export const compress = ({ threshold = 1024, level } = new Empty()) => {
|
|
|
56
65
|
processedResponse.headers.append("Vary", "Accept-Encoding");
|
|
57
66
|
processedResponse.headers.delete("Content-Length");
|
|
58
67
|
processedResponse.headers.set("Content-Encoding", encoding);
|
|
59
|
-
response.content = success(new Response(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
[constants.BROTLI_PARAM_QUALITY]: level ?? 6,
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
: {
|
|
66
|
-
flush: constants.Z_SYNC_FLUSH,
|
|
67
|
-
level,
|
|
68
|
-
})), processedResponse), {
|
|
68
|
+
response.content = success(new Response(
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
stream.pipeThrough(new CompressionStream(encoding)), processedResponse), {
|
|
69
71
|
status: processedResponse.status,
|
|
70
72
|
transform: false,
|
|
71
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,MAAM,kBAAkB,GACvB,uIAAuI,CAAC;AACzI,MAAM,iBAAiB,GAAG,mBAAmB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AE,iBAAiB,CAAC,CAAC;QAE5D,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAEnD,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAE5D,QAAQ,CAAC,OAAO,GAAG,OAAO,CACzB,IAAI,QAAQ;QACX,mBAAmB;QACnB,MAAM,CAAC,WAAW,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC,EACnD,iBAAiB,CACjB,EACD;YACC,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,SAAS,EAAE,KAAK;SAChB,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
},
|
|
7
7
|
"description": "cudenix",
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@biomejs/biome": "2.
|
|
10
|
-
"@types/bun": "1.3.
|
|
9
|
+
"@biomejs/biome": "2.3.7",
|
|
10
|
+
"@types/bun": "1.3.3",
|
|
11
11
|
"tsc-alias": "1.8.16",
|
|
12
12
|
"typescript": "5.9.3"
|
|
13
13
|
},
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"sideEffects": false,
|
|
90
90
|
"type": "module",
|
|
91
91
|
"types": "dist/index.d.ts",
|
|
92
|
-
"version": "0.0.
|
|
92
|
+
"version": "0.0.49"
|
|
93
93
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type BrotliOptions, createBrotliCompress, createDeflate, createGzip, createZstdCompress, type ZlibOptions } from "node:zlib";
|
|
2
|
-
declare const transformMap: {
|
|
3
|
-
readonly br: typeof createBrotliCompress;
|
|
4
|
-
readonly deflate: typeof createDeflate;
|
|
5
|
-
readonly gzip: typeof createGzip;
|
|
6
|
-
readonly zstd: typeof createZstdCompress;
|
|
7
|
-
};
|
|
8
|
-
export declare class CompressionStream {
|
|
9
|
-
readable: ReadableStream;
|
|
10
|
-
writable: WritableStream;
|
|
11
|
-
constructor(method: keyof typeof transformMap, options?: BrotliOptions & ZlibOptions & {
|
|
12
|
-
dictionary?: Buffer;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=compression-stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compression-stream.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/compression-stream.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,aAAa,EAClB,oBAAoB,EACpB,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,KAAK,WAAW,EAChB,MAAM,WAAW,CAAC;AAEnB,QAAA,MAAM,YAAY;;;;;CAKR,CAAC;AAEX,qBAAa,iBAAiB;IAC7B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,cAAc,CAAC;gBAGxB,MAAM,EAAE,MAAM,OAAO,YAAY,EACjC,OAAO,GAAE,aAAa,GAAG,WAAW,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO;CAOpE"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Duplex } from "node:stream";
|
|
2
|
-
import { createBrotliCompress, createDeflate, createGzip, createZstdCompress, } from "node:zlib";
|
|
3
|
-
const transformMap = {
|
|
4
|
-
br: createBrotliCompress,
|
|
5
|
-
deflate: createDeflate,
|
|
6
|
-
gzip: createGzip,
|
|
7
|
-
zstd: createZstdCompress,
|
|
8
|
-
};
|
|
9
|
-
export class CompressionStream {
|
|
10
|
-
readable;
|
|
11
|
-
writable;
|
|
12
|
-
constructor(method, options = {}) {
|
|
13
|
-
const pair = Duplex.toWeb(transformMap[method](options));
|
|
14
|
-
this.readable = pair.readable;
|
|
15
|
-
this.writable = pair.writable;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=compression-stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compression-stream.js","sourceRoot":"","sources":["../../../../src/ecosystem/modules/compress/compression-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAEN,oBAAoB,EACpB,aAAa,EACb,UAAU,EACV,kBAAkB,GAElB,MAAM,WAAW,CAAC;AAEnB,MAAM,YAAY,GAAG;IACpB,EAAE,EAAE,oBAAoB;IACxB,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,kBAAkB;CACf,CAAC;AAEX,MAAM,OAAO,iBAAiB;IAC7B,QAAQ,CAAiB;IACzB,QAAQ,CAAiB;IAEzB,YACC,MAAiC,EACjC,UAAiE,EAAE;QAEnE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAEzD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAqC,CAAC;QAC3D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC/B,CAAC;CACD"}
|