@readyfor/api-client-base 1.155.0 → 1.155.1-pr1532.7d29327

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.
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,5 +19,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
- //#endregion
23
22
  exports.__toESM = __toESM;
@@ -1,4 +1,4 @@
1
- //#region src/store.ts
1
+ // src/store.ts
2
2
  const createStore = (initialState) => {
3
3
  let state = initialState;
4
4
  const listeners = /* @__PURE__ */ new Set();
@@ -17,8 +17,7 @@ const createStore = (initialState) => {
17
17
  subscribe
18
18
  };
19
19
  };
20
- //#endregion
21
- //#region src/utils/headersInit.ts
20
+ // src/utils/headersInit.ts
22
21
  /**
23
22
  * 二つのHeadersInitの情報を元に、新たなHeadersInitを作成する
24
23
  *
@@ -63,8 +62,7 @@ const toHeadersInit = (headers) => {
63
62
  for (const [key, value] of Object.entries(headers)) if (value !== void 0) result[key] = String(value);
64
63
  return result;
65
64
  };
66
- //#endregion
67
- //#region src/utils/requestInit.ts
65
+ // src/utils/requestInit.ts
68
66
  /**
69
67
  * 第一引数と第二引数のequestInitをマージした新たなRequestInitを返す。
70
68
  * 同じフィールドが存在する場合、第二引数の値で上書きされる。
@@ -79,8 +77,8 @@ const mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: override
79
77
  const store = globalThis[Symbol.for("@readyfor/api-client-base/config")] ??= createStore({});
80
78
  const setApiClientConfig = (config) => store.setState(() => config);
81
79
  const buildRequestInitWithDefaultConfig = (customRequestInit = {}) => {
82
- const { defaultRequestInit = {} } = store.getState();
83
- return mergeRequestInit(defaultRequestInit, customRequestInit);
80
+ const { defaultRequestInit } = store.getState();
81
+ if (typeof defaultRequestInit === "function") return customRequestInit;
82
+ return mergeRequestInit(defaultRequestInit ?? {}, customRequestInit);
84
83
  };
85
- //#endregion
86
84
  export { mergeHeadersInit as a, mergeRequestInit as i, setApiClientConfig as n, toHeadersInit as o, store as r, createStore as s, buildRequestInitWithDefaultConfig as t };
@@ -1,5 +1,4 @@
1
1
  import { Store } from "./store.js";
2
- //#region src/apiClientConfigStore.d.ts
3
2
  type DeserializeResponseConfig = {
4
3
  forceDeserializeResponse?: false;
5
4
  } | {
@@ -11,12 +10,17 @@ type LoggingConfig = {
11
10
  };
12
11
  export type RequestConfig = {
13
12
  hostName?: string | ((path: string) => string);
14
- defaultRequestInit?: RequestInit;
13
+ /**
14
+ * 関数を渡すと、設定時ではなく API 呼び出しごとに fetch の直前で評価される。リクエストごとに変わる値は設定時ではなくこの関数の中で読むこと。
15
+ * すべての宛先への fetch で呼ばれるため、転送してよい宛先かは必要に応じて `input` で判断すること。
16
+ * 受け取ったリクエストヘッダーを丸ごと返さず、必要なもの(Cookie や User-Agent など)だけを返すこと。host や connection などが混ざると fetch が失敗する。
17
+ * 同じフィールドや同名のヘッダーを API 呼び出し時の RequestInit で指定した場合は、そちらが優先される。
18
+ */
19
+ defaultRequestInit?: RequestInit | ((input: RequestInfo) => RequestInit | Promise<RequestInit>);
15
20
  onError?: (error: unknown) => void;
16
21
  };
17
22
  export type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
18
23
  export declare const store: Store<Config>;
19
24
  export declare const setApiClientConfig: (config: Config) => void;
20
25
  export declare const buildRequestInitWithDefaultConfig: (customRequestInit?: RequestInit) => RequestInit;
21
- //#endregion
22
26
  export {};
