@nice-code/action 0.2.15 → 0.2.16

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.
@@ -2,18 +2,36 @@
2
2
  import {
3
3
  useMutation
4
4
  } from "@tanstack/react-query";
5
+ import { useRef } from "react";
5
6
  function useActionMutation(action, options) {
6
7
  const mutationOptions = options ?? {};
7
- return useMutation({
8
- mutationFn: (input) => action.request(input).runToOutput(),
8
+ const callSiteRef = useRef(undefined);
9
+ const result = useMutation({
10
+ mutationFn: (input) => {
11
+ const req = action.request(input);
12
+ req._callSite = callSiteRef.current;
13
+ callSiteRef.current = undefined;
14
+ return req.runToOutput();
15
+ },
9
16
  ...mutationOptions
10
17
  });
18
+ return {
19
+ ...result,
20
+ mutate: (...args) => {
21
+ callSiteRef.current = new Error().stack;
22
+ return result.mutate(...args);
23
+ },
24
+ mutateAsync: (...args) => {
25
+ callSiteRef.current = new Error().stack;
26
+ return result.mutateAsync(...args);
27
+ }
28
+ };
11
29
  }
12
30
  // src/react-query/hooks/useActionQuery.ts
13
31
  import {
14
32
  useQuery
15
33
  } from "@tanstack/react-query";
16
- import { useRef } from "react";
34
+ import { useRef as useRef2 } from "react";
17
35
  function actionQueryKey(action, input) {
18
36
  if (input === undefined) {
19
37
  return ["nice-action", action.domain, action.allDomains, action.id];
@@ -30,7 +48,7 @@ function useActionQuery(action, ...args) {
30
48
  [options] = args;
31
49
  }
32
50
  const { enabled, ...queryOptions } = options ?? {};
33
- const callSiteRef = useRef(new Error().stack);
51
+ const callSiteRef = useRef2(new Error().stack);
34
52
  return useQuery({
35
53
  queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),
36
54
  queryFn: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-code/action",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -44,8 +44,8 @@
44
44
  "build-types": "tsc --project tsconfig.build.json"
45
45
  },
46
46
  "dependencies": {
47
- "@nice-code/common-errors": "0.2.15",
48
- "@nice-code/error": "0.2.15",
47
+ "@nice-code/common-errors": "0.2.16",
48
+ "@nice-code/error": "0.2.16",
49
49
  "@standard-schema/spec": "^1.1.0",
50
50
  "@tanstack/react-virtual": "^3.13.26",
51
51
  "http-status-codes": "^2.3.0",