@web-ts-toolkit/express-response-handler 0.30.0 → 0.31.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/README.md +12 -0
- package/create-handler.js +312 -39
- package/create-handler.mjs +322 -24
- package/error-format.js +14 -12
- package/error-format.mjs +13 -12
- package/error-formats.js +3 -1
- package/error-formats.mjs +2 -1
- package/http-response.js +117 -15
- package/http-response.mjs +102 -14
- package/index.js +603 -23
- package/index.mjs +609 -20
- package/package.json +3 -3
- package/public-types.js +10 -2
- package/public-types.mjs +6 -1
- package/responses/csv.d.mts +4 -1
- package/responses/csv.d.ts +4 -1
- package/responses/csv.js +24 -4
- package/responses/csv.mjs +20 -3
- package/responses/index.d.mts +4 -1
- package/responses/index.d.ts +4 -1
- package/responses/index.js +24 -4
- package/responses/index.mjs +20 -3
- package/responses/success.js +36 -21
- package/responses/success.mjs +33 -21
package/responses/csv.d.ts
CHANGED
|
@@ -9,7 +9,10 @@ type CsvStreamResponse = {
|
|
|
9
9
|
destroy?(error?: Error): void;
|
|
10
10
|
end(): void;
|
|
11
11
|
};
|
|
12
|
+
declare const csvResponseBrand: unique symbol;
|
|
13
|
+
declare const isCSVResponse: (value: unknown) => value is CSVResponse;
|
|
12
14
|
declare class CSVResponse {
|
|
15
|
+
readonly [csvResponseBrand] = true;
|
|
13
16
|
readonly dataset: unknown[];
|
|
14
17
|
readonly filename: string;
|
|
15
18
|
readonly processor: CsvProcessor;
|
|
@@ -18,4 +21,4 @@ declare class CSVResponse {
|
|
|
18
21
|
streamCsv(res: CsvStreamResponse): void;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
export { CSVResponse };
|
|
24
|
+
export { CSVResponse, csvResponseBrand, isCSVResponse };
|
package/responses/csv.js
CHANGED
|
@@ -16,15 +16,33 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/responses/csv.ts
|
|
19
21
|
var csv_exports = {};
|
|
20
22
|
__export(csv_exports, {
|
|
21
|
-
CSVResponse: () => CSVResponse
|
|
23
|
+
CSVResponse: () => CSVResponse,
|
|
24
|
+
csvResponseBrand: () => csvResponseBrand,
|
|
25
|
+
isCSVResponse: () => isCSVResponse
|
|
22
26
|
});
|
|
23
27
|
module.exports = __toCommonJS(csv_exports);
|
|
24
28
|
var import_format = require("@fast-csv/format");
|
|
25
29
|
var import_utils = require("@web-ts-toolkit/utils");
|
|
26
|
-
|
|
30
|
+
var csvResponseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.csv-response");
|
|
31
|
+
var isCSVResponse = (value) => {
|
|
32
|
+
if (value instanceof CSVResponse) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value !== "object" || value === null) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const candidate = value;
|
|
39
|
+
return candidate[csvResponseBrand] === true && typeof candidate.streamCsv === "function";
|
|
40
|
+
};
|
|
41
|
+
var _a;
|
|
42
|
+
_a = csvResponseBrand;
|
|
43
|
+
var CSVResponse = class {
|
|
27
44
|
constructor(dataset = [], options = {}) {
|
|
45
|
+
this[_a] = true;
|
|
28
46
|
this.dataset = (0, import_utils.castArray)(dataset);
|
|
29
47
|
this.filename = options.filename || "download.csv";
|
|
30
48
|
this.processor = options.processor || ((value) => value);
|
|
@@ -50,8 +68,10 @@ class CSVResponse {
|
|
|
50
68
|
this.dataset.forEach((value) => stream.write(this.processor(value)));
|
|
51
69
|
stream.end();
|
|
52
70
|
}
|
|
53
|
-
}
|
|
71
|
+
};
|
|
54
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
73
|
0 && (module.exports = {
|
|
56
|
-
CSVResponse
|
|
74
|
+
CSVResponse,
|
|
75
|
+
csvResponseBrand,
|
|
76
|
+
isCSVResponse
|
|
57
77
|
});
|
package/responses/csv.mjs
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
// src/responses/csv.ts
|
|
1
2
|
import { format } from "@fast-csv/format";
|
|
2
3
|
import { castArray, isBoolean, isPlainObject } from "@web-ts-toolkit/utils";
|
|
3
|
-
|
|
4
|
+
var csvResponseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.csv-response");
|
|
5
|
+
var isCSVResponse = (value) => {
|
|
6
|
+
if (value instanceof CSVResponse) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value !== "object" || value === null) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const candidate = value;
|
|
13
|
+
return candidate[csvResponseBrand] === true && typeof candidate.streamCsv === "function";
|
|
14
|
+
};
|
|
15
|
+
var _a;
|
|
16
|
+
_a = csvResponseBrand;
|
|
17
|
+
var CSVResponse = class {
|
|
4
18
|
constructor(dataset = [], options = {}) {
|
|
19
|
+
this[_a] = true;
|
|
5
20
|
this.dataset = castArray(dataset);
|
|
6
21
|
this.filename = options.filename || "download.csv";
|
|
7
22
|
this.processor = options.processor || ((value) => value);
|
|
@@ -27,7 +42,9 @@ class CSVResponse {
|
|
|
27
42
|
this.dataset.forEach((value) => stream.write(this.processor(value)));
|
|
28
43
|
stream.end();
|
|
29
44
|
}
|
|
30
|
-
}
|
|
45
|
+
};
|
|
31
46
|
export {
|
|
32
|
-
CSVResponse
|
|
47
|
+
CSVResponse,
|
|
48
|
+
csvResponseBrand,
|
|
49
|
+
isCSVResponse
|
|
33
50
|
};
|
package/responses/index.d.mts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
declare const responseBrand: unique symbol;
|
|
2
|
+
declare const isResponse: (value: unknown) => value is Response<unknown>;
|
|
1
3
|
declare class Response<T = unknown> {
|
|
4
|
+
readonly [responseBrand] = true;
|
|
2
5
|
readonly statusCode: number;
|
|
3
6
|
readonly data: T;
|
|
4
7
|
constructor(statusCode: number | undefined, data: T);
|
|
5
8
|
}
|
|
6
9
|
|
|
7
|
-
export { Response };
|
|
10
|
+
export { Response, isResponse, responseBrand };
|
package/responses/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
declare const responseBrand: unique symbol;
|
|
2
|
+
declare const isResponse: (value: unknown) => value is Response<unknown>;
|
|
1
3
|
declare class Response<T = unknown> {
|
|
4
|
+
readonly [responseBrand] = true;
|
|
2
5
|
readonly statusCode: number;
|
|
3
6
|
readonly data: T;
|
|
4
7
|
constructor(statusCode: number | undefined, data: T);
|
|
5
8
|
}
|
|
6
9
|
|
|
7
|
-
export { Response };
|
|
10
|
+
export { Response, isResponse, responseBrand };
|
package/responses/index.js
CHANGED
|
@@ -16,18 +16,38 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/responses/index.ts
|
|
19
21
|
var responses_exports = {};
|
|
20
22
|
__export(responses_exports, {
|
|
21
|
-
Response: () => Response
|
|
23
|
+
Response: () => Response,
|
|
24
|
+
isResponse: () => isResponse,
|
|
25
|
+
responseBrand: () => responseBrand
|
|
22
26
|
});
|
|
23
27
|
module.exports = __toCommonJS(responses_exports);
|
|
24
|
-
|
|
28
|
+
var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
|
|
29
|
+
var isResponse = (value) => {
|
|
30
|
+
if (value instanceof Response) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value !== "object" || value === null) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const candidate = value;
|
|
37
|
+
return candidate[responseBrand] === true && typeof candidate.statusCode === "number" && "data" in candidate;
|
|
38
|
+
};
|
|
39
|
+
var _a;
|
|
40
|
+
_a = responseBrand;
|
|
41
|
+
var Response = class {
|
|
25
42
|
constructor(statusCode = 200, data) {
|
|
43
|
+
this[_a] = true;
|
|
26
44
|
this.statusCode = statusCode;
|
|
27
45
|
this.data = data;
|
|
28
46
|
}
|
|
29
|
-
}
|
|
47
|
+
};
|
|
30
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
49
|
0 && (module.exports = {
|
|
32
|
-
Response
|
|
50
|
+
Response,
|
|
51
|
+
isResponse,
|
|
52
|
+
responseBrand
|
|
33
53
|
});
|
package/responses/index.mjs
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
// src/responses/index.ts
|
|
2
|
+
var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
|
|
3
|
+
var isResponse = (value) => {
|
|
4
|
+
if (value instanceof Response) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (typeof value !== "object" || value === null) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const candidate = value;
|
|
11
|
+
return candidate[responseBrand] === true && typeof candidate.statusCode === "number" && "data" in candidate;
|
|
12
|
+
};
|
|
13
|
+
var _a;
|
|
14
|
+
_a = responseBrand;
|
|
15
|
+
var Response = class {
|
|
2
16
|
constructor(statusCode = 200, data) {
|
|
17
|
+
this[_a] = true;
|
|
3
18
|
this.statusCode = statusCode;
|
|
4
19
|
this.data = data;
|
|
5
20
|
}
|
|
6
|
-
}
|
|
21
|
+
};
|
|
7
22
|
export {
|
|
8
|
-
Response
|
|
23
|
+
Response,
|
|
24
|
+
isResponse,
|
|
25
|
+
responseBrand
|
|
9
26
|
};
|
package/responses/success.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/responses/success.ts
|
|
19
21
|
var success_exports = {};
|
|
20
22
|
__export(success_exports, {
|
|
21
23
|
Accepted: () => Accepted,
|
|
@@ -30,57 +32,70 @@ __export(success_exports, {
|
|
|
30
32
|
ResetContent: () => ResetContent
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(success_exports);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
|
|
36
|
+
// src/responses/index.ts
|
|
37
|
+
var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
|
|
38
|
+
var _a;
|
|
39
|
+
_a = responseBrand;
|
|
40
|
+
var Response = class {
|
|
41
|
+
constructor(statusCode = 200, data) {
|
|
42
|
+
this[_a] = true;
|
|
43
|
+
this.statusCode = statusCode;
|
|
44
|
+
this.data = data;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/responses/success.ts
|
|
49
|
+
var OK = class extends Response {
|
|
35
50
|
constructor(data) {
|
|
36
51
|
super(200, data);
|
|
37
52
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
53
|
+
};
|
|
54
|
+
var Created = class extends Response {
|
|
40
55
|
constructor(data) {
|
|
41
56
|
super(201, data);
|
|
42
57
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
58
|
+
};
|
|
59
|
+
var Accepted = class extends Response {
|
|
45
60
|
constructor(data) {
|
|
46
61
|
super(202, data);
|
|
47
62
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
63
|
+
};
|
|
64
|
+
var NonAuthoritativeInfo = class extends Response {
|
|
50
65
|
constructor(data) {
|
|
51
66
|
super(203, data);
|
|
52
67
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
68
|
+
};
|
|
69
|
+
var NoContent = class extends Response {
|
|
55
70
|
constructor() {
|
|
56
71
|
super(204, void 0);
|
|
57
72
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
73
|
+
};
|
|
74
|
+
var ResetContent = class extends Response {
|
|
60
75
|
constructor(data) {
|
|
61
76
|
super(205, data);
|
|
62
77
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
78
|
+
};
|
|
79
|
+
var PartialContent = class extends Response {
|
|
65
80
|
constructor(data) {
|
|
66
81
|
super(206, data);
|
|
67
82
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
83
|
+
};
|
|
84
|
+
var MultiStatus = class extends Response {
|
|
70
85
|
constructor(data) {
|
|
71
86
|
super(207, data);
|
|
72
87
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
88
|
+
};
|
|
89
|
+
var AlreadyReported = class extends Response {
|
|
75
90
|
constructor(data) {
|
|
76
91
|
super(208, data);
|
|
77
92
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
93
|
+
};
|
|
94
|
+
var IMUsed = class extends Response {
|
|
80
95
|
constructor(data) {
|
|
81
96
|
super(226, data);
|
|
82
97
|
}
|
|
83
|
-
}
|
|
98
|
+
};
|
|
84
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
85
100
|
0 && (module.exports = {
|
|
86
101
|
Accepted,
|
package/responses/success.mjs
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/responses/index.ts
|
|
2
|
+
var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
|
|
3
|
+
var _a;
|
|
4
|
+
_a = responseBrand;
|
|
5
|
+
var Response = class {
|
|
6
|
+
constructor(statusCode = 200, data) {
|
|
7
|
+
this[_a] = true;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/responses/success.ts
|
|
14
|
+
var OK = class extends Response {
|
|
3
15
|
constructor(data) {
|
|
4
16
|
super(200, data);
|
|
5
17
|
}
|
|
6
|
-
}
|
|
7
|
-
|
|
18
|
+
};
|
|
19
|
+
var Created = class extends Response {
|
|
8
20
|
constructor(data) {
|
|
9
21
|
super(201, data);
|
|
10
22
|
}
|
|
11
|
-
}
|
|
12
|
-
|
|
23
|
+
};
|
|
24
|
+
var Accepted = class extends Response {
|
|
13
25
|
constructor(data) {
|
|
14
26
|
super(202, data);
|
|
15
27
|
}
|
|
16
|
-
}
|
|
17
|
-
|
|
28
|
+
};
|
|
29
|
+
var NonAuthoritativeInfo = class extends Response {
|
|
18
30
|
constructor(data) {
|
|
19
31
|
super(203, data);
|
|
20
32
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
33
|
+
};
|
|
34
|
+
var NoContent = class extends Response {
|
|
23
35
|
constructor() {
|
|
24
36
|
super(204, void 0);
|
|
25
37
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
38
|
+
};
|
|
39
|
+
var ResetContent = class extends Response {
|
|
28
40
|
constructor(data) {
|
|
29
41
|
super(205, data);
|
|
30
42
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
43
|
+
};
|
|
44
|
+
var PartialContent = class extends Response {
|
|
33
45
|
constructor(data) {
|
|
34
46
|
super(206, data);
|
|
35
47
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
48
|
+
};
|
|
49
|
+
var MultiStatus = class extends Response {
|
|
38
50
|
constructor(data) {
|
|
39
51
|
super(207, data);
|
|
40
52
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
53
|
+
};
|
|
54
|
+
var AlreadyReported = class extends Response {
|
|
43
55
|
constructor(data) {
|
|
44
56
|
super(208, data);
|
|
45
57
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
58
|
+
};
|
|
59
|
+
var IMUsed = class extends Response {
|
|
48
60
|
constructor(data) {
|
|
49
61
|
super(226, data);
|
|
50
62
|
}
|
|
51
|
-
}
|
|
63
|
+
};
|
|
52
64
|
export {
|
|
53
65
|
Accepted,
|
|
54
66
|
AlreadyReported,
|