@midwayjs/core 3.17.0 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/interface.d.ts +4 -4
- package/dist/response/base.d.ts +3 -3
- package/dist/response/base.js +6 -6
- package/dist/response/http.d.ts +8 -5
- package/dist/response/http.js +26 -7
- package/dist/response/sse.d.ts +3 -3
- package/dist/response/sse.js +1 -1
- package/dist/response/stream.d.ts +3 -3
- package/dist/response/stream.js +1 -1
- package/package.json +2 -2
package/dist/interface.d.ts
CHANGED
|
@@ -1004,12 +1004,12 @@ export interface ServerSendEventMessage {
|
|
|
1004
1004
|
id?: string;
|
|
1005
1005
|
retry?: number;
|
|
1006
1006
|
}
|
|
1007
|
-
export interface ServerStreamOptions {
|
|
1008
|
-
tpl?: (data: unknown) => unknown;
|
|
1007
|
+
export interface ServerStreamOptions<CTX extends IMidwayContext> {
|
|
1008
|
+
tpl?: (data: unknown, ctx: CTX) => unknown;
|
|
1009
1009
|
}
|
|
1010
|
-
export interface ServerSendEventStreamOptions {
|
|
1010
|
+
export interface ServerSendEventStreamOptions<CTX extends IMidwayContext> {
|
|
1011
1011
|
closeEvent?: string;
|
|
1012
|
-
tpl?: (data: ServerSendEventMessage) => ServerSendEventMessage;
|
|
1012
|
+
tpl?: (data: ServerSendEventMessage, ctx: CTX) => ServerSendEventMessage;
|
|
1013
1013
|
}
|
|
1014
1014
|
export {};
|
|
1015
1015
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/response/base.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export declare class ServerResponse<CTX extends IMidwayContext = IMidwayContext>
|
|
|
4
4
|
protected readonly ctx: any;
|
|
5
5
|
protected isSuccess: boolean;
|
|
6
6
|
constructor(ctx: CTX);
|
|
7
|
-
static TEXT_TPL: (data: string, isSuccess: boolean) => unknown;
|
|
8
|
-
static JSON_TPL: (data: Record<any, any>, isSuccess: boolean) => unknown;
|
|
9
|
-
static BLOB_TPL: (data: Buffer, isSuccess: boolean) => unknown;
|
|
7
|
+
static TEXT_TPL: <CTX_1 extends import("../interface").Context>(data: string, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
8
|
+
static JSON_TPL: <CTX_1 extends import("../interface").Context>(data: Record<any, any>, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
9
|
+
static BLOB_TPL: <CTX_1 extends import("../interface").Context>(data: Buffer, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
10
10
|
json(data: Record<any, any>): any;
|
|
11
11
|
text(data: string): any;
|
|
12
12
|
blob(data: Buffer): any;
|
package/dist/response/base.js
CHANGED
|
@@ -7,13 +7,13 @@ class ServerResponse {
|
|
|
7
7
|
this.ctx = ctx;
|
|
8
8
|
}
|
|
9
9
|
json(data) {
|
|
10
|
-
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess);
|
|
10
|
+
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess, this.ctx);
|
|
11
11
|
}
|
|
12
12
|
text(data) {
|
|
13
|
-
return Object.getPrototypeOf(this).constructor.TEXT_TPL(data, this.isSuccess);
|
|
13
|
+
return Object.getPrototypeOf(this).constructor.TEXT_TPL(data, this.isSuccess, this.ctx);
|
|
14
14
|
}
|
|
15
15
|
blob(data) {
|
|
16
|
-
return Object.getPrototypeOf(this).constructor.BLOB_TPL(data, this.isSuccess);
|
|
16
|
+
return Object.getPrototypeOf(this).constructor.BLOB_TPL(data, this.isSuccess, this.ctx);
|
|
17
17
|
}
|
|
18
18
|
success() {
|
|
19
19
|
this.isSuccess = true;
|
|
@@ -25,10 +25,10 @@ class ServerResponse {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.ServerResponse = ServerResponse;
|
|
28
|
-
ServerResponse.TEXT_TPL = (data, isSuccess) => {
|
|
28
|
+
ServerResponse.TEXT_TPL = (data, isSuccess, ctx) => {
|
|
29
29
|
return data;
|
|
30
30
|
};
|
|
31
|
-
ServerResponse.JSON_TPL = (data, isSuccess) => {
|
|
31
|
+
ServerResponse.JSON_TPL = (data, isSuccess, ctx) => {
|
|
32
32
|
if (isSuccess) {
|
|
33
33
|
return {
|
|
34
34
|
success: 'true',
|
|
@@ -42,7 +42,7 @@ ServerResponse.JSON_TPL = (data, isSuccess) => {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
ServerResponse.BLOB_TPL = (data, isSuccess) => {
|
|
45
|
+
ServerResponse.BLOB_TPL = (data, isSuccess, ctx) => {
|
|
46
46
|
return data;
|
|
47
47
|
};
|
|
48
48
|
//# sourceMappingURL=base.js.map
|
package/dist/response/http.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ import { Readable } from 'stream';
|
|
|
7
7
|
import { HttpStreamResponse } from './stream';
|
|
8
8
|
export declare class HttpServerResponse<CTX extends IMidwayContext> extends ServerResponse<CTX> {
|
|
9
9
|
constructor(ctx: CTX);
|
|
10
|
-
static FILE_TPL: (data: Readable, isSuccess: boolean) => Readable;
|
|
11
|
-
static SSE_TPL: (data: ServerSendEventMessage) => ServerSendEventMessage;
|
|
12
|
-
static STREAM_TPL: (data: unknown) => unknown;
|
|
10
|
+
static FILE_TPL: <CTX_1 extends import("../interface").Context>(data: Readable, isSuccess: boolean, ctx: CTX_1) => Readable;
|
|
11
|
+
static SSE_TPL: <CTX_1 extends import("../interface").Context>(data: ServerSendEventMessage, ctx: CTX_1) => ServerSendEventMessage;
|
|
12
|
+
static STREAM_TPL: <CTX_1 extends import("../interface").Context>(data: unknown, ctx: CTX_1) => unknown;
|
|
13
|
+
static HTML_TPL: <CTX_1 extends import("../interface").Context>(data: string, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
13
14
|
status(code: number): this;
|
|
14
15
|
header(key: string, value: string): this;
|
|
15
16
|
headers(headers: Record<string, string>): this;
|
|
@@ -17,7 +18,9 @@ export declare class HttpServerResponse<CTX extends IMidwayContext> extends Serv
|
|
|
17
18
|
text(data: string): any;
|
|
18
19
|
file(filePath: string, mimeType?: string): any;
|
|
19
20
|
blob(data: Buffer, mimeType?: string): any;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
html(data: string): any;
|
|
22
|
+
redirect(url: string, status?: number): any;
|
|
23
|
+
sse(options?: ServerSendEventStreamOptions<CTX>): ServerSendEventStream<import("../interface").Context>;
|
|
24
|
+
stream(options?: ServerStreamOptions<CTX>): HttpStreamResponse<import("../interface").Context>;
|
|
22
25
|
}
|
|
23
26
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/response/http.js
CHANGED
|
@@ -31,20 +31,36 @@ class HttpServerResponse extends base_1.ServerResponse {
|
|
|
31
31
|
}
|
|
32
32
|
json(data) {
|
|
33
33
|
this.header('Content-Type', 'application/json');
|
|
34
|
-
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess);
|
|
34
|
+
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess, this.ctx);
|
|
35
35
|
}
|
|
36
36
|
text(data) {
|
|
37
37
|
this.header('Content-Type', 'text/plain');
|
|
38
|
-
return Object.getPrototypeOf(this).constructor.TEXT_TPL(data, this.isSuccess);
|
|
38
|
+
return Object.getPrototypeOf(this).constructor.TEXT_TPL(data, this.isSuccess, this.ctx);
|
|
39
39
|
}
|
|
40
40
|
file(filePath, mimeType) {
|
|
41
41
|
this.header('Content-Type', mimeType || 'application/octet-stream');
|
|
42
42
|
this.header('Content-Disposition', `attachment; filename=${(0, path_1.basename)(filePath)}`);
|
|
43
|
-
return Object.getPrototypeOf(this).constructor.FILE_TPL(typeof filePath === 'string' ? (0, fs_1.createReadStream)(filePath) : filePath, this.isSuccess);
|
|
43
|
+
return Object.getPrototypeOf(this).constructor.FILE_TPL(typeof filePath === 'string' ? (0, fs_1.createReadStream)(filePath) : filePath, this.isSuccess, this.ctx);
|
|
44
44
|
}
|
|
45
45
|
blob(data, mimeType) {
|
|
46
46
|
this.header('Content-Type', mimeType || 'application/octet-stream');
|
|
47
|
-
return Object.getPrototypeOf(this).constructor.BLOB_TPL(data, this.isSuccess);
|
|
47
|
+
return Object.getPrototypeOf(this).constructor.BLOB_TPL(data, this.isSuccess, this.ctx);
|
|
48
|
+
}
|
|
49
|
+
html(data) {
|
|
50
|
+
this.header('Content-Type', 'text/html');
|
|
51
|
+
return Object.getPrototypeOf(this).constructor.HTML_TPL(data, this.isSuccess, this.ctx);
|
|
52
|
+
}
|
|
53
|
+
redirect(url, status = 302) {
|
|
54
|
+
this.status(status);
|
|
55
|
+
if (this.ctx.redirect) {
|
|
56
|
+
return this.ctx.redirect(url);
|
|
57
|
+
}
|
|
58
|
+
else if (this.ctx.res.redirect) {
|
|
59
|
+
return this.ctx.res.redirect(url);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.header('Location', url);
|
|
63
|
+
}
|
|
48
64
|
}
|
|
49
65
|
sse(options = {}) {
|
|
50
66
|
return new sse_1.ServerSendEventStream(this.ctx, {
|
|
@@ -60,13 +76,16 @@ class HttpServerResponse extends base_1.ServerResponse {
|
|
|
60
76
|
}
|
|
61
77
|
}
|
|
62
78
|
exports.HttpServerResponse = HttpServerResponse;
|
|
63
|
-
HttpServerResponse.FILE_TPL = (data, isSuccess) => {
|
|
79
|
+
HttpServerResponse.FILE_TPL = (data, isSuccess, ctx) => {
|
|
80
|
+
return data;
|
|
81
|
+
};
|
|
82
|
+
HttpServerResponse.SSE_TPL = (data, ctx) => {
|
|
64
83
|
return data;
|
|
65
84
|
};
|
|
66
|
-
HttpServerResponse.
|
|
85
|
+
HttpServerResponse.STREAM_TPL = (data, ctx) => {
|
|
67
86
|
return data;
|
|
68
87
|
};
|
|
69
|
-
HttpServerResponse.
|
|
88
|
+
HttpServerResponse.HTML_TPL = (data, isSuccess, ctx) => {
|
|
70
89
|
return data;
|
|
71
90
|
};
|
|
72
91
|
//# sourceMappingURL=http.js.map
|
package/dist/response/sse.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Transform } from 'stream';
|
|
3
|
-
import { ServerSendEventStreamOptions } from '../interface';
|
|
3
|
+
import { IMidwayContext, ServerSendEventStreamOptions } from '../interface';
|
|
4
4
|
interface MessageEvent {
|
|
5
5
|
data?: string | object;
|
|
6
6
|
event?: string;
|
|
7
7
|
id?: string;
|
|
8
8
|
retry?: number;
|
|
9
9
|
}
|
|
10
|
-
export declare class ServerSendEventStream extends Transform {
|
|
10
|
+
export declare class ServerSendEventStream<CTX extends IMidwayContext> extends Transform {
|
|
11
11
|
private readonly ctx;
|
|
12
12
|
private isActive;
|
|
13
13
|
private readonly closeEvent;
|
|
14
14
|
private options;
|
|
15
|
-
constructor(ctx: any, options?: ServerSendEventStreamOptions);
|
|
15
|
+
constructor(ctx: any, options?: ServerSendEventStreamOptions<CTX>);
|
|
16
16
|
_transform(chunk: any, encoding: any, callback: any): void;
|
|
17
17
|
sendError(error: Error): void;
|
|
18
18
|
sendEnd(message?: MessageEvent): void;
|
package/dist/response/sse.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Transform } from 'stream';
|
|
3
|
-
import { ServerStreamOptions } from '../interface';
|
|
4
|
-
export declare class HttpStreamResponse extends Transform {
|
|
3
|
+
import { IMidwayContext, ServerStreamOptions } from '../interface';
|
|
4
|
+
export declare class HttpStreamResponse<CTX extends IMidwayContext> extends Transform {
|
|
5
5
|
private ctx;
|
|
6
6
|
private isActive;
|
|
7
7
|
private options;
|
|
8
|
-
constructor(ctx: any, options?: ServerStreamOptions);
|
|
8
|
+
constructor(ctx: any, options?: ServerStreamOptions<CTX>);
|
|
9
9
|
_transform(chunk: any, encoding: any, callback: any): void;
|
|
10
10
|
send(data: unknown): void;
|
|
11
11
|
sendError(error: any): void;
|
package/dist/response/stream.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.1",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=12"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "824d8474a425b342fcd4480649c83677f846afb9"
|
|
47
47
|
}
|