@nice-code/action 0.2.2 → 0.2.4
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 +3161 -3144
- package/build/react-query/index.js +5 -5
- package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +3 -3
- package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +5 -5
- package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +1 -1
- package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +3 -1
- package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +3 -0
- package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +2 -2
- package/build/types/ActionRuntime/ActionRuntime.d.ts +6 -4
- package/build/types/ActionRuntime/ActionRuntime.types.d.ts +2 -2
- package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +4 -4
- package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +4 -4
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +2 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +2 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +3 -3
- package/build/types/ActionRuntime/RuntimeCoordinate.d.ts +55 -0
- package/build/types/ActionRuntime/utils/runtimeCoordinateToStringIds.d.ts +2 -0
- package/build/types/errors/err_nice_action.d.ts +4 -4
- package/build/types/index.d.ts +1 -1
- package/build/types/nice_action.static.d.ts +2 -2
- package/build/types/react-query/hooks/useActionMutation.d.ts +7 -3
- package/build/types/react-query/hooks/useActionQuery.d.ts +4 -4
- package/package.json +1 -1
- package/build/types/ActionRuntime/Client/ActionClientSpecifier.d.ts +0 -47
- package/build/types/ActionRuntime/Client/utils/clientSpecifierToStringIds.d.ts +0 -2
|
@@ -3108,23 +3108,23 @@ function useActionMutation(action, options) {
|
|
|
3108
3108
|
});
|
|
3109
3109
|
}
|
|
3110
3110
|
// src/react-query/hooks/useActionQuery.ts
|
|
3111
|
-
function
|
|
3111
|
+
function actionQueryKey(action, input) {
|
|
3112
3112
|
if (input === undefined) {
|
|
3113
3113
|
return ["nice-action", action.domain, action.allDomains, action.id];
|
|
3114
3114
|
}
|
|
3115
3115
|
return ["nice-action", action.domain, action.allDomains, action.id, input];
|
|
3116
3116
|
}
|
|
3117
|
-
function
|
|
3117
|
+
function useActionQuery(action, input, options) {
|
|
3118
3118
|
const { enabled, ...queryOptions2 } = options ?? {};
|
|
3119
3119
|
return useQuery({
|
|
3120
|
-
queryKey: input != null ?
|
|
3120
|
+
queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),
|
|
3121
3121
|
queryFn: () => action.request(input).runToOutput(),
|
|
3122
3122
|
enabled: input != null && (enabled ?? true),
|
|
3123
3123
|
...queryOptions2
|
|
3124
3124
|
});
|
|
3125
3125
|
}
|
|
3126
3126
|
export {
|
|
3127
|
-
|
|
3127
|
+
useActionQuery,
|
|
3128
3128
|
useActionMutation,
|
|
3129
|
-
|
|
3129
|
+
actionQueryKey
|
|
3130
3130
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuntimeCoordinate } from "../../../ActionRuntime/RuntimeCoordinate";
|
|
2
2
|
import type { ActionDomain } from "../../Domain/ActionDomain";
|
|
3
3
|
import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../Domain/ActionDomain.types";
|
|
4
4
|
import { ActionBase } from "../ActionBase";
|
|
@@ -10,9 +10,9 @@ export declare class ActionContext<DOM extends IActionDomain, ID extends keyof D
|
|
|
10
10
|
readonly _routing: IActionRouteItem[];
|
|
11
11
|
readonly timeCreated: number;
|
|
12
12
|
readonly cuid: string;
|
|
13
|
-
originClient:
|
|
13
|
+
originClient: RuntimeCoordinate;
|
|
14
14
|
constructor(_domain: ActionDomain<DOM>, id: ID, hydrationData: IActionContext_Data);
|
|
15
|
-
_setOriginClient(client:
|
|
15
|
+
_setOriginClient(client: RuntimeCoordinate): void;
|
|
16
16
|
toJsonString(): string;
|
|
17
17
|
toContextDataJsonObject(): IActionContext_Data_JsonObject;
|
|
18
18
|
toJsonObject(): IActionContext_JsonObject<DOM, ID>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IRuntimeCoordinate, RuntimeCoordinate } from "../../../ActionRuntime/RuntimeCoordinate";
|
|
2
2
|
import type { IActionDomain } from "../../Domain/ActionDomain.types";
|
|
3
3
|
import type { EActionForm, IActionBase, IActionBase_JsonObject } from "../ActionBase.types";
|
|
4
4
|
import type { IActionRouteItemHandler } from "../Payload/ActionPayload.types";
|
|
5
5
|
export interface IActionRouteItem {
|
|
6
|
-
runtime:
|
|
6
|
+
runtime: RuntimeCoordinate;
|
|
7
7
|
handler: IActionRouteItemHandler;
|
|
8
8
|
time: number;
|
|
9
9
|
}
|
|
@@ -11,7 +11,7 @@ export interface IActionContext_Data {
|
|
|
11
11
|
cuid: string;
|
|
12
12
|
timeCreated: number;
|
|
13
13
|
routing: IActionRouteItem[];
|
|
14
|
-
originClient:
|
|
14
|
+
originClient: RuntimeCoordinate;
|
|
15
15
|
}
|
|
16
16
|
export interface IActionContext<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase<EActionForm.context, DOM, ID>, IActionContext_Data {
|
|
17
17
|
}
|
|
@@ -21,7 +21,7 @@ export interface IActionContext<DOM extends IActionDomain, ID extends keyof DOM[
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
export interface IActionRouteItem_JsonObject {
|
|
24
|
-
runtime:
|
|
24
|
+
runtime: IRuntimeCoordinate;
|
|
25
25
|
handler: IActionRouteItemHandler;
|
|
26
26
|
time: number;
|
|
27
27
|
}
|
|
@@ -29,7 +29,7 @@ export interface IActionContext_Data_JsonObject {
|
|
|
29
29
|
cuid: string;
|
|
30
30
|
timeCreated: number;
|
|
31
31
|
routing: IActionRouteItem_JsonObject[];
|
|
32
|
-
originClient:
|
|
32
|
+
originClient: IRuntimeCoordinate;
|
|
33
33
|
}
|
|
34
34
|
export interface IActionContext_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase_JsonObject<EActionForm.context, DOM, ID>, IActionContext_Data_JsonObject {
|
|
35
35
|
}
|
|
@@ -11,7 +11,7 @@ export declare class ActionCore<DOM extends IActionDomain, ID extends keyof DOM[
|
|
|
11
11
|
constructor(_domain: ActionDomain<DOM>, id: ID);
|
|
12
12
|
is<ACT extends IActionBase<any, any, any>>(action: ACT | unknown | null | undefined): action is TNarrowActionType<DOM, ACT, ID>;
|
|
13
13
|
toJsonObject(): IActionBase_JsonObject<EActionForm.core, DOM, ID>;
|
|
14
|
-
request(input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): ActionPayload_Request<DOM, ID>;
|
|
14
|
+
request(...args: [TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]] extends [never] ? [input?: never] : [input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]]): ActionPayload_Request<DOM, ID>;
|
|
15
15
|
deserializeInput(serialized: TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
16
16
|
serializeInput(raw: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"];
|
|
17
17
|
validateInput(input: unknown): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IExecuteActionOptions } from "../../ActionRuntime/Handler/ActionHandler.types";
|
|
2
|
+
import { ActionLocalHandler } from "../../ActionRuntime/Handler/Local/ActionLocalHandler";
|
|
2
3
|
import type { TAction_Any_JsonObject, TDistributeActionPayload_Request, TDistributeActionPayload_Result, TDistributedDomainActions, TNarrowActionJsonTypeToActionInstanceType } from "../Action/Action.combined.types";
|
|
3
4
|
import { type IActionBase } from "../Action/ActionBase.types";
|
|
4
5
|
import { ActionContext } from "../Action/Context/ActionContext";
|
|
@@ -7,7 +8,7 @@ import { ActionCore } from "../Action/Core/ActionCore";
|
|
|
7
8
|
import { type IActionPayload_Request_JsonObject, type IActionPayload_Result_JsonObject } from "../Action/Payload/ActionPayload.types";
|
|
8
9
|
import { ActionPayload_Request } from "../Action/Payload/ActionPayload_Request";
|
|
9
10
|
import type { RunningAction } from "../Action/RunningAction";
|
|
10
|
-
import type { IActionDomain, IActionDomainChildOptions, TActionDomainChildDef } from "./ActionDomain.types";
|
|
11
|
+
import type { IActionDomain, IActionDomainChildOptions, TActionDomainChildDef, TWrappableDomainActionHandler } from "./ActionDomain.types";
|
|
11
12
|
import { ActionDomainBase } from "./ActionDomainBase";
|
|
12
13
|
import { type ActionRootDomain } from "./ActionRootDomain";
|
|
13
14
|
type TActionMap<ACT_DOM extends IActionDomain> = {
|
|
@@ -26,6 +27,7 @@ export declare class ActionDomain<ACT_DOM extends IActionDomain = IActionDomain>
|
|
|
26
27
|
get action(): TActionMap<ACT_DOM>;
|
|
27
28
|
actionsMap(): TActionMap<ACT_DOM>;
|
|
28
29
|
actionForId<ID extends keyof ACT_DOM["actionSchema"] & string>(id: ID): ActionCore<ACT_DOM, ID>;
|
|
30
|
+
wrapAsLocalHandler(wrappedActionExecutor: TWrappableDomainActionHandler<ACT_DOM>): ActionLocalHandler;
|
|
29
31
|
hydrateContext<ID extends keyof ACT_DOM["actionSchema"] & string>(id: ID, contextData: IActionContext_Data_JsonObject): ActionContext<ACT_DOM, ID>;
|
|
30
32
|
isDomainAction<ACT extends IActionBase<any, ACT_DOM, any>>(action: ACT | unknown | null | undefined): action is TDistributedDomainActions<ACT_DOM, ACT>;
|
|
31
33
|
hydrateRequestPayload<ID extends keyof ACT_DOM["actionSchema"] & string, P extends IActionPayload_Request_JsonObject<ACT_DOM, ID>>(serialized: P): TDistributeActionPayload_Request<ACT_DOM, ID>;
|
|
@@ -38,3 +38,6 @@ export type TInferOutputFromSchema<SCH extends ActionSchema<any, any, any>> = SC
|
|
|
38
38
|
Output: OUT[0];
|
|
39
39
|
SerdeOutput: OUT[1];
|
|
40
40
|
} : never;
|
|
41
|
+
export type TWrappableDomainActionHandler<DOM extends IActionDomain> = {
|
|
42
|
+
[K in TDomainActionId<DOM>]: (...args: [TInferInputFromSchema<DOM["actionSchema"][K]>["Input"]] extends [never] ? [] : [input: TInferInputFromSchema<DOM["actionSchema"][K]>["Input"]]) => [TInferOutputFromSchema<DOM["actionSchema"][K]>["Output"]] extends [never] ? Promise<void> | void : Promise<TInferOutputFromSchema<DOM["actionSchema"][K]>["Output"]>;
|
|
43
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ActionRuntime } from "../../ActionRuntime/ActionRuntime";
|
|
2
|
-
import type { IActionClientSpecifier } from "../../ActionRuntime/Client/ActionClientSpecifier";
|
|
3
2
|
import type { IExecuteActionOptions } from "../../ActionRuntime/Handler/ActionHandler.types";
|
|
3
|
+
import type { IRuntimeCoordinate } from "../../ActionRuntime/RuntimeCoordinate";
|
|
4
4
|
import type { ActionPayload_Request } from "../Action/Payload/ActionPayload_Request";
|
|
5
5
|
import type { RunningAction } from "../Action/RunningAction";
|
|
6
6
|
import { ActionDomain } from "./ActionDomain";
|
|
@@ -18,6 +18,6 @@ export declare class ActionRootDomain<ROOT_DOM extends IActionRootDomain = IActi
|
|
|
18
18
|
[K in Exclude<keyof SUB_DOM, keyof IActionDomainChildOptions>]: never;
|
|
19
19
|
}): ActionDomain<TActionDomainChildDef<ROOT_DOM, SUB_DOM>>;
|
|
20
20
|
addActionRuntime(runtime: ActionRuntime): this;
|
|
21
|
-
getRuntime(clientSpecifier:
|
|
21
|
+
getRuntime(clientSpecifier: IRuntimeCoordinate): ActionRuntime | undefined;
|
|
22
22
|
_runAction<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string, ACT extends ActionPayload_Request<DOM, ID> = ActionPayload_Request<DOM, ID>>(actionPayload: ACT, options?: IExecuteActionOptions<DOM, ID>): Promise<RunningAction<DOM, ID>>;
|
|
23
23
|
}
|
|
@@ -3,18 +3,20 @@ import { type TActionPayload_Any_JsonObject } from "../ActionDefinition/Action/P
|
|
|
3
3
|
import { RunningAction } from "../ActionDefinition/Action/RunningAction";
|
|
4
4
|
import type { IActionDomain } from "../ActionDefinition/Domain/ActionDomain.types";
|
|
5
5
|
import type { IRuntimeMeta, TActionRuntimeHandler } from "./ActionRuntime.types";
|
|
6
|
-
import { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
|
|
7
6
|
import { type IHandleActionOptions, type TActionHandler } from "./Handler/ActionHandler.types";
|
|
8
7
|
import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
|
|
8
|
+
import { RuntimeCoordinate } from "./RuntimeCoordinate";
|
|
9
9
|
export declare class ActionRuntime {
|
|
10
|
-
|
|
10
|
+
private _coordinate;
|
|
11
11
|
readonly timeCreated: number;
|
|
12
12
|
readonly runtimeInfo: IRuntimeMeta;
|
|
13
13
|
private readonly actionRouter;
|
|
14
14
|
private readonly _pendingRunningActions;
|
|
15
15
|
private readonly _registeredExternalHandlers;
|
|
16
16
|
static getDefault(): ActionRuntime;
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(coordinate: RuntimeCoordinate);
|
|
18
|
+
get coordinate(): RuntimeCoordinate;
|
|
19
|
+
updateRuntimeCoordinate(newCoordinate: RuntimeCoordinate): void;
|
|
18
20
|
registerRunningAction(ra: RunningAction<any, any>): void;
|
|
19
21
|
resolveIncomingActionPayload(json: TActionPayload_Any_JsonObject<any, any>): void;
|
|
20
22
|
/**
|
|
@@ -38,6 +40,6 @@ export declare class ActionRuntime {
|
|
|
38
40
|
* Used to locate the return-path channel for dispatching results back to the action origin.
|
|
39
41
|
* Returns `undefined` if no handler matches (score > 0 required, i.e. at least id must match).
|
|
40
42
|
*/
|
|
41
|
-
getReturnHandlerForOrigin(originClient:
|
|
43
|
+
getReturnHandlerForOrigin(originClient: RuntimeCoordinate): ActionExternalClientHandler | undefined;
|
|
42
44
|
private _trySetupReturnDispatch;
|
|
43
45
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { RuntimeName } from "std-env";
|
|
2
2
|
import type { ActionRuntime } from "./ActionRuntime";
|
|
3
|
-
import type { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
|
|
4
3
|
import type { TActionHandler } from "./Handler/ActionHandler.types";
|
|
5
4
|
import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
|
|
6
5
|
import type { ActionLocalHandler } from "./Handler/Local/ActionLocalHandler";
|
|
6
|
+
import type { RuntimeCoordinate } from "./RuntimeCoordinate";
|
|
7
7
|
export interface IRuntimeMeta {
|
|
8
8
|
assumed: boolean;
|
|
9
9
|
runtimeName: RuntimeName;
|
|
10
10
|
}
|
|
11
11
|
export interface IRuntimeEnvironmentMeta {
|
|
12
|
-
client:
|
|
12
|
+
client: RuntimeCoordinate;
|
|
13
13
|
runtimeInfo: IRuntimeMeta;
|
|
14
14
|
}
|
|
15
15
|
export interface IActionRuntimeManagerContext {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TActionPayload_Any_Instance } from "../ActionDefinition/Action/Payload/ActionPayload.types";
|
|
2
2
|
import type { ActionRuntime } from "./ActionRuntime";
|
|
3
3
|
import type { IActionHandlerAndRuntime, IActionRuntimeManagerContext } from "./ActionRuntime.types";
|
|
4
|
-
import { type IActionClientSpecifier } from "./Client/ActionClientSpecifier";
|
|
5
4
|
import type { IHandleActionOptions } from "./Handler/ActionHandler.types";
|
|
5
|
+
import { type IRuntimeCoordinate } from "./RuntimeCoordinate";
|
|
6
6
|
export declare class ActionRuntimeManager {
|
|
7
7
|
private _runtimes;
|
|
8
8
|
private _preferredRuntimeClientId;
|
|
@@ -13,7 +13,7 @@ export declare class ActionRuntimeManager {
|
|
|
13
13
|
getRuntimeAndHandlerForActionOrThrow(action: TActionPayload_Any_Instance<any, any>, options?: IHandleActionOptions): IActionHandlerAndRuntime;
|
|
14
14
|
setPreferredRuntime(runtime: ActionRuntime): void;
|
|
15
15
|
getPreferredRuntime(): ActionRuntime | undefined;
|
|
16
|
-
getBestRuntimeForSpecifier(clientSpecifier:
|
|
17
|
-
getBestRuntime(clientSpecifier?:
|
|
18
|
-
getBestRuntimeOrThrow(specifier?:
|
|
16
|
+
getBestRuntimeForSpecifier(clientSpecifier: IRuntimeCoordinate): ActionRuntime | undefined;
|
|
17
|
+
getBestRuntime(clientSpecifier?: IRuntimeCoordinate): ActionRuntime | undefined;
|
|
18
|
+
getBestRuntimeOrThrow(specifier?: IRuntimeCoordinate): ActionRuntime;
|
|
19
19
|
}
|
|
@@ -4,8 +4,8 @@ import type { RunningAction } from "../../ActionDefinition/Action/RunningAction"
|
|
|
4
4
|
import type { TRunningActionUpdateListener } from "../../ActionDefinition/Action/RunningAction.types";
|
|
5
5
|
import type { IActionDomain } from "../../ActionDefinition/Domain/ActionDomain.types";
|
|
6
6
|
import type { ActionRuntime } from "../ActionRuntime";
|
|
7
|
-
import type { ActionClientSpecifier, IActionClientSpecifier } from "../Client/ActionClientSpecifier";
|
|
8
7
|
import type { ActionRouter } from "../Routing/ActionRouter";
|
|
8
|
+
import type { IRuntimeCoordinate, RuntimeCoordinate } from "../RuntimeCoordinate";
|
|
9
9
|
export declare enum EActionHandlerType {
|
|
10
10
|
external = "external",
|
|
11
11
|
local = "local"
|
|
@@ -14,14 +14,14 @@ export interface IActionHandler_Json<T extends EActionHandlerType> {
|
|
|
14
14
|
type: T;
|
|
15
15
|
}
|
|
16
16
|
export interface IActionHandler_ExternalClient_Json extends IActionHandler_Json<EActionHandlerType.external> {
|
|
17
|
-
client:
|
|
17
|
+
client: IRuntimeCoordinate;
|
|
18
18
|
}
|
|
19
19
|
export interface IActionHandler_Local_Json extends IActionHandler_Json<EActionHandlerType.local> {
|
|
20
20
|
}
|
|
21
21
|
export type TActionHandler_Json = IActionHandler_Local_Json | IActionHandler_ExternalClient_Json;
|
|
22
22
|
export interface IHandleActionOptions {
|
|
23
23
|
timeout?: number;
|
|
24
|
-
targetExternalClient?:
|
|
24
|
+
targetExternalClient?: RuntimeCoordinate;
|
|
25
25
|
targetLocalRuntime?: ActionRuntime;
|
|
26
26
|
}
|
|
27
27
|
export interface IExecuteActionOptions<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IHandleActionOptions {
|
|
@@ -53,7 +53,7 @@ export interface IActionHandler_Local extends IActionHandler_Base<EActionHandler
|
|
|
53
53
|
export interface IHandleActionOptions_External extends IHandleActionOptions {
|
|
54
54
|
}
|
|
55
55
|
export interface IActionHandler_ExternalClient extends IActionHandler_Base<EActionHandlerType.external> {
|
|
56
|
-
externalClient:
|
|
56
|
+
externalClient: RuntimeCoordinate;
|
|
57
57
|
handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_External) => Promise<RunningAction<DOM, ID>>;
|
|
58
58
|
_setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any>) => void): void;
|
|
59
59
|
}
|
|
@@ -5,14 +5,14 @@ import { RunningAction } from "../../../ActionDefinition/Action/RunningAction";
|
|
|
5
5
|
import type { ActionDomain } from "../../../ActionDefinition/Domain/ActionDomain";
|
|
6
6
|
import type { IActionDomain } from "../../../ActionDefinition/Domain/ActionDomain.types";
|
|
7
7
|
import { ActionRuntime } from "../../ActionRuntime";
|
|
8
|
-
import { ActionClientSpecifier } from "../../Client/ActionClientSpecifier";
|
|
9
8
|
import { ActionRouter } from "../../Routing/ActionRouter";
|
|
9
|
+
import { RuntimeCoordinate } from "../../RuntimeCoordinate";
|
|
10
10
|
import { ActionHandler } from "../ActionHandler";
|
|
11
11
|
import { EActionHandlerType, type IActionHandler_ExternalClient, type IActionHandler_ExternalClient_Json, type IHandleActionOptions } from "../ActionHandler.types";
|
|
12
12
|
import type { IActionExternalClientRequestHandlerConfig } from "./ActionExternalClientHandler.types";
|
|
13
13
|
import type { Transport } from "./Transport/Transport";
|
|
14
14
|
export declare class ActionExternalClientHandler extends ActionHandler<EActionHandlerType.external> implements IActionHandler_ExternalClient {
|
|
15
|
-
readonly externalClient:
|
|
15
|
+
readonly externalClient: RuntimeCoordinate;
|
|
16
16
|
readonly handlerType = EActionHandlerType.external;
|
|
17
17
|
readonly cuid: string;
|
|
18
18
|
private _defaultTimeout;
|
package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuntimeCoordinate } from "../../RuntimeCoordinate";
|
|
2
2
|
import type { TActionTransportDef } from "./Transport/Transport.combined.types";
|
|
3
3
|
export interface IActionExternalClientRequestHandlerConfig {
|
|
4
4
|
defaultTimeout?: number;
|
|
5
|
-
externalClientSpecifier:
|
|
5
|
+
externalClientSpecifier: RuntimeCoordinate;
|
|
6
6
|
transports: TActionTransportDef[];
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import type { IActionPayload_Request_JsonObject, IActionPayload_Result_JsonObjec
|
|
|
3
3
|
import type { ActionPayload_Request } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Request";
|
|
4
4
|
import type { ActionPayload_Result } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Result";
|
|
5
5
|
import type { RunningAction } from "../../../../ActionDefinition/Action/RunningAction";
|
|
6
|
-
import type {
|
|
6
|
+
import type { RuntimeCoordinate } from "../../../RuntimeCoordinate";
|
|
7
7
|
import type { Transport } from "./Transport";
|
|
8
8
|
export declare enum ETransportType {
|
|
9
9
|
ws = "ws",
|
|
@@ -56,8 +56,8 @@ export type TTransportStatusInfo_GetTransport_Output<READY extends IActionTransp
|
|
|
56
56
|
*
|
|
57
57
|
*/
|
|
58
58
|
export interface ITransportRouteClientParams {
|
|
59
|
-
localClient:
|
|
60
|
-
externalClient:
|
|
59
|
+
localClient: RuntimeCoordinate;
|
|
60
|
+
externalClient: RuntimeCoordinate;
|
|
61
61
|
}
|
|
62
62
|
export interface ITransportRouteActionParams extends ITransportRouteClientParams {
|
|
63
63
|
action: TActionPayload_Any_Instance<any, any>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface IRuntimeCoordinate {
|
|
2
|
+
/**
|
|
3
|
+
* A static runtime environment identifier (e.g. "web_app_v1", "backend_analytics")
|
|
4
|
+
*/
|
|
5
|
+
envId: string;
|
|
6
|
+
/**
|
|
7
|
+
* A unique and persistent client ID (should stay the same between runtime instance reloads)
|
|
8
|
+
*/
|
|
9
|
+
perId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A unique instance (or "memory-only") ID (unique for each instance of an action runtime, which should generally
|
|
12
|
+
* not persist between reloads, depending on the architecture)
|
|
13
|
+
*/
|
|
14
|
+
insId?: string;
|
|
15
|
+
}
|
|
16
|
+
export type TRuntimeCoordinateStringId = `envId[${string}]perId[${string | "_"}]:insId[${string | "_"}]`;
|
|
17
|
+
export interface IRuntimeFullCoordinates extends Required<IRuntimeCoordinate> {
|
|
18
|
+
}
|
|
19
|
+
export declare class RuntimeCoordinate implements IRuntimeCoordinate {
|
|
20
|
+
readonly envId: string;
|
|
21
|
+
readonly perId?: string;
|
|
22
|
+
readonly insId?: string;
|
|
23
|
+
static get unknown(): RuntimeCoordinate;
|
|
24
|
+
static env(envId: string): RuntimeCoordinate;
|
|
25
|
+
withPersistentId(perId: string): RuntimeCoordinate;
|
|
26
|
+
constructor({ envId, perId, insId }: IRuntimeCoordinate);
|
|
27
|
+
specify(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
|
|
28
|
+
specifyIfUnset(newInputs: Omit<IRuntimeCoordinate, "envId">): RuntimeCoordinate;
|
|
29
|
+
toJsonObject(): IRuntimeCoordinate;
|
|
30
|
+
isExactlySame(other: IRuntimeCoordinate): boolean;
|
|
31
|
+
isSameFor(other: IRuntimeCoordinate): {
|
|
32
|
+
id: boolean;
|
|
33
|
+
perId: boolean;
|
|
34
|
+
insId: boolean;
|
|
35
|
+
};
|
|
36
|
+
similarityLevel(other: IRuntimeCoordinate): number;
|
|
37
|
+
get stringId(): TRuntimeCoordinateStringId;
|
|
38
|
+
/**
|
|
39
|
+
* Takes the "Runtime Coordinate" and generates a list of full coordinate IDs representing the runtime
|
|
40
|
+
* with decreasing levels of specificity.
|
|
41
|
+
*
|
|
42
|
+
* The first full coordinate ID is the most specific (including instance ID), while the last ID is
|
|
43
|
+
* the least specific (only environment ID).
|
|
44
|
+
*
|
|
45
|
+
* Example output for a RuntimeCoordinate with envId "web_app", perId "user123", and insId "instance456":
|
|
46
|
+
* [
|
|
47
|
+
* "envId[web_app]perId[user123]:insId[instance456]",
|
|
48
|
+
* "envId[web_app]perId[user123]:insId[_]",
|
|
49
|
+
* "envId[web_app]perId[_]:insId[_]"
|
|
50
|
+
* ]
|
|
51
|
+
*
|
|
52
|
+
* @returns a list of "full" runtime coordinate IDs with decreasing accuracy for targeting a runtime.
|
|
53
|
+
*/
|
|
54
|
+
toStringIds(): TRuntimeCoordinateStringId[];
|
|
55
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IActionRuntimeManagerContext } from "../ActionRuntime/ActionRuntime.types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RuntimeCoordinate, TRuntimeCoordinateStringId } from "../ActionRuntime/RuntimeCoordinate";
|
|
3
3
|
export declare enum EErrId_NiceAction {
|
|
4
4
|
not_implemented = "not_implemented",
|
|
5
5
|
action_id_not_in_domain = "action_id_not_in_domain",
|
|
@@ -53,7 +53,7 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain
|
|
|
53
53
|
no_action_execution_handler: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
54
54
|
domain: string;
|
|
55
55
|
actionId: string;
|
|
56
|
-
specifiedClient?:
|
|
56
|
+
specifiedClient?: RuntimeCoordinate;
|
|
57
57
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
58
58
|
wire_action_not_payload: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
59
59
|
domain: string;
|
|
@@ -63,11 +63,11 @@ export declare const err_nice_action: import("@nice-code/error").NiceErrorDomain
|
|
|
63
63
|
wire_not_action_data: import("@nice-code/error").INiceErrorIdMetadata<any, import("@nice-code/error").JSONSerializableValue>;
|
|
64
64
|
client_runtime_already_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
65
65
|
context?: IActionRuntimeManagerContext;
|
|
66
|
-
client:
|
|
66
|
+
client: RuntimeCoordinate;
|
|
67
67
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
68
68
|
client_runtime_not_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
69
69
|
context?: IActionRuntimeManagerContext;
|
|
70
|
-
clientStringId:
|
|
70
|
+
clientStringId: TRuntimeCoordinateStringId;
|
|
71
71
|
}, import("@nice-code/error").JSONSerializableValue>;
|
|
72
72
|
no_client_runtimes_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
73
73
|
context?: IActionRuntimeManagerContext;
|
package/build/types/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export { createActionRootDomain } from "./ActionDefinition/Domain/helpers/create
|
|
|
14
14
|
export { ActionSchema, actionSchema, type TInferActionError, } from "./ActionDefinition/Schema/ActionSchema";
|
|
15
15
|
export type { TActionSchemaOptions, TActionSerializationDefinition, TTransportedValue, } from "./ActionDefinition/Schema/ActionSchema.types";
|
|
16
16
|
export { ActionRuntime } from "./ActionRuntime/ActionRuntime";
|
|
17
|
-
export { ActionClientSpecifier, type IActionClientSpecifier, } from "./ActionRuntime/Client/ActionClientSpecifier";
|
|
18
17
|
export { ActionExternalClientHandler, createExternalClientHandler, } from "./ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler";
|
|
19
18
|
export * from "./ActionRuntime/Handler/ExternalClient/err_nice_external_client";
|
|
20
19
|
export * from "./ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport";
|
|
@@ -25,6 +24,7 @@ export type { TActionTransportDef } from "./ActionRuntime/Handler/ExternalClient
|
|
|
25
24
|
export * from "./ActionRuntime/Handler/ExternalClient/Transport/Transport.types";
|
|
26
25
|
export * from "./ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket";
|
|
27
26
|
export { ActionLocalHandler, createLocalHandler, } from "./ActionRuntime/Handler/Local/ActionLocalHandler";
|
|
27
|
+
export { type IRuntimeCoordinate, RuntimeCoordinate, } from "./ActionRuntime/RuntimeCoordinate";
|
|
28
28
|
export { EErrId_NiceAction, err_nice_action } from "./errors/err_nice_action";
|
|
29
29
|
export { isActionPayload_Any_JsonObject } from "./utils/isActionPayload_Any_JsonObject";
|
|
30
30
|
export * from "./utils/isActionPayload_Request_JsonObject";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const DEFAULT_TRANSPORT_TIMEOUT = 10000;
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const UNSET_RUNTIME_ENV_ID = "_unset_";
|
|
3
|
+
export declare const UNSET_RUNTIME_PER_ID = "_0_0_";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type UseMutationOptions, type UseMutationResult } from "@tanstack/react-query";
|
|
2
2
|
import type { ActionCore } from "../../ActionDefinition/Action/Core/ActionCore";
|
|
3
3
|
import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../ActionDefinition/Domain/ActionDomain.types";
|
|
4
|
-
import type { TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
|
|
5
|
-
|
|
6
|
-
export
|
|
4
|
+
import type { ActionSchema, TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
|
|
5
|
+
/** When an action has no input schema (Input = never), use void so mutate() needs no arguments. */
|
|
6
|
+
export type TActionMutationVars<SCH extends ActionSchema<any, any, any>> = [
|
|
7
|
+
TInferInputFromSchema<SCH>["Input"]
|
|
8
|
+
] extends [never] ? void : TInferInputFromSchema<SCH>["Input"];
|
|
9
|
+
export type TUseNiceMutationOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TContext = unknown> = Omit<UseMutationOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TActionMutationVars<SCH>, TContext>, "mutationFn">;
|
|
10
|
+
export declare function useActionMutation<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TContext = unknown>(action: ActionCore<DOM, ID>, options?: TUseNiceMutationOptions<DOM, ID, SCH, TContext>): UseMutationResult<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TActionMutationVars<SCH>, TContext>;
|
|
@@ -2,8 +2,8 @@ import { type QueryKey, type UseQueryOptions, type UseQueryResult } from "@tanst
|
|
|
2
2
|
import type { ActionCore } from "../../ActionDefinition/Action/Core/ActionCore";
|
|
3
3
|
import type { IActionDomain, TInferInputFromSchema, TInferOutputFromSchema } from "../../ActionDefinition/Domain/ActionDomain.types";
|
|
4
4
|
import type { TInferActionError } from "../../ActionDefinition/Schema/ActionSchema";
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function actionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>): readonly ["nice-action", DOM["domain"], DOM["allDomains"], ID];
|
|
6
|
+
export declare function actionQueryKey<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): readonly [
|
|
7
7
|
"nice-action",
|
|
8
8
|
DOM["domain"],
|
|
9
9
|
DOM["allDomains"],
|
|
@@ -11,5 +11,5 @@ export declare function niceActionQueryKey<DOM extends IActionDomain, ID extends
|
|
|
11
11
|
TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"],
|
|
12
12
|
string | undefined
|
|
13
13
|
];
|
|
14
|
-
export type
|
|
15
|
-
export declare function
|
|
14
|
+
export type TUseActionQueryOptions<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID] = DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]> = Omit<UseQueryOptions<TInferOutputFromSchema<SCH>["Output"], TInferActionError<SCH>, TSelect, QueryKey>, "queryKey" | "queryFn">;
|
|
15
|
+
export declare function useActionQuery<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, SCH extends DOM["actionSchema"][ID], TSelect = TInferOutputFromSchema<SCH>["Output"]>(action: ActionCore<DOM, ID>, input: TInferInputFromSchema<SCH>["Input"] | null | undefined, options?: TUseActionQueryOptions<DOM, ID, SCH, TSelect>): UseQueryResult<TSelect, TInferActionError<SCH>>;
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export interface IActionClientSpecifier {
|
|
2
|
-
/**
|
|
3
|
-
* A static client identifier (e.g. "web_app_v1", "backend_analytics")
|
|
4
|
-
*/
|
|
5
|
-
id: string;
|
|
6
|
-
/**
|
|
7
|
-
* A unique and persistant ID (between client instance reloads)
|
|
8
|
-
*/
|
|
9
|
-
perId?: string;
|
|
10
|
-
/**
|
|
11
|
-
* A unique instance ID (unique for each instance of a client, does not persist between reloads)
|
|
12
|
-
*/
|
|
13
|
-
insId?: string;
|
|
14
|
-
}
|
|
15
|
-
export type TClientSpecifierStringId = `id[${string}]perId[${string | "_"}]:insId[${string | "_"}]`;
|
|
16
|
-
export interface IActionClientFullSpecifier extends Required<IActionClientSpecifier> {
|
|
17
|
-
}
|
|
18
|
-
export declare class ActionClientSpecifier implements IActionClientSpecifier {
|
|
19
|
-
readonly id: string;
|
|
20
|
-
readonly perId?: string;
|
|
21
|
-
readonly insId?: string;
|
|
22
|
-
static get unknown(): ActionClientSpecifier;
|
|
23
|
-
static root(id: string): ActionClientSpecifier;
|
|
24
|
-
withPersistentId(perId: string): ActionClientSpecifier;
|
|
25
|
-
constructor({ id, perId, insId }: IActionClientSpecifier);
|
|
26
|
-
specify(newInputs: Omit<IActionClientSpecifier, "id">): ActionClientSpecifier;
|
|
27
|
-
specifyIfUnset(newInputs: Omit<IActionClientSpecifier, "id">): ActionClientSpecifier;
|
|
28
|
-
toJsonObject(): IActionClientSpecifier;
|
|
29
|
-
isExactlySame(other: IActionClientSpecifier): boolean;
|
|
30
|
-
isSameFor(other: IActionClientSpecifier): {
|
|
31
|
-
id: boolean;
|
|
32
|
-
perId: boolean;
|
|
33
|
-
insId: boolean;
|
|
34
|
-
};
|
|
35
|
-
similarityLevel(other: IActionClientSpecifier): number;
|
|
36
|
-
get stringId(): TClientSpecifierStringId;
|
|
37
|
-
/**
|
|
38
|
-
* Generates a list of string IDs representing the client with decreasing levels of specificity.
|
|
39
|
-
* The first ID is the most specific (including instance ID), while the last ID is the least specific (only client ID).
|
|
40
|
-
*
|
|
41
|
-
* Example output for a client with id "web_app", perId "user123", and insId "instance456":
|
|
42
|
-
* ["id[web_app]perId[user123]:insId[instance456]", "id[web_app]perId[user123]:insId[_]", "id[web_app]perId[_]:insId[_]"]
|
|
43
|
-
*
|
|
44
|
-
* @returns a list of "string IDs" with decreasing target accuracy for the client
|
|
45
|
-
*/
|
|
46
|
-
toStringIds(): TClientSpecifierStringId[];
|
|
47
|
-
}
|