@nice-code/action 0.2.10 → 0.2.12

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.
@@ -1,3 +1,43 @@
1
- // src/react-query/index.ts
2
- export * from "./hooks/useActionMutation";
3
- export * from "./hooks/useActionQuery";
1
+ // src/react-query/hooks/useActionMutation.ts
2
+ import {
3
+ useMutation
4
+ } from "@tanstack/react-query";
5
+ function useActionMutation(action, options) {
6
+ const mutationOptions = options ?? {};
7
+ return useMutation({
8
+ mutationFn: (input) => action.request(input).runToOutput(),
9
+ ...mutationOptions
10
+ });
11
+ }
12
+ // src/react-query/hooks/useActionQuery.ts
13
+ import {
14
+ useQuery
15
+ } from "@tanstack/react-query";
16
+ function actionQueryKey(action, input) {
17
+ if (input === undefined) {
18
+ return ["nice-action", action.domain, action.allDomains, action.id];
19
+ }
20
+ return ["nice-action", action.domain, action.allDomains, action.id, input];
21
+ }
22
+ function useActionQuery(action, ...args) {
23
+ const hasInputSchema = action.schema.inputSchema != null;
24
+ let input;
25
+ let options;
26
+ if (hasInputSchema) {
27
+ [input, options] = args;
28
+ } else {
29
+ [options] = args;
30
+ }
31
+ const { enabled, ...queryOptions } = options ?? {};
32
+ return useQuery({
33
+ queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),
34
+ queryFn: () => action.request(input).runToOutput(),
35
+ enabled: hasInputSchema ? input != null && (enabled ?? true) : enabled ?? true,
36
+ ...queryOptions
37
+ });
38
+ }
39
+ export {
40
+ useActionQuery,
41
+ useActionMutation,
42
+ actionQueryKey
43
+ };
@@ -5,7 +5,7 @@ import type { IActionDomain } from "../ActionDefinition/Domain/ActionDomain.type
5
5
  import type { IRuntimeMeta, TActionRuntimeHandler } from "./ActionRuntime.types";
6
6
  import { type IHandleActionOptions, type TActionHandler } from "./Handler/ActionHandler.types";
7
7
  import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
