@keq-request/exception 5.0.0-alpha.18 → 5.0.0-alpha.20
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/CHANGELOG.md +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -4
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/plugins/index.js +9 -9
- package/dist/plugins/index.mjs +8 -8
- package/dist/validate-status-code.d.ts +3 -0
- package/dist/validate-status-code.d.ts.map +1 -0
- package/package.json +8 -8
- package/plugins/validate-response.ts +7 -7
- package/dist/validate-response.d.ts +0 -3
- package/dist/validate-response.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.0.0-alpha.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [1f367c0]
|
|
8
|
+
- keq@5.0.0-alpha.20
|
|
9
|
+
|
|
10
|
+
## 5.0.0-alpha.19
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 30b0848: rename validateResponse to validateStatusCode
|
|
15
|
+
- keq@5.0.0-alpha.19
|
|
16
|
+
|
|
3
17
|
## 5.0.0-alpha.18
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
catchException: () => catchException,
|
|
24
24
|
throwException: () => throwException,
|
|
25
|
-
|
|
25
|
+
validateStatusCode: () => validateStatusCode
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
@@ -45,9 +45,9 @@ function catchException(handler) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// src/validate-
|
|
48
|
+
// src/validate-status-code.ts
|
|
49
49
|
var import_keq = require("keq");
|
|
50
|
-
function
|
|
50
|
+
function validateStatusCode() {
|
|
51
51
|
return async (context, next) => {
|
|
52
52
|
await next();
|
|
53
53
|
const response = context.response;
|
|
@@ -65,14 +65,28 @@ function validateResponse() {
|
|
|
65
65
|
throw new import_keq.ForbiddenException(statusText);
|
|
66
66
|
case 404:
|
|
67
67
|
throw new import_keq.NotFoundedException(statusText);
|
|
68
|
+
case 405:
|
|
69
|
+
throw new import_keq.MethodNotAllowedException(statusText);
|
|
68
70
|
case 406:
|
|
69
71
|
throw new import_keq.NotAcceptableException(statusText);
|
|
72
|
+
case 407:
|
|
73
|
+
throw new import_keq.ProxyAuthenticationRequiredException(statusText);
|
|
74
|
+
case 408:
|
|
75
|
+
throw new import_keq.RequestTimeoutException(statusText);
|
|
70
76
|
case 409:
|
|
71
77
|
throw new import_keq.ConflictException(statusText);
|
|
72
78
|
case 412:
|
|
73
79
|
throw new import_keq.PreconditionFailedException(statusText);
|
|
80
|
+
case 413:
|
|
81
|
+
throw new import_keq.ContentTooLargeException(statusText);
|
|
82
|
+
case 414:
|
|
83
|
+
throw new import_keq.UriTooLongException(statusText);
|
|
84
|
+
case 415:
|
|
85
|
+
throw new import_keq.UnsupportedMediaTypeException(statusText);
|
|
74
86
|
case 418:
|
|
75
87
|
throw new import_keq.ImATeapotException(statusText);
|
|
88
|
+
case 429:
|
|
89
|
+
throw new import_keq.TooManyRequestsException(statusText);
|
|
76
90
|
default:
|
|
77
91
|
throw new import_keq.RequestException(status, statusText, false);
|
|
78
92
|
}
|
|
@@ -81,6 +95,8 @@ function validateResponse() {
|
|
|
81
95
|
switch (status) {
|
|
82
96
|
case 500:
|
|
83
97
|
throw new import_keq.InternalServerErrorException(statusText);
|
|
98
|
+
case 501:
|
|
99
|
+
throw new import_keq.NotImplementedException(statusText);
|
|
84
100
|
case 502:
|
|
85
101
|
throw new import_keq.BadGatewayException(statusText);
|
|
86
102
|
case 503:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["export * from './throw-exception.js'\nexport * from './catch-exception.js'\nexport * from './validate-status-code.js'\n","import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async (context, next) => {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText)\n case 401:\n throw new UnauthorizedException(statusText)\n case 403:\n throw new ForbiddenException(statusText)\n case 404:\n throw new NotFoundedException(statusText)\n case 405:\n throw new MethodNotAllowedException(statusText)\n case 406:\n throw new NotAcceptableException(statusText)\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText)\n case 408:\n throw new RequestTimeoutException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 413:\n throw new ContentTooLargeException(statusText)\n case 414:\n throw new UriTooLongException(statusText)\n case 415:\n throw new UnsupportedMediaTypeException(statusText)\n case 418:\n throw new ImATeapotException(statusText)\n case 429:\n throw new TooManyRequestsException(statusText)\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, false)\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText)\n case 501:\n throw new NotImplementedException(statusText)\n case 502:\n throw new BadGatewayException(statusText)\n case 503:\n throw new ServiceUnavailableException(statusText)\n case 504:\n throw new GatewayTimeoutException(statusText)\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, true)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,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mB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,oCAAyB,UAAU;AAAA,QAC/C;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,wCAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,mCAAwB,UAAU;AAAA,QAC9C,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,uCAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,mCAAwB,UAAU;AAAA,QAC9C;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,IAAI;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException"]}
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ function catchException(handler) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// src/validate-
|
|
20
|
+
// src/validate-status-code.ts
|
|
21
21
|
import {
|
|
22
22
|
BadGatewayException,
|
|
23
23
|
BadRequestException,
|
|
@@ -31,9 +31,17 @@ import {
|
|
|
31
31
|
RequestException,
|
|
32
32
|
ServiceUnavailableException,
|
|
33
33
|
UnauthorizedException,
|
|
34
|
-
ImATeapotException
|
|
34
|
+
ImATeapotException,
|
|
35
|
+
MethodNotAllowedException,
|
|
36
|
+
UriTooLongException,
|
|
37
|
+
ContentTooLargeException,
|
|
38
|
+
ProxyAuthenticationRequiredException,
|
|
39
|
+
RequestTimeoutException,
|
|
40
|
+
TooManyRequestsException,
|
|
41
|
+
NotImplementedException,
|
|
42
|
+
UnsupportedMediaTypeException
|
|
35
43
|
} from "keq";
|
|
36
|
-
function
|
|
44
|
+
function validateStatusCode() {
|
|
37
45
|
return async (context, next) => {
|
|
38
46
|
await next();
|
|
39
47
|
const response = context.response;
|
|
@@ -51,14 +59,28 @@ function validateResponse() {
|
|
|
51
59
|
throw new ForbiddenException(statusText);
|
|
52
60
|
case 404:
|
|
53
61
|
throw new NotFoundedException(statusText);
|
|
62
|
+
case 405:
|
|
63
|
+
throw new MethodNotAllowedException(statusText);
|
|
54
64
|
case 406:
|
|
55
65
|
throw new NotAcceptableException(statusText);
|
|
66
|
+
case 407:
|
|
67
|
+
throw new ProxyAuthenticationRequiredException(statusText);
|
|
68
|
+
case 408:
|
|
69
|
+
throw new RequestTimeoutException(statusText);
|
|
56
70
|
case 409:
|
|
57
71
|
throw new ConflictException(statusText);
|
|
58
72
|
case 412:
|
|
59
73
|
throw new PreconditionFailedException(statusText);
|
|
74
|
+
case 413:
|
|
75
|
+
throw new ContentTooLargeException(statusText);
|
|
76
|
+
case 414:
|
|
77
|
+
throw new UriTooLongException(statusText);
|
|
78
|
+
case 415:
|
|
79
|
+
throw new UnsupportedMediaTypeException(statusText);
|
|
60
80
|
case 418:
|
|
61
81
|
throw new ImATeapotException(statusText);
|
|
82
|
+
case 429:
|
|
83
|
+
throw new TooManyRequestsException(statusText);
|
|
62
84
|
default:
|
|
63
85
|
throw new RequestException(status, statusText, false);
|
|
64
86
|
}
|
|
@@ -67,6 +89,8 @@ function validateResponse() {
|
|
|
67
89
|
switch (status) {
|
|
68
90
|
case 500:
|
|
69
91
|
throw new InternalServerErrorException(statusText);
|
|
92
|
+
case 501:
|
|
93
|
+
throw new NotImplementedException(statusText);
|
|
70
94
|
case 502:
|
|
71
95
|
throw new BadGatewayException(statusText);
|
|
72
96
|
case 503:
|
|
@@ -82,6 +106,6 @@ function validateResponse() {
|
|
|
82
106
|
export {
|
|
83
107
|
catchException,
|
|
84
108
|
throwException,
|
|
85
|
-
|
|
109
|
+
validateStatusCode
|
|
86
110
|
};
|
|
87
111
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-
|
|
1
|
+
{"version":3,"sources":["../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async (context, next) => {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText)\n case 401:\n throw new UnauthorizedException(statusText)\n case 403:\n throw new ForbiddenException(statusText)\n case 404:\n throw new NotFoundedException(statusText)\n case 405:\n throw new MethodNotAllowedException(statusText)\n case 406:\n throw new NotAcceptableException(statusText)\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText)\n case 408:\n throw new RequestTimeoutException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 413:\n throw new ContentTooLargeException(statusText)\n case 414:\n throw new UriTooLongException(statusText)\n case 415:\n throw new UnsupportedMediaTypeException(statusText)\n case 418:\n throw new ImATeapotException(statusText)\n case 429:\n throw new TooManyRequestsException(statusText)\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, false)\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText)\n case 501:\n throw new NotImplementedException(statusText)\n case 502:\n throw new BadGatewayException(statusText)\n case 503:\n throw new ServiceUnavailableException(statusText)\n case 504:\n throw new GatewayTimeoutException(statusText)\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, true)\n }\n }\n }\n}\n"],"mappings":";AAMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;ACZA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,qBAAoC;AAClD,SAAO,OAAO,SAAS,SAAS;AAC9B,UAAM,KAAK;AAEX,UAAM,WAAW,QAAQ;AACzB,QAAI,CAAC,SAAU;AAEf,UAAM,EAAE,QAAQ,WAAW,IAAI;AAG/B,QAAI,UAAU,OAAO,S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AM,IAAI,wBAAwB,UAAU;AAAA,QAC9C;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,IAAI;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException"]}
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -3,10 +3,10 @@ import { Plugin, Compiler } from '@keq-request/cli';
|
|
|
3
3
|
interface Options {
|
|
4
4
|
modules?: string[];
|
|
5
5
|
}
|
|
6
|
-
declare class
|
|
6
|
+
declare class ValidateStatusCodePlugin implements Plugin {
|
|
7
7
|
private options;
|
|
8
8
|
constructor(options?: Options);
|
|
9
9
|
apply(compiler: Compiler): void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { ValidateStatusCodePlugin };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { Plugin, Compiler } from '@keq-request/cli';
|
|
|
3
3
|
interface Options {
|
|
4
4
|
modules?: string[];
|
|
5
5
|
}
|
|
6
|
-
declare class
|
|
6
|
+
declare class ValidateStatusCodePlugin implements Plugin {
|
|
7
7
|
private options;
|
|
8
8
|
constructor(options?: Options);
|
|
9
9
|
apply(compiler: Compiler): void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { ValidateStatusCodePlugin };
|
package/dist/plugins/index.js
CHANGED
|
@@ -20,29 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// plugins/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
ValidateStatusCodePlugin: () => ValidateStatusCodePlugin
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
27
|
// plugins/validate-response.ts
|
|
28
28
|
var import_cli = require("@keq-request/cli");
|
|
29
|
-
var
|
|
29
|
+
var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
|
|
30
30
|
constructor(options = {}) {
|
|
31
31
|
this.options = options;
|
|
32
32
|
}
|
|
33
33
|
apply(compiler) {
|
|
34
34
|
if (this.options.modules && this.options.modules.length === 0) return;
|
|
35
|
-
compiler.hooks.afterShaking.tap(
|
|
35
|
+
compiler.hooks.afterShaking.tap(_ValidateStatusCodePlugin.name, () => {
|
|
36
36
|
if (!compiler.context.shaken) return;
|
|
37
37
|
const documents = compiler.context.shaken.documents;
|
|
38
38
|
compiler.context.shaken.documents = documents.map((document) => {
|
|
39
39
|
if (this.options.modules && !this.options.modules.includes(document.module.name)) {
|
|
40
40
|
return document;
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
42
|
+
const spec = document.specification;
|
|
43
|
+
if (!spec.paths || typeof spec.paths !== "object" || spec.paths === null) return document;
|
|
44
44
|
const paths = Object.fromEntries(
|
|
45
|
-
Object.entries(
|
|
45
|
+
Object.entries(spec.paths).map(([path, pathItem]) => {
|
|
46
46
|
if (!pathItem || typeof pathItem !== "object" || pathItem === null) return [path, pathItem];
|
|
47
47
|
return [
|
|
48
48
|
path,
|
|
@@ -65,10 +65,10 @@ var ValidateResponsePlugin = class _ValidateResponsePlugin {
|
|
|
65
65
|
];
|
|
66
66
|
})
|
|
67
67
|
);
|
|
68
|
-
return new import_cli.ApiDocumentV3_1({ ...
|
|
68
|
+
return new import_cli.ApiDocumentV3_1({ ...spec, paths }, document.module);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
-
compiler.hooks.afterCompileKeqRequest.tap(
|
|
71
|
+
compiler.hooks.afterCompileKeqRequest.tap(_ValidateStatusCodePlugin.name, (artifact) => {
|
|
72
72
|
artifact.addDependence("@keq-request/exception", ["validateResponse"]);
|
|
73
73
|
if (!this.options.modules) {
|
|
74
74
|
artifact.anchor.prepend("file:end", "request.use(validateResponse())\n");
|
|
@@ -89,5 +89,5 @@ var ValidateResponsePlugin = class _ValidateResponsePlugin {
|
|
|
89
89
|
};
|
|
90
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
91
|
0 && (module.exports = {
|
|
92
|
-
|
|
92
|
+
ValidateStatusCodePlugin
|
|
93
93
|
});
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
// plugins/validate-response.ts
|
|
2
2
|
import { ApiDocumentV3_1 } from "@keq-request/cli";
|
|
3
|
-
var
|
|
3
|
+
var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
|
|
4
4
|
constructor(options = {}) {
|
|
5
5
|
this.options = options;
|
|
6
6
|
}
|
|
7
7
|
apply(compiler) {
|
|
8
8
|
if (this.options.modules && this.options.modules.length === 0) return;
|
|
9
|
-
compiler.hooks.afterShaking.tap(
|
|
9
|
+
compiler.hooks.afterShaking.tap(_ValidateStatusCodePlugin.name, () => {
|
|
10
10
|
if (!compiler.context.shaken) return;
|
|
11
11
|
const documents = compiler.context.shaken.documents;
|
|
12
12
|
compiler.context.shaken.documents = documents.map((document) => {
|
|
13
13
|
if (this.options.modules && !this.options.modules.includes(document.module.name)) {
|
|
14
14
|
return document;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
16
|
+
const spec = document.specification;
|
|
17
|
+
if (!spec.paths || typeof spec.paths !== "object" || spec.paths === null) return document;
|
|
18
18
|
const paths = Object.fromEntries(
|
|
19
|
-
Object.entries(
|
|
19
|
+
Object.entries(spec.paths).map(([path, pathItem]) => {
|
|
20
20
|
if (!pathItem || typeof pathItem !== "object" || pathItem === null) return [path, pathItem];
|
|
21
21
|
return [
|
|
22
22
|
path,
|
|
@@ -39,10 +39,10 @@ var ValidateResponsePlugin = class _ValidateResponsePlugin {
|
|
|
39
39
|
];
|
|
40
40
|
})
|
|
41
41
|
);
|
|
42
|
-
return new ApiDocumentV3_1({ ...
|
|
42
|
+
return new ApiDocumentV3_1({ ...spec, paths }, document.module);
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
|
-
compiler.hooks.afterCompileKeqRequest.tap(
|
|
45
|
+
compiler.hooks.afterCompileKeqRequest.tap(_ValidateStatusCodePlugin.name, (artifact) => {
|
|
46
46
|
artifact.addDependence("@keq-request/exception", ["validateResponse"]);
|
|
47
47
|
if (!this.options.modules) {
|
|
48
48
|
artifact.anchor.prepend("file:end", "request.use(validateResponse())\n");
|
|
@@ -62,5 +62,5 @@ var ValidateResponsePlugin = class _ValidateResponsePlugin {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
export {
|
|
65
|
-
|
|
65
|
+
ValidateStatusCodePlugin
|
|
66
66
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-status-code.d.ts","sourceRoot":"","sources":["../src/validate-status-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,aAAa,EAgBd,MAAM,KAAK,CAAA;AAEZ,wBAAgB,kBAAkB,IAAI,aAAa,CAyElD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keq-request/exception",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.20",
|
|
4
4
|
"description": "Request exception for keq",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keq",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"type-fest": "^5.
|
|
37
|
+
"type-fest": "^5.3.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@scalar/openapi-types": "^0.5.
|
|
41
|
-
"@types/node": "^20.19.
|
|
42
|
-
"@keq-request/cli": "5.0.0-alpha.
|
|
43
|
-
"keq": "5.0.0-alpha.
|
|
40
|
+
"@scalar/openapi-types": "^0.5.2",
|
|
41
|
+
"@types/node": "^20.19.25",
|
|
42
|
+
"@keq-request/cli": "5.0.0-alpha.20",
|
|
43
|
+
"keq": "5.0.0-alpha.20"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"keq": "^5.0.0-alpha.
|
|
46
|
+
"keq": "^5.0.0-alpha.20"
|
|
47
47
|
},
|
|
48
48
|
"optionalDependencies": {
|
|
49
|
-
"@keq-request/cli": "5.0.0-alpha.
|
|
49
|
+
"@keq-request/cli": "5.0.0-alpha.20"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup",
|
|
@@ -6,14 +6,14 @@ interface Options {
|
|
|
6
6
|
modules?: string[]
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export class
|
|
9
|
+
export class ValidateStatusCodePlugin implements Plugin {
|
|
10
10
|
constructor(private options: Options = {}) {}
|
|
11
11
|
|
|
12
12
|
apply(compiler: Compiler): void {
|
|
13
13
|
if (this.options.modules && this.options.modules.length === 0) return
|
|
14
14
|
|
|
15
15
|
// remove 4xx and 5xx responses from OpenAPI documents
|
|
16
|
-
compiler.hooks.afterShaking.tap(
|
|
16
|
+
compiler.hooks.afterShaking.tap(ValidateStatusCodePlugin.name, () => {
|
|
17
17
|
if (!compiler.context.shaken) return
|
|
18
18
|
|
|
19
19
|
const documents = compiler.context.shaken.documents
|
|
@@ -23,12 +23,12 @@ export class ValidateResponsePlugin implements Plugin {
|
|
|
23
23
|
return document
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const spec: OpenAPIV3_1.Document = document.specification
|
|
27
27
|
|
|
28
|
-
if (!
|
|
28
|
+
if (!spec.paths || typeof spec.paths !== 'object' || spec.paths === null) return document
|
|
29
29
|
|
|
30
30
|
const paths = Object.fromEntries(
|
|
31
|
-
Object.entries(
|
|
31
|
+
Object.entries(spec.paths)
|
|
32
32
|
.map(([path, pathItem]) => {
|
|
33
33
|
if (!pathItem || typeof pathItem !== 'object' || pathItem === null) return [path, pathItem]
|
|
34
34
|
|
|
@@ -59,12 +59,12 @@ export class ValidateResponsePlugin implements Plugin {
|
|
|
59
59
|
}),
|
|
60
60
|
)
|
|
61
61
|
|
|
62
|
-
return new ApiDocumentV3_1({ ...
|
|
62
|
+
return new ApiDocumentV3_1({ ...spec, paths }, document.module)
|
|
63
63
|
})
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
// inject validateResponse middleware into generated code
|
|
67
|
-
compiler.hooks.afterCompileKeqRequest.tap(
|
|
67
|
+
compiler.hooks.afterCompileKeqRequest.tap(ValidateStatusCodePlugin.name, (artifact: Artifact) => {
|
|
68
68
|
artifact.addDependence('@keq-request/exception', ['validateResponse'])
|
|
69
69
|
|
|
70
70
|
if (!this.options.modules) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-response.d.ts","sourceRoot":"","sources":["../src/validate-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,aAAa,EAQd,MAAM,KAAK,CAAA;AAEZ,wBAAgB,gBAAgB,IAAI,aAAa,CAyDhD"}
|