@readyfor/api-client-base 1.78.0 → 1.80.0
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/dist/_virtual/_rolldown/runtime.js +1 -1
- package/dist/apiClientConfigStore.d.ts +6 -7
- package/dist/apiError.d.ts +9 -10
- package/dist/fetcher.d.ts +9 -10
- package/dist/fetcher.js +11 -5
- package/dist/react/ApiClientConfigProvider.d.ts +3 -4
- package/dist/react/swr.d.ts +3 -4
- package/dist/react/useApiClientConfig.d.ts +4 -5
- package/dist/requestUrl.d.ts +2 -3
- package/dist/store.d.ts +3 -4
- package/dist/types.d.ts +3 -4
- package/dist/utils/headersInit.d.ts +3 -4
- package/dist/utils/requestInit.d.ts +2 -3
- package/dist/zod.d.ts +3 -4
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
@@ -9,14 +9,13 @@ type DeserializeResponseConfig = {
|
|
|
9
9
|
type LoggingConfig = {
|
|
10
10
|
showsSchemaParseError?: boolean;
|
|
11
11
|
};
|
|
12
|
-
type RequestConfig = {
|
|
12
|
+
export type RequestConfig = {
|
|
13
13
|
hostName?: string | ((path: string) => string);
|
|
14
14
|
defaultRequestInit?: RequestInit;
|
|
15
15
|
onError?: (error: unknown) => void;
|
|
16
16
|
};
|
|
17
|
-
type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
|
|
18
|
-
declare const store: Store<Config>;
|
|
19
|
-
declare const setApiClientConfig: (config: Config) => void;
|
|
20
|
-
declare const buildRequestInitWithDefaultConfig: (customRequestInit?: RequestInit) => RequestInit;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store };
|
|
17
|
+
export type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
|
|
18
|
+
export declare const store: Store<Config>;
|
|
19
|
+
export declare const setApiClientConfig: (config: Config) => void;
|
|
20
|
+
export declare const buildRequestInitWithDefaultConfig: (customRequestInit?: RequestInit) => RequestInit;
|
|
21
|
+
//#endregion
|
package/dist/apiError.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/apiError.d.ts
|
|
2
|
-
type ErrorStatusCode = 301 | 302 | 400 | 401 | 403 | 404 | 409 | 413 | 418 | 422 | 500 | 502 | 503 | 504 | 540 | 901 | 999;
|
|
3
|
-
declare const errorStatusCode: {
|
|
2
|
+
export type ErrorStatusCode = 301 | 302 | 400 | 401 | 403 | 404 | 409 | 413 | 418 | 422 | 500 | 502 | 503 | 504 | 540 | 901 | 999;
|
|
3
|
+
export declare const errorStatusCode: {
|
|
4
4
|
readonly MOVED_PERMANENTLY: 301;
|
|
5
5
|
readonly FOUND: 302;
|
|
6
6
|
readonly BAD_REQUEST: 400;
|
|
@@ -19,8 +19,8 @@ declare const errorStatusCode: {
|
|
|
19
19
|
readonly ZOD_ERROR: 901;
|
|
20
20
|
readonly UNHANDLED_ERROR: 999;
|
|
21
21
|
};
|
|
22
|
-
declare const errorTitle: { [key in ErrorStatusCode]: string; };
|
|
23
|
-
declare class HTTPError extends Error {
|
|
22
|
+
export declare const errorTitle: { [key in ErrorStatusCode]: string; };
|
|
23
|
+
export declare class HTTPError extends Error {
|
|
24
24
|
status: ErrorStatusCode;
|
|
25
25
|
body?: unknown;
|
|
26
26
|
constructor(status: ErrorStatusCode);
|
|
@@ -32,9 +32,8 @@ declare class HTTPError extends Error {
|
|
|
32
32
|
* 別バージョンのクラスと一致しないケースがあるため、
|
|
33
33
|
* プロパティベースで判定する。
|
|
34
34
|
*/
|
|
35
|
-
declare const isHttpErrorWithStatus: (error: unknown, status: number) => boolean;
|
|
36
|
-
declare const getHttpErrorBody: (error: unknown) => unknown;
|
|
37
|
-
declare const getHttpErrorBodyReason: (body: unknown) => string | undefined;
|
|
38
|
-
declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus };
|
|
35
|
+
export declare const isHttpErrorWithStatus: (error: unknown, status: number) => boolean;
|
|
36
|
+
export declare const getHttpErrorBody: (error: unknown) => unknown;
|
|
37
|
+
export declare const getHttpErrorBodyReason: (body: unknown) => string | undefined;
|
|
38
|
+
export declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
|
|
39
|
+
//#endregion
|
package/dist/fetcher.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/fetcher.d.ts
|
|
3
|
-
type FetcherOptions = {
|
|
3
|
+
export type FetcherOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* フェッチャー本体が後段でボディを読むため、ここでボディを消費してはいけない。
|
|
6
6
|
*/
|
|
7
7
|
onResponse?: (res: Response) => void;
|
|
8
8
|
};
|
|
9
|
-
declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
|
|
10
|
-
declare const createTextFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
|
|
11
|
-
type BlobFetcherResponse = {
|
|
9
|
+
export declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
|
|
10
|
+
export declare const createTextFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
|
|
11
|
+
export type BlobFetcherResponse = {
|
|
12
12
|
body: Blob;
|
|
13
13
|
headers: Headers;
|
|
14
14
|
};
|
|
15
|
-
declare const createBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
|
|
16
|
-
type FileOrBlobFetcherResponse = {
|
|
15
|
+
export declare const createBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
|
|
16
|
+
export type FileOrBlobFetcherResponse = {
|
|
17
17
|
body: File | Blob;
|
|
18
18
|
headers: Headers;
|
|
19
19
|
};
|
|
20
|
-
declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
|
|
21
|
-
declare const createVoidFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
|
|
22
|
-
//#endregion
|
|
23
|
-
export { BlobFetcherResponse, FetcherOptions, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
|
|
20
|
+
export declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
|
|
21
|
+
export declare const createVoidFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
|
|
22
|
+
//#endregion
|
package/dist/fetcher.js
CHANGED
|
@@ -9,7 +9,8 @@ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (inp
|
|
|
9
9
|
const text = await res.text();
|
|
10
10
|
const body = text ? JSON.parse(text) : {};
|
|
11
11
|
if (res.ok) return body;
|
|
12
|
-
|
|
12
|
+
const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
13
|
+
throw new require_apiError.HTTPError(code, body);
|
|
13
14
|
}).catch((error) => {
|
|
14
15
|
require_apiClientConfigStore.store.getState().onError?.(error);
|
|
15
16
|
throw error;
|
|
@@ -28,7 +29,8 @@ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requ
|
|
|
28
29
|
options.onResponse?.(res);
|
|
29
30
|
const body = await res.text();
|
|
30
31
|
if (res.ok) return body;
|
|
31
|
-
|
|
32
|
+
const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
33
|
+
throw new require_apiError.HTTPError(code, body);
|
|
32
34
|
}).catch((error) => {
|
|
33
35
|
require_apiClientConfigStore.store.getState().onError?.(error);
|
|
34
36
|
throw error;
|
|
@@ -40,7 +42,8 @@ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requ
|
|
|
40
42
|
body,
|
|
41
43
|
headers: res.headers
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
46
|
+
throw new require_apiError.HTTPError(code, body);
|
|
44
47
|
}).catch((error) => {
|
|
45
48
|
require_apiClientConfigStore.store.getState().onError?.(error);
|
|
46
49
|
throw error;
|
|
@@ -52,7 +55,8 @@ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input
|
|
|
52
55
|
body,
|
|
53
56
|
headers: res.headers
|
|
54
57
|
};
|
|
55
|
-
|
|
58
|
+
const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
59
|
+
throw new require_apiError.HTTPError(code, body);
|
|
56
60
|
}).catch((error) => {
|
|
57
61
|
require_apiClientConfigStore.store.getState().onError?.(error);
|
|
58
62
|
throw error;
|
|
@@ -60,7 +64,9 @@ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input
|
|
|
60
64
|
const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
|
|
61
65
|
options.onResponse?.(res);
|
|
62
66
|
if (res.ok) return;
|
|
63
|
-
|
|
67
|
+
const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
|
|
68
|
+
const body = await res.text();
|
|
69
|
+
throw new require_apiError.HTTPError(code, body);
|
|
64
70
|
}).catch((error) => {
|
|
65
71
|
require_apiClientConfigStore.store.getState().onError?.(error);
|
|
66
72
|
throw error;
|
|
@@ -10,7 +10,6 @@ type Props = {
|
|
|
10
10
|
config: Configuration;
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
};
|
|
13
|
-
declare const ApiClientConfigProvider: FC<Props>;
|
|
14
|
-
declare const useApiClientConfigContext: () => Store<Config>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { ApiClientConfigProvider, useApiClientConfigContext };
|
|
13
|
+
export declare const ApiClientConfigProvider: FC<Props>;
|
|
14
|
+
export declare const useApiClientConfigContext: () => Store<Config>;
|
|
15
|
+
//#endregion
|
package/dist/react/swr.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SWRConfiguration } from "swr";
|
|
2
2
|
//#region src/react/swr.d.ts
|
|
3
|
-
type Configuration<T> = SWRConfiguration<T> & {
|
|
3
|
+
export type Configuration<T> = SWRConfiguration<T> & {
|
|
4
4
|
/**
|
|
5
5
|
* fetchを止めるかどうかのオプション
|
|
6
6
|
* trueの場合: useSWRの第一引数にnullが渡されます
|
|
@@ -8,6 +8,5 @@ type Configuration<T> = SWRConfiguration<T> & {
|
|
|
8
8
|
*/
|
|
9
9
|
shouldNotFetch?: boolean;
|
|
10
10
|
};
|
|
11
|
-
declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { Configuration, createSwrConfig };
|
|
11
|
+
export declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
|
|
12
|
+
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Config } from "../apiClientConfigStore.js";
|
|
2
2
|
//#region src/react/useApiClientConfig.d.ts
|
|
3
|
-
declare const useApiClientConfig: () => any;
|
|
4
|
-
declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
|
|
5
|
-
declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit };
|
|
3
|
+
export declare const useApiClientConfig: () => any;
|
|
4
|
+
export declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
|
|
5
|
+
export declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
|
|
6
|
+
//#endregion
|
package/dist/requestUrl.d.ts
CHANGED
|
@@ -5,6 +5,5 @@ type UrlArgs = {
|
|
|
5
5
|
path?: PathParams;
|
|
6
6
|
query?: QueryParams;
|
|
7
7
|
};
|
|
8
|
-
declare const __internal__requestUrl: (rawPath: string, { path: pathParams, query }?: UrlArgs) => string;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { __internal__requestUrl };
|
|
8
|
+
export declare const __internal__requestUrl: (rawPath: string, { path: pathParams, query }?: UrlArgs) => string;
|
|
9
|
+
//#endregion
|
package/dist/store.d.ts
CHANGED
|
@@ -4,11 +4,10 @@ type GetState<T> = () => T;
|
|
|
4
4
|
type SetState<T> = (fn: (state: T) => T) => void;
|
|
5
5
|
type Subscribe = (listener: Listener) => Unsubscribe;
|
|
6
6
|
type Unsubscribe = () => void;
|
|
7
|
-
type Store<T> = {
|
|
7
|
+
export type Store<T> = {
|
|
8
8
|
getState: GetState<T>;
|
|
9
9
|
setState: SetState<T>;
|
|
10
10
|
subscribe: Subscribe;
|
|
11
11
|
};
|
|
12
|
-
declare const createStore: <T>(initialState: T) => Store<T>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { Store, createStore };
|
|
12
|
+
export declare const createStore: <T>(initialState: T) => Store<T>;
|
|
13
|
+
//#endregion
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
-
type ForceDig<T, K extends string[]> = K extends [infer P extends string, ...infer Rest extends string[]] ? T extends { [key in P]?: infer S; } ? ForceDig<Exclude<S, undefined>, Rest> : Record<string, never> : T;
|
|
2
|
+
export type ForceDig<T, K extends string[]> = K extends [infer P extends string, ...infer Rest extends string[]] ? T extends { [key in P]?: infer S; } ? ForceDig<Exclude<S, undefined>, Rest> : Record<string, never> : T;
|
|
3
3
|
type RemoveBracket<T> = T extends `${infer S}[]` ? S : T;
|
|
4
|
-
type QueryPropsFor<T extends Record<string, unknown>> = { [K in keyof T as RemoveBracket<K>]: K extends `${string}[]` ? Exclude<T[K], undefined>[] : T[K]; };
|
|
5
|
-
//#endregion
|
|
6
|
-
export { ForceDig, QueryPropsFor };
|
|
4
|
+
export type QueryPropsFor<T extends Record<string, unknown>> = { [K in keyof T as RemoveBracket<K>]: K extends `${string}[]` ? Exclude<T[K], undefined>[] : T[K]; };
|
|
5
|
+
//#endregion
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @param baseHeadersInit 元となるHeadersInit
|
|
14
14
|
* @param overrideHeadersInit 上書きしたいヘッダーを含むHeadersInit。
|
|
15
15
|
*/
|
|
16
|
-
declare const mergeHeadersInit: (baseHeadersInit: HeadersInit, overrideHeadersInit: HeadersInit) => HeadersInit;
|
|
16
|
+
export declare const mergeHeadersInit: (baseHeadersInit: HeadersInit, overrideHeadersInit: HeadersInit) => HeadersInit;
|
|
17
17
|
/**
|
|
18
18
|
* OpenAPI から生成されたヘッダーオブジェクトを HeadersInit に変換する
|
|
19
19
|
*
|
|
@@ -24,6 +24,5 @@ declare const mergeHeadersInit: (baseHeadersInit: HeadersInit, overrideHeadersIn
|
|
|
24
24
|
* @param headers OpenAPI から生成されたヘッダーオブジェクト
|
|
25
25
|
* @returns HeadersInit として使用可能なオブジェクト
|
|
26
26
|
*/
|
|
27
|
-
declare const toHeadersInit: (headers: Record<string, string | number | boolean | undefined>) => HeadersInit;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { mergeHeadersInit, toHeadersInit };
|
|
27
|
+
export declare const toHeadersInit: (headers: Record<string, string | number | boolean | undefined>) => HeadersInit;
|
|
28
|
+
//#endregion
|
|
@@ -5,6 +5,5 @@
|
|
|
5
5
|
* ただし、`headers`フィールドに関しては、`base`と`override`両方に有効なHeadersInitがある場合に限り、
|
|
6
6
|
* `mergeHeadersInit`を使用してヘッダーの内容をマージする
|
|
7
7
|
*/
|
|
8
|
-
declare const mergeRequestInit: ({ headers: baseHeaders, ...base }: RequestInit, { headers: overrideHeaders, ...override }: RequestInit) => RequestInit;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { mergeRequestInit };
|
|
8
|
+
export declare const mergeRequestInit: ({ headers: baseHeaders, ...base }: RequestInit, { headers: overrideHeaders, ...override }: RequestInit) => RequestInit;
|
|
9
|
+
//#endregion
|
package/dist/zod.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/zod.d.ts
|
|
3
|
-
declare const schemaForType: <T>() => <S extends z.ZodType<T>>(arg: S) => S;
|
|
4
|
-
declare const isZodError: (obj: unknown) => obj is z.ZodError;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { isZodError, schemaForType };
|
|
3
|
+
export declare const schemaForType: <T>() => <S extends z.ZodType<T>>(arg: S) => S;
|
|
4
|
+
export declare const isZodError: (obj: unknown) => obj is z.ZodError;
|
|
5
|
+
//#endregion
|