@ciwergrp/nuxid 1.16.7 → 1.17.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/module.json
CHANGED
|
@@ -5,9 +5,9 @@ export async function useCursorHttp(url, options) {
|
|
|
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 key2 in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
10
|
+
const value = obj[key2];
|
|
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 key2 in obj) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
27
|
+
const value = obj[key2];
|
|
28
28
|
if (isRef(value)) {
|
|
29
|
-
unwrapped[
|
|
29
|
+
unwrapped[key2] = value.value;
|
|
30
30
|
} else if (typeof value === "object") {
|
|
31
|
-
unwrapped[
|
|
31
|
+
unwrapped[key2] = unwrapReactiveObject(value);
|
|
32
32
|
} else {
|
|
33
|
-
unwrapped[
|
|
33
|
+
unwrapped[key2] = value;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -58,7 +58,8 @@ export async function useCursorHttp(url, options) {
|
|
|
58
58
|
fetchOptions,
|
|
59
59
|
meta,
|
|
60
60
|
itemKey = "id",
|
|
61
|
-
cursorParam = "cursor"
|
|
61
|
+
cursorParam = "cursor",
|
|
62
|
+
key
|
|
62
63
|
} = options ?? {};
|
|
63
64
|
const initialUrl = url;
|
|
64
65
|
const data = ref();
|
|
@@ -199,7 +200,27 @@ export async function useCursorHttp(url, options) {
|
|
|
199
200
|
if (lazy) {
|
|
200
201
|
void init();
|
|
201
202
|
} else {
|
|
202
|
-
|
|
203
|
+
const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
|
|
204
|
+
try {
|
|
205
|
+
const { useAsyncData } = await import("#app");
|
|
206
|
+
loading.value = true;
|
|
207
|
+
const { data: asyncData, error: asyncError } = await useAsyncData(
|
|
208
|
+
asyncKey,
|
|
209
|
+
() => fetcherFn(initialUrl, currentParams.value)
|
|
210
|
+
);
|
|
211
|
+
loading.value = false;
|
|
212
|
+
if (asyncData.value) {
|
|
213
|
+
const val = asyncData.value;
|
|
214
|
+
data.value = { ...val, data: [...val.data] };
|
|
215
|
+
nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
|
|
216
|
+
hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
|
|
217
|
+
}
|
|
218
|
+
if (asyncError.value) {
|
|
219
|
+
error.value = normalizeFetchError(asyncError.value);
|
|
220
|
+
}
|
|
221
|
+
} catch {
|
|
222
|
+
await init();
|
|
223
|
+
}
|
|
203
224
|
}
|
|
204
225
|
}
|
|
205
226
|
return {
|