@genesislcap/foundation-state-machine 14.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +26 -0
  2. package/dist/dts/core/actions.d.ts +61 -0
  3. package/dist/dts/core/actions.d.ts.map +1 -0
  4. package/dist/dts/core/binding.d.ts +37 -0
  5. package/dist/dts/core/binding.d.ts.map +1 -0
  6. package/dist/dts/core/errors.d.ts +41 -0
  7. package/dist/dts/core/errors.d.ts.map +1 -0
  8. package/dist/dts/core/guards.d.ts +67 -0
  9. package/dist/dts/core/guards.d.ts.map +1 -0
  10. package/dist/dts/core/index.d.ts +8 -0
  11. package/dist/dts/core/index.d.ts.map +1 -0
  12. package/dist/dts/core/inputs.d.ts +19 -0
  13. package/dist/dts/core/inputs.d.ts.map +1 -0
  14. package/dist/dts/core/machine.d.ts +338 -0
  15. package/dist/dts/core/machine.d.ts.map +1 -0
  16. package/dist/dts/core/state.d.ts +11 -0
  17. package/dist/dts/core/state.d.ts.map +1 -0
  18. package/dist/dts/index.d.ts +4 -0
  19. package/dist/dts/index.d.ts.map +1 -0
  20. package/dist/dts/index.federated.d.ts +1 -0
  21. package/dist/dts/index.federated.d.ts.map +1 -0
  22. package/dist/dts/machines/fetch/errors.d.ts +39 -0
  23. package/dist/dts/machines/fetch/errors.d.ts.map +1 -0
  24. package/dist/dts/machines/fetch/index.d.ts +5 -0
  25. package/dist/dts/machines/fetch/index.d.ts.map +1 -0
  26. package/dist/dts/machines/fetch/machine.d.ts +57 -0
  27. package/dist/dts/machines/fetch/machine.d.ts.map +1 -0
  28. package/dist/dts/machines/fetch/policies.d.ts +25 -0
  29. package/dist/dts/machines/fetch/policies.d.ts.map +1 -0
  30. package/dist/dts/machines/fetch/types.d.ts +118 -0
  31. package/dist/dts/machines/fetch/types.d.ts.map +1 -0
  32. package/dist/dts/machines/index.d.ts +2 -0
  33. package/dist/dts/machines/index.d.ts.map +1 -0
  34. package/dist/dts/tsdoc-metadata.json +11 -0
  35. package/dist/dts/utils/index.d.ts +2 -0
  36. package/dist/dts/utils/index.d.ts.map +1 -0
  37. package/dist/dts/utils/logger.d.ts +5 -0
  38. package/dist/dts/utils/logger.d.ts.map +1 -0
  39. package/dist/esm/core/actions.js +46 -0
  40. package/dist/esm/core/binding.js +16 -0
  41. package/dist/esm/core/errors.js +70 -0
  42. package/dist/esm/core/guards.js +73 -0
  43. package/dist/esm/core/index.js +7 -0
  44. package/dist/esm/core/inputs.js +10 -0
  45. package/dist/esm/core/machine.js +180 -0
  46. package/dist/esm/core/state.js +26 -0
  47. package/dist/esm/index.federated.js +1 -0
  48. package/dist/esm/index.js +3 -0
  49. package/dist/esm/machines/fetch/errors.js +46 -0
  50. package/dist/esm/machines/fetch/index.js +4 -0
  51. package/dist/esm/machines/fetch/machine.js +216 -0
  52. package/dist/esm/machines/fetch/policies.js +48 -0
  53. package/dist/esm/machines/fetch/types.js +48 -0
  54. package/dist/esm/machines/index.js +1 -0
  55. package/dist/esm/utils/index.js +1 -0
  56. package/dist/esm/utils/logger.js +5 -0
  57. package/dist/foundation-state-machine.api.json +5594 -0
  58. package/dist/foundation-state-machine.d.ts +884 -0
  59. package/docs/.gitattributes +2 -0
  60. package/docs/api/foundation-state-machine.abstractmachine.actor.md +18 -0
  61. package/docs/api/foundation-state-machine.abstractmachine.binding.md +27 -0
  62. package/docs/api/foundation-state-machine.abstractmachine.complete.md +13 -0
  63. package/docs/api/foundation-state-machine.abstractmachine.context.md +13 -0
  64. package/docs/api/foundation-state-machine.abstractmachine.error.md +13 -0
  65. package/docs/api/foundation-state-machine.abstractmachine.errors.md +13 -0
  66. package/docs/api/foundation-state-machine.abstractmachine.getfromcontainer.md +23 -0
  67. package/docs/api/foundation-state-machine.abstractmachine.hastag.md +28 -0
  68. package/docs/api/foundation-state-machine.abstractmachine.machine.md +18 -0
  69. package/docs/api/foundation-state-machine.abstractmachine.matches.md +28 -0
  70. package/docs/api/foundation-state-machine.abstractmachine.md +44 -0
  71. package/docs/api/foundation-state-machine.abstractmachine.onsendevent.md +13 -0
  72. package/docs/api/foundation-state-machine.abstractmachine.output.md +13 -0
  73. package/docs/api/foundation-state-machine.abstractmachine.provide.md +24 -0
  74. package/docs/api/foundation-state-machine.abstractmachine.send.md +24 -0
  75. package/docs/api/foundation-state-machine.abstractmachine.start.md +28 -0
  76. package/docs/api/foundation-state-machine.abstractmachine.startingcontext.md +13 -0
  77. package/docs/api/foundation-state-machine.abstractmachine.startingstate.md +13 -0
  78. package/docs/api/foundation-state-machine.abstractmachine.state.md +13 -0
  79. package/docs/api/foundation-state-machine.abstractmachine.stop.md +17 -0
  80. package/docs/api/foundation-state-machine.apierror._constructor_.md +22 -0
  81. package/docs/api/foundation-state-machine.apierror.data.md +11 -0
  82. package/docs/api/foundation-state-machine.apierror.md +32 -0
  83. package/docs/api/foundation-state-machine.apierror.status.md +11 -0
  84. package/docs/api/foundation-state-machine.assertevent.md +27 -0
  85. package/docs/api/foundation-state-machine.createerrorstatenode.md +13 -0
  86. package/docs/api/foundation-state-machine.createfetchpolicy.md +18 -0
  87. package/docs/api/foundation-state-machine.createresponsedataextractorwithdeserializer.md +13 -0
  88. package/docs/api/foundation-state-machine.defaultfetchconfig.md +13 -0
  89. package/docs/api/foundation-state-machine.defaultfetchmachine._constructor_.md +20 -0
  90. package/docs/api/foundation-state-machine.defaultfetchmachine.getfromcontainer.md +23 -0
  91. package/docs/api/foundation-state-machine.defaultfetchmachine.md +30 -0
  92. package/docs/api/foundation-state-machine.defaultfetchmachine.start.md +28 -0
  93. package/docs/api/foundation-state-machine.defaultfetchmachinecontext.md +13 -0
  94. package/docs/api/foundation-state-machine.defaultfetchpolicy.md +13 -0
  95. package/docs/api/foundation-state-machine.defaultresponsedataextractor.md +18 -0
  96. package/docs/api/foundation-state-machine.defaultresponseokchecker.md +13 -0
  97. package/docs/api/foundation-state-machine.defaultretrystatscodes.md +13 -0
  98. package/docs/api/foundation-state-machine.errorworkflowinput.md +15 -0
  99. package/docs/api/foundation-state-machine.escalateerror.md +42 -0
  100. package/docs/api/foundation-state-machine.fetchconfig.fetcher.md +13 -0
  101. package/docs/api/foundation-state-machine.fetchconfig.fetchpolicy.md +13 -0
  102. package/docs/api/foundation-state-machine.fetchconfig.md +23 -0
  103. package/docs/api/foundation-state-machine.fetchconfig.responsedataextractor.md +13 -0
  104. package/docs/api/foundation-state-machine.fetchconfig.responseokchecker.md +13 -0
  105. package/docs/api/foundation-state-machine.fetchmachine.md +15 -0
  106. package/docs/api/foundation-state-machine.fetchmachinecontext.controller.md +13 -0
  107. package/docs/api/foundation-state-machine.fetchmachinecontext.data.md +13 -0
  108. package/docs/api/foundation-state-machine.fetchmachinecontext.md +28 -0
  109. package/docs/api/foundation-state-machine.fetchmachinecontext.params.md +17 -0
  110. package/docs/api/foundation-state-machine.fetchmachinecontext.response.md +13 -0
  111. package/docs/api/foundation-state-machine.fetchmachineevent.md +24 -0
  112. package/docs/api/foundation-state-machine.fetchmachineeventmap.md +21 -0
  113. package/docs/api/foundation-state-machine.fetchmachineoutput.md +21 -0
  114. package/docs/api/foundation-state-machine.genesisservererror._constructor_.md +22 -0
  115. package/docs/api/foundation-state-machine.genesisservererror.getdetailserror.md +15 -0
  116. package/docs/api/foundation-state-machine.genesisservererror.getmessageerror.md +15 -0
  117. package/docs/api/foundation-state-machine.genesisservererror.haserrorcode.md +22 -0
  118. package/docs/api/foundation-state-machine.genesisservererror.isignorableerror.md +17 -0
  119. package/docs/api/foundation-state-machine.genesisservererror.md +41 -0
  120. package/docs/api/foundation-state-machine.genesisservererror.received.md +11 -0
  121. package/docs/api/foundation-state-machine.genesisservererror.sent.md +11 -0
  122. package/docs/api/foundation-state-machine.isaborterror.md +15 -0
  123. package/docs/api/foundation-state-machine.isactorerrorevent.md +13 -0
  124. package/docs/api/foundation-state-machine.isapierror.md +11 -0
  125. package/docs/api/foundation-state-machine.isdoneinvokeevent.md +13 -0
  126. package/docs/api/foundation-state-machine.iserrorcustomevent.md +18 -0
  127. package/docs/api/foundation-state-machine.iserrorevent.md +13 -0
  128. package/docs/api/foundation-state-machine.iserrortype.md +13 -0
  129. package/docs/api/foundation-state-machine.isgenesisservererror.md +11 -0
  130. package/docs/api/foundation-state-machine.ismappingerror.md +11 -0
  131. package/docs/api/foundation-state-machine.isnetworkerror.md +11 -0
  132. package/docs/api/foundation-state-machine.isnotfounderror.md +13 -0
  133. package/docs/api/foundation-state-machine.issyntaxerror.md +15 -0
  134. package/docs/api/foundation-state-machine.istypeerror.md +15 -0
  135. package/docs/api/foundation-state-machine.logger.md +12 -0
  136. package/docs/api/foundation-state-machine.machine.actor.md +18 -0
  137. package/docs/api/foundation-state-machine.machine.binding.md +47 -0
  138. package/docs/api/foundation-state-machine.machine.complete.md +13 -0
  139. package/docs/api/foundation-state-machine.machine.context.md +13 -0
  140. package/docs/api/foundation-state-machine.machine.error.md +13 -0
  141. package/docs/api/foundation-state-machine.machine.errors.md +13 -0
  142. package/docs/api/foundation-state-machine.machine.getfromcontainer.md +35 -0
  143. package/docs/api/foundation-state-machine.machine.hastag.md +35 -0
  144. package/docs/api/foundation-state-machine.machine.machine.md +18 -0
  145. package/docs/api/foundation-state-machine.machine.matches.md +35 -0
  146. package/docs/api/foundation-state-machine.machine.md +101 -0
  147. package/docs/api/foundation-state-machine.machine.onsendevent.md +24 -0
  148. package/docs/api/foundation-state-machine.machine.output.md +13 -0
  149. package/docs/api/foundation-state-machine.machine.provide.md +44 -0
  150. package/docs/api/foundation-state-machine.machine.send.md +24 -0
  151. package/docs/api/foundation-state-machine.machine.start.md +28 -0
  152. package/docs/api/foundation-state-machine.machine.startingcontext.md +13 -0
  153. package/docs/api/foundation-state-machine.machine.startingstate.md +13 -0
  154. package/docs/api/foundation-state-machine.machine.state.md +13 -0
  155. package/docs/api/foundation-state-machine.machine.stop.md +17 -0
  156. package/docs/api/foundation-state-machine.machinecontext.error.md +13 -0
  157. package/docs/api/foundation-state-machine.machinecontext.errors.md +13 -0
  158. package/docs/api/foundation-state-machine.machinecontext.md +36 -0
  159. package/docs/api/foundation-state-machine.mappingerror._constructor_.md +21 -0
  160. package/docs/api/foundation-state-machine.mappingerror.dto.md +11 -0
  161. package/docs/api/foundation-state-machine.mappingerror.md +27 -0
  162. package/docs/api/foundation-state-machine.md +81 -0
  163. package/docs/api/foundation-state-machine.networkerror._constructor_.md +21 -0
  164. package/docs/api/foundation-state-machine.networkerror.md +31 -0
  165. package/docs/api/foundation-state-machine.networkerror.url.md +11 -0
  166. package/docs/api/foundation-state-machine.responsedataextractor.md +18 -0
  167. package/docs/api/foundation-state-machine.responseokchecker.md +13 -0
  168. package/docs/api/foundation-state-machine.seterror.md +25 -0
  169. package/docs/api/foundation-state-machine.seterrorbykey.md +25 -0
  170. package/docs/api/index.md +12 -0
  171. package/docs/api-report.md +393 -0
  172. package/license.txt +46 -0
  173. package/package.json +60 -0
