@nice-code/action 0.1.3 → 0.2.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.
Files changed (104) hide show
  1. package/README.md +1 -410
  2. package/build/index.js +5176 -1970
  3. package/build/react-query/index.js +7 -7
  4. package/build/types/ActionDefinition/Action/Action.combined.types.d.ts +27 -0
  5. package/build/types/ActionDefinition/Action/ActionBase.d.ts +14 -0
  6. package/build/types/ActionDefinition/Action/ActionBase.types.d.ts +24 -0
  7. package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +26 -0
  8. package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +35 -0
  9. package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +20 -0
  10. package/build/types/ActionDefinition/Action/Core/ActionCore.types.d.ts +10 -0
  11. package/build/types/ActionDefinition/Action/Payload/ActionPayload.d.ts +14 -0
  12. package/build/types/ActionDefinition/Action/Payload/ActionPayload.types.d.ts +106 -0
  13. package/build/types/ActionDefinition/Action/Payload/ActionPayload_Progress.d.ts +15 -0
  14. package/build/types/ActionDefinition/Action/Payload/ActionPayload_Request.d.ts +24 -0
  15. package/build/types/ActionDefinition/Action/Payload/ActionPayload_Result.d.ts +18 -0
  16. package/build/types/ActionDefinition/Action/RunningAction.d.ts +33 -0
  17. package/build/types/ActionDefinition/Action/RunningAction.types.d.ts +65 -0
  18. package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +30 -0
  19. package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +37 -0
  20. package/build/types/ActionDefinition/Domain/ActionDomainBase.d.ts +14 -0
  21. package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +23 -0
  22. package/build/types/ActionDefinition/Domain/helpers/createRootActionDomain.d.ts +5 -0
  23. package/build/types/{ActionSchema/NiceActionSchema.d.ts → ActionDefinition/Schema/ActionSchema.d.ts} +10 -29
  24. package/build/types/ActionDefinition/Schema/ActionSchema.types.d.ts +32 -0
  25. package/build/types/ActionRuntime/ActionDomainManager.d.ts +13 -0
  26. package/build/types/ActionRuntime/ActionRuntime.d.ts +48 -0
  27. package/build/types/ActionRuntime/ActionRuntime.types.d.ts +22 -0
  28. package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +19 -0
  29. package/build/types/ActionRuntime/Client/ActionClientSpecifier.d.ts +47 -0
  30. package/build/types/ActionRuntime/Client/utils/clientSpecifierToStringIds.d.ts +2 -0
  31. package/build/types/ActionRuntime/Handler/ActionHandler.d.ts +16 -0
  32. package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +68 -0
  33. package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +42 -0
  34. package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +7 -0
  35. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/ConnectionTransportManager.d.ts +9 -0
  36. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.d.ts +7 -0
  37. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.types.d.ts +11 -0
  38. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.d.ts +8 -0
  39. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.types.d.ts +17 -0
  40. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.combined.types.d.ts +4 -0
  41. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.d.ts +13 -0
  42. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +106 -0
  43. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.d.ts +13 -0
  44. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.types.d.ts +13 -0
  45. package/build/types/{ActionRuntimeEnvironment/ActionConnect → ActionRuntime/Handler/ExternalClient}/Transport/err_nice_transport.d.ts +5 -7
  46. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/addTransportStatusMetadata.d.ts +2 -0
  47. package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/createUnsetTransportResolvers.d.ts +2 -0
  48. package/build/types/ActionRuntime/Handler/ExternalClient/err_nice_external_client.d.ts +5 -0
  49. package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.d.ts +55 -0
  50. package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.types.d.ts +6 -0
  51. package/build/types/ActionRuntime/Routing/ActionRouter.d.ts +55 -0
  52. package/build/types/ActionRuntime/Routing/ActionRouter.types.d.ts +20 -0
  53. package/build/types/ActionRuntime/test/helpers/new_action_test_data.d.ts +301 -0
  54. package/build/types/errors/err_nice_action.d.ts +22 -12
  55. package/build/types/index.d.ts +31 -32
  56. package/build/types/nice_action.static.d.ts +3 -0
  57. package/build/types/react-query/index.d.ts +9 -10
  58. package/build/types/utils/assertIsActionJson.d.ts +2 -0
  59. package/build/types/utils/getAssumedRuntimeEnvironment.d.ts +2 -0
  60. package/build/types/utils/isActionPayload_Any_JsonObject.d.ts +2 -0
  61. package/build/types/utils/isActionPayload_Progress_JsonObject.d.ts +2 -0
  62. package/build/types/utils/isActionPayload_Request_JsonObject.d.ts +2 -0
  63. package/build/types/utils/isActionPayload_Result_JsonObject.d.ts +2 -0
  64. package/build/types/utils/isAction_Any_Instance.d.ts +3 -0
  65. package/build/types/utils/isAction_Any_JsonObject.d.ts +2 -0
  66. package/build/types/utils/isAction_Base_JsonObject.d.ts +2 -0
  67. package/build/types/utils/isAction_Context_JsonObject.d.ts +2 -0
  68. package/build/types/utils/isAction_Core_JsonObject.d.ts +2 -0
  69. package/build/types/utils/wait.utils.d.ts +13 -0
  70. package/package.json +3 -3
  71. package/build/types/ActionDomain/NiceActionDomain.d.ts +0 -40
  72. package/build/types/ActionDomain/NiceActionDomain.types.d.ts +0 -37
  73. package/build/types/ActionDomain/NiceActionDomainBase.d.ts +0 -14
  74. package/build/types/ActionDomain/RootDomain/NiceActionRootDomain.d.ts +0 -22
  75. package/build/types/ActionDomain/helpers/createRootActionDomain.d.ts +0 -5
  76. package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.d.ts +0 -24
  77. package/build/types/ActionRuntimeEnvironment/ActionConnect/ActionConnect.types.d.ts +0 -15
  78. package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.d.ts +0 -12
  79. package/build/types/ActionRuntimeEnvironment/ActionConnect/ConnectionConfig/ConnectionConfig.types.d.ts +0 -6
  80. package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.d.ts +0 -19
  81. package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/Transport.types.d.ts +0 -70
  82. package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportCustom.d.ts +0 -12
  83. package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportHttp.d.ts +0 -9
  84. package/build/types/ActionRuntimeEnvironment/ActionConnect/Transport/TransportWebSocket.d.ts +0 -17
  85. package/build/types/ActionRuntimeEnvironment/ActionConnect/err_nice_connect.d.ts +0 -5
  86. package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.d.ts +0 -80
  87. package/build/types/ActionRuntimeEnvironment/ActionHandler/ActionHandler.types.d.ts +0 -69
  88. package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.d.ts +0 -32
  89. package/build/types/ActionRuntimeEnvironment/ActionRuntimeEnvironment.types.d.ts +0 -15
  90. package/build/types/ActionRuntimeEnvironment/utils/getAssumedRuntimeEnvironment.d.ts +0 -2
  91. package/build/types/ActionSchema/NiceActionSchema.types.d.ts +0 -32
  92. package/build/types/ActionSchema/action.d.ts +0 -2
  93. package/build/types/NiceAction/MatchAction/MatchAction.d.ts +0 -27
  94. package/build/types/NiceAction/NiceAction.d.ts +0 -64
  95. package/build/types/NiceAction/NiceAction.enums.d.ts +0 -5
  96. package/build/types/NiceAction/NiceAction.types.d.ts +0 -78
  97. package/build/types/NiceAction/NiceActionCombined.types.d.ts +0 -10
  98. package/build/types/NiceAction/NiceActionPrimed.d.ts +0 -43
  99. package/build/types/NiceAction/NiceActionResponse.d.ts +0 -42
  100. package/build/types/NiceAction/utils/isNiceActionInstance.d.ts +0 -3
  101. package/build/types/utils/isActionResponseJsonObject.d.ts +0 -2
  102. package/build/types/utils/isPrimedActionJsonObject.d.ts +0 -2
  103. /package/build/types/{ActionRuntimeEnvironment/ActionConnect → ActionRuntime/Handler/ExternalClient}/Transport/err_nice_transport_ws.d.ts +0 -0
  104. /package/build/types/utils/{maybePromise.d.ts → typescript/MaybePromise.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { err_cast_not_nice, type INiceErrorDomainProps, type InferNiceError, type JSONSerializableValue, type NiceErrorDomain } from "@nice-code/error";
2
2
  import type { StandardSchemaV1 } from "@standard-schema/spec";
3
- import type { INiceActionErrorDeclaration, TInferDeclaredErrors, TNiceActonSchemaOptions, TTransportedValue } from "./NiceActionSchema.types";
4
- export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any> = never, OUTPUT extends TTransportedValue<any, any> = never, ERRORS extends readonly INiceActionErrorDeclaration<any, any>[] = readonly []> {
3
+ import type { IActionErrorDeclaration, TActionSchemaOptions, TInferDeclaredErrors, TTransportedValue } from "./ActionSchema.types";
4
+ export declare class ActionSchema<INPUT extends TTransportedValue<any, any> = never, OUTPUT extends TTransportedValue<any, any> = never, ERRORS extends readonly IActionErrorDeclaration<any, any>[] = readonly []> {
5
5
  private _errorDeclarations;
6
6
  private inputOptions;
7
7
  private outputOptions;
@@ -12,7 +12,7 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
12
12
  * For non-JSON-native inputs, prefer the 3-argument form below to avoid
13
13
  * needing explicit type parameters.
14
14
  */
15
- input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = never>(options: TNiceActonSchemaOptions<VS, SERDE_IN>): NiceActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
15
+ input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends JSONSerializableValue = never>(options: TActionSchemaOptions<VS, SERDE_IN>): ActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
16
16
  /**
17
17
  * Declare the input schema with serialization via sequential parameters.
18
18
  * TypeScript infers SERDE_IN from `serialize`'s return type (left-to-right),
@@ -21,13 +21,13 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
21
21
  */
22
22
  input<VS extends StandardSchemaV1, SERDE_IN extends JSONSerializableValue>(options: {
23
23
  schema: VS;
24
- }, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_IN, deserialize: (serde: SERDE_IN) => StandardSchemaV1.InferInput<VS>): NiceActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
24
+ }, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_IN, deserialize: (serde: SERDE_IN) => StandardSchemaV1.InferInput<VS>): ActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
25
25
  /**
26
26
  * Declare the output schema (JSON-native or with explicit SERDE type param).
27
27
  * For non-JSON-native outputs, prefer the 3-argument form below to avoid
28
28
  * needing explicit type parameters.
29
29
  */
30
- output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT extends JSONSerializableValue = JSONSerializableValue>(options: TNiceActonSchemaOptions<VS, SERDE_OUT>): NiceActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
30
+ output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT extends JSONSerializableValue = JSONSerializableValue>(options: TActionSchemaOptions<VS, SERDE_OUT>): ActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
31
31
  /**
32
32
  * Declare the output schema with serialization via sequential parameters.
33
33
  * TypeScript infers SERDE_OUT from `serialize`'s return type (left-to-right),
@@ -36,17 +36,17 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
36
36
  */
37
37
  output<VS extends StandardSchemaV1, SERDE_OUT extends JSONSerializableValue>(options: {
38
38
  schema: VS;
39
- }, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_OUT, deserialize: (serde: SERDE_OUT) => StandardSchemaV1.InferInput<VS>): NiceActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
39
+ }, serialize: (raw: StandardSchemaV1.InferInput<VS>) => SERDE_OUT, deserialize: (serde: SERDE_OUT) => StandardSchemaV1.InferInput<VS>): ActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
40
40
  /**
41
41
  * Declare that this action may throw any error from `domain`.
42
42
  * `TInferActionError` will include `NiceError<DEF, keyof schema>` in its union.
43
43
  */
