@mittwald/api-client-commons
Advanced tools
| export * from "axios"; |
| import axios, { Axios } from "axios"; | ||
| import Request from "./Request.js"; | ||
| export class ApiClientBase { | ||
| axios; | ||
| constructor(axiosConfig = axios) { | ||
| this.axios = | ||
| axiosConfig instanceof Axios ? axiosConfig : axios.create(axiosConfig); | ||
| } | ||
| requestFunctionFactory(operation) { | ||
| return (conf) => new Request(operation, conf).execute(this.axios); | ||
| } | ||
| } | ||
| export default ApiClientBase; |
| import { AxiosError } from "axios"; | ||
| export class ApiClientError extends AxiosError { | ||
| constructor(message, code, config, request, response) { | ||
| super(message, code, config, request, response); | ||
| Object.setPrototypeOf(this, ApiClientError.prototype); | ||
| this.name = "ApiClientError"; | ||
| } | ||
| static fromResponse(message, response) { | ||
| return new ApiClientError(message, undefined, response.config, response.request, response); | ||
| } | ||
| } | ||
| export default ApiClientError; |
| export * from "./ApiClientBase.js"; | ||
| export * from "./ApiClientError.js"; | ||
| export * from "./OpenAPIPath.js"; | ||
| export * from "./Request.js"; |
| export class OpenAPIPath { | ||
| rawPath; | ||
| params; | ||
| constructor(rawPath, params) { | ||
| this.rawPath = rawPath; | ||
| this.params = params; | ||
| } | ||
| buildUrl() { | ||
| return OpenAPIPath.setPathParams(this.rawPath, this.params); | ||
| } | ||
| static setPathParams(path, params) { | ||
| const asEntries = Object.entries(params ?? {}); | ||
| const finalPath = asEntries.reduce((path, entry) => { | ||
| const [key, value] = entry; | ||
| return path.replace(`{${key}}`, encodeURIComponent(value)); | ||
| }, path); | ||
| return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath; | ||
| } | ||
| } | ||
| export default OpenAPIPath; |
| import OpenAPIPath from "./OpenAPIPath.js"; | ||
| export class Request { | ||
| operationDescriptor; | ||
| requestObject; | ||
| requestConfig; | ||
| constructor(operationDescriptor, requestObject) { | ||
| this.operationDescriptor = operationDescriptor; | ||
| this.requestObject = requestObject; | ||
| this.requestConfig = Object.freeze(this.buildAxiosConfig()); | ||
| } | ||
| execute(axios) { | ||
| return axios.request(this.requestConfig); | ||
| } | ||
| buildAxiosConfig() { | ||
| const { method, path } = this.operationDescriptor; | ||
| const pathParameters = this.requestObject; | ||
| const openApiPath = new OpenAPIPath(path, pathParameters); | ||
| const url = openApiPath.buildUrl(); | ||
| const data = this.requestObject && "data" in this.requestObject | ||
| ? this.requestObject.data | ||
| : undefined; | ||
| const headersConfig = this.requestObject && "headers" in this.requestObject | ||
| ? this.requestObject.headers | ||
| : undefined; | ||
| const headers = headersConfig | ||
| ? this.makeAxiosHeaders(headersConfig) | ||
| : undefined; | ||
| const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject | ||
| ? this.requestObject.queryParameters | ||
| : undefined; | ||
| const params = this.convertQueryToUrlSearchParams(queryParametersConfig); | ||
| return { | ||
| url, | ||
| method, | ||
| headers, | ||
| // Must be a plain object or an URLSearchParams object | ||
| params, | ||
| data, | ||
| validateStatus: () => true, | ||
| }; | ||
| } | ||
| makeAxiosHeaders(headers) { | ||
| return Object.fromEntries(Object.entries(headers).map(([key, value]) => [key, value?.toString()])); | ||
| } | ||
| convertQueryToUrlSearchParams(query) { | ||
| if (query === undefined || query === null) { | ||
| return undefined; | ||
| } | ||
| if (query instanceof URLSearchParams) { | ||
| return query; | ||
| } | ||
| if (typeof query === "string") { | ||
| return new URLSearchParams(query); | ||
| } | ||
| if (typeof query === "object") { | ||
| const searchParams = new URLSearchParams(); | ||
| for (const [key, value] of Object.entries(query)) { | ||
| if (Array.isArray(value)) { | ||
| for (const arrayItem of value) { | ||
| searchParams.append(key, arrayItem); | ||
| } | ||
| } | ||
| else { | ||
| searchParams.append(key, typeof value === "string" || | ||
| typeof value === "number" || | ||
| typeof value === "boolean" | ||
| ? value.toString() | ||
| : JSON.stringify(value)); | ||
| } | ||
| } | ||
| return searchParams; | ||
| } | ||
| throw new Error(`Unexpected query parameter type (${typeof query})`); | ||
| } | ||
| } | ||
| export default Request; |
| import Request from "./Request.js"; | ||
| import { jest } from "@jest/globals"; | ||
| const requestFn = jest.fn(); | ||
| const mockedAxios = { | ||
| request: requestFn, | ||
| }; | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
| describe("query parameters", () => { | ||
| const op = { | ||
| path: "/", | ||
| operationId: "test", | ||
| method: "GET", | ||
| }; | ||
| const executeRequest = (query) => { | ||
| const request = new Request(op, { queryParameters: query }); | ||
| request.execute(mockedAxios); | ||
| const requestConfig = requestFn.mock.calls[0][0]; | ||
| return requestConfig.params.toString(); | ||
| }; | ||
| test("Empty query", () => { | ||
| const query = executeRequest({}); | ||
| expect(query).toBe(""); | ||
| }); | ||
| test("Simple parameter", () => { | ||
| const query = executeRequest({ | ||
| foo: "bar", | ||
| }); | ||
| expect(query).toBe("foo=bar"); | ||
| }); | ||
| test("Two parameters", () => { | ||
| const query = executeRequest({ | ||
| foo: "bar", | ||
| bam: "baz", | ||
| }); | ||
| expect(query).toBe("foo=bar&bam=baz"); | ||
| }); | ||
| test("Array parameters", () => { | ||
| const query = executeRequest({ | ||
| foo: ["bar", "bam"], | ||
| }); | ||
| expect(query).toBe("foo=bar&foo=bam"); | ||
| }); | ||
| test("Number, boolean, JSON", () => { | ||
| const query = executeRequest({ | ||
| foo: 1, | ||
| bar: true, | ||
| baz: { some: "value" }, | ||
| }); | ||
| expect(query).toBe("foo=1&bar=true&baz=%7B%22some%22%3A%22value%22%7D"); | ||
| }); | ||
| }); |
| export * from "./core/index.js"; | ||
| export * from "./types/index.js"; | ||
| export * from "./axios.js"; |
| import { getAsyncResource } from "@mittwald/react-use-promise"; | ||
| import { assertStatus, } from "../types/index.js"; | ||
| import Request from "../core/Request.js"; | ||
| export class ApiCallAsyncResourceFactory { | ||
| static namespace = "@mittwald/api-client"; | ||
| operation; | ||
| requestFn; | ||
| constructor(operation, requestFn) { | ||
| this.operation = operation; | ||
| this.requestFn = requestFn; | ||
| } | ||
| getAsyncResourceId() { | ||
| return `${ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`; | ||
| } | ||
| getAsyncResourceTags(request) { | ||
| const url = request.requestConfig.url ?? ""; | ||
| return [ | ||
| this.getAsyncResourceId(), | ||
| `${ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`, | ||
| `${ApiCallAsyncResourceFactory.namespace}/${url}`, | ||
| ]; | ||
| } | ||
| async executeRequest(requestObj) { | ||
| const response = await this.requestFn(requestObj); | ||
| assertStatus(response, 200); | ||
| return response.data; | ||
| } | ||
| getApiResource = ((requestObj) => { | ||
| const request = new Request(this.operation, requestObj); | ||
| return getAsyncResource((requestObj) => this.executeRequest(requestObj), [requestObj], { | ||
| tags: this.getAsyncResourceTags(request), | ||
| loaderId: this.getAsyncResourceId(), | ||
| }); | ||
| }); | ||
| } |
| import { ApiCallAsyncResourceFactory } from "./ApiCallAsyncResourceFactory.js"; | ||
| const getStuff = new ApiCallAsyncResourceFactory({ | ||
| operationId: "getStuff", | ||
| path: "/stuff", | ||
| method: "GET", | ||
| }, {}); | ||
| function ignoredCheckRequestType() { | ||
| getStuff.getApiResource({ | ||
| data: { | ||
| // @ts-expect-error Not matching request type | ||
| foo: "", | ||
| }, | ||
| }); | ||
| getStuff.getApiResource({ | ||
| data: { | ||
| requestString: "", | ||
| }, | ||
| }); | ||
| } | ||
| function ignoredCheckResponseType() { | ||
| const stuff = getStuff | ||
| .getApiResource({ | ||
| data: { | ||
| requestString: "", | ||
| }, | ||
| }) | ||
| .use(); | ||
| // @ts-expect-error Accessing unknown prop | ||
| stuff.foo; | ||
| (function (ignored) { | ||
| // @ts-expect-error is a number | ||
| })(stuff.responseData); | ||
| (function (ignored) { | ||
| // is number | ||
| })(stuff.responseData); | ||
| } |
| import { beforeEach, expect, jest } from "@jest/globals"; | ||
| import { ApiCallAsyncResourceFactory } from "./ApiCallAsyncResourceFactory.js"; | ||
| import { refresh } from "@mittwald/react-use-promise"; | ||
| beforeEach(() => { | ||
| refresh(); | ||
| jest.resetAllMocks(); | ||
| }); | ||
| const requestMock = jest.fn(); | ||
| const getStuff = new ApiCallAsyncResourceFactory({ | ||
| operationId: "getStuff", | ||
| path: "/stuff", | ||
| method: "GET", | ||
| }, requestMock); | ||
| const testRequest1 = { | ||
| data: { | ||
| foo: "bar", | ||
| }, | ||
| }; | ||
| const testRequest2 = { | ||
| data: { | ||
| foo: "baz", | ||
| }, | ||
| }; | ||
| test("Resource loader executes request", async () => { | ||
| await getStuff.getApiResource(testRequest1).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(1); | ||
| const firstRequestParams = requestMock.mock.calls[0][0]; | ||
| expect(firstRequestParams).toMatchObject(testRequest1); | ||
| }); | ||
| test("Resource is cached under URL", async () => { | ||
| await getStuff.getApiResource(testRequest1).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(1); | ||
| await getStuff.getApiResource(testRequest1).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(1); | ||
| refresh({ | ||
| tag: "@mittwald/api-client/stuff", | ||
| }); | ||
| await getStuff.getApiResource(testRequest1).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(2); | ||
| }); | ||
| test("Resources are different when request object changes", async () => { | ||
| await getStuff.getApiResource(testRequest1).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(1); | ||
| await getStuff.getApiResource(testRequest2).load(); | ||
| expect(requestMock).toHaveBeenCalledTimes(2); | ||
| }); |
| export * from "./ApiCallAsyncResourceFactory.js"; |
| export {}; |
| import ApiClientError from "../core/ApiClientError.js"; | ||
| export function assertStatus(response, expectedStatus) { | ||
| if (response.status !== expectedStatus) { | ||
| throw ApiClientError.fromResponse(`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, response); | ||
| } | ||
| } | ||
| export default assertStatus; |
| import { expectAssignable } from "tsd"; | ||
| import assertStatus from "./assertStatus.js"; | ||
| function ignoredTestAssertStatusAssertsAlsoTheCorrectResponseType() { | ||
| assertStatus(someResponse, 200); | ||
| expectAssignable(someResponse); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable(someResponse); | ||
| } |
| export {}; |
| export * from "./RequestType.js"; | ||
| export * from "./RequestFunction.js"; | ||
| export * from "./Response.js"; | ||
| export * from "./OpenAPIOperation.js"; | ||
| export * from "./http.js"; | ||
| export * from "./simplify.js"; | ||
| export * from "./assertStatus.js"; |
| export {}; |
| export {}; |
| export {}; |
| function ignoredTestEmptyRequestTypes() { | ||
| const f = {}; | ||
| void f(); | ||
| void f({ | ||
| headers: {}, | ||
| }); | ||
| void f({ | ||
| headers: { extra: true }, | ||
| }); | ||
| } | ||
| function ignoredTestOptionalHeadersRequestTypes() { | ||
| const f = {}; | ||
| void f(); | ||
| void f({ | ||
| headers: {}, | ||
| }); | ||
| void f({ | ||
| headers: { extra: true }, | ||
| }); | ||
| } | ||
| function ignoredTestPathParametersAreInRootOfRequestConfig() { | ||
| const f = {}; | ||
| void f({ | ||
| foo: "", | ||
| }); | ||
| // @ts-expect-error Missing parameter | ||
| void f({}); | ||
| } | ||
| export {}; |
| export {}; |
| import { expectAssignable } from "tsd"; | ||
| function ignoredTestEmptyRequestTypes() { | ||
| expectAssignable({}); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({ extra: true }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({ data: {} }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({ data: null }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({ pathParameters: {} }); | ||
| } | ||
| function ignoredTestRequestTypesWithDataType() { | ||
| expectAssignable({ data: { foo: "" } }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({}); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| data: { foo: "", extra: "" }, | ||
| }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({ data: { noFoo: "" } }); | ||
| } | ||
| function ignoredTestRequestTypesWithPathParameters() { | ||
| expectAssignable({ | ||
| data: { foo: "" }, | ||
| pathParameters: { bar: "" }, | ||
| }); | ||
| expectAssignable({ | ||
| pathParameters: { bar: "" }, | ||
| }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({}); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| pathParameters: {}, | ||
| }); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| pathParameters: { foo: "", extra: "" }, | ||
| }); | ||
| } | ||
| function ignoredTestRequestTypesWithHeader() { | ||
| expectAssignable({ | ||
| data: { | ||
| foo: "", | ||
| }, | ||
| pathParameters: { bar: "" }, | ||
| headers: { baz: "" }, | ||
| }); | ||
| expectAssignable({ | ||
| pathParameters: { bar: "" }, | ||
| headers: { baz: "" }, | ||
| }); | ||
| expectAssignable({ | ||
| headers: { baz: "" }, | ||
| }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({}); | ||
| expectAssignable({ | ||
| headers: { | ||
| // @ts-expect-error Not assignable | ||
| baz: 42, | ||
| }, | ||
| }); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| headers: {}, | ||
| }); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| data: {}, | ||
| headers: { | ||
| baz: "", | ||
| }, | ||
| }); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| pathParameters: {}, | ||
| headers: { | ||
| baz: "", | ||
| }, | ||
| }); | ||
| } | ||
| function ignoredTestRequestTypesWithQuery() { | ||
| expectAssignable({ | ||
| data: { | ||
| foo: "", | ||
| }, | ||
| pathParameters: { bar: "" }, | ||
| headers: { baz: "" }, | ||
| queryParameters: { | ||
| whut: "", | ||
| }, | ||
| }); | ||
| expectAssignable({ | ||
| pathParameters: { bar: "" }, | ||
| headers: { baz: "" }, | ||
| queryParameters: { | ||
| whut: "", | ||
| }, | ||
| }); | ||
| expectAssignable({ | ||
| queryParameters: { | ||
| whut: "", | ||
| }, | ||
| }); | ||
| // @ts-expect-error Not assignable | ||
| expectAssignable({}); | ||
| expectAssignable({ | ||
| queryParameters: { | ||
| // @ts-expect-error Not assignable | ||
| whut: 42, | ||
| }, | ||
| }); | ||
| expectAssignable({ | ||
| // @ts-expect-error Not assignable | ||
| queryParameters: {}, | ||
| }); | ||
| } | ||
| function ignoredTestAdditionalHeadersCanAlwaysBeSet() { | ||
| expectAssignable({ | ||
| headers: { extra: true }, | ||
| }); | ||
| expectAssignable({ | ||
| headers: { extra: true }, | ||
| }); | ||
| expectAssignable({ | ||
| headers: { extra: true }, | ||
| }); | ||
| expectAssignable({ | ||
| data: { | ||
| foo: "", | ||
| }, | ||
| headers: { extra: true }, | ||
| }); | ||
| expectAssignable({ | ||
| pathParameters: { | ||
| bar: "", | ||
| }, | ||
| headers: { extra: true }, | ||
| }); | ||
| expectAssignable({ | ||
| headers: { extra: true, baz: "" }, | ||
| }); | ||
| } |
| export {}; |
| import { expectAssignable, expectNotAssignable, expectType } from "tsd"; | ||
| const additionalAxiosResponseData = { | ||
| statusText: "", | ||
| headers: {}, | ||
| config: {}, | ||
| mediaType: "application/json", | ||
| }; | ||
| expectAssignable({ | ||
| data: { a: "" }, | ||
| status: 200, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectNotAssignable({ | ||
| data: { a: "", extra: "!" }, | ||
| status: 200, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectAssignable({ | ||
| data: { | ||
| b: "", | ||
| }, | ||
| status: 201, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectAssignable({ | ||
| data: null, | ||
| status: 400, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectNotAssignable({ | ||
| data: null, | ||
| status: 42, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectNotAssignable({ | ||
| data: null, | ||
| status: 42, | ||
| extra: "!", | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| expectNotAssignable({ | ||
| data: { extraContent: "" }, | ||
| status: 400, | ||
| ...additionalAxiosResponseData, | ||
| }); | ||
| function ignoredTestRequestTypesWithDataPathParameters() { | ||
| const someResponse = {}; | ||
| expectType(someResponse.status); | ||
| if (someResponse.status === 200) { | ||
| // @ts-expect-error > a is not in data | ||
| someResponse.data.a; | ||
| // @ts-expect-error > b is not in data | ||
| someResponse.data.b; | ||
| if (someResponse.mediaType === "text/plain") { | ||
| // @ts-expect-error > a is not in data | ||
| someResponse.data.a; | ||
| expectType(someResponse.data.text); | ||
| } | ||
| else { | ||
| // @ts-expect-error > text is not in data | ||
| someResponse.data.text; | ||
| expectType(someResponse.data.a); | ||
| } | ||
| } | ||
| else if (someResponse.status === 201) { | ||
| expectType(someResponse.data.b); | ||
| // @ts-expect-error > a is not in data | ||
| someResponse.data.a; | ||
| } | ||
| } |
| export {}; |
| export * from "axios"; |
| import { AxiosInstance, CreateAxiosDefaults } from "axios"; | ||
| import { RequestFunction } from "../types/index.js"; | ||
| import { OpenAPIOperation } from "../types/index.js"; | ||
| export declare abstract class ApiClientBase { | ||
| axios: AxiosInstance; | ||
| constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults); | ||
| protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>; | ||
| } | ||
| export default ApiClientBase; |
| import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from "axios"; | ||
| import { AnyResponse } from "../types/Response.js"; | ||
| export declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> { | ||
| constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>); | ||
| static fromResponse(message: string, response: AnyResponse): ApiClientError; | ||
| } | ||
| export default ApiClientError; |
| export * from "./ApiClientBase.js"; | ||
| export * from "./ApiClientError.js"; | ||
| export * from "./OpenAPIPath.js"; | ||
| export * from "./Request.js"; |
| import { PathParameters } from "../types/http.js"; | ||
| export declare class OpenAPIPath { | ||
| private readonly rawPath; | ||
| private readonly params?; | ||
| constructor(rawPath: string, params?: PathParameters); | ||
| buildUrl(): string; | ||
| private static setPathParams; | ||
| } | ||
| export default OpenAPIPath; |
| import { OpenAPIOperation, RequestObject, ResponsePromise } from "../types/index.js"; | ||
| import { AxiosInstance, AxiosRequestConfig } from "axios"; | ||
| export declare class Request<TOp extends OpenAPIOperation> { | ||
| private readonly operationDescriptor; | ||
| private readonly requestObject?; | ||
| readonly requestConfig: AxiosRequestConfig; | ||
| constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>); | ||
| execute(axios: AxiosInstance): ResponsePromise<TOp>; | ||
| private buildAxiosConfig; | ||
| private makeAxiosHeaders; | ||
| private convertQueryToUrlSearchParams; | ||
| } | ||
| export default Request; |
| export {}; |
| export * from "./core/index.js"; | ||
| export * from "./types/index.js"; | ||
| export * from "./axios.js"; |
| import { OpenAPIOperation, RequestFunction } from "../types/index.js"; | ||
| import { GetApiResourceFn } from "./types.js"; | ||
| export declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> { | ||
| private static namespace; | ||
| private readonly operation; | ||
| private readonly requestFn; | ||
| constructor(operation: TOp, requestFn: RequestFunction<TOp>); | ||
| private getAsyncResourceId; | ||
| private getAsyncResourceTags; | ||
| private executeRequest; | ||
| getApiResource: GetApiResourceFn<TOp>; | ||
| } |
| export * from "./ApiCallAsyncResourceFactory.js"; |
| import { OpenAPIOperation, RequestObject, InferredResponseData } from "../types/index.js"; | ||
| import { AsyncResource } from "@mittwald/react-use-promise"; | ||
| export type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<InferredResponseData<TOp>>; |
| import { Response } from "./Response.js"; | ||
| export declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & { | ||
| status: S; | ||
| }; | ||
| export default assertStatus; |
| export {}; |
| export type HttpPayload = unknown; | ||
| export type HttpStatus = number | "default"; | ||
| export type HttpMediaType = string; | ||
| type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS"; | ||
| type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH"; | ||
| export type HttpMethod = SafeHttpMethod | UnsafeHttpMethod; | ||
| type HeaderValue = string | number | boolean; | ||
| export type HttpHeaders = Partial<{ | ||
| [TKey: string]: HeaderValue | HeaderValue[]; | ||
| }>; | ||
| export type PathParameters = Record<string, string | number>; | ||
| export type QueryParameters = Record<string, unknown>; | ||
| export {}; |
| export * from "./RequestType.js"; | ||
| export * from "./RequestFunction.js"; | ||
| export * from "./Response.js"; | ||
| export * from "./OpenAPIOperation.js"; | ||
| export * from "./http.js"; | ||
| export * from "./simplify.js"; | ||
| export * from "./assertStatus.js"; |
| import { HasRequiredKeys, OmitIndexSignature, PartialOnUndefinedDeep } from "type-fest"; | ||
| type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{ | ||
| [TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined; | ||
| }>>; | ||
| export type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null; | ||
| export {}; |
| import { AnyResponse, Response } from "./Response.js"; | ||
| import { AnyRequest, RequestType } from "./RequestType.js"; | ||
| import { HttpMethod, HttpStatus } from "./http.js"; | ||
| export interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> { | ||
| operationId: string; | ||
| path: string; | ||
| method: HttpMethod; | ||
| } | ||
| export type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never; | ||
| export type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never; | ||
| export type InferredResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, { | ||
| status: TStatus; | ||
| }>["data"]; | ||
| export type InferredRequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends { | ||
| data: infer TData; | ||
| } ? TData : never : never; | ||
| /** @deprecated Use InferredResponseData */ | ||
| export type ResponseData<TOp> = InferredResponseData<TOp>; | ||
| /** @deprecated Use InferredRequestData */ | ||
| export type RequestData<TOp> = InferredRequestData<TOp>; |
| import { InferredRequestType, InferredResponseType, OpenAPIOperation } from "./OpenAPIOperation.js"; | ||
| import { NullableOnNoRequiredKeysDeep } from "./NullableOnNoRequiredKeysDeep.js"; | ||
| type UnboxPathParameters<T> = T extends { | ||
| pathParameters: infer TPath; | ||
| } ? Omit<T, "pathParameters"> & TPath : T; | ||
| export type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>; | ||
| export type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>; | ||
| type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>; | ||
| type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>; | ||
| export type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>; | ||
| export {}; |
| export {}; |
| import { HttpHeaders, HttpPayload, PathParameters, QueryParameters } from "./http.js"; | ||
| type EmptyObject = Record<string, never>; | ||
| type EmptyRequestComponent = EmptyObject | null; | ||
| type RequestWithOptionalHeaders = { | ||
| headers?: HttpHeaders; | ||
| }; | ||
| type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| data: TData; | ||
| }; | ||
| type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| pathParameters: TPathParameters; | ||
| }; | ||
| type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| headers: THeaders & HttpHeaders; | ||
| }; | ||
| type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| queryParameters: TQuery & HttpHeaders; | ||
| }; | ||
| export type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>; | ||
| export type AnyRequest = RequestType<any, any, any, any>; | ||
| export {}; |
| export {}; |
| import { HttpMediaType, HttpPayload, HttpStatus } from "./http.js"; | ||
| import { AxiosResponse } from "axios"; | ||
| export type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & { | ||
| status: TStatus; | ||
| mediaType: TMediaType; | ||
| }; | ||
| export type AnyResponse = Response<any, any, any>; |
| export {}; |
| export type Simplify<T> = { | ||
| [KeyType in keyof T]: T[KeyType]; | ||
| } & {}; |
+21
| MIT License | ||
| Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+52
-45
| { | ||
| "name": "@mittwald/api-client-commons", | ||
| "version": "4.2.0-alpha.10", | ||
| "version": "4.2.1-alpha.0", | ||
| "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>", | ||
| "type": "module", | ||
| "description": "Common types and utilities for mittwald API clients", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "api", | ||
| "client", | ||
| "mittwald", | ||
| "rest", | ||
| "sdk" | ||
| ], | ||
| "homepage": "https://developer.mittwald.de", | ||
| "repository": "https://github.com/mittwald/api-client-js.git", | ||
| "author": { | ||
| "name": "Mittwald CM Service GmbH & Co. KG", | ||
| "email": "opensource@mittwald.de" | ||
| }, | ||
| "homepage": "https://developer.mittwald.de", | ||
| "bugs": "https://github.com/mittwald/api-client-js/issues", | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/index.cjs", | ||
| "import": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| "types": "./dist/types/index.d.ts", | ||
| "default": "./dist/esm/index.js" | ||
| }, | ||
| "./react": { | ||
| "require": "./dist/react.cjs", | ||
| "import": "./dist/react.js", | ||
| "types": "./dist/react.d.ts" | ||
| "types": "./dist/types/react/index.d.ts", | ||
| "default": "./dist/esm/react/index.js" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "compile": "tsup src/index.ts src/react.ts --format esm,cjs --dts --clean", | ||
| "build": "run build:clean && run tsc", | ||
| "build:clean": "run rimraf dist", | ||
| "format": "run prettier --write '**/*.{ts,tsx,yaml,yml,json,md,mdx,js}'", | ||
| "lint": "run eslint .", | ||
| "test": "node --experimental-vm-modules $(yarn bin jest)" | ||
| }, | ||
| "files": [ | ||
| "dist/**/*.*" | ||
| ], | ||
| "keywords": [ | ||
| "mittwald", | ||
| "api", | ||
| "client", | ||
| "sdk", | ||
| "rest" | ||
| ], | ||
| "peerDependencies": { | ||
| "@mittwald/react-use-promise": "^1.3.6" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@mittwald/react-use-promise": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@types/parse-path": "^7.0.2", | ||
| "axios": "^1.6.0", | ||
| "@types/parse-path": "^7.0.3", | ||
| "axios": "^1.6.7", | ||
| "parse-path": "^7.0.0", | ||
| "path-to-regexp": "^6.2.1", | ||
| "type-fest": "^4.6.0" | ||
| "type-fest": "^4.10.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@jest/globals": "^29.7.0", | ||
| "@mittwald/react-use-promise": "^2.0.1", | ||
| "@types/jest": "^29.5.7", | ||
| "@mittwald/react-use-promise": "^2.3.12", | ||
| "@types/jest": "^29.5.12", | ||
| "@typescript-eslint/eslint-plugin": "^7.0.2", | ||
| "@typescript-eslint/parser": "^7.0.2", | ||
| "eslint": "^8.56.0", | ||
| "eslint-config-prettier": "^9.1.0", | ||
| "eslint-plugin-json": "^3.1.0", | ||
| "eslint-plugin-prettier": "^5.1.3", | ||
| "jest": "^29.7.0", | ||
| "prettier": "^3.2.5", | ||
| "prettier-plugin-jsdoc": "^1.3.0", | ||
| "prettier-plugin-pkgsort": "^0.2.1", | ||
| "prettier-plugin-sort-json": "^3.1.0", | ||
| "react": "^18.2.0", | ||
| "ts-jest": "^29.1.1", | ||
| "tsup": "^7.2.0", | ||
| "typescript": "^5.2.2" | ||
| "rimraf": "^5.0.5", | ||
| "ts-jest": "^29.1.2", | ||
| "tsd": "^0.30.6", | ||
| "typescript": "^5.3.3" | ||
| }, | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| "peerDependencies": { | ||
| "@mittwald/react-use-promise": "^2.1.0" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@mittwald/react-use-promise": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "gitHead": "6af0f63d14186cf75a69b2a87227b1cfc1f84379" | ||
| } |
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
| // src/core/OpenAPIPath.ts | ||
| var OpenAPIPath = class _OpenAPIPath { | ||
| constructor(rawPath, params) { | ||
| this.rawPath = rawPath; | ||
| this.params = params; | ||
| } | ||
| buildUrl() { | ||
| return _OpenAPIPath.setPathParams(this.rawPath, this.params); | ||
| } | ||
| static setPathParams(path, params) { | ||
| const asEntries = Object.entries(params ?? {}); | ||
| const finalPath = asEntries.reduce((path2, entry) => { | ||
| const [key, value] = entry; | ||
| return path2.replace(`{${key}}`, encodeURIComponent(value)); | ||
| }, path); | ||
| return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath; | ||
| } | ||
| }; | ||
| var OpenAPIPath_default = OpenAPIPath; | ||
| // src/core/Request.ts | ||
| var Request = class { | ||
| constructor(operationDescriptor, requestObject) { | ||
| this.operationDescriptor = operationDescriptor; | ||
| this.requestObject = requestObject; | ||
| this.requestConfig = Object.freeze(this.buildAxiosConfig()); | ||
| } | ||
| execute(axios) { | ||
| return axios.request(this.requestConfig); | ||
| } | ||
| buildAxiosConfig() { | ||
| const { method, path } = this.operationDescriptor; | ||
| const pathParameters = this.requestObject; | ||
| const openApiPath = new OpenAPIPath_default(path, pathParameters); | ||
| const url = openApiPath.buildUrl(); | ||
| const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0; | ||
| const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0; | ||
| const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0; | ||
| const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0; | ||
| const params = this.convertQueryToUrlSearchParams(queryParametersConfig); | ||
| return { | ||
| url, | ||
| method, | ||
| headers, | ||
| // Must be a plain object or an URLSearchParams object | ||
| params, | ||
| data, | ||
| validateStatus: () => true | ||
| }; | ||
| } | ||
| makeAxiosHeaders(headers) { | ||
| return Object.fromEntries( | ||
| Object.entries(headers).map(([key, value]) => [key, value?.toString()]) | ||
| ); | ||
| } | ||
| convertQueryToUrlSearchParams(query) { | ||
| if (query === void 0 || query === null) { | ||
| return void 0; | ||
| } | ||
| if (query instanceof URLSearchParams) { | ||
| return query; | ||
| } | ||
| if (typeof query === "string") { | ||
| return new URLSearchParams(query); | ||
| } | ||
| if (typeof query === "object") { | ||
| const searchParams = new URLSearchParams(); | ||
| for (const [key, value] of Object.entries(query)) { | ||
| if (Array.isArray(value)) { | ||
| for (const arrayItem of value) { | ||
| searchParams.append(key, arrayItem); | ||
| } | ||
| } else { | ||
| searchParams.append( | ||
| key, | ||
| typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value) | ||
| ); | ||
| } | ||
| } | ||
| return searchParams; | ||
| } | ||
| throw new Error(`Unexpected query parameter type (${typeof query})`); | ||
| } | ||
| }; | ||
| var Request_default = Request; | ||
| // src/core/ApiClientError.ts | ||
| import { AxiosError } from "axios"; | ||
| var ApiClientError = class _ApiClientError extends AxiosError { | ||
| constructor(message, code, config, request, response) { | ||
| super(message, code, config, request, response); | ||
| Object.setPrototypeOf(this, _ApiClientError.prototype); | ||
| this.name = "ApiClientError"; | ||
| } | ||
| static fromResponse(message, response) { | ||
| return new _ApiClientError( | ||
| message, | ||
| void 0, | ||
| response.config, | ||
| response.request, | ||
| response | ||
| ); | ||
| } | ||
| }; | ||
| var ApiClientError_default = ApiClientError; | ||
| // src/types/assertStatus.ts | ||
| function assertStatus(response, expectedStatus) { | ||
| if (response.status !== expectedStatus) { | ||
| throw ApiClientError_default.fromResponse( | ||
| `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, | ||
| response | ||
| ); | ||
| } | ||
| } | ||
| // src/types/assertOneOfStatus.ts | ||
| function assertOneOfStatus(response, expectedStatus) { | ||
| if (!expectedStatus.includes(response.status)) { | ||
| throw ApiClientError_default.fromResponse( | ||
| `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, | ||
| response | ||
| ); | ||
| } | ||
| } | ||
| export { | ||
| __export, | ||
| __reExport, | ||
| OpenAPIPath, | ||
| Request, | ||
| Request_default, | ||
| ApiClientError, | ||
| assertStatus, | ||
| assertOneOfStatus | ||
| }; |
-196
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| ApiClientBase: () => ApiClientBase, | ||
| ApiClientError: () => ApiClientError, | ||
| OpenAPIPath: () => OpenAPIPath, | ||
| Request: () => Request, | ||
| assertOneOfStatus: () => assertOneOfStatus, | ||
| assertStatus: () => assertStatus | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| // src/core/ApiClientBase.ts | ||
| var import_axios = __toESM(require("axios"), 1); | ||
| // src/core/OpenAPIPath.ts | ||
| var OpenAPIPath = class _OpenAPIPath { | ||
| constructor(rawPath, params) { | ||
| this.rawPath = rawPath; | ||
| this.params = params; | ||
| } | ||
| buildUrl() { | ||
| return _OpenAPIPath.setPathParams(this.rawPath, this.params); | ||
| } | ||
| static setPathParams(path, params) { | ||
| const asEntries = Object.entries(params ?? {}); | ||
| const finalPath = asEntries.reduce((path2, entry) => { | ||
| const [key, value] = entry; | ||
| return path2.replace(`{${key}}`, encodeURIComponent(value)); | ||
| }, path); | ||
| return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath; | ||
| } | ||
| }; | ||
| var OpenAPIPath_default = OpenAPIPath; | ||
| // src/core/Request.ts | ||
| var Request = class { | ||
| constructor(operationDescriptor, requestObject) { | ||
| this.operationDescriptor = operationDescriptor; | ||
| this.requestObject = requestObject; | ||
| this.requestConfig = Object.freeze(this.buildAxiosConfig()); | ||
| } | ||
| execute(axios2) { | ||
| return axios2.request(this.requestConfig); | ||
| } | ||
| buildAxiosConfig() { | ||
| const { method, path } = this.operationDescriptor; | ||
| const pathParameters = this.requestObject; | ||
| const openApiPath = new OpenAPIPath_default(path, pathParameters); | ||
| const url = openApiPath.buildUrl(); | ||
| const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0; | ||
| const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0; | ||
| const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0; | ||
| const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0; | ||
| const params = this.convertQueryToUrlSearchParams(queryParametersConfig); | ||
| return { | ||
| url, | ||
| method, | ||
| headers, | ||
| // Must be a plain object or an URLSearchParams object | ||
| params, | ||
| data, | ||
| validateStatus: () => true | ||
| }; | ||
| } | ||
| makeAxiosHeaders(headers) { | ||
| return Object.fromEntries( | ||
| Object.entries(headers).map(([key, value]) => [key, value?.toString()]) | ||
| ); | ||
| } | ||
| convertQueryToUrlSearchParams(query) { | ||
| if (query === void 0 || query === null) { | ||
| return void 0; | ||
| } | ||
| if (query instanceof URLSearchParams) { | ||
| return query; | ||
| } | ||
| if (typeof query === "string") { | ||
| return new URLSearchParams(query); | ||
| } | ||
| if (typeof query === "object") { | ||
| const searchParams = new URLSearchParams(); | ||
| for (const [key, value] of Object.entries(query)) { | ||
| if (Array.isArray(value)) { | ||
| for (const arrayItem of value) { | ||
| searchParams.append(key, arrayItem); | ||
| } | ||
| } else { | ||
| searchParams.append( | ||
| key, | ||
| typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value) | ||
| ); | ||
| } | ||
| } | ||
| return searchParams; | ||
| } | ||
| throw new Error(`Unexpected query parameter type (${typeof query})`); | ||
| } | ||
| }; | ||
| var Request_default = Request; | ||
| // src/core/ApiClientBase.ts | ||
| var ApiClientBase = class { | ||
| constructor(axiosConfig = import_axios.default) { | ||
| this.axios = axiosConfig instanceof import_axios.Axios ? axiosConfig : import_axios.default.create(axiosConfig); | ||
| } | ||
| requestFunctionFactory(operation) { | ||
| return (conf) => new Request_default(operation, conf).execute(this.axios); | ||
| } | ||
| }; | ||
| // src/core/ApiClientError.ts | ||
| var import_axios2 = require("axios"); | ||
| var ApiClientError = class _ApiClientError extends import_axios2.AxiosError { | ||
| constructor(message, code, config, request, response) { | ||
| super(message, code, config, request, response); | ||
| Object.setPrototypeOf(this, _ApiClientError.prototype); | ||
| this.name = "ApiClientError"; | ||
| } | ||
| static fromResponse(message, response) { | ||
| return new _ApiClientError( | ||
| message, | ||
| void 0, | ||
| response.config, | ||
| response.request, | ||
| response | ||
| ); | ||
| } | ||
| }; | ||
| var ApiClientError_default = ApiClientError; | ||
| // src/types/assertStatus.ts | ||
| function assertStatus(response, expectedStatus) { | ||
| if (response.status !== expectedStatus) { | ||
| throw ApiClientError_default.fromResponse( | ||
| `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, | ||
| response | ||
| ); | ||
| } | ||
| } | ||
| // src/types/assertOneOfStatus.ts | ||
| function assertOneOfStatus(response, expectedStatus) { | ||
| if (!expectedStatus.includes(response.status)) { | ||
| throw ApiClientError_default.fromResponse( | ||
| `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, | ||
| response | ||
| ); | ||
| } | ||
| } | ||
| // src/axios.ts | ||
| var axios_exports = {}; | ||
| __reExport(axios_exports, require("axios")); | ||
| // src/index.ts | ||
| __reExport(src_exports, axios_exports, module.exports); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| ApiClientBase, | ||
| ApiClientError, | ||
| OpenAPIPath, | ||
| Request, | ||
| assertOneOfStatus, | ||
| assertStatus | ||
| }); |
| import { AxiosInstance, CreateAxiosDefaults, AxiosError, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios'; | ||
| export * from 'axios'; | ||
| import { R as Response, O as OpenAPIOperation, a as RequestFunction, A as AnyResponse, P as PathParameters, b as RequestObject, c as ResponsePromise } from './RequestFunction-b1412636.js'; | ||
| export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './RequestFunction-b1412636.js'; | ||
| import 'type-fest'; | ||
| type Simplify<T> = { | ||
| [KeyType in keyof T]: T[KeyType]; | ||
| } & {}; | ||
| declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & { | ||
| status: S; | ||
| }; | ||
| declare function assertOneOfStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S[]): asserts response is T & { | ||
| status: S; | ||
| }; | ||
| declare abstract class ApiClientBase { | ||
| axios: AxiosInstance; | ||
| constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults); | ||
| protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>; | ||
| } | ||
| declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> { | ||
| constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>); | ||
| static fromResponse(message: string, response: AnyResponse): ApiClientError; | ||
| } | ||
| declare class OpenAPIPath { | ||
| private readonly rawPath; | ||
| private readonly params?; | ||
| constructor(rawPath: string, params?: PathParameters); | ||
| buildUrl(): string; | ||
| private static setPathParams; | ||
| } | ||
| declare class Request<TOp extends OpenAPIOperation> { | ||
| private readonly operationDescriptor; | ||
| private readonly requestObject?; | ||
| readonly requestConfig: AxiosRequestConfig; | ||
| constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>); | ||
| execute(axios: AxiosInstance): ResponsePromise<TOp>; | ||
| private buildAxiosConfig; | ||
| private makeAxiosHeaders; | ||
| private convertQueryToUrlSearchParams; | ||
| } | ||
| export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, Simplify, assertOneOfStatus, assertStatus }; |
| import { AxiosInstance, CreateAxiosDefaults, AxiosError, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios'; | ||
| export * from 'axios'; | ||
| import { R as Response, O as OpenAPIOperation, a as RequestFunction, A as AnyResponse, P as PathParameters, b as RequestObject, c as ResponsePromise } from './RequestFunction-b1412636.js'; | ||
| export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './RequestFunction-b1412636.js'; | ||
| import 'type-fest'; | ||
| type Simplify<T> = { | ||
| [KeyType in keyof T]: T[KeyType]; | ||
| } & {}; | ||
| declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & { | ||
| status: S; | ||
| }; | ||
| declare function assertOneOfStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S[]): asserts response is T & { | ||
| status: S; | ||
| }; | ||
| declare abstract class ApiClientBase { | ||
| axios: AxiosInstance; | ||
| constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults); | ||
| protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>; | ||
| } | ||
| declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> { | ||
| constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>); | ||
| static fromResponse(message: string, response: AnyResponse): ApiClientError; | ||
| } | ||
| declare class OpenAPIPath { | ||
| private readonly rawPath; | ||
| private readonly params?; | ||
| constructor(rawPath: string, params?: PathParameters); | ||
| buildUrl(): string; | ||
| private static setPathParams; | ||
| } | ||
| declare class Request<TOp extends OpenAPIOperation> { | ||
| private readonly operationDescriptor; | ||
| private readonly requestObject?; | ||
| readonly requestConfig: AxiosRequestConfig; | ||
| constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>); | ||
| execute(axios: AxiosInstance): ResponsePromise<TOp>; | ||
| private buildAxiosConfig; | ||
| private makeAxiosHeaders; | ||
| private convertQueryToUrlSearchParams; | ||
| } | ||
| export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, Simplify, assertOneOfStatus, assertStatus }; |
| import { | ||
| ApiClientError, | ||
| OpenAPIPath, | ||
| Request, | ||
| Request_default, | ||
| __export, | ||
| __reExport, | ||
| assertOneOfStatus, | ||
| assertStatus | ||
| } from "./chunk-PEYA5TMK.js"; | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| ApiClientBase: () => ApiClientBase, | ||
| ApiClientError: () => ApiClientError, | ||
| OpenAPIPath: () => OpenAPIPath, | ||
| Request: () => Request, | ||
| assertOneOfStatus: () => assertOneOfStatus, | ||
| assertStatus: () => assertStatus | ||
| }); | ||
| // src/core/ApiClientBase.ts | ||
| import axios, { Axios } from "axios"; | ||
| var ApiClientBase = class { | ||
| constructor(axiosConfig = axios) { | ||
| this.axios = axiosConfig instanceof Axios ? axiosConfig : axios.create(axiosConfig); | ||
| } | ||
| requestFunctionFactory(operation) { | ||
| return (conf) => new Request_default(operation, conf).execute(this.axios); | ||
| } | ||
| }; | ||
| // src/axios.ts | ||
| var axios_exports = {}; | ||
| __reExport(axios_exports, axios_star); | ||
| import * as axios_star from "axios"; | ||
| // src/index.ts | ||
| __reExport(src_exports, axios_exports); | ||
| export { | ||
| ApiClientBase, | ||
| ApiClientError, | ||
| OpenAPIPath, | ||
| Request, | ||
| assertOneOfStatus, | ||
| assertStatus | ||
| }; |
-185
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/react.ts | ||
| var react_exports = {}; | ||
| __export(react_exports, { | ||
| ApiCallAsyncResourceFactory: () => ApiCallAsyncResourceFactory | ||
| }); | ||
| module.exports = __toCommonJS(react_exports); | ||
| // src/react/ApiCallAsyncResourceFactory.ts | ||
| var import_react_use_promise = require("@mittwald/react-use-promise"); | ||
| // src/core/ApiClientError.ts | ||
| var import_axios = require("axios"); | ||
| var ApiClientError = class _ApiClientError extends import_axios.AxiosError { | ||
| constructor(message, code, config, request, response) { | ||
| super(message, code, config, request, response); | ||
| Object.setPrototypeOf(this, _ApiClientError.prototype); | ||
| this.name = "ApiClientError"; | ||
| } | ||
| static fromResponse(message, response) { | ||
| return new _ApiClientError( | ||
| message, | ||
| void 0, | ||
| response.config, | ||
| response.request, | ||
| response | ||
| ); | ||
| } | ||
| }; | ||
| var ApiClientError_default = ApiClientError; | ||
| // src/types/assertStatus.ts | ||
| function assertStatus(response, expectedStatus) { | ||
| if (response.status !== expectedStatus) { | ||
| throw ApiClientError_default.fromResponse( | ||
| `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, | ||
| response | ||
| ); | ||
| } | ||
| } | ||
| // src/core/OpenAPIPath.ts | ||
| var OpenAPIPath = class _OpenAPIPath { | ||
| constructor(rawPath, params) { | ||
| this.rawPath = rawPath; | ||
| this.params = params; | ||
| } | ||
| buildUrl() { | ||
| return _OpenAPIPath.setPathParams(this.rawPath, this.params); | ||
| } | ||
| static setPathParams(path, params) { | ||
| const asEntries = Object.entries(params ?? {}); | ||
| const finalPath = asEntries.reduce((path2, entry) => { | ||
| const [key, value] = entry; | ||
| return path2.replace(`{${key}}`, encodeURIComponent(value)); | ||
| }, path); | ||
| return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath; | ||
| } | ||
| }; | ||
| var OpenAPIPath_default = OpenAPIPath; | ||
| // src/core/Request.ts | ||
| var Request = class { | ||
| constructor(operationDescriptor, requestObject) { | ||
| this.operationDescriptor = operationDescriptor; | ||
| this.requestObject = requestObject; | ||
| this.requestConfig = Object.freeze(this.buildAxiosConfig()); | ||
| } | ||
| execute(axios) { | ||
| return axios.request(this.requestConfig); | ||
| } | ||
| buildAxiosConfig() { | ||
| const { method, path } = this.operationDescriptor; | ||
| const pathParameters = this.requestObject; | ||
| const openApiPath = new OpenAPIPath_default(path, pathParameters); | ||
| const url = openApiPath.buildUrl(); | ||
| const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0; | ||
| const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0; | ||
| const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0; | ||
| const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0; | ||
| const params = this.convertQueryToUrlSearchParams(queryParametersConfig); | ||
| return { | ||
| url, | ||
| method, | ||
| headers, | ||
| // Must be a plain object or an URLSearchParams object | ||
| params, | ||
| data, | ||
| validateStatus: () => true | ||
| }; | ||
| } | ||
| makeAxiosHeaders(headers) { | ||
| return Object.fromEntries( | ||
| Object.entries(headers).map(([key, value]) => [key, value?.toString()]) | ||
| ); | ||
| } | ||
| convertQueryToUrlSearchParams(query) { | ||
| if (query === void 0 || query === null) { | ||
| return void 0; | ||
| } | ||
| if (query instanceof URLSearchParams) { | ||
| return query; | ||
| } | ||
| if (typeof query === "string") { | ||
| return new URLSearchParams(query); | ||
| } | ||
| if (typeof query === "object") { | ||
| const searchParams = new URLSearchParams(); | ||
| for (const [key, value] of Object.entries(query)) { | ||
| if (Array.isArray(value)) { | ||
| for (const arrayItem of value) { | ||
| searchParams.append(key, arrayItem); | ||
| } | ||
| } else { | ||
| searchParams.append( | ||
| key, | ||
| typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value) | ||
| ); | ||
| } | ||
| } | ||
| return searchParams; | ||
| } | ||
| throw new Error(`Unexpected query parameter type (${typeof query})`); | ||
| } | ||
| }; | ||
| var Request_default = Request; | ||
| // src/react/ApiCallAsyncResourceFactory.ts | ||
| var _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory { | ||
| constructor(operation, requestFn) { | ||
| this.getApiResource = (requestObj) => { | ||
| const request = new Request_default(this.operation, requestObj); | ||
| return (0, import_react_use_promise.getAsyncResource)( | ||
| (requestObj2) => this.executeRequest(requestObj2), | ||
| [requestObj], | ||
| { | ||
| tags: this.getAsyncResourceTags(request), | ||
| loaderId: this.getAsyncResourceId() | ||
| } | ||
| ); | ||
| }; | ||
| this.operation = operation; | ||
| this.requestFn = requestFn; | ||
| } | ||
| getAsyncResourceId() { | ||
| return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`; | ||
| } | ||
| getAsyncResourceTags(request) { | ||
| const url = request.requestConfig.url ?? ""; | ||
| return [ | ||
| this.getAsyncResourceId(), | ||
| `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`, | ||
| `${_ApiCallAsyncResourceFactory.namespace}/${url}` | ||
| ]; | ||
| } | ||
| async executeRequest(requestObj) { | ||
| const response = await this.requestFn(requestObj); | ||
| assertStatus(response, 200); | ||
| return response.data; | ||
| } | ||
| }; | ||
| _ApiCallAsyncResourceFactory.namespace = "@mittwald/api-client"; | ||
| var ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| ApiCallAsyncResourceFactory | ||
| }); |
| import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from './RequestFunction-b1412636.js'; | ||
| import { AsyncResource } from '@mittwald/react-use-promise'; | ||
| import 'axios'; | ||
| import 'type-fest'; | ||
| type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>>; | ||
| declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> { | ||
| private static namespace; | ||
| private readonly operation; | ||
| private readonly requestFn; | ||
| constructor(operation: TOp, requestFn: RequestFunction<TOp>); | ||
| private getAsyncResourceId; | ||
| private getAsyncResourceTags; | ||
| private executeRequest; | ||
| getApiResource: GetApiResourceFn<TOp>; | ||
| } | ||
| export { ApiCallAsyncResourceFactory, GetApiResourceFn }; |
| import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from './RequestFunction-b1412636.js'; | ||
| import { AsyncResource } from '@mittwald/react-use-promise'; | ||
| import 'axios'; | ||
| import 'type-fest'; | ||
| type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>>; | ||
| declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> { | ||
| private static namespace; | ||
| private readonly operation; | ||
| private readonly requestFn; | ||
| constructor(operation: TOp, requestFn: RequestFunction<TOp>); | ||
| private getAsyncResourceId; | ||
| private getAsyncResourceTags; | ||
| private executeRequest; | ||
| getApiResource: GetApiResourceFn<TOp>; | ||
| } | ||
| export { ApiCallAsyncResourceFactory, GetApiResourceFn }; |
| import { | ||
| Request_default, | ||
| assertStatus | ||
| } from "./chunk-PEYA5TMK.js"; | ||
| // src/react/ApiCallAsyncResourceFactory.ts | ||
| import { getAsyncResource } from "@mittwald/react-use-promise"; | ||
| var _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory { | ||
| constructor(operation, requestFn) { | ||
| this.getApiResource = (requestObj) => { | ||
| const request = new Request_default(this.operation, requestObj); | ||
| return getAsyncResource( | ||
| (requestObj2) => this.executeRequest(requestObj2), | ||
| [requestObj], | ||
| { | ||
| tags: this.getAsyncResourceTags(request), | ||
| loaderId: this.getAsyncResourceId() | ||
| } | ||
| ); | ||
| }; | ||
| this.operation = operation; | ||
| this.requestFn = requestFn; | ||
| } | ||
| getAsyncResourceId() { | ||
| return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`; | ||
| } | ||
| getAsyncResourceTags(request) { | ||
| const url = request.requestConfig.url ?? ""; | ||
| return [ | ||
| this.getAsyncResourceId(), | ||
| `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`, | ||
| `${_ApiCallAsyncResourceFactory.namespace}/${url}` | ||
| ]; | ||
| } | ||
| async executeRequest(requestObj) { | ||
| const response = await this.requestFn(requestObj); | ||
| assertStatus(response, 200); | ||
| return response.data; | ||
| } | ||
| }; | ||
| _ApiCallAsyncResourceFactory.namespace = "@mittwald/api-client"; | ||
| var ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory; | ||
| export { | ||
| ApiCallAsyncResourceFactory | ||
| }; |
| import { AxiosResponse } from 'axios'; | ||
| import { HasRequiredKeys, PartialOnUndefinedDeep, OmitIndexSignature } from 'type-fest'; | ||
| type HttpPayload = unknown; | ||
| type HttpStatus = number | "default"; | ||
| type HttpMediaType = string; | ||
| type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS"; | ||
| type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH"; | ||
| type HttpMethod = SafeHttpMethod | UnsafeHttpMethod; | ||
| type HeaderValue = string | number | boolean; | ||
| type HttpHeaders = Partial<{ | ||
| [TKey: string]: HeaderValue | HeaderValue[]; | ||
| }>; | ||
| type PathParameters = Record<string, string | number>; | ||
| type QueryParameters = Record<string, unknown>; | ||
| type EmptyObject = Record<string, never>; | ||
| type EmptyRequestComponent = EmptyObject | null; | ||
| type RequestWithOptionalHeaders = { | ||
| headers?: HttpHeaders; | ||
| }; | ||
| type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| data: TData; | ||
| }; | ||
| type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| pathParameters: TPathParameters; | ||
| }; | ||
| type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| headers: THeaders & HttpHeaders; | ||
| }; | ||
| type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : { | ||
| queryParameters: TQuery & HttpHeaders; | ||
| }; | ||
| type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>; | ||
| type AnyRequest = RequestType<any, any, any, any>; | ||
| type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & { | ||
| status: TStatus; | ||
| mediaType: TMediaType; | ||
| }; | ||
| type AnyResponse = Response<any, any, any>; | ||
| interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> { | ||
| operationId: string; | ||
| path: string; | ||
| method: HttpMethod; | ||
| } | ||
| type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never; | ||
| type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never; | ||
| type ResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, { | ||
| status: TStatus; | ||
| }>["data"]; | ||
| type RequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends { | ||
| data: infer TData; | ||
| } ? TData : never : never; | ||
| type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{ | ||
| [TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined; | ||
| }>>; | ||
| type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null; | ||
| type UnboxPathParameters<T> = T extends { | ||
| pathParameters: infer TPath; | ||
| } ? Omit<T, "pathParameters"> & TPath : T; | ||
| type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>; | ||
| type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>; | ||
| type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>; | ||
| type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>; | ||
| type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>; | ||
| export { AnyResponse as A, HttpPayload as H, InferredRequestType as I, OpenAPIOperation as O, PathParameters as P, QueryParameters as Q, Response as R, RequestFunction as a, RequestObject as b, ResponsePromise as c, RequestType as d, AnyRequest as e, InferredResponseType as f, ResponseData as g, RequestData as h, HttpStatus as i, HttpMediaType as j, HttpMethod as k, HttpHeaders as l }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
55
358.33%739
2.07%29559
-14.19%19
137.5%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated