@keq-request/exception 5.0.0-alpha.18 → 5.0.0-alpha.19
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 +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- 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
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;
|
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} 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 406:\n throw new NotAcceptableException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 418:\n throw new ImATeapotException(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 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,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,iBAeO;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,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,KAAK;AACjC,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,iCAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,kCAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,6BAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,uCAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC;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,+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,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
UnauthorizedException,
|
|
34
34
|
ImATeapotException
|
|
35
35
|
} from "keq";
|
|
36
|
-
function
|
|
36
|
+
function validateStatusCode() {
|
|
37
37
|
return async (context, next) => {
|
|
38
38
|
await next();
|
|
39
39
|
const response = context.response;
|
|
@@ -82,6 +82,6 @@ function validateResponse() {
|
|
|
82
82
|
export {
|
|
83
83
|
catchException,
|
|
84
84
|
throwException,
|
|
85
|
-
|
|
85
|
+
validateStatusCode
|
|
86
86
|
};
|
|
87
87
|
//# 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} 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 406:\n throw new NotAcceptableException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 418:\n throw new ImATeapotException(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 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,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,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,KAAK;AACjC,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,sBAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,uBAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,kBAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,6BAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,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,EAQd,MAAM,KAAK,CAAA;AAEZ,wBAAgB,kBAAkB,IAAI,aAAa,CAyDlD"}
|
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.19",
|
|
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.19",
|
|
43
|
+
"keq": "5.0.0-alpha.19"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"keq": "^5.0.0-alpha.
|
|
46
|
+
"keq": "^5.0.0-alpha.19"
|
|
47
47
|
},
|
|
48
48
|
"optionalDependencies": {
|
|
49
|
-
"@keq-request/cli": "5.0.0-alpha.
|
|
49
|
+
"@keq-request/cli": "5.0.0-alpha.19"
|
|
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"}
|