@@ -4,10 +4,10 @@ const require_utils_requestInit = require("./utils/requestInit.js");
4
4
  const store = globalThis[Symbol.for("@readyfor/api-client-base/config")] ??= require_store.createStore({});
5
5
  const setApiClientConfig = (config) => store.setState(() => config);
6
6
  const buildRequestInitWithDefaultConfig = (customRequestInit = {}) => {
7
- const { defaultRequestInit = {} } = store.getState();
8
- return require_utils_requestInit.mergeRequestInit(defaultRequestInit, customRequestInit);
7
+ const { defaultRequestInit } = store.getState();
8
+ if (typeof defaultRequestInit === "function") return customRequestInit;
9
+ return require_utils_requestInit.mergeRequestInit(defaultRequestInit ?? {}, customRequestInit);
9
10
  };
10
- //#endregion
11
11
  exports.buildRequestInitWithDefaultConfig = buildRequestInitWithDefaultConfig;
12
12
  exports.setApiClientConfig = setApiClientConfig;
13
13
  exports.store = store;
@@ -1,4 +1,3 @@
1
- //#region src/apiError.d.ts
2
1
  export type ErrorStatusCode = 301 | 302 | 400 | 401 | 403 | 404 | 409 | 413 | 418 | 422 | 500 | 502 | 503 | 504 | 540 | 901 | 999;
