grab-url 1.5.4 → 1.5.5

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "grab-url",
3
3
  "description": "📥 Generate Request to API from Browser",
4
4
  "type": "module",
5
- "version": "1.5.4",
5
+ "version": "1.5.5",
6
6
  "author": "vtempest",
7
7
  "license": "rights.institute/prosper",
8
8
  "repository": {
package/readme.md CHANGED
@@ -14,8 +14,8 @@
14
14
  <a href="https://codespaces.new/vtempest/GRAB-URL"><img src="https://github.com/codespaces/badge.svg" width="150" height="20"/></a>
15
15
  </p>
16
16
  <h3 align="center">
17
- <a href="https://grab.js.org"> 📑 Docs (grab.js.org)</a>
18
- <a href="https://grab.js.org/docs/Examples"> 🎯 Example Strategies </a>
17
+ <a href="https://grab-url.vercel.app"> 📑 Docs </a>
18
+ <a href="https://grab-url.vercel.app/docs/Examples/basic"> 🎯 Example Strategies </a>
19
19
  </h3>
20
20
 
21
21
  ```bash
@@ -36,36 +36,35 @@ export async function grab<TResponse = any, TParams = any>(
36
36
  headers, response: responseOption, method = merged.post ? "POST" : merged.put ? "PUT" : merged.patch ? "PATCH" : "GET",
37
37
  cache, timeout = 30, baseURL = (typeof process !== "undefined" && process.env.SERVER_API_URL) || "/api/",
38
38
  cancelOngoingIfNew, cancelNewIfOngoing, rateLimit, debug, infiniteScroll, logger = log,
39
- onRequest, onResponse, onError, onStream, body, ...params
39
+ onRequest, onResponse, onError, onStream, body, post, put, patch, ...params
40
40
  } = merged;
41
41
 
42
42
  const urlConfig = buildUrl(baseURL, path);
43
43
  baseURL = urlConfig.baseURL;
44
44
  path = urlConfig.path;
45
45
 
46
- let response: any = {};
47
- let resFunction: ((data: any) => any) | null = null;
46
+ const initialized = initializeResponse(responseOption);
47
+ let response: any = initialized.response;
48
+ let resFunction = initialized.resFunction;
48
49
  const target = (typeof window !== "undefined" ? window.grab : (globalThis as any).grab) as GrabFunction;
49
50
  const grabLog = target?.log || [];
50
51
 
52
+ // Set loading state synchronously before any await
53
+ if (resFunction) response = resFunction({ ...response, isLoading: true });
54
+ else if (typeof response === "object") response.isLoading = true;
55
+
51
56
  try {
52
57
  const flowResult = await handleFlowControl(path, options || {}, merged, grab);
53
58
  if (flowResult) return flowResult as any;
54
59
 
55
60
  handleRegrabEvents(path, options || {}, merged, grab);
56
61
 
57
- ({ response, resFunction } = initializeResponse(responseOption));
58
-
59
62
  let { params: updatedParams, priorRequest, response: updatedResponse, paramsAsText } = manageCacheAndPagination(path, params, merged, response, resFunction, grabLog);
60
63
  params = updatedParams;
61
64
  response = updatedResponse;
62
65
 
63
66
  setupInfiniteScroll(path, options, infiniteScroll, priorRequest, grab);
64
67
 
65
- // Set loading state
66
- if (resFunction) response = resFunction({ ...response, isLoading: true });
67
- else if (typeof response === "object") response.isLoading = true;
68
-
69
68
  if (rateLimit > 0 && priorRequest?.lastFetchTime > Date.now() - 1000 * rateLimit) {
70
69
  throw new Error(`Fetch rate limit exceeded for ${path}. Wait ${rateLimit}s between requests.`);
71
70
  }