@nice-code/action 0.1.3 → 0.2.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 +1 -410
- package/build/index.js +5176 -1970
- package/build/react-query/index.js +7 -7
- package/build/types/ActionDefinition/Action/Action.combined.types.d.ts +37 -0
- package/build/types/ActionDefinition/Action/ActionBase.d.ts +14 -0
- package/build/types/ActionDefinition/Action/ActionBase.types.d.ts +24 -0
- package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +25 -0
- package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +35 -0
- package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +19 -0
- package/build/types/ActionDefinition/Action/Core/ActionCore.types.d.ts +10 -0
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.d.ts +14 -0
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.types.d.ts +106 -0
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Progress.d.ts +15 -0
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Request.d.ts +24 -0
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Result.d.ts +18 -0
- package/build/types/ActionDefinition/Action/RunningAction.d.ts +33 -0
- package/build/types/ActionDefinition/Action/RunningAction.types.d.ts +71 -0
- package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +29 -0
- package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +40 -0
- package/build/types/ActionDefinition/Domain/ActionDomainBase.d.ts +14 -0
- package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +23 -0
- package/build/types/ActionDefinition/Domain/helpers/createRootActionDomain.d.ts +5 -0
- package/build/types/{ActionSchema/NiceActionSchema.d.ts → ActionDefinition/Schema/ActionSchema.d.ts} +15 -34
- package/build/types/ActionDefinition/Schema/ActionSchema.types.d.ts +28 -0
- package/build/types/ActionRuntime/ActionDomainManager.d.ts +13 -0
- package/build/types/ActionRuntime/ActionRuntime.d.ts +48 -0
- package/build/types/ActionRuntime/ActionRuntime.types.d.ts +22 -0
- package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +19 -0
- package/build/types/ActionRuntime/Client/ActionClientSpecifier.d.ts +47 -0
- package/build/types/ActionRuntime/Client/utils/clientSpecifierToStringIds.d.ts +2 -0
- package/build/types/ActionRuntime/Handler/ActionHandler.d.ts +16 -0
- package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +68 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +42 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +7 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/ConnectionTransportManager.d.ts +9 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.d.ts +7 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.types.d.ts +11 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.d.ts +8 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.types.d.ts +17 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.combined.types.d.ts +4 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.d.ts +13 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +106 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.d.ts +13 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.types.d.ts +13 -0
- package/build/types/{ActionRuntimeEnvironment/ActionConnect → ActionRuntime/Handler/ExternalClient}/Transport/err_nice_transport.d.ts +5 -7
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/addTransportStatusMetadata.d.ts +2 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/createUnsetTransportResolvers.d.ts +2 -0
- package/build/types/ActionRuntime/Handler/ExternalClient/err_nice_external_client.d.ts +5 -0
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.d.ts +55 -0
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.types.d.ts +7 -0
- package/build/types/ActionRuntime/Routing/ActionRouter.d.ts +55 -0
- package/build/types/ActionRuntime/Routing/ActionRouter.types.d.ts +20 -0
- package/build/types/ActionRuntime/test/helpers/new_action_test_data.d.ts +207 -0
- package/build/types/errors/err_nice_action.d.ts +22 -12
- package/build/types/index.d.ts +31 -32
- package/build/types/nice_action.static.d.ts +3 -0
- package/build/types/react-query/index.d.ts +9 -10
- package/build/types/utils/assertIsActionJson.d.ts +2 -0
- package/build/types/utils/getAssumedRuntimeEnvironment.d.ts +2 -0
- package/build/types/utils/isActionPayload_Any_JsonObject.d.ts +2 -0
- package/build/types/utils/isActionPayload_Progress_JsonObject.d.ts +2 -0
- package/build/types/utils/isActionPayload_Request_JsonObject.d.ts +2 -0
- package/build/types/utils/isActionPayload_Result_JsonObject.d.ts +2 -0
- package/build/types/utils/isAction_Any_Instance.d.ts +3 -0
- package/build/types/utils/isAction_Any_JsonObject.d.ts +2 -0
- package/build/types/utils/isAction_Base_JsonObject.d.ts +2 -0
- package/build/types/utils/isAction_Context_JsonObject.d.ts +2 -0
- package/build/types/utils/isAction_Core_JsonObject.d.ts +2 -0
- package/build/types/utils/wait.utils.d.ts +13 -0
- package/package.json +3 -3
- package/build/types/ActionDomain/NiceActionDomain.d.ts +0 -40
- package/build/types/ActionDomain/NiceActionDomain.types.d.ts +0 -37
- package/build/types/ActionDomain/NiceActionDomainBase.d.ts +0 -14
- package/build/types/ActionDomain/RootDomain/NiceActionRootDomain.d.ts +0 -22
- package/build/types/ActionDomain/helpers/createRootActionDomain.d.ts +0 -5
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.d.ts +0 -24
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.types.d.ts +0 -15
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.d.ts +0 -12
- package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.types.d.ts +0 -6
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.d.ts +0 -19
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.types.d.ts +0 -70
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportCustom.d.ts +0 -12
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportHttp.d.ts +0 -9
- package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportWebSocket.d.ts +0 -17
- package/build/types/ActionRuntimeEnvironment/ActionConnect/err_nice_connect.d.ts +0 -5
- package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.d.ts +0 -80
- package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.types.d.ts +0 -69
- package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.d.ts +0 -32
- package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.types.d.ts +0 -15
- package/build/types/ActionRuntimeEnvironment/utils/getAssumedRuntimeEnvironment.d.ts +0 -2
- package/build/types/ActionSchema/NiceActionSchema.types.d.ts +0 -32
- package/build/types/ActionSchema/action.d.ts +0 -2
- package/build/types/NiceAction/MatchAction/MatchAction.d.ts +0 -27
- package/build/types/NiceAction/NiceAction.d.ts +0 -64
- package/build/types/NiceAction/NiceAction.enums.d.ts +0 -5
- package/build/types/NiceAction/NiceAction.types.d.ts +0 -78
- package/build/types/NiceAction/NiceActionCombined.types.d.ts +0 -10
- package/build/types/NiceAction/NiceActionPrimed.d.ts +0 -43
- package/build/types/NiceAction/NiceActionResponse.d.ts +0 -42
- package/build/types/NiceAction/utils/isNiceActionInstance.d.ts +0 -3
- package/build/types/utils/isActionResponseJsonObject.d.ts +0 -2
- package/build/types/utils/isPrimedActionJsonObject.d.ts +0 -2
- /package/build/types/{ActionRuntimeEnvironment/ActionConnect → ActionRuntime/Handler/ExternalClient}/Transport/err_nice_transport_ws.d.ts +0 -0
- /package/build/types/utils/{maybePromise.d.ts → typescript/MaybePromise.d.ts} +0 -0
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { INiceAction } from "../NiceAction/NiceAction.types";
|
|
2
|
-
import type { IActionHandler, TStoredHandlers } from "./ActionHandler/ActionHandler.types";
|
|
3
|
-
import type { IActionRuntimeEnvironment_JsonObject, IRuntimeMeta } from "./ActionRuntimeEnvironment.types";
|
|
4
|
-
interface IActionRuntimeEnvironment_Constructor_Input {
|
|
5
|
-
envId: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class ActionRuntimeEnvironment {
|
|
8
|
-
readonly envId: string;
|
|
9
|
-
/**
|
|
10
|
-
* A unique identifier for this runtime environment instance.
|
|
11
|
-
*
|
|
12
|
-
* Format: `${envId}::${randomSuffix}` where `envId` is the runtime static ID and `randomSuffix` is a short random
|
|
13
|
-
* string to distinguish multiple instances of the same runtime.
|
|
14
|
-
*/
|
|
15
|
-
readonly memCuid: string;
|
|
16
|
-
readonly timeCreated: number;
|
|
17
|
-
readonly runtimeInfo: IRuntimeMeta;
|
|
18
|
-
private _handlersByTag;
|
|
19
|
-
private _defaultHandlers;
|
|
20
|
-
constructor(input: IActionRuntimeEnvironment_Constructor_Input);
|
|
21
|
-
addHandlers(handlers: IActionHandler[]): this;
|
|
22
|
-
setDefaultHandler(handler: TStoredHandlers, tag?: string): this;
|
|
23
|
-
getDefaultHandler(tag?: string): TStoredHandlers | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Return the first handler registered for the given matchTag, or undefined
|
|
26
|
-
* if none has been registered.
|
|
27
|
-
*/
|
|
28
|
-
getHandlerForAction(action: Pick<INiceAction<any, any>, "domain" | "id">, tag?: string): IActionHandler | undefined;
|
|
29
|
-
toJsonObject(): IActionRuntimeEnvironment_JsonObject;
|
|
30
|
-
}
|
|
31
|
-
export declare const createActionRuntime: (config: IActionRuntimeEnvironment_Constructor_Input) => ActionRuntimeEnvironment;
|
|
32
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { RuntimeName } from "std-env";
|
|
2
|
-
export interface IRuntimeMeta {
|
|
3
|
-
assumed: boolean;
|
|
4
|
-
runtimeName: RuntimeName;
|
|
5
|
-
}
|
|
6
|
-
export interface IActionRuntimeEnvironment_JsonObject {
|
|
7
|
-
envId: string;
|
|
8
|
-
memCuid: string;
|
|
9
|
-
timeCreated: number;
|
|
10
|
-
runtimeInfo: IRuntimeMeta;
|
|
11
|
-
}
|
|
12
|
-
export interface IRuntimeEnvironmentMeta {
|
|
13
|
-
envId?: string;
|
|
14
|
-
runtimeInfo: IRuntimeMeta;
|
|
15
|
-
}
|
|
@@ -1,32 +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 TNiceActionJsonSerializableValue = JSONSerializableValue;
|
|
4
|
-
export type TTransportedValue<RAW_VAL, SERDE_VAL extends TNiceActionJsonSerializableValue> = RAW_VAL extends TNiceActionJsonSerializableValue ? [RAW_VAL] | [RAW_VAL, SERDE_VAL] : [RAW_VAL, SERDE_VAL];
|
|
5
|
-
export type TNiceActionSerializationDefinition<RAW_VAL = any, SERDE_VAL extends TNiceActionJsonSerializableValue = TNiceActionJsonSerializableValue> = {
|
|
6
|
-
serialize: (value: RAW_VAL) => SERDE_VAL;
|
|
7
|
-
deserialize: (value: SERDE_VAL) => RAW_VAL;
|
|
8
|
-
};
|
|
9
|
-
export type TNiceActonSchemaOptions<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends TNiceActionJsonSerializableValue = TNiceActionJsonSerializableValue> = StandardSchemaV1.InferInput<VS> extends TNiceActionJsonSerializableValue ? {
|
|
10
|
-
schema: VS;
|
|
11
|
-
serialization?: TNiceActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
12
|
-
} : {
|
|
13
|
-
schema: VS;
|
|
14
|
-
serialization: TNiceActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* One error declaration on an action schema.
|
|
18
|
-
* `IDS` is the subset of error IDs that may be thrown. When the full
|
|
19
|
-
* `keyof schema` union is used it means any ID from the domain can be thrown.
|
|
20
|
-
*
|
|
21
|
-
* Build via `action().throws(domain)` or `action().throws(domain, ids)`.
|
|
22
|
-
*/
|
|
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
|
-
/** The specific IDs constrained for this declaration, or `undefined` meaning the full domain. */
|
|
26
|
-
readonly _ids: ReadonlyArray<IDS & string> | undefined;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Union of all `NiceError` types that can be thrown from a tuple of error declarations.
|
|
30
|
-
* Distributes over each declaration and unions the results.
|
|
31
|
-
*/
|
|
32
|
-
export type TInferDeclaredErrors<DECLS extends readonly INiceActionErrorDeclaration[]> = TInferErrorFromDeclaration<DECLS[number]>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { INiceActionDomain } from "../../ActionDomain/NiceActionDomain.types";
|
|
2
|
-
import type { MaybePromise } from "../../utils/maybePromise";
|
|
3
|
-
import type { INiceAction } from "../NiceAction.types";
|
|
4
|
-
import type { TNarrowActionType } from "../NiceActionCombined.types";
|
|
5
|
-
type TMatchHandler<A extends INiceAction<any>> = (action: A) => MaybePromise<void>;
|
|
6
|
-
type THandlerForId<ACT extends INiceAction<any>> = (action: ACT) => MaybePromise<void>;
|
|
7
|
-
declare class MatchAction<ACT extends INiceAction<any>> {
|
|
8
|
-
readonly action: ACT;
|
|
9
|
-
private _entries;
|
|
10
|
-
private _otherwise?;
|
|
11
|
-
constructor(action: ACT);
|
|
12
|
-
with<D extends INiceActionDomain, ID extends keyof D["actions"] & string>(opts: {
|
|
13
|
-
domain: D;
|
|
14
|
-
id: ID;
|
|
15
|
-
handler: THandlerForId<TNarrowActionType<ACT, D, ID>>;
|
|
16
|
-
}): this;
|
|
17
|
-
with<D extends INiceActionDomain>(opts: {
|
|
18
|
-
domain: D;
|
|
19
|
-
handler: TMatchHandler<TNarrowActionType<ACT, D, keyof D["actions"] & string>>;
|
|
20
|
-
}): this;
|
|
21
|
-
otherwise(handler: TMatchHandler<ACT>): this;
|
|
22
|
-
private _findMatch;
|
|
23
|
-
run(): boolean;
|
|
24
|
-
runAsync(): Promise<boolean>;
|
|
25
|
-
}
|
|
26
|
-
export declare const matchAction: <ACT extends INiceAction<any>>(action: ACT) => MatchAction<ACT>;
|
|
27
|
-
export {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { JSONSerializableValue } from "@nice-code/error";
|
|
2
|
-
import type { NiceActionDomain } from "../ActionDomain/NiceActionDomain";
|
|
3
|
-
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
4
|
-
import type { IActionMetaInputs } from "../ActionRuntimeEnvironment/ActionHandler/ActionHandler.types";
|
|
5
|
-
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
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";
|
|
9
|
-
import { NiceActionPrimed } from "./NiceActionPrimed";
|
|
10
|
-
import { NiceActionResponse } from "./NiceActionResponse";
|
|
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> {
|
|
12
|
-
readonly actionDomain: NiceActionDomain<DOM>;
|
|
13
|
-
readonly schema: SCH;
|
|
14
|
-
readonly type = EActionState.empty;
|
|
15
|
-
readonly id: ID;
|
|
16
|
-
readonly domain: DOM["domain"];
|
|
17
|
-
readonly allDomains: DOM["allDomains"];
|
|
18
|
-
readonly timeCreated: number;
|
|
19
|
-
readonly cuid: string;
|
|
20
|
-
constructor(actionDomain: NiceActionDomain<DOM>, schema: SCH, id: ID, hydrationData?: Pick<INiceAction_JsonObject<DOM, ID>, "cuid" | "timeCreated">);
|
|
21
|
-
/**
|
|
22
|
-
* Serialize this action definition (without input) to a JSON-safe object.
|
|
23
|
-
* Useful for describing which action will be invoked without yet having input.
|
|
24
|
-
*/
|
|
25
|
-
toJsonObject(): INiceAction_JsonObject<DOM, ID>;
|
|
26
|
-
toJsonString(): string;
|
|
27
|
-
toHttpResponse(): Response;
|
|
28
|
-
is<ACT extends INiceAction<any>>(action: ACT | unknown | null | undefined): action is TNarrowActionType<ACT, DOM, ID>;
|
|
29
|
-
prime(input: TInferInputFromSchema<SCH>["Input"], hydrationData?: Pick<INiceActionPrimed_JsonObject<DOM, ID>, "timePrimed">): NiceActionPrimed<DOM, ID, SCH>;
|
|
30
|
-
execute(input: TInferInputFromSchema<SCH>["Input"], meta?: IActionMetaInputs): Promise<TInferOutputFromSchema<SCH>["Output"]>;
|
|
31
|
-
/**
|
|
32
|
-
* Like `execute`, but catches thrown errors and returns a `NiceActionResult` discriminated union
|
|
33
|
-
* instead of propagating. On success: `{ ok: true, output }`. On failure: `{ ok: false, error }`.
|
|
34
|
-
*
|
|
35
|
-
* The `error` type is the union of all `NiceError` types declared via `.throws()` on the schema,
|
|
36
|
-
* plus `InferNiceError<typeof err_cast_not_nice>` as the always-present fallback.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* const result = await domain.action("getUser").executeSafe({ userId: "123" });
|
|
41
|
-
* if (!result.ok) {
|
|
42
|
-
* result.error.handleWithSync([
|
|
43
|
-
* forDomain(err_auth, (h) => res.status(401).end()),
|
|
44
|
-
* ]);
|
|
45
|
-
* return;
|
|
46
|
-
* }
|
|
47
|
-
* console.log(result.output); // typed as the action's OUTPUT
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
executeSafe(input: TInferInputFromSchema<SCH>["Input"], meta?: IActionMetaInputs): Promise<TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>>;
|
|
51
|
-
/**
|
|
52
|
-
* Prime this action with input, execute it, and return a `NiceActionResponse`
|
|
53
|
-
* that carries both the original primed action (domain + actionId + input) and
|
|
54
|
-
* the result (`{ ok: true, output }` or `{ ok: false, error }`).
|
|
55
|
-
*
|
|
56
|
-
* The response can be serialized for cross-boundary transport via `toJsonObject()`.
|
|
57
|
-
* Reconstruct on the receiving end with `domain.hydrateResponse(wire)`.
|
|
58
|
-
*/
|
|
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
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { INiceErrorJsonObject } from "@nice-code/error";
|
|
2
|
-
import type { INiceActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
3
|
-
import type { EActionState } from "./NiceAction.enums";
|
|
4
|
-
export interface INiceAction<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> {
|
|
5
|
-
id: ID;
|
|
6
|
-
type: EActionState;
|
|
7
|
-
domain: DOM["domain"];
|
|
8
|
-
allDomains: DOM["allDomains"];
|
|
9
|
-
schema: DOM["actions"][ID];
|
|
10
|
-
cuid: string;
|
|
11
|
-
timeCreated: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Wire format for a serialized NiceActionPrimed — safe to JSON.stringify / transmit.
|
|
15
|
-
*/
|
|
16
|
-
export type INiceAction_JsonObject<DOM extends INiceActionDomain = INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = {
|
|
17
|
-
type: EActionState.empty;
|
|
18
|
-
domain: DOM["domain"];
|
|
19
|
-
allDomains: DOM["allDomains"];
|
|
20
|
-
id: ID;
|
|
21
|
-
cuid: string;
|
|
22
|
-
timeCreated: number;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Wire format for a serialized NiceActionPrimed — safe to JSON.stringify / transmit.
|
|
26
|
-
*/
|
|
27
|
-
export type INiceActionPrimed_JsonObject<DOM extends INiceActionDomain = INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = Omit<INiceAction_JsonObject<DOM, ID>, "type"> & {
|
|
28
|
-
type: EActionState.primed;
|
|
29
|
-
input: TInferInputFromSchema<DOM["actions"][ID]>["SerdeInput"];
|
|
30
|
-
timePrimed: number;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Return type of `executeSafe` — a discriminated union of success and failure.
|
|
34
|
-
*
|
|
35
|
-
* - `{ ok: true; output: OUT }` — the action completed and returned `OUT`
|
|
36
|
-
* - `{ ok: false; error: ERR }` — the action threw; `ERR` is the declared error union
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* const result = await domain.action("getUser").executeSafe({ userId: "123" });
|
|
41
|
-
* if (!result.ok) {
|
|
42
|
-
* result.error.handleWithSync([
|
|
43
|
-
* forDomain(err_auth, (h) => res.status(401).end()),
|
|
44
|
-
* ]);
|
|
45
|
-
* return;
|
|
46
|
-
* }
|
|
47
|
-
* console.log(result.output); // typed as the action's OUTPUT
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export type TNiceActionResult<OUT, ERR> = {
|
|
51
|
-
ok: true;
|
|
52
|
-
output: OUT;
|
|
53
|
-
} | {
|
|
54
|
-
ok: false;
|
|
55
|
-
error: ERR;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Wire format for a serialized NiceActionResponse — safe to JSON.stringify / transmit.
|
|
59
|
-
*
|
|
60
|
-
* Carries the original action identity (domain + actionId + serialized input) alongside
|
|
61
|
-
* either the serialized output value or a serialized NiceError.
|
|
62
|
-
*
|
|
63
|
-
* Produced by `NiceActionResponse.toJsonObject()`.
|
|
64
|
-
* Reconstructed by `NiceActionDomain.hydrateResponse()`.
|
|
65
|
-
*/
|
|
66
|
-
export interface INiceActionResponse_JsonObject_Base<DOM extends INiceActionDomain, ID extends keyof DOM["actions"] & string> extends Omit<INiceActionPrimed_JsonObject<DOM, ID>, "type"> {
|
|
67
|
-
type: EActionState.resolved;
|
|
68
|
-
timeResponded: number;
|
|
69
|
-
}
|
|
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> & {
|
|
71
|
-
ok: true;
|
|
72
|
-
output: TInferOutputFromSchema<DOM["actions"][ID]>["SerdeOutput"];
|
|
73
|
-
};
|
|
74
|
-
export type INiceActionResponse_JsonObject_Failure<DOM extends INiceActionDomain = INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = INiceActionResponse_JsonObject_Base<DOM, ID> & {
|
|
75
|
-
ok: false;
|
|
76
|
-
error: INiceErrorJsonObject;
|
|
77
|
-
};
|
|
78
|
-
export type TNiceActionResponse_JsonObject<DOM extends INiceActionDomain = INiceActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> = INiceActionResponse_JsonObject_Success<DOM, ID> | INiceActionResponse_JsonObject_Failure<DOM, ID>;
|
|
@@ -1,10 +0,0 @@
|
|
|
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,43 +0,0 @@
|
|
|
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";
|
|
4
|
-
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
5
|
-
import type { NiceAction } from "./NiceAction";
|
|
6
|
-
import { EActionState } from "./NiceAction.enums";
|
|
7
|
-
import { type INiceAction, type INiceActionPrimed_JsonObject, type TNiceActionResponse_JsonObject, type TNiceActionResult } from "./NiceAction.types";
|
|
8
|
-
import { NiceActionResponse } from "./NiceActionResponse";
|
|
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> {
|
|
10
|
-
readonly coreAction: NiceAction<DOM, ID, SCH>;
|
|
11
|
-
private _input;
|
|
12
|
-
readonly type = EActionState.primed;
|
|
13
|
-
readonly domain: DOM["domain"];
|
|
14
|
-
readonly allDomains: DOM["allDomains"];
|
|
15
|
-
readonly id: ID;
|
|
16
|
-
readonly timePrimed: number;
|
|
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;
|
|
23
|
-
/**
|
|
24
|
-
* Serialize this primed action to a JSON-safe wire format.
|
|
25
|
-
* The input is passed through the schema's serialize function if one is defined,
|
|
26
|
-
* otherwise the (already JSON-native) input is used as-is.
|
|
27
|
-
*/
|
|
28
|
-
toJsonObject(): INiceActionPrimed_JsonObject<DOM, ID>;
|
|
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>;
|
|
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"]>;
|
|
36
|
-
/**
|
|
37
|
-
* Like `execute`, but catches thrown errors and returns a `NiceActionResult` discriminated union
|
|
38
|
-
* instead of propagating. On success: `{ ok: true, output }`. On failure: `{ ok: false, error }`.
|
|
39
|
-
*
|
|
40
|
-
* Mirrors `NiceAction.executeSafe` — useful when re-executing a hydrated primed action.
|
|
41
|
-
*/
|
|
42
|
-
executeSafe(meta?: IActionMetaInputs): Promise<TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>>;
|
|
43
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { INiceActionDomain, TInferOutputFromSchema } from "../ActionDomain/NiceActionDomain.types";
|
|
2
|
-
import type { IRuntimeEnvironmentMeta } from "../ActionRuntimeEnvironment/ActionRuntimeEnvironment.types";
|
|
3
|
-
import type { TInferActionError } from "../ActionSchema/NiceActionSchema";
|
|
4
|
-
import type { NiceAction } from "./NiceAction";
|
|
5
|
-
import { EActionState } from "./NiceAction.enums";
|
|
6
|
-
import { type INiceAction, type TNiceActionResponse_JsonObject, type TNiceActionResult } from "./NiceAction.types";
|
|
7
|
-
import { NiceActionPrimed } from "./NiceActionPrimed";
|
|
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;
|
|
10
|
-
readonly domain: DOM["domain"];
|
|
11
|
-
readonly allDomains: DOM["allDomains"];
|
|
12
|
-
readonly id: ID;
|
|
13
|
-
readonly primed: NiceActionPrimed<DOM, ID, SCH>;
|
|
14
|
-
readonly result: TNiceActionResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>>;
|
|
15
|
-
readonly timeResponded: number;
|
|
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;
|
|
21
|
-
/**
|
|
22
|
-
* Serialize this response to a JSON-safe wire format.
|
|
23
|
-
*
|
|
24
|
-
* On success, the output is passed through the schema's serialize function
|
|
25
|
-
* if one is defined, otherwise used as-is.
|
|
26
|
-
* On failure, the error is serialized via `NiceError.toJsonObject()`.
|
|
27
|
-
*/
|
|
28
|
-
toJsonObject(): TNiceActionResponse_JsonObject;
|
|
29
|
-
toJsonString(): string;
|
|
30
|
-
hydrateResponseJson(wire: TNiceActionResponse_JsonObject<DOM, ID>): NiceActionResponse<DOM, ID, SCH>;
|
|
31
|
-
toHttpResponse({ useErrorStatus }?: {
|
|
32
|
-
useErrorStatus?: boolean;
|
|
33
|
-
}): Response;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Reconstruct a loosely-typed NiceActionResponse from its wire format.
|
|
37
|
-
* Called by `NiceActionDomain.hydrateResponse` — not part of the public API.
|
|
38
|
-
*
|
|
39
|
-
* The result's error type is `NiceError<TUnknownNiceErrorDef>` (from `castNiceError`).
|
|
40
|
-
* Use `handleWith` / `forDomain` / `isExact` to narrow on the receiving end.
|
|
41
|
-
*/
|
|
42
|
-
export declare function hydrateNiceActionResponse<DOM extends INiceActionDomain>(wire: TNiceActionResponse_JsonObject, coreAction: NiceAction<DOM, keyof DOM["actions"] & string, DOM["actions"][keyof DOM["actions"] & string]>): NiceActionResponse<DOM, keyof DOM["actions"] & string, DOM["actions"][keyof DOM["actions"] & string]>;
|
|
File without changes
|
|
File without changes
|