3
2
  export declare const errorStatusCode: {
4
3
  readonly MOVED_PERMANENTLY: 301;
@@ -35,5 +34,4 @@ export declare class HTTPError extends Error {
35
34
  export declare const isHttpErrorWithStatus: (error: unknown, status: number) => boolean;
36
35
  export declare const getHttpErrorBody: (error: unknown) => unknown;
37
36
  export declare const getHttpErrorBodyReason: (body: unknown) => string | undefined;
38
- export declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
39
- //#endregion
37
+ export declare const getErrorStatus: (response: unknown) => ErrorStatusCode | undefined;
package/dist/apiError.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_zod = require("./zod.js");
3
- //#region src/apiError.ts
3
+ // src/apiError.ts
4
4
  const errorStatusCode = {
5
5
  MOVED_PERMANENTLY: 301,
6
6
  FOUND: 302,
@@ -70,7 +70,6 @@ const getErrorStatus = (response) => {
70
70
  }
71
71
  if (require_zod.isZodError(response)) return errorStatusCode.ZOD_ERROR;
72
72
  };
73
- //#endregion
74
73
  exports.HTTPError = HTTPError;
75
74
  exports.errorStatusCode = errorStatusCode;
76
75
  exports.errorTitle = errorTitle;
package/dist/fetcher.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- //#region src/fetcher.d.ts
3
2
  export type FetcherOptions = {
4
3
  /**
5
4
  * フェッチャー本体が後段でボディを読むため、ここでボディを消費してはいけない。
@@ -18,5 +17,4 @@ export type FileOrBlobFetcherResponse = {
18
17
  headers: Headers;
19
18
  };
20
19
  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
20
+ export declare const createVoidFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
package/dist/fetcher.js CHANGED
@@ -2,9 +2,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_requestInit = require("./utils/requestInit.js");
3
3
  const require_apiClientConfigStore = require("./apiClientConfigStore.js");
4
4
  const require_apiError = require("./apiError.js");
5
- //#region src/fetcher.ts
5
+ // src/fetcher.ts
6
6
  const defaultRequestInit = { credentials: "include" };
7
- const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
7
+ const fetchWithDefaultRequestInit = (input, customRequestInit, requestInit) => {
8
+ const callerRequestInit = require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit);
9
+ const { defaultRequestInit: configDefaultRequestInit } = require_apiClientConfigStore.store.getState();
10
+ if (typeof configDefaultRequestInit !== "function") return fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, callerRequestInit));
11
+ return Promise.resolve().then(() => configDefaultRequestInit(input)).then((resolved) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(resolved, callerRequestInit))));
12
+ };
13
+ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
8
14
  options.onResponse?.(res);
9
15
  const text = await res.text();
10
16
  const body = text ? JSON.parse(text) : {};
@@ -25,7 +31,7 @@ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (inp
25
31
  }
26
32
  throw result.error;
27
33
  });
28
- const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
34
+ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
29
35
  options.onResponse?.(res);
30
36
  const body = await res.text();
31
37
  if (res.ok) return body;
@@ -35,7 +41,7 @@ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requ
35
41
  require_apiClientConfigStore.store.getState().onError?.(error);
36
42
  throw error;
37
43
  });
38
- const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
44
+ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
39
45
  options.onResponse?.(res);
40
46
  const body = await res.blob();
41
47
  if (res.ok) return {
@@ -48,7 +54,7 @@ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requ
48
54
  require_apiClientConfigStore.store.getState().onError?.(error);
49
55
  throw error;
50
56
  });
51
- const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
57
+ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
52
58
  options.onResponse?.(res);
53
59
  const body = await res.blob();
54
60
  if (res.ok) return {
@@ -61,7 +67,7 @@ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input
61
67
  require_apiClientConfigStore.store.getState().onError?.(error);
62
68
  throw error;
63
69
  });
64
- const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
70
+ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
65
71
  options.onResponse?.(res);
66
72
  if (res.ok) return;
67
73
  const code = Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
@@ -71,7 +77,6 @@ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requ
71
77
  require_apiClientConfigStore.store.getState().onError?.(error);
72
78
  throw error;
73
79
  });
74
- //#endregion
75
80
  exports.createBlobFetcher = createBlobFetcher;
76
81
  exports.createFileOrBlobFetcher = createFileOrBlobFetcher;
77
82
  exports.createJsonFetcher = createJsonFetcher;
package/dist/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
- import { a as mergeHeadersInit, i as mergeRequestInit, n as setApiClientConfig, o as toHeadersInit, r as store, s as createStore, t as buildRequestInitWithDefaultConfig } from "./apiClientConfigStore-DDleIkQN.mjs";
1
+ import { a as mergeHeadersInit, i as mergeRequestInit, n as setApiClientConfig, o as toHeadersInit, r as store, s as createStore, t as buildRequestInitWithDefaultConfig } from "./apiClientConfigStore-DbTqjD1_.mjs";
2
2
  import qs from "qs";
3
- //#region src/zod.ts
3
+ // src/zod.ts
4
4
  const schemaForType = () => (arg) => {
5
5
  return arg;
6
6
  };
7
7
  const isZodError = (obj) => obj !== null && typeof obj === "object" && obj.constructor.name === "ZodError";
8
- //#endregion
9
- //#region src/apiError.ts
8
+ // src/apiError.ts
10
9
  const errorStatusCode = {
11
10
  MOVED_PERMANENTLY: 301,
12
11
  FOUND: 302,
@@ -76,10 +75,15 @@ const getErrorStatus = (response) => {
76
75
  }
77
76
  if (isZodError(response)) return errorStatusCode.ZOD_ERROR;
78
77
  };
79
- //#endregion
80
- //#region src/fetcher.ts
78
+ // src/fetcher.ts
81
79
  const defaultRequestInit = { credentials: "include" };
82
- const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
80
+ const fetchWithDefaultRequestInit = (input, customRequestInit, requestInit) => {
81
+ const callerRequestInit = mergeRequestInit(customRequestInit, requestInit);
82
+ const { defaultRequestInit: configDefaultRequestInit } = store.getState();
83
+ if (typeof configDefaultRequestInit !== "function") return fetch(input, mergeRequestInit(defaultRequestInit, callerRequestInit));
84
+ return Promise.resolve().then(() => configDefaultRequestInit(input)).then((resolved) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(resolved, callerRequestInit))));
85
+ };
86
+ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
83
87
  options.onResponse?.(res);
84
88
  const text = await res.text();
85
89
  const body = text ? JSON.parse(text) : {};
@@ -99,7 +103,7 @@ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (inp
99
103
  }
100
104
  throw result.error;
101
105
  });
102
- const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
106
+ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
103
107
  options.onResponse?.(res);
104
108
  const body = await res.text();
105
109
  if (res.ok) return body;
@@ -108,7 +112,7 @@ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requ
108
112
  store.getState().onError?.(error);
109
113
  throw error;
110
114
  });
111
- const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
115
+ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
112
116
  options.onResponse?.(res);
113
117
  const body = await res.blob();
114
118
  if (res.ok) return {
@@ -120,7 +124,7 @@ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requ
120
124
  store.getState().onError?.(error);
121
125
  throw error;
122
126
  });
123
- const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
127
+ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
124
128
  options.onResponse?.(res);
125
129
  const body = await res.blob();
126
130
  if (res.ok) return {
@@ -132,7 +136,7 @@ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input
132
136
  store.getState().onError?.(error);
133
137
  throw error;
134
138
  });
135
- const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
139
+ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetchWithDefaultRequestInit(input, customRequestInit, requestInit).then(async (res) => {
136
140
  options.onResponse?.(res);
137
141
  if (res.ok) return;
138
142
  throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
@@ -140,12 +144,10 @@ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requ
140
144
  store.getState().onError?.(error);
141
145
  throw error;
142
146
  });
143
- //#endregion
144
- //#region src/requestUrl.ts
147
+ // src/requestUrl.ts
145
148
  const __internal__requestUrl = (rawPath, { path: pathParams = {}, query } = {}) => {
146
149
  const config = store.getState();
147
150
  const path = (config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "") + Object.entries(pathParams).reduce((path, [key, value]) => path.replace(`{${key}}`, String(value)), rawPath);
148
151
  return query ? `${path}?${qs.stringify(query)}` : path;
149
152
  };
150
- //#endregion
151
153
  export { HTTPError, __internal__requestUrl, buildRequestInitWithDefaultConfig, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createStore, createTextFetcher, createVoidFetcher, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus, isZodError, mergeHeadersInit, mergeRequestInit, schemaForType, setApiClientConfig, store, toHeadersInit };
@@ -2,7 +2,6 @@ import { Store } from "../store.js";
2
2
  import { Config } from "../apiClientConfigStore.js";
3
3
  import { FC, ReactNode } from "react";
4
4
  import { SWRConfiguration } from "swr";
5
- //#region src/react/ApiClientConfigProvider.d.ts
6
5
  type Configuration = Config & {
7
6
  swr?: SWRConfiguration;
8
7
  };
@@ -12,5 +11,4 @@ type Props = {
12
11
  };
13
12
  export declare const ApiClientConfigProvider: FC<Props>;
14
13
  export declare const useApiClientConfigContext: () => Store<Config>;
15
- //#endregion
16
14
  export {};
@@ -4,7 +4,7 @@ const require_react_swr = require("./swr.js");
4
4
  let react = require("react");
5
5
  let swr = require("swr");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
- //#region src/react/ApiClientConfigProvider.tsx
7
+ // src/react/ApiClientConfigProvider.tsx
8
8
  const ApiClientConfigContext = (0, react.createContext)(require_apiClientConfigStore.store);
9
9
  const ApiClientConfigProvider = (props) => {
10
10
  const { swr: swr$1, ...config } = props.config;
@@ -20,6 +20,5 @@ const ApiClientConfigProvider = (props) => {
20
20
  });
21
21
  };
22
22
  const useApiClientConfigContext = () => (0, react.useContext)(ApiClientConfigContext) || require_apiClientConfigStore.store;
23
- //#endregion
24
23
  exports.ApiClientConfigProvider = ApiClientConfigProvider;
25
24
  exports.useApiClientConfigContext = useApiClientConfigContext;
@@ -1,10 +1,10 @@
1
- import { i as mergeRequestInit, r as store } from "../apiClientConfigStore-DDleIkQN.mjs";
1
+ import { i as mergeRequestInit, r as store } from "../apiClientConfigStore-DbTqjD1_.mjs";
2
2
  import { createContext, useContext, useEffect, useMemo, useRef } from "react";
3
3
  import { SWRConfig } from "swr";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
6
6
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
7
- //#region src/react/swr.ts
7
+ // src/react/swr.ts
8
8
  /**
9
9
  * requestのfetchを中断させるためのmiddleware
10
10
  *
@@ -27,8 +27,7 @@ const createSwrConfig = (config) => ({
27
27
  ...config,
28
28
  use: [...config?.use ?? [], abortMiddleware]
29
29
  });
30
- //#endregion
31
- //#region src/react/ApiClientConfigProvider.tsx
30
+ // src/react/ApiClientConfigProvider.tsx
32
31
  const ApiClientConfigContext = createContext(store);
33
32
  const ApiClientConfigProvider = (props) => {
34
33
  const { swr, ...config } = props.config;
@@ -44,8 +43,7 @@ const ApiClientConfigProvider = (props) => {
44
43
  });
45
44
  };
46
45
  const useApiClientConfigContext = () => useContext(ApiClientConfigContext) || store;
47
- //#endregion
48
- //#region src/react/useApiClientConfig.ts
46
+ // src/react/useApiClientConfig.ts
49
47
  const useApiClientConfig = () => {
50
48
  const store = useApiClientConfigContext();
51
49
  return useSyncExternalStore(store.subscribe, store.getState, store.getState);
@@ -55,8 +53,7 @@ const useApiClientConfigWithSelector = (selector) => {
55
53
  return useSyncExternalStoreWithSelector(store.subscribe, store.getState, store.getState, selector);
56
54
  };
57
55
  const useRequestInit = (customRequestInit = {}) => {
58
- const { defaultRequestInit = {} } = useApiClientConfig();
59
- return useMemo(() => mergeRequestInit(defaultRequestInit, customRequestInit), [defaultRequestInit, customRequestInit]);
56
+ const { defaultRequestInit } = useApiClientConfig();
57
+ return useMemo(() => typeof defaultRequestInit === "function" ? customRequestInit : mergeRequestInit(defaultRequestInit ?? {}, customRequestInit), [defaultRequestInit, customRequestInit]);
60
58
  };
61
- //#endregion
62
59
  export { ApiClientConfigProvider, createSwrConfig, useApiClientConfig, useApiClientConfigContext, useApiClientConfigWithSelector, useRequestInit };
@@ -1,5 +1,4 @@
1
1
  import { SWRConfiguration } from "swr";
2
- //#region src/react/swr.d.ts
3
2
  export type Configuration<T> = SWRConfiguration<T> & {
4
3
  /**
5
4
  * fetchを止めるかどうかのオプション
@@ -8,5 +7,4 @@ export type Configuration<T> = SWRConfiguration<T> & {
8
7
  */
9
8
  shouldNotFetch?: boolean;
10
9
  };
11
- export declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
12
- //#endregion
10
+ export declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
package/dist/react/swr.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let react = require("react");
3
- //#region src/react/swr.ts
3
+ // src/react/swr.ts
4
4
  /**
5
5
  * requestのfetchを中断させるためのmiddleware
6
6
  *
@@ -23,5 +23,4 @@ const createSwrConfig = (config) => ({
23
23
  ...config,
24
24
  use: [...config?.use ?? [], abortMiddleware]
25
25
  });
26
- //#endregion
27
26
  exports.createSwrConfig = createSwrConfig;
@@ -1,6 +1,4 @@
1
1
  import { Config } from "../apiClientConfigStore.js";
2
- //#region src/react/useApiClientConfig.d.ts
3
2
  export declare const useApiClientConfig: () => any;
4
3
  export declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
5
- export declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
6
- //#endregion
4
+ export declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
@@ -4,7 +4,7 @@ const require_react_ApiClientConfigProvider = require("./ApiClientConfigProvider
4
4
  let react = require("react");
5
5
  let use_sync_external_store_shim_index_js = require("use-sync-external-store/shim/index.js");
6
6
  let use_sync_external_store_shim_with_selector_js = require("use-sync-external-store/shim/with-selector.js");
7
- //#region src/react/useApiClientConfig.ts
7
+ // src/react/useApiClientConfig.ts
8
8
  const useApiClientConfig = () => {
9
9
  const store = require_react_ApiClientConfigProvider.useApiClientConfigContext();
10
10
  return (0, use_sync_external_store_shim_index_js.useSyncExternalStore)(store.subscribe, store.getState, store.getState);
@@ -14,10 +14,9 @@ const useApiClientConfigWithSelector = (selector) => {
14
14
  return (0, use_sync_external_store_shim_with_selector_js.useSyncExternalStoreWithSelector)(store.subscribe, store.getState, store.getState, selector);
15
15
  };
16
16
  const useRequestInit = (customRequestInit = {}) => {
17
- const { defaultRequestInit = {} } = useApiClientConfig();
18
- return (0, react.useMemo)(() => require_utils_requestInit.mergeRequestInit(defaultRequestInit, customRequestInit), [defaultRequestInit, customRequestInit]);
17
+ const { defaultRequestInit } = useApiClientConfig();
18
+ return (0, react.useMemo)(() => typeof defaultRequestInit === "function" ? customRequestInit : require_utils_requestInit.mergeRequestInit(defaultRequestInit ?? {}, customRequestInit), [defaultRequestInit, customRequestInit]);
19
19
  };
20
- //#endregion
21
20
  exports.useApiClientConfig = useApiClientConfig;
22
21
  exports.useApiClientConfigWithSelector = useApiClientConfigWithSelector;
23
22
  exports.useRequestInit = useRequestInit;
@@ -1,4 +1,3 @@
1
- //#region src/requestUrl.d.ts
2
1
  type PathParams = Record<string, string | number>;
3
2
  type QueryParams = Record<string, unknown>;
4
3
  type UrlArgs = {
@@ -6,5 +5,4 @@ type UrlArgs = {
6
5
  query?: QueryParams;
7
6
  };
8
7
  export declare const __internal__requestUrl: (rawPath: string, { path: pathParams, query }?: UrlArgs) => string;
9
- //#endregion
10
8
  export {};
@@ -3,11 +3,10 @@ const require_runtime = require("./_virtual/_rolldown/runtime.js");
3
3
  const require_apiClientConfigStore = require("./apiClientConfigStore.js");
4
4
  let qs = require("qs");
5
5
  qs = require_runtime.__toESM(qs);
6
- //#region src/requestUrl.ts
6
+ // src/requestUrl.ts
7
7
  const __internal__requestUrl = (rawPath, { path: pathParams = {}, query } = {}) => {
8
8
  const config = require_apiClientConfigStore.store.getState();
9
9
  const path = (config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "") + Object.entries(pathParams).reduce((path, [key, value]) => path.replace(`{${key}}`, String(value)), rawPath);
10
10
  return query ? `${path}?${qs.default.stringify(query)}` : path;
11
11
  };
12
- //#endregion
13
12
  exports.__internal__requestUrl = __internal__requestUrl;
package/dist/store.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/store.d.ts
2
1
  type Listener = () => void;
3
2
  type GetState<T> = () => T;
4
3
  type SetState<T> = (fn: (state: T) => T) => void;
@@ -10,5 +9,4 @@ export type Store<T> = {
10
9
  subscribe: Subscribe;
11
10
  };
12
11
  export declare const createStore: <T>(initialState: T) => Store<T>;
13
- //#endregion
14
12
  export {};
package/dist/store.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/store.ts
2
+ // src/store.ts
3
3
  const createStore = (initialState) => {
4
4
  let state = initialState;
5
5
  const listeners = /* @__PURE__ */ new Set();
@@ -18,5 +18,4 @@ const createStore = (initialState) => {
18
18
  subscribe
19
19
  };
20
20
  };
21
- //#endregion
22
21
  exports.createStore = createStore;
package/dist/types.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- //#region src/types.d.ts
2
1
  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
2
  type RemoveBracket<T> = T extends `${infer S}[]` ? S : T;
4
3
  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
6
4
  export {};
@@ -1,4 +1,3 @@
1
- //#region src/utils/headersInit.d.ts
2
1
  /**
3
2
  * 二つのHeadersInitの情報を元に、新たなHeadersInitを作成する
4
3
  *
@@ -24,5 +23,4 @@ export declare const mergeHeadersInit: (baseHeadersInit: HeadersInit, overrideHe
24
23
  * @param headers OpenAPI から生成されたヘッダーオブジェクト
25
24
  * @returns HeadersInit として使用可能なオブジェクト
26
25
  */
27
- export declare const toHeadersInit: (headers: Record<string, string | number | boolean | undefined>) => HeadersInit;
28
- //#endregion
26
+ export declare const toHeadersInit: (headers: Record<string, string | number | boolean | undefined>) => HeadersInit;
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/utils/headersInit.ts
2
+ // src/utils/headersInit.ts
3
3
  /**
4
4
  * 二つのHeadersInitの情報を元に、新たなHeadersInitを作成する
5
5
  *
@@ -44,6 +44,5 @@ const toHeadersInit = (headers) => {
44
44
  for (const [key, value] of Object.entries(headers)) if (value !== void 0) result[key] = String(value);
45
45
  return result;
46
46
  };
47
- //#endregion
48
47
  exports.mergeHeadersInit = mergeHeadersInit;
49
48
  exports.toHeadersInit = toHeadersInit;
@@ -1,9 +1,7 @@
1
- //#region src/utils/requestInit.d.ts
2
1
  /**
3
2
  * 第一引数と第二引数のequestInitをマージした新たなRequestInitを返す。
4
3
  * 同じフィールドが存在する場合、第二引数の値で上書きされる。
5
4
  * ただし、`headers`フィールドに関しては、`base`と`override`両方に有効なHeadersInitがある場合に限り、
6
5
  * `mergeHeadersInit`を使用してヘッダーの内容をマージする
7
6
  */
8
- export declare const mergeRequestInit: ({ headers: baseHeaders, ...base }: RequestInit, { headers: overrideHeaders, ...override }: RequestInit) => RequestInit;
9
- //#endregion
7
+ export declare const mergeRequestInit: ({ headers: baseHeaders, ...base }: RequestInit, { headers: overrideHeaders, ...override }: RequestInit) => RequestInit;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_headersInit = require("./headersInit.js");
3
- //#region src/utils/requestInit.ts
3
+ // src/utils/requestInit.ts
4
4
  /**
5
5
  * 第一引数と第二引数のequestInitをマージした新たなRequestInitを返す。
6
6
  * 同じフィールドが存在する場合、第二引数の値で上書きされる。
@@ -12,5 +12,4 @@ const mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: override
12
12
  ...override,
13
13
  headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : require_utils_headersInit.mergeHeadersInit(baseHeaders, overrideHeaders)
14
14
  });
15
- //#endregion
16
15
  exports.mergeRequestInit = mergeRequestInit;
package/dist/zod.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import { z } from "zod";
2
- //#region src/zod.d.ts
3
2
  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
3
+ export declare const isZodError: (obj: unknown) => obj is z.ZodError;
package/dist/zod.js CHANGED
@@ -1,9 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/zod.ts
2
+ // src/zod.ts
3
3
  const schemaForType = () => (arg) => {
4
4
  return arg;
5
5
  };
6
6
  const isZodError = (obj) => obj !== null && typeof obj === "object" && obj.constructor.name === "ZodError";
7
- //#endregion
8
7
  exports.isZodError = isZodError;
9
8
  exports.schemaForType = schemaForType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readyfor/api-client-base",
3
- "version": "1.155.0",
3
+ "version": "1.155.1-pr1532.7d29327",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",