@ciwergrp/nuxid 1.17.2 → 1.17.4
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/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -599,7 +599,7 @@ function registerFetcherFeature(options, { from }) {
|
|
|
599
599
|
if (!options.enabled) {
|
|
600
600
|
return;
|
|
601
601
|
}
|
|
602
|
-
addImports({ name: "
|
|
602
|
+
addImports({ name: "default", as: "useCursorHttp", from });
|
|
603
603
|
addImports({ name: "APIResponseCursor", as: "APIResponseCursor", from, type: true });
|
|
604
604
|
addImports({ name: "CursorFetchOptions", as: "CursorFetchOptions", from, type: true });
|
|
605
605
|
}
|
|
@@ -19,7 +19,6 @@ export interface CursorFetchOptions<TRequest extends NitroFetchRequest = NitroFe
|
|
|
19
19
|
itemKey?: string;
|
|
20
20
|
cursorParam?: string;
|
|
21
21
|
query?: Record<string, any>;
|
|
22
|
-
key?: string;
|
|
23
22
|
}
|
|
24
23
|
export interface FetchError<TData = any> {
|
|
25
24
|
statusCode: number | undefined;
|
|
@@ -44,3 +43,4 @@ export declare function useCursorHttp<T extends Record<string, any> = any, TResp
|
|
|
44
43
|
refresh: () => Promise<void>;
|
|
45
44
|
init: () => Promise<void>;
|
|
46
45
|
}>;
|
|
46
|
+
export default useCursorHttp;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { isRef, onUnmounted, readonly, ref, shallowRef, watch } from "vue";
|
|
1
|
+
import { isRef, onBeforeMount, onUnmounted, readonly, ref, shallowRef, watch } from "vue";
|
|
2
2
|
export async function useCursorHttp(url, options) {
|
|
3
3
|
function findReactiveSources(obj) {
|
|
4
4
|
const sources = [];
|
|
5
5
|
if (!obj || typeof obj !== "object") {
|
|
6
6
|
return sources;
|
|
7
7
|
}
|
|
8
|
-
for (const
|
|
9
|
-
if (Object.prototype.hasOwnProperty.call(obj,
|
|
10
|
-
const value = obj[
|
|
8
|
+
for (const key in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
10
|
+
const value = obj[key];
|
|
11
11
|
if (isRef(value)) {
|
|
12
12
|
sources.push(value);
|
|
13
13
|
} else if (typeof value === "object") {
|
|
@@ -22,15 +22,15 @@ export async function useCursorHttp(url, options) {
|
|
|
22
22
|
return obj;
|
|
23
23
|
}
|
|
24
24
|
const unwrapped = Array.isArray(obj) ? [] : {};
|
|
25
|
-
for (const
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(obj,
|
|
27
|
-
const value = obj[
|
|
25
|
+
for (const key in obj) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
27
|
+
const value = obj[key];
|
|
28
28
|
if (isRef(value)) {
|
|
29
|
-
unwrapped[
|
|
29
|
+
unwrapped[key] = value.value;
|
|
30
30
|
} else if (typeof value === "object") {
|
|
31
|
-
unwrapped[
|
|
31
|
+
unwrapped[key] = unwrapReactiveObject(value);
|
|
32
32
|
} else {
|
|
33
|
-
unwrapped[
|
|
33
|
+
unwrapped[key] = value;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -58,8 +58,7 @@ export async function useCursorHttp(url, options) {
|
|
|
58
58
|
fetchOptions,
|
|
59
59
|
meta,
|
|
60
60
|
itemKey = "id",
|
|
61
|
-
cursorParam = "cursor"
|
|
62
|
-
key
|
|
61
|
+
cursorParam = "cursor"
|
|
63
62
|
} = options ?? {};
|
|
64
63
|
const initialUrl = url;
|
|
65
64
|
const data = ref();
|
|
@@ -131,6 +130,7 @@ export async function useCursorHttp(url, options) {
|
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
};
|
|
133
|
+
const initialFetch = () => fetchData(initialUrl, currentParams.value);
|
|
134
134
|
const pollData = async () => {
|
|
135
135
|
try {
|
|
136
136
|
const response = await fetcherFn(initialUrl, currentParams.value);
|
|
@@ -201,43 +201,12 @@ export async function useCursorHttp(url, options) {
|
|
|
201
201
|
}
|
|
202
202
|
});
|
|
203
203
|
if (immediate) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
asyncKey,
|
|
208
|
-
() => fetcherFn(initialUrl, currentParams.value),
|
|
209
|
-
{ lazy: true }
|
|
210
|
-
);
|
|
211
|
-
watch(asyncPending, (v) => loading.value = v, { immediate: true });
|
|
212
|
-
watch(asyncData, (val) => {
|
|
213
|
-
if (val) {
|
|
214
|
-
const response = val;
|
|
215
|
-
data.value = { ...response, data: [...response.data] };
|
|
216
|
-
nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
|
|
217
|
-
hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
watch(asyncError, (val) => {
|
|
221
|
-
if (val) {
|
|
222
|
-
error.value = normalizeFetchError(val);
|
|
223
|
-
}
|
|
204
|
+
if (import.meta.client && lazy) {
|
|
205
|
+
onBeforeMount(() => {
|
|
206
|
+
void initialFetch();
|
|
224
207
|
});
|
|
225
208
|
} else {
|
|
226
|
-
|
|
227
|
-
const { data: asyncData, error: asyncError } = await useAsyncData(
|
|
228
|
-
asyncKey,
|
|
229
|
-
() => fetcherFn(initialUrl, currentParams.value)
|
|
230
|
-
);
|
|
231
|
-
loading.value = false;
|
|
232
|
-
if (asyncData.value) {
|
|
233
|
-
const val = asyncData.value;
|
|
234
|
-
data.value = { ...val, data: [...val.data] };
|
|
235
|
-
nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
|
|
236
|
-
hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
|
|
237
|
-
}
|
|
238
|
-
if (asyncError.value) {
|
|
239
|
-
error.value = normalizeFetchError(asyncError.value);
|
|
240
|
-
}
|
|
209
|
+
await initialFetch();
|
|
241
210
|
}
|
|
242
211
|
}
|
|
243
212
|
return {
|
|
@@ -251,3 +220,4 @@ export async function useCursorHttp(url, options) {
|
|
|
251
220
|
init
|
|
252
221
|
};
|
|
253
222
|
}
|
|
223
|
+
export default useCursorHttp;
|