@readyfor/api-client-base 0.0.1-pr889.422eb87
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/LICENSE.md +1 -0
- package/dist/apiClientConfigStore.d.mts +17 -0
- package/dist/apiClientConfigStore.d.ts +17 -0
- package/dist/apiClientConfigStore.js +56 -0
- package/dist/apiClientConfigStore.mjs +9 -0
- package/dist/apiError.d.mts +30 -0
- package/dist/apiError.d.ts +30 -0
- package/dist/apiError.js +94 -0
- package/dist/apiError.mjs +13 -0
- package/dist/chunk-3SEO7S3Q.mjs +23 -0
- package/dist/chunk-472P3XVV.mjs +13 -0
- package/dist/chunk-C5P5R2CL.mjs +79 -0
- package/dist/chunk-DHYJM4DQ.mjs +19 -0
- package/dist/chunk-H3C7VSOJ.mjs +25 -0
- package/dist/chunk-JCZWXJBU.mjs +10 -0
- package/dist/chunk-PY35XWDS.mjs +66 -0
- package/dist/chunk-RGDL3AEX.mjs +22 -0
- package/dist/chunk-VVRQ7D57.mjs +25 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/fetcher.d.mts +12 -0
- package/dist/fetcher.d.ts +12 -0
- package/dist/fetcher.js +170 -0
- package/dist/fetcher.mjs +16 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +232 -0
- package/dist/index.mjs +43 -0
- package/dist/react/ApiClientConfigProvider.d.mts +17 -0
- package/dist/react/ApiClientConfigProvider.d.ts +17 -0
- package/dist/react/ApiClientConfigProvider.js +87 -0
- package/dist/react/ApiClientConfigProvider.mjs +11 -0
- package/dist/react/index.d.mts +8 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +112 -0
- package/dist/react/index.mjs +20 -0
- package/dist/react/swr.d.mts +13 -0
- package/dist/react/swr.d.ts +13 -0
- package/dist/react/swr.js +43 -0
- package/dist/react/swr.mjs +6 -0
- package/dist/react/useApiClientConfig.d.mts +8 -0
- package/dist/react/useApiClientConfig.d.ts +8 -0
- package/dist/react/useApiClientConfig.js +86 -0
- package/dist/react/useApiClientConfig.mjs +12 -0
- package/dist/requestUrl.d.mts +6 -0
- package/dist/requestUrl.d.ts +6 -0
- package/dist/requestUrl.js +78 -0
- package/dist/requestUrl.mjs +8 -0
- package/dist/requestUrl.test.d.mts +2 -0
- package/dist/requestUrl.test.d.ts +2 -0
- package/dist/requestUrl.test.js +171 -0
- package/dist/requestUrl.test.mjs +114 -0
- package/dist/store.d.mts +13 -0
- package/dist/store.d.ts +13 -0
- package/dist/store.js +47 -0
- package/dist/store.mjs +6 -0
- package/dist/types.d.mts +12 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/zod.d.mts +6 -0
- package/dist/zod.d.ts +6 -0
- package/dist/zod.js +35 -0
- package/dist/zod.mjs +8 -0
- package/package.json +66 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/index.ts
|
|
21
|
+
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
ApiClientConfigProvider: () => ApiClientConfigProvider,
|
|
24
|
+
createSwrConfig: () => createSwrConfig,
|
|
25
|
+
useApiClientConfig: () => useApiClientConfig,
|
|
26
|
+
useApiClientConfigContext: () => useApiClientConfigContext,
|
|
27
|
+
useApiClientConfigWithSelector: () => useApiClientConfigWithSelector
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(react_exports);
|
|
30
|
+
|
|
31
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
|
|
34
|
+
// src/store.ts
|
|
35
|
+
var createStore = (initialState) => {
|
|
36
|
+
let state = initialState;
|
|
37
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
38
|
+
const getState = () => state;
|
|
39
|
+
const setState = (fn) => {
|
|
40
|
+
state = fn(state);
|
|
41
|
+
listeners.forEach((listener) => listener());
|
|
42
|
+
};
|
|
43
|
+
const subscribe = (listener) => {
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
return () => listeners.delete(listener);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
getState,
|
|
49
|
+
setState,
|
|
50
|
+
subscribe
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/apiClientConfigStore.ts
|
|
55
|
+
var defaultConfig = {};
|
|
56
|
+
var store = createStore(defaultConfig);
|
|
57
|
+
|
|
58
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
59
|
+
var import_swr = require("swr");
|
|
60
|
+
|
|
61
|
+
// src/react/swr.ts
|
|
62
|
+
var import_react = require("react");
|
|
63
|
+
var abortMiddleware = (useSWRNext) => (key, fetcher, config) => {
|
|
64
|
+
const ctrlRef = (0, import_react.useRef)();
|
|
65
|
+
const extendedFetcher = fetcher ? (key2) => {
|
|
66
|
+
ctrlRef.current?.abort();
|
|
67
|
+
ctrlRef.current = new AbortController();
|
|
68
|
+
return fetcher(key2, { signal: ctrlRef.current.signal });
|
|
69
|
+
} : fetcher;
|
|
70
|
+
return useSWRNext(key, extendedFetcher, config);
|
|
71
|
+
};
|
|
72
|
+
var createSwrConfig = (config) => ({
|
|
73
|
+
...config,
|
|
74
|
+
use: [...config?.use ?? [], abortMiddleware]
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
78
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
79
|
+
var ApiClientConfigContext = (0, import_react2.createContext)(store);
|
|
80
|
+
var ApiClientConfigProvider = (props) => {
|
|
81
|
+
const { swr, ...config } = props.config;
|
|
82
|
+
(0, import_react2.useEffect)(() => {
|
|
83
|
+
store.setState(() => config);
|
|
84
|
+
}, [config]);
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ApiClientConfigContext.Provider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_swr.SWRConfig, { value: createSwrConfig(swr), children: props.children }) });
|
|
86
|
+
};
|
|
87
|
+
var useApiClientConfigContext = () => (0, import_react2.useContext)(ApiClientConfigContext) || store;
|
|
88
|
+
|
|
89
|
+
// src/react/useApiClientConfig.ts
|
|
90
|
+
var import_shim = require("use-sync-external-store/shim");
|
|
91
|
+
var import_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
92
|
+
var useApiClientConfig = () => {
|
|
93
|
+
const store2 = useApiClientConfigContext();
|
|
94
|
+
return (0, import_shim.useSyncExternalStore)(store2.subscribe, store2.getState);
|
|
95
|
+
};
|
|
96
|
+
var useApiClientConfigWithSelector = (selector) => {
|
|
97
|
+
const store2 = useApiClientConfigContext();
|
|
98
|
+
return (0, import_with_selector.useSyncExternalStoreWithSelector)(
|
|
99
|
+
store2.subscribe,
|
|
100
|
+
store2.getState,
|
|
101
|
+
null,
|
|
102
|
+
selector
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
ApiClientConfigProvider,
|
|
108
|
+
createSwrConfig,
|
|
109
|
+
useApiClientConfig,
|
|
110
|
+
useApiClientConfigContext,
|
|
111
|
+
useApiClientConfigWithSelector
|
|
112
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfig,
|
|
3
|
+
useApiClientConfigWithSelector
|
|
4
|
+
} from "../chunk-H3C7VSOJ.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ApiClientConfigProvider,
|
|
7
|
+
useApiClientConfigContext
|
|
8
|
+
} from "../chunk-VVRQ7D57.mjs";
|
|
9
|
+
import {
|
|
10
|
+
createSwrConfig
|
|
11
|
+
} from "../chunk-DHYJM4DQ.mjs";
|
|
12
|
+
import "../chunk-472P3XVV.mjs";
|
|
13
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
14
|
+
export {
|
|
15
|
+
ApiClientConfigProvider,
|
|
16
|
+
createSwrConfig,
|
|
17
|
+
useApiClientConfig,
|
|
18
|
+
useApiClientConfigContext,
|
|
19
|
+
useApiClientConfigWithSelector
|
|
20
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SWRConfiguration } from 'swr';
|
|
2
|
+
|
|
3
|
+
type Configuration<T> = SWRConfiguration<T> & {
|
|
4
|
+
/**
|
|
5
|
+
* fetchを止めるかどうかのオプション
|
|
6
|
+
* trueの場合: useSWRの第一引数にnullが渡されます
|
|
7
|
+
* false,または未指定の場合: useSWRの第一引数にURLが渡されます
|
|
8
|
+
*/
|
|
9
|
+
shouldNotFetch?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
|
|
12
|
+
|
|
13
|
+
export { type Configuration, createSwrConfig };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SWRConfiguration } from 'swr';
|
|
2
|
+
|
|
3
|
+
type Configuration<T> = SWRConfiguration<T> & {
|
|
4
|
+
/**
|
|
5
|
+
* fetchを止めるかどうかのオプション
|
|
6
|
+
* trueの場合: useSWRの第一引数にnullが渡されます
|
|
7
|
+
* false,または未指定の場合: useSWRの第一引数にURLが渡されます
|
|
8
|
+
*/
|
|
9
|
+
shouldNotFetch?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const createSwrConfig: (config?: SWRConfiguration) => SWRConfiguration;
|
|
12
|
+
|
|
13
|
+
export { type Configuration, createSwrConfig };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/swr.ts
|
|
21
|
+
var swr_exports = {};
|
|
22
|
+
__export(swr_exports, {
|
|
23
|
+
createSwrConfig: () => createSwrConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(swr_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var abortMiddleware = (useSWRNext) => (key, fetcher, config) => {
|
|
28
|
+
const ctrlRef = (0, import_react.useRef)();
|
|
29
|
+
const extendedFetcher = fetcher ? (key2) => {
|
|
30
|
+
ctrlRef.current?.abort();
|
|
31
|
+
ctrlRef.current = new AbortController();
|
|
32
|
+
return fetcher(key2, { signal: ctrlRef.current.signal });
|
|
33
|
+
} : fetcher;
|
|
34
|
+
return useSWRNext(key, extendedFetcher, config);
|
|
35
|
+
};
|
|
36
|
+
var createSwrConfig = (config) => ({
|
|
37
|
+
...config,
|
|
38
|
+
use: [...config?.use ?? [], abortMiddleware]
|
|
39
|
+
});
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
createSwrConfig
|
|
43
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from '../apiClientConfigStore.mjs';
|
|
2
|
+
import '../store.mjs';
|
|
3
|
+
import '../requestUrl.mjs';
|
|
4
|
+
|
|
5
|
+
declare const useApiClientConfig: () => Config;
|
|
6
|
+
declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
|
|
7
|
+
|
|
8
|
+
export { useApiClientConfig, useApiClientConfigWithSelector };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from '../apiClientConfigStore.js';
|
|
2
|
+
import '../store.js';
|
|
3
|
+
import '../requestUrl.js';
|
|
4
|
+
|
|
5
|
+
declare const useApiClientConfig: () => Config;
|
|
6
|
+
declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
|
|
7
|
+
|
|
8
|
+
export { useApiClientConfig, useApiClientConfigWithSelector };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/react/useApiClientConfig.ts
|
|
21
|
+
var useApiClientConfig_exports = {};
|
|
22
|
+
__export(useApiClientConfig_exports, {
|
|
23
|
+
useApiClientConfig: () => useApiClientConfig,
|
|
24
|
+
useApiClientConfigWithSelector: () => useApiClientConfigWithSelector
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(useApiClientConfig_exports);
|
|
27
|
+
|
|
28
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
29
|
+
var import_react2 = require("react");
|
|
30
|
+
|
|
31
|
+
// src/store.ts
|
|
32
|
+
var createStore = (initialState) => {
|
|
33
|
+
let state = initialState;
|
|
34
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
35
|
+
const getState = () => state;
|
|
36
|
+
const setState = (fn) => {
|
|
37
|
+
state = fn(state);
|
|
38
|
+
listeners.forEach((listener) => listener());
|
|
39
|
+
};
|
|
40
|
+
const subscribe = (listener) => {
|
|
41
|
+
listeners.add(listener);
|
|
42
|
+
return () => listeners.delete(listener);
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
getState,
|
|
46
|
+
setState,
|
|
47
|
+
subscribe
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/apiClientConfigStore.ts
|
|
52
|
+
var defaultConfig = {};
|
|
53
|
+
var store = createStore(defaultConfig);
|
|
54
|
+
|
|
55
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
56
|
+
var import_swr = require("swr");
|
|
57
|
+
|
|
58
|
+
// src/react/swr.ts
|
|
59
|
+
var import_react = require("react");
|
|
60
|
+
|
|
61
|
+
// src/react/ApiClientConfigProvider.tsx
|
|
62
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
63
|
+
var ApiClientConfigContext = (0, import_react2.createContext)(store);
|
|
64
|
+
var useApiClientConfigContext = () => (0, import_react2.useContext)(ApiClientConfigContext) || store;
|
|
65
|
+
|
|
66
|
+
// src/react/useApiClientConfig.ts
|
|
67
|
+
var import_shim = require("use-sync-external-store/shim");
|
|
68
|
+
var import_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
69
|
+
var useApiClientConfig = () => {
|
|
70
|
+
const store2 = useApiClientConfigContext();
|
|
71
|
+
return (0, import_shim.useSyncExternalStore)(store2.subscribe, store2.getState);
|
|
72
|
+
};
|
|
73
|
+
var useApiClientConfigWithSelector = (selector) => {
|
|
74
|
+
const store2 = useApiClientConfigContext();
|
|
75
|
+
return (0, import_with_selector.useSyncExternalStoreWithSelector)(
|
|
76
|
+
store2.subscribe,
|
|
77
|
+
store2.getState,
|
|
78
|
+
null,
|
|
79
|
+
selector
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
useApiClientConfig,
|
|
85
|
+
useApiClientConfigWithSelector
|
|
86
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useApiClientConfig,
|
|
3
|
+
useApiClientConfigWithSelector
|
|
4
|
+
} from "../chunk-H3C7VSOJ.mjs";
|
|
5
|
+
import "../chunk-VVRQ7D57.mjs";
|
|
6
|
+
import "../chunk-DHYJM4DQ.mjs";
|
|
7
|
+
import "../chunk-472P3XVV.mjs";
|
|
8
|
+
import "../chunk-3SEO7S3Q.mjs";
|
|
9
|
+
export {
|
|
10
|
+
useApiClientConfig,
|
|
11
|
+
useApiClientConfigWithSelector
|
|
12
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/requestUrl.ts
|
|
31
|
+
var requestUrl_exports = {};
|
|
32
|
+
__export(requestUrl_exports, {
|
|
33
|
+
__internal__requestUrl: () => __internal__requestUrl
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(requestUrl_exports);
|
|
36
|
+
var import_qs = __toESM(require("qs"));
|
|
37
|
+
|
|
38
|
+
// src/store.ts
|
|
39
|
+
var createStore = (initialState) => {
|
|
40
|
+
let state = initialState;
|
|
41
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
42
|
+
const getState = () => state;
|
|
43
|
+
const setState = (fn) => {
|
|
44
|
+
state = fn(state);
|
|
45
|
+
listeners.forEach((listener) => listener());
|
|
46
|
+
};
|
|
47
|
+
const subscribe = (listener) => {
|
|
48
|
+
listeners.add(listener);
|
|
49
|
+
return () => listeners.delete(listener);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
getState,
|
|
53
|
+
setState,
|
|
54
|
+
subscribe
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/apiClientConfigStore.ts
|
|
59
|
+
var defaultConfig = {};
|
|
60
|
+
var store = createStore(defaultConfig);
|
|
61
|
+
|
|
62
|
+
// src/requestUrl.ts
|
|
63
|
+
function __internal__requestUrl(...args) {
|
|
64
|
+
const config = store.getState();
|
|
65
|
+
const rawPath = args[0];
|
|
66
|
+
const params = args[1] || {};
|
|
67
|
+
const query = args[2];
|
|
68
|
+
const hostName = config.hostName ? typeof config.hostName === "string" ? config.hostName : config.hostName(rawPath) : "";
|
|
69
|
+
const path = hostName + Object.entries(params).reduce(
|
|
70
|
+
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
71
|
+
rawPath
|
|
72
|
+
);
|
|
73
|
+
return query ? `${path}?${import_qs.default.stringify(query)}` : path;
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
__internal__requestUrl
|
|
78
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/requestUrl.ts
|
|
26
|
+
var import_qs = __toESM(require("qs"));
|
|
27
|
+
|
|
28
|
+
// src/store.ts
|
|
29
|
+
var createStore = (initialState) => {
|
|
30
|
+
let state = initialState;
|
|
31
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
32
|
+
const getState = () => state;
|
|
33
|
+
const setState = (fn) => {
|
|
34
|
+
state = fn(state);
|
|
35
|
+
listeners.forEach((listener) => listener());
|
|
36
|
+
};
|
|
37
|
+
const subscribe = (listener) => {
|
|
38
|
+
listeners.add(listener);
|
|
39
|
+
return () => listeners.delete(listener);
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
getState,
|
|
43
|
+
setState,
|
|
44
|
+
subscribe
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/apiClientConfigStore.ts
|
|
49
|
+
var defaultConfig = {};
|
|
50
|
+
var store = createStore(defaultConfig);
|
|
51
|
+
|
|
52
|
+
// src/requestUrl.ts
|
|
53
|
+
function __internal__requestUrl(...args) {
|
|
54
|
+
const config2 = store.getState();
|
|
55
|
+
const rawPath = args[0];
|
|
56
|
+
const params = args[1] || {};
|
|
57
|
+
const query = args[2];
|
|
58
|
+
const hostName = config2.hostName ? typeof config2.hostName === "string" ? config2.hostName : config2.hostName(rawPath) : "";
|
|
59
|
+
const path = hostName + Object.entries(params).reduce(
|
|
60
|
+
(path2, [key, value]) => path2.replace(`{${key}}`, String(value)),
|
|
61
|
+
rawPath
|
|
62
|
+
);
|
|
63
|
+
return query ? `${path}?${import_qs.default.stringify(query)}` : path;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/requestUrl.test.ts
|
|
67
|
+
var config = {
|
|
68
|
+
hostName: (url) => url.startsWith("/api/v1") ? "https://v1host.example.com" : "https://v2host.example.com"
|
|
69
|
+
};
|
|
70
|
+
describe("__internal_requestUrl", () => {
|
|
71
|
+
describe("path\u306E\u307F\u306E\u30D1\u30E9\u30E1\u30FC\u30BF\u306E\u6642", () => {
|
|
72
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u306A\u3044\u6642", () => {
|
|
73
|
+
test("path\u304C\u305D\u306E\u307E\u307E\u8FD4\u3055\u308C\u308B", () => {
|
|
74
|
+
store.setState(() => ({}));
|
|
75
|
+
expect(__internal__requestUrl("/api/v1/my/fundraising/header")).toEqual(
|
|
76
|
+
"/api/v1/my/fundraising/header"
|
|
77
|
+
);
|
|
78
|
+
expect(__internal__requestUrl("/api/v2/token")).toEqual(
|
|
79
|
+
"/api/v2/token"
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u6642", () => {
|
|
84
|
+
test("hostUrl\u4ED8\u304D\u306EURL\u304C\u8FD4\u3055\u308C\u308B", () => {
|
|
85
|
+
store.setState(() => config);
|
|
86
|
+
expect(__internal__requestUrl("/api/v1/my/fundraising/header")).toEqual(
|
|
87
|
+
"https://v1host.example.com/api/v1/my/fundraising/header"
|
|
88
|
+
);
|
|
89
|
+
expect(__internal__requestUrl("/api/v2/token")).toEqual(
|
|
90
|
+
"https://v2host.example.com/api/v2/token"
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe("path\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u3042\u308B\u6642", () => {
|
|
96
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u306A\u3044\u6642", () => {
|
|
97
|
+
test("path\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u7F6E\u304D\u63DB\u3048\u3089\u308C\u305Fpath\u304C\u8FD4\u3055\u308C\u308B", () => {
|
|
98
|
+
store.setState(() => ({}));
|
|
99
|
+
expect(
|
|
100
|
+
__internal__requestUrl(
|
|
101
|
+
"/api/v1/my/fundraising/projects/{project_id}",
|
|
102
|
+
{
|
|
103
|
+
project_id: 12345
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
).toEqual("/api/v1/my/fundraising/projects/12345");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u6642", () => {
|
|
110
|
+
test("path\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u7F6E\u304D\u63DB\u3048\u3089\u308C\u305FURL\u304C\u8FD4\u3055\u308C\u308B", () => {
|
|
111
|
+
store.setState(() => config);
|
|
112
|
+
expect(
|
|
113
|
+
__internal__requestUrl(
|
|
114
|
+
"/api/v1/my/fundraising/projects/{project_id}",
|
|
115
|
+
{
|
|
116
|
+
project_id: 12345
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
).toEqual(
|
|
120
|
+
"https://v1host.example.com/api/v1/my/fundraising/projects/12345"
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe("query\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u3042\u308B\u6642", () => {
|
|
126
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u306A\u3044\u6642", () => {
|
|
127
|
+
test("query\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u3064\u3051\u3089\u308C\u305Fpath\u304C\u8FD4\u3055\u308C\u308B", () => {
|
|
128
|
+
store.setState(() => ({}));
|
|
129
|
+
expect(
|
|
130
|
+
__internal__requestUrl(
|
|
131
|
+
"/api/v1/my/messages/tree",
|
|
132
|
+
{},
|
|
133
|
+
{ follow_id: 12345 }
|
|
134
|
+
)
|
|
135
|
+
).toEqual("/api/v1/my/messages/tree?follow_id=12345");
|
|
136
|
+
expect(
|
|
137
|
+
__internal__requestUrl(
|
|
138
|
+
"/api/v2/contributions/project_info",
|
|
139
|
+
{},
|
|
140
|
+
{ project_id: "12345" }
|
|
141
|
+
)
|
|
142
|
+
).toEqual("/api/v2/contributions/project_info?project_id=12345");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe("url\u306Econfig\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u6642", () => {
|
|
146
|
+
test("query\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u3064\u3051\u3089\u308C\u305FURL\u304C\u8FD4\u3055\u308C\u308B", () => {
|
|
147
|
+
store.setState(() => config);
|
|
148
|
+
expect(
|
|
149
|
+
__internal__requestUrl(
|
|
150
|
+
"/api/v1/my/messages/tree",
|
|
151
|
+
{},
|
|
152
|
+
{ follow_id: 12345 }
|
|
153
|
+
)
|
|
154
|
+
).toEqual(
|
|
155
|
+
"https://v1host.example.com/api/v1/my/messages/tree?follow_id=12345"
|
|
156
|
+
);
|
|
157
|
+
expect(
|
|
158
|
+
__internal__requestUrl(
|
|
159
|
+
"/api/v2/contributions/project_info",
|
|
160
|
+
{},
|
|
161
|
+
{ project_id: "12345" }
|
|
162
|
+
)
|
|
163
|
+
).toEqual(
|
|
164
|
+
"https://v2host.example.com/api/v2/contributions/project_info?project_id=12345"
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe("path\u30D1\u30E9\u30E1\u30FC\u30BF\u3068query\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u3042\u308B\u6642", () => {
|
|
170
|
+
});
|
|
171
|
+
});
|