@nice-code/action 0.0.20 → 0.1.0
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 +1235 -772
- package/build/react-query/index.js +3129 -0
- package/build/types/ActionDomain/NiceActionDomain.d.ts +18 -45
- package/build/types/ActionDomain/NiceActionDomain.types.d.ts +9 -50
- package/build/types/ActionDomain/NiceActionDomainBase.d.ts +14 -0
- package/build/types/ActionDomain/RootDomain/NiceActionRootDomain.d.ts +22 -0
- package/build/types/ActionDomain/helpers/createRootActionDomain.d.ts +5 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.d.ts +24 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.types.d.ts +15 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.d.ts +12 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.types.d.ts +6 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.d.ts +16 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.types.d.ts +50 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportHttp.d.ts +9 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportWebSocket.d.ts +15 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/err_nice_transport.d.ts +34 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/err_nice_transport_ws.d.ts +18 -0
- package/build/types/ActionRuntimeEnvironment/ActionConnect/err_nice_connect.d.ts +5 -0
- package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.d.ts +80 -0
- package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.types.d.ts +68 -0
- package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.d.ts +32 -0
- package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.types.d.ts +15 -0
- package/build/types/ActionRuntimeEnvironment/utils/getAssumedRuntimeEnvironment.d.ts +2 -0
- package/build/types/ActionSchema/NiceActionSchema.d.ts +14 -10
- package/build/types/ActionSchema/NiceActionSchema.types.d.ts +4 -4
- package/build/types/NiceAction/MatchAction/MatchAction.d.ts +26 -0
- package/build/types/NiceAction/NiceAction.d.ts +20 -20
- package/build/types/NiceAction/NiceAction.enums.d.ts +5 -0
- package/build/types/NiceAction/NiceAction.types.d.ts +7 -10
- package/build/types/NiceAction/NiceActionCombined.types.d.ts +10 -0
- package/build/types/NiceAction/NiceActionPrimed.d.ts +20 -36
- package/build/types/NiceAction/NiceActionResponse.d.ts +15 -5
- package/build/types/NiceAction/utils/isNiceActionInstance.d.ts +3 -0
- package/build/types/errors/err_nice_action.d.ts +35 -13
- package/build/types/index.d.ts +16 -8
- package/build/types/react-query/index.d.ts +73 -0
- package/package.json +15 -5
- package/build/types/ActionDomain/createActionDomain.d.ts +0 -5
- package/build/types/ActionRequestResponse/ActionRequester/NiceActionRequester.d.ts +0 -31
- package/build/types/ActionRequestResponse/ActionResponder/NiceActionResponder.d.ts +0 -49
- package/build/types/ActionRequestResponse/ActionResponder/NiceActionResponder.types.d.ts +0 -7
- package/build/types/ActionRequestResponse/ActionResponder/NiceActionResponderEnvironment.d.ts +0 -42
- package/build/types/NiceAction/ActionSchema/NiceActionSchema.d.ts +0 -99
- package/build/types/NiceAction/ActionSchema/NiceActionSchema.types.d.ts +0 -31
- package/build/types/NiceAction/ActionSchema/NiceActionSchemaBuilder.d.ts +0 -1
- package/build/types/NiceAction/ActionSchema/action.d.ts +0 -2
- package/build/types/NiceAction/NiceActionPrimed.schema.d.ts +0 -8
- package/build/types/test/nice_action_test_schema.d.ts +0 -30
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { err_cast_not_nice, type
|
|
1
|
+
import { err_cast_not_nice, type INiceErrorDomainProps, type InferNiceError, type JSONSerializableValue, type NiceErrorDomain } from "@nice-code/error";
|
|
2
2
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
import type { INiceActionErrorDeclaration, TInferDeclaredErrors,
|
|
4
|
-
export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any> =
|
|
3
|
+
import type { INiceActionErrorDeclaration, TInferDeclaredErrors, TNiceActonSchemaOptions, TTransportedValue } from "./NiceActionSchema.types";
|
|
4
|
+
export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any> = never, OUTPUT extends TTransportedValue<any, any> = never, ERRORS extends readonly INiceActionErrorDeclaration<any, any>[] = readonly []> {
|
|
5
5
|
private _errorDeclarations;
|
|
6
6
|
private inputOptions;
|
|
7
7
|
private outputOptions;
|
|
8
|
-
get inputSchema(): StandardSchemaV1;
|
|
9
|
-
get outputSchema(): StandardSchemaV1;
|
|
8
|
+
get inputSchema(): StandardSchemaV1 | undefined;
|
|
9
|
+
get outputSchema(): StandardSchemaV1 | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Declare the input schema (JSON-native or with explicit SERDE type param).
|
|
12
12
|
* For non-JSON-native inputs, prefer the 3-argument form below to avoid
|
|
13
13
|
* needing explicit type parameters.
|
|
14
14
|
*/
|
|
15
|
-
input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = never>(options:
|
|
15
|
+
input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = never>(options: TNiceActonSchemaOptions<VS, SERDE_IN>): NiceActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
|
|
16
16
|
/**
|
|
17
17
|
* Declare the input schema with serialization via sequential parameters.
|
|
18
18
|
* TypeScript infers SERDE_IN from `serialize`'s return type (left-to-right),
|
|
@@ -27,7 +27,7 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
|
|
|
27
27
|
* For non-JSON-native outputs, prefer the 3-argument form below to avoid
|
|
28
28
|
* needing explicit type parameters.
|
|
29
29
|
*/
|
|
30
|
-
output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT extends JSONSerializableValue = JSONSerializableValue>(options:
|
|
30
|
+
output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT extends JSONSerializableValue = JSONSerializableValue>(options: TNiceActonSchemaOptions<VS, SERDE_OUT>): NiceActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
|
|
31
31
|
/**
|
|
32
32
|
* Declare the output schema with serialization via sequential parameters.
|
|
33
33
|
* TypeScript infers SERDE_OUT from `serialize`'s return type (left-to-right),
|
|
@@ -41,12 +41,12 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
|
|
|
41
41
|
* Declare that this action may throw any error from `domain`.
|
|
42
42
|
* `TInferActionError` will include `NiceError<DEF, keyof schema>` in its union.
|
|
43
43
|
*/
|
|
44
|
-
throws<ERR_DEF extends
|
|
44
|
+
throws<ERR_DEF extends INiceErrorDomainProps>(domain: NiceErrorDomain<ERR_DEF>): NiceActionSchema<INPUT, OUTPUT, readonly [...ERRORS, INiceActionErrorDeclaration<ERR_DEF, keyof ERR_DEF["schema"] & string>]>;
|
|
45
45
|
/**
|
|
46
46
|
* Declare that this action may throw only the listed `ids` from `domain`.
|
|
47
47
|
* `TInferActionError` will include `NiceError<DEF, IDS[number]>` narrowed to those IDs.
|
|
48
48
|
*/
|
|
49
|
-
throws<ERR_DEF extends
|
|
49
|
+
throws<ERR_DEF extends INiceErrorDomainProps, IDS extends ReadonlyArray<keyof ERR_DEF["schema"] & string>>(domain: NiceErrorDomain<ERR_DEF>, ids: IDS): NiceActionSchema<INPUT, OUTPUT, readonly [...ERRORS, INiceActionErrorDeclaration<ERR_DEF, IDS[number] & string>]>;
|
|
50
50
|
/**
|
|
51
51
|
* Serialize raw input to a JSON-serializable form.
|
|
52
52
|
* Uses the schema's serialization.serialize if defined; otherwise the input
|
|
@@ -68,7 +68,11 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
|
|
|
68
68
|
validateInput(value: unknown, meta: {
|
|
69
69
|
domain: string;
|
|
70
70
|
actionId: string;
|
|
71
|
-
}):
|
|
71
|
+
}): INPUT[0];
|
|
72
|
+
validateOutput(value: unknown, meta: {
|
|
73
|
+
domain: string;
|
|
74
|
+
actionId: string;
|
|
75
|
+
}): OUTPUT[0];
|
|
72
76
|
/**
|
|
73
77
|
* Serialize raw output to a JSON-serializable form.
|
|
74
78
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type INiceErrorDomainProps, type JSONSerializableValue, type NiceErrorDomain } from "@nice-code/error";
|
|
2
2
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
export type TNiceActionJsonSerializableValue = JSONSerializableValue;
|
|
4
4
|
export type TTransportedValue<RAW_VAL = never, SERDE_VAL extends TNiceActionJsonSerializableValue = never> = RAW_VAL extends TNiceActionJsonSerializableValue ? [RAW_VAL] | [RAW_VAL, SERDE_VAL] : [RAW_VAL, SERDE_VAL];
|
|
@@ -6,7 +6,7 @@ export type TNiceActionSerializationDefinition<RAW_VAL = any, SERDE_VAL extends
|
|
|
6
6
|
serialize: (value: RAW_VAL) => SERDE_VAL;
|
|
7
7
|
deserialize: (value: SERDE_VAL) => RAW_VAL;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
9
|
+
export type TNiceActonSchemaOptions<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends TNiceActionJsonSerializableValue = TNiceActionJsonSerializableValue> = StandardSchemaV1.InferInput<VS> extends TNiceActionJsonSerializableValue ? {
|
|
10
10
|
schema: VS;
|
|
11
11
|
serialization?: TNiceActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
12
12
|
} : {
|
|
@@ -20,8 +20,8 @@ export type TNiceActonSchemaInputOptions<VS extends StandardSchemaV1 = StandardS
|
|
|
20
20
|
*
|
|
21
21
|
* Build via `action().throws(domain)` or `action().throws(domain, ids)`.
|
|
22
22
|
*/
|
|
23
|
-
export interface INiceActionErrorDeclaration<ERR_DEF extends
|
|
24
|
-
readonly _domain:
|
|
23
|
+
export interface INiceActionErrorDeclaration<ERR_DEF extends INiceErrorDomainProps = INiceErrorDomainProps, IDS extends keyof ERR_DEF["schema"] & string = keyof ERR_DEF["schema"] & string> {
|
|
24
|
+
readonly _domain: NiceErrorDomain<ERR_DEF>;
|
|
25
25
|
/** The specific IDs constrained for this declaration, or `undefined` meaning the full domain. */
|
|
26
26
|
readonly _ids: ReadonlyArray<IDS & string> | undefined;
|
|
27
27
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { INiceActionDomain, MaybePromise } from "../../ActionDomain/NiceActionDomain.types";
|
|
2
|
+
import type { INiceAction } from "../NiceAction.types";
|
|
3
|
+
import type { TNarrowActionType } from "../NiceActionCombined.types";
|
|
4
|
+
type TMatchHandler<A extends INiceAction<any>> = (action: A) => MaybePromise<void>;
|
|
5
|
+
type THandlerForId<ACT extends INiceAction<any>> = (action: ACT) => MaybePromise<void>;
|
|
6
|
+
declare class MatchAction<ACT extends INiceAction<any>> {
|
|
7
|
+
readonly action: ACT;
|
|
8
|
+
private _entries;
|
|
9
|
+
private _otherwise?;
|
|
10
|
+
constructor(action: ACT);
|
|
11
|
+
with<D extends INiceActionDomain, ID extends keyof D["actions"] & string>(opts: {
|
|
12
|
+
domain: D;
|
|
13
|
+
id: ID;
|
|
14
|
+
handler: THandlerForId<TNarrowActionType<ACT, D, ID>>;
|
|
15
|
+
}): this;
|
|
16
|
+
with<D extends INiceActionDomain>(opts: {
|
|
17
|
+
domain: D;
|
|
18
|
+
handler: TMatchHandler<TNarrowActionType<ACT, D, keyof D["actions"] & string>>;
|
|
19
|
+
}): this;
|
|
20
|
+
otherwise(handler: TMatchHandler<ACT>): this;
|
|
21
|
+
private _findMatch;
|
|
22
|
+
run(): boolean;
|
|
23
|
+
runAsync(): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export declare const matchAction: <ACT extends INiceAction<any>>(action: ACT) => MatchAction<ACT>;
|
|
26
|
+
export {};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JSONSerializableValue } from "@nice-code/error";
|
|
2
2
|
import type { NiceActionDomain } from "../ActionDomain/NiceActionDomain";
|
|
3
3
|
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
4
|
+
import type { IActionMetaInputs } from "../ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
4
5
|
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
5
|
-
import { EActionState
|
|
6
|
+
import { EActionState } from "./NiceAction.enums";
|
|
7
|
+
import { type INiceAction, type INiceAction_JsonObject, type INiceActionPrimed_JsonObject, type TNiceActionResult } from "./NiceAction.types";
|
|
8
|
+
import type { TNarrowActionType } from "./NiceActionCombined.types";
|
|
6
9
|
import { NiceActionPrimed } from "./NiceActionPrimed";
|
|
7
10
|
import { NiceActionResponse } from "./NiceActionResponse";
|
|
8
|
-
export declare class NiceAction<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID]> implements INiceAction<DOM, ID> {
|
|
11
|
+
export declare class NiceAction<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string, SCH extends DOM["actions"][ID] = DOM["actions"][ID]> implements INiceAction<DOM, ID> {
|
|
9
12
|
readonly actionDomain: NiceActionDomain<DOM>;
|
|
10
13
|
readonly schema: SCH;
|
|
11
|
-
readonly id: ID;
|
|
12
14
|
readonly type = EActionState.empty;
|
|
15
|
+
readonly id: ID;
|
|
13
16
|
readonly domain: DOM["domain"];
|
|
14
17
|
readonly allDomains: DOM["allDomains"];
|
|
15
|
-
readonly _actionDomain: NiceActionDomain<DOM>;
|
|
16
18
|
readonly timeCreated: number;
|
|
17
19
|
readonly cuid: string;
|
|
18
20
|
constructor(actionDomain: NiceActionDomain<DOM>, schema: SCH, id: ID, hydrationData?: Pick<INiceAction_JsonObject<DOM, ID>, "cuid" | "timeCreated">);
|
|
@@ -21,20 +23,14 @@ export declare class NiceAction<DOM extends INiceActionDomain, ID extends keyof
|
|
|
21
23
|
* Useful for describing which action will be invoked without yet having input.
|
|
22
24
|
*/
|
|
23
25
|
toJsonObject(): INiceAction_JsonObject<DOM, ID>;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
toJsonString(): string;
|
|
27
|
+
toHttpResponse(): Response;
|
|
28
|
+
is<ACT extends INiceAction<any>>(action: ACT | unknown | null | undefined): action is TNarrowActionType<ACT, DOM, ID>;
|
|
26
29
|
prime(input: TInferInputFromSchema<SCH>["Input"], hydrationData?: Pick<INiceActionPrimed_JsonObject<DOM, ID>, "timePrimed">): NiceActionPrimed<DOM, ID, SCH>;
|
|
27
|
-
|
|
28
|
-
* Prime this action with input and immediately execute it through the domain handler or resolver.
|
|
29
|
-
*
|
|
30
|
-
* Pass `envId` to target a specific named handler/resolver registered on the domain via
|
|
31
|
-
* `setActionHandler(h, { envId })` or `registerResolver(r, { envId })`.
|
|
32
|
-
* Throws `action_environment_not_found` if no handler or resolver with that id exists.
|
|
33
|
-
*/
|
|
34
|
-
execute(input: TInferInputFromSchema<SCH>["Input"], envId?: string): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
30
|
+
execute(input: TInferInputFromSchema<SCH>["Input"], meta?: IActionMetaInputs): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
35
31
|
/**
|
|
36
32
|
* Like `execute`, but catches thrown errors and returns a `NiceActionResult` discriminated union
|
|
37
|
-
* instead of propagating. On success: `{ ok: true,
|
|
33
|
+
* instead of propagating. On success: `{ ok: true, output }`. On failure: `{ ok: false, error }`.
|
|
38
34
|
*
|
|
39
35
|
* The `error` type is the union of all `NiceError` types declared via `.throws()` on the schema,
|
|
40
36
|
* plus `InferNiceError<typeof err_cast_not_nice>` as the always-present fallback.
|
|
@@ -48,17 +44,21 @@ export declare class NiceAction<DOM extends INiceActionDomain, ID extends keyof
|
|
|
48
44
|
* ]);
|
|
49
45
|
* return;
|
|
50
46
|
* }
|
|
51
|
-
* console.log(result.
|
|
47
|
+
* console.log(result.output); // typed as the action's OUTPUT
|
|
52
48
|
* ```
|
|
53
49
|
*/
|
|
54
|
-
executeSafe(input: TInferInputFromSchema<SCH>["Input"],
|
|
50
|
+
executeSafe(input: TInferInputFromSchema<SCH>["Input"], meta?: IActionMetaInputs): Promise<TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>>;
|
|
55
51
|
/**
|
|
56
52
|
* Prime this action with input, execute it, and return a `NiceActionResponse`
|
|
57
53
|
* that carries both the original primed action (domain + actionId + input) and
|
|
58
|
-
* the result (`{ ok: true,
|
|
54
|
+
* the result (`{ ok: true, output }` or `{ ok: false, error }`).
|
|
59
55
|
*
|
|
60
56
|
* The response can be serialized for cross-boundary transport via `toJsonObject()`.
|
|
61
57
|
* Reconstruct on the receiving end with `domain.hydrateResponse(wire)`.
|
|
62
58
|
*/
|
|
63
|
-
executeToResponse(input: TInferInputFromSchema<SCH>["Input"],
|
|
59
|
+
executeToResponse(input: TInferInputFromSchema<SCH>["Input"], meta?: IActionMetaInputs): Promise<NiceActionResponse<DOM, ID, SCH>>;
|
|
60
|
+
deserializeInput(serialized: JSONSerializableValue): TInferInputFromSchema<SCH>["Input"];
|
|
61
|
+
serializeInput(raw: TInferInputFromSchema<SCH>["Input"]): JSONSerializableValue;
|
|
62
|
+
validateInput(input: unknown): TInferInputFromSchema<SCH>["Input"];
|
|
63
|
+
validateOutput(output: unknown): TInferOutputFromSchema<SCH>["Output"];
|
|
64
64
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { INiceErrorJsonObject } from "@nice-code/error";
|
|
2
2
|
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
primed = "primed",
|
|
6
|
-
response = "response"
|
|
7
|
-
}
|
|
8
|
-
export interface INiceAction<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string> {
|
|
3
|
+
import type { EActionState } from "./NiceAction.enums";
|
|
4
|
+
export interface INiceAction<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> {
|
|
9
5
|
id: ID;
|
|
6
|
+
type: EActionState;
|
|
10
7
|
domain: DOM["domain"];
|
|
11
8
|
allDomains: DOM["allDomains"];
|
|
12
9
|
schema: DOM["actions"][ID];
|
|
@@ -35,7 +32,7 @@ export type INiceActionPrimed_JsonObject<DOM extends INiceActionDomain = INiceAc
|
|
|
35
32
|
/**
|
|
36
33
|
* Return type of `executeSafe` — a discriminated union of success and failure.
|
|
37
34
|
*
|
|
38
|
-
* - `{ ok: true;
|
|
35
|
+
* - `{ ok: true; output: OUT }` — the action completed and returned `OUT`
|
|
39
36
|
* - `{ ok: false; error: ERR }` — the action threw; `ERR` is the declared error union
|
|
40
37
|
*
|
|
41
38
|
* @example
|
|
@@ -47,10 +44,10 @@ export type INiceActionPrimed_JsonObject<DOM extends INiceActionDomain = INiceAc
|
|
|
47
44
|
* ]);
|
|
48
45
|
* return;
|
|
49
46
|
* }
|
|
50
|
-
* console.log(result.
|
|
47
|
+
* console.log(result.output); // typed as the action's OUTPUT
|
|
51
48
|
* ```
|
|
52
49
|
*/
|
|
53
|
-
export type
|
|
50
|
+
export type TNiceActionResult<OUT, ERR> = {
|
|
54
51
|
ok: true;
|
|
55
52
|
output: OUT;
|
|
56
53
|
} | {
|
|
@@ -67,7 +64,7 @@ export type NiceActionResult<OUT, ERR> = {
|
|
|
67
64
|
* Reconstructed by `NiceActionDomain.hydrateResponse()`.
|
|
68
65
|
*/
|
|
69
66
|
export interface INiceActionResponse_JsonObject_Base<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string> extends Omit<INiceActionPrimed_JsonObject<DOM, ID>, "type"> {
|
|
70
|
-
type: EActionState.
|
|
67
|
+
type: EActionState.resolved;
|
|
71
68
|
timeResponded: number;
|
|
72
69
|
}
|
|
73
70
|
export type INiceActionResponse_JsonObject_Success<DOM extends INiceActionDomain = INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = INiceActionResponse_JsonObject_Base<DOM, ID> & {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { INiceActionDomain } from "../ActionDomain/NiceActionDomain.types";
|
|
2
|
+
import type { NiceAction } from "./NiceAction";
|
|
3
|
+
import type { INiceAction } from "./NiceAction.types";
|
|
4
|
+
import type { NiceActionPrimed } from "./NiceActionPrimed";
|
|
5
|
+
import type { NiceActionResponse } from "./NiceActionResponse";
|
|
6
|
+
export type TNiceActionInstanceAny<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = NiceAction<DOM, ID, DOM["actions"][ID]> | NiceActionPrimed<DOM, ID, DOM["actions"][ID]> | NiceActionResponse<DOM, ID, DOM["actions"][ID]>;
|
|
7
|
+
export type TNarrowActionType<ACT extends INiceAction<any>, D extends INiceActionDomain, ID extends keyof D["actions"] & string = keyof D["actions"] & string> = ACT extends NiceActionResponse<any> ? NiceActionResponse<D, ID> : ACT extends NiceActionPrimed<any> ? NiceActionPrimed<D, ID> : ACT extends NiceAction<any> ? NiceAction<D, ID> : INiceAction<D, ID>;
|
|
8
|
+
export type TDistributedDomainActions<ACT extends INiceAction<any>, DOM extends INiceActionDomain> = {
|
|
9
|
+
[ID in keyof DOM["actions"] & string]: TNarrowActionType<ACT, DOM, ID>;
|
|
10
|
+
}[keyof DOM["actions"] & string];
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
2
|
+
import type { IActionMetaInputs } from "../ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
3
|
+
import type { IRuntimeEnvironmentMeta } from "../ActionRuntimeEnvironment/ActionRuntimeEnvironment.types";
|
|
2
4
|
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
3
5
|
import type { NiceAction } from "./NiceAction";
|
|
4
|
-
import { EActionState
|
|
6
|
+
import { EActionState } from "./NiceAction.enums";
|
|
7
|
+
import { type INiceAction, type INiceActionPrimed_JsonObject, type TNiceActionResponse_JsonObject, type TNiceActionResult } from "./NiceAction.types";
|
|
5
8
|
import { NiceActionResponse } from "./NiceActionResponse";
|
|
6
|
-
export declare class NiceActionPrimed<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID]> implements
|
|
9
|
+
export declare class NiceActionPrimed<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string, SCH extends DOM["actions"][ID] = DOM["actions"][ID]> implements INiceAction<DOM, ID> {
|
|
7
10
|
readonly coreAction: NiceAction<DOM, ID, SCH>;
|
|
8
|
-
|
|
11
|
+
private _input;
|
|
9
12
|
readonly type = EActionState.primed;
|
|
10
13
|
readonly domain: DOM["domain"];
|
|
11
14
|
readonly allDomains: DOM["allDomains"];
|
|
12
15
|
readonly id: ID;
|
|
13
16
|
readonly timePrimed: number;
|
|
14
|
-
|
|
17
|
+
readonly cuid: string;
|
|
18
|
+
readonly schema: SCH;
|
|
19
|
+
readonly timeCreated: number;
|
|
20
|
+
constructor(coreAction: NiceAction<DOM, ID, SCH>, _input: TInferInputFromSchema<SCH>["Input"], hydrationData?: Pick<INiceActionPrimed_JsonObject<DOM, ID>, "timePrimed">);
|
|
21
|
+
get input(): TInferInputFromSchema<SCH>["Input"];
|
|
22
|
+
getEnvironmentMeta(): IRuntimeEnvironmentMeta;
|
|
15
23
|
/**
|
|
16
24
|
* Serialize this primed action to a JSON-safe wire format.
|
|
17
25
|
* The input is passed through the schema's serialize function if one is defined,
|
|
@@ -19,41 +27,17 @@ export declare class NiceActionPrimed<DOM extends INiceActionDomain, ID extends
|
|
|
19
27
|
*/
|
|
20
28
|
toJsonObject(): INiceActionPrimed_JsonObject<DOM, ID>;
|
|
21
29
|
toJsonString(): string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* Intended for use inside `NiceActionRequester` handlers that receive a
|
|
30
|
-
* `TNiceActionResponse_JsonObject` from a network call, so the caller of `execute()`
|
|
31
|
-
* always gets the raw output type without manually deserializing.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* dom.setActionRequester().forDomain(dom, async (act) => {
|
|
36
|
-
* const wire = await fetch("/api/actions", {
|
|
37
|
-
* method: "POST",
|
|
38
|
-
* body: JSON.stringify(act.toJsonObject()),
|
|
39
|
-
* }).then((r) => r.json());
|
|
40
|
-
* return act.processResponse(wire);
|
|
41
|
-
* });
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
processResponse(wire: TNiceActionResponse_JsonObject): TInferOutputFromSchema<SCH>["Output"];
|
|
45
|
-
/**
|
|
46
|
-
* Re-execute this primed action through the domain handler or resolver.
|
|
47
|
-
* Useful for deferred or cross-environment execution of a hydrated action.
|
|
48
|
-
*
|
|
49
|
-
* Pass `envId` to target a specific named handler/resolver on the domain.
|
|
50
|
-
*/
|
|
51
|
-
execute(envId?: string): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
30
|
+
hydratePrimeJson(wire: INiceActionPrimed_JsonObject<DOM, ID>): NiceActionPrimed<DOM, ID, SCH>;
|
|
31
|
+
hydrateResponseJson(wire: TNiceActionResponse_JsonObject<DOM, ID>): NiceActionResponse<DOM, ID, SCH>;
|
|
32
|
+
errorResponse(err: TInferActionError<SCH>): NiceActionResponse<DOM, ID, SCH>;
|
|
33
|
+
toHttpResponse(): Response;
|
|
34
|
+
setResponse(...args: [TInferOutputFromSchema<SCH>["Output"]] extends [never] ? [] : [output: TInferOutputFromSchema<SCH>["Output"]]): NiceActionResponse<DOM, ID, SCH>;
|
|
35
|
+
execute(meta?: IActionMetaInputs): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
52
36
|
/**
|
|
53
37
|
* Like `execute`, but catches thrown errors and returns a `NiceActionResult` discriminated union
|
|
54
|
-
* instead of propagating. On success: `{ ok: true,
|
|
38
|
+
* instead of propagating. On success: `{ ok: true, output }`. On failure: `{ ok: false, error }`.
|
|
55
39
|
*
|
|
56
40
|
* Mirrors `NiceAction.executeSafe` — useful when re-executing a hydrated primed action.
|
|
57
41
|
*/
|
|
58
|
-
executeSafe(
|
|
42
|
+
executeSafe(meta?: IActionMetaInputs): Promise<TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>>;
|
|
59
43
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import type { INiceActionDomain, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
2
|
+
import type { IRuntimeEnvironmentMeta } from "../ActionRuntimeEnvironment/ActionRuntimeEnvironment.types";
|
|
2
3
|
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
3
4
|
import type { NiceAction } from "./NiceAction";
|
|
4
|
-
import { EActionState
|
|
5
|
+
import { EActionState } from "./NiceAction.enums";
|
|
6
|
+
import { type INiceAction, type TNiceActionResponse_JsonObject, type TNiceActionResult } from "./NiceAction.types";
|
|
5
7
|
import { NiceActionPrimed } from "./NiceActionPrimed";
|
|
6
|
-
export declare class NiceActionResponse<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID]> implements
|
|
7
|
-
readonly type = EActionState.
|
|
8
|
+
export declare class NiceActionResponse<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string, SCH extends DOM["actions"][ID] = DOM["actions"][ID]> implements INiceAction<DOM, ID> {
|
|
9
|
+
readonly type = EActionState.resolved;
|
|
8
10
|
readonly domain: DOM["domain"];
|
|
9
11
|
readonly allDomains: DOM["allDomains"];
|
|
10
12
|
readonly id: ID;
|
|
11
13
|
readonly primed: NiceActionPrimed<DOM, ID, SCH>;
|
|
12
|
-
readonly result:
|
|
14
|
+
readonly result: TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>;
|
|
13
15
|
readonly timeResponded: number;
|
|
14
|
-
|
|
16
|
+
readonly cuid: string;
|
|
17
|
+
readonly schema: SCH;
|
|
18
|
+
readonly timeCreated: number;
|
|
19
|
+
constructor(primed: NiceActionPrimed<DOM, ID, SCH>, result: TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>, hydrationData?: Pick<TNiceActionResponse_JsonObject<DOM, ID>, "timeResponded">);
|
|
20
|
+
getEnvironmentMeta(): IRuntimeEnvironmentMeta;
|
|
15
21
|
/**
|
|
16
22
|
* Serialize this response to a JSON-safe wire format.
|
|
17
23
|
*
|
|
@@ -21,6 +27,10 @@ export declare class NiceActionResponse<DOM extends INiceActionDomain, ID extend
|
|
|
21
27
|
*/
|
|
22
28
|
toJsonObject(): TNiceActionResponse_JsonObject;
|
|
23
29
|
toJsonString(): string;
|
|
30
|
+
hydrateResponseJson(wire: TNiceActionResponse_JsonObject<DOM, ID>): NiceActionResponse<DOM, ID, SCH>;
|
|
31
|
+
toHttpResponse({ useErrorStatus }?: {
|
|
32
|
+
useErrorStatus?: boolean;
|
|
33
|
+
}): Response;
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
36
|
* Reconstruct a loosely-typed NiceActionResponse from its wire format.
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import type { EActionState } from "../NiceAction/NiceAction.
|
|
1
|
+
import type { EActionState } from "../NiceAction/NiceAction.enums";
|
|
2
2
|
export declare enum EErrId_NiceAction {
|
|
3
3
|
action_id_not_in_domain = "action_id_not_in_domain",
|
|
4
|
-
|
|
4
|
+
domain_already_exists_in_hierarchy = "domain_already_exists_in_hierarchy",
|
|
5
5
|
domain_no_handler = "domain_no_handler",
|
|
6
6
|
hydration_domain_mismatch = "hydration_domain_mismatch",
|
|
7
7
|
hydration_action_state_mismatch = "hydration_action_state_mismatch",
|
|
8
8
|
hydration_action_id_not_found = "hydration_action_id_not_found",
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
no_action_execution_handler = "no_action_execution_handler",
|
|
10
|
+
wire_action_not_primed_or_response = "wire_action_not_primed_or_response",
|
|
11
|
+
wire_not_action_data = "wire_not_action_data",
|
|
12
|
+
action_tag_handler_not_found = "action_tag_handler_not_found",
|
|
12
13
|
environment_already_registered = "environment_already_registered",
|
|
13
|
-
action_input_validation_failed = "action_input_validation_failed"
|
|
14
|
+
action_input_validation_failed = "action_input_validation_failed",
|
|
15
|
+
action_input_validation_promise = "action_input_validation_promise",
|
|
16
|
+
action_output_validation_failed = "action_output_validation_failed",
|
|
17
|
+
action_output_validation_promise = "action_output_validation_promise"
|
|
14
18
|
}
|
|
15
|
-
export declare const err_nice_action: import("@nice-code/error").
|
|
19
|
+
export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain<{
|
|
16
20
|
domain: string;
|
|
17
21
|
allDomains: [string, "err_nice"];
|
|
18
22
|
schema: {
|
|
@@ -20,8 +24,10 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDefine
|
|
|
20
24
|
domain: string;
|
|
21
25
|
actionId: string;
|
|
22
26
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
23
|
-
|
|
27
|
+
domain_already_exists_in_hierarchy: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
24
28
|
domain: string;
|
|
29
|
+
allParentDomains: string[];
|
|
30
|
+
parentDomain: string;
|
|
25
31
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
26
32
|
domain_no_handler: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
27
33
|
domain: string;
|
|
@@ -38,25 +44,41 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDefine
|
|
|
38
44
|
domain: string;
|
|
39
45
|
actionId: string;
|
|
40
46
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
41
|
-
|
|
47
|
+
no_action_execution_handler: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
42
48
|
domain: string;
|
|
49
|
+
actionId: string;
|
|
43
50
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
44
|
-
|
|
51
|
+
wire_action_not_primed_or_response: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
45
52
|
domain: string;
|
|
46
53
|
actionId: string;
|
|
54
|
+
actionState: EActionState | undefined;
|
|
47
55
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
48
|
-
|
|
56
|
+
wire_not_action_data: import("@nice-code/error").INiceErrorIdMetadata<any, import("@nice-code/error").JSONSerializableValue>;
|
|
57
|
+
action_tag_handler_not_found: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
49
58
|
domain: string;
|
|
50
|
-
|
|
59
|
+
matchTag: string;
|
|
51
60
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
52
61
|
environment_already_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
53
62
|
domain: string;
|
|
54
|
-
|
|
63
|
+
matchTag: string;
|
|
55
64
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
56
65
|
action_input_validation_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
57
66
|
domain: string;
|
|
58
67
|
actionId: string;
|
|
59
68
|
validationMessage: string;
|
|
60
69
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
70
|
+
action_input_validation_promise: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
71
|
+
domain: string;
|
|
72
|
+
actionId: string;
|
|
73
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
74
|
+
action_output_validation_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
75
|
+
domain: string;
|
|
76
|
+
actionId: string;
|
|
77
|
+
validationMessage: string;
|
|
78
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
79
|
+
action_output_validation_promise: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
80
|
+
domain: string;
|
|
81
|
+
actionId: string;
|
|
82
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
61
83
|
};
|
|
62
84
|
}>;
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createActionRootDomain } from "./ActionDomain/helpers/createRootActionDomain";
|
|
2
2
|
export { NiceActionDomain } from "./ActionDomain/NiceActionDomain";
|
|
3
|
-
export type { INiceActionDomain, INiceActionDomainChildOptions, MaybePromise,
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
3
|
+
export type { INiceActionDomain, INiceActionDomainChildOptions, MaybePromise, TDomainActionId, TInferInputFromSchema, TInferOutputFromSchema, TNiceActionDomainChildDef, TNiceActionDomainSchema, TPossibleDomainId, TPossibleDomainIdList, } from "./ActionDomain/NiceActionDomain.types";
|
|
4
|
+
export { ActionConnect } from "./ActionRuntimeEnvironment/ActionConnect/ActionConnect";
|
|
5
|
+
export * from "./ActionRuntimeEnvironment/ActionConnect/ActionConnect.types";
|
|
6
|
+
export { ConnectionConfig as Transport } from "./ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig";
|
|
7
|
+
export * from "./ActionRuntimeEnvironment/ActionConnect/err_nice_connect";
|
|
8
|
+
export * from "./ActionRuntimeEnvironment/ActionConnect/Transport/err_nice_transport";
|
|
9
|
+
export * from "./ActionRuntimeEnvironment/ActionConnect/Transport/err_nice_transport_ws";
|
|
10
|
+
export { ActionHandler, createHandler, } from "./ActionRuntimeEnvironment/ActionHandler/ActionHandler";
|
|
11
|
+
export type { IActionHandlerInputs, TAtLeastOne, TExecutionAndResponseHandlers, THandleActionExecutionFn, THandleActionResponseFn, THandleActionResult, } from "./ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
12
|
+
export { ActionRuntimeEnvironment, createActionRuntime, } from "./ActionRuntimeEnvironment/ActionRuntimeEnvironment";
|
|
13
|
+
export type { IActionRuntimeEnvironment_JsonObject } from "./ActionRuntimeEnvironment/ActionRuntimeEnvironment.types";
|
|
8
14
|
export { action } from "./ActionSchema/action";
|
|
9
15
|
export type { TInferActionError } from "./ActionSchema/NiceActionSchema";
|
|
10
16
|
export { NiceActionSchema } from "./ActionSchema/NiceActionSchema";
|
|
11
|
-
export type { TNiceActionSerializationDefinition, TNiceActonSchemaInputOptions, TTransportedValue, } from "./ActionSchema/NiceActionSchema.types";
|
|
17
|
+
export type { TNiceActionSerializationDefinition, TNiceActonSchemaOptions as TNiceActonSchemaInputOptions, TTransportedValue, } from "./ActionSchema/NiceActionSchema.types";
|
|
12
18
|
export { EErrId_NiceAction, err_nice_action } from "./errors/err_nice_action";
|
|
19
|
+
export { matchAction } from "./NiceAction/MatchAction/MatchAction";
|
|
13
20
|
export { NiceAction } from "./NiceAction/NiceAction";
|
|
14
|
-
export
|
|
21
|
+
export { EActionState } from "./NiceAction/NiceAction.enums";
|
|
22
|
+
export type { INiceAction, INiceAction_JsonObject, INiceActionPrimed_JsonObject, TNiceActionResponse_JsonObject, TNiceActionResult as NiceActionResult, } from "./NiceAction/NiceAction.types";
|
|
15
23
|
export { NiceActionPrimed } from "./NiceAction/NiceActionPrimed";
|
|
16
24
|
export { NiceActionResponse } from "./NiceAction/NiceActionResponse";
|
|
17
25
|
export * from "./utils/isActionResponseJsonObject";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
3
|
+
import type { IActionMetaInputs } from "../ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
4
|
+
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
5
|
+
import type { NiceAction } from "../NiceAction/NiceAction";
|
|
6
|
+
/**
|
|
7
|
+
* Builds a stable TanStack Query key for a Nice Action.
|
|
8
|
+
*
|
|
9
|
+
* Overload 1 (no input) — returns a prefix key suitable for `queryClient.invalidateQueries`,
|
|
10
|
+
* which will match every cached query for this action regardless of input.
|
|
11
|
+
*
|
|
12
|
+
* Overload 2 (with input) — returns the exact key used by `useNiceQuery` for the given input.
|
|
13
|
+
* Use this when you need to read or invalidate a single cached result.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Invalidate all cached results for an action
|
|
17
|
+
* queryClient.invalidateQueries({ queryKey: niceActionQueryKey(domain.action("getUser")) });
|
|
18
|
+
*
|
|
19
|
+
* // Invalidate a specific cached result
|
|
20
|
+
* queryClient.invalidateQueries({ queryKey: niceActionQueryKey(domain.action("getUser"), { userId: "123" }) });
|
|
21
|
+
*/
|
|
22
|
+
export declare function niceActionQueryKey<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string>(action: NiceAction<DOM, ID, DOM["actions"][ID]>): readonly ["nice-action", DOM["domain"], DOM["allDomains"], ID];
|
|
23
|
+
export declare function niceActionQueryKey<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string>(action: NiceAction<DOM, ID, DOM["actions"][ID]>, input: TInferInputFromSchema<DOM["actions"][ID]>["Input"], meta?: IActionMetaInputs): readonly [
|
|
24
|
+
"nice-action",
|
|
25
|
+
DOM["domain"],
|
|
26
|
+
DOM["allDomains"],
|
|
27
|
+
ID,
|
|
28
|
+
TInferInputFromSchema<DOM["actions"][ID]>["Input"],
|
|
29
|
+
string | undefined
|
|
30
|
+
];
|
|
31
|
+
export type TUseNiceQueryOptions<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID] = DOM["actions"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]> = Omit<UseQueryOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TSelect, QueryKey>, "queryKey" | "queryFn"> & IActionMetaInputs;
|
|
32
|
+
export type TUseNiceMutationOptions<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID] = DOM["actions"][ID], TContext = unknown> = Omit<UseMutationOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TInferInputFromSchema<SCH>["Input"], TContext>, "mutationFn"> & IActionMetaInputs;
|
|
33
|
+
/**
|
|
34
|
+
* Execute a Nice Action as a TanStack Query.
|
|
35
|
+
*
|
|
36
|
+
* Automatically constructs a stable query key from the action's domain, id, and input.
|
|
37
|
+
* Passing `null` or `undefined` as `input` disables the query (sets `enabled: false`),
|
|
38
|
+
* which allows conditional execution while respecting React's rules of hooks.
|
|
39
|
+
*
|
|
40
|
+
* The `envId` option targets a specific named handler/resolver registered on the domain.
|
|
41
|
+
*
|
|
42
|
+
* Supports TanStack Query's `select` option with full type inference — if you pass a
|
|
43
|
+
* `select` transformer, `data` will be typed as the transformer's return type.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const { data, isPending, error } = useNiceQuery(
|
|
47
|
+
* domain.action("getUser"),
|
|
48
|
+
* { userId: "123" },
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Conditionally enabled
|
|
53
|
+
* const { data } = useNiceQuery(domain.action("getUser"), userId ? { userId } : null);
|
|
54
|
+
*/
|
|
55
|
+
export declare function useNiceQuery<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]>(action: NiceAction<DOM, ID, SCH>, input: TInferInputFromSchema<SCH>["Input"] | null | undefined, options?: TUseNiceQueryOptions<DOM, ID, SCH, TSelect>): UseQueryResult<TSelect, TInferActionError<SCH>>;
|
|
56
|
+
/**
|
|
57
|
+
* Execute a Nice Action as a TanStack Mutation.
|
|
58
|
+
*
|
|
59
|
+
* Ideal for actions that change server state — form submissions, updates, deletes, etc.
|
|
60
|
+
* The input is provided at call time via `mutation.mutate(input)` or `mutation.mutateAsync(input)`.
|
|
61
|
+
*
|
|
62
|
+
* The `envId` option targets a specific named handler/resolver registered on the domain.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const mutation = useNiceMutation(domain.action("createUser"));
|
|
66
|
+
*
|
|
67
|
+
* function handleSubmit(data: CreateUserInput) {
|
|
68
|
+
* mutation.mutate(data, {
|
|
69
|
+
* onSuccess: (user) => router.push(`/users/${user.id}`),
|
|
70
|
+
* });
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
export declare function useNiceMutation<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string, SCH extends DOM["actions"][ID], TContext = unknown>(action: NiceAction<DOM, ID, SCH>, options?: TUseNiceMutationOptions<DOM, ID, SCH, TContext>): UseMutationResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TInferInputFromSchema<SCH>["Input"], TContext>;
|