44
- throws<ERR_DEF extends INiceErrorDomainProps>(domain: NiceErrorDomain<ERR_DEF>): NiceActionSchema<INPUT, OUTPUT, readonly [...ERRORS, INiceActionErrorDeclaration<ERR_DEF, keyof ERR_DEF["schema"] & string>]>;
44
+ throws<ERR_DEF extends INiceErrorDomainProps>(domain: NiceErrorDomain<ERR_DEF>): ActionSchema<INPUT, OUTPUT, readonly [...ERRORS, IActionErrorDeclaration<ERR_DEF, keyof ERR_DEF["schema"] & string>]>;
45
45
  /**
46
46
  * Declare that this action may throw only the listed `ids` from `domain`.
47
47
  * `TInferActionError` will include `NiceError<DEF, IDS[number]>` narrowed to those IDs.
48
48
  */
49
- 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>]>;
49
+ throws<ERR_DEF extends INiceErrorDomainProps, IDS extends ReadonlyArray<keyof ERR_DEF["schema"] & string>>(domain: NiceErrorDomain<ERR_DEF>, ids: IDS): ActionSchema<INPUT, OUTPUT, readonly [...ERRORS, IActionErrorDeclaration<ERR_DEF, IDS[number] & string>]>;
50
50
  /**
51
51
  * Serialize raw input to a JSON-serializable form.
52
52
  * Uses the schema's serialization.serialize if defined; otherwise the input
@@ -82,24 +82,5 @@ export declare class NiceActionSchema<INPUT extends TTransportedValue<any, any>
82
82
  */
