@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
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
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": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./build/types/index.d.ts",
|
|
9
9
|
"import": "./build/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./react-query": {
|
|
12
|
+
"types": "./build/types/react-query/index.d.ts",
|
|
13
|
+
"import": "./build/react-query/index.js"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"files": [
|
|
@@ -28,14 +32,20 @@
|
|
|
28
32
|
"build-types": "tsc --project tsconfig.build.json"
|
|
29
33
|
},
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"@nice-code/error": "0.0
|
|
32
|
-
"@nice-code/common-errors": "0.0
|
|
35
|
+
"@nice-code/error": "0.1.0",
|
|
36
|
+
"@nice-code/common-errors": "0.1.0",
|
|
33
37
|
"@standard-schema/spec": "^1.1.0",
|
|
34
38
|
"http-status-codes": "^2.3.0",
|
|
35
|
-
"nanoid": "^5.1.9"
|
|
39
|
+
"nanoid": "^5.1.9",
|
|
40
|
+
"std-env": "^4.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tanstack/react-query": "^5.100.3",
|
|
44
|
+
"msw": "^2.13.6"
|
|
36
45
|
},
|
|
37
|
-
"devDependencies": {},
|
|
38
46
|
"peerDependencies": {
|
|
47
|
+
"@tanstack/react-query": "^5.100.3",
|
|
48
|
+
"react": ">=18",
|
|
39
49
|
"valibot": "^1.3.1"
|
|
40
50
|
}
|
|
41
51
|
}
|
|
@@ -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 INiceErrorDefinedProps, type InferNiceError, type JSONSerializableValue, type NiceErrorDefined } 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 INiceErrorDefinedProps>(domain: NiceErrorDefined<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 INiceErrorDefinedProps, IDS extends ReadonlyArray<keyof ERR_DEF["schema"] & string>>(domain: NiceErrorDefined<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;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type INiceErrorDefinedProps, type JSONSerializableValue, type NiceErrorDefined } from "@nice-code/error";
|
|
2
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
export type TTransportedValue<RAW_VAL = never, SERDE_VAL extends JSONSerializableValue = never> = RAW_VAL extends JSONSerializableValue ? [RAW_VAL] | [RAW_VAL, SERDE_VAL] : [RAW_VAL, SERDE_VAL];
|
|
4
|
-
export type TNiceActionSerializationDefinition<RAW_VAL = any, SERDE_VAL extends JSONSerializableValue = JSONSerializableValue> = {
|
|
5
|
-
serialize: (value: RAW_VAL) => SERDE_VAL;
|
|
6
|
-
deserialize: (value: SERDE_VAL) => RAW_VAL;
|
|
7
|
-
};
|
|
8
|
-
export type TNiceActonSchemaInputOptions<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = JSONSerializableValue> = StandardSchemaV1.InferInput<VS> extends JSONSerializableValue ? {
|
|
9
|
-
schema: VS;
|
|
10
|
-
serialization?: TNiceActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
11
|
-
} : {
|
|
12
|
-
schema: VS;
|
|
13
|
-
serialization: TNiceActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* One error declaration on an action schema.
|
|
17
|
-
* `IDS` is the subset of error IDs that may be thrown. When the full
|
|
18
|
-
* `keyof schema` union is used it means any ID from the domain can be thrown.
|
|
19
|
-
*
|
|
20
|
-
* Build via `action().throws(domain)` or `action().throws(domain, ids)`.
|
|
21
|
-
*/
|
|
22
|
-
export interface INiceActionErrorDeclaration<ERR_DEF extends INiceErrorDefinedProps = INiceErrorDefinedProps, IDS extends keyof ERR_DEF["schema"] & string = keyof ERR_DEF["schema"] & string> {
|
|
23
|
-
readonly _domain: NiceErrorDefined<ERR_DEF>;
|
|
24
|
-
/** The specific IDs constrained for this declaration, or `undefined` meaning the full domain. */
|
|
25
|
-
readonly _ids: ReadonlyArray<IDS & string> | undefined;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Union of all `NiceError` types that can be thrown from a tuple of error declarations.
|
|
29
|
-
* Distributes over each declaration and unions the results.
|
|
30
|
-
*/
|
|
31
|
-
export type TInferDeclaredErrors<DECLS extends readonly INiceActionErrorDeclaration[]> = TInferErrorFromDeclaration<DECLS[number]>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { JSONSerializableValue } from "@nice-code/error";
|
|
2
|
-
import * as v from "valibot";
|
|
3
|
-
export declare const vNiceActionPrimedJsonObject: v.ObjectSchema<{
|
|
4
|
-
readonly id: v.StringSchema<undefined>;
|
|
5
|
-
readonly domain: v.StringSchema<undefined>;
|
|
6
|
-
readonly allDomains: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
7
|
-
readonly input: v.CustomSchema<JSONSerializableValue, undefined>;
|
|
8
|
-
}, undefined>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { JSONSerializableValue } from "@nice-code/error";
|
|
2
|
-
export declare const demo_domain: import("..").NiceActionDomain<{
|
|
3
|
-
domain: string;
|
|
4
|
-
actions: {
|
|
5
|
-
action1: import("..").NiceActionSchema<[{
|
|
6
|
-
a: string;
|
|
7
|
-
cust: JSONSerializableValue;
|
|
8
|
-
}] | [{
|
|
9
|
-
a: string;
|
|
10
|
-
cust: JSONSerializableValue;
|
|
11
|
-
}, any], [any] | [any, never], readonly []>;
|
|
12
|
-
action2: import("..").NiceActionSchema<[{
|
|
13
|
-
b: string;
|
|
14
|
-
custBad: Omit<import("..").INiceAction_JsonObject<import("..").INiceActionDomain<import("..").TPossibleDomainIdList, import("..").TNiceActionDomainSchema>, string>, "type"> & {
|
|
15
|
-
type: import("../NiceAction/NiceAction.types").EActionState.primed;
|
|
16
|
-
input: any;
|
|
17
|
-
timePrimed: number;
|
|
18
|
-
};
|
|
19
|
-
}] | [{
|
|
20
|
-
b: string;
|
|
21
|
-
custBad: Omit<import("..").INiceAction_JsonObject<import("..").INiceActionDomain<import("..").TPossibleDomainIdList, import("..").TNiceActionDomainSchema>, string>, "type"> & {
|
|
22
|
-
type: import("../NiceAction/NiceAction.types").EActionState.primed;
|
|
23
|
-
input: any;
|
|
24
|
-
timePrimed: number;
|
|
25
|
-
};
|
|
26
|
-
}, any], [any] | [any, never], readonly []>;
|
|
27
|
-
};
|
|
28
|
-
} & {
|
|
29
|
-
allDomains: [string];
|
|
30
|
-
}>;
|