@varlet/axle 1.0.1 → 1.0.2
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/api.d.mts +27 -0
- package/dist/api.mjs +46 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.mjs +324 -0
- package/dist/instance-ar9qY3vp.d.mts +64 -0
- package/dist/use.d.mts +85 -0
- package/dist/use.mjs +229 -0
- package/package.json +33 -33
- package/lib/api.cjs +0 -89
- package/lib/api.d.cts +0 -28
- package/lib/api.d.ts +0 -28
- package/lib/api.js +0 -41
- package/lib/chunk-G2ADBYYC.js +0 -37
- package/lib/index.cjs +0 -490
- package/lib/index.d.cts +0 -85
- package/lib/index.d.ts +0 -85
- package/lib/index.js +0 -427
- package/lib/instance-857fe07c.d.ts +0 -64
- package/lib/use.cjs +0 -351
- package/lib/use.d.cts +0 -85
- package/lib/use.d.ts +0 -85
- package/lib/use.js +0 -314
package/dist/use.mjs
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { isFunction } from "rattail";
|
|
2
|
+
import { getCurrentInstance, onActivated, onDeactivated, onMounted, onUnmounted, ref, watch } from "vue";
|
|
3
|
+
//#region src/use.ts
|
|
4
|
+
function normalizeValueGetter(valueGetter) {
|
|
5
|
+
return isFunction(valueGetter) ? valueGetter() : valueGetter;
|
|
6
|
+
}
|
|
7
|
+
const cacheBuffer = /* @__PURE__ */ new Map();
|
|
8
|
+
function cleanupCacheBuffer() {
|
|
9
|
+
cacheBuffer.forEach((value, key) => {
|
|
10
|
+
if (value.expiredTime && Date.now() >= value.expiredTime) cacheBuffer.delete(key);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function createUseAxle(options) {
|
|
14
|
+
const { axle, onTransform: defaultOnTransform, immediate: defaultImmediate = true, abortOnUnmount: defaultAbortOnUnmount = true, cacheTime: defaultCacheTime = Infinity } = options;
|
|
15
|
+
const useAxle = (options) => {
|
|
16
|
+
const { url: initialUrlOrGetter, method, immediate = defaultImmediate, abortOnUnmount = defaultAbortOnUnmount, cacheTime = defaultCacheTime, cacheKey, pollingInterval, pollingOnHidden = true, pollingOnDeactivated = false, refreshOnWindowFocus = false, value: initialValue, resetValue: initialResetValue, cloneResetValue: initialCloneResetValue, params: initialParamsOrGetter, config: initialConfigOrGetter, watch: watchOptions, runnable = () => true, onBefore = () => {}, onAfter = () => {}, onTransform = defaultOnTransform ?? ((response) => response), onSuccess = () => {}, onError = () => {} } = options;
|
|
17
|
+
const value = ref(initialValue);
|
|
18
|
+
const loading = ref(false);
|
|
19
|
+
const error = ref();
|
|
20
|
+
const downloadProgress = ref(0);
|
|
21
|
+
const uploadProgress = ref(0);
|
|
22
|
+
const pollingCanceled = ref(false);
|
|
23
|
+
const refs = {
|
|
24
|
+
value,
|
|
25
|
+
loading,
|
|
26
|
+
error,
|
|
27
|
+
downloadProgress,
|
|
28
|
+
uploadProgress,
|
|
29
|
+
pollingCanceled
|
|
30
|
+
};
|
|
31
|
+
const extra = {
|
|
32
|
+
uploadProgress,
|
|
33
|
+
downloadProgress,
|
|
34
|
+
loading,
|
|
35
|
+
error,
|
|
36
|
+
pollingCanceled,
|
|
37
|
+
abort,
|
|
38
|
+
resetValue,
|
|
39
|
+
invalidateCache,
|
|
40
|
+
cancelPolling
|
|
41
|
+
};
|
|
42
|
+
let controller = new AbortController();
|
|
43
|
+
let pollingTimer = null;
|
|
44
|
+
let deactivated = false;
|
|
45
|
+
let hidden = false;
|
|
46
|
+
let unmounted = false;
|
|
47
|
+
const run = Object.assign(async (options = {}) => {
|
|
48
|
+
if (!runnable() || abortOnUnmount && unmounted) return;
|
|
49
|
+
pollingCanceled.value = false;
|
|
50
|
+
if (controller.signal.aborted) controller = new AbortController();
|
|
51
|
+
if ((options.resetValue ?? initialResetValue ?? false) === true) resetValue(options);
|
|
52
|
+
uploadProgress.value = 0;
|
|
53
|
+
downloadProgress.value = 0;
|
|
54
|
+
const url = options.url ?? normalizeValueGetter(initialUrlOrGetter);
|
|
55
|
+
const params = options.params ?? normalizeValueGetter(initialParamsOrGetter);
|
|
56
|
+
const config = options.config ?? normalizeValueGetter(initialConfigOrGetter);
|
|
57
|
+
const normalizedCacheKey = cacheKey ? normalizeValueGetter(cacheKey) : void 0;
|
|
58
|
+
onBefore(refs);
|
|
59
|
+
loading.value = true;
|
|
60
|
+
try {
|
|
61
|
+
cleanupCacheBuffer();
|
|
62
|
+
const response = await getResponse();
|
|
63
|
+
if (shouldSetCacheResponse(normalizedCacheKey)) {
|
|
64
|
+
const cache = cacheBuffer.get(normalizedCacheKey);
|
|
65
|
+
cache.response = response;
|
|
66
|
+
cache.expiredTime = Date.now() + cacheTime;
|
|
67
|
+
}
|
|
68
|
+
value.value = await onTransform(response, refs);
|
|
69
|
+
error.value = void 0;
|
|
70
|
+
onSuccess(response, refs);
|
|
71
|
+
loading.value = false;
|
|
72
|
+
onAfter(refs);
|
|
73
|
+
return response;
|
|
74
|
+
} catch (responseError) {
|
|
75
|
+
error.value = responseError;
|
|
76
|
+
onError(responseError, refs);
|
|
77
|
+
loading.value = false;
|
|
78
|
+
onAfter(refs);
|
|
79
|
+
throw responseError;
|
|
80
|
+
} finally {
|
|
81
|
+
clearPolling();
|
|
82
|
+
startPolling();
|
|
83
|
+
}
|
|
84
|
+
function getResponse() {
|
|
85
|
+
if (shouldUseCache(normalizedCacheKey)) return JSON.parse(JSON.stringify(cacheBuffer.get(normalizedCacheKey).response));
|
|
86
|
+
if (shouldAwaitCachePromise(normalizedCacheKey)) return cacheBuffer.get(normalizedCacheKey).promise;
|
|
87
|
+
const promise = fetchResponse();
|
|
88
|
+
if (shouldSetCachePromise(normalizedCacheKey)) cacheBuffer.set(normalizedCacheKey, { promise });
|
|
89
|
+
return promise;
|
|
90
|
+
}
|
|
91
|
+
function fetchResponse() {
|
|
92
|
+
return axle[method](url, params, {
|
|
93
|
+
signal: controller.signal,
|
|
94
|
+
onUploadProgress(event) {
|
|
95
|
+
uploadProgress.value = event.progress ?? 0;
|
|
96
|
+
},
|
|
97
|
+
onDownloadProgress(event) {
|
|
98
|
+
downloadProgress.value = event.progress ?? 0;
|
|
99
|
+
},
|
|
100
|
+
...config
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function shouldUseCache(key) {
|
|
104
|
+
if (!key || !cacheBuffer.has(key)) return false;
|
|
105
|
+
return cacheBuffer.get(key).response != null;
|
|
106
|
+
}
|
|
107
|
+
function shouldAwaitCachePromise(key) {
|
|
108
|
+
if (!key || !cacheBuffer.has(key)) return false;
|
|
109
|
+
return cacheBuffer.get(key).promise;
|
|
110
|
+
}
|
|
111
|
+
function shouldSetCachePromise(key) {
|
|
112
|
+
if (!key || cacheBuffer.has(key)) return false;
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
function shouldSetCacheResponse(key) {
|
|
116
|
+
if (!key || !cacheBuffer.has(key)) return false;
|
|
117
|
+
return cacheBuffer.get(key).response == null;
|
|
118
|
+
}
|
|
119
|
+
}, extra);
|
|
120
|
+
if (immediate) runWithInitialConfig();
|
|
121
|
+
if (getCurrentInstance()) {
|
|
122
|
+
onActivated(() => {
|
|
123
|
+
deactivated = false;
|
|
124
|
+
addVisibilityChangeListener();
|
|
125
|
+
addWindowFocusListener();
|
|
126
|
+
startPolling();
|
|
127
|
+
});
|
|
128
|
+
onMounted(() => {
|
|
129
|
+
addVisibilityChangeListener();
|
|
130
|
+
addWindowFocusListener();
|
|
131
|
+
});
|
|
132
|
+
onDeactivated(() => {
|
|
133
|
+
deactivated = true;
|
|
134
|
+
removeVisibilityChangeListener();
|
|
135
|
+
removeWindowFocusListener();
|
|
136
|
+
clearPolling();
|
|
137
|
+
});
|
|
138
|
+
onUnmounted(() => {
|
|
139
|
+
removeVisibilityChangeListener();
|
|
140
|
+
removeWindowFocusListener();
|
|
141
|
+
cancelPolling();
|
|
142
|
+
});
|
|
143
|
+
onUnmounted(() => {
|
|
144
|
+
unmounted = true;
|
|
145
|
+
if (abortOnUnmount) abort();
|
|
146
|
+
});
|
|
147
|
+
if (watchOptions) {
|
|
148
|
+
const normalizedWatchOptions = watchOptions === true ? {
|
|
149
|
+
params: true,
|
|
150
|
+
config: true
|
|
151
|
+
} : {
|
|
152
|
+
params: false,
|
|
153
|
+
config: false,
|
|
154
|
+
...watchOptions
|
|
155
|
+
};
|
|
156
|
+
const enableWatchParams = isFunction(initialParamsOrGetter) && normalizedWatchOptions.params;
|
|
157
|
+
const enableWatchConfig = isFunction(initialConfigOrGetter) && normalizedWatchOptions.config;
|
|
158
|
+
watch(() => [
|
|
159
|
+
enableWatchParams ? normalizeValueGetter(initialParamsOrGetter) : void 0,
|
|
160
|
+
enableWatchConfig ? normalizeValueGetter(initialConfigOrGetter) : void 0,
|
|
161
|
+
normalizedWatchOptions._custom ? normalizedWatchOptions._custom() : void 0
|
|
162
|
+
], () => {
|
|
163
|
+
runWithInitialConfig();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function runWithInitialConfig() {
|
|
168
|
+
return run({
|
|
169
|
+
url: normalizeValueGetter(initialUrlOrGetter),
|
|
170
|
+
params: normalizeValueGetter(initialParamsOrGetter),
|
|
171
|
+
config: normalizeValueGetter(initialConfigOrGetter)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function resetValue(options = {}) {
|
|
175
|
+
value.value = ((options.cloneResetValue ?? initialCloneResetValue ?? false) === true ? (v) => v == null ? null : JSON.parse(JSON.stringify(v)) : isFunction(initialCloneResetValue) ? initialCloneResetValue : (v) => v)(initialValue);
|
|
176
|
+
}
|
|
177
|
+
function abort() {
|
|
178
|
+
controller.abort();
|
|
179
|
+
}
|
|
180
|
+
function addWindowFocusListener() {
|
|
181
|
+
if (typeof window !== "undefined") window.addEventListener("focus", handleWindowFocus);
|
|
182
|
+
}
|
|
183
|
+
function removeWindowFocusListener() {
|
|
184
|
+
if (typeof window !== "undefined") window.removeEventListener("focus", handleWindowFocus);
|
|
185
|
+
}
|
|
186
|
+
function handleWindowFocus() {
|
|
187
|
+
if (refreshOnWindowFocus) runWithInitialConfig();
|
|
188
|
+
}
|
|
189
|
+
function addVisibilityChangeListener() {
|
|
190
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
191
|
+
}
|
|
192
|
+
function removeVisibilityChangeListener() {
|
|
193
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
194
|
+
}
|
|
195
|
+
function handleVisibilityChange() {
|
|
196
|
+
hidden = document.visibilityState === "hidden";
|
|
197
|
+
if (pollingOnHidden) return;
|
|
198
|
+
hidden ? clearPolling() : startPolling();
|
|
199
|
+
}
|
|
200
|
+
function startPolling() {
|
|
201
|
+
if (pollingInterval == null || pollingCanceled.value || pollingTimer != null || deactivated && !pollingOnDeactivated || hidden && !pollingOnHidden) return;
|
|
202
|
+
pollingTimer = setTimeout(() => {
|
|
203
|
+
runWithInitialConfig();
|
|
204
|
+
}, pollingInterval);
|
|
205
|
+
}
|
|
206
|
+
function clearPolling() {
|
|
207
|
+
if (pollingTimer == null) return;
|
|
208
|
+
clearTimeout(pollingTimer);
|
|
209
|
+
pollingTimer = null;
|
|
210
|
+
}
|
|
211
|
+
function cancelPolling() {
|
|
212
|
+
clearPolling();
|
|
213
|
+
pollingCanceled.value = true;
|
|
214
|
+
}
|
|
215
|
+
function invalidateCache() {
|
|
216
|
+
const normalizedCacheKey = cacheKey ? normalizeValueGetter(cacheKey) : void 0;
|
|
217
|
+
if (!normalizedCacheKey || !cacheBuffer.has(normalizedCacheKey)) return;
|
|
218
|
+
cacheBuffer.delete(normalizedCacheKey);
|
|
219
|
+
}
|
|
220
|
+
return [
|
|
221
|
+
value,
|
|
222
|
+
run,
|
|
223
|
+
extra
|
|
224
|
+
];
|
|
225
|
+
};
|
|
226
|
+
return useAxle;
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
229
|
+
export { cleanupCacheBuffer, createUseAxle, normalizeValueGetter };
|
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/axle",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Progressive request tool based on axios",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"axle",
|
|
7
6
|
"axios",
|
|
7
|
+
"axle",
|
|
8
|
+
"composition api",
|
|
8
9
|
"helpers",
|
|
9
|
-
"vue3"
|
|
10
|
-
"composition api"
|
|
10
|
+
"vue3"
|
|
11
11
|
],
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/varletjs/axle/issues"
|
|
14
14
|
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "haoziqaq <357229046@qq.com>",
|
|
15
17
|
"repository": {
|
|
16
18
|
"type": "git",
|
|
17
19
|
"url": "git+https://github.com/varletjs/axle.git"
|
|
18
20
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
22
24
|
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"main": "dist/index.mjs",
|
|
27
|
+
"module": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.mts",
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
"*": {
|
|
31
|
+
"use": [
|
|
32
|
+
"dist/use.d.mts"
|
|
33
|
+
],
|
|
34
|
+
"api": [
|
|
35
|
+
"dist/api.d.mts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
23
39
|
"exports": {
|
|
24
40
|
".": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"types": "./lib/index.d.ts"
|
|
41
|
+
"types": "./dist/index.d.mts",
|
|
42
|
+
"import": "./dist/index.mjs"
|
|
28
43
|
},
|
|
29
44
|
"./use": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"types": "./lib/use.d.ts"
|
|
45
|
+
"types": "./dist/use.d.mts",
|
|
46
|
+
"import": "./dist/use.mjs"
|
|
33
47
|
},
|
|
34
48
|
"./api": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"types": "./lib/api.d.ts"
|
|
49
|
+
"types": "./dist/api.d.mts",
|
|
50
|
+
"import": "./dist/api.mjs"
|
|
38
51
|
},
|
|
39
52
|
"./*": "./*"
|
|
40
53
|
},
|
|
41
|
-
"main": "lib/index.cjs",
|
|
42
|
-
"module": "lib/index.js",
|
|
43
|
-
"types": "index.d.ts",
|
|
44
|
-
"typesVersions": {
|
|
45
|
-
"*": {
|
|
46
|
-
"*": [
|
|
47
|
-
"./lib/*"
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"files": [
|
|
52
|
-
"lib"
|
|
53
|
-
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"axios": "1.7.3",
|
|
56
56
|
"crypto-js": "^4.2.0",
|
|
57
57
|
"lodash": "4.17.21",
|
|
58
58
|
"qs": "^6.11.0",
|
|
59
|
-
"rattail": "1.
|
|
59
|
+
"rattail": "^1.8.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/crypto-js": "^4.2.1",
|
|
63
63
|
"@types/lodash": "4.14.202",
|
|
64
64
|
"@types/qs": "^6.9.7",
|
|
65
|
-
"tsup": "7.2.0",
|
|
66
65
|
"typescript": "^5.1.5",
|
|
66
|
+
"vite-plus": "^0.1.16",
|
|
67
67
|
"vue": "3.3.4"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vue": "^3.2.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
|
-
"build": "
|
|
74
|
-
"dev": "
|
|
73
|
+
"build": "vp pack",
|
|
74
|
+
"dev": "vp pack --watch"
|
|
75
75
|
}
|
|
76
76
|
}
|
package/lib/api.cjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __objRest = (source, exclude) => {
|
|
24
|
-
var target = {};
|
|
25
|
-
for (var prop in source)
|
|
26
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
-
target[prop] = source[prop];
|
|
28
|
-
if (source != null && __getOwnPropSymbols)
|
|
29
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
-
target[prop] = source[prop];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
var __export = (target, all) => {
|
|
36
|
-
for (var name in all)
|
|
37
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
-
};
|
|
39
|
-
var __copyProps = (to, from, except, desc) => {
|
|
40
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
-
for (let key of __getOwnPropNames(from))
|
|
42
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
-
}
|
|
45
|
-
return to;
|
|
46
|
-
};
|
|
47
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
-
|
|
49
|
-
// src/api.ts
|
|
50
|
-
var api_exports = {};
|
|
51
|
-
__export(api_exports, {
|
|
52
|
-
createApi: () => createApi
|
|
53
|
-
});
|
|
54
|
-
module.exports = __toCommonJS(api_exports);
|
|
55
|
-
var import_rattail = require("rattail");
|
|
56
|
-
function createApi(axle, useAxle) {
|
|
57
|
-
return function api(url, method) {
|
|
58
|
-
function load(params, pathParams, config) {
|
|
59
|
-
return axle[method](patchUrl(url, pathParams != null ? pathParams : {}), params, config);
|
|
60
|
-
}
|
|
61
|
-
function use(options = {}) {
|
|
62
|
-
const _a = options, { pathParams = {}, watch: watchOptions } = _a, rest = __objRest(_a, ["pathParams", "watch"]);
|
|
63
|
-
const enableWatchPathParams = (0, import_rattail.isFunction)(pathParams) && ((watchOptions == null ? void 0 : watchOptions.pathParams) || watchOptions === true);
|
|
64
|
-
const normalizedWatchOptions = watchOptions === true ? { params: true, config: true, _custom: enableWatchPathParams ? pathParams : void 0 } : watchOptions === false ? { params: false, config: false } : __spreadProps(__spreadValues({ params: false, config: false }, watchOptions), { _custom: enableWatchPathParams ? pathParams : void 0 });
|
|
65
|
-
return useAxle(__spreadValues({
|
|
66
|
-
url: () => patchUrl(url, pathParams),
|
|
67
|
-
method,
|
|
68
|
-
watch: normalizedWatchOptions
|
|
69
|
-
}, rest));
|
|
70
|
-
}
|
|
71
|
-
function patchUrl(url2, pathParams) {
|
|
72
|
-
const params = (0, import_rattail.isFunction)(pathParams) ? pathParams() : pathParams;
|
|
73
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
74
|
-
url2 = url2.replace(`:${key}`, value);
|
|
75
|
-
});
|
|
76
|
-
return url2;
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
url,
|
|
80
|
-
load,
|
|
81
|
-
use,
|
|
82
|
-
patchUrl
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
createApi
|
|
89
|
-
});
|
package/lib/api.d.cts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-857fe07c.js';
|
|
2
|
-
import { WatchOptions, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxle, UseAxleInstance } from './use.cjs';
|
|
3
|
-
import 'axios';
|
|
4
|
-
import 'vue';
|
|
5
|
-
|
|
6
|
-
type ApiPathParams = Record<string, any> | (() => Record<string, any>);
|
|
7
|
-
type ApiWatchOptions = WatchOptions & {
|
|
8
|
-
pathParams?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type ApiUseOptions<V, R, P, D> = Partial<UseAxleOptions<V, R, P, D>> & {
|
|
11
|
-
pathParams?: ApiPathParams;
|
|
12
|
-
watch?: ApiWatchOptions;
|
|
13
|
-
};
|
|
14
|
-
type ApiUseOptionsWithRunnable<V, R, P, D> = Partial<Omit<UseAxleOptionsWithRunnable<V, R, P, D>, 'runnable'>> & Pick<UseAxleOptionsWithRunnable<V, R, P, D>, 'runnable'> & {
|
|
15
|
-
pathParams?: ApiPathParams;
|
|
16
|
-
watch?: ApiWatchOptions;
|
|
17
|
-
};
|
|
18
|
-
declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>, D = Record<string, any>>(url: string, method: RunnerMethod) => {
|
|
19
|
-
url: string;
|
|
20
|
-
load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig<D, Record<string, any>> | undefined) => Promise<R>;
|
|
21
|
-
use: {
|
|
22
|
-
<V = R>(options?: ApiUseOptionsWithRunnable<V, R, P, D> | undefined): UseAxleInstance<V, R | undefined, P, D>;
|
|
23
|
-
<V_1 = R>(options?: ApiUseOptions<V_1, R, P, D> | undefined): UseAxleInstance<V_1, R, P, D>;
|
|
24
|
-
};
|
|
25
|
-
patchUrl: (url: string, pathParams: ApiPathParams) => string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { ApiPathParams, ApiUseOptions, ApiUseOptionsWithRunnable, ApiWatchOptions, createApi };
|
package/lib/api.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { e as AxleInstance, d as RunnerMethod, A as AxleRequestConfig } from './instance-857fe07c.js';
|
|
2
|
-
import { WatchOptions, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxle, UseAxleInstance } from './use.js';
|
|
3
|
-
import 'axios';
|
|
4
|
-
import 'vue';
|
|
5
|
-
|
|
6
|
-
type ApiPathParams = Record<string, any> | (() => Record<string, any>);
|
|
7
|
-
type ApiWatchOptions = WatchOptions & {
|
|
8
|
-
pathParams?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type ApiUseOptions<V, R, P, D> = Partial<UseAxleOptions<V, R, P, D>> & {
|
|
11
|
-
pathParams?: ApiPathParams;
|
|
12
|
-
watch?: ApiWatchOptions;
|
|
13
|
-
};
|
|
14
|
-
type ApiUseOptionsWithRunnable<V, R, P, D> = Partial<Omit<UseAxleOptionsWithRunnable<V, R, P, D>, 'runnable'>> & Pick<UseAxleOptionsWithRunnable<V, R, P, D>, 'runnable'> & {
|
|
15
|
-
pathParams?: ApiPathParams;
|
|
16
|
-
watch?: ApiWatchOptions;
|
|
17
|
-
};
|
|
18
|
-
declare function createApi(axle: AxleInstance, useAxle: UseAxle): <R = any, P = Record<string, any>, D = Record<string, any>>(url: string, method: RunnerMethod) => {
|
|
19
|
-
url: string;
|
|
20
|
-
load: (params?: P | undefined, pathParams?: ApiPathParams, config?: AxleRequestConfig<D, Record<string, any>> | undefined) => Promise<R>;
|
|
21
|
-
use: {
|
|
22
|
-
<V = R>(options?: ApiUseOptionsWithRunnable<V, R, P, D> | undefined): UseAxleInstance<V, R | undefined, P, D>;
|
|
23
|
-
<V_1 = R>(options?: ApiUseOptions<V_1, R, P, D> | undefined): UseAxleInstance<V_1, R, P, D>;
|
|
24
|
-
};
|
|
25
|
-
patchUrl: (url: string, pathParams: ApiPathParams) => string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { ApiPathParams, ApiUseOptions, ApiUseOptionsWithRunnable, ApiWatchOptions, createApi };
|
package/lib/api.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__objRest,
|
|
3
|
-
__spreadProps,
|
|
4
|
-
__spreadValues
|
|
5
|
-
} from "./chunk-G2ADBYYC.js";
|
|
6
|
-
|
|
7
|
-
// src/api.ts
|
|
8
|
-
import { isFunction } from "rattail";
|
|
9
|
-
function createApi(axle, useAxle) {
|
|
10
|
-
return function api(url, method) {
|
|
11
|
-
function load(params, pathParams, config) {
|
|
12
|
-
return axle[method](patchUrl(url, pathParams != null ? pathParams : {}), params, config);
|
|
13
|
-
}
|
|
14
|
-
function use(options = {}) {
|
|
15
|
-
const _a = options, { pathParams = {}, watch: watchOptions } = _a, rest = __objRest(_a, ["pathParams", "watch"]);
|
|
16
|
-
const enableWatchPathParams = isFunction(pathParams) && ((watchOptions == null ? void 0 : watchOptions.pathParams) || watchOptions === true);
|
|
17
|
-
const normalizedWatchOptions = watchOptions === true ? { params: true, config: true, _custom: enableWatchPathParams ? pathParams : void 0 } : watchOptions === false ? { params: false, config: false } : __spreadProps(__spreadValues({ params: false, config: false }, watchOptions), { _custom: enableWatchPathParams ? pathParams : void 0 });
|
|
18
|
-
return useAxle(__spreadValues({
|
|
19
|
-
url: () => patchUrl(url, pathParams),
|
|
20
|
-
method,
|
|
21
|
-
watch: normalizedWatchOptions
|
|
22
|
-
}, rest));
|
|
23
|
-
}
|
|
24
|
-
function patchUrl(url2, pathParams) {
|
|
25
|
-
const params = isFunction(pathParams) ? pathParams() : pathParams;
|
|
26
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
27
|
-
url2 = url2.replace(`:${key}`, value);
|
|
28
|
-
});
|
|
29
|
-
return url2;
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
url,
|
|
33
|
-
load,
|
|
34
|
-
use,
|
|
35
|
-
patchUrl
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
createApi
|
|
41
|
-
};
|
package/lib/chunk-G2ADBYYC.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
__spreadValues,
|
|
35
|
-
__spreadProps,
|
|
36
|
-
__objRest
|
|
37
|
-
};
|