denwa-nest-shared 1.0.80 → 1.0.81
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 +2 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/openapi-axios/const/defaultOptions.d.ts +2 -0
- package/cjs/openapi-axios/const/defaultOptions.js +12 -0
- package/cjs/openapi-axios/const/defaultOptions.js.map +1 -0
- package/cjs/openapi-axios/const/methods.d.ts +4 -0
- package/cjs/openapi-axios/const/methods.js +9 -0
- package/cjs/openapi-axios/const/methods.js.map +1 -0
- package/cjs/openapi-axios/index.d.ts +27 -0
- package/cjs/openapi-axios/index.js +89 -0
- package/cjs/openapi-axios/index.js.map +1 -0
- package/cjs/openapi-axios/interpolate-params.d.ts +3 -0
- package/cjs/openapi-axios/interpolate-params.js +34 -0
- package/cjs/openapi-axios/interpolate-params.js.map +1 -0
- package/cjs/openapi-axios/types/options.d.ts +18 -0
- package/cjs/openapi-axios/types/options.js +3 -0
- package/cjs/openapi-axios/types/options.js.map +1 -0
- package/cjs/openapi-axios/types/requestParameters.d.ts +6 -0
- package/cjs/openapi-axios/types/requestParameters.js +3 -0
- package/cjs/openapi-axios/types/requestParameters.js.map +1 -0
- package/cjs/openapi-axios/types/response.d.ts +23 -0
- package/cjs/openapi-axios/types/response.js +3 -0
- package/cjs/openapi-axios/types/response.js.map +1 -0
- package/cjs/openapi-axios/types/schemeTypes.d.ts +38 -0
- package/cjs/openapi-axios/types/schemeTypes.js +3 -0
- package/cjs/openapi-axios/types/schemeTypes.js.map +1 -0
- package/cjs/openapi-axios/types/serializer.d.ts +12 -0
- package/cjs/openapi-axios/types/serializer.js +11 -0
- package/cjs/openapi-axios/types/serializer.js.map +1 -0
- package/cjs/openapi-axios/types/utils.d.ts +11 -0
- package/cjs/openapi-axios/types/utils.js +3 -0
- package/cjs/openapi-axios/types/utils.js.map +1 -0
- package/cjs/openapi-axios/utils/querySerializer.d.ts +3 -0
- package/cjs/openapi-axios/utils/querySerializer.js +89 -0
- package/cjs/openapi-axios/utils/querySerializer.js.map +1 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAll.d.ts +5 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAll.js +30 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAll.js.map +1 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAxios.d.ts +5 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAxios.js +11 -0
- package/cjs/openapi-axios/utils/response-converters/convertToAxios.js.map +1 -0
- package/cjs/openapi-axios/utils/response-converters/convertToFetch.d.ts +5 -0
- package/cjs/openapi-axios/utils/response-converters/convertToFetch.js +25 -0
- package/cjs/openapi-axios/utils/response-converters/convertToFetch.js.map +1 -0
- package/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/const.js +6 -9
- package/dist/const.js.map +1 -1
- package/dist/decorators.js +82 -89
- package/dist/decorators.js.map +1 -1
- package/dist/dto.js +328 -344
- package/dist/dto.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -23
- package/dist/index.js.map +1 -1
- package/dist/interceptors/fields-roles.interceptor.js +13 -16
- package/dist/interceptors/fields-roles.interceptor.js.map +1 -1
- package/dist/interceptors/index.js +1 -17
- package/dist/interceptors/index.js.map +1 -1
- package/dist/lib.js +84 -110
- package/dist/lib.js.map +1 -1
- package/dist/openapi-axios/const/defaultOptions.d.ts +2 -0
- package/dist/openapi-axios/const/defaultOptions.js +9 -0
- package/dist/openapi-axios/const/defaultOptions.js.map +1 -0
- package/dist/openapi-axios/const/methods.d.ts +4 -0
- package/dist/openapi-axios/const/methods.js +5 -0
- package/dist/openapi-axios/const/methods.js.map +1 -0
- package/dist/openapi-axios/index.d.ts +27 -0
- package/dist/openapi-axios/index.js +85 -0
- package/dist/openapi-axios/index.js.map +1 -0
- package/dist/openapi-axios/interpolate-params.d.ts +3 -0
- package/dist/openapi-axios/interpolate-params.js +31 -0
- package/dist/openapi-axios/interpolate-params.js.map +1 -0
- package/dist/openapi-axios/types/options.d.ts +18 -0
- package/dist/openapi-axios/types/options.js +2 -0
- package/dist/openapi-axios/types/options.js.map +1 -0
- package/dist/openapi-axios/types/requestParameters.d.ts +6 -0
- package/dist/openapi-axios/types/requestParameters.js +2 -0
- package/dist/openapi-axios/types/requestParameters.js.map +1 -0
- package/dist/openapi-axios/types/response.d.ts +23 -0
- package/dist/openapi-axios/types/response.js +2 -0
- package/dist/openapi-axios/types/response.js.map +1 -0
- package/dist/openapi-axios/types/schemeTypes.d.ts +38 -0
- package/dist/openapi-axios/types/schemeTypes.js +2 -0
- package/dist/openapi-axios/types/schemeTypes.js.map +1 -0
- package/dist/openapi-axios/types/serializer.d.ts +12 -0
- package/dist/openapi-axios/types/serializer.js +8 -0
- package/dist/openapi-axios/types/serializer.js.map +1 -0
- package/dist/openapi-axios/types/utils.d.ts +11 -0
- package/dist/openapi-axios/types/utils.js +2 -0
- package/dist/openapi-axios/types/utils.js.map +1 -0
- package/dist/openapi-axios/utils/querySerializer.d.ts +3 -0
- package/dist/openapi-axios/utils/querySerializer.js +86 -0
- package/dist/openapi-axios/utils/querySerializer.js.map +1 -0
- package/dist/openapi-axios/utils/response-converters/convertToAll.d.ts +5 -0
- package/dist/openapi-axios/utils/response-converters/convertToAll.js +27 -0
- package/dist/openapi-axios/utils/response-converters/convertToAll.js.map +1 -0
- package/dist/openapi-axios/utils/response-converters/convertToAxios.d.ts +5 -0
- package/dist/openapi-axios/utils/response-converters/convertToAxios.js +8 -0
- package/dist/openapi-axios/utils/response-converters/convertToAxios.js.map +1 -0
- package/dist/openapi-axios/utils/response-converters/convertToFetch.d.ts +5 -0
- package/dist/openapi-axios/utils/response-converters/convertToFetch.js +22 -0
- package/dist/openapi-axios/utils/response-converters/convertToFetch.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.js +4 -7
- package/dist/types.js.map +1 -1
- package/dist/validation/index.js +2 -18
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/validation.exception.js +6 -9
- package/dist/validation/validation.exception.js.map +1 -1
- package/dist/validation/validation.pipe.js +11 -14
- package/dist/validation/validation.pipe.js.map +1 -1
- package/package.json +22 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.81](https://github.com/Denwa799/nest-shared/compare/v1.0.80...v1.0.81) (2026-05-30)
|
|
6
|
+
|
|
5
7
|
### [1.0.80](https://github.com/Denwa799/nest-shared/compare/v1.0.79...v1.0.80) (2026-05-05)
|
|
6
8
|
|
|
7
9
|
### [1.0.79](https://github.com/Denwa799/nest-shared/compare/v1.0.78...v1.0.79) (2026-04-26)
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -21,4 +21,5 @@ __exportStar(require("./const"), exports);
|
|
|
21
21
|
__exportStar(require("./validation"), exports);
|
|
22
22
|
__exportStar(require("./decorators"), exports);
|
|
23
23
|
__exportStar(require("./interceptors"), exports);
|
|
24
|
+
__exportStar(require("./openapi-axios"), exports);
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,+CAA6B;AAC7B,iDAA+B","sourcesContent":["export * from './dto';\nexport * from './lib';\nexport * from './types';\nexport * from './const';\nexport * from './validation';\nexport * from './decorators';\nexport * from './interceptors';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC","sourcesContent":["export * from './dto';\nexport * from './lib';\nexport * from './types';\nexport * from './const';\nexport * from './validation';\nexport * from './decorators';\nexport * from './interceptors';\nexport * from './openapi-axios';\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultOptions = void 0;
|
|
4
|
+
const serializer_js_1 = require("../types/serializer.js");
|
|
5
|
+
exports.defaultOptions = {
|
|
6
|
+
validStatus: 'axios',
|
|
7
|
+
querySerializationParams: {
|
|
8
|
+
style: serializer_js_1.QuerySerializerStyle.From,
|
|
9
|
+
explode: true,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=defaultOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultOptions.js","sourceRoot":"","sources":["../../../src/openapi-axios/const/defaultOptions.ts"],"names":[],"mappings":";;;AACA,0DAA8D;AAKjD,QAAA,cAAc,GAAkC;IAC3D,WAAW,EAAE,OAAO;IACpB,wBAAwB,EAAE;QACxB,KAAK,EAAE,oCAAoB,CAAC,IAAI;QAChC,OAAO,EAAE,IAAI;KACd;CACF,CAAC","sourcesContent":["import type { IOpenApiAxiosOptions } from '../types/options.js';\nimport { QuerySerializerStyle } from '../types/serializer.js';\n\n/**\n * @description Default options for OpenAPI requests using Axios.\n */\nexport const defaultOptions: IOpenApiAxiosOptions<'axios'> = {\n validStatus: 'axios',\n querySerializationParams: {\n style: QuerySerializerStyle.From,\n explode: true,\n },\n};\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type MethodType = "get" | "post" | "patch" | "put" | "delete" | "head" | "options";
|
|
2
|
+
export declare const METHODS_WITH_BODY: readonly ["post", "patch", "put"];
|
|
3
|
+
export type MethodTypeWithBody = (typeof METHODS_WITH_BODY)[number];
|
|
4
|
+
export declare function isMethodWithBody(method: string): method is MethodTypeWithBody;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.METHODS_WITH_BODY = void 0;
|
|
4
|
+
exports.isMethodWithBody = isMethodWithBody;
|
|
5
|
+
exports.METHODS_WITH_BODY = ['post', 'patch', 'put'];
|
|
6
|
+
function isMethodWithBody(method) {
|
|
7
|
+
return exports.METHODS_WITH_BODY.includes(method);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../src/openapi-axios/const/methods.ts"],"names":[],"mappings":";;;AAqBA,4CAEC;AAdY,QAAA,iBAAiB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAYnE,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,OAAQ,yBAAuC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACnE,CAAC","sourcesContent":["/**\n * @description Defines all possible HTTP method types as string literals.\n */\n// prettier-ignore\nexport type MethodType = \"get\" | \"post\" | \"patch\" | \"put\" | \"delete\" | \"head\" | \"options\";\n\n/**\n * @description A constant array of HTTP methods that typically include a request body.\n */\nexport const METHODS_WITH_BODY = ['post', 'patch', 'put'] as const;\n\n/**\n * @description Type that represents any HTTP method from the METHODS_WITH_BODY array.\n */\nexport type MethodTypeWithBody = (typeof METHODS_WITH_BODY)[number];\n\n/**\n * @description Function to check if a given method is one that typically includes a request body.\n * @param method - The HTTP method to check.\n * @returns A boolean indicating whether the method is one that includes a request body.\n */\nexport function isMethodWithBody(method: string): method is MethodTypeWithBody {\n return (METHODS_WITH_BODY as never as string[]).includes(method);\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import { type MethodType } from './const/methods.js';
|
|
3
|
+
import type { IOpenApiAxiosOptions, OptionsType, ValidStatusType } from './types/options.js';
|
|
4
|
+
import type { GetApiResponse } from './types/response.js';
|
|
5
|
+
import type { RouteResponsesByStatusCode, RoutesForMethod, SchemaType } from './types/schemeTypes.js';
|
|
6
|
+
import type { IsNullable } from './types/utils.js';
|
|
7
|
+
export declare class OpenApiAxios<Schema extends SchemaType, ClassValidStatus extends ValidStatusType> {
|
|
8
|
+
private axios;
|
|
9
|
+
private opt;
|
|
10
|
+
constructor(axios: AxiosInstance, options: IOpenApiAxiosOptions<ClassValidStatus>);
|
|
11
|
+
get: <Route extends RoutesForMethod<Schema, "get">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "get", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "get", Route, "parameters">, "query">> ? T extends true ? [path: Route, options: OptionsType<Schema, "get", Route, MethodValidStatus>] : [path: Route, options?: OptionsType<Schema, "get", Route, MethodValidStatus> | undefined] : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "get", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "get", Route, "responses">>>>;
|
|
12
|
+
head: <Route extends RoutesForMethod<Schema, "head">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "head", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "head", Route, "parameters">, "query">> ? T extends true ? [path: Route, options: OptionsType<Schema, "head", Route, MethodValidStatus>] : [path: Route, options?: OptionsType<Schema, "head", Route, MethodValidStatus> | undefined] : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "head", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "head", Route, "responses">>>>;
|
|
13
|
+
delete: <Route extends RoutesForMethod<Schema, "delete">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "delete", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "delete", Route, "parameters">, "query">> ? T extends true ? [path: Route, options: OptionsType<Schema, "delete", Route, MethodValidStatus>] : [path: Route, options?: OptionsType<Schema, "delete", Route, MethodValidStatus> | undefined] : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "delete", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "delete", Route, "responses">>>>;
|
|
14
|
+
options: <Route extends RoutesForMethod<Schema, "options">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "options", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "options", Route, "parameters">, "query">> ? T extends true ? [path: Route, options: OptionsType<Schema, "options", Route, MethodValidStatus>] : [path: Route, options?: OptionsType<Schema, "options", Route, MethodValidStatus> | undefined] : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "options", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "options", Route, "responses">>>>;
|
|
15
|
+
put: <Route extends RoutesForMethod<Schema, "put">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> ? T extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route> : undefined, options: OptionsType<Schema, "put", Route, MethodValidStatus>] : (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> extends infer T_1 ? T_1 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> ? T_1 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route>> : never : never) extends infer T_2 ? T_2 extends (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> extends infer T_3 ? T_3 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "parameters">, "query">> ? T_3 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route>> : never : never) ? T_2 extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route> : undefined, options?: OptionsType<Schema, "put", Route, MethodValidStatus> | undefined] : [path: Route, body?: (import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "put", Route> : undefined) | undefined, options?: OptionsType<Schema, "put", Route, MethodValidStatus> | undefined] : never : never : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "put", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "put", Route, "responses">>>>;
|
|
16
|
+
post: <Route extends RoutesForMethod<Schema, "post">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> ? T extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route> : undefined, options: OptionsType<Schema, "post", Route, MethodValidStatus>] : (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> extends infer T_1 ? T_1 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> ? T_1 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route>> : never : never) extends infer T_2 ? T_2 extends (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> extends infer T_3 ? T_3 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "parameters">, "query">> ? T_3 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route>> : never : never) ? T_2 extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route> : undefined, options?: OptionsType<Schema, "post", Route, MethodValidStatus> | undefined] : [path: Route, body?: (import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "post", Route> : undefined) | undefined, options?: OptionsType<Schema, "post", Route, MethodValidStatus> | undefined] : never : never : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "post", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "post", Route, "responses">>>>;
|
|
17
|
+
patch: <Route extends RoutesForMethod<Schema, "patch">, MethodValidStatus extends ValidStatusType | undefined = undefined>(...args: import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> extends infer T ? T extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> ? T extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route> : undefined, options: OptionsType<Schema, "patch", Route, MethodValidStatus>] : (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> extends infer T_1 ? T_1 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> ? T_1 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route>> : never : never) extends infer T_2 ? T_2 extends (import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> extends infer T_3 ? T_3 extends import("./types/utils.js").NotNever<import("./types/utils.js").FilterKeyOrNever<import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "parameters">, "query">> ? T_3 extends true ? true : import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route>> : never : never) ? T_2 extends true ? [path: Route, body: import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route> : undefined, options?: OptionsType<Schema, "patch", Route, MethodValidStatus> | undefined] : [path: Route, body?: (import("./types/utils.js").NotNever<import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route>> extends true ? import("./types/schemeTypes.js").RouteRequestBody<Schema, "patch", Route> : undefined) | undefined, options?: OptionsType<Schema, "patch", Route, MethodValidStatus> | undefined] : never : never : never : never) => Promise<GetApiResponse<IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>, RouteResponsesByStatusCode<Schema, "patch", Route, import("./types/schemeTypes.js").SchemeRouteField<Schema, "patch", Route, "responses">>>>;
|
|
18
|
+
getUri<Method extends MethodType, Route extends RoutesForMethod<Schema, Method>>(method: Method, path: Route, options?: OptionsType<Schema, Method, Route>): Promise<string>;
|
|
19
|
+
private prepareOptions;
|
|
20
|
+
private prepareResponse;
|
|
21
|
+
private optionsToAxiosOptions;
|
|
22
|
+
private factoryWithoutBody;
|
|
23
|
+
private factoryWithBody;
|
|
24
|
+
}
|
|
25
|
+
export type { GetApiResponse, ApiResponseAll, ApiResponseFetch, ApiResponseAxios, } from './types/response.js';
|
|
26
|
+
export type { RouteResponsesByStatusCode, RoutesForMethod, SchemaType, } from './types/schemeTypes.js';
|
|
27
|
+
export type { MethodType } from './const/methods.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenApiAxios = void 0;
|
|
4
|
+
const defaultOptions_js_1 = require("./const/defaultOptions.js");
|
|
5
|
+
const interpolate_params_js_1 = require("./interpolate-params.js");
|
|
6
|
+
const querySerializer_js_1 = require("./utils/querySerializer.js");
|
|
7
|
+
const convertToAll_js_1 = require("./utils/response-converters/convertToAll.js");
|
|
8
|
+
const convertToAxios_js_1 = require("./utils/response-converters/convertToAxios.js");
|
|
9
|
+
const convertToFetch_js_1 = require("./utils/response-converters/convertToFetch.js");
|
|
10
|
+
class OpenApiAxios {
|
|
11
|
+
axios;
|
|
12
|
+
opt;
|
|
13
|
+
constructor(axios, options) {
|
|
14
|
+
this.axios = axios;
|
|
15
|
+
this.opt = Object.assign({}, defaultOptions_js_1.defaultOptions, options);
|
|
16
|
+
}
|
|
17
|
+
get = this.factoryWithoutBody('get');
|
|
18
|
+
head = this.factoryWithoutBody('head');
|
|
19
|
+
delete = this.factoryWithoutBody('delete');
|
|
20
|
+
options = this.factoryWithoutBody('options');
|
|
21
|
+
put = this.factoryWithBody('put');
|
|
22
|
+
post = this.factoryWithBody('post');
|
|
23
|
+
patch = this.factoryWithBody('patch');
|
|
24
|
+
async getUri(method, path, options) {
|
|
25
|
+
const { urlString, newOptions } = this.prepareOptions(path, options);
|
|
26
|
+
const { paramsSerializer, params, ...axios } = this.optionsToAxiosOptions(newOptions);
|
|
27
|
+
const typedParams = params;
|
|
28
|
+
const queryUri = Object.keys(typedParams || {}).length > 0
|
|
29
|
+
? `?${paramsSerializer(typedParams)}`
|
|
30
|
+
: '';
|
|
31
|
+
return this.axios.getUri({
|
|
32
|
+
url: `${urlString}${queryUri}`,
|
|
33
|
+
method,
|
|
34
|
+
...axios,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
prepareOptions(path, options) {
|
|
38
|
+
let urlString = path;
|
|
39
|
+
const newOptions = Object.assign({}, options, {
|
|
40
|
+
validStatus: this.opt.validStatus,
|
|
41
|
+
});
|
|
42
|
+
const optionsWithParams = newOptions;
|
|
43
|
+
if (optionsWithParams?.params)
|
|
44
|
+
urlString = (0, interpolate_params_js_1.interpolateParams)(urlString, optionsWithParams.params);
|
|
45
|
+
const querySerializationParams = options?.querySerializationParams || this.opt.querySerializationParams;
|
|
46
|
+
if (!options?.axios?.paramsSerializer && querySerializationParams) {
|
|
47
|
+
newOptions.axios = Object.assign({}, newOptions.axios, {
|
|
48
|
+
paramsSerializer: (0, querySerializer_js_1.getQuerySerializer)(querySerializationParams),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
urlString,
|
|
53
|
+
newOptions,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async prepareResponse(response, options) {
|
|
57
|
+
switch (options.validStatus) {
|
|
58
|
+
case 'all':
|
|
59
|
+
return (0, convertToAll_js_1.convertToAll)(response);
|
|
60
|
+
case 'fetch':
|
|
61
|
+
return (0, convertToFetch_js_1.convertToFetch)(response);
|
|
62
|
+
case 'axios':
|
|
63
|
+
default:
|
|
64
|
+
return (0, convertToAxios_js_1.convertToAxios)(response);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
optionsToAxiosOptions(options) {
|
|
68
|
+
return {
|
|
69
|
+
params: options?.query,
|
|
70
|
+
...options.axios,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
factoryWithoutBody(method) {
|
|
74
|
+
return (...args) => {
|
|
75
|
+
const [path, options] = args;
|
|
76
|
+
const { urlString, newOptions } = this.prepareOptions(path, options);
|
|
77
|
+
return this.prepareResponse(this.axios[method](urlString, this.optionsToAxiosOptions(newOptions)), newOptions);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
factoryWithBody(method) {
|
|
81
|
+
return (...args) => {
|
|
82
|
+
const [path, body, options] = args;
|
|
83
|
+
const { urlString, newOptions } = this.prepareOptions(path, options);
|
|
84
|
+
return this.prepareResponse(this.axios[method](urlString, body, this.optionsToAxiosOptions(newOptions)), newOptions);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.OpenApiAxios = OpenApiAxios;
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openapi-axios/index.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n AxiosInstance,\n AxiosRequestConfig,\n AxiosResponse,\n CustomParamsSerializer,\n} from 'axios';\nimport { defaultOptions } from './const/defaultOptions.js';\nimport { type MethodType, type MethodTypeWithBody } from './const/methods.js';\nimport { interpolateParams } from './interpolate-params.js';\nimport type { IOpenApiAxiosOptions, OptionsType, ValidStatusType } from './types/options.js';\nimport type {\n FetcherWithBodyParameters,\n FetcherWithoutBodyParameters,\n} from './types/requestParameters.js';\nimport type { GetApiResponse } from './types/response.js';\nimport type {\n RouteResponsesByStatusCode,\n RoutesForMethod,\n SchemaType,\n} from './types/schemeTypes.js';\nimport type { IsNullable } from './types/utils.js';\nimport { getQuerySerializer } from './utils/querySerializer.js';\nimport { convertToAll } from './utils/response-converters/convertToAll.js';\nimport { convertToAxios } from './utils/response-converters/convertToAxios.js';\nimport { convertToFetch } from './utils/response-converters/convertToFetch.js';\n\n/**\n * @description OpenApiAxios class is a wrapper around Axios that provides methods to handle API requests\n * and responses based on OpenAPI specifications.\n *\n * @template Schema - The OpenAPI schema type.\n * @template ClassValidStatus - The type that configures the error handling strategy.\n */\nexport class OpenApiAxios<Schema extends SchemaType, ClassValidStatus extends ValidStatusType> {\n private axios: AxiosInstance;\n private opt: IOpenApiAxiosOptions<ClassValidStatus>;\n\n /**\n * @description Creates an instance of OpenApiAxios.\n *\n * @param axios - The Axios instance to use for requests.\n * @param options - Configuration options for the OpenApiAxios instance.\n */\n constructor(axios: AxiosInstance, options: IOpenApiAxiosOptions<ClassValidStatus>) {\n this.axios = axios;\n this.opt = Object.assign({}, defaultOptions, options);\n }\n\n // HTTP methods without a request body\n public get = this.factoryWithoutBody('get');\n public head = this.factoryWithoutBody('head');\n public delete = this.factoryWithoutBody('delete');\n public options = this.factoryWithoutBody('options');\n\n // HTTP methods with a request body\n public put = this.factoryWithBody('put');\n public post = this.factoryWithBody('post');\n public patch = this.factoryWithBody('patch');\n\n /**\n * @description Generates a URI for a given API endpoint, including query parameters.\n *\n * @param method - The HTTP method to use.\n * @param path - The API route.\n * @param options - Additional options for the request.\n * @returns The generated URI as a string.\n */\n public async getUri<Method extends MethodType, Route extends RoutesForMethod<Schema, Method>>(\n method: Method,\n path: Route,\n options?: OptionsType<Schema, Method, Route>,\n ): Promise<string> {\n const { urlString, newOptions } = this.prepareOptions(path, options);\n const { paramsSerializer, params, ...axios } = this.optionsToAxiosOptions(newOptions);\n const typedParams = params as Record<string, unknown> | undefined;\n\n // Axios getUri doesn't support serializers\n const queryUri =\n Object.keys(typedParams || {}).length > 0\n ? `?${(paramsSerializer as CustomParamsSerializer)(typedParams as Record<string, unknown>)}`\n : '';\n\n return this.axios.getUri({\n url: `${urlString}${queryUri}`,\n method,\n ...axios,\n });\n }\n\n /**\n * @description Prepares the options and URL for an API request.\n *\n * @param path - The API route.\n * @param options - Additional options for the request.\n * @returns An object containing the prepared URL string and new options.\n */\n private prepareOptions<\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined,\n >(\n path: Route,\n options?: OptionsType<Schema, Method, Route, MethodValidStatus>,\n ): {\n urlString: string;\n newOptions: OptionsType<\n Schema,\n Method,\n Route,\n IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>\n >;\n } {\n let urlString = path as string;\n\n // Assign ValidStatus from class if not provided in request options\n const newOptions: OptionsType<\n Schema,\n Method,\n Route,\n IsNullable<MethodValidStatus> extends true ? ClassValidStatus : NonNullable<MethodValidStatus>\n > = Object.assign({}, options, {\n validStatus: this.opt.validStatus,\n });\n\n // Create URL by interpolating parameters based on the OpenAPI pattern\n const optionsWithParams = newOptions as { params?: Record<string, unknown> };\n if (optionsWithParams?.params)\n urlString = interpolateParams(urlString, optionsWithParams.params);\n\n // Assign query serializer to Axios\n const querySerializationParams =\n options?.querySerializationParams || this.opt.querySerializationParams;\n if (!options?.axios?.paramsSerializer && querySerializationParams) {\n newOptions.axios = Object.assign({}, newOptions.axios, {\n paramsSerializer: getQuerySerializer(querySerializationParams),\n });\n }\n\n return {\n urlString,\n newOptions,\n };\n }\n\n /**\n * @description Prepares the API response based on the valid status type.\n *\n * @param response - The Axios response promise.\n * @param options - Options for the request.\n * @returns A promise that resolves to the processed API response.\n */\n private async prepareResponse<\n ValidStatus extends ValidStatusType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n DataByCode extends Record<number, unknown> = RouteResponsesByStatusCode<Schema, Method, Route>,\n >(\n response: Promise<AxiosResponse>,\n options: OptionsType<Schema, Method, Route, ValidStatus>,\n ): Promise<GetApiResponse<ValidStatus, DataByCode>> {\n switch (options.validStatus) {\n case 'all':\n return convertToAll<Schema, Method, Route, DataByCode>(response) as Promise<\n GetApiResponse<ValidStatus, DataByCode>\n >;\n case 'fetch':\n return convertToFetch<Schema, Method, Route, DataByCode>(response) as Promise<\n GetApiResponse<ValidStatus, DataByCode>\n >;\n case 'axios':\n default:\n return convertToAxios<Schema, Method, Route, DataByCode>(response) as Promise<\n GetApiResponse<ValidStatus, DataByCode>\n >;\n }\n }\n\n /**\n * @description Converts OpenAPI options to Axios request options.\n *\n * @param options - The options to convert.\n * @returns The converted Axios request configuration.\n */\n private optionsToAxiosOptions<\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType,\n >(options: OptionsType<Schema, Method, Route, MethodValidStatus>): AxiosRequestConfig {\n return {\n params: (options as { query?: Record<string, unknown> })?.query,\n ...options.axios,\n };\n }\n\n /**\n * @description Creates a fetcher method for HTTP methods that do not have a request body (e.g., GET, DELETE).\n *\n * @param method - The HTTP method to create a fetcher for.\n * @returns A function that performs the API request.\n */\n private factoryWithoutBody<Method extends Exclude<MethodType, MethodTypeWithBody>>(\n method: Method,\n ): <\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined = undefined,\n >(\n ...args: FetcherWithoutBodyParameters<Schema, Method, Route, MethodValidStatus>\n ) => Promise<\n GetApiResponse<\n IsNullable<MethodValidStatus> extends true\n ? ClassValidStatus\n : NonNullable<MethodValidStatus>,\n RouteResponsesByStatusCode<Schema, Method, Route>\n >\n > {\n return <\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined = undefined,\n >(\n ...args: FetcherWithoutBodyParameters<Schema, Method, Route, MethodValidStatus>\n ) => {\n const [path, options] = args;\n const { urlString, newOptions } = this.prepareOptions(path, options);\n\n return this.prepareResponse(\n this.axios[method](urlString, this.optionsToAxiosOptions(newOptions)),\n newOptions,\n );\n };\n }\n\n /**\n * @description Creates a fetcher method for HTTP methods that have a request body (e.g., POST, PUT).\n *\n * @param method - The HTTP method to create a fetcher for.\n * @returns A function that performs the API request.\n */\n private factoryWithBody<Method extends MethodTypeWithBody>(\n method: Method,\n ): <\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined = undefined,\n >(\n ...args: FetcherWithBodyParameters<Schema, Method, Route, MethodValidStatus>\n ) => Promise<\n GetApiResponse<\n IsNullable<MethodValidStatus> extends true\n ? ClassValidStatus\n : NonNullable<MethodValidStatus>,\n RouteResponsesByStatusCode<Schema, Method, Route>\n >\n > {\n return <\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined,\n >(\n ...args: FetcherWithBodyParameters<Schema, Method, Route, MethodValidStatus>\n ) => {\n const [path, body, options] = args;\n const { urlString, newOptions } = this.prepareOptions(path, options);\n\n return this.prepareResponse(\n this.axios[method](urlString, body, this.optionsToAxiosOptions(newOptions)),\n newOptions,\n );\n };\n }\n}\n\nexport type {\n GetApiResponse,\n ApiResponseAll,\n ApiResponseFetch,\n ApiResponseAxios,\n} from './types/response.js';\nexport type {\n RouteResponsesByStatusCode,\n RoutesForMethod,\n SchemaType,\n} from './types/schemeTypes.js';\nexport type { MethodType } from './const/methods.js';\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolateParams = interpolateParams;
|
|
4
|
+
const paramRegex = /{[a-zA-Z_]+}/g;
|
|
5
|
+
function defaultMap(_param, value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function copyParams(params) {
|
|
9
|
+
const result = {};
|
|
10
|
+
for (const param in params) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(params, param)) {
|
|
12
|
+
result[param] = params[param];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function interpolateParams(pattern, params, map) {
|
|
18
|
+
const actualMap = map || defaultMap;
|
|
19
|
+
const remainingParams = copyParams(params);
|
|
20
|
+
const interpolatedPattern = pattern.replace(paramRegex, function (paramWithBrackets) {
|
|
21
|
+
const param = paramWithBrackets.slice(1, paramWithBrackets.length - 1);
|
|
22
|
+
if (param in params) {
|
|
23
|
+
const value = actualMap(param, params[param]);
|
|
24
|
+
if (value === null) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
delete remainingParams[param];
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return paramWithBrackets;
|
|
31
|
+
});
|
|
32
|
+
return interpolatedPattern;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=interpolate-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate-params.js","sourceRoot":"","sources":["../../src/openapi-axios/interpolate-params.ts"],"names":[],"mappings":";;AA2CA,8CAoBC;AA5DD,MAAM,UAAU,GAAG,eAAe,CAAC;AAYnC,SAAS,UAAU,CAAC,MAAc,EAAE,KAAU;IAC5C,OAAO,KAAK,CAAC;AACf,CAAC;AAQD,SAAS,UAAU,CAAC,MAA2B;IAC7C,MAAM,MAAM,GAAG,EAAyB,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAUD,SAAgB,iBAAiB,CAC/B,OAAe,EACf,MAA2B,EAC3B,GAAsB;IAEtB,MAAM,SAAS,GAAG,GAAG,IAAI,UAAU,CAAC;IACpC,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,iBAAiB;QACjF,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACvE,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;YAC9B,OAAO,KAAe,CAAC;QACzB,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["// @REFERENCE: https://github.com/moroshko/interpolate-params\n/* eslint @typescript-eslint/no-explicit-any: 0 */\n\nconst paramRegex = /{[a-zA-Z_]+}/g;\n\ntype InterpolationMap = (param: string, value: any) => any;\n\n/**\n * @description Default mapping function used during parameter interpolation.\n * It simply returns the value provided without modification.\n *\n * @param _param - The parameter name (unused).\n * @param value - The value to map.\n * @returns The mapped value.\n */\nfunction defaultMap(_param: string, value: any): any {\n return value;\n}\n\n/**\n * @description Creates a shallow copy of the given parameters object.\n *\n * @param params - The parameters object to copy.\n * @returns A shallow copy of the `params` object.\n */\nfunction copyParams(params: Record<string, any>): Record<string, any> {\n const result = {} as Record<string, any>;\n for (const param in params) {\n if (Object.prototype.hasOwnProperty.call(params, param)) {\n result[param] = params[param];\n }\n }\n return result;\n}\n\n/**\n * @description Replaces placeholders in a pattern string with corresponding values from the `params` object.\n *\n * @param pattern - The string pattern containing placeholders in the format `{paramName}`.\n * @param params - An object containing parameter values keyed by their names.\n * @param map - An optional mapping function to transform values before interpolation.\n * @returns The interpolated string with placeholders replaced by their corresponding values.\n */\nexport function interpolateParams(\n pattern: string,\n params: Record<string, any>,\n map?: InterpolationMap,\n): string {\n const actualMap = map || defaultMap;\n const remainingParams = copyParams(params);\n const interpolatedPattern = pattern.replace(paramRegex, function (paramWithBrackets) {\n const param = paramWithBrackets.slice(1, paramWithBrackets.length - 1);\n if (param in params) {\n const value = actualMap(param, params[param]);\n if (value === null) {\n return '';\n }\n delete remainingParams[param];\n return value as string;\n }\n return paramWithBrackets;\n });\n return interpolatedPattern;\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { MethodType } from '../const/methods.js';
|
|
3
|
+
import type { RoutePath, RouteQuery, RoutesForMethod, SchemaType } from './schemeTypes.js';
|
|
4
|
+
import type { QuerySerializationParams } from './serializer.js';
|
|
5
|
+
import type { MakeNeverEmpty } from './utils.js';
|
|
6
|
+
export type ValidStatusType = 'all' | 'axios' | 'fetch';
|
|
7
|
+
export interface IOpenApiAxiosOptions<Status extends ValidStatusType> {
|
|
8
|
+
validStatus: Status;
|
|
9
|
+
querySerializationParams?: QuerySerializationParams;
|
|
10
|
+
}
|
|
11
|
+
export type OptionsType<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>, Status extends ValidStatusType | undefined = undefined> = MakeNeverEmpty<{
|
|
12
|
+
params: RoutePath<Schema, Method, Route>;
|
|
13
|
+
query: RouteQuery<Schema, Method, Route>;
|
|
14
|
+
}> & {
|
|
15
|
+
axios?: AxiosRequestConfig;
|
|
16
|
+
validStatus?: Status;
|
|
17
|
+
querySerializationParams?: QuerySerializationParams;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/options.ts"],"names":[],"mappings":"","sourcesContent":["import type { AxiosRequestConfig } from 'axios';\nimport type { MethodType } from '../const/methods.js';\nimport type { RoutePath, RouteQuery, RoutesForMethod, SchemaType } from './schemeTypes.js';\nimport type { QuerySerializationParams } from './serializer.js';\nimport type { MakeNeverEmpty } from './utils.js';\n\n/**\n * @description Type for valid status codes used in OpenAPI requests\n */\nexport type ValidStatusType = 'all' | 'axios' | 'fetch';\n\n/**\n * @description Interface for options passed to OpenAPI requests using Axios\n */\nexport interface IOpenApiAxiosOptions<Status extends ValidStatusType> {\n validStatus: Status;\n querySerializationParams?: QuerySerializationParams;\n}\n\n/**\n * @description Defines options that include path and query parameters, Axios configuration, and valid status codes\n */\nexport type OptionsType<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n Status extends ValidStatusType | undefined = undefined,\n> = MakeNeverEmpty<{\n params: RoutePath<Schema, Method, Route>;\n query: RouteQuery<Schema, Method, Route>;\n}> & {\n axios?: AxiosRequestConfig;\n validStatus?: Status;\n querySerializationParams?: QuerySerializationParams;\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MethodType, MethodTypeWithBody } from '../const/methods.js';
|
|
2
|
+
import type { OptionsType, ValidStatusType } from './options.js';
|
|
3
|
+
import type { RouteQuery, RouteRequestBody, RoutesForMethod, SchemaType } from './schemeTypes.js';
|
|
4
|
+
import type { NotNever } from './utils.js';
|
|
5
|
+
export type FetcherWithoutBodyParameters<Schema extends SchemaType, Method extends Exclude<MethodType, MethodTypeWithBody>, Route extends RoutesForMethod<Schema, Method>, MethodValidStatus extends ValidStatusType | undefined = undefined, StrictOptions extends boolean = NotNever<RouteQuery<Schema, Method, Route>>> = Parameters<(...args: StrictOptions extends true ? Parameters<(path: Route, options: OptionsType<Schema, Method, Route, MethodValidStatus>) => never> : Parameters<(path: Route, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>) => never>;
|
|
6
|
+
export type FetcherWithBodyParameters<Schema extends SchemaType, Method extends MethodTypeWithBody, Route extends RoutesForMethod<Schema, Method>, MethodValidStatus extends ValidStatusType | undefined = undefined, Body extends NotNever<RouteRequestBody<Schema, Method, Route>> extends true ? RouteRequestBody<Schema, Method, Route> : undefined = NotNever<RouteRequestBody<Schema, Method, Route>> extends true ? RouteRequestBody<Schema, Method, Route> : undefined, StrictBody extends boolean = NotNever<RouteRequestBody<Schema, Method, Route>>, StrictOptions extends boolean = NotNever<RouteQuery<Schema, Method, Route>>, HasBody extends boolean = StrictOptions extends true ? true : StrictBody> = Parameters<(...args: StrictOptions extends true ? Parameters<(path: Route, body: Body, options: OptionsType<Schema, Method, Route, MethodValidStatus>) => never> : HasBody extends true ? Parameters<(path: Route, body: Body, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never> : Parameters<(path: Route, body?: Body, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>) => never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestParameters.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/requestParameters.ts"],"names":[],"mappings":"","sourcesContent":["import type { MethodType, MethodTypeWithBody } from '../const/methods.js';\nimport type { OptionsType, ValidStatusType } from './options.js';\nimport type { RouteQuery, RouteRequestBody, RoutesForMethod, SchemaType } from './schemeTypes.js';\nimport type { NotNever } from './utils.js';\n\n/**\n * @description Type definition for fetcher functions without a request body.\n * This type handles methods that do not require a request body (e.g., GET, DELETE).\n *\n * @template Schema - The OpenAPI schema type.\n * @template Method - The HTTP method type (excluding methods with a body).\n * @template Route - The route type within the schema.\n */\nexport type FetcherWithoutBodyParameters<\n Schema extends SchemaType,\n Method extends Exclude<MethodType, MethodTypeWithBody>,\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined = undefined,\n StrictOptions extends boolean = NotNever<RouteQuery<Schema, Method, Route>>,\n> = Parameters<\n (\n // prettier-ignore\n ...args: StrictOptions extends true\n ? Parameters<(path: Route, options: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>\n : Parameters<(path: Route, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>\n ) => never\n>;\n\n/**\n * @description Type definition for fetcher functions with a request body.\n * This type handles methods that require a request body (e.g., POST, PUT).\n *\n * @template Schema - The OpenAPI schema type.\n * @template Method - The HTTP method type (requiring a body).\n * @template Route - The route type within the schema.\n */\nexport type FetcherWithBodyParameters<\n Schema extends SchemaType,\n Method extends MethodTypeWithBody,\n Route extends RoutesForMethod<Schema, Method>,\n MethodValidStatus extends ValidStatusType | undefined = undefined,\n Body extends NotNever<RouteRequestBody<Schema, Method, Route>> extends true\n ? RouteRequestBody<Schema, Method, Route>\n : undefined = NotNever<RouteRequestBody<Schema, Method, Route>> extends true\n ? RouteRequestBody<Schema, Method, Route>\n : undefined,\n StrictBody extends boolean = NotNever<RouteRequestBody<Schema, Method, Route>>,\n StrictOptions extends boolean = NotNever<RouteQuery<Schema, Method, Route>>,\n HasBody extends boolean = StrictOptions extends true ? true : StrictBody,\n> = Parameters<\n (\n // prettier-ignore\n ...args: StrictOptions extends true\n ? Parameters<(path: Route, body: Body, options: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>\n : HasBody extends true\n ? Parameters<(path: Route, body: Body, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>\n : Parameters<(path: Route, body?: Body, options?: OptionsType<Schema, Method, Route, MethodValidStatus>) => never>\n ) => never\n>;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
+
import type { ErrorStatus, OkStatus } from 'openapi-typescript-helpers';
|
|
3
|
+
import type { ValidStatusType } from './options.js';
|
|
4
|
+
export type GetApiResponse<ValidStatus extends ValidStatusType, DataByCode extends Record<number, unknown>> = (ValidStatus extends 'all' ? ApiResponseAll<never, undefined, undefined> : never) | {
|
|
5
|
+
[K in keyof DataByCode]: ValidStatus extends 'all' ? ApiResponseAll<DataByCode[K], K, K extends OkStatus | ErrorStatus ? AxiosResponse<DataByCode[K]> : never, AxiosError> : ValidStatus extends 'fetch' ? ApiResponseFetch<DataByCode[K], K> : ValidStatus extends 'axios' ? K extends OkStatus ? ApiResponseAxios<DataByCode[K], K> : never : never;
|
|
6
|
+
}[keyof DataByCode];
|
|
7
|
+
export type ApiResponseAxios<ResponseData, StatusCode> = {
|
|
8
|
+
status: StatusCode;
|
|
9
|
+
data: ResponseData;
|
|
10
|
+
response: AxiosResponse<ResponseData>;
|
|
11
|
+
};
|
|
12
|
+
export interface ApiResponseFetch<ResponseData, StatusCode> {
|
|
13
|
+
status: StatusCode;
|
|
14
|
+
data: ResponseData;
|
|
15
|
+
error: AxiosError | undefined;
|
|
16
|
+
response: AxiosResponse<ResponseData>;
|
|
17
|
+
}
|
|
18
|
+
export interface ApiResponseAll<ResponseData, StatusCode, AxiosResponseType = AxiosResponse<ResponseData>, ErrorResponseType = unknown> {
|
|
19
|
+
status: StatusCode;
|
|
20
|
+
data: ResponseData;
|
|
21
|
+
error: ErrorResponseType;
|
|
22
|
+
response: AxiosResponseType;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/response.ts"],"names":[],"mappings":"","sourcesContent":["import type { AxiosError, AxiosResponse } from 'axios';\nimport type { ErrorStatus, OkStatus } from 'openapi-typescript-helpers';\nimport type { ValidStatusType } from './options.js';\n\n/**\n * @description Type for retrieving an API response based on the ValidStatus type and data by status code.\n *\n * @description The ValidStatus type configures the error handling strategy and sets up the returned value:\n * - \"axios\" (default): Throws an error in the following cases:\n * - `response.status >= 400`\n * - Request failure (e.g., network error)\n * - Axios interceptors failure\n * - \"fetch\": Throws an error in the following cases:\n * - Request failure (e.g., network error)\n * - Axios interceptors failure\n * - \"all\": Never throws an error, so no try/catch is required.\n *\n * @template ValidStatus - The type that determines whether all, fetch, or axios valid statuses are used.\n * @template DataByCode - A record type mapping status codes to their corresponding data types.\n */\nexport type GetApiResponse<\n ValidStatus extends ValidStatusType,\n DataByCode extends Record<number, unknown>,\n> =\n | (ValidStatus extends 'all' ? ApiResponseAll<never, undefined, undefined> : never)\n | {\n [K in keyof DataByCode]: ValidStatus extends 'all'\n ? ApiResponseAll<\n DataByCode[K],\n K,\n K extends OkStatus | ErrorStatus ? AxiosResponse<DataByCode[K]> : never,\n AxiosError\n >\n : ValidStatus extends 'fetch'\n ? ApiResponseFetch<DataByCode[K], K>\n : ValidStatus extends 'axios'\n ? K extends OkStatus\n ? ApiResponseAxios<DataByCode[K], K>\n : never\n : never;\n }[keyof DataByCode];\n\n/**\n * @description Type representing an Axios-specific API response for successful requests.\n *\n * @template ResponseData - The type of the data returned by the request.\n * @template StatusCode - The HTTP status code.\n */\nexport type ApiResponseAxios<ResponseData, StatusCode> = {\n /**\n * @description HTTP status code. Can only be 1xx, 2xx, or 3xx.\n */\n status: StatusCode;\n\n /**\n * @description Data returned by the request.\n */\n data: ResponseData;\n\n /**\n * @description Axios response object. Contains all the information about the request.\n */\n response: AxiosResponse<ResponseData>;\n};\n\n/**\n * @description Interface representing an API response for fetch requests.\n *\n * @template ResponseData - The type of the data returned by the request.\n * @template StatusCode - The HTTP status code.\n */\nexport interface ApiResponseFetch<ResponseData, StatusCode> {\n /**\n * @description HTTP status code.\n */\n status: StatusCode;\n\n /**\n * @description Data returned by the request.\n */\n data: ResponseData;\n\n /**\n * @description Field to store the error.\n * This can be an error from a request with an HTTP status of 4xx or 5xx.\n * Does not include errors when the server does not respond\n * (e.g., due to a network error) or errors handled by\n * a custom interceptor.\n */\n error: AxiosError | undefined;\n\n /**\n * @description Axios response object. Contains all the information about the request.\n */\n response: AxiosResponse<ResponseData>;\n}\n\n/**\n * @description Interface representing an API response for any valid status type, including both success and error responses.\n *\n * @template ResponseData - The type of the data returned by the request.\n * @template StatusCode - The HTTP status code.\n * @template AxiosResponseType - The type of the Axios response object.\n * @template ErrorResponseType - The type of the error object.\n */\nexport interface ApiResponseAll<\n ResponseData,\n StatusCode,\n AxiosResponseType = AxiosResponse<ResponseData>,\n ErrorResponseType = unknown,\n> {\n /**\n * @description HTTP status code. Can be undefined, check error description.\n */\n status: StatusCode;\n\n /**\n * @description Data returned by the request.\n */\n data: ResponseData;\n\n /**\n * @description Field to store the error.\n * This can include any errors such as:\n * - Errors from requests with an HTTP status of 4xx or 5xx.\n * - Errors when the server does not respond (e.g., due to a network error).\n * - Errors handled by a custom interceptor.\n */\n error: ErrorResponseType;\n\n /**\n * @description Axios response object. Contains all the information about the request.\n */\n response: AxiosResponseType;\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FilterKeys, PathsWithMethod } from 'openapi-typescript-helpers';
|
|
2
|
+
import type { MethodType } from '../const/methods.js';
|
|
3
|
+
import type { FilterKeyOrNever, IsFieldOptional } from './utils.js';
|
|
4
|
+
export type FieldType = 'parameters' | 'requestBody' | 'responses';
|
|
5
|
+
type MediaType = `${string}/${string}`;
|
|
6
|
+
export type SchemaType = {
|
|
7
|
+
[route in keyof object]: {
|
|
8
|
+
[method in MethodType]?: {
|
|
9
|
+
parameters: {
|
|
10
|
+
query?: object;
|
|
11
|
+
path?: object;
|
|
12
|
+
};
|
|
13
|
+
requestBody?: {
|
|
14
|
+
content: {
|
|
15
|
+
[content in MediaType]: unknown;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
responses?: {
|
|
19
|
+
[code in number]: {
|
|
20
|
+
content: {
|
|
21
|
+
[content in MediaType]: unknown;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type SchemeRoute<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>> = FilterKeys<FilterKeys<Schema, Route>, Method>;
|
|
29
|
+
export type SchemeRouteField<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>, Field extends FieldType> = FilterKeys<SchemeRoute<Schema, Method, Route>, Field>;
|
|
30
|
+
export type RoutePath<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>> = FilterKeyOrNever<SchemeRouteField<Schema, Method, Route, 'parameters'>, 'path'>;
|
|
31
|
+
export type RouteQuery<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>> = FilterKeyOrNever<SchemeRouteField<Schema, Method, Route, 'parameters'>, 'query'>;
|
|
32
|
+
export type RoutesForMethod<Schema extends SchemaType, Method extends MethodType> = PathsWithMethod<Schema, Method>;
|
|
33
|
+
type TargetMimeTypes = `${string}/json` | `multipart/form-data`;
|
|
34
|
+
export type RouteRequestBody<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>> = IsFieldOptional<SchemeRoute<Schema, Method, Route>, 'requestBody'> extends true ? FilterKeys<FilterKeys<FilterKeys<Required<SchemeRoute<Schema, Method, Route>>, 'requestBody'>, 'content'>, TargetMimeTypes> | undefined : FilterKeys<FilterKeys<FilterKeys<FilterKeys<FilterKeys<Schema, Route>, Method>, 'requestBody'>, 'content'>, TargetMimeTypes>;
|
|
35
|
+
export type RouteResponsesByStatusCode<Schema extends SchemaType, Method extends MethodType, Route extends RoutesForMethod<Schema, Method>, Responses = SchemeRouteField<Schema, Method, Route, 'responses'>> = {
|
|
36
|
+
[k in keyof Responses]: FilterKeys<FilterKeys<Responses[k], 'content'>, TargetMimeTypes>;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemeTypes.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/schemeTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { FilterKeys, PathsWithMethod } from 'openapi-typescript-helpers';\nimport type { MethodType } from '../const/methods.js';\nimport type { FilterKeyOrNever, IsFieldOptional } from './utils.js';\n\n/**\n * @description Define possible field types in OpenAPI schema\n */\nexport type FieldType = 'parameters' | 'requestBody' | 'responses';\ntype MediaType = `${string}/${string}`;\n\n/**\n * @description Type definition for the OpenAPI schema\n */\nexport type SchemaType = {\n [route in keyof object]: {\n [method in MethodType]?: {\n parameters: {\n query?: object;\n path?: object;\n };\n requestBody?: {\n content: {\n [content in MediaType]: unknown;\n };\n };\n responses?: {\n [code in number]: {\n content: {\n [content in MediaType]: unknown;\n };\n };\n };\n };\n };\n};\n\n/**\n * @description Checks for the existence of an internal route. If it exists, it retrieves it\n */\nexport type SchemeRoute<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n> = FilterKeys<FilterKeys<Schema, Route>, Method>;\n\n/**\n * @description Checks for the existence of an internal field. If it exists, it retrieves it\n */\nexport type SchemeRouteField<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n Field extends FieldType,\n> = FilterKeys<SchemeRoute<Schema, Method, Route>, Field>;\n\n/**\n * @description Extracts all path parameters for a given route and method in the schema\n */\nexport type RoutePath<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n> = FilterKeyOrNever<SchemeRouteField<Schema, Method, Route, 'parameters'>, 'path'>;\n\n/**\n * @description Extracts all query parameters for a given route and method in the schema\n */\nexport type RouteQuery<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n> = FilterKeyOrNever<SchemeRouteField<Schema, Method, Route, 'parameters'>, 'query'>;\n\n/**\n * @description Extracts all routes from the OpenAPI schema interface\n */\nexport type RoutesForMethod<Schema extends SchemaType, Method extends MethodType> = PathsWithMethod<\n Schema,\n Method\n>;\n\ntype TargetMimeTypes = `${string}/json` | `multipart/form-data`;\n\n/**\n * @description Retrieves the request body\n */\nexport type RouteRequestBody<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n> =\n IsFieldOptional<SchemeRoute<Schema, Method, Route>, 'requestBody'> extends true\n ?\n | FilterKeys<\n FilterKeys<\n FilterKeys<Required<SchemeRoute<Schema, Method, Route>>, 'requestBody'>,\n 'content'\n >,\n TargetMimeTypes\n >\n | undefined\n : FilterKeys<\n FilterKeys<\n FilterKeys<FilterKeys<FilterKeys<Schema, Route>, Method>, 'requestBody'>,\n 'content'\n >,\n TargetMimeTypes\n >;\n\n/**\n * @example\n * {\n * 200: data,\n * 400: data\n * }\n */\nexport type RouteResponsesByStatusCode<\n Schema extends SchemaType,\n Method extends MethodType,\n Route extends RoutesForMethod<Schema, Method>,\n Responses = SchemeRouteField<Schema, Method, Route, 'responses'>,\n> = {\n [k in keyof Responses]: FilterKeys<FilterKeys<Responses[k], 'content'>, TargetMimeTypes>;\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum QuerySerializerStyle {
|
|
2
|
+
From = "form",
|
|
3
|
+
SpaceDelimited = "spaceDelimited",
|
|
4
|
+
PipeDelimited = "pipeDelimited",
|
|
5
|
+
DeepObject = "deepObject"
|
|
6
|
+
}
|
|
7
|
+
type QuerySerializationParamsVariant<Style extends QuerySerializerStyle, Explode extends boolean> = {
|
|
8
|
+
style: Style;
|
|
9
|
+
explode: Explode;
|
|
10
|
+
};
|
|
11
|
+
export type QuerySerializationParams = QuerySerializationParamsVariant<Exclude<QuerySerializerStyle, QuerySerializerStyle.DeepObject>, boolean> | QuerySerializationParamsVariant<QuerySerializerStyle.DeepObject, true>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuerySerializerStyle = void 0;
|
|
4
|
+
var QuerySerializerStyle;
|
|
5
|
+
(function (QuerySerializerStyle) {
|
|
6
|
+
QuerySerializerStyle["From"] = "form";
|
|
7
|
+
QuerySerializerStyle["SpaceDelimited"] = "spaceDelimited";
|
|
8
|
+
QuerySerializerStyle["PipeDelimited"] = "pipeDelimited";
|
|
9
|
+
QuerySerializerStyle["DeepObject"] = "deepObject";
|
|
10
|
+
})(QuerySerializerStyle || (exports.QuerySerializerStyle = QuerySerializerStyle = {}));
|
|
11
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/serializer.ts"],"names":[],"mappings":";;;AAGA,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,yDAAiC,CAAA;IACjC,uDAA+B,CAAA;IAC/B,iDAAyB,CAAA;AAC3B,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","sourcesContent":["/**\n * @description Enumeration for different styles of query parameter serialization\n */\nexport enum QuerySerializerStyle {\n From = 'form',\n SpaceDelimited = 'spaceDelimited',\n PipeDelimited = 'pipeDelimited',\n DeepObject = 'deepObject',\n}\n\n/**\n * @description Define a type for query serialization parameters with different styles and explode options\n */\ntype QuerySerializationParamsVariant<\n Style extends QuerySerializerStyle,\n Explode extends boolean,\n> = {\n style: Style;\n explode: Explode;\n};\n\n/**\n * @description Combine all possible query serialization parameters into a union type\n */\nexport type QuerySerializationParams =\n | QuerySerializationParamsVariant<\n Exclude<QuerySerializerStyle, QuerySerializerStyle.DeepObject>,\n boolean\n >\n | QuerySerializationParamsVariant<QuerySerializerStyle.DeepObject, true>;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type IsNullable<T> = [T] extends [NonNullable<T>] ? false : true;
|
|
2
|
+
type Empty = void | undefined | null;
|
|
3
|
+
export type MakeNeverEmpty<T> = {
|
|
4
|
+
[K in keyof T as T[K] extends Empty ? never : K]: T[K];
|
|
5
|
+
} & {
|
|
6
|
+
[K in keyof T as T[K] extends Empty ? K : never]?: undefined;
|
|
7
|
+
};
|
|
8
|
+
export type NotNever<T> = [T] extends [never] ? false : true;
|
|
9
|
+
export type IsFieldOptional<T, K extends string> = K extends keyof T ? undefined extends T[K] ? true : false : false;
|
|
10
|
+
export type FilterKeyOrNever<T, K> = K extends keyof T ? T[K] extends undefined ? never : T[K] : never;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/openapi-axios/types/utils.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @description Type utility to determine if a type `T` is nullable.\n * Returns `true` if `T` is `null` or `undefined`, otherwise `false`.\n *\n * @template T - The type to check for nullability.\n */\nexport type IsNullable<T> = [T] extends [NonNullable<T>] ? false : true;\n\ntype Empty = void | undefined | null;\n\n/**\n * @description Type utility that removes properties from a type `T` where the property type is `never` or `void`.\n * Properties with type `never` or `void` are made optional and set to `undefined`.\n *\n * @template T - The type from which to remove `never` and `void` properties.\n */\nexport type MakeNeverEmpty<T> = {\n [K in keyof T as T[K] extends Empty ? never : K]: T[K];\n} & {\n [K in keyof T as T[K] extends Empty ? K : never]?: undefined;\n};\n\n/**\n * @description Type utility to determine if a type `T` is `never`.\n * Returns `true` if `T` is not `never`, otherwise `false`.\n *\n * @template T - The type to check.\n */\nexport type NotNever<T> = [T] extends [never] ? false : true;\n\n/**\n * @description Type utility to determine if a field in an object type `T` can be `undefined`.\n * Returns `true` if the field `K` of type `T` can be `undefined`, otherwise `false`.\n *\n * @template T - The object type to check.\n * @template K - The key of the field in the object type `T` to check for `undefined`.\n */\nexport type IsFieldOptional<T, K extends string> = K extends keyof T\n ? undefined extends T[K]\n ? true\n : false\n : false;\n\n/**\n * @description Type utility to filter the key `K` from type `T`.\n * Returns the type of `T[K]` if `K` is a key of `T` and `T[K]` is not `undefined`.\n * Otherwise, returns `never`.\n *\n * @template T - The object type to check.\n * @template K - The key to filter.\n */\nexport type FilterKeyOrNever<T, K> = K extends keyof T\n ? T[K] extends undefined\n ? never\n : T[K]\n : never;\n"]}
|