8
- import { RuntimeCoordinate } from "./RuntimeCoordinate";
8
+ import { type IRuntimeCoordinateSpecifics, RuntimeCoordinate } from "./RuntimeCoordinate";
9
9
  export declare class ActionRuntime {
10
10
  private _coordinate;
11
11
  readonly timeCreated: number;
@@ -17,7 +17,9 @@ export declare class ActionRuntime {
17
17
  static getDefault(): ActionRuntime;
18
18
  constructor(coordinate: RuntimeCoordinate);
19
19
  get coordinate(): RuntimeCoordinate;
20
- updateRuntimeCoordinate(newCoordinate: RuntimeCoordinate): void;
20
+ specifyRuntimeCoordinate(specifics: IRuntimeCoordinateSpecifics & {
21
+ envId?: string;
22
+ }): void;
21
23
  registerRunningAction(ra: RunningAction<any, any>): void;
22
24
  resolveIncomingActionPayload(json: TActionPayload_Any_JsonObject<any, any>): void;
23
25
  /**
@@ -1,8 +1,4 @@
1
- export interface IRuntimeCoordinate {
2
- /**
3
- * A static runtime environment identifier (e.g. "web_app_v1", "backend_analytics")
4
- */
5
- envId: string;
1
+ export interface IRuntimeCoordinateSpecifics {
6
2
  /**
7
3
  * A unique and persistent client ID (should stay the same between runtime instance reloads)
8
4
  */
@@ -13,6 +9,12 @@ export interface IRuntimeCoordinate {
13
9
  */
14
10
  insId?: string;
15
11
  }
12
+ export interface IRuntimeCoordinate extends IRuntimeCoordinateSpecifics {
13
+ /**
14
+ * A static runtime environment identifier (e.g. "web_app_v1", "backend_analytics")
15
+ */
16
+ envId: string;
17
+ }
16
18
  export type TRuntimeCoordinateEnvId = `envId[${string}]`;
17
19
  export type TRuntimeCoordinateStringId = `${TRuntimeCoordinateEnvId}perId[${string | "_"}]:insId[${string | "_"}]`;
18
20
  export interface IRuntimeFullCoordinates extends Required<IRuntimeCoordinate> {
@@ -25,8 +27,8 @@ export declare class RuntimeCoordinate implements IRuntimeCoordinate {
25
27
  static env(envId: string): RuntimeCoordinate;
26
28
  withPersistentId(perId: string): RuntimeCoordinate;
27
29
  constructor({ envId, perId, insId }: IRuntimeCoordinate);
28
- specify(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
29
- specifyIfUnset(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
30
+ specify(specifics: IRuntimeCoordinateSpecifics): RuntimeCoordinate;
31
+ specifyIfUnset(specifics: IRuntimeCoordinateSpecifics): RuntimeCoordinate;
30
32
  toJsonObject(): IRuntimeCoordinate;
31
33
  isExactlySame(other: IRuntimeCoordinate): boolean;
32
34
  isSameFor(other: IRuntimeCoordinate): {
@@ -0,0 +1,8 @@
1
+ import type { TDevtoolsPosition } from "../core/ActionDevtools.types";
2
+ import type { ActionDevtoolsCore } from "../core/ActionDevtoolsCore";
3
+ export interface INiceActionDevtoolsProps {
4
+ core: ActionDevtoolsCore;
5
+ position?: TDevtoolsPosition;
6
+ initialOpen?: boolean;
7
+ }
8
+ export declare function NiceActionDevtools(props: INiceActionDevtoolsProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,3 @@
1
+ export type { IDevtoolsActionEntry, IDevtoolsObservableDomain, TDevtoolsActionStatus, TDevtoolsListener, } from "../core/ActionDevtools.types";
2
+ export { ActionDevtoolsCore, type IActionDevtoolsCoreOptions } from "../core/ActionDevtoolsCore";
3
+ export { type INiceActionDevtoolsProps, NiceActionDevtools } from "./NiceActionDevtools";
@@ -0,0 +1,47 @@
1
+ import type { TActionProgress } from "../../ActionDefinition/Action/Payload/ActionPayload.types";
2
+ export type TDevtoolsActionStatus = "running" | "success" | "failed" | "aborted";
3
+ export type TDevtoolsPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left" | "dock-bottom" | "dock-top" | "dock-left" | "dock-right";
4
+ export interface IDevtoolsRouteItem {
5
+ runtime: {
6
+ envId: string;
7
+ perId?: string;
8
+ insId?: string;
9
+ };
10
+ handlerType: "local" | "external";
11
+ handlerClient?: {
12
+ envId: string;
13
+ perId?: string;
14
+ insId?: string;
15
+ };
16
+ transport?: string;
17
+ time: number;
18
+ }
19
+ export interface IDevtoolsActionMeta {
20
+ timeCreated: number;
21
+ originClient: {
22
+ envId: string;
23
+ perId?: string;
24
+ insId?: string;
25
+ };
26
+ routing: IDevtoolsRouteItem[];
27
+ }
28
+ export interface IDevtoolsActionEntry {
29
+ cuid: string;
30
+ actionId: string;
31
+ domain: string;
32
+ allDomains: string[];
33
+ status: TDevtoolsActionStatus;
34
+ startTime: number;
35
+ endTime?: number;
36
+ input: unknown;
37
+ output?: unknown;
38
+ error?: unknown;
39
+ abortReason?: unknown;
40
+ progressUpdates: TActionProgress[];
41
+ meta: IDevtoolsActionMeta;
42
+ }
43
+ export type TDevtoolsListener = (entries: readonly IDevtoolsActionEntry[]) => void;
44
+ export interface IDevtoolsObservableDomain {
45
+ domain: string;
46
+ addActionListener(listener: (update: any) => void): () => void;
47
+ }
@@ -0,0 +1,16 @@
1
+ import type { IDevtoolsActionEntry, IDevtoolsObservableDomain, TDevtoolsListener } from "./ActionDevtools.types";
2
+ export interface IActionDevtoolsCoreOptions {
3
+ maxEntries?: number;
4
+ }
5
+ export declare class ActionDevtoolsCore {
6
+ private _entries;
7
+ private _listeners;
8
+ private readonly _maxEntries;
9
+ constructor(options?: IActionDevtoolsCoreOptions);
10
+ attachToDomain(domain: IDevtoolsObservableDomain): () => void;
11
+ getEntries(): readonly IDevtoolsActionEntry[];
12
+ subscribe(listener: TDevtoolsListener): () => void;
13
+ clear(): void;
14
+ private _updateEntry;
15
+ private _notify;
16
+ }
@@ -0,0 +1,30 @@
1
+ import type { IDevtoolsObservableDomain } from "../core/ActionDevtools.types";
2
+ export type TServerDevtoolsLogFn = (message: string, data?: Record<string, unknown>) => void;
3
+ export interface IActionServerDevtoolsOptions {
4
+ /**
5
+ * Custom logger function. Defaults to console.log / console.error.
6
+ */
7
+ logger?: TServerDevtoolsLogFn;
8
+ /**
9
+ * Output format.
10
+ * - "pretty": human-readable lines (default)
11
+ * - "json": newline-delimited JSON for log aggregators
12
+ */
13
+ format?: "pretty" | "json";
14
+ /**
15
+ * Whether to log action input/output payloads.
16
+ * Disable if payloads may contain sensitive data. Defaults to true.
17
+ */
18
+ logPayloads?: boolean;
19
+ /**
20
+ * Whether devtools are active. Defaults to process.env.NODE_ENV !== "production".
21
+ */
22
+ enabled?: boolean;
23
+ }
24
+ export declare class ActionServerDevtools {
25
+ private readonly _options;
26
+ private readonly _inFlight;
27
+ constructor(options?: IActionServerDevtoolsOptions);
28
+ attachToDomain(domain: IDevtoolsObservableDomain): () => void;
29
+ private _log;
30
+ }
@@ -0,0 +1,3 @@
1
+ export { ActionServerDevtools, type IActionServerDevtoolsOptions, type TServerDevtoolsLogFn, } from "./NiceActionServerDevtools";
2
+ export { ActionDevtoolsCore, type IActionDevtoolsCoreOptions } from "../core/ActionDevtoolsCore";
3
+ export type { IDevtoolsActionEntry, IDevtoolsObservableDomain, TDevtoolsActionStatus, TDevtoolsListener, } from "../core/ActionDevtools.types";
@@ -24,7 +24,7 @@ export type { TActionTransportDef } from "./ActionRuntime/Handler/ExternalClient
24
24
  export * from "./ActionRuntime/Handler/ExternalClient/Transport/Transport.types";
25
25
  export * from "./ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket";
26
26
  export { ActionLocalHandler, createLocalHandler, } from "./ActionRuntime/Handler/Local/ActionLocalHandler";
27
- export { type IRuntimeCoordinate, RuntimeCoordinate, } from "./ActionRuntime/RuntimeCoordinate";
27
+ export * from "./ActionRuntime/RuntimeCoordinate";
28
28
  export { EErrId_NiceAction, err_nice_action } from "./errors/err_nice_action";
29
29
  export { isActionPayload_Any_JsonObject } from "./utils/isActionPayload_Any_JsonObject";
30
30
  export * from "./utils/isActionPayload_Request_JsonObject";
package/package.json CHANGED
@@ -1,16 +1,28 @@
1
1
  {
2
2
  "name": "@nice-code/action",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
+ "source": "./src/index.ts",
8
9
  "types": "./build/types/index.d.ts",
9
10
  "import": "./build/index.js"
10
11
  },
11
12
  "./react-query": {
13
+ "source": "./src/react-query/index.ts",
12
14
  "types": "./build/types/react-query/index.d.ts",
13
15
  "import": "./build/react-query/index.js"
16
+ },
17
+ "./devtools/browser": {
18
+ "source": "./src/devtools/browser/index.ts",
19
+ "types": "./build/types/devtools/browser/index.d.ts",
20
+ "import": "./build/devtools/browser/index.js"
21
+ },
22
+ "./devtools/server": {
23
+ "source": "./src/devtools/server/index.ts",
24
+ "types": "./build/types/devtools/server/index.d.ts",
25
+ "import": "./build/devtools/server/index.js"
14
26
  }
15
27
  },
16
28
  "files": [
@@ -32,15 +44,17 @@
32
44
  "build-types": "tsc --project tsconfig.build.json"
33
45
  },
34
46
  "dependencies": {
35
- "@nice-code/error": "0.2.10",
36
- "@nice-code/common-errors": "0.2.10",
47
+ "@nice-code/common-errors": "0.2.12",
48
+ "@nice-code/error": "0.2.12",
37
49
  "@standard-schema/spec": "^1.1.0",
50
+ "@tanstack/react-virtual": "^3.13.26",
38
51
  "http-status-codes": "^2.3.0",
39
52
  "nanoid": "^5.1.9",
40
53
  "std-env": "^4.1.0"
41
54
  },
42
55
  "devDependencies": {
43
56
  "@tanstack/react-query": "^5.100.3",
57
+ "@types/react": "^19.0.0",
44
58
  "msw": "^2.13.6"
45
59
  },
46
60
  "peerDependencies": {