83
83
  deserializeOutput(serialized: OUTPUT[1]): OUTPUT[0];
84
84
  }
85
- /**
86
- * Infers the full error union that a `NiceActionSchema` may throw.
87
- *
88
- * Includes every declared `NiceError<DEF, IDS>` from `.throws()` calls, plus
89
- * `InferNiceError<typeof err_cast_not_nice>` as the always-present fallback
90
- * for any unrecognized thrown value.
91
- *
92
- * @example
93
- * ```ts
94
- * const payAction = action()
95
- * .input({ schema: v.object({ amount: v.number() }) })
96
- * .throws(err_payment)
97
- * .throws(err_auth, ["unauthenticated"] as const);
98
- *
99
- * type PayError = TInferActionError<typeof payAction>;
100
- * // → NiceError<ErrPaymentDef, keyof ErrPaymentSchema>
101
- * // | NiceError<ErrAuthDef, "unauthenticated">
102
- * // | NiceError<ErrCastNotNiceDef, keyof ErrCastNotNiceSchema>
103
- * ```
104
- */
105
- 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;
85
+ export type TInferActionError<SCH> = SCH extends ActionSchema<any, any, infer DECLS> ? DECLS extends readonly IActionErrorDeclaration[] ? TInferDeclaredErrors<DECLS> | InferNiceError<typeof err_cast_not_nice> : InferNiceError<typeof err_cast_not_nice> : never;
86
+ export declare const actionSchema: () => ActionSchema;
@@ -0,0 +1,32 @@
1
+ import { type INiceErrorDomainProps, type JSONSerializableValue, type NiceErrorDomain } from "@nice-code/error";
2
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
3
+ export type TActionJsonSerializableValue = JSONSerializableValue;
4
+ export type TTransportedValue<RAW_VAL, SERDE_VAL extends TActionJsonSerializableValue> = RAW_VAL extends TActionJsonSerializableValue ? [RAW_VAL] | [RAW_VAL, SERDE_VAL] : [RAW_VAL, SERDE_VAL];
5
+ export type TActionSerializationDefinition<RAW_VAL = any, SERDE_VAL extends TActionJsonSerializableValue = TActionJsonSerializableValue> = {
6
+ serialize: (value: RAW_VAL) => SERDE_VAL;
7
+ deserialize: (value: SERDE_VAL) => RAW_VAL;
8
+ };
9
+ export type TActionSchemaOptions<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN extends TActionJsonSerializableValue = TActionJsonSerializableValue> = StandardSchemaV1.InferInput<VS> extends TActionJsonSerializableValue ? {
10
+ schema: VS;
11
+ serialization?: TActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
12
+ } : {
13
+ schema: VS;
14
+ serialization: TActionSerializationDefinition<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 IActionErrorDeclaration<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 IActionErrorDeclaration[]> = TInferErrorFromDeclaration<DECLS[number]>;
@@ -0,0 +1,13 @@
1
+ import type { TAction_Any_JsonObject, TNarrowActionJsonTypeToActionInstanceType } from "../ActionDefinition/Action/Action.combined.types";
2
+ import type { INiceActionIdAndDomain } from "../ActionDefinition/Action/ActionBase.types";
3
+ import type { ActionDomain } from "../ActionDefinition/Domain/ActionDomain";
4
+ import type { IActionDomain } from "../ActionDefinition/Domain/ActionDomain.types";
5
+ export declare class ActionDomainManager {
6
+ private _domains;
7
+ addDomain(domain: ActionDomain<any>): void;
8
+ getDomains(): ActionDomain<any>[];
9
+ verifyIsActionJson(action: INiceActionIdAndDomain<any>): void;
10
+ getActionDomain<DOM extends IActionDomain, ACT extends INiceActionIdAndDomain<DOM>>(action: ACT): ActionDomain<DOM> | undefined;
11
+ getActionDomainOrThrow<DOM extends IActionDomain, ACT extends INiceActionIdAndDomain<DOM>>(action: ACT): ActionDomain<DOM>;
12
+ hydrateActionPayload<D extends IActionDomain, ID extends keyof D["actions"] & string, A extends TAction_Any_JsonObject<D, ID>>(actionJson: A): TNarrowActionJsonTypeToActionInstanceType<D, A, ID>;
13
+ }
@@ -0,0 +1,48 @@
1
+ import type { TActionPayload_Any_Instance } from "../ActionDefinition/Action/Payload/ActionPayload.types";
2
+ import { type TActionPayload_Any_JsonObject } from "../ActionDefinition/Action/Payload/ActionPayload.types";
3
+ import { RunningAction } from "../ActionDefinition/Action/RunningAction";
4
+ import type { IActionDomain } from "../ActionDefinition/Domain/ActionDomain.types";
5
+ import type { IRuntimeMeta, TActionRuntimeHandler } from "./ActionRuntime.types";
6
+ import { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
7
+ import { type IHandleActionOptions, type TActionHandler } from "./Handler/ActionHandler.types";
8
+ import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
9
+ export declare class ActionRuntime {
10
+ readonly clientSpecifier: ActionClientSpecifier;
11
+ readonly timeCreated: number;
12
+ readonly runtimeInfo: IRuntimeMeta;
13
+ private readonly actionRouter;
14
+ private readonly _pendingRunningActions;
15
+ private readonly _registeredExternalHandlers;
16
+ static getDefault(): ActionRuntime;
17
+ constructor(client: ActionClientSpecifier);
18
+ registerRunningAction(ra: RunningAction<any, any>): void;
19
+ resolveIncomingActionPayload(json: TActionPayload_Any_JsonObject<any, any>): void;
20
+ /**
21
+ * Handle an incoming action wire (e.g. from a transport layer), route it to
22
+ * the correct handler, and return the response. The most specific handler
23
+ * match is chosen (action-ID-specific beats domain-wildcard).
24
+ */
25
+ handleActionPayloadWire<D extends IActionDomain, ID extends keyof D["actions"] & string>(wire: TActionPayload_Any_JsonObject<D, ID>): Promise<RunningAction<D, ID>>;
26
+ handleActionPayloadWire(wire: unknown): Promise<RunningAction<any, any>>;
27
+ handleActionPayload<DOM extends IActionDomain, ID extends keyof DOM["actions"] & string>(action: TActionPayload_Any_Instance<DOM, ID>, options?: Omit<IHandleActionOptions, "targetLocalRuntime">): Promise<RunningAction<DOM, ID>>;
28
+ /**
29
+ * Return the first handler registered for the given action, or `undefined`
30
+ * if none has been registered (action-ID-specific beats domain-wildcard).
31
+ */
32
+ getHandlerForAction<ACT extends TActionPayload_Any_Instance<any, any>>(action: ACT, options?: Omit<IHandleActionOptions, "targetLocalRuntime">): TActionHandler | undefined;
33
+ getHandlerForActionOrThrow<ACT extends TActionPayload_Any_Instance<any, any>>(action: ACT, options?: Omit<IHandleActionOptions, "localRuntime">): TActionHandler;
34
+ /**
35
+ * Register one or more handlers. Each handler's own `actionRouter` defines
36
+ * which domains/actions it handles — those routing keys are mirrored into
37
+ * this runtime's router so the same action can be served by multiple handlers.
38
+ * Duplicate registrations (same handler cuid for the same key) are skipped.
39
+ */
40
+ addHandlers(handlers: TActionRuntimeHandler[]): this;
41
+ /**
42
+ * Find the best registered external handler that can reach `originClient` directly.
43
+ * Used to locate the return-path channel for dispatching results back to the action origin.
44
+ * Returns `undefined` if no handler matches (score > 0 required, i.e. at least id must match).
45
+ */
46
+ getReturnHandlerForOrigin(originClient: ActionClientSpecifier): ActionExternalClientHandler | undefined;
47
+ private _trySetupReturnDispatch;
48
+ }
@@ -0,0 +1,22 @@
1
+ import type { RuntimeName } from "std-env";
2
+ import type { ActionRuntime } from "./ActionRuntime";
3
+ import type { ActionClientSpecifier } from "./Client/ActionClientSpecifier";
4
+ import type { TActionHandler } from "./Handler/ActionHandler.types";
5
+ import type { ActionExternalClientHandler } from "./Handler/ExternalClient/ActionExternalClientHandler";
6
+ import type { ActionLocalHandler } from "./Handler/Local/ActionLocalHandler";
7
+ export interface IRuntimeMeta {
8
+ assumed: boolean;
9
+ runtimeName: RuntimeName;
10
+ }
11
+ export interface IRuntimeEnvironmentMeta {
12
+ client: ActionClientSpecifier;
13
+ runtimeInfo: IRuntimeMeta;
14
+ }
15
+ export interface IActionRuntimeManagerContext {
16
+ domain?: string;
17
+ }
18
+ export interface IActionHandlerAndRuntime {
19
+ handler: TActionHandler;
20
+ runtime: ActionRuntime;
21
+ }
22
+ export type TActionRuntimeHandler = ActionLocalHandler | ActionExternalClientHandler;
@@ -0,0 +1,19 @@
1
+ import type { TActionPayload_Any_Instance } from "../ActionDefinition/Action/Payload/ActionPayload.types";
2
+ import type { ActionRuntime } from "./ActionRuntime";
3
+ import type { IActionHandlerAndRuntime, IActionRuntimeManagerContext } from "./ActionRuntime.types";
4
+ import { type IActionClientSpecifier } from "./Client/ActionClientSpecifier";
5
+ import type { IHandleActionOptions } from "./Handler/ActionHandler.types";
6
+ export declare class ActionRuntimeManager {
7
+ private _runtimes;
8
+ private _preferredRuntimeClientId;
9
+ private _context;
10
+ constructor(context?: IActionRuntimeManagerContext);
11
+ registerRuntime(runtime: ActionRuntime): void;
12
+ getRuntimeAndHandlerForAction(action: TActionPayload_Any_Instance<any, any>, options?: IHandleActionOptions, throwOnIssue?: boolean): IActionHandlerAndRuntime | undefined;
13
+ getRuntimeAndHandlerForActionOrThrow(action: TActionPayload_Any_Instance<any, any>, options?: IHandleActionOptions): IActionHandlerAndRuntime;
14
+ setPreferredRuntime(runtime: ActionRuntime): void;
15
+ getPreferredRuntime(): ActionRuntime | undefined;
16
+ getBestRuntimeForSpecifier(clientSpecifier: IActionClientSpecifier): ActionRuntime | undefined;
17
+ getBestRuntime(clientSpecifier?: IActionClientSpecifier): ActionRuntime | undefined;
18
+ getBestRuntimeOrThrow(specifier?: IActionClientSpecifier): ActionRuntime;
19
+ }
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import type { IActionClientSpecifier, TClientSpecifierStringId } from "../ActionClientSpecifier";
2
+ export declare function clientSpecifierToStringIds(specifier: IActionClientSpecifier): TClientSpecifierStringId[];
@@ -0,0 +1,16 @@
1
+ import type { IActionRouteItemHandler } from "../../ActionDefinition/Action/Payload/ActionPayload.types";
2
+ import type { ActionPayload_Request } from "../../ActionDefinition/Action/Payload/ActionPayload_Request";
3
+ import type { RunningAction } from "../../ActionDefinition/Action/RunningAction";
4
+ import type { IActionDomain } from "../../ActionDefinition/Domain/ActionDomain.types";
5
+ import { ActionRouter } from "../Routing/ActionRouter";
6
+ import type { EActionHandlerType, IActionHandler_Base, IHandleActionOptions, TActionHandler_Json } from "./ActionHandler.types";
7
+ export declare abstract class ActionHandler<T extends EActionHandlerType> implements IActionHandler_Base<T> {
8
+ abstract readonly handlerType: T;
9
+ readonly cuid: string;
10
+ abstract readonly actionRouter: ActionRouter<any>;
11
+ constructor();
12
+ getActionRouter(): ActionRouter<any>;
13
+ abstract handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actions"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
14
+ abstract toJsonObject(): TActionHandler_Json;
15
+ abstract toHandlerRouteItem(...args: any[]): IActionRouteItemHandler;
16
+ }
@@ -0,0 +1,68 @@
1
+ import type { TActionPayload_Any_JsonObject } from "../../ActionDefinition/Action/Payload/ActionPayload.types";
2
+ import type { ActionPayload_Request } from "../../ActionDefinition/Action/Payload/ActionPayload_Request";
3
+ import type { RunningAction } from "../../ActionDefinition/Action/RunningAction";
4
+ import type { TRunningActionUpdateListener } from "../../ActionDefinition/Action/RunningAction.types";
5
+ import type { IActionDomain } from "../../ActionDefinition/Domain/ActionDomain.types";
6
+ import type { ActionRuntime } from "../ActionRuntime";
7
+ import type { ActionClientSpecifier, IActionClientSpecifier } from "../Client/ActionClientSpecifier";
8
+ import type { ActionRouter } from "../Routing/ActionRouter";
9
+ export declare enum EActionHandlerType {
10
+ external = "external",
11
+ local = "local"
12
+ }
13
+ export interface IActionHandler_Json<T extends EActionHandlerType> {
14
+ type: T;
15
+ }
16
+ export interface IActionHandler_ExternalClient_Json extends IActionHandler_Json<EActionHandlerType.external> {
17
+ client: IActionClientSpecifier;
18
+ }
19
+ export interface IActionHandler_Local_Json extends IActionHandler_Json<EActionHandlerType.local> {
20
+ }
21
+ export type TActionHandler_Json = IActionHandler_Local_Json | IActionHandler_ExternalClient_Json;
22
+ export interface IHandleActionOptions {
23
+ timeout?: number;
24
+ targetExternalClient?: ActionClientSpecifier;
25
+ targetLocalRuntime?: ActionRuntime;
26
+ }
27
+ export interface IExecuteActionOptions<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> extends IHandleActionOptions {
28
+ listeners?: TRunningActionUpdateListener<DOM, ID>[];
29
+ }
30
+ export type TAtLeastOne<T extends object> = {
31
+ [K in keyof T]-?: Required<Pick<T, K>> & Partial<Omit<T, K>>;
32
+ }[keyof T];
33
+ export interface IActionHandler_Base<T extends EActionHandlerType> {
34
+ cuid: string;
35
+ handlerType: T;
36
+ getActionRouter: () => ActionRouter<any>;
37
+ }
38
+ export interface IHandleActionPrimed_Input_Base<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actions"] & string = keyof DOM["actions"] & string> {
39
+ action: ActionPayload_Request<DOM, ID>;
40
+ }
41
+ /**
42
+ *
43
+ * LOCAL ACTION HANDLER
44
+ *
45
+ */
46
+ export interface IHandleActionOptions_Local extends IHandleActionOptions {
47
+ }
48
+ export interface IActionHandler_Local extends IActionHandler_Base<EActionHandlerType.local> {
49
+ handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actions"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_Local) => Promise<RunningAction<DOM, ID>>;
50
+ }
51
+ /**
52
+ *
53
+ * EXTERNAL CLIENT ACTION HANDLER
54
+ *
55
+ */
56
+ export interface IHandleActionOptions_External extends IHandleActionOptions {
57
+ }
58
+ export interface IActionHandler_ExternalClient extends IActionHandler_Base<EActionHandlerType.external> {
59
+ externalClient: ActionClientSpecifier;
60
+ handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actions"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_External) => Promise<RunningAction<DOM, ID>>;
61
+ _setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any>) => void): void;
62
+ }
63
+ /**
64
+ *
65
+ * COMBINED
66
+ *
67
+ */
68
+ export type TActionHandler = IActionHandler_Local | IActionHandler_ExternalClient;
@@ -0,0 +1,42 @@
1
+ import type { ActionCore } from "../../../ActionDefinition/Action/Core/ActionCore";
2
+ import type { IActionRouteItemHandler, TActionPayload_Any_Instance, TActionPayload_Any_JsonObject } from "../../../ActionDefinition/Action/Payload/ActionPayload.types";
3
+ import type { ActionPayload_Request } from "../../../ActionDefinition/Action/Payload/ActionPayload_Request";
4
+ import { RunningAction } from "../../../ActionDefinition/Action/RunningAction";
5
+ import type { ActionDomain } from "../../../ActionDefinition/Domain/ActionDomain";
6
+ import type { IActionDomain } from "../../../ActionDefinition/Domain/ActionDomain.types";
7
+ import { ActionRuntime } from "../../ActionRuntime";
8
+ import { ActionClientSpecifier } from "../../Client/ActionClientSpecifier";
9
+ import { ActionRouter } from "../../Routing/ActionRouter";
10
+ import { ActionHandler } from "../ActionHandler";
11
+ import { EActionHandlerType, type IActionHandler_ExternalClient, type IActionHandler_ExternalClient_Json, type IHandleActionOptions } from "../ActionHandler.types";
12
+ import type { IActionExternalClientRequestHandlerConfig } from "./ActionExternalClientHandler.types";
13
+ import type { Transport } from "./Transport/Transport";
14
+ export declare class ActionExternalClientHandler extends ActionHandler<EActionHandlerType.external> implements IActionHandler_ExternalClient {
15
+ readonly externalClient: ActionClientSpecifier;
16
+ readonly handlerType = EActionHandlerType.external;
17
+ readonly cuid: string;
18
+ private _defaultTimeout;
19
+ private _transportCache;
20
+ private transportManager;
21
+ private _incomingActionDataListeners;
22
+ readonly actionRouter: ActionRouter<true>;
23
+ constructor({ externalClientSpecifier, transports, defaultTimeout, }: IActionExternalClientRequestHandlerConfig);
24
+ forDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>): this;
25
+ forAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actions"] & string>(action: ActionCore<ACT_DOM, ID>): this;
26
+ forActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actions"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS): this;
27
+ _setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any, any>) => void): void;
28
+ handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actions"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
29
+ /**
30
+ * Dispatch a result or progress payload directly back to the external client via the best
31
+ * available bidirectional transport (WebSocket / Custom). Used for return-path routing when the
32
+ * local runtime recognises that it has a direct channel to the action's originClient.
33
+ *
34
+ * Returns `true` if the payload was sent, `false` if no suitable transport was available.
35
+ */
36
+ sendReturnPayload(payload: TActionPayload_Any_Instance<any, any>, config: {
37
+ targetLocalRuntime: ActionRuntime;
38
+ }): Promise<boolean>;
39
+ toJsonObject(): IActionHandler_ExternalClient_Json;
40
+ toHandlerRouteItem(transport: Transport): IActionRouteItemHandler;
41
+ }
42
+ export declare const createExternalClientHandler: (config: IActionExternalClientRequestHandlerConfig) => ActionExternalClientHandler;
@@ -0,0 +1,7 @@
1
+ import type { ActionClientSpecifier } from "../../Client/ActionClientSpecifier";
2
+ import type { TActionTransportDef } from "./Transport/Transport.combined.types";
3
+ export interface IActionExternalClientRequestHandlerConfig {
4
+ defaultTimeout?: number;
5
+ externalClientSpecifier: ActionClientSpecifier;
6
+ transports: TActionTransportDef[];
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { Transport } from "./Transport";
2
+ import { type IActionTransportReady, type ITransportRouteActionParams, type TTransportCache } from "./Transport.types";
3
+ export declare class ConnectionTransportManager {
4
+ private _cache;
5
+ private _transports;
6
+ constructor(_cache: TTransportCache);
7
+ addTransport(transport: Transport): void;
8
+ getReadyTransport(routeActionParams: ITransportRouteActionParams): Promise<IActionTransportReady>;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { Transport } from "../Transport";
2
+ import { ETransportType, type IActionTransportReadyData_Methods, type ITransportRouteActionParams } from "../Transport.types";
3
+ import type { IActionTransportDef_Custom, IActionTransportInitialized_Custom, IActionTransportReadyData_Custom, TActionTransportDef_Custom_NoType } from "./TransportCustom.types";
4
+ export declare class TransportCustom extends Transport<ETransportType.custom, ITransportRouteActionParams, IActionTransportReadyData_Custom, IActionTransportInitialized_Custom, IActionTransportDef_Custom> {
5
+ constructor(def: TActionTransportDef_Custom_NoType);
6
+ protected _finalizeTransportMethods(inputs: IActionTransportReadyData_Custom): IActionTransportReadyData_Methods;
7
+ }
@@ -0,0 +1,11 @@
1
+ import type { ETransportType, IActionTransportDef, IActionTransportInitialized, IActionTransportReadyData_Base, ITransportMethod_SendActionData_Input, ITransportRouteActionParams, TSendReturnDataMethod } from "../Transport.types";
2
+ export interface IActionTransportReadyData_Custom extends IActionTransportReadyData_Base {
3
+ sendActionData: (input: ITransportMethod_SendActionData_Input) => void;
4
+ sendReturnData?: TSendReturnDataMethod;
5
+ closeTransport: (input?: ITransportRouteActionParams) => void;
6
+ }
7
+ export interface IActionTransportInitialized_Custom extends IActionTransportInitialized<ITransportRouteActionParams, IActionTransportReadyData_Custom> {
8
+ }
9
+ export interface IActionTransportDef_Custom extends IActionTransportDef<ETransportType.custom, IActionTransportInitialized_Custom> {
10
+ }
11
+ export type TActionTransportDef_Custom_NoType = Omit<IActionTransportDef_Custom, "type">;
@@ -0,0 +1,8 @@
1
+ import { Transport } from "../Transport";
2
+ import { ETransportType, type IActionTransportReadyData_Methods, type ITransportDispatchAction, type ITransportRouteActionParams } from "../Transport.types";
3
+ import type { IActionTransportDef_Http, IActionTransportInitialized_Http, IActionTransportReadyData_Http, IActionTransportReadyParams_Http } from "./TransportHttp.types";
4
+ export declare class TransportHttp extends Transport<ETransportType.http, ITransportRouteActionParams, IActionTransportReadyData_Http, IActionTransportInitialized_Http, IActionTransportDef_Http> {
5
+ constructor(def: Omit<IActionTransportDef_Http, "type">);
6
+ _finalizeTransportMethods(methods: IActionTransportReadyData_Http): IActionTransportReadyData_Methods;
7
+ protected send(input: ITransportDispatchAction<IActionTransportReadyParams_Http>): Promise<void>;
8
+ }
@@ -0,0 +1,17 @@
1
+ import type { ETransportType, IActionTransportDef, IActionTransportInitialized, IActionTransportReadyData_Base, ITransportRouteActionParams } from "../Transport.types";
2
+ interface IHttpRequestParams {
3
+ url: string;
4
+ headers?: Record<string, string>;
5
+ body?: string;
6
+ }
7
+ export interface IActionTransportReadyParams_Http {
8
+ request: IHttpRequestParams;
9
+ }
10
+ export interface IActionTransportReadyData_Http extends IActionTransportReadyData_Base {
11
+ createRequest: (input: ITransportRouteActionParams) => IHttpRequestParams;
12
+ }
13
+ export interface IActionTransportInitialized_Http extends IActionTransportInitialized<ITransportRouteActionParams, IActionTransportReadyData_Http> {
14
+ }
15
+ export interface IActionTransportDef_Http extends IActionTransportDef<ETransportType.http, IActionTransportInitialized_Http> {
16
+ }
17
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { IActionTransportDef_Custom } from "./Custom/TransportCustom.types";
2
+ import type { IActionTransportDef_Http } from "./Http/TransportHttp.types";
3
+ import type { IActionTransportDef_Ws } from "./WebSocket/TransportWebSocket.types";
4
+ export type TActionTransportDef = IActionTransportDef_Ws | IActionTransportDef_Http | IActionTransportDef_Custom;
@@ -0,0 +1,13 @@
1
+ import { type ETransportType, type IActionTransportDef, type IActionTransportInitialized, type IActionTransportReadyData_Base, type IActionTransportReadyData_Methods, type ITransportRouteActionParams, type TTransportStatusInfo } from "./Transport.types";
2
+ export declare abstract class Transport<T extends ETransportType = ETransportType, RP extends ITransportRouteActionParams = ITransportRouteActionParams, RD extends IActionTransportReadyData_Base = IActionTransportReadyData_Base, I extends IActionTransportInitialized<RP, RD> = IActionTransportInitialized<RP, RD>, DEF extends IActionTransportDef<T, I> = IActionTransportDef<T, I>> {
3
+ readonly def: DEF;
4
+ readonly transOrd: number;
5
+ readonly type: T;
6
+ readonly initialized: I;
7
+ constructor(def: DEF);
8
+ protected abstract _finalizeTransportMethods(inputs: RD): IActionTransportReadyData_Methods;
9
+ protected _getCacheKey(input: RP): string | null;
10
+ getCacheKey(input: RP): string | null;
11
+ getTransport(input: RP): TTransportStatusInfo<IActionTransportReadyData_Methods>;
12
+ protected _processTransportStatus(input: RP): TTransportStatusInfo<IActionTransportReadyData_Methods>;
13
+ }
@@ -0,0 +1,106 @@
1
+ import type { NiceError } from "@nice-code/error";
2
+ import type { IActionPayload_Request_JsonObject, IActionPayload_Result_JsonObject, TActionPayload_Any_Instance, TActionPayload_Any_JsonObject } from "../../../../ActionDefinition/Action/Payload/ActionPayload.types";
3
+ import type { ActionPayload_Request } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Request";
4
+ import type { ActionPayload_Result } from "../../../../ActionDefinition/Action/Payload/ActionPayload_Result";
5
+ import type { RunningAction } from "../../../../ActionDefinition/Action/RunningAction";
6
+ import type { ActionClientSpecifier } from "../../../Client/ActionClientSpecifier";
7
+ import type { Transport } from "./Transport";
8
+ export declare enum ETransportType {
9
+ ws = "ws",
10
+ http = "http",
11
+ custom = "custom"
12
+ }
13
+ export interface IUpdateActionRunConfig_Output {
14
+ timeout?: number;
15
+ }
16
+ export type TUpdateActionRunConfig = (input: ITransportRouteActionParams & {
17
+ timeout: number;
18
+ }) => IUpdateActionRunConfig_Output;
19
+ export interface IActionTransportReadyData_Base {
20
+ updateRunConfig?: TUpdateActionRunConfig;
21
+ }
22
+ /**
23
+ *
24
+ * TRANSPORT READINESS RESPONSE
25
+ *
26
+ */
27
+ export declare enum ETransportStatus {
28
+ uninitialized = "uninitialized",
29
+ unsupported = "unsupported",
30
+ initializing = "initializing",
31
+ ready = "ready",
32
+ failed = "failed"
33
+ }
34
+ export interface ITransportStatusInfo_Base<S extends ETransportStatus> {
35
+ status: S;
36
+ }
37
+ export interface ITransportStatusInfo_Failed extends ITransportStatusInfo_Base<ETransportStatus.failed> {
38
+ error: NiceError;
39
+ timeFailed: number;
40
+ }
41
+ export interface ITransportStatusInfo_Unsupported extends ITransportStatusInfo_Base<ETransportStatus.unsupported> {
42
+ }
43
+ export interface ITransportStatusInfo_Ready<READY extends IActionTransportReadyData_Base> extends ITransportStatusInfo_Base<ETransportStatus.ready> {
44
+ readyData: READY;
45
+ }
46
+ export type TTransportInitializationFinishedInfo<READY extends IActionTransportReadyData_Base> = ITransportStatusInfo_Ready<READY> | ITransportStatusInfo_Failed | ITransportStatusInfo_Unsupported;
47
+ export interface ITransportStatusInfo_Initializing<READY extends IActionTransportReadyData_Base> extends ITransportStatusInfo_Base<ETransportStatus.initializing> {
48
+ timeStarted: number;
49
+ initializationPromise: Promise<TTransportInitializationFinishedInfo<READY>>;
50
+ }
51
+ export type TTransportStatusInfo<READY extends IActionTransportReadyData_Base> = ITransportStatusInfo_Base<ETransportStatus.uninitialized> | ITransportStatusInfo_Unsupported | ITransportStatusInfo_Initializing<READY> | ITransportStatusInfo_Ready<READY> | ITransportStatusInfo_Failed;
52
+ export type TTransportStatusInfo_GetTransport_Output<READY extends IActionTransportReadyData_Base> = ITransportStatusInfo_Base<ETransportStatus.uninitialized> | ITransportStatusInfo_Unsupported | Omit<ITransportStatusInfo_Initializing<READY>, "timeStarted"> | ITransportStatusInfo_Ready<READY> | Omit<ITransportStatusInfo_Failed, "timeFailed">;
53
+ /**
54
+ *
55
+ * TRANSPORT ROUTING
56
+ *
57
+ */
58
+ export interface ITransportRouteClientParams {
59
+ localClient: ActionClientSpecifier;
60
+ externalClient: ActionClientSpecifier;
61
+ }
62
+ export interface ITransportRouteActionParams extends ITransportRouteClientParams {
63
+ action: TActionPayload_Any_Instance<any, any>;
64
+ }
65
+ export interface ITransportMethod_SendActionData_Input extends ITransportRouteActionParams {
66
+ runningAction: RunningAction<any, any>;
67
+ timeout: number;
68
+ }
69
+ export interface ITransportDispatchAction<P> extends ITransportMethod_SendActionData_Input {
70
+ params: P;
71
+ }
72
+ export type TSendActionDataMethod = (input: ITransportMethod_SendActionData_Input) => void;
73
+ export type TSendReturnDataMethod = (payload: TActionPayload_Any_Instance<any, any>) => void;
74
+ export interface IActionTransportReadyData_Methods extends IActionTransportReadyData_Base {
75
+ sendActionData: TSendActionDataMethod;
76
+ /**
77
+ * Optional — implement on bidirectional transports (WebSocket, Custom) to enable return-path
78
+ * routing. When present, the runtime uses this to dispatch results and progress payloads directly
79
+ * back to `originClient` without going through the original request transport.
80
+ */
81
+ sendReturnData?: TSendReturnDataMethod;
82
+ addOnDisconnectListener?: (callback: () => void) => void;
83
+ }
84
+ export interface IActionTransportReady {
85
+ methods: IActionTransportReadyData_Methods;
86
+ transport: Transport;
87
+ }
88
+ export type TTransportCache = Map<string, IActionTransportReady | Promise<IActionTransportReady>>;
89
+ export type TOnResolveIncomingRequest = (request: ActionPayload_Request<any>) => void;
90
+ export type TOnResolveIncomingRequestJson = (request: IActionPayload_Request_JsonObject<any>) => void;
91
+ export type TOnResolveIncomingResponse = (response: ActionPayload_Result<any>) => void;
92
+ export type TOnResolveIncomingResponseJson = (response: IActionPayload_Result_JsonObject<any>) => void;
93
+ export type TOnResolveAnyIncomingActionData = (actionData: ActionPayload_Request<any> | ActionPayload_Result<any>) => void;
94
+ export type TOnResolveAnyIncomingActionData_Json = (actionData: TActionPayload_Any_JsonObject<any>) => void;
95
+ export interface IActionTransportResolvers {
96
+ onIncomingActionDataJson: TOnResolveAnyIncomingActionData_Json;
97
+ }
98
+ export type TGetTransportFn<IN extends ITransportRouteActionParams, READY extends IActionTransportReadyData_Base> = (input: IN) => TTransportStatusInfo_GetTransport_Output<READY>;
99
+ export interface IActionTransportInitialized<IN extends ITransportRouteActionParams, READY extends IActionTransportReadyData_Base> {
100
+ getTransportCacheKey?: (input: IN) => string[];
101
+ getTransport: TGetTransportFn<IN, READY>;
102
+ }
103
+ export interface IActionTransportDef<TYPE extends ETransportType, INIT extends IActionTransportInitialized<any, any>> {
104
+ type: TYPE;
105
+ initialize: () => INIT;
106
+ }
@@ -0,0 +1,13 @@
1
+ import { Transport } from "../Transport";
2
+ import { ETransportType, type IActionTransportReadyData_Methods, type IActionTransportResolvers, type ITransportRouteActionParams, type TTransportStatusInfo } from "../Transport.types";
3
+ import type { IActionTransportDef_Ws, IActionTransportInitialized_Ws, IActionTransportReadyData_Ws } from "./TransportWebSocket.types";
4
+ export declare class TransportWebSocket extends Transport<ETransportType.ws, ITransportRouteActionParams, IActionTransportReadyData_Ws, IActionTransportInitialized_Ws, IActionTransportDef_Ws> {
5
+ private resolvers;
6
+ private _abortSet;
7
+ constructor(def: Omit<IActionTransportDef_Ws, "type">, resolvers?: IActionTransportResolvers);
8
+ protected _getCacheKey(_input: ITransportRouteActionParams): string;
9
+ protected _processTransportStatus(input: ITransportRouteActionParams): TTransportStatusInfo<IActionTransportReadyData_Methods>;
10
+ _finalizeTransportMethods(wsData: IActionTransportReadyData_Ws): IActionTransportReadyData_Methods;
11
+ private _parseActionMessage;
12
+ private _abortAll;
13
+ }