@ciwergrp/nuxid 1.16.7 → 1.17.1

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.16.7",
4
+ "version": "1.17.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -19,6 +19,7 @@ export interface CursorFetchOptions<TRequest extends NitroFetchRequest = NitroFe
19
19
  itemKey?: string;
20
20
  cursorParam?: string;
21
21
  query?: Record<string, any>;
22
+ key?: string;
22
23
  }
23
24
  export interface FetchError<TData = any> {
24
25
  statusCode: number | undefined;
@@ -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 key in obj) {
9
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
10
- const value = obj[key];
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 key in obj) {
26
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
27
- const value = obj[key];
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[key] = value.value;
29
+ unwrapped[key2] = value.value;
30
30
  } else if (typeof value === "object") {
31
- unwrapped[key] = unwrapReactiveObject(value);
31
+ unwrapped[key2] = unwrapReactiveObject(value);
32
32
  } else {
33
- unwrapped[key] = value;
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();
@@ -196,10 +197,43 @@ export async function useCursorHttp(url, options) {
196
197
  }
197
198
  });
198
199
  if (immediate) {
200
+ const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
199
201
  if (lazy) {
200
- void init();
202
+ const { data: asyncData, error: asyncError, pending: asyncPending } = useAsyncData(
203
+ asyncKey,
204
+ () => fetcherFn(initialUrl, currentParams.value),
205
+ { lazy: true }
206
+ );
207
+ watch(asyncPending, (v) => loading.value = v, { immediate: true });
208
+ watch(asyncData, (val) => {
209
+ if (val) {
210
+ const response = val;
211
+ data.value = { ...response, data: [...response.data] };
212
+ nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
213
+ hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
214
+ }
215
+ });
216
+ watch(asyncError, (val) => {
217
+ if (val) {
218
+ error.value = normalizeFetchError(val);
219
+ }
220
+ });
201
221
  } else {
202
- await init();
222
+ loading.value = true;
223
+ const { data: asyncData, error: asyncError } = await useAsyncData(
224
+ asyncKey,
225
+ () => fetcherFn(initialUrl, currentParams.value)
226
+ );
227
+ loading.value = false;
228
+ if (asyncData.value) {
229
+ const val = asyncData.value;
230
+ data.value = { ...val, data: [...val.data] };
231
+ nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
232
+ hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
233
+ }
234
+ if (asyncError.value) {
235
+ error.value = normalizeFetchError(asyncError.value);
236
+ }
203
237
  }
204
238
  }
205
239
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.16.7",
3
+ "version": "1.17.1",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",