@nice-code/action 0.2.14 → 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.
package/build/index.js CHANGED
@@ -311,7 +311,9 @@ class ActionPayload_Request extends ActionPayload {
311
311
  return value.waitForResultPayload();
312
312
  }
313
313
  async run(options) {
314
- this._callSite = new Error().stack;
314
+ if (this._callSite == null) {
315
+ this._callSite = new Error().stack;
316
+ }
315
317
  return this._domain.runAction(this, options);
316
318
  }
317
319
  }
@@ -2,17 +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";
34
+ import { useRef as useRef2 } from "react";
16
35
  function actionQueryKey(action, input) {
17
36
  if (input === undefined) {
18
37
  return ["nice-action", action.domain, action.allDomains, action.id];
@@ -29,9 +48,14 @@ function useActionQuery(action, ...args) {
29
48
  [options] = args;
30
49
  }
31
50
  const { enabled, ...queryOptions } = options ?? {};
51
+ const callSiteRef = useRef2(new Error().stack);
32
52
  return useQuery({
33
53
  queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),
34
- queryFn: () => action.request(input).runToOutput(),
54
+ queryFn: () => {
55
+ const req = action.request(input);
56
+ req._callSite = callSiteRef.current;
57
+ return req.runToOutput();
58
+ },
35
59
  enabled: hasInputSchema ? input != null && (enabled ?? true) : enabled ?? true,
36
60
  ...queryOptions
37
61
  });
@@ -0,0 +1,6 @@
1
+ export interface IResolvedSourcePosition {
2
+ file: string;
3
+ line: number;
4
+ col: number;
5
+ }
6
+ export declare function resolveCompiledPosition(fileUrl: string, line: number, col: number): Promise<IResolvedSourcePosition | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-code/action",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -44,12 +44,13 @@
44
44
  "build-types": "tsc --project tsconfig.build.json"
45
45
  },
46
46
  "dependencies": {
47
- "@nice-code/common-errors": "0.2.14",
48
- "@nice-code/error": "0.2.14",
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",
52
52
  "nanoid": "^5.1.9",
53
+ "source-map-js": "^1.2.1",
53
54
  "std-env": "^4.1.0"
54
55
  },
55
56
  "devDependencies": {