enlace 0.0.1-beta.11 → 0.0.1-beta.13

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/README.md CHANGED
@@ -341,7 +341,7 @@ function PostList({ posts }: { posts: Post[] }) {
341
341
 
342
342
  const handleDelete = (postId: number) => {
343
343
  // Pass the actual ID when triggering
344
- trigger({ pathParams: { id: postId } });
344
+ trigger({ params: { id: postId } });
345
345
  };
346
346
 
347
347
  return (
@@ -366,7 +366,7 @@ const { trigger } = useAPI(
366
366
  (api) => api.users[":userId"].posts[":postId"].delete
367
367
  );
368
368
 
369
- trigger({ pathParams: { userId: "1", postId: "42" } });
369
+ trigger({ params: { userId: "1", postId: "42" } });
370
370
  // → DELETE /users/1/posts/42
371
371
  ```
372
372
 
@@ -376,7 +376,7 @@ trigger({ pathParams: { userId: "1", postId: "42" } });
376
376
  const { trigger } = useAPI((api) => api.products[":id"].patch);
377
377
 
378
378
  trigger({
379
- pathParams: { id: "123" },
379
+ params: { id: "123" },
380
380
  body: { name: "Updated Product" },
381
381
  });
382
382
  // → PATCH /products/123 with body
@@ -618,7 +618,7 @@ type RequestOptions = {
618
618
  headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>); // Request headers
619
619
  tags?: string[]; // Cache tags (GET only)
620
620
  revalidateTags?: string[]; // Tags to invalidate after mutation
621
- pathParams?: Record<string, string | number>; // Dynamic path parameters
621
+ params?: Record<string, string | number>; // Dynamic path parameters
622
622
  };
623
623
  ```
624
624
 
@@ -15,9 +15,9 @@ type ReactRequestOptionsBase = {
15
15
  * Used to replace :paramName placeholders in the URL path.
16
16
  * @example
17
17
  * // With path api.products[':id'].delete
18
- * trigger({ pathParams: { id: '123' } }) // → DELETE /products/123
18
+ * trigger({ params: { id: '123' } }) // → DELETE /products/123
19
19
  */
20
- pathParams?: Record<string, string | number>;
20
+ params?: Record<string, string | number>;
21
21
  };
22
22
  /** Options for query mode hooks */
23
23
  type UseEnlaceQueryOptions = {
@@ -15,9 +15,9 @@ type ReactRequestOptionsBase = {
15
15
  * Used to replace :paramName placeholders in the URL path.
16
16
  * @example
17
17
  * // With path api.products[':id'].delete
18
- * trigger({ pathParams: { id: '123' } }) // → DELETE /products/123
18
+ * trigger({ params: { id: '123' } }) // → DELETE /products/123
19
19
  */
20
- pathParams?: Record<string, string | number>;
20
+ params?: Record<string, string | number>;
21
21
  };
22
22
  /** Options for query mode hooks */
23
23
  type UseEnlaceQueryOptions = {
@@ -52,6 +52,13 @@ function hookReducer(state, action) {
52
52
  fetching: true,
53
53
  error: void 0
54
54
  };
55
+ case "MUTATION_START":
56
+ return {
57
+ ...state,
58
+ loading: true,
59
+ fetching: true,
60
+ error: void 0
61
+ };
55
62
  case "FETCH_SUCCESS":
56
63
  return {
57
64
  loading: false,
@@ -178,12 +185,12 @@ function onRevalidate(callback) {
178
185
  }
179
186
 
180
187
  // src/react/useQueryMode.ts
181
- function resolvePath(path, pathParams) {
182
- if (!pathParams) return path;
188
+ function resolvePath(path, params) {
189
+ if (!params) return path;
183
190
  return path.map((segment) => {
184
191
  if (segment.startsWith(":")) {
185
192
  const paramName = segment.slice(1);
186
- const value = pathParams[paramName];
193
+ const value = params[paramName];
187
194
  if (value === void 0) {
188
195
  throw new Error(`Missing path parameter: ${paramName}`);
189
196
  }
@@ -196,10 +203,7 @@ function useQueryMode(api, trackedCall, options) {
196
203
  const { autoGenerateTags, staleTime, enabled } = options;
197
204
  const queryKey = createQueryKey(trackedCall);
198
205
  const requestOptions = trackedCall.options;
199
- const resolvedPath = resolvePath(
200
- trackedCall.path,
201
- requestOptions?.pathParams
202
- );
206
+ const resolvedPath = resolvePath(trackedCall.path, requestOptions?.params);
203
207
  const queryTags = requestOptions?.tags ?? (autoGenerateTags ? generateTags(resolvedPath) : []);
204
208
  const getCacheState = (includeNeedsFetch = false) => {
205
209
  const cached = getCache(queryKey);
@@ -242,23 +246,19 @@ function useQueryMode(api, trackedCall, options) {
242
246
  }
243
247
  const method = current[trackedCall.method];
244
248
  const fetchPromise = method(trackedCall.options).then((res) => {
245
- if (mountedRef.current) {
246
- setCache(queryKey, {
247
- data: res.error ? void 0 : res.data,
248
- error: res.error,
249
- timestamp: Date.now(),
250
- tags: queryTags
251
- });
252
- }
249
+ setCache(queryKey, {
250
+ data: res.error ? void 0 : res.data,
251
+ error: res.error,
252
+ timestamp: Date.now(),
253
+ tags: queryTags
254
+ });
253
255
  }).catch((err) => {
254
- if (mountedRef.current) {
255
- setCache(queryKey, {
256
- data: void 0,
257
- error: err,
258
- timestamp: Date.now(),
259
- tags: queryTags
260
- });
261
- }
256
+ setCache(queryKey, {
257
+ data: void 0,
258
+ error: err,
259
+ timestamp: Date.now(),
260
+ tags: queryTags
261
+ });
262
262
  });
263
263
  setCache(queryKey, {
264
264
  promise: fetchPromise,
@@ -329,12 +329,12 @@ function createTrackingProxy(onTrack) {
329
329
 
330
330
  // src/react/useSelectorMode.ts
331
331
  var import_react2 = require("react");
332
- function resolvePath2(path, pathParams) {
333
- if (!pathParams) return path;
332
+ function resolvePath2(path, params) {
333
+ if (!params) return path;
334
334
  return path.map((segment) => {
335
335
  if (segment.startsWith(":")) {
336
336
  const paramName = segment.slice(1);
337
- const value = pathParams[paramName];
337
+ const value = params[paramName];
338
338
  if (value === void 0) {
339
339
  throw new Error(`Missing path parameter: ${paramName}`);
340
340
  }
@@ -362,9 +362,9 @@ function useSelectorMode(config) {
362
362
  autoRevalidateRef.current = autoRevalidateTags;
363
363
  if (!triggerRef.current) {
364
364
  triggerRef.current = (async (...args) => {
365
- dispatch({ type: "FETCH_START" });
365
+ dispatch({ type: "MUTATION_START" });
366
366
  const options = args[0];
367
- const resolvedPath = resolvePath2(pathRef.current, options?.pathParams);
367
+ const resolvedPath = resolvePath2(pathRef.current, options?.params);
368
368
  let res;
369
369
  if (hasPathParams(pathRef.current)) {
370
370
  let current = apiRef.current;
@@ -27,6 +27,13 @@ function hookReducer(state, action) {
27
27
  fetching: true,
28
28
  error: void 0
29
29
  };
30
+ case "MUTATION_START":
31
+ return {
32
+ ...state,
33
+ loading: true,
34
+ fetching: true,
35
+ error: void 0
36
+ };
30
37
  case "FETCH_SUCCESS":
31
38
  return {
32
39
  loading: false,
@@ -153,12 +160,12 @@ function onRevalidate(callback) {
153
160
  }
154
161
 
155
162
  // src/react/useQueryMode.ts
156
- function resolvePath(path, pathParams) {
157
- if (!pathParams) return path;
163
+ function resolvePath(path, params) {
164
+ if (!params) return path;
158
165
  return path.map((segment) => {
159
166
  if (segment.startsWith(":")) {
160
167
  const paramName = segment.slice(1);
161
- const value = pathParams[paramName];
168
+ const value = params[paramName];
162
169
  if (value === void 0) {
163
170
  throw new Error(`Missing path parameter: ${paramName}`);
164
171
  }
@@ -171,10 +178,7 @@ function useQueryMode(api, trackedCall, options) {
171
178
  const { autoGenerateTags, staleTime, enabled } = options;
172
179
  const queryKey = createQueryKey(trackedCall);
173
180
  const requestOptions = trackedCall.options;
174
- const resolvedPath = resolvePath(
175
- trackedCall.path,
176
- requestOptions?.pathParams
177
- );
181
+ const resolvedPath = resolvePath(trackedCall.path, requestOptions?.params);
178
182
  const queryTags = requestOptions?.tags ?? (autoGenerateTags ? generateTags(resolvedPath) : []);
179
183
  const getCacheState = (includeNeedsFetch = false) => {
180
184
  const cached = getCache(queryKey);
@@ -217,23 +221,19 @@ function useQueryMode(api, trackedCall, options) {
217
221
  }
218
222
  const method = current[trackedCall.method];
219
223
  const fetchPromise = method(trackedCall.options).then((res) => {
220
- if (mountedRef.current) {
221
- setCache(queryKey, {
222
- data: res.error ? void 0 : res.data,
223
- error: res.error,
224
- timestamp: Date.now(),
225
- tags: queryTags
226
- });
227
- }
224
+ setCache(queryKey, {
225
+ data: res.error ? void 0 : res.data,
226
+ error: res.error,
227
+ timestamp: Date.now(),
228
+ tags: queryTags
229
+ });
228
230
  }).catch((err) => {
229
- if (mountedRef.current) {
230
- setCache(queryKey, {
231
- data: void 0,
232
- error: err,
233
- timestamp: Date.now(),
234
- tags: queryTags
235
- });
236
- }
231
+ setCache(queryKey, {
232
+ data: void 0,
233
+ error: err,
234
+ timestamp: Date.now(),
235
+ tags: queryTags
236
+ });
237
237
  });
238
238
  setCache(queryKey, {
239
239
  promise: fetchPromise,
@@ -304,12 +304,12 @@ function createTrackingProxy(onTrack) {
304
304
 
305
305
  // src/react/useSelectorMode.ts
306
306
  import { useRef as useRef2, useReducer as useReducer2 } from "react";
307
- function resolvePath2(path, pathParams) {
308
- if (!pathParams) return path;
307
+ function resolvePath2(path, params) {
308
+ if (!params) return path;
309
309
  return path.map((segment) => {
310
310
  if (segment.startsWith(":")) {
311
311
  const paramName = segment.slice(1);
312
- const value = pathParams[paramName];
312
+ const value = params[paramName];
313
313
  if (value === void 0) {
314
314
  throw new Error(`Missing path parameter: ${paramName}`);
315
315
  }
@@ -337,9 +337,9 @@ function useSelectorMode(config) {
337
337
  autoRevalidateRef.current = autoRevalidateTags;
338
338
  if (!triggerRef.current) {
339
339
  triggerRef.current = (async (...args) => {
340
- dispatch({ type: "FETCH_START" });
340
+ dispatch({ type: "MUTATION_START" });
341
341
  const options = args[0];
342
- const resolvedPath = resolvePath2(pathRef.current, options?.pathParams);
342
+ const resolvedPath = resolvePath2(pathRef.current, options?.params);
343
343
  let res;
344
344
  if (hasPathParams(pathRef.current)) {
345
345
  let current = apiRef.current;
package/dist/index.d.mts CHANGED
@@ -16,9 +16,9 @@ type ReactRequestOptionsBase = {
16
16
  * Used to replace :paramName placeholders in the URL path.
17
17
  * @example
18
18
  * // With path api.products[':id'].delete
19
- * trigger({ pathParams: { id: '123' } }) // → DELETE /products/123
19
+ * trigger({ params: { id: '123' } }) // → DELETE /products/123
20
20
  */
21
- pathParams?: Record<string, string | number>;
21
+ params?: Record<string, string | number>;
22
22
  };
23
23
  /** Options for createEnlaceHookReact factory */
24
24
  type EnlaceHookOptions = {
package/dist/index.d.ts CHANGED
@@ -16,9 +16,9 @@ type ReactRequestOptionsBase = {
16
16
  * Used to replace :paramName placeholders in the URL path.
17
17
  * @example
18
18
  * // With path api.products[':id'].delete
19
- * trigger({ pathParams: { id: '123' } }) // → DELETE /products/123
19
+ * trigger({ params: { id: '123' } }) // → DELETE /products/123
20
20
  */
21
- pathParams?: Record<string, string | number>;
21
+ params?: Record<string, string | number>;
22
22
  };
23
23
  /** Options for createEnlaceHookReact factory */
24
24
  type EnlaceHookOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enlace",
3
- "version": "0.0.1-beta.11",
3
+ "version": "0.0.1-beta.13",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"