@nice-code/action 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ActionDevtoolsCore-B4s6aGvI.d.ts +79 -0
- package/build/ActionDevtoolsCore-BLeY_N-3.js +159 -0
- package/build/ActionDevtoolsCore-BLeY_N-3.js.map +1 -0
- package/build/ActionDevtoolsCore-Pg7ERO3L.d.ts +79 -0
- package/build/ActionDevtoolsCore-yfJ9tkvl.js +154 -0
- package/build/ActionDevtoolsCore-yfJ9tkvl.js.map +1 -0
- package/build/ActionPayload.types-BN-rXFBK.d.ts +2328 -0
- package/build/ActionPayload.types-D28ELKXC.d.ts +2328 -0
- package/build/RunningAction.types-C176rqHG.js +22 -0
- package/build/RunningAction.types-C176rqHG.js.map +1 -0
- package/build/RunningAction.types-DjCX1xp5.js +39 -0
- package/build/RunningAction.types-DjCX1xp5.js.map +1 -0
- package/build/devtools/browser/index.d.ts +17 -0
- package/build/devtools/browser/index.js +3775 -5814
- package/build/devtools/browser/index.js.map +1 -0
- package/build/devtools/server/index.d.ts +35 -0
- package/build/devtools/server/index.js +97 -255
- package/build/devtools/server/index.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +3877 -3674
- package/build/index.js.map +1 -0
- package/build/react-query/index.d.ts +17 -0
- package/build/react-query/index.js +60 -60
- package/build/react-query/index.js.map +1 -0
- package/package.json +34 -29
- package/build/types/ActionDefinition/Action/Action.combined.types.d.ts +0 -37
- package/build/types/ActionDefinition/Action/ActionBase.d.ts +0 -14
- package/build/types/ActionDefinition/Action/ActionBase.types.d.ts +0 -24
- package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +0 -25
- package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +0 -35
- package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +0 -19
- package/build/types/ActionDefinition/Action/Core/ActionCore.types.d.ts +0 -10
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.d.ts +0 -14
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.types.d.ts +0 -110
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Progress.d.ts +0 -15
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Request.d.ts +0 -26
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Result.d.ts +0 -19
- package/build/types/ActionDefinition/Action/RunningAction.d.ts +0 -36
- package/build/types/ActionDefinition/Action/RunningAction.types.d.ts +0 -73
- package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +0 -42
- package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +0 -43
- package/build/types/ActionDefinition/Domain/ActionDomainBase.d.ts +0 -14
- package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +0 -24
- package/build/types/ActionDefinition/Domain/helpers/createRootActionDomain.d.ts +0 -5
- package/build/types/ActionDefinition/Schema/ActionSchema.d.ts +0 -68
- package/build/types/ActionDefinition/Schema/ActionSchema.types.d.ts +0 -28
- package/build/types/ActionRuntime/ActionDomainManager.d.ts +0 -13
- package/build/types/ActionRuntime/ActionRuntime.d.ts +0 -56
- package/build/types/ActionRuntime/ActionRuntime.types.d.ts +0 -22
- package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +0 -20
- package/build/types/ActionRuntime/Handler/ActionHandler.d.ts +0 -16
- package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +0 -65
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +0 -45
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts +0 -7
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/ConnectionTransportManager.d.ts +0 -16
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomConnection.d.ts +0 -7
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomTransport.d.ts +0 -43
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.types.d.ts +0 -11
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpConnection.d.ts +0 -8
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpTransport.d.ts +0 -26
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.types.d.ts +0 -16
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.d.ts +0 -27
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts +0 -125
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/TransportConnection.d.ts +0 -27
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.types.d.ts +0 -41
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketConnection.d.ts +0 -33
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketTransport.d.ts +0 -60
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/actionFrameCrypto.d.ts +0 -31
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/actionWireCodec.d.ts +0 -41
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/actionWsHandshake.d.ts +0 -187
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/createBinaryWsAdapter.d.ts +0 -20
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/createBinaryWsSessionFactory.d.ts +0 -31
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/secureWsChannel.d.ts +0 -63
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/ws_util.d.ts +0 -11
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport.d.ts +0 -36
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport_ws.d.ts +0 -18
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/addTransportStatusMetadata.d.ts +0 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/Transport/helpers/createUnsetTransportResolvers.d.ts +0 -2
- package/build/types/ActionRuntime/Handler/ExternalClient/err_nice_external_client.d.ts +0 -5
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.d.ts +0 -55
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.types.d.ts +0 -7
- package/build/types/ActionRuntime/Handler/Server/ActionServerHandler.d.ts +0 -197
- package/build/types/ActionRuntime/Handler/Server/createSecureActionServer.d.ts +0 -71
- package/build/types/ActionRuntime/HandlerCallStack.d.ts +0 -3
- package/build/types/ActionRuntime/Routing/ActionRouter.d.ts +0 -55
- package/build/types/ActionRuntime/Routing/ActionRouter.types.d.ts +0 -20
- package/build/types/ActionRuntime/RuntimeCoordinate.d.ts +0 -58
- package/build/types/ActionRuntime/test/helpers/new_action_test_data.d.ts +0 -207
- package/build/types/ActionRuntime/utils/runtimeCoordinateToStringIds.d.ts +0 -2
- package/build/types/devtools/browser/NiceActionDevtools.d.ts +0 -14
- package/build/types/devtools/browser/components/ActionErrorDisplay.d.ts +0 -5
- package/build/types/devtools/browser/components/CallStackSection.d.ts +0 -8
- package/build/types/devtools/browser/components/ChildDispatchChips.d.ts +0 -6
- package/build/types/devtools/browser/components/Chip.d.ts +0 -22
- package/build/types/devtools/browser/components/DetailSection.d.ts +0 -5
- package/build/types/devtools/browser/components/DomainChip.d.ts +0 -8
- package/build/types/devtools/browser/components/HandlerChips.d.ts +0 -21
- package/build/types/devtools/browser/components/Icon.d.ts +0 -16
- package/build/types/devtools/browser/components/MetaSection.d.ts +0 -4
- package/build/types/devtools/browser/components/NiceErrorDisplay.d.ts +0 -19
- package/build/types/devtools/browser/components/OriginChip.d.ts +0 -15
- package/build/types/devtools/browser/components/PanelChrome.d.ts +0 -41
- package/build/types/devtools/browser/components/RoutingSection.d.ts +0 -5
- package/build/types/devtools/browser/components/RunningTimer.d.ts +0 -7
- package/build/types/devtools/browser/components/SectionLabel.d.ts +0 -4
- package/build/types/devtools/browser/components/StackTraceSection.d.ts +0 -9
- package/build/types/devtools/browser/components/Tooltip.d.ts +0 -24
- package/build/types/devtools/browser/components/action_detail/ActionDetailPanel.d.ts +0 -7
- package/build/types/devtools/browser/components/action_list/ActionEntryRow.d.ts +0 -14
- package/build/types/devtools/browser/components/action_list/ActionInputAndOutputChip.d.ts +0 -11
- package/build/types/devtools/browser/components/action_list/ActionList.d.ts +0 -10
- package/build/types/devtools/browser/components/action_list/IoTooltipContent.d.ts +0 -6
- package/build/types/devtools/browser/components/action_list/action_list.types.d.ts +0 -4
- package/build/types/devtools/browser/components/sourceMapResolver.d.ts +0 -6
- package/build/types/devtools/browser/components/utils.d.ts +0 -22
- package/build/types/devtools/browser/devtools_dock.d.ts +0 -54
- package/build/types/devtools/browser/devtools_storage.d.ts +0 -6
- package/build/types/devtools/browser/index.d.ts +0 -3
- package/build/types/devtools/browser/ui_util/size.d.ts +0 -6
- package/build/types/devtools/core/ActionDevtools.types.d.ts +0 -55
- package/build/types/devtools/core/ActionDevtoolsCore.d.ts +0 -14
- package/build/types/devtools/core/devtools_colors.d.ts +0 -63
- package/build/types/devtools/server/NiceActionServerDevtools.d.ts +0 -30
- package/build/types/devtools/server/index.d.ts +0 -3
- package/build/types/errors/err_nice_action.d.ts +0 -96
- package/build/types/index.d.ts +0 -41
- package/build/types/nice_action.static.d.ts +0 -3
- package/build/types/react-query/hooks/useActionMutation.d.ts +0 -10
- package/build/types/react-query/hooks/useActionQuery.d.ts +0 -17
- package/build/types/react-query/index.d.ts +0 -2
- package/build/types/utils/assertIsActionJson.d.ts +0 -2
- package/build/types/utils/decodeActionFrame.d.ts +0 -17
- package/build/types/utils/getAssumedRuntimeEnvironment.d.ts +0 -2
- package/build/types/utils/hashPayloadData.d.ts +0 -5
- package/build/types/utils/isActionPayload_Any_JsonObject.d.ts +0 -2
- package/build/types/utils/isActionPayload_Progress_JsonObject.d.ts +0 -2
- package/build/types/utils/isActionPayload_Request_JsonObject.d.ts +0 -2
- package/build/types/utils/isActionPayload_Result_JsonObject.d.ts +0 -2
- package/build/types/utils/isAction_Any_Instance.d.ts +0 -3
- package/build/types/utils/isAction_Any_JsonObject.d.ts +0 -2
- package/build/types/utils/isAction_Base_JsonObject.d.ts +0 -2
- package/build/types/utils/isAction_Context_JsonObject.d.ts +0 -2
- package/build/types/utils/isAction_Core_JsonObject.d.ts +0 -2
- package/build/types/utils/typescript/MaybePromise.d.ts +0 -1
- package/build/types/utils/wait.utils.d.ts +0 -13
|
@@ -0,0 +1,2328 @@
|
|
|
1
|
+
import { INiceErrorDomainProps, InferNiceError, NiceError, NiceErrorDomain, err_cast_not_nice } from "@nice-code/error";
|
|
2
|
+
import { RuntimeName } from "std-env";
|
|
3
|
+
import { ClientCryptoKeyLink, StorageAdapter, TSerializedCryptoKeyData_Ed25519_Raw, TSerializedCryptoKeyData_X25519_Raw, TTypeAndId } from "@nice-code/util";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
|
|
7
|
+
//#region src/ActionDefinition/Schema/ActionSchema.types.d.ts
|
|
8
|
+
type TTransportedValue<RAW_VAL, SERDE_VAL> = [RAW_VAL] | [RAW_VAL, SERDE_VAL];
|
|
9
|
+
type TActionSerializationDefinition<RAW_VAL = any, SERDE_VAL = any> = {
|
|
10
|
+
serialize: (value: RAW_VAL) => SERDE_VAL;
|
|
11
|
+
deserialize: (value: SERDE_VAL) => RAW_VAL;
|
|
12
|
+
};
|
|
13
|
+
type TActionSchemaOptions<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN = any> = {
|
|
14
|
+
schema: VS;
|
|
15
|
+
serialization?: TActionSerializationDefinition<StandardSchemaV1.InferInput<VS>, SERDE_IN>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* One error declaration on an action schema.
|
|
19
|
+
* `IDS` is the subset of error IDs that may be thrown. When the full
|
|
20
|
+
* `keyof schema` union is used it means any ID from the domain can be thrown.
|
|
21
|
+
*
|
|
22
|
+
* Build via `action().throws(domain)` or `action().throws(domain, ids)`.
|
|
23
|
+
*/
|
|
24
|
+
interface IActionErrorDeclaration<ERR_DEF extends INiceErrorDomainProps = INiceErrorDomainProps, IDS extends keyof ERR_DEF["schema"] & string = keyof ERR_DEF["schema"] & string> {
|
|
25
|
+
readonly _domain: NiceErrorDomain<ERR_DEF>;
|
|
26
|
+
/** The specific IDs constrained for this declaration, or `undefined` meaning the full domain. */
|
|
27
|
+
readonly _ids: ReadonlyArray<IDS & string> | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** @internal Maps a single INiceActionErrorDeclaration to its NiceError type. */
|
|
30
|
+
type TInferErrorFromDeclaration<D> = D extends IActionErrorDeclaration<infer DEF, infer IDS> ? NiceError<DEF, IDS> : never;
|
|
31
|
+
/**
|
|
32
|
+
* Union of all `NiceError` types that can be thrown from a tuple of error declarations.
|
|
33
|
+
* Distributes over each declaration and unions the results.
|
|
34
|
+
*/
|
|
35
|
+
type TInferDeclaredErrors<DECLS extends readonly IActionErrorDeclaration[]> = TInferErrorFromDeclaration<DECLS[number]>;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/ActionDefinition/Schema/ActionSchema.d.ts
|
|
38
|
+
declare class ActionSchema<INPUT extends TTransportedValue<any, any> = never, OUTPUT extends TTransportedValue<any, any> = never, ERRORS extends readonly IActionErrorDeclaration<any, any>[] = readonly []> {
|
|
39
|
+
private _errorDeclarations;
|
|
40
|
+
private inputOptions;
|
|
41
|
+
private outputOptions;
|
|
42
|
+
get inputSchema(): StandardSchemaV1 | undefined;
|
|
43
|
+
get outputSchema(): StandardSchemaV1 | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Declare the input schema (JSON-native or with explicit SERDE type param).
|
|
46
|
+
* For non-JSON-native inputs, prefer the 3-argument form below to avoid
|
|
47
|
+
* needing explicit type parameters.
|
|
48
|
+
*/
|
|
49
|
+
input<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_IN = any>(options: TActionSchemaOptions<VS, SERDE_IN>): ActionSchema<TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_IN>, OUTPUT, ERRORS>;
|
|
50
|
+
/**
|
|
51
|
+
* Declare the output schema (JSON-native or with explicit SERDE type param).
|
|
52
|
+
* For non-JSON-native outputs, prefer the 3-argument form below to avoid
|
|
53
|
+
* needing explicit type parameters.
|
|
54
|
+
*/
|
|
55
|
+
output<VS extends StandardSchemaV1 = StandardSchemaV1, SERDE_OUT = any>(options: TActionSchemaOptions<VS, SERDE_OUT>): ActionSchema<INPUT, TTransportedValue<StandardSchemaV1.InferInput<VS>, SERDE_OUT>, ERRORS>;
|
|
56
|
+
/**
|
|
57
|
+
* Declare that this action may throw any error from `domain`.
|
|
58
|
+
* `TInferActionError` will include `NiceError<DEF, keyof schema>` in its union.
|
|
59
|
+
*/
|
|
60
|
+
throws<ERR_DEF extends INiceErrorDomainProps>(domain: NiceErrorDomain<ERR_DEF>): ActionSchema<INPUT, OUTPUT, readonly [...ERRORS, IActionErrorDeclaration<ERR_DEF, keyof ERR_DEF["schema"] & string>]>;
|
|
61
|
+
/**
|
|
62
|
+
* Declare that this action may throw only the listed `ids` from `domain`.
|
|
63
|
+
* `TInferActionError` will include `NiceError<DEF, IDS[number]>` narrowed to those IDs.
|
|
64
|
+
*/
|
|
65
|
+
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>]>;
|
|
66
|
+
/**
|
|
67
|
+
* Serialize raw input to a JSON-serializable form.
|
|
68
|
+
* Uses the schema's serialization.serialize if defined; otherwise the input
|
|
69
|
+
* is already JSON-native and is returned as-is.
|
|
70
|
+
*/
|
|
71
|
+
serializeInput(rawInput: INPUT[0]): INPUT[1];
|
|
72
|
+
/**
|
|
73
|
+
* Deserialize a JSON value back into the raw input type.
|
|
74
|
+
* Uses serialization.deserialize if defined; otherwise the value is cast
|
|
75
|
+
* directly (it's already in the correct shape).
|
|
76
|
+
*/
|
|
77
|
+
deserializeInput(serialized: INPUT[1]): INPUT[0];
|
|
78
|
+
/**
|
|
79
|
+
* Validate raw input against the schema defined via `.input({ schema })`.
|
|
80
|
+
* Throws `action_input_validation_failed` if validation fails.
|
|
81
|
+
* Returns the validated (and possibly coerced) value on success.
|
|
82
|
+
* If no input schema was declared, the value is passed through as-is.
|
|
83
|
+
*/
|
|
84
|
+
validateInput(value: unknown, meta: {
|
|
85
|
+
domain: string;
|
|
86
|
+
actionId: string;
|
|
87
|
+
}): INPUT[0];
|
|
88
|
+
validateOutput(value: unknown, meta: {
|
|
89
|
+
domain: string;
|
|
90
|
+
actionId: string;
|
|
91
|
+
}): OUTPUT[0];
|
|
92
|
+
/**
|
|
93
|
+
* Serialize raw output to a JSON-serializable form.
|
|
94
|
+
*/
|
|
95
|
+
serializeOutput(rawOutput: OUTPUT[0]): OUTPUT[1];
|
|
96
|
+
/**
|
|
97
|
+
* Deserialize a JSON value back into the raw output type.
|
|
98
|
+
*/
|
|
99
|
+
deserializeOutput(serialized: OUTPUT[1]): OUTPUT[0];
|
|
100
|
+
}
|
|
101
|
+
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;
|
|
102
|
+
declare const actionSchema: () => ActionSchema;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/ActionDefinition/Domain/ActionDomain.types.d.ts
|
|
105
|
+
type TPossibleDomainId = string;
|
|
106
|
+
type TPossibleDomainIdList = [...TPossibleDomainId[], TPossibleDomainId];
|
|
107
|
+
type TActionDomainSchema = Record<string, ActionSchema<TTransportedValue<any, any>, TTransportedValue<any, any>, readonly IActionErrorDeclaration<any, any>[]>>;
|
|
108
|
+
/**
|
|
109
|
+
* Data shape for a domain — used for construction and as the type-level schema carrier.
|
|
110
|
+
* Does NOT include class methods.
|
|
111
|
+
*/
|
|
112
|
+
interface IActionDomain<IDS extends TPossibleDomainIdList = TPossibleDomainIdList, SCH extends TActionDomainSchema = TActionDomainSchema> {
|
|
113
|
+
domain: IDS[0] & string;
|
|
114
|
+
allDomains: IDS;
|
|
115
|
+
actionSchema: SCH;
|
|
116
|
+
}
|
|
117
|
+
interface IActionRootDomain<ID extends TPossibleDomainId = TPossibleDomainId> extends IActionDomain<[ID], {}> {
|
|
118
|
+
domain: ID;
|
|
119
|
+
allDomains: [ID];
|
|
120
|
+
actionSchema: {};
|
|
121
|
+
}
|
|
122
|
+
interface IActionDomainChildOptions<ERR_DOMAIN extends string = string, SCHEMA extends TActionDomainSchema = TActionDomainSchema> {
|
|
123
|
+
domain: ERR_DOMAIN;
|
|
124
|
+
actions: SCHEMA;
|
|
125
|
+
}
|
|
126
|
+
type TActionDomainChildDef<PARENT_DEF extends IActionDomain, SUB extends IActionDomainChildOptions> = {
|
|
127
|
+
domain: SUB["domain"];
|
|
128
|
+
allDomains: [...PARENT_DEF["allDomains"], SUB["domain"]];
|
|
129
|
+
actionSchema: SUB["actions"];
|
|
130
|
+
};
|
|
131
|
+
type TDomainActionId<DOM extends IActionDomain> = keyof DOM["actionSchema"] & string;
|
|
132
|
+
type TInferInputFromSchema<SCH extends ActionSchema<any, any, any>> = SCH extends ActionSchema<infer IN, any, any> ? {
|
|
133
|
+
Input: IN[0];
|
|
134
|
+
SerdeInput: IN[1];
|
|
135
|
+
} : {
|
|
136
|
+
Input: never;
|
|
137
|
+
SerdeInput: never;
|
|
138
|
+
};
|
|
139
|
+
type TInferOutputFromSchema<SCH extends ActionSchema<any, any, any>> = SCH extends ActionSchema<any, infer OUT, any> ? {
|
|
140
|
+
Output: OUT[0];
|
|
141
|
+
SerdeOutput: OUT[1];
|
|
142
|
+
} : never;
|
|
143
|
+
type TWrappableDomainActionHandler<DOM extends IActionDomain> = { [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"]> };
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/ActionRuntime/RuntimeCoordinate.d.ts
|
|
146
|
+
interface IRuntimeCoordinateSpecifics {
|
|
147
|
+
/**
|
|
148
|
+
* A unique and persistent client ID (should stay the same between runtime instance reloads)
|
|
149
|
+
*/
|
|
150
|
+
perId?: string;
|
|
151
|
+
/**
|
|
152
|
+
* A unique instance (or "memory-only") ID (unique for each instance of an action runtime, which should generally
|
|
153
|
+
* not persist between reloads, depending on the architecture)
|
|
154
|
+
*/
|
|
155
|
+
insId?: string;
|
|
156
|
+
}
|
|
157
|
+
interface IRuntimeCoordinate extends IRuntimeCoordinateSpecifics {
|
|
158
|
+
/**
|
|
159
|
+
* A static runtime environment identifier (e.g. "web_app_v1", "backend_analytics")
|
|
160
|
+
*/
|
|
161
|
+
envId: string;
|
|
162
|
+
}
|
|
163
|
+
type TRuntimeCoordinateEnvId = `envId[${string}]`;
|
|
164
|
+
type TRuntimeCoordinateStringId = `${TRuntimeCoordinateEnvId}perId[${string | "_"}]:insId[${string | "_"}]`;
|
|
165
|
+
interface IRuntimeFullCoordinates extends Required<IRuntimeCoordinate> {}
|
|
166
|
+
declare class RuntimeCoordinate implements IRuntimeCoordinate {
|
|
167
|
+
readonly envId: string;
|
|
168
|
+
readonly perId?: string;
|
|
169
|
+
readonly insId?: string;
|
|
170
|
+
static get unknown(): RuntimeCoordinate;
|
|
171
|
+
static env(envId: string): RuntimeCoordinate;
|
|
172
|
+
withPersistentId(perId: string): RuntimeCoordinate;
|
|
173
|
+
constructor({
|
|
174
|
+
envId,
|
|
175
|
+
perId,
|
|
176
|
+
insId
|
|
177
|
+
}: IRuntimeCoordinate);
|
|
178
|
+
specify(specifics: IRuntimeCoordinateSpecifics): RuntimeCoordinate;
|
|
179
|
+
specifyIfUnset(specifics: IRuntimeCoordinateSpecifics): RuntimeCoordinate;
|
|
180
|
+
toJsonObject(): IRuntimeCoordinate;
|
|
181
|
+
isExactlySame(other: IRuntimeCoordinate): boolean;
|
|
182
|
+
isSameFor(other: IRuntimeCoordinate): {
|
|
183
|
+
id: boolean;
|
|
184
|
+
perId: boolean;
|
|
185
|
+
insId: boolean;
|
|
186
|
+
};
|
|
187
|
+
similarityLevel(other: IRuntimeCoordinate): number;
|
|
188
|
+
get stringId(): TRuntimeCoordinateStringId;
|
|
189
|
+
/**
|
|
190
|
+
* Takes the "Runtime Coordinate" and generates a list of full coordinate IDs representing the runtime
|
|
191
|
+
* with decreasing levels of specificity.
|
|
192
|
+
*
|
|
193
|
+
* The first full coordinate ID is the most specific (including instance ID), while the last ID is
|
|
194
|
+
* the least specific (only environment ID).
|
|
195
|
+
*
|
|
196
|
+
* Example output for a RuntimeCoordinate with envId "web_app", perId "user123", and insId "instance456":
|
|
197
|
+
* [
|
|
198
|
+
* "envId[web_app]perId[user123]:insId[instance456]",
|
|
199
|
+
* "envId[web_app]perId[user123]:insId[_]",
|
|
200
|
+
* "envId[web_app]perId[_]:insId[_]"
|
|
201
|
+
* ]
|
|
202
|
+
*
|
|
203
|
+
* @returns a list of "full" runtime coordinate IDs with decreasing accuracy for targeting a runtime.
|
|
204
|
+
*/
|
|
205
|
+
toStringIds(): TRuntimeCoordinateStringId[];
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/ActionDefinition/Action/ActionBase.types.d.ts
|
|
209
|
+
declare enum EActionForm {
|
|
210
|
+
core = "core",
|
|
211
|
+
context = "context",
|
|
212
|
+
data = "data"
|
|
213
|
+
}
|
|
214
|
+
interface INiceActionIdAndDomain<DOM extends IActionDomain = IActionDomain> {
|
|
215
|
+
domain: DOM["domain"];
|
|
216
|
+
id: keyof DOM["actionSchema"] & string;
|
|
217
|
+
}
|
|
218
|
+
interface IActionBase<FORM extends EActionForm, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends INiceActionIdAndDomain<DOM> {
|
|
219
|
+
id: ID;
|
|
220
|
+
form: FORM;
|
|
221
|
+
_domain: ActionDomain<DOM>;
|
|
222
|
+
allDomains: DOM["allDomains"];
|
|
223
|
+
schema: DOM["actionSchema"][ID];
|
|
224
|
+
}
|
|
225
|
+
interface IActionBase_JsonObject<FORM extends EActionForm = EActionForm, DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> {
|
|
226
|
+
form: FORM;
|
|
227
|
+
domain: DOM["domain"];
|
|
228
|
+
allDomains: DOM["allDomains"];
|
|
229
|
+
id: ID;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/ActionDefinition/Action/ActionBase.d.ts
|
|
233
|
+
declare abstract class ActionBase<FORM extends EActionForm, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> implements IActionBase<FORM, DOM, ID> {
|
|
234
|
+
readonly form: FORM;
|
|
235
|
+
readonly _domain: ActionDomain<DOM>;
|
|
236
|
+
readonly id: ID;
|
|
237
|
+
readonly domain: DOM["domain"];
|
|
238
|
+
readonly allDomains: DOM["allDomains"];
|
|
239
|
+
readonly schema: DOM["actionSchema"][ID];
|
|
240
|
+
constructor(form: FORM, _domain: ActionDomain<DOM>, id: ID);
|
|
241
|
+
protected toJsonObject(): IActionBase_JsonObject<FORM, DOM, ID>;
|
|
242
|
+
protected toJsonString(): string;
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/ActionDefinition/Action/Context/ActionContext.types.d.ts
|
|
246
|
+
interface IActionRouteItem {
|
|
247
|
+
runtime: RuntimeCoordinate;
|
|
248
|
+
handler: IActionRouteItemHandler;
|
|
249
|
+
time: number;
|
|
250
|
+
}
|
|
251
|
+
interface IActionContext_Data {
|
|
252
|
+
cuid: string;
|
|
253
|
+
timeCreated: number;
|
|
254
|
+
routing: IActionRouteItem[];
|
|
255
|
+
originClient: RuntimeCoordinate;
|
|
256
|
+
}
|
|
257
|
+
interface IActionContext<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase<EActionForm.context, DOM, ID>, IActionContext_Data {}
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* JSON TYPES
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
interface IActionRouteItem_JsonObject {
|
|
264
|
+
runtime: IRuntimeCoordinate;
|
|
265
|
+
handler: IActionRouteItemHandler;
|
|
266
|
+
time: number;
|
|
267
|
+
}
|
|
268
|
+
interface IActionContext_Data_JsonObject {
|
|
269
|
+
cuid: string;
|
|
270
|
+
timeCreated: number;
|
|
271
|
+
routing: IActionRouteItem_JsonObject[];
|
|
272
|
+
originClient: IRuntimeCoordinate;
|
|
273
|
+
}
|
|
274
|
+
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 {}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/ActionDefinition/Action/Context/ActionContext.d.ts
|
|
277
|
+
declare class ActionContext<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionBase<EActionForm.context, DOM, ID> implements IActionContext<DOM, ID> {
|
|
278
|
+
readonly _domain: ActionDomain<DOM>;
|
|
279
|
+
readonly form = EActionForm.context;
|
|
280
|
+
readonly _routing: IActionRouteItem[];
|
|
281
|
+
readonly timeCreated: number;
|
|
282
|
+
readonly cuid: string;
|
|
283
|
+
originClient: RuntimeCoordinate;
|
|
284
|
+
constructor(_domain: ActionDomain<DOM>, id: ID, hydrationData: IActionContext_Data);
|
|
285
|
+
_setOriginClient(client: RuntimeCoordinate): void;
|
|
286
|
+
toJsonString(): string;
|
|
287
|
+
toContextDataJsonObject(): IActionContext_Data_JsonObject;
|
|
288
|
+
toJsonObject(): IActionContext_JsonObject<DOM, ID>;
|
|
289
|
+
get routing(): IActionRouteItem[];
|
|
290
|
+
addRouteItem(item: IActionRouteItem): void;
|
|
291
|
+
deserializeInput(serialized: TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
292
|
+
serializeInput(raw: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"];
|
|
293
|
+
validateInput(input: unknown): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
294
|
+
validateOutput(output: unknown): TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"];
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/ActionDefinition/Action/Payload/ActionPayload.d.ts
|
|
298
|
+
declare abstract class ActionPayload<DT extends EActionPayloadType, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionBase<EActionForm.data, DOM, ID> implements IActionPayload_Base<DT, DOM, ID> {
|
|
299
|
+
readonly form: EActionForm.data;
|
|
300
|
+
readonly type: DT;
|
|
301
|
+
readonly context: ActionContext<DOM, ID>;
|
|
302
|
+
readonly time: number;
|
|
303
|
+
protected constructor(context: ActionContext<DOM, ID>, type: DT, data: IActionPayload_Data_Base);
|
|
304
|
+
protected toBaseJsonObject(): IActionPayload_Base_JsonObject<DT, DOM, ID>;
|
|
305
|
+
abstract toJsonObject(): IActionPayload_Base_JsonObject<DT, DOM, ID>;
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/ActionDefinition/Action/Payload/ActionPayload_Result.d.ts
|
|
309
|
+
declare class ActionPayload_Result<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionPayload<EActionPayloadType.result, DOM, ID> {
|
|
310
|
+
readonly result: TActionResultOutcome<TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"], TInferActionError<DOM["actionSchema"][ID]>>;
|
|
311
|
+
readonly outputHash: string;
|
|
312
|
+
constructor(params: {
|
|
313
|
+
context: ActionContext<DOM, ID>;
|
|
314
|
+
} | ActionPayload_Request<DOM, ID>, result: TActionResultOutcome<TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"], TInferActionError<DOM["actionSchema"][ID]>>, data: IActionPayload_Data_Base);
|
|
315
|
+
toJsonObject(): IActionPayload_Result_JsonObject<DOM, ID>;
|
|
316
|
+
toJsonString(): string;
|
|
317
|
+
toHttpResponse({
|
|
318
|
+
useErrorStatus
|
|
319
|
+
}?: {
|
|
320
|
+
useErrorStatus?: boolean;
|
|
321
|
+
}): Response;
|
|
322
|
+
}
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/ActionDefinition/Action/RunningAction.types.d.ts
|
|
325
|
+
declare enum ERunningActionState {
|
|
326
|
+
running = "running",
|
|
327
|
+
completed = "completed"
|
|
328
|
+
}
|
|
329
|
+
interface IRunningActionState<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> {
|
|
330
|
+
request: ActionPayload_Request<DOM, ID>;
|
|
331
|
+
progress: ActionPayload_Progress<DOM, ID>[];
|
|
332
|
+
result?: ActionPayload_Result<DOM, ID>;
|
|
333
|
+
}
|
|
334
|
+
interface IRunningActionState_ConstructorParams<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> {
|
|
335
|
+
context: ActionContext<DOM, ID>;
|
|
336
|
+
request: ActionPayload_Request<DOM, ID>;
|
|
337
|
+
progress?: ActionPayload_Progress<DOM, ID>[];
|
|
338
|
+
result?: ActionPayload_Result<DOM, ID>;
|
|
339
|
+
parentCuid?: string;
|
|
340
|
+
callSite?: string;
|
|
341
|
+
}
|
|
342
|
+
declare enum ERunningActionUpdateType {
|
|
343
|
+
started = "started",
|
|
344
|
+
progress = "progress",
|
|
345
|
+
finished = "finished"
|
|
346
|
+
}
|
|
347
|
+
interface IRunningActionEvent_Base<T extends ERunningActionUpdateType, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> {
|
|
348
|
+
type: T;
|
|
349
|
+
runningAction: RunningAction<DOM, ID>;
|
|
350
|
+
time: number;
|
|
351
|
+
}
|
|
352
|
+
interface IRunningActionUpdate_Started<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionEvent_Base<ERunningActionUpdateType.started, DOM, ID> {}
|
|
353
|
+
interface IRunningActionUpdate_Progress<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionEvent_Base<ERunningActionUpdateType.progress, DOM, ID> {
|
|
354
|
+
progress: TActionProgress;
|
|
355
|
+
}
|
|
356
|
+
declare enum ERunningActionFinishedType {
|
|
357
|
+
aborted = "aborted",
|
|
358
|
+
failed = "failed",
|
|
359
|
+
success = "success"
|
|
360
|
+
}
|
|
361
|
+
interface IRunningActionUpdate_Finished<FT extends ERunningActionFinishedType, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionEvent_Base<ERunningActionUpdateType.finished, DOM, ID> {
|
|
362
|
+
finishType: FT;
|
|
363
|
+
reason?: unknown;
|
|
364
|
+
}
|
|
365
|
+
interface IRunningActionUpdate_Abort<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.aborted, DOM, ID> {
|
|
366
|
+
reason?: unknown;
|
|
367
|
+
}
|
|
368
|
+
interface IRunningActionUpdate_Failed<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.failed, DOM, ID> {
|
|
369
|
+
error: TInferActionError<DOM["actionSchema"][ID]>;
|
|
370
|
+
}
|
|
371
|
+
interface IRunningActionUpdate_Success<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IRunningActionUpdate_Finished<ERunningActionFinishedType.success, DOM, ID> {
|
|
372
|
+
response: ActionPayload_Result<DOM, ID>;
|
|
373
|
+
}
|
|
374
|
+
type TRunningActionUpdateFinished<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = IRunningActionUpdate_Abort<DOM, ID> | IRunningActionUpdate_Failed<DOM, ID> | IRunningActionUpdate_Success<DOM, ID>;
|
|
375
|
+
type TRunningActionUpdate<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = IRunningActionUpdate_Started<DOM, ID> | IRunningActionUpdate_Progress<DOM, ID> | TRunningActionUpdateFinished<DOM, ID>;
|
|
376
|
+
type TRunningActionUpdateListener<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = (update: TRunningActionUpdate<DOM, ID>) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Distributes a union ID into a proper discriminated union of RunningAction update events,
|
|
379
|
+
* so that narrowing on `update.runningAction.id` also narrows `update.runningAction`'s input/output types.
|
|
380
|
+
*/
|
|
381
|
+
type TDistributeRunningActionUpdate<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = ID extends keyof DOM["actionSchema"] & string ? TRunningActionUpdate<DOM, ID> : never;
|
|
382
|
+
type TDistributeRunningActionUpdateListener<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = (update: TDistributeRunningActionUpdate<DOM, ID>) => void;
|
|
383
|
+
interface IRunningActionUserMethods<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> {
|
|
384
|
+
waitForResultPayload(): Promise<ActionPayload_Result<DOM, ID>>;
|
|
385
|
+
addUpdateListeners(listeners: TRunningActionUpdateListener<DOM, ID>[]): () => void;
|
|
386
|
+
iterateUpdates(): AsyncIterable<TRunningActionUpdate<DOM, ID>>;
|
|
387
|
+
abort(reason?: unknown): void;
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/ActionDefinition/Action/Core/ActionCore.types.d.ts
|
|
391
|
+
interface IActionCore<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase<EActionForm.core, DOM, ID> {}
|
|
392
|
+
type IActionCore_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = {
|
|
393
|
+
form: EActionForm.core;
|
|
394
|
+
domain: DOM["domain"];
|
|
395
|
+
allDomains: DOM["allDomains"];
|
|
396
|
+
id: ID;
|
|
397
|
+
};
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/ActionDefinition/Action/Action.combined.types.d.ts
|
|
400
|
+
/**
|
|
401
|
+
* Distributes a union ID into a proper discriminated union of ActionPayload_Request instances,
|
|
402
|
+
* so that narrowing on `.id` also narrows `.input`.
|
|
403
|
+
*/
|
|
404
|
+
type TDistributeActionPayload_Request<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> = ID extends keyof DOM["actionSchema"] & string ? ActionPayload_Request<DOM, ID> : never;
|
|
405
|
+
/**
|
|
406
|
+
* Distributes a union ID into a proper discriminated union of ActionPayload_Result instances,
|
|
407
|
+
* so that narrowing on `.id` also narrows `.result`.
|
|
408
|
+
*/
|
|
409
|
+
type TDistributeActionPayload_Result<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> = ID extends keyof DOM["actionSchema"] & string ? ActionPayload_Result<DOM, ID> : never;
|
|
410
|
+
/**
|
|
411
|
+
*
|
|
412
|
+
* COMBINED JSON TYPES
|
|
413
|
+
*
|
|
414
|
+
*/
|
|
415
|
+
type TAction_Any_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = IActionCore_JsonObject<DOM, ID> | TActionPayload_Any_JsonObject<DOM, ID> | IActionContext_JsonObject<DOM, ID>;
|
|
416
|
+
/**
|
|
417
|
+
*
|
|
418
|
+
* UTILITY TYPES
|
|
419
|
+
*
|
|
420
|
+
*/
|
|
421
|
+
type TDistributedDomainActions<DOM extends IActionDomain, ACT extends IActionBase<any, DOM, any>> = { [ID in keyof DOM["actionSchema"] & string]: TNarrowActionType<DOM, ACT, ID> }[keyof DOM["actionSchema"] & string];
|
|
422
|
+
type TNarrowActionType<DOM extends IActionDomain, ACT extends IActionBase<any, DOM, any>, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = ACT extends ActionPayload_Result<any> ? ActionPayload_Result<DOM, ID> : ACT extends ActionPayload_Request<any> ? ActionPayload_Request<DOM, ID> : ACT extends ActionPayload_Progress<any> ? ActionPayload_Progress<DOM, ID> : ACT extends ActionCore<any> ? ActionCore<DOM, ID> : never;
|
|
423
|
+
type TNarrowActionJsonTypeToActionInstanceType<DOM extends IActionDomain, ACT extends TAction_Any_JsonObject<DOM>, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = ACT extends IActionPayload_Request_JsonObject<any> ? ActionPayload_Request<DOM, ID> : ACT extends IActionPayload_Result_JsonObject<any> ? ActionPayload_Result<DOM, ID> : ACT extends IActionPayload_Progress_JsonObject<any> ? ActionPayload_Progress<DOM, ID> : ACT extends IActionCore_JsonObject<any> ? ActionCore<DOM, ID> : never;
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/ActionRuntime/ActionDomainManager.d.ts
|
|
426
|
+
declare class ActionDomainManager {
|
|
427
|
+
private _domains;
|
|
428
|
+
addDomain(domain: ActionDomain<any>): void;
|
|
429
|
+
getDomains(): ActionDomain<any>[];
|
|
430
|
+
verifyIsActionJson(action: INiceActionIdAndDomain<any>): void;
|
|
431
|
+
getActionDomain<DOM extends IActionDomain, ACT extends INiceActionIdAndDomain<DOM>>(action: ACT): ActionDomain<DOM> | undefined;
|
|
432
|
+
getActionDomainOrThrow<DOM extends IActionDomain, ACT extends INiceActionIdAndDomain<DOM>>(action: ACT): ActionDomain<DOM>;
|
|
433
|
+
hydrateActionPayload<D extends IActionDomain, ID extends keyof D["actionSchema"] & string, A extends TAction_Any_JsonObject<D, ID>>(actionJson: A): TNarrowActionJsonTypeToActionInstanceType<D, A, ID>;
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/ActionRuntime/Routing/ActionRouter.types.d.ts
|
|
437
|
+
/**
|
|
438
|
+
* Format: `dom[${domainName}]id[${actionId | "_"}]`
|
|
439
|
+
* The wildcard `_` matches any action ID within a domain.
|
|
440
|
+
*/
|
|
441
|
+
type TMatchHandlerKey = `${"dom"}[${string}]id[${string | "_"}]`;
|
|
442
|
+
declare enum EActionRouterContextType {
|
|
443
|
+
runtime_to_handler = "runtime_to_handler",
|
|
444
|
+
handler_route = "handler_route"
|
|
445
|
+
}
|
|
446
|
+
interface IActionRouterContext_HandlerRoute {
|
|
447
|
+
contextType: EActionRouterContextType.handler_route;
|
|
448
|
+
handler: TActionHandler;
|
|
449
|
+
}
|
|
450
|
+
interface IActionRouterContext_RuntimeToHandler {
|
|
451
|
+
contextType: EActionRouterContextType.runtime_to_handler;
|
|
452
|
+
runtime: ActionRuntime;
|
|
453
|
+
}
|
|
454
|
+
type IActionRouterContext = IActionRouterContext_HandlerRoute | IActionRouterContext_RuntimeToHandler;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/ActionRuntime/Routing/ActionRouter.d.ts
|
|
457
|
+
declare class ActionRouter<DATA> {
|
|
458
|
+
readonly domainManager: ActionDomainManager;
|
|
459
|
+
private actionRouteData;
|
|
460
|
+
private _context;
|
|
461
|
+
constructor(context: IActionRouterContext);
|
|
462
|
+
/** Copy all routes from another router into this one, replacing any overlapping keys. */
|
|
463
|
+
mergeRouter(actionRouter: ActionRouter<DATA>): void;
|
|
464
|
+
addDomainsFromOther(actionRouter: ActionRouter<DATA>): void;
|
|
465
|
+
/** All FNs registered for an action, ID-specific entries first then domain wildcard. */
|
|
466
|
+
getRouteDataEntriesForAction(action: {
|
|
467
|
+
domain: string;
|
|
468
|
+
id: string;
|
|
469
|
+
}): DATA[];
|
|
470
|
+
/** First FN registered for an action (ID-specific beats domain wildcard). */
|
|
471
|
+
getRouteDataForAction(action: INiceActionIdAndDomain): DATA | undefined;
|
|
472
|
+
private throwNoHandlerForAction;
|
|
473
|
+
getRouteDataEntriesForActionOrThrow(action: INiceActionIdAndDomain, context: IHandleActionOptions): DATA[];
|
|
474
|
+
getRouteDataForActionOrThrow(action: INiceActionIdAndDomain, context: IHandleActionOptions): DATA;
|
|
475
|
+
/** All FNs stored under an exact match key. */
|
|
476
|
+
getForKey(key: TMatchHandlerKey): readonly DATA[];
|
|
477
|
+
/** Every match key that has at least one registered FN. */
|
|
478
|
+
getRegisteredKeys(): TMatchHandlerKey[];
|
|
479
|
+
getDomains(): ActionDomain[];
|
|
480
|
+
/** Register a handler for all actions in a domain, replacing any existing one. */
|
|
481
|
+
forDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, routeData: DATA): this;
|
|
482
|
+
forAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(action: ActionCore<ACT_DOM, ID>, routeData: DATA): this;
|
|
483
|
+
/** Register a handler for a specific action, replacing any existing one. */
|
|
484
|
+
forActionId<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(domain: ActionDomain<ACT_DOM>, id: ID, routeData: DATA): this;
|
|
485
|
+
/** Register one handler for several action IDs, replacing any existing ones. */
|
|
486
|
+
forActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actionSchema"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS, routeData: DATA): this;
|
|
487
|
+
/** Register per-action handlers from a cases map, replacing any existing ones. */
|
|
488
|
+
forDomainActionCases<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, cases: { [ID in keyof FOR_DOM["actionSchema"] & string]?: DATA }): this;
|
|
489
|
+
/** Append a handler for all actions in a domain (accumulates alongside existing). */
|
|
490
|
+
addForDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, routeData: DATA): this;
|
|
491
|
+
/** Append a handler for a specific action (accumulates alongside existing). */
|
|
492
|
+
addForAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(domain: ActionDomain<ACT_DOM>, id: ID, routeData: DATA): this;
|
|
493
|
+
/** Append one handler for several action IDs (accumulates alongside existing). */
|
|
494
|
+
addForActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actionSchema"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS, routeData: DATA): this;
|
|
495
|
+
/** Append per-action handlers from a cases map (accumulates alongside existing). */
|
|
496
|
+
addForDomainActionCases<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, cases: { [ID in keyof FOR_DOM["actionSchema"] & string]?: DATA }): this;
|
|
497
|
+
/** Append a handler directly by its raw match key (used when the key is known ahead of time). */
|
|
498
|
+
addForKey(key: TMatchHandlerKey, routeData: DATA): this;
|
|
499
|
+
private _push;
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/ActionRuntime/Handler/ActionHandler.types.d.ts
|
|
503
|
+
declare enum EActionHandlerType {
|
|
504
|
+
external = "external",
|
|
505
|
+
local = "local"
|
|
506
|
+
}
|
|
507
|
+
interface IActionHandler_Json<T extends EActionHandlerType> {
|
|
508
|
+
type: T;
|
|
509
|
+
}
|
|
510
|
+
interface IActionHandler_ExternalClient_Json extends IActionHandler_Json<EActionHandlerType.external> {
|
|
511
|
+
client: IRuntimeCoordinate;
|
|
512
|
+
}
|
|
513
|
+
interface IActionHandler_Local_Json extends IActionHandler_Json<EActionHandlerType.local> {}
|
|
514
|
+
type TActionHandler_Json = IActionHandler_Local_Json | IActionHandler_ExternalClient_Json;
|
|
515
|
+
interface IHandleActionOptions {
|
|
516
|
+
timeout?: number;
|
|
517
|
+
targetExternalClient?: RuntimeCoordinate;
|
|
518
|
+
targetLocalRuntime?: ActionRuntime;
|
|
519
|
+
}
|
|
520
|
+
interface IExecuteActionOptions<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IHandleActionOptions {
|
|
521
|
+
listeners?: TRunningActionUpdateListener<DOM, ID>[];
|
|
522
|
+
}
|
|
523
|
+
interface IActionHandler_Base<T extends EActionHandlerType> {
|
|
524
|
+
cuid: string;
|
|
525
|
+
handlerType: T;
|
|
526
|
+
getActionRouter: () => ActionRouter<any>;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
*
|
|
530
|
+
* LOCAL ACTION HANDLER
|
|
531
|
+
*
|
|
532
|
+
*/
|
|
533
|
+
interface IHandleActionOptions_Local extends IHandleActionOptions {}
|
|
534
|
+
interface IActionHandler_Local extends IActionHandler_Base<EActionHandlerType.local> {
|
|
535
|
+
handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_Local) => Promise<RunningAction<DOM, ID>>;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
*
|
|
539
|
+
* EXTERNAL CLIENT ACTION HANDLER
|
|
540
|
+
*
|
|
541
|
+
*/
|
|
542
|
+
interface IHandleActionOptions_External extends IHandleActionOptions {}
|
|
543
|
+
interface IActionHandler_ExternalClient extends IActionHandler_Base<EActionHandlerType.external> {
|
|
544
|
+
externalClient: RuntimeCoordinate;
|
|
545
|
+
handleActionRequest: <DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions_External) => Promise<RunningAction<DOM, ID>>;
|
|
546
|
+
_setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any>) => void): void;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
*
|
|
550
|
+
* COMBINED
|
|
551
|
+
*
|
|
552
|
+
*/
|
|
553
|
+
type TActionHandler = IActionHandler_Local | IActionHandler_ExternalClient;
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/ActionDefinition/Action/Payload/ActionPayload_Request.d.ts
|
|
556
|
+
declare class ActionPayload_Request<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionPayload<EActionPayloadType.request, DOM, ID> {
|
|
557
|
+
readonly input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
558
|
+
readonly inputHash: string;
|
|
559
|
+
_callSite?: string;
|
|
560
|
+
constructor(params: {
|
|
561
|
+
context: ActionContext<DOM, ID>;
|
|
562
|
+
}, input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"], data: IActionPayload_Data_Base);
|
|
563
|
+
successResult(...args: [TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"]] extends [never] ? [] | [output: TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"]] : [output: TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"]]): ActionPayload_Result<DOM, ID>;
|
|
564
|
+
errorResult(err: TInferActionError<DOM["actionSchema"][ID]>): ActionPayload_Result<DOM, ID>;
|
|
565
|
+
progress(progress: TActionProgress): ActionPayload_Progress<DOM, ID>;
|
|
566
|
+
toJsonObject(): IActionPayload_Request_JsonObject<DOM, ID>;
|
|
567
|
+
toJsonString(): string;
|
|
568
|
+
runToOutput(options?: IExecuteActionOptions<DOM, ID>): Promise<TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"]>;
|
|
569
|
+
runToResultPayload(options?: IExecuteActionOptions<DOM, ID>): Promise<ActionPayload_Result<DOM, ID>>;
|
|
570
|
+
run(options?: IExecuteActionOptions<DOM, ID>): Promise<RunningAction<DOM, ID>>;
|
|
571
|
+
}
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/ActionDefinition/Action/Payload/ActionPayload_Progress.d.ts
|
|
574
|
+
declare class ActionPayload_Progress<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionPayload<EActionPayloadType.progress, DOM, ID> implements IActionPayload_Progress<DOM, ID> {
|
|
575
|
+
readonly progress: TActionProgress;
|
|
576
|
+
constructor(params: {
|
|
577
|
+
context: ActionContext<DOM, ID>;
|
|
578
|
+
} | ActionPayload_Request<DOM, ID>, progress: TActionProgress, data: IActionPayload_Data_Base);
|
|
579
|
+
toJsonObject(): IActionPayload_Progress_JsonObject<DOM, ID>;
|
|
580
|
+
toJsonString(): string;
|
|
581
|
+
toHttpResponse(): Response;
|
|
582
|
+
}
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/ActionDefinition/Action/RunningAction.d.ts
|
|
585
|
+
declare class RunningAction<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> implements IRunningActionUserMethods<DOM, ID> {
|
|
586
|
+
protected _state: IRunningActionState<DOM, ID>;
|
|
587
|
+
readonly context: ActionContext<DOM, ID>;
|
|
588
|
+
readonly cuid: string;
|
|
589
|
+
readonly id: ID;
|
|
590
|
+
readonly _domain: ActionDomain<DOM>;
|
|
591
|
+
readonly domain: DOM["domain"];
|
|
592
|
+
readonly allDomains: DOM["allDomains"];
|
|
593
|
+
readonly parentCuid?: string;
|
|
594
|
+
readonly callSite?: string;
|
|
595
|
+
private readonly _resultPayloadPromise;
|
|
596
|
+
private _resolveResult;
|
|
597
|
+
private _rejectResult;
|
|
598
|
+
private _isAborted;
|
|
599
|
+
private readonly _updates;
|
|
600
|
+
private readonly _updateListeners;
|
|
601
|
+
constructor(initialState: IRunningActionState_ConstructorParams<DOM, ID>);
|
|
602
|
+
get state(): IRunningActionState<DOM, ID>;
|
|
603
|
+
abort(reason?: unknown): void;
|
|
604
|
+
addUpdateListeners(listeners: TRunningActionUpdateListener<DOM, ID>[]): () => void;
|
|
605
|
+
iterateUpdates(): AsyncIterable<TRunningActionUpdate<DOM, ID>>;
|
|
606
|
+
_sendUpdate(update: TRunningActionUpdate<DOM, ID>): void;
|
|
607
|
+
_completeWithResult(result: ActionPayload_Result<DOM, ID>): boolean;
|
|
608
|
+
_abort(reason?: unknown): boolean;
|
|
609
|
+
_failWithError(error: unknown): boolean;
|
|
610
|
+
_updateProgress(progress: ActionPayload_Progress<DOM, ID>): void;
|
|
611
|
+
waitForResultPayload(): Promise<ActionPayload_Result<DOM, ID>>;
|
|
612
|
+
_resolveFromJson(resultJson: IActionPayload_Result_JsonObject<DOM, ID>): boolean;
|
|
613
|
+
}
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/ActionRuntime/Handler/ActionHandler.d.ts
|
|
616
|
+
declare abstract class ActionHandler<T extends EActionHandlerType> implements IActionHandler_Base<T> {
|
|
617
|
+
abstract readonly handlerType: T;
|
|
618
|
+
readonly cuid: string;
|
|
619
|
+
abstract readonly actionRouter: ActionRouter<any>;
|
|
620
|
+
constructor();
|
|
621
|
+
getActionRouter(): ActionRouter<any>;
|
|
622
|
+
abstract handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
|
|
623
|
+
abstract toJsonObject(): TActionHandler_Json;
|
|
624
|
+
abstract toHandlerRouteItem(...args: any[]): IActionRouteItemHandler;
|
|
625
|
+
}
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/TransportConnection.d.ts
|
|
628
|
+
/**
|
|
629
|
+
* Live, per-handler transport runtime built from a reusable {@link Transport} definition. Holds the
|
|
630
|
+
* connection-scoped state (ordinal, initialized config, sockets / abort sets) that must not be shared
|
|
631
|
+
* across handlers. Construct these via `definition._createConnection(...)`, never directly.
|
|
632
|
+
*/
|
|
633
|
+
declare abstract class TransportConnection<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>> {
|
|
634
|
+
readonly def: DEF;
|
|
635
|
+
readonly transOrd: number;
|
|
636
|
+
readonly type: T;
|
|
637
|
+
readonly initialized: I;
|
|
638
|
+
/** Backref to the public definition that created this connection (used for devtools route info). */
|
|
639
|
+
definition?: Transport<T>;
|
|
640
|
+
constructor(def: DEF);
|
|
641
|
+
/**
|
|
642
|
+
* Devtools route info for an action routed through this live connection. Defaults to the stateless
|
|
643
|
+
* {@link definition}'s info; connections override to enrich it from live state (e.g. the actual
|
|
644
|
+
* resolved socket URL) when the definition couldn't resolve it on its own.
|
|
645
|
+
*/
|
|
646
|
+
getRouteInfo(input: RP): ITransportRouteInfo | undefined;
|
|
647
|
+
protected abstract _finalizeTransportMethods(inputs: RD): IActionTransportReadyData_Methods;
|
|
648
|
+
protected _getCacheKey(input: RP): string | null;
|
|
649
|
+
getCacheKey(input: RP): string | null;
|
|
650
|
+
getTransport(input: RP): TTransportStatusInfo<IActionTransportReadyData_Methods>;
|
|
651
|
+
protected _processTransportStatus(input: RP): TTransportStatusInfo<IActionTransportReadyData_Methods>;
|
|
652
|
+
}
|
|
653
|
+
//#endregion
|
|
654
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Transport.types.d.ts
|
|
655
|
+
declare enum ETransportType {
|
|
656
|
+
ws = "ws",
|
|
657
|
+
http = "http",
|
|
658
|
+
custom = "custom"
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Serializable, display-only description of how an action was routed through a transport. Stored on
|
|
662
|
+
* the action's route items and shown in the devtools external-handler chips. Keep this free of
|
|
663
|
+
* sensitive data (e.g. auth headers) — route items travel over the wire.
|
|
664
|
+
*/
|
|
665
|
+
interface ITransportRouteInfo {
|
|
666
|
+
type: ETransportType;
|
|
667
|
+
/** Short label for chips, e.g. "POST /resolve_action" or "ws host/resolve_action/ws". */
|
|
668
|
+
summary?: string;
|
|
669
|
+
url?: string;
|
|
670
|
+
method?: string;
|
|
671
|
+
detail?: Record<string, string | number | boolean>;
|
|
672
|
+
}
|
|
673
|
+
interface IUpdateActionRunConfig_Output {
|
|
674
|
+
timeout?: number;
|
|
675
|
+
}
|
|
676
|
+
type TUpdateActionRunConfig = (input: ITransportRouteActionParams & {
|
|
677
|
+
timeout: number;
|
|
678
|
+
}) => IUpdateActionRunConfig_Output;
|
|
679
|
+
interface IActionTransportReadyData_Base {
|
|
680
|
+
updateRunConfig?: TUpdateActionRunConfig;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
*
|
|
684
|
+
* TRANSPORT READINESS RESPONSE
|
|
685
|
+
*
|
|
686
|
+
*/
|
|
687
|
+
declare enum ETransportStatus {
|
|
688
|
+
uninitialized = "uninitialized",
|
|
689
|
+
unsupported = "unsupported",
|
|
690
|
+
initializing = "initializing",
|
|
691
|
+
ready = "ready",
|
|
692
|
+
failed = "failed"
|
|
693
|
+
}
|
|
694
|
+
interface ITransportStatusInfo_Base<S extends ETransportStatus> {
|
|
695
|
+
status: S;
|
|
696
|
+
}
|
|
697
|
+
interface ITransportStatusInfo_Failed extends ITransportStatusInfo_Base<ETransportStatus.failed> {
|
|
698
|
+
error: NiceError;
|
|
699
|
+
timeFailed: number;
|
|
700
|
+
}
|
|
701
|
+
interface ITransportStatusInfo_Unsupported extends ITransportStatusInfo_Base<ETransportStatus.unsupported> {}
|
|
702
|
+
interface ITransportStatusInfo_Ready<READY extends IActionTransportReadyData_Base> extends ITransportStatusInfo_Base<ETransportStatus.ready> {
|
|
703
|
+
readyData: READY;
|
|
704
|
+
}
|
|
705
|
+
type TTransportInitializationFinishedInfo<READY extends IActionTransportReadyData_Base> = ITransportStatusInfo_Ready<READY> | ITransportStatusInfo_Failed | ITransportStatusInfo_Unsupported;
|
|
706
|
+
interface ITransportStatusInfo_Initializing<READY extends IActionTransportReadyData_Base> extends ITransportStatusInfo_Base<ETransportStatus.initializing> {
|
|
707
|
+
timeStarted: number;
|
|
708
|
+
initializationPromise: Promise<TTransportInitializationFinishedInfo<READY>>;
|
|
709
|
+
}
|
|
710
|
+
type TTransportStatusInfo<READY extends IActionTransportReadyData_Base> = ITransportStatusInfo_Base<ETransportStatus.uninitialized> | ITransportStatusInfo_Unsupported | ITransportStatusInfo_Initializing<READY> | ITransportStatusInfo_Ready<READY> | ITransportStatusInfo_Failed;
|
|
711
|
+
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">;
|
|
712
|
+
/**
|
|
713
|
+
*
|
|
714
|
+
* TRANSPORT ROUTING
|
|
715
|
+
*
|
|
716
|
+
*/
|
|
717
|
+
interface ITransportRouteClientParams {
|
|
718
|
+
localClient: RuntimeCoordinate;
|
|
719
|
+
externalClient: RuntimeCoordinate;
|
|
720
|
+
}
|
|
721
|
+
interface ITransportRouteActionParams extends ITransportRouteClientParams {
|
|
722
|
+
action: TActionPayload_Any_Instance<any, any>;
|
|
723
|
+
}
|
|
724
|
+
interface ITransportMethod_SendActionData_Input extends ITransportRouteActionParams {
|
|
725
|
+
runningAction: RunningAction<any, any>;
|
|
726
|
+
timeout: number;
|
|
727
|
+
}
|
|
728
|
+
interface ITransportDispatchAction<P> extends ITransportMethod_SendActionData_Input {
|
|
729
|
+
params: P;
|
|
730
|
+
}
|
|
731
|
+
type TSendActionDataMethod = (input: ITransportMethod_SendActionData_Input) => void;
|
|
732
|
+
type TSendReturnDataMethod = (payload: TActionPayload_Any_Instance<any, any>,
|
|
733
|
+
/**
|
|
734
|
+
* The local/external client pair this payload is being returned over. Bidirectional transports use
|
|
735
|
+
* it to build the full route params their outgoing formatter expects (e.g. binary packing). Optional
|
|
736
|
+
* so existing return-data implementations keep type-checking.
|
|
737
|
+
*/
|
|
738
|
+
|
|
739
|
+
clients?: ITransportRouteClientParams) => void;
|
|
740
|
+
interface IActionTransportReadyData_Methods extends IActionTransportReadyData_Base {
|
|
741
|
+
sendActionData: TSendActionDataMethod;
|
|
742
|
+
/**
|
|
743
|
+
* Optional — implement on bidirectional transports (WebSocket, Custom) to enable return-path
|
|
744
|
+
* routing. When present, the runtime uses this to dispatch results and progress payloads directly
|
|
745
|
+
* back to `originClient` without going through the original request transport.
|
|
746
|
+
*/
|
|
747
|
+
sendReturnData?: TSendReturnDataMethod;
|
|
748
|
+
addOnDisconnectListener?: (callback: () => void) => void;
|
|
749
|
+
/**
|
|
750
|
+
* Optional — implement on transports holding a long-lived connection (WebSocket, Custom) to close it
|
|
751
|
+
* deliberately. Called by `ActionExternalClientHandler.clearTransportCache()` so a teardown actually
|
|
752
|
+
* releases the underlying socket instead of leaving it open until GC.
|
|
753
|
+
*/
|
|
754
|
+
disconnect?: () => void;
|
|
755
|
+
}
|
|
756
|
+
interface IActionTransportReady {
|
|
757
|
+
methods: IActionTransportReadyData_Methods;
|
|
758
|
+
transport: TransportConnection;
|
|
759
|
+
}
|
|
760
|
+
type TTransportCache = Map<string, IActionTransportReady | Promise<IActionTransportReady>>;
|
|
761
|
+
type TOnResolveIncomingRequest = (request: ActionPayload_Request<any>) => void;
|
|
762
|
+
type TOnResolveIncomingRequestJson = (request: IActionPayload_Request_JsonObject<any>) => void;
|
|
763
|
+
type TOnResolveIncomingResponse = (response: ActionPayload_Result<any>) => void;
|
|
764
|
+
type TOnResolveIncomingResponseJson = (response: IActionPayload_Result_JsonObject<any>) => void;
|
|
765
|
+
type TOnResolveAnyIncomingActionData = (actionData: ActionPayload_Request<any> | ActionPayload_Result<any>) => void;
|
|
766
|
+
type TOnResolveAnyIncomingActionData_Json = (actionData: TActionPayload_Any_JsonObject<any>) => void;
|
|
767
|
+
interface IActionTransportResolvers {
|
|
768
|
+
onIncomingActionDataJson: TOnResolveAnyIncomingActionData_Json;
|
|
769
|
+
}
|
|
770
|
+
type TGetTransportFn<IN extends ITransportRouteActionParams, READY extends IActionTransportReadyData_Base> = (input: IN) => TTransportStatusInfo_GetTransport_Output<READY>;
|
|
771
|
+
interface IActionTransportInitialized<IN extends ITransportRouteActionParams, READY extends IActionTransportReadyData_Base> {
|
|
772
|
+
getTransportCacheKey?: (input: IN) => string[];
|
|
773
|
+
getTransport: TGetTransportFn<IN, READY>;
|
|
774
|
+
}
|
|
775
|
+
interface IActionTransportDef<TYPE extends ETransportType, INIT extends IActionTransportInitialized<any, any>> {
|
|
776
|
+
type: TYPE;
|
|
777
|
+
initialize: () => INIT;
|
|
778
|
+
}
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Transport.d.ts
|
|
781
|
+
/**
|
|
782
|
+
* Context handed to a {@link Transport} definition when a handler builds a live connection from it.
|
|
783
|
+
* Only bidirectional transports (WebSocket / Custom) make use of `resolvers`.
|
|
784
|
+
*/
|
|
785
|
+
interface ITransportConnectionContext {
|
|
786
|
+
resolvers?: IActionTransportResolvers;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Reusable transport definition. Devs construct these (`HttpTransport.create({ createRequest })`,
|
|
790
|
+
* `WebSocketTransport.create({ createWebSocket })`, …) and pass them to an
|
|
791
|
+
* `ActionExternalClientHandler`. A single
|
|
792
|
+
* definition can be shared across multiple handlers — each handler builds its own live
|
|
793
|
+
* {@link TransportConnection} via {@link TransportConnection._createConnection}.
|
|
794
|
+
*/
|
|
795
|
+
declare abstract class Transport<T extends ETransportType = ETransportType> {
|
|
796
|
+
abstract readonly type: T;
|
|
797
|
+
/** Internal: build a fresh, per-handler live connection from this definition. */
|
|
798
|
+
abstract _createConnection(ctx: ITransportConnectionContext): TransportConnection<T>;
|
|
799
|
+
/**
|
|
800
|
+
* Resolve human-readable info about how a specific action would be routed through this transport
|
|
801
|
+
* (e.g. the request URL/method, or the WebSocket endpoint). Surfaced in the action devtools.
|
|
802
|
+
*/
|
|
803
|
+
abstract getRouteInfo(input: ITransportRouteActionParams): ITransportRouteInfo;
|
|
804
|
+
}
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region src/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.types.d.ts
|
|
807
|
+
interface IActionExternalClientRequestHandlerConfig {
|
|
808
|
+
defaultTimeout?: number;
|
|
809
|
+
runtimeCoordinate: RuntimeCoordinate;
|
|
810
|
+
transports: Transport[];
|
|
811
|
+
}
|
|
812
|
+
//#endregion
|
|
813
|
+
//#region src/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts
|
|
814
|
+
declare class ActionExternalClientHandler extends ActionHandler<EActionHandlerType.external> implements IActionHandler_ExternalClient {
|
|
815
|
+
readonly externalClient: RuntimeCoordinate;
|
|
816
|
+
readonly handlerType = EActionHandlerType.external;
|
|
817
|
+
readonly cuid: string;
|
|
818
|
+
private _defaultTimeout;
|
|
819
|
+
private _transportCache;
|
|
820
|
+
private transportManager;
|
|
821
|
+
private _incomingActionDataListeners;
|
|
822
|
+
readonly actionRouter: ActionRouter<true>;
|
|
823
|
+
constructor({
|
|
824
|
+
runtimeCoordinate: externalClientSpecifier,
|
|
825
|
+
transports,
|
|
826
|
+
defaultTimeout
|
|
827
|
+
}: IActionExternalClientRequestHandlerConfig);
|
|
828
|
+
forDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>): this;
|
|
829
|
+
forAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(action: ActionCore<ACT_DOM, ID>): this;
|
|
830
|
+
forActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actionSchema"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS): this;
|
|
831
|
+
_setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any, any>) => void): void;
|
|
832
|
+
handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
|
|
833
|
+
private _dispatchWhenTransportReady;
|
|
834
|
+
/**
|
|
835
|
+
* Dispatch a result or progress payload directly back to the external client via the best
|
|
836
|
+
* available bidirectional transport (WebSocket / Custom). Used for return-path routing when the
|
|
837
|
+
* local runtime recognises that it has a direct channel to the action's originClient.
|
|
838
|
+
*
|
|
839
|
+
* Returns `true` if the payload was sent, `false` if no suitable transport was available.
|
|
840
|
+
*/
|
|
841
|
+
sendReturnPayload(payload: TActionPayload_Any_Instance<any, any>, config: {
|
|
842
|
+
targetLocalRuntime: ActionRuntime;
|
|
843
|
+
}): Promise<boolean>;
|
|
844
|
+
toJsonObject(): IActionHandler_ExternalClient_Json;
|
|
845
|
+
toHandlerRouteItem(transport: TransportConnection, input: ITransportRouteActionParams): IActionRouteItemHandler;
|
|
846
|
+
clearTransportCache(): void;
|
|
847
|
+
}
|
|
848
|
+
declare const createExternalClientHandler: (config: IActionExternalClientRequestHandlerConfig) => ActionExternalClientHandler;
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/utils/typescript/MaybePromise.d.ts
|
|
851
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/ActionRuntime/Handler/Local/ActionLocalHandler.types.d.ts
|
|
854
|
+
type THandleActionExecutionFn<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = (action: TDistributeActionPayload_Request<DOM, ID>) => MaybePromise<ActionPayload_Result<DOM, ID> | IActionPayload_Result_JsonObject<DOM, ID> | TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"] | undefined>;
|
|
855
|
+
//#endregion
|
|
856
|
+
//#region src/ActionRuntime/Handler/Local/ActionLocalHandler.d.ts
|
|
857
|
+
declare class ActionLocalHandler extends ActionHandler<EActionHandlerType.local> implements IActionHandler_Local {
|
|
858
|
+
readonly handlerType = EActionHandlerType.local;
|
|
859
|
+
readonly actionRouter: ActionRouter<THandleActionExecutionFn<any, any>>;
|
|
860
|
+
constructor();
|
|
861
|
+
/**
|
|
862
|
+
* Register a handler for all actions in a domain.
|
|
863
|
+
* Receives the full primed action — use `matchAction()` to narrow to a specific action id.
|
|
864
|
+
* Useful for forwarding all domain actions to a remote endpoint.
|
|
865
|
+
* Lower priority than `forAction`.
|
|
866
|
+
*/
|
|
867
|
+
forDomain<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, handler: THandleActionExecutionFn<FOR_DOM>): this;
|
|
868
|
+
/**
|
|
869
|
+
* Register a handler for a base action instance. Takes priority over domain-wide handlers.
|
|
870
|
+
* Receives the full primed action with narrowed input type.
|
|
871
|
+
* Useful for handling specific actions locally while forwarding the rest of the domain. For example, a local "ping" action that checks connectivity without needing a round trip.
|
|
872
|
+
*/
|
|
873
|
+
forAction<ACT_DOM extends IActionDomain, ID extends keyof ACT_DOM["actionSchema"] & string>(action: ActionCore<ACT_DOM, ID>, handler: THandleActionExecutionFn<ACT_DOM, ID>): this;
|
|
874
|
+
/**
|
|
875
|
+
* Register a handler for multiple action IDs (first-match-wins among cases).
|
|
876
|
+
* Receives the full primed action narrowed to the union of those IDs.
|
|
877
|
+
* Use `act.coreAction.id` to branch on which action was dispatched.
|
|
878
|
+
*/
|
|
879
|
+
forActionIds<ACT_DOM extends IActionDomain, IDS extends ReadonlyArray<keyof ACT_DOM["actionSchema"] & string>>(domain: ActionDomain<ACT_DOM>, ids: IDS, handler: THandleActionExecutionFn<ACT_DOM, IDS[number]>): this;
|
|
880
|
+
/**
|
|
881
|
+
* Register per-action handlers for a domain using a single map, without needing
|
|
882
|
+
* separate `forAction` calls. Unregistered action IDs are unaffected.
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```ts
|
|
886
|
+
* handler.forDomainActionCases(userDomain, {
|
|
887
|
+
* getUser: (primed) => db.getUser(primed.input.userId),
|
|
888
|
+
* deleteUser: (primed) => db.deleteUser(primed.input.userId),
|
|
889
|
+
* });
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
forDomainActionCases<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, cases: { [ID in keyof FOR_DOM["actionSchema"] & string]?: THandleActionExecutionFn<FOR_DOM, ID> }): this;
|
|
893
|
+
handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
|
|
894
|
+
private _handleRunningAction;
|
|
895
|
+
handlePayloadWireOrThrow(wire: unknown, config?: IHandleActionOptions): Promise<RunningAction<any, any>>;
|
|
896
|
+
toJsonObject(): IActionHandler_Local_Json;
|
|
897
|
+
toHandlerRouteItem(): IActionRouteItemHandler;
|
|
898
|
+
}
|
|
899
|
+
declare const createLocalHandler: () => ActionLocalHandler;
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/ActionRuntime/ActionRuntime.types.d.ts
|
|
902
|
+
interface IRuntimeMeta {
|
|
903
|
+
assumed: boolean;
|
|
904
|
+
runtimeName: RuntimeName;
|
|
905
|
+
}
|
|
906
|
+
interface IActionRuntimeManagerContext {
|
|
907
|
+
domain?: string;
|
|
908
|
+
}
|
|
909
|
+
type TActionRuntimeHandler = ActionLocalHandler | ActionExternalClientHandler;
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/ActionRuntime/ActionRuntime.d.ts
|
|
912
|
+
declare class ActionRuntime {
|
|
913
|
+
private _coordinate;
|
|
914
|
+
readonly timeCreated: number;
|
|
915
|
+
readonly runtimeInfo: IRuntimeMeta;
|
|
916
|
+
private readonly actionRouter;
|
|
917
|
+
private readonly _pendingRunningActions;
|
|
918
|
+
private readonly _registeredExternalHandlers;
|
|
919
|
+
private _applied;
|
|
920
|
+
static getDefault(): ActionRuntime;
|
|
921
|
+
constructor(coordinate: RuntimeCoordinate);
|
|
922
|
+
get coordinate(): RuntimeCoordinate;
|
|
923
|
+
specifyRuntimeCoordinate(specifics: IRuntimeCoordinateSpecifics & {
|
|
924
|
+
envId?: string;
|
|
925
|
+
}): void;
|
|
926
|
+
registerRunningAction(ra: RunningAction<any, any>): void;
|
|
927
|
+
resolveIncomingActionPayload(json: TActionPayload_Any_JsonObject<any, any>): void;
|
|
928
|
+
/**
|
|
929
|
+
* Handle an incoming action wire (e.g. from a transport layer), route it to
|
|
930
|
+
* the correct handler, and return the response. The most specific handler
|
|
931
|
+
* match is chosen (action-ID-specific beats domain-wildcard).
|
|
932
|
+
*/
|
|
933
|
+
handleActionPayloadWire<D extends IActionDomain, ID extends keyof D["actionSchema"] & string>(wire: TActionPayload_Any_JsonObject<D, ID>): Promise<RunningAction<D, ID>>;
|
|
934
|
+
handleActionPayloadWire(wire: unknown): Promise<RunningAction<any, any>>;
|
|
935
|
+
handleActionPayload<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: TActionPayload_Any_Instance<DOM, ID>, options?: Omit<IHandleActionOptions, "targetLocalRuntime">): Promise<RunningAction<DOM, ID>>;
|
|
936
|
+
/**
|
|
937
|
+
* @internal
|
|
938
|
+
*
|
|
939
|
+
* Return the first handler registered for the given action, or `undefined`
|
|
940
|
+
* if none has been registered (action-ID-specific beats domain-wildcard).
|
|
941
|
+
*/
|
|
942
|
+
_getHandlerForAction<ACT extends TActionPayload_Any_Instance<any, any>>(action: ACT, options?: Omit<IHandleActionOptions, "targetLocalRuntime">): TActionHandler | undefined;
|
|
943
|
+
getHandlerForActionOrThrow<ACT extends TActionPayload_Any_Instance<any, any>>(action: ACT, options?: Omit<IHandleActionOptions, "localRuntime">): TActionHandler;
|
|
944
|
+
/**
|
|
945
|
+
* Register one or more handlers. Each handler's own `actionRouter` defines
|
|
946
|
+
* which domains/actions it handles — those routing keys are mirrored into
|
|
947
|
+
* this runtime's router so the same action can be served by multiple handlers.
|
|
948
|
+
* Duplicate registrations (same handler cuid for the same key) are skipped.
|
|
949
|
+
*/
|
|
950
|
+
addHandlers(handlers: TActionRuntimeHandler[]): this;
|
|
951
|
+
/**
|
|
952
|
+
* Declare an external "backend client" in one call: build an
|
|
953
|
+
* {@link ActionExternalClientHandler} for `externalCoordinate` carrying the given
|
|
954
|
+
* `transports`, route the listed `domains`/`actions` to it, register it (plus any
|
|
955
|
+
* `localHandlers` — e.g. server→client push handlers that share the same channel)
|
|
956
|
+
* on this runtime, and `apply()`. Returns the external handler so the caller can
|
|
957
|
+
* later `clearTransportCache()` it.
|
|
958
|
+
*
|
|
959
|
+
* Sugar over `new ActionExternalClientHandler(...).forDomain(...)` + `addHandlers([...])`,
|
|
960
|
+
* so a single runtime can host one handler per backend target with its transports
|
|
961
|
+
* declared once and reused across every action routed to that backend.
|
|
962
|
+
*/
|
|
963
|
+
connectTo(externalCoordinate: RuntimeCoordinate, options: {
|
|
964
|
+
transports: Transport[];
|
|
965
|
+
domains?: ActionDomain<any>[];
|
|
966
|
+
actions?: ActionCore<any, any>[];
|
|
967
|
+
localHandlers?: TActionRuntimeHandler[];
|
|
968
|
+
defaultTimeout?: number;
|
|
969
|
+
}): ActionExternalClientHandler;
|
|
970
|
+
private applyRuntimeForDomain;
|
|
971
|
+
/**
|
|
972
|
+
* Register this runtime with all root domains covered by its currently-added handlers,
|
|
973
|
+
* making it eligible to execute actions dispatched from those domains.
|
|
974
|
+
* After apply() is called, any subsequent addHandlers() calls also auto-register.
|
|
975
|
+
*/
|
|
976
|
+
apply(): this;
|
|
977
|
+
/**
|
|
978
|
+
* Find the best registered external handler that can reach `originClient` directly.
|
|
979
|
+
* Used to locate the return-path channel for dispatching results back to the action origin.
|
|
980
|
+
* Returns `undefined` if no handler matches (score > 0 required, i.e. at least id must match).
|
|
981
|
+
*/
|
|
982
|
+
getReturnHandlerForOrigin(originClient: RuntimeCoordinate): ActionExternalClientHandler | undefined;
|
|
983
|
+
resetRuntime(): void;
|
|
984
|
+
private _trySetupReturnDispatch;
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
987
|
+
//#region src/ActionDefinition/Domain/ActionDomainBase.d.ts
|
|
988
|
+
declare abstract class ActionDomainBase<ACT_DOM extends IActionDomain = IActionDomain> implements IActionDomain<ACT_DOM["allDomains"], ACT_DOM["actionSchema"]> {
|
|
989
|
+
readonly domain: ACT_DOM["domain"];
|
|
990
|
+
readonly allDomains: ACT_DOM["allDomains"];
|
|
991
|
+
readonly actionSchema: ACT_DOM["actionSchema"];
|
|
992
|
+
protected _listeners: TRunningActionUpdateListener<any, any>[];
|
|
993
|
+
constructor(definition: ACT_DOM);
|
|
994
|
+
/**
|
|
995
|
+
* Add an observer that is called after every action dispatched through this domain.
|
|
996
|
+
* Returns an unsubscribe function — call it to remove the listener.
|
|
997
|
+
*/
|
|
998
|
+
addActionListener(listener: TDistributeRunningActionUpdateListener<ACT_DOM, keyof ACT_DOM["actionSchema"] & string>): () => void;
|
|
999
|
+
/**
|
|
1000
|
+
* @internal
|
|
1001
|
+
* Observers registered directly on this domain via {@link addActionListener}.
|
|
1002
|
+
* Used to wire observers (e.g. devtools) onto RunningActions that aren't created
|
|
1003
|
+
* through the local-dispatch path — notably inbound actions pushed from a backend
|
|
1004
|
+
* or another client over a bidirectional transport.
|
|
1005
|
+
*/
|
|
1006
|
+
_getActionObservers(): TRunningActionUpdateListener<any, any>[];
|
|
1007
|
+
}
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region src/ActionDefinition/Domain/ActionRootDomain.d.ts
|
|
1010
|
+
declare class ActionRootDomain<ROOT_DOM extends IActionRootDomain = IActionRootDomain> extends ActionDomainBase<ROOT_DOM> {
|
|
1011
|
+
readonly domainDefinition: {
|
|
1012
|
+
domain: ROOT_DOM["domain"];
|
|
1013
|
+
};
|
|
1014
|
+
private _actionRuntimeManager;
|
|
1015
|
+
constructor(domainDefinition: {
|
|
1016
|
+
domain: ROOT_DOM["domain"];
|
|
1017
|
+
});
|
|
1018
|
+
createChildDomain<SUB_DOM extends IActionDomainChildOptions>(subDomainDef: SUB_DOM & { [K in Exclude<keyof SUB_DOM, keyof IActionDomainChildOptions>]: never }): ActionDomain<TActionDomainChildDef<ROOT_DOM, SUB_DOM>>;
|
|
1019
|
+
_registerRuntime(runtime: ActionRuntime): void;
|
|
1020
|
+
_hasRuntime(runtime: ActionRuntime): boolean;
|
|
1021
|
+
getRuntime(clientSpecifier: IRuntimeCoordinate): ActionRuntime | undefined;
|
|
1022
|
+
_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>>;
|
|
1023
|
+
}
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/ActionDefinition/Domain/ActionDomain.d.ts
|
|
1026
|
+
type TActionMap<ACT_DOM extends IActionDomain> = { [K in keyof ACT_DOM["actionSchema"] & string]: ActionCore<ACT_DOM, K> };
|
|
1027
|
+
declare class ActionDomain<ACT_DOM extends IActionDomain = IActionDomain> extends ActionDomainBase<ACT_DOM> {
|
|
1028
|
+
private _rootDomain;
|
|
1029
|
+
private readonly _actionMap;
|
|
1030
|
+
constructor(definition: ACT_DOM, {
|
|
1031
|
+
rootDomain
|
|
1032
|
+
}: {
|
|
1033
|
+
rootDomain: ActionRootDomain<any>;
|
|
1034
|
+
});
|
|
1035
|
+
get rootDomain(): ActionRootDomain<any>;
|
|
1036
|
+
/**
|
|
1037
|
+
* @internal
|
|
1038
|
+
* All action observers that should see actions on this domain: the root domain's
|
|
1039
|
+
* observers plus this subdomain's own. Mirrors the listener set the local-dispatch
|
|
1040
|
+
* path assembles in `runAction`/`_runAction`, so inbound actions (pushed from a
|
|
1041
|
+
* backend or another client) can be wired up identically and surface in devtools.
|
|
1042
|
+
*/
|
|
1043
|
+
_collectActionObservers(): TRunningActionUpdateListener<any, any>[];
|
|
1044
|
+
_registerRuntime(runtime: ActionRuntime): void;
|
|
1045
|
+
createChildDomain<SUB_DOM extends IActionDomainChildOptions>(subDomainDef: SUB_DOM & { [K in Exclude<keyof SUB_DOM, keyof IActionDomainChildOptions>]: never }): ActionDomain<TActionDomainChildDef<ACT_DOM, SUB_DOM>>;
|
|
1046
|
+
get action(): TActionMap<ACT_DOM>;
|
|
1047
|
+
actionsMap(): TActionMap<ACT_DOM>;
|
|
1048
|
+
actionForId<ID extends keyof ACT_DOM["actionSchema"] & string>(id: ID): ActionCore<ACT_DOM, ID>;
|
|
1049
|
+
wrapAsPartialLocalHandler(wrappedActionExecutor: Partial<TWrappableDomainActionHandler<ACT_DOM>>): ActionLocalHandler;
|
|
1050
|
+
wrapAsLocalHandler(wrappedActionExecutor: TWrappableDomainActionHandler<ACT_DOM>): ActionLocalHandler;
|
|
1051
|
+
hydrateContext<ID extends keyof ACT_DOM["actionSchema"] & string>(id: ID, contextData: IActionContext_Data_JsonObject): ActionContext<ACT_DOM, ID>;
|
|
1052
|
+
isDomainAction<ACT extends IActionBase<any, ACT_DOM, any>>(action: ACT | unknown | null | undefined): action is TDistributedDomainActions<ACT_DOM, ACT>;
|
|
1053
|
+
hydrateRequestPayload<ID extends keyof ACT_DOM["actionSchema"] & string, P extends IActionPayload_Request_JsonObject<ACT_DOM, ID>>(serialized: P): TDistributeActionPayload_Request<ACT_DOM, ID>;
|
|
1054
|
+
hydrateResultPayload<ID extends keyof ACT_DOM["actionSchema"] & string, R extends IActionPayload_Result_JsonObject<ACT_DOM, ID>>(serialized: R): TDistributeActionPayload_Result<ACT_DOM, ID>;
|
|
1055
|
+
hydrateAnyAction<ID extends keyof ACT_DOM["actionSchema"] & string, AJ extends TAction_Any_JsonObject<ACT_DOM, ID>>(actionJson: AJ): TNarrowActionJsonTypeToActionInstanceType<ACT_DOM, AJ, ID>;
|
|
1056
|
+
runAction<ID extends keyof ACT_DOM["actionSchema"] & string, ACT extends ActionPayload_Request<ACT_DOM, ID>>(request: ACT, options?: IExecuteActionOptions<ACT_DOM, ID>): Promise<RunningAction<ACT_DOM, ID>>;
|
|
1057
|
+
private createActionMap;
|
|
1058
|
+
}
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/ActionDefinition/Action/Core/ActionCore.d.ts
|
|
1061
|
+
declare class ActionCore<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends ActionBase<EActionForm.core, DOM, ID> implements IActionCore<DOM, ID> {
|
|
1062
|
+
readonly _domain: ActionDomain<DOM>;
|
|
1063
|
+
readonly form = EActionForm.core;
|
|
1064
|
+
constructor(_domain: ActionDomain<DOM>, id: ID);
|
|
1065
|
+
is<ACT extends IActionBase<any, any, any>>(action: ACT | unknown | null | undefined): action is TNarrowActionType<DOM, ACT, ID>;
|
|
1066
|
+
toJsonObject(): IActionBase_JsonObject<EActionForm.core, DOM, ID>;
|
|
1067
|
+
request(...args: [TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]] extends [never] ? [input?: never] : [input: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]]): ActionPayload_Request<DOM, ID>;
|
|
1068
|
+
deserializeInput(serialized: TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
1069
|
+
serializeInput(raw: TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"]): TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"];
|
|
1070
|
+
validateInput(input: unknown): TInferInputFromSchema<DOM["actionSchema"][ID]>["Input"];
|
|
1071
|
+
validateOutput(output: unknown): TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"];
|
|
1072
|
+
}
|
|
1073
|
+
//#endregion
|
|
1074
|
+
//#region src/ActionDefinition/Domain/helpers/createRootActionDomain.d.ts
|
|
1075
|
+
declare const createActionRootDomain: <ID extends string>(definition: {
|
|
1076
|
+
domain: ID;
|
|
1077
|
+
}) => ActionRootDomain<IActionRootDomain<ID>>;
|
|
1078
|
+
//#endregion
|
|
1079
|
+
//#region src/ActionRuntime/Handler/ExternalClient/err_nice_external_client.d.ts
|
|
1080
|
+
declare const err_nice_external_client: import("@nice-code/error").NiceErrorDomain<{
|
|
1081
|
+
domain: string;
|
|
1082
|
+
allDomains: [string, string, "err_nice"];
|
|
1083
|
+
schema: {};
|
|
1084
|
+
}>;
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Custom/TransportCustom.types.d.ts
|
|
1087
|
+
interface IActionTransportReadyData_Custom extends IActionTransportReadyData_Base {
|
|
1088
|
+
sendActionData: (input: ITransportMethod_SendActionData_Input) => void;
|
|
1089
|
+
sendReturnData?: TSendReturnDataMethod;
|
|
1090
|
+
closeTransport: (input?: ITransportRouteActionParams) => void;
|
|
1091
|
+
}
|
|
1092
|
+
interface IActionTransportInitialized_Custom extends IActionTransportInitialized<ITransportRouteActionParams, IActionTransportReadyData_Custom> {}
|
|
1093
|
+
interface IActionTransportDef_Custom extends IActionTransportDef<ETransportType.custom, IActionTransportInitialized_Custom> {}
|
|
1094
|
+
type TActionTransportDef_Custom_NoType = Omit<IActionTransportDef_Custom, "type">;
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomConnection.d.ts
|
|
1097
|
+
declare class CustomConnection extends TransportConnection<ETransportType.custom, ITransportRouteActionParams, IActionTransportReadyData_Custom, IActionTransportInitialized_Custom, IActionTransportDef_Custom> {
|
|
1098
|
+
constructor(def: TActionTransportDef_Custom_NoType);
|
|
1099
|
+
protected _finalizeTransportMethods(inputs: IActionTransportReadyData_Custom): IActionTransportReadyData_Methods;
|
|
1100
|
+
}
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Custom/CustomTransport.d.ts
|
|
1103
|
+
interface ICustomTransportSharedOptions {
|
|
1104
|
+
updateRunConfig?: TUpdateActionRunConfig;
|
|
1105
|
+
getTransportCacheKey?: (input: ITransportRouteActionParams) => string[];
|
|
1106
|
+
/** Short label shown in the devtools chip (defaults to "custom"). */
|
|
1107
|
+
label?: string;
|
|
1108
|
+
/** Override the devtools route info for a specific action. */
|
|
1109
|
+
getRouteInfo?: (input: ITransportRouteActionParams) => ITransportRouteInfo;
|
|
1110
|
+
}
|
|
1111
|
+
interface ICustomTransportSendOptions extends ICustomTransportSharedOptions {
|
|
1112
|
+
/** Send a request/progress payload to the external client. */
|
|
1113
|
+
sendActionData: (input: ITransportMethod_SendActionData_Input) => void;
|
|
1114
|
+
/** Optional return-path dispatch for bidirectional channels. */
|
|
1115
|
+
sendReturnData?: TSendReturnDataMethod;
|
|
1116
|
+
closeTransport?: (input?: ITransportRouteActionParams) => void;
|
|
1117
|
+
}
|
|
1118
|
+
interface ICustomTransportAdvancedOptions extends ICustomTransportSharedOptions {
|
|
1119
|
+
/** Full control over readiness/initialization for the custom channel. */
|
|
1120
|
+
getTransport: IActionTransportInitialized_Custom["getTransport"];
|
|
1121
|
+
}
|
|
1122
|
+
type TCustomTransportOptions = (ICustomTransportSendOptions & {
|
|
1123
|
+
mode: "send";
|
|
1124
|
+
}) | (ICustomTransportAdvancedOptions & {
|
|
1125
|
+
mode: "advanced";
|
|
1126
|
+
});
|
|
1127
|
+
/**
|
|
1128
|
+
* Reusable custom transport definition for channels nice-action doesn't model natively. Create one
|
|
1129
|
+
* with `CustomTransport.create({ sendActionData })` for the simple case, or
|
|
1130
|
+
* `CustomTransport.createAdvanced({ getTransport })` for full control over the lifecycle.
|
|
1131
|
+
*/
|
|
1132
|
+
declare class CustomTransport extends Transport<ETransportType.custom> {
|
|
1133
|
+
private readonly options;
|
|
1134
|
+
readonly type = ETransportType.custom;
|
|
1135
|
+
constructor(options: TCustomTransportOptions);
|
|
1136
|
+
static create(options: ICustomTransportSendOptions): CustomTransport;
|
|
1137
|
+
static createAdvanced(options: ICustomTransportAdvancedOptions): CustomTransport;
|
|
1138
|
+
_createConnection(_ctx: ITransportConnectionContext): CustomConnection;
|
|
1139
|
+
getRouteInfo(input: ITransportRouteActionParams): ITransportRouteInfo;
|
|
1140
|
+
}
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport.d.ts
|
|
1143
|
+
declare enum EErrId_NiceTransport {
|
|
1144
|
+
timeout = "timeout",
|
|
1145
|
+
not_found = "not_found",
|
|
1146
|
+
unsupported = "unsupported",
|
|
1147
|
+
initialization_failed = "initialization_failed",
|
|
1148
|
+
send_failed = "send_failed",
|
|
1149
|
+
invalid_action_response = "invalid_action_response"
|
|
1150
|
+
}
|
|
1151
|
+
declare const err_nice_transport: import("@nice-code/error").NiceErrorDomain<{
|
|
1152
|
+
domain: string;
|
|
1153
|
+
allDomains: [string, string, string, "err_nice"];
|
|
1154
|
+
schema: {
|
|
1155
|
+
timeout: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1156
|
+
timeout: number;
|
|
1157
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1158
|
+
not_found: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1159
|
+
actionId: string;
|
|
1160
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1161
|
+
unsupported: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1162
|
+
transportTypes: ETransportType[];
|
|
1163
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1164
|
+
initialization_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1165
|
+
actionId: string;
|
|
1166
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1167
|
+
send_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1168
|
+
actionState: string;
|
|
1169
|
+
actionId: string;
|
|
1170
|
+
httpStatusCode?: number;
|
|
1171
|
+
message?: string;
|
|
1172
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1173
|
+
invalid_action_response: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1174
|
+
actionId: string;
|
|
1175
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1176
|
+
};
|
|
1177
|
+
}>;
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/err_nice_transport_ws.d.ts
|
|
1180
|
+
declare enum EErrId_NiceTransport_WebSocket {
|
|
1181
|
+
ws_disconnected = "ws_disconnected",
|
|
1182
|
+
ws_create_failed = "ws_create_failed",
|
|
1183
|
+
ws_error = "ws_error"
|
|
1184
|
+
}
|
|
1185
|
+
declare const err_nice_transport_ws: import("@nice-code/error").NiceErrorDomain<{
|
|
1186
|
+
domain: string;
|
|
1187
|
+
allDomains: [string, string, string, string, "err_nice"];
|
|
1188
|
+
schema: {
|
|
1189
|
+
ws_disconnected: import("@nice-code/error").INiceErrorIdMetadata<Record<string, never>, import("@nice-code/error").JSONSerializableValue>;
|
|
1190
|
+
ws_create_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1191
|
+
originalError?: Error;
|
|
1192
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1193
|
+
ws_error: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
1194
|
+
originalError?: Error;
|
|
1195
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
1196
|
+
};
|
|
1197
|
+
}>;
|
|
1198
|
+
//#endregion
|
|
1199
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Http/TransportHttp.types.d.ts
|
|
1200
|
+
interface IHttpRequestParams {
|
|
1201
|
+
url: string;
|
|
1202
|
+
headers?: Record<string, string>;
|
|
1203
|
+
body?: string;
|
|
1204
|
+
}
|
|
1205
|
+
interface IActionTransportReadyParams_Http {
|
|
1206
|
+
request: IHttpRequestParams;
|
|
1207
|
+
}
|
|
1208
|
+
interface IActionTransportReadyData_Http extends IActionTransportReadyData_Base {
|
|
1209
|
+
createRequest: (input: ITransportRouteActionParams) => IHttpRequestParams;
|
|
1210
|
+
}
|
|
1211
|
+
interface IActionTransportInitialized_Http extends IActionTransportInitialized<ITransportRouteActionParams, IActionTransportReadyData_Http> {}
|
|
1212
|
+
interface IActionTransportDef_Http extends IActionTransportDef<ETransportType.http, IActionTransportInitialized_Http> {}
|
|
1213
|
+
//#endregion
|
|
1214
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpConnection.d.ts
|
|
1215
|
+
declare class HttpConnection extends TransportConnection<ETransportType.http, ITransportRouteActionParams, IActionTransportReadyData_Http, IActionTransportInitialized_Http, IActionTransportDef_Http> {
|
|
1216
|
+
constructor(def: Omit<IActionTransportDef_Http, "type">);
|
|
1217
|
+
_finalizeTransportMethods(methods: IActionTransportReadyData_Http): IActionTransportReadyData_Methods;
|
|
1218
|
+
protected send(input: ITransportDispatchAction<IActionTransportReadyParams_Http>): Promise<void>;
|
|
1219
|
+
}
|
|
1220
|
+
//#endregion
|
|
1221
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/Http/HttpTransport.d.ts
|
|
1222
|
+
interface IHttpTransportOptions {
|
|
1223
|
+
/**
|
|
1224
|
+
* Build the HTTP request for an action. Return a static request for the simple case, or derive the
|
|
1225
|
+
* url / headers / body from the action params for full control.
|
|
1226
|
+
*/
|
|
1227
|
+
createRequest: (input: ITransportRouteActionParams) => IHttpRequestParams;
|
|
1228
|
+
updateRunConfig?: TUpdateActionRunConfig;
|
|
1229
|
+
getTransportCacheKey?: (input: ITransportRouteActionParams) => string[];
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Reusable HTTP transport definition. Create one with `HttpTransport.create({ createRequest })` — the
|
|
1233
|
+
* single `createRequest` function lets you keep it simple (`() => ({ url })`) or derive the request
|
|
1234
|
+
* per action.
|
|
1235
|
+
*/
|
|
1236
|
+
declare class HttpTransport extends Transport<ETransportType.http> {
|
|
1237
|
+
private readonly options;
|
|
1238
|
+
readonly type = ETransportType.http;
|
|
1239
|
+
constructor(options: IHttpTransportOptions);
|
|
1240
|
+
static create(options: IHttpTransportOptions): HttpTransport;
|
|
1241
|
+
_createConnection(_ctx: ITransportConnectionContext): HttpConnection;
|
|
1242
|
+
getRouteInfo(input: ITransportRouteActionParams): ITransportRouteInfo;
|
|
1243
|
+
}
|
|
1244
|
+
//#endregion
|
|
1245
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/actionFrameCrypto.d.ts
|
|
1246
|
+
/**
|
|
1247
|
+
* Async AES-GCM transform for the `encrypted` security level. It wraps the opaque binary frame a
|
|
1248
|
+
* session codec produces (it does NOT look inside it), encrypting on the way out and decrypting on the
|
|
1249
|
+
* way in with the shared key established by the handshake.
|
|
1250
|
+
*
|
|
1251
|
+
* It is deliberately separate from the (synchronous) session `formatMessage`: WebCrypto is always
|
|
1252
|
+
* Promise-based, so encryption has to happen at the transport's async I/O boundary — the connection
|
|
1253
|
+
* encrypts after `session.outgoing()` and decrypts before `session.incoming()`. The `authenticated`
|
|
1254
|
+
* and `none` levels use no crypto transform at all (frames go out as the session produced them).
|
|
1255
|
+
*
|
|
1256
|
+
* Wire shape of an encrypted frame: `pack([nonceBytes, ciphertextBytes])` — msgpack carries the two
|
|
1257
|
+
* binary fields with a couple of bytes of overhead, no base64 inflation.
|
|
1258
|
+
*/
|
|
1259
|
+
interface IActionFrameCrypto {
|
|
1260
|
+
/** Encrypt one session frame for sending. */
|
|
1261
|
+
encryptFrame(frame: Uint8Array): Promise<Uint8Array>;
|
|
1262
|
+
/** Decrypt one received frame back to the session frame. Throws on a non-binary / malformed /
|
|
1263
|
+
* tampered frame — the caller (transport) decides how to react (drop / close). */
|
|
1264
|
+
decryptFrame(frame: string | ArrayBuffer | Uint8Array): Promise<Uint8Array>;
|
|
1265
|
+
}
|
|
1266
|
+
interface IActionFrameCryptoConfig {
|
|
1267
|
+
link: ClientCryptoKeyLink;
|
|
1268
|
+
/** The handshake-established link id for the remote (key + connection-registry id). */
|
|
1269
|
+
linkedClientId: TTypeAndId;
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Build the encrypt/decrypt transform for a connection whose handshake settled on the `encrypted`
|
|
1273
|
+
* level. Keyed by the link + `linkedClientId`, so it reuses the cached shared AES-GCM key.
|
|
1274
|
+
*/
|
|
1275
|
+
declare function createActionFrameCrypto({
|
|
1276
|
+
link,
|
|
1277
|
+
linkedClientId
|
|
1278
|
+
}: IActionFrameCryptoConfig): IActionFrameCrypto;
|
|
1279
|
+
//#endregion
|
|
1280
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/actionWsHandshake.d.ts
|
|
1281
|
+
/** How much the channel protects after the handshake — chosen by the consumer (perf vs security). */
|
|
1282
|
+
declare enum ESecurityLevel {
|
|
1283
|
+
/** No handshake; identity is self-asserted (fastest, dev / trusted networks). */
|
|
1284
|
+
none = "none",
|
|
1285
|
+
/** Handshake authenticates identity (sign/verify + key pin); frames stay plaintext over TLS. */
|
|
1286
|
+
authenticated = "authenticated",
|
|
1287
|
+
/** Authenticated handshake + every frame AES-GCM encrypted with the derived shared key. */
|
|
1288
|
+
encrypted = "encrypted"
|
|
1289
|
+
}
|
|
1290
|
+
declare enum EHandshakeMessageType {
|
|
1291
|
+
hello = "hello",
|
|
1292
|
+
welcome = "welcome",
|
|
1293
|
+
prove = "prove",
|
|
1294
|
+
accept = "accept",
|
|
1295
|
+
reject = "reject"
|
|
1296
|
+
}
|
|
1297
|
+
declare const vHsHello: v.ObjectSchema<{
|
|
1298
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.hello, undefined>;
|
|
1299
|
+
readonly protocol: v.StringSchema<undefined>;
|
|
1300
|
+
readonly securityLevel: v.PicklistSchema<[ESecurityLevel.none, ESecurityLevel.authenticated, ESecurityLevel.encrypted], undefined>;
|
|
1301
|
+
readonly dictionaryVersion: v.StringSchema<undefined>;
|
|
1302
|
+
readonly client: v.ObjectSchema<{
|
|
1303
|
+
readonly envId: v.StringSchema<undefined>;
|
|
1304
|
+
readonly perId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1305
|
+
readonly insId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1306
|
+
}, undefined>;
|
|
1307
|
+
readonly clientNonce: v.StringSchema<undefined>;
|
|
1308
|
+
readonly verifyPublicKey: v.CustomSchema<`ed25519::raw_base64::${string}`, undefined>;
|
|
1309
|
+
readonly exchangePublicKey: v.OptionalSchema<v.CustomSchema<`x25519::raw_base64::${string}`, undefined>, undefined>;
|
|
1310
|
+
}, undefined>;
|
|
1311
|
+
declare const vHsWelcome: v.ObjectSchema<{
|
|
1312
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.welcome, undefined>;
|
|
1313
|
+
readonly securityLevel: v.PicklistSchema<[ESecurityLevel.none, ESecurityLevel.authenticated, ESecurityLevel.encrypted], undefined>;
|
|
1314
|
+
readonly dictionaryVersion: v.StringSchema<undefined>;
|
|
1315
|
+
readonly server: v.ObjectSchema<{
|
|
1316
|
+
readonly envId: v.StringSchema<undefined>;
|
|
1317
|
+
readonly perId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1318
|
+
readonly insId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1319
|
+
}, undefined>;
|
|
1320
|
+
readonly serverNonce: v.StringSchema<undefined>;
|
|
1321
|
+
readonly verifyPublicKey: v.CustomSchema<`ed25519::raw_base64::${string}`, undefined>;
|
|
1322
|
+
readonly exchangePublicKey: v.OptionalSchema<v.CustomSchema<`x25519::raw_base64::${string}`, undefined>, undefined>;
|
|
1323
|
+
}, undefined>;
|
|
1324
|
+
declare const vHsProve: v.ObjectSchema<{
|
|
1325
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.prove, undefined>;
|
|
1326
|
+
readonly signatureBase64: v.StringSchema<undefined>;
|
|
1327
|
+
}, undefined>;
|
|
1328
|
+
declare const vHsAccept: v.ObjectSchema<{
|
|
1329
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.accept, undefined>;
|
|
1330
|
+
readonly signatureBase64: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1331
|
+
}, undefined>;
|
|
1332
|
+
declare const vHsReject: v.ObjectSchema<{
|
|
1333
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.reject, undefined>;
|
|
1334
|
+
readonly reason: v.StringSchema<undefined>;
|
|
1335
|
+
}, undefined>;
|
|
1336
|
+
declare const vHandshakeMessage: v.VariantSchema<"t", [v.ObjectSchema<{
|
|
1337
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.hello, undefined>;
|
|
1338
|
+
readonly protocol: v.StringSchema<undefined>;
|
|
1339
|
+
readonly securityLevel: v.PicklistSchema<[ESecurityLevel.none, ESecurityLevel.authenticated, ESecurityLevel.encrypted], undefined>;
|
|
1340
|
+
readonly dictionaryVersion: v.StringSchema<undefined>;
|
|
1341
|
+
readonly client: v.ObjectSchema<{
|
|
1342
|
+
readonly envId: v.StringSchema<undefined>;
|
|
1343
|
+
readonly perId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1344
|
+
readonly insId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1345
|
+
}, undefined>;
|
|
1346
|
+
readonly clientNonce: v.StringSchema<undefined>;
|
|
1347
|
+
readonly verifyPublicKey: v.CustomSchema<`ed25519::raw_base64::${string}`, undefined>;
|
|
1348
|
+
readonly exchangePublicKey: v.OptionalSchema<v.CustomSchema<`x25519::raw_base64::${string}`, undefined>, undefined>;
|
|
1349
|
+
}, undefined>, v.ObjectSchema<{
|
|
1350
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.welcome, undefined>;
|
|
1351
|
+
readonly securityLevel: v.PicklistSchema<[ESecurityLevel.none, ESecurityLevel.authenticated, ESecurityLevel.encrypted], undefined>;
|
|
1352
|
+
readonly dictionaryVersion: v.StringSchema<undefined>;
|
|
1353
|
+
readonly server: v.ObjectSchema<{
|
|
1354
|
+
readonly envId: v.StringSchema<undefined>;
|
|
1355
|
+
readonly perId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1356
|
+
readonly insId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1357
|
+
}, undefined>;
|
|
1358
|
+
readonly serverNonce: v.StringSchema<undefined>;
|
|
1359
|
+
readonly verifyPublicKey: v.CustomSchema<`ed25519::raw_base64::${string}`, undefined>;
|
|
1360
|
+
readonly exchangePublicKey: v.OptionalSchema<v.CustomSchema<`x25519::raw_base64::${string}`, undefined>, undefined>;
|
|
1361
|
+
}, undefined>, v.ObjectSchema<{
|
|
1362
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.prove, undefined>;
|
|
1363
|
+
readonly signatureBase64: v.StringSchema<undefined>;
|
|
1364
|
+
}, undefined>, v.ObjectSchema<{
|
|
1365
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.accept, undefined>;
|
|
1366
|
+
readonly signatureBase64: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
1367
|
+
}, undefined>, v.ObjectSchema<{
|
|
1368
|
+
readonly t: v.LiteralSchema<EHandshakeMessageType.reject, undefined>;
|
|
1369
|
+
readonly reason: v.StringSchema<undefined>;
|
|
1370
|
+
}, undefined>], undefined>;
|
|
1371
|
+
type THsHello = v.InferOutput<typeof vHsHello>;
|
|
1372
|
+
type THsWelcome = v.InferOutput<typeof vHsWelcome>;
|
|
1373
|
+
type THsProve = v.InferOutput<typeof vHsProve>;
|
|
1374
|
+
type THsAccept = v.InferOutput<typeof vHsAccept>;
|
|
1375
|
+
type THsReject = v.InferOutput<typeof vHsReject>;
|
|
1376
|
+
type THandshakeMessage = v.InferOutput<typeof vHandshakeMessage>;
|
|
1377
|
+
/** Serialize a handshake message for the wire (handshake frames are JSON — they aren't the hot path). */
|
|
1378
|
+
declare function encodeHandshakeMessage(message: THandshakeMessage): string;
|
|
1379
|
+
/** Parse + structurally validate an incoming handshake frame; `undefined` if it isn't one. */
|
|
1380
|
+
declare function decodeHandshakeMessage(raw: string): THandshakeMessage | undefined;
|
|
1381
|
+
/** Stable link id for a runtime coordinate — the key both the crypto link and the connection use. */
|
|
1382
|
+
declare function runtimeLinkId(coordinate: IRuntimeCoordinate): TTypeAndId;
|
|
1383
|
+
/**
|
|
1384
|
+
* Everything needed to re-derive the shared AES-GCM key for an `encrypted` link after a restart —
|
|
1385
|
+
* the remote's public keys + the HKDF salt/info used at handshake time. The local (server) key pair is
|
|
1386
|
+
* recovered from its own persisted `ClientCryptoKeyLink` storage, so re-linking with this material
|
|
1387
|
+
* yields the identical shared key without a fresh handshake.
|
|
1388
|
+
*/
|
|
1389
|
+
interface IHandshakeEncryptionKeyMaterial {
|
|
1390
|
+
verifyPublicKey: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
1391
|
+
exchangePublicKey: TSerializedCryptoKeyData_X25519_Raw;
|
|
1392
|
+
saltString: string;
|
|
1393
|
+
infoString: string;
|
|
1394
|
+
bindVerifyKeysIntoDerivation: boolean;
|
|
1395
|
+
}
|
|
1396
|
+
/** Outcome of a completed handshake — what the transport/handler needs to wire the channel. */
|
|
1397
|
+
interface IHandshakeResult {
|
|
1398
|
+
/** The crypto-link id (and connection-registry key) for the authenticated remote. */
|
|
1399
|
+
linkedClientId: TTypeAndId;
|
|
1400
|
+
/** The remote's authenticated coordinate. */
|
|
1401
|
+
remote: IRuntimeCoordinate;
|
|
1402
|
+
securityLevel: ESecurityLevel;
|
|
1403
|
+
/** For the `encrypted` level: material to restore the shared key after eviction (persist it). */
|
|
1404
|
+
encryptionKeyMaterial?: IHandshakeEncryptionKeyMaterial;
|
|
1405
|
+
}
|
|
1406
|
+
interface IClientVerifyKeyResolveInput {
|
|
1407
|
+
client: IRuntimeCoordinate;
|
|
1408
|
+
verifyPublicKey: TSerializedCryptoKeyData_Ed25519_Raw;
|
|
1409
|
+
}
|
|
1410
|
+
interface IClientVerifyKeyResolver {
|
|
1411
|
+
/**
|
|
1412
|
+
* Decide whether a presented verify key is trusted for a client identity. The signature is already
|
|
1413
|
+
* verified by the time this runs, so this is purely the identity-pinning decision. Swap in a
|
|
1414
|
+
* persistent / pre-provisioned implementation without touching the protocol.
|
|
1415
|
+
*/
|
|
1416
|
+
resolve(input: IClientVerifyKeyResolveInput): Promise<{
|
|
1417
|
+
trusted: boolean;
|
|
1418
|
+
reason?: string;
|
|
1419
|
+
}>;
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* In-memory trust-on-first-use resolver: trusts (and pins) the first verify key seen for a client
|
|
1423
|
+
* identity, then rejects a different key for that identity. The default; replace with a storage-backed
|
|
1424
|
+
* resolver for cross-restart pinning (see Step 5).
|
|
1425
|
+
*/
|
|
1426
|
+
declare function createInMemoryTofuVerifyKeyResolver(): IClientVerifyKeyResolver;
|
|
1427
|
+
/**
|
|
1428
|
+
* Storage-backed trust-on-first-use resolver: pins survive process restarts / Durable Object eviction
|
|
1429
|
+
* (e.g. back it with `createDurableObjectStorageAdapter`). Same policy as the in-memory variant — trust
|
|
1430
|
+
* + pin the first verify key per client identity, reject a different one thereafter.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function createStorageTofuVerifyKeyResolver(storageAdapter: StorageAdapter): IClientVerifyKeyResolver;
|
|
1433
|
+
interface IClientHandshakeConfig {
|
|
1434
|
+
link: ClientCryptoKeyLink;
|
|
1435
|
+
localCoordinate: IRuntimeCoordinate;
|
|
1436
|
+
dictionaryVersion: string;
|
|
1437
|
+
securityLevel: ESecurityLevel;
|
|
1438
|
+
}
|
|
1439
|
+
declare function createClientHandshake(config: IClientHandshakeConfig): {
|
|
1440
|
+
createHello(): Promise<THsHello>;
|
|
1441
|
+
onWelcome(welcome: THsWelcome): Promise<THsProve>;
|
|
1442
|
+
onAccept(accept: THsAccept): Promise<IHandshakeResult>;
|
|
1443
|
+
};
|
|
1444
|
+
interface IServerHandshakeConfig {
|
|
1445
|
+
link: ClientCryptoKeyLink;
|
|
1446
|
+
localCoordinate: IRuntimeCoordinate;
|
|
1447
|
+
dictionaryVersion: string;
|
|
1448
|
+
/**
|
|
1449
|
+
* The level(s) this server accepts. A single level is strict (the client must match). An array is a
|
|
1450
|
+
* negotiable allowed set — the server adopts whichever level the client requests, as long as it's in
|
|
1451
|
+
* the set (lets one backend serve `authenticated` and `encrypted` clients at once). `none` in the set
|
|
1452
|
+
* is handled by the transport/handler (a `none` client never reaches the handshake).
|
|
1453
|
+
*/
|
|
1454
|
+
securityLevel: ESecurityLevel | readonly ESecurityLevel[];
|
|
1455
|
+
/** Trust decision for a client's verify key. Defaults to in-memory TOFU. */
|
|
1456
|
+
verifyKeyResolver?: IClientVerifyKeyResolver;
|
|
1457
|
+
}
|
|
1458
|
+
declare function createServerHandshake(config: IServerHandshakeConfig): {
|
|
1459
|
+
onHello(hello: THsHello): Promise<THsWelcome | THsReject>;
|
|
1460
|
+
onProve(prove: THsProve): Promise<THsAccept | THsReject>; /** The completed handshake result once `onProve` has accepted, else `undefined`. */
|
|
1461
|
+
getResult(): IHandshakeResult | undefined;
|
|
1462
|
+
};
|
|
1463
|
+
//#endregion
|
|
1464
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/TransportWebSocket.types.d.ts
|
|
1465
|
+
/**
|
|
1466
|
+
* Client-side secure-channel config for a WebSocket. When present (and `securityLevel !== none`), the
|
|
1467
|
+
* connection runs the {@link createClientHandshake} handshake during initialization — authenticating
|
|
1468
|
+
* the identity and, for the `encrypted` level, deriving a shared key that encrypts every action frame.
|
|
1469
|
+
*/
|
|
1470
|
+
interface IWsClientSecureChannel {
|
|
1471
|
+
securityLevel: ESecurityLevel;
|
|
1472
|
+
/** This client's crypto identity (verify + exchange key pairs, optionally persisted). */
|
|
1473
|
+
link: ClientCryptoKeyLink;
|
|
1474
|
+
/** This client's runtime coordinate — its authenticated identity to the server. */
|
|
1475
|
+
localCoordinate: IRuntimeCoordinate;
|
|
1476
|
+
/** Wire dictionary version; the server rejects the handshake on a mismatch. */
|
|
1477
|
+
dictionaryVersion: string;
|
|
1478
|
+
}
|
|
1479
|
+
interface IActionTransportReadyData_Ws extends IActionTransportReadyData_Base {
|
|
1480
|
+
formatMessage?: {
|
|
1481
|
+
/**
|
|
1482
|
+
* Pack an outgoing action payload. Return a `string` for text frames (JSON) or a binary
|
|
1483
|
+
* `Uint8Array`/`ArrayBuffer` for optimized binary frames (e.g. msgpackr).
|
|
1484
|
+
*/
|
|
1485
|
+
outgoing: (input: ITransportRouteActionParams) => string | Uint8Array | ArrayBuffer;
|
|
1486
|
+
/**
|
|
1487
|
+
* Unpack an incoming frame back into the wire JSON object the runtime hydrates + validates.
|
|
1488
|
+
* Return `undefined` to defer to the connection's built-in JSON parser — this is how binary
|
|
1489
|
+
* adapters stay backward compatible with plain-JSON clients on the same socket.
|
|
1490
|
+
*/
|
|
1491
|
+
incoming?: (input: string | ArrayBuffer | Uint8Array | Blob) => TActionPayload_Any_JsonObject<any, any> | undefined;
|
|
1492
|
+
};
|
|
1493
|
+
ws: WebSocket;
|
|
1494
|
+
/** Optional authenticated/encrypted channel; the connection runs the handshake during init. */
|
|
1495
|
+
secureChannel?: IWsClientSecureChannel;
|
|
1496
|
+
}
|
|
1497
|
+
interface IActionTransportInitialized_Ws extends IActionTransportInitialized<ITransportRouteActionParams, IActionTransportReadyData_Ws> {}
|
|
1498
|
+
interface IActionTransportDef_Ws extends IActionTransportDef<ETransportType.ws, IActionTransportInitialized_Ws> {}
|
|
1499
|
+
//#endregion
|
|
1500
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/createBinaryWsAdapter.d.ts
|
|
1501
|
+
/**
|
|
1502
|
+
* Builds a *stateless* `formatMessage` pipeline for {@link WebSocketTransport}, packing action
|
|
1503
|
+
* payloads into a compact msgpackr binary frame instead of JSON. The `domain`/`id` route collapses to
|
|
1504
|
+
* a single integer drawn from a shared dictionary; `form`/`type`, the recomputable
|
|
1505
|
+
* `inputHash`/`outputHash`, and the per-frame `context.routing`/`context.timeCreated` are all dropped
|
|
1506
|
+
* (see {@link ENVELOPE}).
|
|
1507
|
+
*
|
|
1508
|
+
* No validation runs here: `incoming` blindly reconstructs the wire JSON shape and hands it back to
|
|
1509
|
+
* the connection, which flows into `ActionRuntime` → `domain.hydrateAnyAction()` where the Valibot
|
|
1510
|
+
* schemas validate it exactly as they would for a JSON frame.
|
|
1511
|
+
*
|
|
1512
|
+
* Both ends of the socket MUST construct the adapter with the same domains in the same order — the
|
|
1513
|
+
* integer dictionary is positional. Mismatched dictionaries will route to the wrong action.
|
|
1514
|
+
*
|
|
1515
|
+
* Because `incoming` returns `undefined` for text frames, a binary server can still serve plain-JSON
|
|
1516
|
+
* clients on the same runtime (the connection falls back to its built-in JSON parser).
|
|
1517
|
+
*/
|
|
1518
|
+
declare function createBinaryWsAdapter(domains: ActionDomain<any>[]): NonNullable<IActionTransportReadyData_Ws["formatMessage"]>;
|
|
1519
|
+
//#endregion
|
|
1520
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/createBinaryWsSessionFactory.d.ts
|
|
1521
|
+
type TFormatMessage = NonNullable<IActionTransportReadyData_Ws["formatMessage"]>;
|
|
1522
|
+
interface IBinaryWsSessionOptions {
|
|
1523
|
+
/** Override how long an unresolved correlation is retained before being swept (ms). */
|
|
1524
|
+
correlationTtlMs?: number;
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Builds a factory of *stateful, per-connection* codecs for {@link WebSocketTransport} /
|
|
1528
|
+
* `ActionServerHandler` — the maximally compact binary wire. Call the returned factory once per live
|
|
1529
|
+
* connection (each socket on the client, each accepted connection on the server) so every channel
|
|
1530
|
+
* gets its own correlation + identity state.
|
|
1531
|
+
*
|
|
1532
|
+
* On top of everything {@link createBinaryWsAdapter} drops, a session also drops:
|
|
1533
|
+
* - **`cuid`** — replaced by a per-connection integer correlation id. The initiator maps it to its
|
|
1534
|
+
* real cuid; the responder echoes it; each side reconstructs the cuid from its own map. Correlation
|
|
1535
|
+
* only needs to be unique per socket, so a counter suffices.
|
|
1536
|
+
* - **`originClient` after the first request** — the first request each side sends carries its
|
|
1537
|
+
* identity; the peer remembers it and injects it into later frames. Replies omit it entirely (a
|
|
1538
|
+
* reply carries the initiator's own origin, which the initiator already knows).
|
|
1539
|
+
*
|
|
1540
|
+
* Both ends MUST build the factory from the same domains in the same order (positional dictionary).
|
|
1541
|
+
* Text frames still return `undefined` from `incoming`, so JSON clients remain interoperable.
|
|
1542
|
+
*
|
|
1543
|
+
* Hibernation note: after a server connection is evicted its session resets, so a still-connected
|
|
1544
|
+
* client (whose session persists) will keep omitting `originClient`. The server must therefore restore
|
|
1545
|
+
* the connection→client binding from its own store (see `ActionServerHandler.rehydrateConnection`) and
|
|
1546
|
+
* inject `originClient` from there — the session alone can't recover it.
|
|
1547
|
+
*/
|
|
1548
|
+
declare function createBinaryWsSessionFactory(domains: ActionDomain<any>[], options?: IBinaryWsSessionOptions): () => TFormatMessage;
|
|
1549
|
+
//#endregion
|
|
1550
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketConnection.d.ts
|
|
1551
|
+
declare class WebSocketConnection extends TransportConnection<ETransportType.ws, ITransportRouteActionParams, IActionTransportReadyData_Ws, IActionTransportInitialized_Ws, IActionTransportDef_Ws> {
|
|
1552
|
+
private resolvers;
|
|
1553
|
+
/** URL of the most recently resolved live socket — surfaced to devtools when the definition can't. */
|
|
1554
|
+
private _liveSocketUrl?;
|
|
1555
|
+
/** Sockets we closed on purpose (via `disconnect`), so their `close` event stays quiet. */
|
|
1556
|
+
private _intentionalCloses;
|
|
1557
|
+
constructor(def: Omit<IActionTransportDef_Ws, "type">, resolvers?: IActionTransportResolvers);
|
|
1558
|
+
protected _getCacheKey(_input: ITransportRouteActionParams): string;
|
|
1559
|
+
protected _processTransportStatus(input: ITransportRouteActionParams): TTransportStatusInfo<IActionTransportReadyData_Methods>;
|
|
1560
|
+
getRouteInfo(input: ITransportRouteActionParams): ITransportRouteInfo | undefined;
|
|
1561
|
+
private _isSecure;
|
|
1562
|
+
private _awaitOpen;
|
|
1563
|
+
/** Non-secure connections finalize synchronously; secure ones run the handshake first. */
|
|
1564
|
+
private _finalize;
|
|
1565
|
+
_finalizeTransportMethods(wsData: IActionTransportReadyData_Ws): IActionTransportReadyData_Methods;
|
|
1566
|
+
/**
|
|
1567
|
+
* Secure path: a single message listener feeds the handshake until it completes, then routes action
|
|
1568
|
+
* frames (decrypting for the `encrypted` level). Frames that arrive in the gap between accept and
|
|
1569
|
+
* activation are buffered and flushed, so nothing is lost.
|
|
1570
|
+
*/
|
|
1571
|
+
private _finalizeSecureMethods;
|
|
1572
|
+
private _runClientHandshake;
|
|
1573
|
+
private _buildSendMethods;
|
|
1574
|
+
/** Decode (and, when encrypted, decrypt) one inbound action frame and hand it to the runtime. */
|
|
1575
|
+
private _handleIncomingActionFrame;
|
|
1576
|
+
/** Accept text + binary frames (ArrayBuffer / Uint8Array / Blob); Blobs are converted to a buffer. */
|
|
1577
|
+
private _normalizeFrame;
|
|
1578
|
+
private _captureSocketUrl;
|
|
1579
|
+
private _attachLifecycle;
|
|
1580
|
+
private _abortAll;
|
|
1581
|
+
}
|
|
1582
|
+
//#endregion
|
|
1583
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/WebSocketTransport.d.ts
|
|
1584
|
+
interface IWebSocketTransportSharedOptions {
|
|
1585
|
+
/** Custom (de)serialization of action payloads on the wire (shared across all sockets). */
|
|
1586
|
+
formatMessage?: IActionTransportReadyData_Ws["formatMessage"];
|
|
1587
|
+
/**
|
|
1588
|
+
* Per-socket codec factory — called once for each socket so stateful codecs (e.g. the
|
|
1589
|
+
* `createBinaryWsSessionFactory` session, which holds per-connection correlation + identity state)
|
|
1590
|
+
* get their own instance and reset cleanly on reconnect. Takes precedence over `formatMessage`.
|
|
1591
|
+
*/
|
|
1592
|
+
createFormatMessage?: () => IActionTransportReadyData_Ws["formatMessage"];
|
|
1593
|
+
updateRunConfig?: TUpdateActionRunConfig;
|
|
1594
|
+
/**
|
|
1595
|
+
* Keys that identify a reusable socket, so a single socket is shared across actions to the same
|
|
1596
|
+
* endpoint instead of opening one per action.
|
|
1597
|
+
*/
|
|
1598
|
+
getTransportCacheKey?: (input: ITransportRouteActionParams) => string[];
|
|
1599
|
+
/** Override the devtools route info for a specific action. */
|
|
1600
|
+
getRouteInfo?: (input: ITransportRouteActionParams) => ITransportRouteInfo;
|
|
1601
|
+
/**
|
|
1602
|
+
* Secure-channel config. When set (and `securityLevel !== none`), the connection runs the
|
|
1603
|
+
* authenticated handshake during initialization and, at the `encrypted` level, encrypts every frame.
|
|
1604
|
+
*/
|
|
1605
|
+
security?: IActionTransportReadyData_Ws["secureChannel"];
|
|
1606
|
+
}
|
|
1607
|
+
interface IWebSocketTransportSocketOptions extends IWebSocketTransportSharedOptions {
|
|
1608
|
+
/** Open (or reuse) the WebSocket for an action — keep it simple or derive it per action. */
|
|
1609
|
+
createWebSocket: (input: ITransportRouteActionParams) => WebSocket;
|
|
1610
|
+
}
|
|
1611
|
+
interface IWebSocketTransportAdvancedOptions extends IWebSocketTransportSharedOptions {
|
|
1612
|
+
/**
|
|
1613
|
+
* Full control over readiness/initialization. Use this for contextual support detection (return
|
|
1614
|
+
* `{ status: ETransportStatus.unsupported }` when the socket shouldn't be used) or async url
|
|
1615
|
+
* building (return `{ status: ETransportStatus.initializing, initializationPromise }` that resolves
|
|
1616
|
+
* to a `ready` socket).
|
|
1617
|
+
*/
|
|
1618
|
+
getTransport: IActionTransportInitialized_Ws["getTransport"];
|
|
1619
|
+
}
|
|
1620
|
+
type TWebSocketTransportOptions = (IWebSocketTransportSocketOptions & {
|
|
1621
|
+
mode: "socket";
|
|
1622
|
+
}) | (IWebSocketTransportAdvancedOptions & {
|
|
1623
|
+
mode: "advanced";
|
|
1624
|
+
});
|
|
1625
|
+
/**
|
|
1626
|
+
* Reusable WebSocket transport definition. Create one with `WebSocketTransport.create({ createWebSocket })`
|
|
1627
|
+
* for the common case, or `WebSocketTransport.createAdvanced({ getTransport })` for full control over
|
|
1628
|
+
* readiness. The underlying socket is cached (via `getTransportCacheKey`) and reused across actions.
|
|
1629
|
+
*/
|
|
1630
|
+
declare class WebSocketTransport extends Transport<ETransportType.ws> {
|
|
1631
|
+
private readonly options;
|
|
1632
|
+
readonly type = ETransportType.ws;
|
|
1633
|
+
constructor(options: TWebSocketTransportOptions);
|
|
1634
|
+
static create(options: IWebSocketTransportSocketOptions): WebSocketTransport;
|
|
1635
|
+
static createAdvanced(options: IWebSocketTransportAdvancedOptions): WebSocketTransport;
|
|
1636
|
+
_createConnection(ctx: ITransportConnectionContext): WebSocketConnection;
|
|
1637
|
+
getRouteInfo(input: ITransportRouteActionParams): ITransportRouteInfo;
|
|
1638
|
+
}
|
|
1639
|
+
//#endregion
|
|
1640
|
+
//#region src/ActionRuntime/Handler/ExternalClient/Transport/WebSocket/secureWsChannel.d.ts
|
|
1641
|
+
/** The per-connection binary session codec — built once per socket from the channel's domains. */
|
|
1642
|
+
type TChannelCodec = NonNullable<IActionTransportReadyData_Ws["formatMessage"]>;
|
|
1643
|
+
/**
|
|
1644
|
+
* The shared identity of a secure WebSocket channel: the wire dictionary version both ends check
|
|
1645
|
+
* during the handshake, plus the per-connection codec factory both ends build from the *same* domain
|
|
1646
|
+
* list. Define it once (typically in code shared by client and server) and hand it to
|
|
1647
|
+
* {@link createSecureWebSocketTransport} on the client and `createSecureActionServerHandler` on the
|
|
1648
|
+
* server, so the codec and version can never drift apart.
|
|
1649
|
+
*/
|
|
1650
|
+
interface ISecureWsChannel {
|
|
1651
|
+
/** Wire dictionary version — derived from the domains by default; the handshake rejects a mismatch. */
|
|
1652
|
+
dictionaryVersion: string;
|
|
1653
|
+
/** Per-connection session codec factory (call once per live connection). */
|
|
1654
|
+
createCodec: () => TChannelCodec;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Bundle a secure channel's shared identity from its transported domains. Both ends MUST call this
|
|
1658
|
+
* with the same domains in the same order (the binary wire dictionary is positional). The
|
|
1659
|
+
* `dictionaryVersion` is derived from those domains unless you pin an explicit one.
|
|
1660
|
+
*/
|
|
1661
|
+
declare function defineSecureWsChannel(options: {
|
|
1662
|
+
/** Domains transported over this channel, in a stable order. Add new ones to the *end*. */domains: ActionDomain<any>[]; /** Pin a human-readable version instead of the derived hash (must match on both ends). */
|
|
1663
|
+
dictionaryVersion?: string; /** Tuning for the per-connection binary session (e.g. correlation TTL). */
|
|
1664
|
+
sessionOptions?: IBinaryWsSessionOptions;
|
|
1665
|
+
}): ISecureWsChannel;
|
|
1666
|
+
interface ISecureWebSocketTransportOptions {
|
|
1667
|
+
/** The shared channel identity (codec + dictionary version). */
|
|
1668
|
+
channel: ISecureWsChannel;
|
|
1669
|
+
/** This client's runtime — its coordinate is the authenticated identity sent in the handshake. */
|
|
1670
|
+
runtime: ActionRuntime;
|
|
1671
|
+
/** Backing store for this client's crypto identity (a stable verify key across reloads). */
|
|
1672
|
+
storageAdapter: StorageAdapter;
|
|
1673
|
+
/** The level this client requests; the server must allow it. */
|
|
1674
|
+
securityLevel: ESecurityLevel;
|
|
1675
|
+
/** Endpoint URL — drives both the socket and the per-endpoint cache key. */
|
|
1676
|
+
url: string;
|
|
1677
|
+
/** Override socket creation (defaults to a `new WebSocket(url)` with `binaryType = "arraybuffer"`). */
|
|
1678
|
+
createWebSocket?: (input: ITransportRouteActionParams) => WebSocket;
|
|
1679
|
+
/** Override the reuse key (defaults to `[url]`, so one socket is shared per endpoint). */
|
|
1680
|
+
getTransportCacheKey?: (input: ITransportRouteActionParams) => string[];
|
|
1681
|
+
updateRunConfig?: TUpdateActionRunConfig;
|
|
1682
|
+
getRouteInfo?: (input: ITransportRouteActionParams) => ITransportRouteInfo;
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Build a {@link WebSocketTransport} for the secure binary channel with the boilerplate folded in: it
|
|
1686
|
+
* creates the {@link ClientCryptoKeyLink} from `storageAdapter`, opens an `arraybuffer` socket to
|
|
1687
|
+
* `url`, caches it per endpoint, installs the channel's per-connection codec, and assembles the
|
|
1688
|
+
* `security` block from the runtime coordinate + channel version. Pass `createWebSocket` /
|
|
1689
|
+
* `getTransportCacheKey` to take over those bits when you need to.
|
|
1690
|
+
*/
|
|
1691
|
+
declare function createSecureWebSocketTransport(options: ISecureWebSocketTransportOptions): WebSocketTransport;
|
|
1692
|
+
//#endregion
|
|
1693
|
+
//#region src/ActionRuntime/Handler/Server/WsConnectionStateStore.d.ts
|
|
1694
|
+
/**
|
|
1695
|
+
* The composite value persisted to a connection's attachment: the consumer's own app state plus the
|
|
1696
|
+
* {@link ActionServerHandler} routing binding. Co-storing them in one slot means a transport whose
|
|
1697
|
+
* sockets outlive process eviction (e.g. a Durable Object's hibernatable WebSocket) recovers both the
|
|
1698
|
+
* application identity *and* the action routing from a single attachment after a wake — no storage reads.
|
|
1699
|
+
*/
|
|
1700
|
+
interface IConnectionAttachment<TApp> {
|
|
1701
|
+
app?: TApp;
|
|
1702
|
+
binding?: IActionServerConnectionBinding;
|
|
1703
|
+
}
|
|
1704
|
+
interface IWsConnectionStateStoreOptions<TConn, TApp> {
|
|
1705
|
+
/** Read a connection's raw attachment (e.g. `(ws) => ws.deserializeAttachment()`). */
|
|
1706
|
+
read: (connection: TConn) => unknown;
|
|
1707
|
+
/** Persist a connection's attachment (e.g. `(ws, value) => ws.serializeAttachment(value)`). */
|
|
1708
|
+
write: (connection: TConn, value: IConnectionAttachment<TApp>) => void;
|
|
1709
|
+
/**
|
|
1710
|
+
* All currently-live connections (e.g. `() => ctx.getWebSockets()`). Used to replay routing bindings
|
|
1711
|
+
* after a wake (via {@link ActionServerHandler.createConnectionState}) and to enumerate app state in
|
|
1712
|
+
* {@link WsConnectionStateStore.entries}.
|
|
1713
|
+
*/
|
|
1714
|
+
getConnections: () => TConn[];
|
|
1715
|
+
/**
|
|
1716
|
+
* Optional Standard Schema (valibot, zod, …) validating the *app* portion on read. A value that
|
|
1717
|
+
* fails validation reads back as `null` — the same lenient behavior as a hand-written safeParse
|
|
1718
|
+
* helper. The binding is the library's own shape and is never validated.
|
|
1719
|
+
*/
|
|
1720
|
+
schema?: StandardSchemaV1<unknown, TApp>;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* A typed per-connection state store that co-owns the app state and the server handler's routing
|
|
1724
|
+
* binding in one attachment, so neither the consumer nor the handler has to hand-merge the two. Create
|
|
1725
|
+
* it through {@link ActionServerHandler.createConnectionState} (which also wires binding persistence and
|
|
1726
|
+
* replays surviving connections after a wake), then `get`/`set`/`clearApp` the app state directly.
|
|
1727
|
+
*
|
|
1728
|
+
* ```ts
|
|
1729
|
+
* const players = serverHandler.createConnectionState({
|
|
1730
|
+
* schema: vs_player,
|
|
1731
|
+
* read: (ws) => ws.deserializeAttachment(),
|
|
1732
|
+
* write: (ws, v) => ws.serializeAttachment(v),
|
|
1733
|
+
* getConnections: () => ctx.getWebSockets(),
|
|
1734
|
+
* });
|
|
1735
|
+
* players.set(ws, player); // binding is preserved automatically
|
|
1736
|
+
* const player = players.get(ws);
|
|
1737
|
+
* ```
|
|
1738
|
+
*/
|
|
1739
|
+
declare class WsConnectionStateStore<TConn, TApp> {
|
|
1740
|
+
private readonly options;
|
|
1741
|
+
constructor(options: IWsConnectionStateStoreOptions<TConn, TApp>);
|
|
1742
|
+
/** The validated app state for a connection, or `null` if unset / invalid. */
|
|
1743
|
+
get(connection: TConn): TApp | null;
|
|
1744
|
+
/** Set the app state, preserving the runtime binding already pinned to the connection. */
|
|
1745
|
+
set(connection: TConn, app: TApp): void;
|
|
1746
|
+
/** Clear the app state but keep the binding (e.g. a spectator that stopped watching). */
|
|
1747
|
+
clearApp(connection: TConn): void;
|
|
1748
|
+
/** Every live connection paired with its (validated) app state — for rebuilding in-memory state after a wake. */
|
|
1749
|
+
entries(): [TConn, TApp | null][];
|
|
1750
|
+
/** @internal Persist a freshly-bound connection's binding, preserving any app state already stored. */
|
|
1751
|
+
_persistBinding(connection: TConn, binding: IActionServerConnectionBinding): void;
|
|
1752
|
+
/** @internal The persisted binding for a connection, if any (used to replay routing after a wake). */
|
|
1753
|
+
_readBinding(connection: TConn): IActionServerConnectionBinding | undefined;
|
|
1754
|
+
private _readAttachment;
|
|
1755
|
+
private _validateApp;
|
|
1756
|
+
}
|
|
1757
|
+
//#endregion
|
|
1758
|
+
//#region src/ActionRuntime/Handler/Server/ActionServerHandler.d.ts
|
|
1759
|
+
/** The codec shape `ActionServerHandler` uses to pack/unpack frames — same as the WS transport's. */
|
|
1760
|
+
type TActionChannelFormatMessage = NonNullable<IActionTransportReadyData_Ws["formatMessage"]>;
|
|
1761
|
+
/** How a connection encodes its frames, remembered so we answer each client in its own dialect. */
|
|
1762
|
+
type TActionConnectionEncoding = "json" | "binary";
|
|
1763
|
+
/** A connection's restorable identity — what to persist so a binding survives transport eviction. */
|
|
1764
|
+
interface IActionServerConnectionBinding {
|
|
1765
|
+
/** Full client coordinate, so `originClient` can be re-injected into frames that omit it. */
|
|
1766
|
+
client: IRuntimeCoordinate;
|
|
1767
|
+
encoding: TActionConnectionEncoding;
|
|
1768
|
+
/**
|
|
1769
|
+
* Secure-session state (set once a connection's handshake completes). Persist it alongside the
|
|
1770
|
+
* binding so an authenticated/encrypted connection resumes after eviction without re-handshaking —
|
|
1771
|
+
* the `keyMaterial` lets the server re-derive the shared key from its own persisted identity.
|
|
1772
|
+
*/
|
|
1773
|
+
secure?: {
|
|
1774
|
+
securityLevel: ESecurityLevel;
|
|
1775
|
+
linkedClientId: TTypeAndId;
|
|
1776
|
+
keyMaterial?: IHandshakeEncryptionKeyMaterial;
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Server-side secure-channel config. When set, each connection negotiates a level from
|
|
1781
|
+
* {@link securityLevel}: an `authenticated`/`encrypted` client must complete the handshake (and is then
|
|
1782
|
+
* bound to its *authenticated* coordinate) before any action frame is accepted. A `none` client (only
|
|
1783
|
+
* when `none` is in the allowed set) is accepted as-is with a self-asserted identity. For the
|
|
1784
|
+
* `encrypted` level the codec source should be a session factory (`createFormatMessage`).
|
|
1785
|
+
*/
|
|
1786
|
+
interface IActionServerSecurity {
|
|
1787
|
+
/**
|
|
1788
|
+
* Accepted level(s). A single level is strict; an array is a negotiable allowed set — the server
|
|
1789
|
+
* adopts whichever level each client requests (e.g. `[none, authenticated, encrypted]` serves all
|
|
1790
|
+
* three over one endpoint).
|
|
1791
|
+
*/
|
|
1792
|
+
securityLevel: ESecurityLevel | readonly ESecurityLevel[];
|
|
1793
|
+
/** This server's crypto identity (verify + exchange key pairs, optionally persisted). */
|
|
1794
|
+
link: ClientCryptoKeyLink;
|
|
1795
|
+
/** This server's coordinate — its identity to clients during the handshake. */
|
|
1796
|
+
localCoordinate: IRuntimeCoordinate;
|
|
1797
|
+
/** Wire dictionary version; the handshake rejects a client on a mismatch. */
|
|
1798
|
+
dictionaryVersion: string;
|
|
1799
|
+
/** Trust decision for a client's verify key (defaults to in-memory TOFU inside the handshake). */
|
|
1800
|
+
verifyKeyResolver?: IClientVerifyKeyResolver;
|
|
1801
|
+
}
|
|
1802
|
+
interface IActionServerHandlerBaseOptions<TConn> {
|
|
1803
|
+
/**
|
|
1804
|
+
* Coordinate of the *connecting clients* (typically env-only, e.g. `RuntimeCoordinate.env("web_app")`).
|
|
1805
|
+
* The runtime's return-path dispatch scores incoming actions' `originClient` against this to pick
|
|
1806
|
+
* this handler for sending results/pushes back over the right channel.
|
|
1807
|
+
*/
|
|
1808
|
+
clientEnv: RuntimeCoordinate;
|
|
1809
|
+
/** Write an encoded frame to a specific live connection (e.g. `(ws, frame) => ws.send(frame)`). */
|
|
1810
|
+
send: (connection: TConn, frame: string | Uint8Array | ArrayBuffer) => void;
|
|
1811
|
+
/**
|
|
1812
|
+
* The runtime this handler belongs to. When set, {@link ActionServerHandler.broadcast} can be called
|
|
1813
|
+
* without threading a runtime through each call. Optional — `pushToClient` still takes one explicitly.
|
|
1814
|
+
*/
|
|
1815
|
+
runtime?: ActionRuntime;
|
|
1816
|
+
/** Timeout (ms) applied to server-initiated actions awaiting a client response. */
|
|
1817
|
+
defaultTimeout?: number;
|
|
1818
|
+
/**
|
|
1819
|
+
* Called once when a connection is first bound to a client identity. Use it to persist the binding
|
|
1820
|
+
* for transports that can resume after eviction — e.g. a Durable Object's hibernatable WebSocket:
|
|
1821
|
+
* `(ws, binding) => ws.serializeAttachment(binding)` — then replay it via {@link ActionServerHandler.rehydrateConnection}
|
|
1822
|
+
* when the channel comes back.
|
|
1823
|
+
*/
|
|
1824
|
+
onConnectionBound?: (connection: TConn, binding: IActionServerConnectionBinding) => void;
|
|
1825
|
+
/**
|
|
1826
|
+
* Enable the authenticated (optionally encrypted) handshake. When omitted, connections are trusted
|
|
1827
|
+
* as-is (identity self-asserted) — fine for dev / trusted networks.
|
|
1828
|
+
*/
|
|
1829
|
+
security?: IActionServerSecurity;
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Provide exactly one codec source:
|
|
1833
|
+
* - `formatMessage` — a single shared codec for every connection (stateless, e.g. `createBinaryWsAdapter`).
|
|
1834
|
+
* - `createFormatMessage` — a per-connection factory for stateful codecs (e.g.
|
|
1835
|
+
* `createBinaryWsSessionFactory`, whose sessions hold correlation + identity state). Required for the
|
|
1836
|
+
* leanest binary wire; the handler creates and caches one codec per connection.
|
|
1837
|
+
*/
|
|
1838
|
+
type IActionServerHandlerOptions<TConn> = IActionServerHandlerBaseOptions<TConn> & ({
|
|
1839
|
+
formatMessage: TActionChannelFormatMessage;
|
|
1840
|
+
createFormatMessage?: never;
|
|
1841
|
+
} | {
|
|
1842
|
+
createFormatMessage: () => TActionChannelFormatMessage;
|
|
1843
|
+
formatMessage?: never;
|
|
1844
|
+
});
|
|
1845
|
+
/**
|
|
1846
|
+
* A connection-aware execution case (see {@link ActionServerHandler.forConnectionDomainCases}). It
|
|
1847
|
+
* receives the primed request plus the originating client's live connection (already resolved from the
|
|
1848
|
+
* request's `originClient`, `undefined` if the socket is gone), and may return the action's raw output,
|
|
1849
|
+
* a result payload, or nothing (auto-wrapped as an empty success) — exactly like a local handler case.
|
|
1850
|
+
*/
|
|
1851
|
+
type TServerConnectionCaseFn<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string, TConn> = (action: TDistributeActionPayload_Request<DOM, ID>, connection: TConn | undefined) => ReturnType<THandleActionExecutionFn<DOM, ID>> | void;
|
|
1852
|
+
/**
|
|
1853
|
+
* Server-side handler for backends that accept many client connections over a single open channel
|
|
1854
|
+
* (WebSockets, Durable Objects, …). It is transport-agnostic: you feed it inbound frames with
|
|
1855
|
+
* {@link receive} and tell it how to write outbound frames via the `send` option.
|
|
1856
|
+
*
|
|
1857
|
+
* Add it alongside your local execution handler:
|
|
1858
|
+
* ```ts
|
|
1859
|
+
* const serverHandler = createServerHandler({ clientEnv, formatMessage, send: (ws, f) => ws.send(f) });
|
|
1860
|
+
* runtime.addHandlers([localHandler, serverHandler]);
|
|
1861
|
+
* // per inbound message (e.g. a Durable Object's webSocketMessage):
|
|
1862
|
+
* serverHandler.receive(ws, message);
|
|
1863
|
+
* ```
|
|
1864
|
+
*
|
|
1865
|
+
* Inbound requests route to your local handler; the runtime's return dispatch then calls this
|
|
1866
|
+
* handler back (it is an external handler keyed to `clientEnv`) to send the result to the originating
|
|
1867
|
+
* connection. The handler keeps a per-connection identity registry so each result lands on the right
|
|
1868
|
+
* socket, and remembers each connection's encoding so binary and JSON clients can share the channel.
|
|
1869
|
+
*
|
|
1870
|
+
* It registers an empty action router, so it is never chosen to *execute* an inbound request — only
|
|
1871
|
+
* to ferry results/pushes back out.
|
|
1872
|
+
*/
|
|
1873
|
+
declare class ActionServerHandler<TConn = unknown> extends ActionExternalClientHandler {
|
|
1874
|
+
private readonly _formatMessage?;
|
|
1875
|
+
private readonly _createFormatMessage?;
|
|
1876
|
+
private readonly _send;
|
|
1877
|
+
private readonly _runtime?;
|
|
1878
|
+
private readonly _serverTimeout;
|
|
1879
|
+
private _onConnectionBound?;
|
|
1880
|
+
/** Incoming-data listeners installed by the runtime (`resolveIncomingActionPayload`). */
|
|
1881
|
+
private readonly _incomingListeners;
|
|
1882
|
+
private readonly _security?;
|
|
1883
|
+
/** Normalized accepted levels; whether `none` (plain) is allowed; whether any level needs a handshake. */
|
|
1884
|
+
private readonly _allowedLevels;
|
|
1885
|
+
private readonly _noneAllowed;
|
|
1886
|
+
private readonly _handshakeMode;
|
|
1887
|
+
private readonly _connByClient;
|
|
1888
|
+
private readonly _clientByConn;
|
|
1889
|
+
private readonly _connEncoding;
|
|
1890
|
+
private readonly _codecByConn;
|
|
1891
|
+
private readonly _handshakeByConn;
|
|
1892
|
+
private readonly _cryptoByConn;
|
|
1893
|
+
private readonly _authedConns;
|
|
1894
|
+
private readonly _plainConns;
|
|
1895
|
+
private readonly _inboundChainByConn;
|
|
1896
|
+
private readonly _outboundChainByConn;
|
|
1897
|
+
constructor(options: IActionServerHandlerOptions<TConn>);
|
|
1898
|
+
/**
|
|
1899
|
+
* The codec for a connection: a per-connection session (cached) when a factory was provided, else
|
|
1900
|
+
* the single shared `formatMessage`.
|
|
1901
|
+
*/
|
|
1902
|
+
private _codecFor;
|
|
1903
|
+
_setIncomingActionDataListener(listener: (json: TActionPayload_Any_JsonObject<any>) => void): void;
|
|
1904
|
+
/**
|
|
1905
|
+
* Register (or replace) the connection-bound persistence callback after construction. Used by
|
|
1906
|
+
* lifecycle helpers like {@link createHibernatableWsServerAdapter} so persistence and replay are
|
|
1907
|
+
* owned by one place instead of being split across the constructor options.
|
|
1908
|
+
*/
|
|
1909
|
+
setOnConnectionBound(onConnectionBound: (connection: TConn, binding: IActionServerConnectionBinding) => void): void;
|
|
1910
|
+
/**
|
|
1911
|
+
* Create a typed per-connection state store that co-owns the consumer's app state and this handler's
|
|
1912
|
+
* routing binding in one attachment. It registers itself as the connection-bound persistence callback
|
|
1913
|
+
* (so bindings are written without overwriting app state) and immediately replays every live
|
|
1914
|
+
* connection's stored binding via {@link rehydrateConnection} — so on a transport that resumes after
|
|
1915
|
+
* eviction (e.g. a Durable Object waking from hibernation) both the app identity and the action
|
|
1916
|
+
* routing come back from a single attachment, with no storage reads and no hand-rolled merge.
|
|
1917
|
+
*
|
|
1918
|
+
* This supersedes {@link createHibernatableWsServerAdapter} for app code that also pins its own state
|
|
1919
|
+
* to the connection. Construct it once when the handler is built, then `get`/`set` app state directly.
|
|
1920
|
+
*/
|
|
1921
|
+
createConnectionState<TApp>(options: IWsConnectionStateStoreOptions<TConn, TApp>): WsConnectionStateStore<TConn, TApp>;
|
|
1922
|
+
/**
|
|
1923
|
+
* Feed one inbound frame from a connection into the runtime. Decodes text or binary, binds the
|
|
1924
|
+
* connection to the requesting client's identity, then routes it (requests execute locally;
|
|
1925
|
+
* results/progress resolve pending server-initiated actions).
|
|
1926
|
+
*/
|
|
1927
|
+
receive(connection: TConn, frame: string | ArrayBuffer | Uint8Array): void;
|
|
1928
|
+
private _receivePlain;
|
|
1929
|
+
private _receiveSecure;
|
|
1930
|
+
private _completeServerHandshake;
|
|
1931
|
+
/**
|
|
1932
|
+
* Ensure an inbound request carries the client's identity and that this connection is bound to it,
|
|
1933
|
+
* so its result can be routed back. A session codec omits `originClient` after the first request, so
|
|
1934
|
+
* when it's missing we restore it from the (possibly rehydrated) binding instead. (Plain mode only;
|
|
1935
|
+
* secure mode binds the authenticated coordinate at handshake time.)
|
|
1936
|
+
*/
|
|
1937
|
+
private _resolveRequestIdentity;
|
|
1938
|
+
/**
|
|
1939
|
+
* Restore a connection→client binding without an inbound frame — for transports that resume after
|
|
1940
|
+
* eviction. Pair it with the {@link IActionServerHandlerOptions.onConnectionBound} hook: persist
|
|
1941
|
+
* the binding there, then replay each live connection here when the channel comes back (e.g. a
|
|
1942
|
+
* Durable Object iterating `ctx.getWebSockets()` as it wakes from hibernation).
|
|
1943
|
+
*/
|
|
1944
|
+
rehydrateConnection(connection: TConn, binding: IActionServerConnectionBinding): void;
|
|
1945
|
+
toHandlerRouteItem(): IActionRouteItemHandler;
|
|
1946
|
+
/** Forget a connection (call on socket close) so stale entries don't misroute later results. */
|
|
1947
|
+
dropConnection(connection: TConn): void;
|
|
1948
|
+
/** Live connection for a client coordinate, if currently registered. */
|
|
1949
|
+
getConnectionForClient(client: RuntimeCoordinate): TConn | undefined;
|
|
1950
|
+
/**
|
|
1951
|
+
* Send (and optionally await) a server-initiated action to a specific connected client. Pass the
|
|
1952
|
+
* connection token directly (e.g. the `ws`) or a client `RuntimeCoordinate` to look one up.
|
|
1953
|
+
*/
|
|
1954
|
+
pushToClient<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(runtime: ActionRuntime, target: TConn | RuntimeCoordinate, request: ActionPayload_Request<DOM, ID>, options?: {
|
|
1955
|
+
timeout?: number;
|
|
1956
|
+
}): RunningAction<DOM, ID>;
|
|
1957
|
+
/**
|
|
1958
|
+
* Build a local handler whose cases are connection-aware: each case receives the primed request and
|
|
1959
|
+
* the originating client's live connection (resolved from `originClient`), so handlers don't repeat
|
|
1960
|
+
* the `getConnectionForClient(action.context.originClient)` lookup. Cases may return raw output or
|
|
1961
|
+
* nothing, just like {@link ActionLocalHandler.forDomainActionCases}. Add the returned handler to the
|
|
1962
|
+
* runtime alongside this server handler:
|
|
1963
|
+
* ```ts
|
|
1964
|
+
* runtime.addHandlers([serverHandler.forConnectionDomainCases(domain, { … }), serverHandler]);
|
|
1965
|
+
* ```
|
|
1966
|
+
*/
|
|
1967
|
+
forConnectionDomainCases<FOR_DOM extends IActionDomain>(domain: ActionDomain<FOR_DOM>, cases: { [ID in keyof FOR_DOM["actionSchema"] & string]?: TServerConnectionCaseFn<FOR_DOM, ID, TConn> }): ActionLocalHandler;
|
|
1968
|
+
/**
|
|
1969
|
+
* Fan a server-initiated request out to every currently-bound connection. A fresh request is built
|
|
1970
|
+
* per connection (each push mutates its own action context) and dispatched fire-and-forget. Pass
|
|
1971
|
+
* `except` to skip the originating socket and `where` to filter by connection (e.g. read its
|
|
1972
|
+
* attachment for a role). Iterating bound connections (rather than every accepted socket) skips
|
|
1973
|
+
* sockets that are still mid-handshake and so can't yet receive a frame.
|
|
1974
|
+
*/
|
|
1975
|
+
broadcast<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(makeRequest: () => ActionPayload_Request<DOM, ID>, options?: {
|
|
1976
|
+
runtime?: ActionRuntime;
|
|
1977
|
+
except?: TConn | null;
|
|
1978
|
+
where?: (connection: TConn) => boolean;
|
|
1979
|
+
timeout?: number;
|
|
1980
|
+
onError?: (error: unknown, connection: TConn) => void;
|
|
1981
|
+
}): void;
|
|
1982
|
+
sendReturnPayload(payload: TActionPayload_Any_Instance<any, any>, config: {
|
|
1983
|
+
targetLocalRuntime: ActionRuntime;
|
|
1984
|
+
}): Promise<boolean>;
|
|
1985
|
+
handleActionRequest<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string>(action: ActionPayload_Request<DOM, ID>, config?: IHandleActionOptions): Promise<RunningAction<DOM, ID>>;
|
|
1986
|
+
private _dispatch;
|
|
1987
|
+
private _sendPayload;
|
|
1988
|
+
private _bindConnection;
|
|
1989
|
+
private _resolveConnection;
|
|
1990
|
+
private _resolveSingleConnection;
|
|
1991
|
+
}
|
|
1992
|
+
declare const createServerHandler: <TConn = unknown>(options: IActionServerHandlerOptions<TConn>) => ActionServerHandler<TConn>;
|
|
1993
|
+
//#endregion
|
|
1994
|
+
//#region src/ActionRuntime/Handler/Server/createActionFetchHandler.d.ts
|
|
1995
|
+
interface IActionFetchHandlerOptions {
|
|
1996
|
+
/**
|
|
1997
|
+
* CORS headers merged onto every response (a preflight `OPTIONS` is answered `204` with them).
|
|
1998
|
+
* Defaults to permissive `*`; pass `false` to attach no CORS headers at all.
|
|
1999
|
+
*/
|
|
2000
|
+
cors?: Record<string, string> | false;
|
|
2001
|
+
/** Which requests carry an action wire on `POST`. Default: pathname ends with `/action`. */
|
|
2002
|
+
isActionPath?: (url: URL) => boolean;
|
|
2003
|
+
/** Which requests are WebSocket upgrades. Default: pathname ends with `/ws`. */
|
|
2004
|
+
isWebSocketPath?: (url: URL) => boolean;
|
|
2005
|
+
/**
|
|
2006
|
+
* Perform the transport-specific WebSocket upgrade (e.g. a Durable Object's
|
|
2007
|
+
* `new WebSocketPair()` + `ctx.acceptWebSocket()` returning a `101`). Omit for HTTP-only endpoints.
|
|
2008
|
+
* Its response is returned as-is — a `101` upgrade carries no CORS headers.
|
|
2009
|
+
*/
|
|
2010
|
+
onWebSocketUpgrade?: (request: Request, url: URL) => Response | Promise<Response>;
|
|
2011
|
+
/** Forwarded to `ActionPayload_Result.toHttpResponse` — use the error's HTTP status (default true). */
|
|
2012
|
+
useErrorStatus?: boolean;
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Build the `fetch` handler a server/Durable-Object exposes for action traffic, folding in the
|
|
2016
|
+
* boilerplate every endpoint repeats: CORS (incl. the `OPTIONS` preflight), routing the `/action`
|
|
2017
|
+
* `POST` body through the runtime (`handleActionPayloadWire` → `waitForResultPayload` →
|
|
2018
|
+
* `toHttpResponse`), an optional WebSocket-upgrade hook, and a `404` fallback.
|
|
2019
|
+
*
|
|
2020
|
+
* It only touches web-standard `Request`/`Response`, so it stays transport-agnostic — the one
|
|
2021
|
+
* environment-specific bit (the WS upgrade) is injected via {@link IActionFetchHandlerOptions.onWebSocketUpgrade}:
|
|
2022
|
+
* ```ts
|
|
2023
|
+
* this.fetchHandler = createActionFetchHandler(this.runtime, {
|
|
2024
|
+
* onWebSocketUpgrade: () => {
|
|
2025
|
+
* const pair = new WebSocketPair();
|
|
2026
|
+
* this.ctx.acceptWebSocket(pair[1]);
|
|
2027
|
+
* return new Response(null, { status: 101, webSocket: pair[0] });
|
|
2028
|
+
* },
|
|
2029
|
+
* });
|
|
2030
|
+
* // async fetch(request) { return this.fetchHandler(request); }
|
|
2031
|
+
* ```
|
|
2032
|
+
*/
|
|
2033
|
+
declare function createActionFetchHandler(runtime: ActionRuntime, options?: IActionFetchHandlerOptions): (request: Request) => Promise<Response>;
|
|
2034
|
+
//#endregion
|
|
2035
|
+
//#region src/ActionRuntime/Handler/Server/createSecureActionServer.d.ts
|
|
2036
|
+
interface ISecureActionServerHandlerOptions<TConn> {
|
|
2037
|
+
/** The shared channel identity (codec + dictionary version) — same one the clients use. */
|
|
2038
|
+
channel: ISecureWsChannel;
|
|
2039
|
+
/**
|
|
2040
|
+
* Coordinate of the *connecting clients* (typically env-only, e.g. `RuntimeCoordinate.env("web_app")`),
|
|
2041
|
+
* used to route results/pushes back over this handler.
|
|
2042
|
+
*/
|
|
2043
|
+
clientEnv: RuntimeCoordinate;
|
|
2044
|
+
/** This server's runtime — its coordinate is the server identity presented in the handshake. */
|
|
2045
|
+
runtime: ActionRuntime;
|
|
2046
|
+
/**
|
|
2047
|
+
* One backing store for the server's crypto identity *and* its trust-on-first-use verify-key pins.
|
|
2048
|
+
* Their keys don't collide, so a single adapter is enough; back it with persistent storage (e.g. a
|
|
2049
|
+
* Durable Object's storage) so identity and pins survive eviction.
|
|
2050
|
+
*/
|
|
2051
|
+
storageAdapter: StorageAdapter;
|
|
2052
|
+
/** Write an encoded frame to a specific live connection (e.g. `(ws, frame) => ws.send(frame)`). */
|
|
2053
|
+
send: (connection: TConn, frame: string | Uint8Array | ArrayBuffer) => void;
|
|
2054
|
+
/** Accepted level(s); defaults to negotiating any of none/authenticated/encrypted. */
|
|
2055
|
+
securityLevel?: ESecurityLevel | readonly ESecurityLevel[];
|
|
2056
|
+
/** Trust decision for a client's verify key; defaults to storage-backed TOFU over `storageAdapter`. */
|
|
2057
|
+
verifyKeyResolver?: IClientVerifyKeyResolver;
|
|
2058
|
+
/** Timeout (ms) applied to server-initiated actions awaiting a client response. */
|
|
2059
|
+
defaultTimeout?: number;
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* Build an {@link ActionServerHandler} for the secure binary channel with the boilerplate folded in:
|
|
2063
|
+
* it creates the {@link ClientCryptoKeyLink} and the storage-backed TOFU resolver from a single
|
|
2064
|
+
* `storageAdapter`, installs the channel's per-connection codec, and assembles the `security` block
|
|
2065
|
+
* from the runtime coordinate + channel version (accepting all three levels by default).
|
|
2066
|
+
*
|
|
2067
|
+
* For a hibernatable transport (e.g. a Durable Object), pair it with
|
|
2068
|
+
* {@link createHibernatableWsServerAdapter} to wire persistence + replay.
|
|
2069
|
+
*/
|
|
2070
|
+
declare function createSecureActionServerHandler<TConn = unknown>(options: ISecureActionServerHandlerOptions<TConn>): ActionServerHandler<TConn>;
|
|
2071
|
+
interface IHibernatableWsServerAdapterOptions<TConn> {
|
|
2072
|
+
/** The handler to drive (from {@link createSecureActionServerHandler} or `createServerHandler`). */
|
|
2073
|
+
handler: ActionServerHandler<TConn>;
|
|
2074
|
+
/** All currently-live connections — replayed on construction to rebuild bindings after a wake. */
|
|
2075
|
+
getWebSockets: () => TConn[];
|
|
2076
|
+
/** Read a connection's persisted binding (e.g. `(ws) => ws.deserializeAttachment()`). */
|
|
2077
|
+
getAttachment: (connection: TConn) => IActionServerConnectionBinding | undefined;
|
|
2078
|
+
/** Persist a connection's binding when it is bound (e.g. `(ws, b) => ws.serializeAttachment(b)`). */
|
|
2079
|
+
setAttachment: (connection: TConn, binding: IActionServerConnectionBinding) => void;
|
|
2080
|
+
}
|
|
2081
|
+
interface IHibernatableWsServerAdapter<TConn> {
|
|
2082
|
+
/** Feed one inbound frame from a connection into the handler. */
|
|
2083
|
+
receive: (connection: TConn, frame: string | ArrayBuffer | Uint8Array) => void;
|
|
2084
|
+
/** Forget a connection (call on socket close/error). */
|
|
2085
|
+
drop: (connection: TConn) => void;
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* Wire the hibernation lifecycle for a server handler on a transport whose sockets outlive process
|
|
2089
|
+
* eviction (e.g. a Durable Object's hibernatable WebSockets). It owns persistence end to end:
|
|
2090
|
+
* registers `setAttachment` as the handler's connection-bound callback and immediately replays every
|
|
2091
|
+
* live connection's stored binding via `getAttachment`, so results/pushes still route after a wake.
|
|
2092
|
+
*
|
|
2093
|
+
* Construct it once when the handler is built, then forward socket events:
|
|
2094
|
+
* ```ts
|
|
2095
|
+
* const wsServer = createHibernatableWsServerAdapter({ handler, getWebSockets, getAttachment, setAttachment });
|
|
2096
|
+
* // webSocketMessage(ws, msg) => wsServer.receive(ws, msg);
|
|
2097
|
+
* // webSocketClose/Error(ws) => wsServer.drop(ws);
|
|
2098
|
+
* ```
|
|
2099
|
+
*/
|
|
2100
|
+
declare function createHibernatableWsServerAdapter<TConn>(options: IHibernatableWsServerAdapterOptions<TConn>): IHibernatableWsServerAdapter<TConn>;
|
|
2101
|
+
//#endregion
|
|
2102
|
+
//#region src/errors/err_nice_action.d.ts
|
|
2103
|
+
declare enum EErrId_NiceAction {
|
|
2104
|
+
not_implemented = "not_implemented",
|
|
2105
|
+
action_id_not_in_domain = "action_id_not_in_domain",
|
|
2106
|
+
domain_already_exists_in_hierarchy = "domain_already_exists_in_hierarchy",
|
|
2107
|
+
domain_no_handler = "domain_no_handler",
|
|
2108
|
+
hydration_domain_mismatch = "hydration_domain_mismatch",
|
|
2109
|
+
hydration_action_state_mismatch = "hydration_action_state_mismatch",
|
|
2110
|
+
hydration_action_id_not_found = "hydration_action_id_not_found",
|
|
2111
|
+
no_action_execution_handler = "no_action_execution_handler",
|
|
2112
|
+
wire_action_not_payload = "wire_action_not_payload",
|
|
2113
|
+
wire_not_action_data = "wire_not_action_data",
|
|
2114
|
+
client_runtime_already_registered = "client_runtime_already_registered",
|
|
2115
|
+
client_runtime_not_registered = "client_runtime_not_registered",
|
|
2116
|
+
runtime_reset = "runtime_reset",
|
|
2117
|
+
no_client_runtimes_registered = "no_client_runtimes_registered",
|
|
2118
|
+
action_input_validation_failed = "action_input_validation_failed",
|
|
2119
|
+
action_input_validation_promise = "action_input_validation_promise",
|
|
2120
|
+
action_output_validation_failed = "action_output_validation_failed",
|
|
2121
|
+
action_output_validation_promise = "action_output_validation_promise"
|
|
2122
|
+
}
|
|
2123
|
+
declare const err_nice_action: import("@nice-code/error").NiceErrorDomain<{
|
|
2124
|
+
domain: string;
|
|
2125
|
+
allDomains: [string, "err_nice"];
|
|
2126
|
+
schema: {
|
|
2127
|
+
not_implemented: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2128
|
+
label: string;
|
|
2129
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2130
|
+
action_id_not_in_domain: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2131
|
+
domain: string;
|
|
2132
|
+
actionId: string;
|
|
2133
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2134
|
+
domain_already_exists_in_hierarchy: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2135
|
+
domain: string;
|
|
2136
|
+
allParentDomains: string[];
|
|
2137
|
+
parentDomain: string;
|
|
2138
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2139
|
+
domain_no_handler: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2140
|
+
domain: string;
|
|
2141
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2142
|
+
hydration_domain_mismatch: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2143
|
+
expected: string;
|
|
2144
|
+
received: string;
|
|
2145
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2146
|
+
hydration_action_state_mismatch: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2147
|
+
expected: string;
|
|
2148
|
+
received: string;
|
|
2149
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2150
|
+
hydration_action_id_not_found: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2151
|
+
domain: string;
|
|
2152
|
+
actionId: string;
|
|
2153
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2154
|
+
no_action_execution_handler: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2155
|
+
domain: string;
|
|
2156
|
+
actionId: string;
|
|
2157
|
+
specifiedClient?: RuntimeCoordinate;
|
|
2158
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2159
|
+
wire_action_not_payload: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2160
|
+
domain: string;
|
|
2161
|
+
actionId: string;
|
|
2162
|
+
actionState: string | undefined;
|
|
2163
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2164
|
+
wire_not_action_data: import("@nice-code/error").INiceErrorIdMetadata<any, import("@nice-code/error").JSONSerializableValue>;
|
|
2165
|
+
runtime_reset: import("@nice-code/error").INiceErrorIdMetadata<any, import("@nice-code/error").JSONSerializableValue>;
|
|
2166
|
+
client_runtime_already_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2167
|
+
context?: IActionRuntimeManagerContext;
|
|
2168
|
+
client: RuntimeCoordinate;
|
|
2169
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2170
|
+
client_runtime_not_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2171
|
+
context?: IActionRuntimeManagerContext;
|
|
2172
|
+
clientStringId: TRuntimeCoordinateStringId;
|
|
2173
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2174
|
+
no_client_runtimes_registered: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2175
|
+
context?: IActionRuntimeManagerContext;
|
|
2176
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2177
|
+
action_input_validation_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2178
|
+
domain: string;
|
|
2179
|
+
actionId: string;
|
|
2180
|
+
validationMessage: string;
|
|
2181
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2182
|
+
action_input_validation_promise: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2183
|
+
domain: string;
|
|
2184
|
+
actionId: string;
|
|
2185
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2186
|
+
action_output_validation_failed: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2187
|
+
domain: string;
|
|
2188
|
+
actionId: string;
|
|
2189
|
+
validationMessage: string;
|
|
2190
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2191
|
+
action_output_validation_promise: import("@nice-code/error").INiceErrorIdMetadata<{
|
|
2192
|
+
domain: string;
|
|
2193
|
+
actionId: string;
|
|
2194
|
+
}, import("@nice-code/error").JSONSerializableValue>;
|
|
2195
|
+
};
|
|
2196
|
+
}>;
|
|
2197
|
+
//#endregion
|
|
2198
|
+
//#region src/utils/decodeActionFrame.d.ts
|
|
2199
|
+
/**
|
|
2200
|
+
* Minimal codec shape needed to turn an incoming channel frame back into action wire JSON. Matches
|
|
2201
|
+
* the `formatMessage` object the WebSocket transport (and `createBinaryWsAdapter`) provide.
|
|
2202
|
+
*/
|
|
2203
|
+
interface IActionFrameDecoder {
|
|
2204
|
+
incoming?: (frame: string | ArrayBuffer | Uint8Array | Blob) => TActionPayload_Any_JsonObject<any, any> | undefined;
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Decode a single inbound channel frame (text or binary) into validated action wire JSON, or
|
|
2208
|
+
* `undefined` if it isn't a recognisable action payload.
|
|
2209
|
+
*
|
|
2210
|
+
* Shared by the WebSocket transport's message listener and the server-side `ActionServerHandler` so
|
|
2211
|
+
* both decode identically: a binary `decoder.incoming` (e.g. msgpackr) takes precedence, and plain
|
|
2212
|
+
* text frames fall back to JSON — keeping binary and JSON clients interoperable on one channel.
|
|
2213
|
+
*/
|
|
2214
|
+
declare function decodeActionFrame(frame: string | ArrayBuffer | Uint8Array, decoder?: IActionFrameDecoder): TActionPayload_Any_JsonObject<any, any> | undefined;
|
|
2215
|
+
//#endregion
|
|
2216
|
+
//#region src/utils/isActionPayload_Any_JsonObject.d.ts
|
|
2217
|
+
declare function isActionPayload_Any_JsonObject(obj: unknown): obj is TActionPayload_Any_JsonObject;
|
|
2218
|
+
//#endregion
|
|
2219
|
+
//#region src/utils/isActionPayload_Request_JsonObject.d.ts
|
|
2220
|
+
declare const isActionPayload_Request_JsonObject: (obj: unknown) => obj is IActionPayload_Request_JsonObject;
|
|
2221
|
+
//#endregion
|
|
2222
|
+
//#region src/utils/isActionPayload_Result_JsonObject.d.ts
|
|
2223
|
+
declare const isActionPayload_Result_JsonObject: (obj: unknown) => obj is IActionPayload_Result_JsonObject;
|
|
2224
|
+
//#endregion
|
|
2225
|
+
//#region src/ActionDefinition/Action/Payload/ActionPayload.types.d.ts
|
|
2226
|
+
declare enum EActionPayloadType {
|
|
2227
|
+
request = "request",
|
|
2228
|
+
progress = "progress",
|
|
2229
|
+
result = "result",
|
|
2230
|
+
stream = "stream",
|
|
2231
|
+
push = "push"
|
|
2232
|
+
}
|
|
2233
|
+
interface IActionPayload_Data_Base {
|
|
2234
|
+
time: number;
|
|
2235
|
+
}
|
|
2236
|
+
interface IActionPayload_Base<DT extends EActionPayloadType, DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> extends IActionBase<EActionForm.data, DOM, ID>, IActionPayload_Data_Base {
|
|
2237
|
+
readonly type: DT;
|
|
2238
|
+
readonly context: ActionContext<DOM, ID>;
|
|
2239
|
+
}
|
|
2240
|
+
type IActionRouteItemHandler = IActionHandler_Local_Json | (IActionHandler_ExternalClient_Json & {
|
|
2241
|
+
transType: ETransportType;
|
|
2242
|
+
transOrd: number;
|
|
2243
|
+
transInfo?: ITransportRouteInfo;
|
|
2244
|
+
});
|
|
2245
|
+
/**
|
|
2246
|
+
* [ ]
|
|
2247
|
+
* [ ACTION PAYLOAD TYPES ]
|
|
2248
|
+
* [ ]
|
|
2249
|
+
*/
|
|
2250
|
+
/**
|
|
2251
|
+
*
|
|
2252
|
+
* [ RESULT ]
|
|
2253
|
+
*
|
|
2254
|
+
*/
|
|
2255
|
+
type TActionResultOutcome<OUT, ERR> = {
|
|
2256
|
+
ok: true;
|
|
2257
|
+
output: OUT;
|
|
2258
|
+
} | {
|
|
2259
|
+
ok: false;
|
|
2260
|
+
error: ERR;
|
|
2261
|
+
};
|
|
2262
|
+
interface IActionPayload_Result<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> extends IActionPayload_Base<EActionPayloadType.result, DOM, ID> {
|
|
2263
|
+
readonly result: TActionResultOutcome<TInferOutputFromSchema<DOM["actionSchema"][ID]>["Output"], TInferActionError<DOM["actionSchema"][ID]>>;
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
*
|
|
2267
|
+
* [ PROGRESS ]
|
|
2268
|
+
*
|
|
2269
|
+
*/
|
|
2270
|
+
declare enum EActionProgressType {
|
|
2271
|
+
none = "none",
|
|
2272
|
+
percentage = "percentage",
|
|
2273
|
+
custom = "custom"
|
|
2274
|
+
}
|
|
2275
|
+
interface IActionProgress_None {
|
|
2276
|
+
type: EActionProgressType.none;
|
|
2277
|
+
}
|
|
2278
|
+
interface IActionProgress_Percentage {
|
|
2279
|
+
type: EActionProgressType.percentage;
|
|
2280
|
+
progress: number;
|
|
2281
|
+
message?: string;
|
|
2282
|
+
}
|
|
2283
|
+
interface IActionProgress_Custom {
|
|
2284
|
+
type: EActionProgressType.custom;
|
|
2285
|
+
data: any;
|
|
2286
|
+
}
|
|
2287
|
+
type TActionProgress = IActionProgress_None | IActionProgress_Percentage | IActionProgress_Custom;
|
|
2288
|
+
interface IActionPayload_Progress<DOM extends IActionDomain, ID extends keyof DOM["actionSchema"] & string> extends IActionPayload_Base<EActionPayloadType.progress, DOM, ID> {
|
|
2289
|
+
readonly progress: TActionProgress;
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
*
|
|
2293
|
+
* [ ]
|
|
2294
|
+
* [ Wire JSON types ]
|
|
2295
|
+
* [ ]
|
|
2296
|
+
*
|
|
2297
|
+
*/
|
|
2298
|
+
interface IActionPayload_Base_JsonObject<DT extends EActionPayloadType, DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionBase_JsonObject<EActionForm.data, DOM, ID> {
|
|
2299
|
+
type: DT;
|
|
2300
|
+
context: IActionContext_Data_JsonObject;
|
|
2301
|
+
time: number;
|
|
2302
|
+
}
|
|
2303
|
+
interface IActionPayload_Request_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionPayload_Base_JsonObject<EActionPayloadType.request, DOM, ID> {
|
|
2304
|
+
type: EActionPayloadType.request;
|
|
2305
|
+
input: TInferInputFromSchema<DOM["actionSchema"][ID]>["SerdeInput"];
|
|
2306
|
+
inputHash: string;
|
|
2307
|
+
}
|
|
2308
|
+
interface IActionPayload_Progress_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionPayload_Base_JsonObject<EActionPayloadType.progress, DOM, ID> {
|
|
2309
|
+
type: EActionPayloadType.progress;
|
|
2310
|
+
progress: TActionProgress;
|
|
2311
|
+
}
|
|
2312
|
+
interface IActionPayload_Result_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> extends IActionPayload_Base_JsonObject<EActionPayloadType.result, DOM, ID> {
|
|
2313
|
+
type: EActionPayloadType.result;
|
|
2314
|
+
result: TActionResultOutcome<TInferOutputFromSchema<DOM["actionSchema"][ID]>["SerdeOutput"], TInferActionError<DOM["actionSchema"][ID]>>;
|
|
2315
|
+
outputHash: string;
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
*
|
|
2319
|
+
* [ ]
|
|
2320
|
+
* [ COMBINED TYPES ]
|
|
2321
|
+
* [ ]
|
|
2322
|
+
*
|
|
2323
|
+
*/
|
|
2324
|
+
type TActionPayload_Any_Instance<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = ActionPayload_Request<DOM, ID> | ActionPayload_Result<DOM, ID> | ActionPayload_Progress<DOM, ID>;
|
|
2325
|
+
type TActionPayload_Any_JsonObject<DOM extends IActionDomain = IActionDomain, ID extends keyof DOM["actionSchema"] & string = keyof DOM["actionSchema"] & string> = IActionPayload_Request_JsonObject<DOM, ID> | IActionPayload_Progress_JsonObject<DOM, ID> | IActionPayload_Result_JsonObject<DOM, ID>;
|
|
2326
|
+
//#endregion
|
|
2327
|
+
export { createBinaryWsAdapter as $, TInferOutputFromSchema as $n, ITransportDispatchAction as $t, createSecureActionServerHandler as A, ERunningActionState as An, ICustomTransportSendOptions as At, IConnectionAttachment as B, IRuntimeCoordinate as Bn, MaybePromise as Bt, decodeActionFrame as C, TUpdateActionRunConfig as Cn, IHttpTransportOptions as Ct, IHibernatableWsServerAdapterOptions as D, IActionCore as Dn, err_nice_transport as Dt, IHibernatableWsServerAdapter as E, ActionPayload_Request as En, EErrId_NiceTransport as Et, IActionServerHandlerOptions as F, IRunningActionUpdate_Success as Fn, ActionDomain as Ft, createSecureWebSocketTransport as G, TRuntimeCoordinateStringId as Gn, ETransportStatus as Gt, WsConnectionStateStore as H, IRuntimeFullCoordinates as Hn, createExternalClientHandler as Ht, TActionChannelFormatMessage as I, TRunningActionUpdate as In, ActionRootDomain as It, IWebSocketTransportSocketOptions as J, IActionRootDomain as Jn, IActionTransportInitialized as Jt, defineSecureWsChannel as K, IActionDomain as Kn, ETransportType as Kt, TActionConnectionEncoding as L, TRunningActionUpdateFinished as Ln, ActionRuntime as Lt, createActionFetchHandler as M, IRunningActionUpdate_Abort as Mn, err_nice_external_client as Mt, ActionServerHandler as N, IRunningActionUpdate_Progress as Nn, createActionRootDomain as Nt, ISecureActionServerHandlerOptions as O, IActionCore_JsonObject as On, CustomTransport as Ot, IActionServerConnectionBinding as P, IRunningActionUpdate_Started as Pn, ActionCore as Pt, createBinaryWsSessionFactory as Q, TInferInputFromSchema as Qn, IActionTransportResolvers as Qt, TServerConnectionCaseFn as R, TRunningActionUpdateListener as Rn, ActionLocalHandler as Rt, IActionFrameDecoder as S, TTransportStatusInfo_GetTransport_Output as Sn, HttpTransport as St, err_nice_action as T, ActionPayload_Progress as Tn, err_nice_transport_ws as Tt, ISecureWebSocketTransportOptions as U, RuntimeCoordinate as Un, ITransportConnectionContext as Ut, IWsConnectionStateStoreOptions as V, IRuntimeCoordinateSpecifics as Vn, ActionExternalClientHandler as Vt, ISecureWsChannel as W, TRuntimeCoordinateEnvId as Wn, Transport as Wt, WebSocketTransport as X, TActionDomainSchema as Xn, IActionTransportReadyData_Base as Xt, TWebSocketTransportOptions as Y, TActionDomainChildDef as Yn, IActionTransportReady as Yt, IBinaryWsSessionOptions as Z, TDomainActionId as Zn, IActionTransportReadyData_Methods as Zt, TActionProgress as _, TSendActionDataMethod as _n, encodeHandshakeMessage as _t, IActionPayload_Data_Base as a, ITransportStatusInfo_Failed as an, TActionSchemaOptions as ar, IClientHandshakeConfig as at, isActionPayload_Request_JsonObject as b, TTransportInitializationFinishedInfo as bn, IActionFrameCryptoConfig as bt, IActionPayload_Request_JsonObject as c, ITransportStatusInfo_Unsupported as cn, IHandshakeEncryptionKeyMaterial as ct, IActionProgress_Custom as d, TOnResolveAnyIncomingActionData as dn, THandshakeMessage as dt, ITransportMethod_SendActionData_Input as en, TPossibleDomainId as er, IActionTransportDef_Ws as et, IActionProgress_None as f, TOnResolveAnyIncomingActionData_Json as fn, createClientHandshake as ft, TActionPayload_Any_JsonObject as g, TOnResolveIncomingResponseJson as gn, decodeHandshakeMessage as gt, TActionPayload_Any_Instance as h, TOnResolveIncomingResponse as hn, createStorageTofuVerifyKeyResolver as ht, IActionPayload_Base_JsonObject as i, ITransportStatusInfo_Base as in, actionSchema as ir, ESecurityLevel as it, IActionFetchHandlerOptions as j, ERunningActionUpdateType as jn, TCustomTransportOptions as jt, createHibernatableWsServerAdapter as k, ERunningActionFinishedType as kn, ICustomTransportAdvancedOptions as kt, IActionPayload_Result as l, IUpdateActionRunConfig_Output as ln, IHandshakeResult as lt, IActionRouteItemHandler as m, TOnResolveIncomingRequestJson as mn, createServerHandshake as mt, EActionProgressType as n, ITransportRouteClientParams as nn, ActionSchema as nr, IActionTransportReadyData_Ws as nt, IActionPayload_Progress as o, ITransportStatusInfo_Initializing as on, TActionSerializationDefinition as or, IClientVerifyKeyResolveInput as ot, IActionProgress_Percentage as p, TOnResolveIncomingRequest as pn, createInMemoryTofuVerifyKeyResolver as pt, IWebSocketTransportAdvancedOptions as q, IActionDomainChildOptions as qn, IActionTransportDef as qt, IActionPayload_Base as r, ITransportRouteInfo as rn, TInferActionError as rr, EHandshakeMessageType as rt, IActionPayload_Progress_JsonObject as s, ITransportStatusInfo_Ready as sn, TTransportedValue as sr, IClientVerifyKeyResolver as st, EActionPayloadType as t, ITransportRouteActionParams as tn, TPossibleDomainIdList as tr, IActionTransportInitialized_Ws as tt, IActionPayload_Result_JsonObject as u, TGetTransportFn as un, IServerHandshakeConfig as ut, TActionResultOutcome as v, TSendReturnDataMethod as vn, runtimeLinkId as vt, EErrId_NiceAction as w, RunningAction as wn, EErrId_NiceTransport_WebSocket as wt, isActionPayload_Any_JsonObject as x, TTransportStatusInfo as xn, createActionFrameCrypto as xt, isActionPayload_Result_JsonObject as y, TTransportCache as yn, IActionFrameCrypto as yt, createServerHandler as z, ActionPayload_Result as zn, createLocalHandler as zt };
|
|
2328
|
+
//# sourceMappingURL=ActionPayload.types-D28ELKXC.d.ts.map
|