@nice-code/action 0.0.21 → 0.1.1
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/README.md +410 -0
- package/build/index.js +1148 -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 +19 -21
- package/build/types/NiceAction/NiceAction.enums.d.ts +5 -0
- package/build/types/NiceAction/NiceAction.types.d.ts +8 -11
- 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 +22 -8
- package/build/types/react-query/index.d.ts +8 -10
- 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
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;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type INiceErrorDomainProps, type JSONSerializableValue, type NiceErrorDomain } 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 INiceErrorDomainProps = INiceErrorDomainProps, IDS extends keyof ERR_DEF["schema"] & string = keyof ERR_DEF["schema"] & string> {
|
|
23
|
-
readonly _domain: NiceErrorDomain<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
|
-
}>;
|