@nice-code/action 0.0.21 → 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 +1128 -749
- package/build/react-query/index.js +170 -45
- package/build/types/ActionDomain/NiceActionDomain.d.ts +18 -46
- package/build/types/ActionDomain/NiceActionDomain.types.d.ts +9 -45
- 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 +11 -7
- package/build/types/ActionSchema/NiceActionSchema.types.d.ts +1 -1
- package/build/types/NiceAction/MatchAction/MatchAction.d.ts +26 -0
- package/build/types/NiceAction/NiceAction.d.ts +18 -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 +19 -36
- package/build/types/NiceAction/NiceActionResponse.d.ts +15 -6
- package/build/types/NiceAction/utils/isNiceActionInstance.d.ts +3 -0
- package/build/types/errors/err_nice_action.d.ts +34 -12
- package/build/types/index.d.ts +16 -8
- package/build/types/react-query/index.d.ts +6 -8
- package/package.json +8 -6
- 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,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,42 +27,17 @@ export declare class NiceActionPrimed<DOM extends INiceActionDomain, ID extends
|
|
|
19
27
|
*/
|
|
20
28
|
toJsonObject(): INiceActionPrimed_JsonObject<DOM, ID>;
|
|
21
29
|
toJsonString(): string;
|
|
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>;
|
|
22
33
|
toHttpResponse(): Response;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* Process a wire response returned by a remote `NiceActionResponderEnvironment`.
|
|
26
|
-
*
|
|
27
|
-
* Deserializes the output using the schema's deserialization if defined, and throws
|
|
28
|
-
* the error (via `castNiceError`) if the response indicates failure.
|
|
29
|
-
*
|
|
30
|
-
* Intended for use inside `NiceActionRequester` handlers that receive a
|
|
31
|
-
* `TNiceActionResponse_JsonObject` from a network call, so the caller of `execute()`
|
|
32
|
-
* always gets the raw output type without manually deserializing.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* dom.setActionRequester().forDomain(dom, async (act) => {
|
|
37
|
-
* const wire = await fetch("/api/actions", {
|
|
38
|
-
* method: "POST",
|
|
39
|
-
* body: JSON.stringify(act.toJsonObject()),
|
|
40
|
-
* }).then((r) => r.json());
|
|
41
|
-
* return act.processResponse(wire);
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
processResponse(wire: TNiceActionResponse_JsonObject): TInferOutputFromSchema<SCH>["Output"];
|
|
46
|
-
/**
|
|
47
|
-
* Re-execute this primed action through the domain handler or resolver.
|
|
48
|
-
* Useful for deferred or cross-environment execution of a hydrated action.
|
|
49
|
-
*
|
|
50
|
-
* Pass `envId` to target a specific named handler/resolver on the domain.
|
|
51
|
-
*/
|
|
52
|
-
execute(envId?: string): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
34
|
+
setResponse(...args: [TInferOutputFromSchema<SCH>["Output"]] extends [never] ? [] : [output: TInferOutputFromSchema<SCH>["Output"]]): NiceActionResponse<DOM, ID, SCH>;
|
|
35
|
+
execute(meta?: IActionMetaInputs): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
53
36
|
/**
|
|
54
37
|
* Like `execute`, but catches thrown errors and returns a `NiceActionResult` discriminated union
|
|
55
|
-
* instead of propagating. On success: `{ ok: true,
|
|
38
|
+
* instead of propagating. On success: `{ ok: true, output }`. On failure: `{ ok: false, error }`.
|
|
56
39
|
*
|
|
57
40
|
* Mirrors `NiceAction.executeSafe` — useful when re-executing a hydrated primed action.
|
|
58
41
|
*/
|
|
59
|
-
executeSafe(
|
|
42
|
+
executeSafe(meta?: IActionMetaInputs): Promise<TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>>;
|
|
60
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,7 +27,10 @@ export declare class NiceActionResponse<DOM extends INiceActionDomain, ID extend
|
|
|
21
27
|
*/
|
|
22
28
|
toJsonObject(): TNiceActionResponse_JsonObject;
|
|
23
29
|
toJsonString(): string;
|
|
24
|
-
|
|
30
|
+
hydrateResponseJson(wire: TNiceActionResponse_JsonObject<DOM, ID>): NiceActionResponse<DOM, ID, SCH>;
|
|
31
|
+
toHttpResponse({ useErrorStatus }?: {
|
|
32
|
+
useErrorStatus?: boolean;
|
|
33
|
+
}): Response;
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
36
|
* Reconstruct a loosely-typed NiceActionResponse from its wire format.
|
|
@@ -1,16 +1,20 @@
|
|
|
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
19
|
export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain<{
|
|
16
20
|
domain: string;
|
|
@@ -20,8 +24,10 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain
|
|
|
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").NiceErrorDomain
|
|
|
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";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
2
2
|
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
3
|
+
import type { IActionMetaInputs } from "../ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
3
4
|
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
4
5
|
import type { NiceAction } from "../NiceAction/NiceAction";
|
|
5
6
|
/**
|
|
@@ -19,19 +20,16 @@ import type { NiceAction } from "../NiceAction/NiceAction";
|
|
|
19
20
|
* queryClient.invalidateQueries({ queryKey: niceActionQueryKey(domain.action("getUser"), { userId: "123" }) });
|
|
20
21
|
*/
|
|
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];
|
|
22
|
-
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"]): readonly [
|
|
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 [
|
|
23
24
|
"nice-action",
|
|
24
25
|
DOM["domain"],
|
|
25
26
|
DOM["allDomains"],
|
|
26
27
|
ID,
|
|
27
|
-
TInferInputFromSchema<DOM["actions"][ID]>["Input"]
|
|
28
|
+
TInferInputFromSchema<DOM["actions"][ID]>["Input"],
|
|
29
|
+
string | undefined
|
|
28
30
|
];
|
|
29
|
-
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"> &
|
|
30
|
-
|
|
31
|
-
};
|
|
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"> & {
|
|
33
|
-
envId?: string;
|
|
34
|
-
};
|
|
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;
|
|
35
33
|
/**
|
|
36
34
|
* Execute a Nice Action as a TanStack Query.
|
|
37
35
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice-code/action",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,17 +32,19 @@
|
|
|
32
32
|
"build-types": "tsc --project tsconfig.build.json"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nice-code/error": "0.0
|
|
36
|
-
"@nice-code/common-errors": "0.0
|
|
35
|
+
"@nice-code/error": "0.1.0",
|
|
36
|
+
"@nice-code/common-errors": "0.1.0",
|
|
37
37
|
"@standard-schema/spec": "^1.1.0",
|
|
38
38
|
"http-status-codes": "^2.3.0",
|
|
39
|
-
"nanoid": "^5.1.9"
|
|
39
|
+
"nanoid": "^5.1.9",
|
|
40
|
+
"std-env": "^4.1.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@tanstack/react-query": "^5.
|
|
43
|
+
"@tanstack/react-query": "^5.100.3",
|
|
44
|
+
"msw": "^2.13.6"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
|
-
"@tanstack/react-query": "^5.
|
|
47
|
+
"@tanstack/react-query": "^5.100.3",
|
|
46
48
|
"react": ">=18",
|
|
47
49
|
"valibot": "^1.3.1"
|
|
48
50
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { NiceActionDomain } from "./NiceActionDomain";
|
|
2
|
-
import type { INiceActionDomain } from "./NiceActionDomain.types";
|
|
3
|
-
export declare const createActionDomain: <ACT_DOM extends Omit<INiceActionDomain, "allDomains">>(definition: ACT_DOM) => NiceActionDomain<ACT_DOM & {
|
|
4
|
-
allDomains: [string];
|
|
5
|
-
}>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { NiceActionDomain } from "../../ActionDomain/NiceActionDomain";
|
|
2
|
-
import type { INiceActionDomain, TActionHandlerForDomain, TActionIdHandlerForDomain, TBroadActionRequester } from "../../ActionDomain/NiceActionDomain.types";
|
|
3
|
-
import type { NiceActionPrimed } from "../../NiceAction/NiceActionPrimed";
|
|
4
|
-
export declare class NiceActionRequester {
|
|
5
|
-
private cases;
|
|
6
|
-
private _defaultRequester?;
|
|
7
|
-
handleAction(action: NiceActionPrimed<any, any, any>): Promise<unknown>;
|
|
8
|
-
/**
|
|
9
|
-
* Register a handler that fires for **any** action whose domain matches `domain`.
|
|
10
|
-
* `act.input` is typed as the union of input types for all actions in `domain`.
|
|
11
|
-
* First matching case wins.
|
|
12
|
-
*/
|
|
13
|
-
forDomain<FOR_DOM extends INiceActionDomain>(domain: NiceActionDomain<FOR_DOM>, handler: TActionHandlerForDomain<FOR_DOM>): this;
|
|
14
|
-
/**
|
|
15
|
-
* Register a handler that fires only for the specific action `id`.
|
|
16
|
-
* The handler's `action.input` is narrowed to the schema for that ID.
|
|
17
|
-
* First matching case wins.
|
|
18
|
-
*/
|
|
19
|
-
forActionId<ACT_DOM extends INiceActionDomain, ID extends keyof ACT_DOM["actions"] & string>(domain: NiceActionDomain<ACT_DOM>, id: ID, handler: TActionIdHandlerForDomain<ACT_DOM, ID>): this;
|
|
20
|
-
/**
|
|
21
|
-
* Register a handler that fires for any action whose id is in `ids`.
|
|
22
|
-
* The handler's `action.input` is narrowed to the union of those IDs' schemas.
|
|
23
|
-
* First matching case wins.
|
|
24
|
-
*/
|
|
25
|
-
forActionIds<ACT_DOM extends INiceActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actions"] & string>>(domain: NiceActionDomain<ACT_DOM>, ids: IDS, handler: TActionIdHandlerForDomain<ACT_DOM, IDS[number]>): this;
|
|
26
|
-
/**
|
|
27
|
-
* Register a fallback handler that fires when no other case matches.
|
|
28
|
-
* Only one default handler can be registered — calling this twice replaces the previous one.
|
|
29
|
-
*/
|
|
30
|
-
setDefaultHandler(handler: TBroadActionRequester<NiceActionPrimed<any, any, any>>): this;
|
|
31
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { NiceActionDomain } from "../../ActionDomain/NiceActionDomain";
|
|
2
|
-
import type { INiceActionDomain } from "../../ActionDomain/NiceActionDomain.types";
|
|
3
|
-
import type { INiceActionPrimed_JsonObject } from "../../NiceAction/NiceAction.types";
|
|
4
|
-
import type { NiceActionPrimed } from "../../NiceAction/NiceActionPrimed";
|
|
5
|
-
import { NiceActionResponse } from "../../NiceAction/NiceActionResponse";
|
|
6
|
-
import type { TActionResponderFn } from "./NiceActionResponder.types";
|
|
7
|
-
export declare class NiceActionDomainResponder<DOM extends INiceActionDomain> {
|
|
8
|
-
private _domain;
|
|
9
|
-
private _responders;
|
|
10
|
-
constructor(domain: NiceActionDomain<DOM>);
|
|
11
|
-
get domainId(): DOM["domain"];
|
|
12
|
-
/**
|
|
13
|
-
* Register a responder function for a specific action ID in this domain.
|
|
14
|
-
* The input and output types are inferred from the domain's schema for that action ID.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* createDomainResponder(myDomain)
|
|
19
|
-
* .resolve("myAction", async (input) => {
|
|
20
|
-
* return { result: await db.query(input.id) };
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
resolveAction<ID extends keyof DOM["actions"] & string>(actionId: ID, fn: TActionResponderFn<DOM["actions"][ID]>): this;
|
|
25
|
-
/**
|
|
26
|
-
* Internal: called by `NiceActionDomain._dispatchAction` when this resolver is registered
|
|
27
|
-
* as the domain's fallback. Calls the registered fn directly — no re-serialization.
|
|
28
|
-
* Errors from the fn propagate naturally (consistent with handler dispatch).
|
|
29
|
-
*
|
|
30
|
-
* Throws `resolver_action_not_registered` if no fn was registered for the action ID.
|
|
31
|
-
*/
|
|
32
|
-
_resolvePrimed(primed: NiceActionPrimed<any, any, any>): Promise<unknown>;
|
|
33
|
-
/**
|
|
34
|
-
* Internal: hydrate the wire action, call the registered resolver fn, and return a
|
|
35
|
-
* `NiceActionResponse`. Any error thrown by the resolver fn is caught and wrapped in the
|
|
36
|
-
* response as `{ ok: false }` via `castNiceError`.
|
|
37
|
-
*
|
|
38
|
-
* Throws `resolver_action_not_registered` if no fn was registered for the action ID.
|
|
39
|
-
* Throws `hydration_*` errors (from `NiceActionDomain.hydrateAction`) if the action ID
|
|
40
|
-
* is not part of this domain's schema.
|
|
41
|
-
*/
|
|
42
|
-
_dispatch<P extends INiceActionPrimed_JsonObject<DOM, string>>(wire: P): Promise<NiceActionResponse<DOM, P["id"], DOM["actions"][P["id"]]>>;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a `NiceActionDomainResolver` for `domain`.
|
|
46
|
-
* Chain `.resolve(actionId, fn)` calls to register typed resolver functions,
|
|
47
|
-
* then pass the resolver to `createResolverEnvironment`.
|
|
48
|
-
*/
|
|
49
|
-
export declare function createDomainResolver<DOM extends INiceActionDomain>(domain: NiceActionDomain<DOM>): NiceActionDomainResponder<DOM>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { MaybePromise, TInferInputFromSchema, TInferOutputFromSchema } from "../../ActionDomain/NiceActionDomain.types";
|
|
2
|
-
import type { NiceActionSchema } from "../../ActionSchema/NiceActionSchema";
|
|
3
|
-
/**
|
|
4
|
-
* A resolver function for a specific action.
|
|
5
|
-
* Receives the deserialized input and must return (or resolve to) the deserialized output.
|
|
6
|
-
*/
|
|
7
|
-
export type TActionResponderFn<SCH extends NiceActionSchema<any, any, any>> = (input: TInferInputFromSchema<SCH>["Input"]) => MaybePromise<TInferOutputFromSchema<SCH>["Output"]>;
|
package/build/types/ActionRequestResponse/ActionResponder/NiceActionResponderEnvironment.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { INiceActionDomain } from "../../ActionDomain/NiceActionDomain.types";
|
|
2
|
-
import type { INiceActionPrimed_JsonObject, TNiceActionResponse_JsonObject } from "../../NiceAction/NiceAction.types";
|
|
3
|
-
import type { NiceActionDomainResponder } from "./NiceActionResponder";
|
|
4
|
-
export declare class NiceActionResponderEnvironment {
|
|
5
|
-
private _resolvers;
|
|
6
|
-
constructor(resolvers: NiceActionDomainResponder<INiceActionDomain>[]);
|
|
7
|
-
/**
|
|
8
|
-
* Dispatch a serialized action to the matching domain resolver.
|
|
9
|
-
*
|
|
10
|
-
* Finds the resolver by `wire.domain`, hydrates the action, calls the registered fn,
|
|
11
|
-
* and returns the serialized response as `ISerializedNiceActionResponse`.
|
|
12
|
-
*
|
|
13
|
-
* Throws `resolver_domain_not_registered` if no resolver was registered for the domain.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* // server handler
|
|
18
|
-
* app.post("/actions", async (req, res) => {
|
|
19
|
-
* const response = await env.dispatch(req.body);
|
|
20
|
-
* res.json(response);
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
dispatch(wire: INiceActionPrimed_JsonObject<INiceActionDomain, string>): Promise<TNiceActionResponse_JsonObject>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create a `NiceActionResponderEnvironment` from one or more domain resolvers.
|
|
28
|
-
* The environment routes incoming serialized actions to the correct resolver by domain ID.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const env = createResponderEnvironment([
|
|
33
|
-
* createDomainResolver(paymentDomain)
|
|
34
|
-
* .resolve("chargeCard", async (input) => { ... }),
|
|
35
|
-
* createDomainResolver(authDomain)
|
|
36
|
-
* .resolve("login", async (input) => { ... }),
|
|
37
|
-
* ]);
|
|
38
|
-
*
|
|
39
|
-
* const serializedResponse = await env.dispatch(incomingWire);
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function createResponderEnvironment(resolvers: NiceActionDomainResponder<INiceActionDomain<any, any>>[]): NiceActionResponderEnvironment;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { err_cast_not_nice, type INiceErrorDomainProps, type InferNiceError, type JSONSerializableValue, type NiceErrorDomain } from "@nice-code/error";
|
|
2
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
import type { INiceActionErrorDeclaration, TInferDeclaredErrors, TNiceActonSchemaInputOptions, TTransportedValue } from "./NiceActionSchema.types";
|
|
4
|
-
export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any> = TTransportedValue<any, any>, OUTPUT extends TTransportedValue<any, any> = TTransportedValue<any>, ERRORS extends readonly INiceActionErrorDeclaration<any, any>[] = readonly []> {
|
|
5
|
-
private _errorDeclarations;
|
|
6
|
-
private inputOptions;
|
|
7
|
-
private outputOptions;
|
|
8
|
-
/**
|
|
9
|
-
* Declare the input schema (JSON-native or with explicit SERDE type param).
|
|
10
|
-
* For non-JSON-native inputs, prefer the 3-argument form below to avoid
|
|
11
|
-
* needing explicit type parameters.
|
|
12
|
-
*/
|
|
13
|
-
input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = never>(options: TNiceActonSchemaInputOptions<VS, SERDE_IN>): NiceActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
|
|
14
|
-
/**
|
|
15
|
-
* Declare the input schema with serialization via sequential parameters.
|
|
16
|
-
* TypeScript infers SERDE_IN from `serialize`'s return type (left-to-right),
|
|
17
|
-
* then provides it as the contextual type for `deserialize`'s parameter —
|
|
18
|
-
* no explicit type parameters or casts needed.
|
|
19
|
-
*/
|
|
20
|
-
input<VS extends StandardSchemaV1, SERDE_IN extends JSONSerializableValue>(options: {
|
|
21
|
-
schema: VS;
|
|
22
|
-
}, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_IN, deserialize: (serde: SERDE_IN) => StandardSchemaV1.InferInput<VS>): NiceActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
|
|
23
|
-
/**
|
|
24
|
-
* Declare the output schema (JSON-native or with explicit SERDE type param).
|
|
25
|
-
* For non-JSON-native outputs, prefer the 3-argument form below to avoid
|
|
26
|
-
* needing explicit type parameters.
|
|
27
|
-
*/
|
|
28
|
-
output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT extends JSONSerializableValue = JSONSerializableValue>(options: TNiceActonSchemaInputOptions<VS, SERDE_OUT>): NiceActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
|
|
29
|
-
/**
|
|
30
|
-
* Declare the output schema with serialization via sequential parameters.
|
|
31
|
-
* TypeScript infers SERDE_OUT from `serialize`'s return type (left-to-right),
|
|
32
|
-
* then provides it as the contextual type for `deserialize`'s parameter —
|
|
33
|
-
* no explicit type parameters or casts needed.
|
|
34
|
-
*/
|
|
35
|
-
output<VS extends StandardSchemaV1, SERDE_OUT extends JSONSerializableValue>(options: {
|
|
36
|
-
schema: VS;
|
|
37
|
-
}, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_OUT, deserialize: (serde: SERDE_OUT) => StandardSchemaV1.InferInput<VS>): NiceActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
|
|
38
|
-
/**
|
|
39
|
-
* Declare that this action may throw any error from `domain`.
|
|
40
|
-
* `TInferActionError` will include `NiceError<DEF, keyof schema>` in its union.
|
|
41
|
-
*/
|
|
42
|
-
throws<ERR_DEF extends INiceErrorDomainProps>(domain: NiceErrorDomain<ERR_DEF>): NiceActionSchema<INPUT, OUTPUT, readonly [...ERRORS, INiceActionErrorDeclaration<ERR_DEF, keyof ERR_DEF["schema"] & string>]>;
|
|
43
|
-
/**
|
|
44
|
-
* Declare that this action may throw only the listed `ids` from `domain`.
|
|
45
|
-
* `TInferActionError` will include `NiceError<DEF, IDS[number]>` narrowed to those IDs.
|
|
46
|
-
*/
|
|
47
|
-
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>]>;
|
|
48
|
-
/**
|
|
49
|
-
* Serialize raw input to a JSON-serializable form.
|
|
50
|
-
* Uses the schema's serialization.serialize if defined; otherwise the input
|
|
51
|
-
* is already JSON-native and is returned as-is.
|
|
52
|
-
*/
|
|
53
|
-
serializeInput(rawInput: INPUT[0]): JSONSerializableValue;
|
|
54
|
-
/**
|
|
55
|
-
* Deserialize a JSON value back into the raw input type.
|
|
56
|
-
* Uses serialization.deserialize if defined; otherwise the value is cast
|
|
57
|
-
* directly (it's already in the correct shape).
|
|
58
|
-
*/
|
|
59
|
-
deserializeInput(serialized: JSONSerializableValue): INPUT[0];
|
|
60
|
-
/**
|
|
61
|
-
* Validate raw input against the schema defined via `.input({ schema })`.
|
|
62
|
-
* Throws `action_input_validation_failed` if validation fails.
|
|
63
|
-
* Returns the validated (and possibly coerced) value on success.
|
|
64
|
-
* If no input schema was declared, the value is passed through as-is.
|
|
65
|
-
*/
|
|
66
|
-
validateInput(value: unknown, meta: {
|
|
67
|
-
domain: string;
|
|
68
|
-
actionId: string;
|
|
69
|
-
}): Promise<INPUT[0]>;
|
|
70
|
-
/**
|
|
71
|
-
* Serialize raw output to a JSON-serializable form.
|
|
72
|
-
*/
|
|
73
|
-
serializeOutput(rawOutput: OUTPUT[0]): OUTPUT[1];
|
|
74
|
-
/**
|
|
75
|
-
* Deserialize a JSON value back into the raw output type.
|
|
76
|
-
*/
|
|
77
|
-
deserializeOutput(serialized: OUTPUT[1]): OUTPUT[0];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Infers the full error union that a `NiceActionSchema` may throw.
|
|
81
|
-
*
|
|
82
|
-
* Includes every declared `NiceError<DEF, IDS>` from `.throws()` calls, plus
|
|
83
|
-
* `InferNiceError<typeof err_cast_not_nice>` as the always-present fallback
|
|
84
|
-
* for any unrecognized thrown value.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const payAction = action()
|
|
89
|
-
* .input({ schema: v.object({ amount: v.number() }) })
|
|
90
|
-
* .throws(err_payment)
|
|
91
|
-
* .throws(err_auth, ["unauthenticated"] as const);
|
|
92
|
-
*
|
|
93
|
-
* type PayError = TInferActionError<typeof payAction>;
|
|
94
|
-
* // → NiceError<ErrPaymentDef, keyof ErrPaymentSchema>
|
|
95
|
-
* // | NiceError<ErrAuthDef, "unauthenticated">
|
|
96
|
-
* // | NiceError<ErrCastNotNiceDef, keyof ErrCastNotNiceSchema>
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export type TInferActionError<SCH> = SCH extends NiceActionSchema<any, any, infer DECLS> ? DECLS extends readonly INiceActionErrorDeclaration[] ? TInferDeclaredErrors<DECLS> | InferNiceError<typeof err_cast_not_nice> : InferNiceError<typeof err_cast_not_nice> : never;
|