@@ -0,0 +1,884 @@
1
+ /// <reference types="webappsec-credential-management" />
2
+
3
+ import { ActionArgs } from 'xstate';
4
+ import { AnyActorContext } from 'xstate';
5
+ import { AnyActorRef } from 'xstate';
6
+ import type { AnyEventObject } from 'xstate';
7
+ import { AnyState } from 'xstate';
8
+ import { Assigner } from 'xstate';
9
+ import { BindingObserver } from '@microsoft/fast-element';
10
+ import { Container } from '@microsoft/fast-foundation';
11
+ import { DelayExpr } from 'xstate';
12
+ import { DoneInvokeEvent } from 'xstate';
13
+ import { ErrorDetailMap } from '@genesislcap/foundation-utils';
14
+ import { ErrorEvent as ErrorEvent_2 } from 'xstate';
15
+ import { ErrorMap } from '@genesislcap/foundation-utils';
16
+ import { EventObject } from 'xstate';
17
+ import { ExecutionContext } from '@microsoft/fast-element';
18
+ import type { IBackoffFactory } from 'cockatiel';
19
+ import { ICancellationContext } from 'cockatiel';
20
+ import { IMergedPolicy } from 'cockatiel';
21
+ import { InterfaceSymbol } from '@microsoft/fast-foundation';
22
+ import type { InternalMachineImplementations } from 'xstate';
23
+ import type { InterpreterFrom } from 'xstate';
24
+ import type { InterpreterOptions } from 'xstate';
25
+ import type { IRetryBackoffContext } from 'cockatiel';
26
+ import { IRetryContext } from 'cockatiel';
27
+ import { Logger } from '@genesislcap/foundation-utils';
28
+ import { MachineContext as MachineContext_2 } from 'xstate';
29
+ import { Message } from '@genesislcap/foundation-comms';
30
+ import type { NoInfer } from 'xstate';
31
+ import { ParameterizedObject } from 'xstate';
32
+ import { PropertyAssigner } from 'xstate';
33
+ import type { ProvidedActor } from 'xstate';
34
+ import type { ResolveTypegenMeta } from 'xstate';
35
+ import { RetryPolicy } from 'cockatiel';
36
+ import { SendExpr } from 'xstate';
37
+ import type { StateMachine } from 'xstate';
38
+ import type { StateNodeConfig } from 'xstate';
39
+ import type { StateValue } from 'xstate';
40
+ import type { StateValueFrom } from 'xstate';
41
+ import { StatusCodes } from 'http-status-codes';
42
+ import { TimeoutPolicy } from 'cockatiel';
43
+ import type { TypegenDisabled } from 'xstate';
44
+ import { UnifiedArg } from 'xstate';
45
+
46
+ /**
47
+ * AbstractMachine base class.
48
+ * @public
49
+ */
50
+ export declare abstract class AbstractMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TAction extends ParameterizedObject = ParameterizedObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TActor>> implements Machine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta> {
51
+ /**
52
+ * @internal
53
+ */
54
+ protected container: Container;
55
+ /** {@inheritDoc Machine.machine} */
56
+ machine: StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>;
57
+ /** {@inheritDoc Machine.actor} */
58
+ actor: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
59
+ /** {@inheritDoc Machine.state} */
60
+ state: StateValue;
61
+ /** {@inheritDoc Machine.startingState} */
62
+ startingState: StateValue;
63
+ /** {@inheritDoc Machine.context} */
64
+ context: Partial<TContext>;
65
+ /** {@inheritDoc Machine.startingContext} */
66
+ startingContext: Partial<TContext>;
67
+ /** {@inheritDoc Machine.complete} */
68
+ complete: boolean;
69
+ /** {@inheritDoc Machine.output} */
70
+ output: any;
71
+ /** {@inheritDoc Machine.errors} */
72
+ errors: ErrorMap<ErrorDetailMap>;
73
+ /** {@inheritDoc Machine.error} */
74
+ error: any;
75
+ /**
76
+ * @internal
77
+ */
78
+ private subscription;
79
+ /** {@inheritDoc Machine.start} */
80
+ start(options?: InterpreterOptions<typeof AbstractMachine.machine>): void;
81
+ /** {@inheritDoc Machine.stop} */
82
+ stop(): void;
83
+ /**
84
+ * @internal
85
+ */
86
+ protected interpret(options?: InterpreterOptions<typeof AbstractMachine.machine>): void;
87
+ /**
88
+ * @internal
89
+ */
90
+ protected subscribe(): void;
91
+ /**
92
+ * @internal
93
+ */
94
+ protected unsubscribe(): void;
95
+ /**
96
+ * @internal
97
+ */
98
+ protected startActor(): void;
99
+ /**
100
+ * @internal
101
+ */
102
+ protected stopActor(): void;
103
+ /** {@inheritDoc Machine.provide} */
104
+ provide(implementations: InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, true>): void;
105
+ /** {@inheritDoc Machine.matches} */
106
+ matches(value: StateValueFrom<typeof AbstractMachine.machine>): boolean;
107
+ /** {@inheritDoc Machine.hasTag} */
108
+ hasTag(tag: string): boolean;
109
+ /** {@inheritDoc Machine.send} */
110
+ send(event: TEvent): void;
111
+ /** {@inheritDoc Machine.onSendEvent} */
112
+ onSendEvent: (event: CustomEvent<TEvent>) => void;
113
+ /** {@inheritDoc Machine.binding} */
114
+ binding<TReturn = any, TParent = any>(token: ((target: this) => TReturn) | keyof this, subscriberChangeCallback?: SubscriberChangeCallback<TReturn> | undefined, isVolatileBinding?: boolean, context?: ExecutionContext): BindingObserver<this, TReturn, TParent>;
115
+ /** {@inheritDoc Machine.getFromContainer} */
116
+ abstract getFromContainer(): this;
117
+ }
118
+
119
+ /**
120
+ * APIError.
121
+ * @remarks
122
+ * Bad server `Response`.
123
+ * @public
124
+ */
125
+ export declare class APIError extends Error {
126
+ status: number;
127
+ data?: unknown;
128
+ constructor(status: number, data?: unknown, message?: string);
129
+ }
130
+
131
+ /**
132
+ * assertEvent.
133
+ * @privateRemarks
134
+ * Note `asserts` need to be functions to work.
135
+ * @param event - An event.
136
+ * @param type - An event type.
137
+ * @public
138
+ */
139
+ export declare function assertEvent<TEvent extends EventObject = EventObject>(event: TEvent, type: TEvent['type']): asserts event is Extract<TEvent, {
140
+ type: TEvent['type'];
141
+ }>;
142
+
143
+ /**
144
+ * Creates an error state node.
145
+ *
146
+ * @param key - An error state key.
147
+ * @param metaContent - An optional meta content value.
148
+ * @param final - An optional flag which adds final with output functionality.
149
+ * @public
150
+ */
151
+ export declare const createErrorStateNode: (key: string, metaContent?: string, final?: boolean) => StateNodeConfig<any, any, any, any>;
152
+
153
+ /**
154
+ * A fetch policy factory.
155
+ * @remarks
156
+ * Will retry network errors and responses with certain status codes up to the specified max attempts.
157
+ * @param maxAttempts - Max attempts. Defaults to `2`.
158
+ * @param retryCodes - Status code array to retry. Defaults to {@link defaultRetryStatsCodes}.
159
+ * @param backoff - Backoff algo. Defaults to {@link cockatiel#ExponentialBackoff}.
160
+ * @param timeoutDuration - Timeout duration. Defaults to 3 seconds.
161
+ * @param logEvents - Log events to the console. Defaults to `true`.
162
+ * @public
163
+ */
164
+ export declare const createFetchPolicy: (maxAttempts?: number, retryCodes?: StatusCodes[] | number[], backoff?: IBackoffFactory<IRetryBackoffContext<unknown>>, timeoutDuration?: number, logEvents?: boolean) => IMergedPolicy<IRetryContext & ICancellationContext, never, [RetryPolicy, TimeoutPolicy]>;
165
+
166
+ /**
167
+ * Creates an extractor that applies a deserializer to the extracted response data.
168
+ * @param deserializer - The deserializer to apply.
169
+ * @param extractor - An optional data extractor. Defaults to {@link defaultResponseDataExtractor}.
170
+ * @public
171
+ */
172
+ export declare const createResponseDataExtractorWithDeserializer: <TInput = any, TOutput = any>(deserializer: (data: TInput) => Promise<TOutput>, extractor?: ResponseDataExtractor) => ResponseDataExtractor;
173
+
174
+ /**
175
+ * The default fetch config.
176
+ * @public
177
+ */
178
+ export declare const defaultFetchConfig: FetchConfig;
179
+
180
+ /**
181
+ * Default FetchMachine.
182
+ * @public
183
+ */
184
+ export declare class DefaultFetchMachine extends AbstractMachine<FetchMachineContext, FetchMachineEvent> implements FetchMachine {
185
+ private config;
186
+ constructor(config?: FetchConfig);
187
+ /** {@inheritDoc Machine.start} */
188
+ start(options?: InterpreterOptions<typeof DefaultFetchMachine.machine>): void;
189
+ /** {@inheritDoc Machine.getFromContainer} */
190
+ getFromContainer(): this;
191
+ }
192
+
193
+ /**
194
+ * Default FetchMachineContext.
195
+ * @public
196
+ */
197
+ export declare const defaultFetchMachineContext: Partial<FetchMachineContext>;
198
+
199
+ /**
200
+ * The default fetch policy.
201
+ * @public
202
+ */
203
+ export declare const defaultFetchPolicy: IMergedPolicy<IRetryContext & ICancellationContext, never, [RetryPolicy, TimeoutPolicy]>;
204
+
205
+ /**
206
+ * {@inheritDoc ResponseDataExtractor}
207
+ * @public
208
+ */
209
+ export declare const defaultResponseDataExtractor: ResponseDataExtractor;
210
+
211
+ /**
212
+ * {@inheritDoc ResponseOkChecker}
213
+ * @public
214
+ */
215
+ export declare const defaultResponseOkChecker: ResponseOkChecker;
216
+
217
+ /**
218
+ * Default retry stats codes.
219
+ * @public
220
+ */
221
+ export declare const defaultRetryStatsCodes: StatusCodes[];
222
+
223
+ /**
224
+ * ErrorWorkflowInput type.
225
+ * @public
226
+ */
227
+ export declare type ErrorWorkflowInput = {
228
+ errorKey: string;
229
+ errorValue: any;
230
+ errorMap: ErrorMap<ErrorDetailMap>;
231
+ };
232
+
233
+ /**
234
+ * Error workflow input.
235
+ * @param key - An error key.
236
+ * @public
237
+ */
238
+ export declare const errorWorkflowInput: (key: string) => ({ context }: {
239
+ context: any;
240
+ }) => ErrorWorkflowInput;
241
+
242
+ /**
243
+ * Escalate error action.
244
+ * @remarks
245
+ * Guard this call with a parent check to avoid warnings when there's no parent.
246
+ * @public
247
+ */
248
+ export declare const escalateError: {
249
+ (_: ActionArgs<MachineContext_2, EventObject, ParameterizedObject>): void;
250
+ type: string;
251
+ to: string | AnyActorRef | ((args: UnifiedArg<MachineContext_2, EventObject>) => string | AnyActorRef);
252
+ event: any;
253
+ id: string;
254
+ delay: string | number | DelayExpr<MachineContext_2, EventObject>;
255
+ resolve: (actorContext: AnyActorContext, state: AnyState, args: ActionArgs<any, any, ParameterizedObject>, { to, event: eventOrExpr, id, delay }: {
256
+ to: string | AnyActorRef | ((args: UnifiedArg<MachineContext_2, EventObject>) => string | AnyActorRef);
257
+ event: EventObject | SendExpr<MachineContext_2, EventObject, EventObject>;
258
+ id: string;
259
+ delay: string | number | DelayExpr<MachineContext_2, EventObject>;
260
+ }) => (AnyState | {
261
+ to: AnyActorRef;
262
+ event: EventObject;
263
+ id: string;
264
+ delay: number;
265
+ })[];
266
+ execute: (actorContext: AnyActorContext, params: {
267
+ to: AnyActorRef;
268
+ event: EventObject;
269
+ id: string;
270
+ delay: number;
271
+ }) => void;
272
+ };
273
+
274
+ /**
275
+ * FetchConfig interface.
276
+ * @public
277
+ */
278
+ export declare interface FetchConfig {
279
+ /**
280
+ * Defaults to {@link typescript#fetch}.
281
+ * @privateRemarks
282
+ * This config property allows us to mock {@link typescript#Response | responses} during testing.
283
+ */
284
+ fetcher: typeof fetch;
285
+ /**
286
+ * Defaults to {@link defaultFetchPolicy}
287
+ */
288
+ fetchPolicy?: IMergedPolicy<any, any, any>;
289
+ /**
290
+ * Defaults to {@link defaultResponseOkChecker}
291
+ */
292
+ responseOkChecker?: ResponseOkChecker;
293
+ /**
294
+ * Defaults to {@link defaultResponseDataExtractor}
295
+ */
296
+ responseDataExtractor?: ResponseDataExtractor;
297
+ }
298
+
299
+ /**
300
+ * FetchConfig DI key.
301
+ * @internal
302
+ */
303
+ export declare const FetchConfig: InterfaceSymbol<FetchConfig>;
304
+
305
+ /**
306
+ * FetchMachine interface.
307
+ * @public
308
+ */
309
+ export declare interface FetchMachine extends Machine<FetchMachineContext, FetchMachineEvent> {
310
+ }
311
+
312
+ /**
313
+ * FetchMachine DI key.
314
+ * @internal
315
+ */
316
+ export declare const FetchMachine: InterfaceSymbol<FetchMachine>;
317
+
318
+ /**
319
+ * FetchMachineContext interface.
320
+ * @remarks
321
+ * Transient state during the machine's execution.
322
+ * @public
323
+ */
324
+ export declare interface FetchMachineContext extends MachineContext {
325
+ /**
326
+ * The params of the fetch request.
327
+ */
328
+ params: {
329
+ url: string;
330
+ /**
331
+ * See {@link typescript#RequestInit} or {@link typescript#CMRequestInit}.
332
+ */
333
+ requestInit?: RequestInit | CMRequestInit;
334
+ /**
335
+ * Individual fetch requests can provide fetch config overrides when necessary.
336
+ */
337
+ fetchConfig?: FetchConfig;
338
+ };
339
+ /**
340
+ * The abort controller of the fetch request.
341
+ */
342
+ controller: AbortController;
343
+ /**
344
+ * The fetch response.
345
+ */
346
+ response: Response | undefined;
347
+ /**
348
+ * The extracted response data.
349
+ */
350
+ data: any;
351
+ }
352
+
353
+ /**
354
+ * FetchMachineEvent type.
355
+ * @remarks
356
+ * The send action events used to invoke the machine.
357
+ * @public
358
+ */
359
+ export declare type FetchMachineEvent = {
360
+ type: 'fetch';
361
+ params: FetchMachineContext['params'];
362
+ } | {
363
+ type: 'cancel';
364
+ } | DoneInvokeEvent<unknown> | ErrorEvent_2<unknown>;
365
+
366
+ /**
367
+ * FetchMachineEventMap type.
368
+ * @remarks
369
+ * The mediation CustomEvent used to invoke machine actions.
370
+ * @public
371
+ */
372
+ export declare type FetchMachineEventMap = {
373
+ 'fetch-machine-event': FetchMachineEvent;
374
+ };
375
+
376
+ /**
377
+ * FetchMachineOutput type.
378
+ * @remarks
379
+ * The output of the machine when it reaches it's final state, which is provided to host machines via handlers.
380
+ * @public
381
+ */
382
+ export declare type FetchMachineOutput<TData = any> = Partial<Pick<FetchMachineContext, 'response' | 'error'>> & {
383
+ data: TData;
384
+ };
385
+
386
+ /**
387
+ * GenesisServerError.
388
+ * @remarks
389
+ * Represents an error received from a Genesis Server.
390
+ * @public
391
+ */
392
+ export declare class GenesisServerError extends Error {
393
+ sent?: Message;
394
+ received?: Message;
395
+ constructor(sent?: Message, received?: Message, message?: string);
396
+ /**
397
+ * Capture known edge cases.
398
+ * @privateRemarks
399
+ * This is ugly, lets figure out if this is still an issue and remove if not.
400
+ */
401
+ isIgnorableError(): boolean;
402
+ getMessageError(): string;
403
+ getDetailsError(): string;
404
+ hasErrorCode(code: string): boolean;
405
+ private errorDetailFormatter;
406
+ }
407
+
408
+ /**
409
+ * @typeParam TTarget - The target interface.
410
+ * @param args - Binding args.
411
+ * @internal
412
+ */
413
+ export declare const getBindArgs: <TTarget = any>(...args: unknown[]) => TargetBinding<TTarget>;
414
+
415
+ /**
416
+ * isAbortError.
417
+ * @public
418
+ */
419
+ export declare const isAbortError: ({ event }: {
420
+ event: any;
421
+ }) => boolean;
422
+
423
+ /**
424
+ * isActorErrorEvent.
425
+ * @param actorId - An actor id.
426
+ * @param event - An event.
427
+ * @public
428
+ */
429
+ export declare const isActorErrorEvent: <TData = any>(actorId: string, event: EventObject | ErrorEvent_2<TData>) => event is ErrorEvent_2<TData>;
430
+
431
+ /**
432
+ * @param error - An error.
433
+ * @public
434
+ */
435
+ export declare const isAPIError: (error: unknown) => boolean;
436
+
437
+ /**
438
+ * isDoneInvokeEvent.
439
+ * @param event - An event.
440
+ * @public
441
+ */
442
+ export declare const isDoneInvokeEvent: <TData = any>(event: EventObject | DoneInvokeEvent<TData>) => event is DoneInvokeEvent<TData>;
443
+
444
+ /**
445
+ * isErrorCustomEvent.
446
+ * @remarks
447
+ * What `escalate` from a child is typed as.
448
+ * @param event - An event.
449
+ * @public
450
+ */
451
+ export declare const isErrorCustomEvent: <TData = any>(event: EventObject | ErrorEvent_2<TData>) => event is ErrorEvent_2<TData>;
452
+
453
+ /**
454
+ * isErrorEvent.
455
+ * @param event - An event.
456
+ * @public
457
+ */
458
+ export declare const isErrorEvent: <TData = any>(event: EventObject | ErrorEvent_2<TData>) => event is ErrorEvent_2<TData>;
459
+
460
+ /**
461
+ * isErrorType.
462
+ * @param type - An event type.
463
+ * @public
464
+ */
465
+ export declare const isErrorType: <TType extends ErrorConstructor>(type: TType) => (event: any) => boolean;
466
+
467
+ /**
468
+ * @param error - An error.
469
+ * @public
470
+ */
471
+ export declare const isGenesisServerError: (error: unknown) => boolean;
472
+
473
+ /**
474
+ * @param error - An error.
475
+ * @public
476
+ */
477
+ export declare const isMappingError: (error: unknown) => boolean;
478
+
479
+ /**
480
+ * @param error - An error.
481
+ * @public
482
+ */
483
+ export declare const isNetworkError: (error: unknown) => boolean;
484
+
485
+ /**
486
+ * @param error - An error.
487
+ * @public
488
+ */
489
+ export declare const isNotFoundError: (error: {
490
+ status?: number;
491
+ }) => boolean;
492
+
493
+ /**
494
+ * isSyntaxError.
495
+ * @public
496
+ */
497
+ export declare const isSyntaxError: ({ event }: {
498
+ event: any;
499
+ }) => boolean;
500
+
501
+ /**
502
+ * isTypeError.
503
+ * @public
504
+ */
505
+ export declare const isTypeError: ({ event }: {
506
+ event: any;
507
+ }) => boolean;
508
+
509
+ /**
510
+ * @public
511
+ */
512
+ export declare const logger: Logger;
513
+
514
+ /**
515
+ * Machine interface.
516
+ *
517
+ * @remarks
518
+ * The interface of our xstate based machines or logic workflows. These contain bindable properties for convenience.
519
+ * Should be extended.
520
+ *
521
+ * @example Creating a machine in the DI.
522
+ * ```ts
523
+ * export interface MyMachine extends Machine<MyMachineContext, MyMachineEvent> {
524
+ * readonly service: MyService;
525
+ * ...
526
+ * }
527
+ * export class DefaultMyMachine
528
+ * extends AbstractMachine<MyMachineContext, MyMachineEvent>
529
+ * implements MyMachine
530
+ * {
531
+ * constructor(@MyService readonly service: MyService) {
532
+ * super();
533
+ * this.machine = createMachine<MyMachineContext, MyMachineEvent>(...);
534
+ * this.start(); // < Call now or later to ready the machine.
535
+ * }
536
+ * start(
537
+ * options: InterpreterOptions<typeof this.machine> = {
538
+ * input: myDefaultContext,
539
+ * },
540
+ * ) {
541
+ * super.start(options);
542
+ * }
543
+ * }
544
+ * // Whether the machine should be `transient` or a `singleton` probably depends on the use case and if it contains a `final` state.
545
+ * export const MyMachine = DI.createInterface<MyMachine>((x) => x.transient(DefaultMyMachine));
546
+ * ```
547
+ *
548
+ * Machines are bindable from templates and other logic.
549
+ *
550
+ * @example Surface errors in a template.
551
+ * ```ts
552
+ * ${when(
553
+ * (x) => !!x.myMachine.errors.size,
554
+ * html<MyComponent>`
555
+ * <span>${(x) => x.myMachine.errors.messages}</span>
556
+ * `,
557
+ * )}
558
+ * ```
559
+ *
560
+ * @example Use context data in a class.
561
+ * ```ts
562
+ * this.myMachine.binding((x) => x.context.data, (value) => {
563
+ * // use data
564
+ * });
565
+ * ```
566
+ *
567
+ * @public
568
+ */
569
+ export declare interface Machine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TAction extends ParameterizedObject = ParameterizedObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TActor>> {
570
+ /**
571
+ * Mandatory machine property.
572
+ * @remarks
573
+ * The logic / config that goes into a machine is not accessible from the outside, and is owned by the implementing
574
+ * class. However, consumers of that may provide custom `implementations` in the xstate sense via the `provide()` api.
575
+ */
576
+ readonly machine: StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>;
577
+ /**
578
+ * Optional actor
579
+ * @remarks
580
+ * Callers can decide to reuse/reference if set or create their own.
581
+ */
582
+ readonly actor?: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
583
+ /**
584
+ * The current `state` of the machine itself. This is not to be confused with state in the data or store sense.
585
+ */
586
+ readonly state: StateValue;
587
+ /**
588
+ * The `state` of the machine when started. Allows consumers to start a machine from a persisted state.
589
+ */
590
+ readonly startingState: StateValue;
591
+ /**
592
+ * The current `context` of the machine. The data points in context may be considered transient in nature.
593
+ *
594
+ * @privateRemarks
595
+ * Review the possibility of using an object with `@observable` properties as `context`, such as a store fragment or class.
596
+ */
597
+ readonly context: Partial<TContext>;
598
+ /**
599
+ * The `context` of the machine when started.
600
+ */
601
+ readonly startingContext: Partial<TContext>;
602
+ /**
603
+ * Indicates if the machine has completed the happy path.
604
+ */
605
+ readonly complete: boolean;
606
+ /**
607
+ * Holds successful machine output if any.
608
+ */
609
+ readonly output: any;
610
+ /**
611
+ * An {@link @genesislcap/foundation-utils#ErrorMap | ErrorMap} of errors that may have occurred during the machine's workflows.
612
+ */
613
+ readonly errors: ErrorMap<ErrorDetailMap>;
614
+ /**
615
+ * A general machine error. Likely equal to `errors.lastError`.
616
+ */
617
+ readonly error: any;
618
+ /**
619
+ * Start the machine.
620
+ *
621
+ * @remarks
622
+ * Called to ready the machine and create the internal actor (interpreter). This is called internally after
623
+ * `createMachine` by convention, however it should also be called after calling {@link Machine.provide | provide}
624
+ * when overriding logic. Calling `start` on an injected machine allows you to restart/reuse it if needed. This is okay
625
+ * for machines registered as `transient` in the DI, but care should be taken when creating a machine registered as a
626
+ * `singleton`. You may need to check the status of the machine and block re-starts.
627
+ *
628
+ * @param options - Optional InterpreterOptions. Can be used to restore to a previously persisted state.
629
+ */
630
+ start(options?: InterpreterOptions<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>): any;
631
+ /**
632
+ * Stop the machine.
633
+ */
634
+ stop(): void;
635
+ /**
636
+ * Recreate the internal machine with the provided implementations.
637
+ *
638
+ * @example Using an existing machine with a custom implementation.
639
+ * ```ts
640
+ * @MyMachine readonly machine: MyMachine;
641
+ * ...
642
+ * this.machine.provide({
643
+ * actors: {
644
+ * serviceCallX: fromPromise(async ({ input }) => Promise.resolve(new Error('Overridden serviceCallX'))),
645
+ * onSuccess: (context) => successHandlerInHost(context.data)
646
+ * },
647
+ * guards: {
648
+ * isAssured: ({ context }) => true,
649
+ * },
650
+ * });
651
+ * // When you change the machine it will stop if running, so you'll have to call {@link Machine.start | start} again.
652
+ * this.machine.start();
653
+ * ```
654
+ *
655
+ * @param implementations - `actions`, `guards`, `actors`... to merge with existing options.
656
+ */
657
+ provide(implementations: InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, true>): void;
658
+ /**
659
+ * Check `state` matches provided value.
660
+ *
661
+ * @remarks
662
+ * Can be useful if you need to conditionally run logic or render markup.
663
+ *
664
+ * @example
665
+ * ```ts
666
+ * if (machine.matches('inactive')) { ... }
667
+ * ```
668
+ *
669
+ * @param value - A state value.
670
+ */
671
+ matches(value: StateValueFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>): boolean;
672
+ /**
673
+ * Check `tags` contain provided tag.
674
+ *
675
+ * @remarks
676
+ * This differs from `matches`, as multiple states may use common tags such as `pending` to indicate some async work
677
+ * is occurring. As with `matches`, `hasTag` can be useful if you need to conditionally run logic or render markup.
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * if (machine.hasTag('pending')) { ... }
682
+ * ```
683
+ *
684
+ * @param tag - A tag.
685
+ */
686
+ hasTag(tag: string): boolean;
687
+ /**
688
+ * An api to send events to the machine.
689
+ *
690
+ * @param event - An event.
691
+ */
692
+ send(event: TEvent): void;
693
+ /**
694
+ * A custom event handler to send events to the machine.
695
+ *
696
+ * @param event - A custom event.
697
+ */
698
+ onSendEvent(event: CustomEvent<TEvent>): void;
699
+ /**
700
+ * An api to allow the observation of values and arbitrary bindings outside the template engine.
701
+ *
702
+ * @example
703
+ * TS attains the value type information from the machine's interface.
704
+ * ```ts
705
+ * this.myMachine.binding(x => x.context.data, value => {...}); // value is typeof data
706
+ * ```
707
+ *
708
+ * @example
709
+ * You can also use the underlying BindingObserver api should you prefer.
710
+ * ```ts
711
+ * this.myMachine.binding(x => x.error).subscribe({
712
+ * handleChange(binding, args) {
713
+ * ...
714
+ * }
715
+ * })
716
+ * ```
717
+ *
718
+ * @param token - A target lookup token which can take various forms.
719
+ * @param subscriberChangeCallback - {@link SubscriberChangeCallback}.
720
+ * @param isVolatileBinding - Indicates the binding is volatile.
721
+ * @param context - {@link @microsoft/fast-element#ExecutionContext}.
722
+ *
723
+ * @public
724
+ */
725
+ binding<TReturn = any, TParent = any>(token: ((target: this) => TReturn) | keyof this, subscriberChangeCallback?: SubscriberChangeCallback<TReturn> | undefined, isVolatileBinding?: boolean, context?: ExecutionContext): BindingObserver<this, TReturn, TParent>;
726
+ /**
727
+ * Gets the machine from the container.
728
+ *
729
+ * @remarks
730
+ * Calling `getFromContainer` on an injected machine will return a new instance providing it was registered with the
731
+ * DI as `transient`. This is simply a convenience method, and may be useful as some machines contain 'final' states,
732
+ * meaning once they complete they can no longer receive events. However, if you want to continue to work with your
733
+ * injected machine reference, re-calling {@link Machine.start | start} may also be a viable option.
734
+ *
735
+ * Please note that machines are injected into other machines to form parts of complex workflows. In such cases,
736
+ * the parent machine will `invoke` or `spawn` the injected machine's `logic` directly to always create a new actor.
737
+ *
738
+ * @example Invoke an injected machine's `logic` from a parent machine
739
+ * ```ts
740
+ * invoke: {
741
+ * id: 'dataFetcher',
742
+ * src: fetchMachine.machine, // < Or `src: 'fetcher'`, and create that actor to interact with the injected machine.
743
+ * ...
744
+ * }
745
+ * ```
746
+ */
747
+ getFromContainer(): this;
748
+ }
749
+
750
+ /**
751
+ * MachineContext interface.
752
+ *
753
+ * @remarks
754
+ * The interface of our xstate based machine contexts that include `error` and `errors` properties. Should be extended.
755
+ *
756
+ * @example Creating a machine context.
757
+ * ```ts
758
+ * export interface MyMachineContext extends MachineContext {
759
+ * ...
760
+ * };
761
+ * ```
762
+ *
763
+ * @public
764
+ */
765
+ export declare interface MachineContext extends MachineContext_2 {
766
+ /**
767
+ * A `ErrorMap` of errors that may have occurred during the machine's workflows.
768
+ */
769
+ readonly errors: ErrorMap<ErrorDetailMap>;
770
+ /**
771
+ * A general machine error. Maybe equal to `errors.lastError`.
772
+ */
773
+ readonly error: any;
774
+ }
775
+
776
+ /**
777
+ * MappingError.
778
+ * @public
779
+ */
780
+ export declare class MappingError extends Error {
781
+ dto?: unknown;
782
+ constructor(dto?: unknown, message?: string);
783
+ }
784
+
785
+ /**
786
+ * NetworkError.
787
+ * @remarks
788
+ * Failed to reach server.
789
+ * @public
790
+ */
791
+ export declare class NetworkError extends Error {
792
+ url: string;
793
+ constructor(url: string, message?: string);
794
+ }
795
+
796
+ /**
797
+ * ResponseDataExtractor type.
798
+ * @remarks
799
+ * Extracts data from the {@link typescript#Response} and processes it accordingly. The default data extractor will inspect
800
+ * `content-type` and call `JSON.parse()` if it includes `application/json`. Custom data extractors can be used here.
801
+ * @privateRemarks
802
+ * Need to find out if the Genesis http layer returns mixed responses. If needed we can catch and return just the text.
803
+ * @typeParam TData - The expected data type. Defaults to any;
804
+ * @param response - The {@link typescript#Response}.
805
+ * @returns The extracted data.
806
+ * @public
807
+ */
808
+ export declare type ResponseDataExtractor<TData = any> = (response: Response) => Promise<TData>;
809
+
810
+ /**
811
+ * ResponseOkChecker type.
812
+ * @privateRemarks
813
+ * Genesis HTTP-Based APIs may provide unexpected status codes, so special handling can be required.
814
+ * @param response - The {@link typescript#Response}.
815
+ * @returns A boolean to indicate if the response is ok.
816
+ * @public
817
+ */
818
+ export declare type ResponseOkChecker = (response: Response) => boolean;
819
+
820
+ /**
821
+ * Set error action.
822
+ * @remarks
823
+ * Used to set a top level error on the machine. This may equal to {@link @genesislcap/foundation-utils#ErrorMap} `lastError` in the `errors` property.
824
+ * @public
825
+ */
826
+ export declare const setError: {
827
+ (_: ActionArgs<MachineContext_2, EventObject, ParameterizedObject>): void;
828
+ type: string;
829
+ assignment: Assigner<MachineContext_2, EventObject> | PropertyAssigner<MachineContext_2, EventObject>;
830
+ resolve: (actorContext: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any, ParameterizedObject>, { assignment }: {
831
+ assignment: Assigner<any, any> | PropertyAssigner<any, any>;
832
+ }) => AnyState[];
833
+ };
834
+
835
+ /**
836
+ * Set error by key action.
837
+ * @remarks
838
+ * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
839
+ * @param key - The error key.
840
+ * @public
841
+ */
842
+ export declare const setErrorByKey: (key: string) => {
843
+ (_: ActionArgs<MachineContext_2, EventObject, ParameterizedObject>): void;
844
+ type: string;
845
+ assignment: Assigner<MachineContext_2, EventObject> | PropertyAssigner<MachineContext_2, EventObject>;
846
+ resolve: (actorContext: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any, ParameterizedObject>, { assignment }: {
847
+ assignment: Assigner<any, any> | PropertyAssigner<any, any>;
848
+ }) => AnyState[];
849
+ };
850
+
851
+ /**
852
+ * @typeParam TReturn - The return type.
853
+ * @param value - The bound value.
854
+ * @param args - A binding observer.
855
+ * @internal
856
+ */
857
+ export declare type SubscriberChangeCallback<TReturn = any> = (value: TReturn, args: BindingObserver) => void;
858
+
859
+ /**
860
+ * @typeParam TTarget - The target interface.
861
+ * @typeParam TReturn - The return type.
862
+ * @param binding - A binding.
863
+ * @param args - A binding observer.
864
+ * @internal
865
+ */
866
+ export declare type SubscriberChangeHandler<TTarget = any, TReturn = any> = (binding: (x?: TTarget, context?: ExecutionContext) => TReturn, args: BindingObserver) => void;
867
+
868
+ /**
869
+ * @typeParam TTarget - The target interface.
870
+ * @param target - The target.
871
+ * @internal
872
+ */
873
+ export declare type TargetBinding<TTarget = any> = (target: TTarget) => any;
874
+
875
+ /**
876
+ * @typeParam TTarget - The target interface.
877
+ * @typeParam TReturn - The return type.
878
+ * @internal
879
+ */
880
+ export declare interface TargetSubscriber<TTarget = any, TReturn = any> {
881
+ handleChange: SubscriberChangeHandler<TTarget, TReturn>;
882
+ }
883
+
884
+ export { }