@genesislcap/foundation-state-machine 14.95.0 → 14.96.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/dts/core/actions.d.ts +6 -1
  2. package/dist/dts/core/actions.d.ts.map +1 -1
  3. package/dist/dts/core/errors.d.ts +2 -2
  4. package/dist/dts/core/errors.d.ts.map +1 -1
  5. package/dist/dts/core/guards.d.ts +7 -1
  6. package/dist/dts/core/guards.d.ts.map +1 -1
  7. package/dist/dts/core/machine.d.ts +28 -1
  8. package/dist/dts/core/machine.d.ts.map +1 -1
  9. package/dist/dts/core/state.d.ts.map +1 -1
  10. package/dist/dts/machines/fetch/errors.d.ts +14 -3
  11. package/dist/dts/machines/fetch/errors.d.ts.map +1 -1
  12. package/dist/esm/core/actions.js +23 -8
  13. package/dist/esm/core/guards.js +6 -0
  14. package/dist/esm/core/machine.js +39 -12
  15. package/dist/esm/core/state.js +18 -6
  16. package/dist/esm/machines/fetch/errors.js +11 -0
  17. package/dist/esm/machines/fetch/policies.js +5 -5
  18. package/dist/foundation-state-machine.api.json +464 -11
  19. package/dist/foundation-state-machine.d.ts +59 -7
  20. package/docs/api/foundation-state-machine.abstractmachine.getmetavaluesbykey.md +28 -0
  21. package/docs/api/foundation-state-machine.abstractmachine.md +3 -0
  22. package/docs/api/foundation-state-machine.abstractmachine.meta.md +13 -0
  23. package/docs/api/foundation-state-machine.abstractmachine.snapshot.md +13 -0
  24. package/docs/api/foundation-state-machine.apierror.isunauthorized.md +16 -0
  25. package/docs/api/foundation-state-machine.apierror.md +6 -0
  26. package/docs/api/foundation-state-machine.escalateerror.md +1 -1
  27. package/docs/api/foundation-state-machine.isapierror.md +1 -1
  28. package/docs/api/foundation-state-machine.iseventwithparams.md +13 -0
  29. package/docs/api/foundation-state-machine.isgenesisservererror.md +1 -1
  30. package/docs/api/foundation-state-machine.ismappingerror.md +1 -1
  31. package/docs/api/foundation-state-machine.isnetworkerror.md +1 -1
  32. package/docs/api/foundation-state-machine.isnotfounderror.md +1 -1
  33. package/docs/api/foundation-state-machine.isunauthorizederror.md +13 -0
  34. package/docs/api/foundation-state-machine.machine.getmetavaluesbykey.md +28 -0
  35. package/docs/api/foundation-state-machine.machine.md +3 -0
  36. package/docs/api/foundation-state-machine.machine.meta.md +13 -0
  37. package/docs/api/foundation-state-machine.machine.snapshot.md +13 -0
  38. package/docs/api/foundation-state-machine.md +3 -1
  39. package/docs/api-report.md +25 -6
  40. package/package.json +7 -7
@@ -2,6 +2,8 @@
2
2
  * Set error action.
3
3
  * @remarks
4
4
  * Used to set a top level error on the machine. This may equal to {@link @genesislcap/foundation-utils#ErrorMap} `lastError` in the `errors` property.
5
+ * @privateRemarks
6
+ * Contains done event handling to deal with 200 Nacks.
5
7
  * @public
6
8
  */
7
9
  export declare const setError: {
@@ -16,6 +18,9 @@ export declare const setError: {
16
18
  * Set error by key action.
17
19
  * @remarks
18
20
  * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
21
+ * @privateRemarks
22
+ * Contains done event handling to deal with 200 Nacks. If done output is an error use it, or fallback to `context.error`
23
+ * and set that under the provided key.
19
24
  * @param key - The error key.
20
25
  * @public
21
26
  */
@@ -28,7 +33,7 @@ export declare const setErrorByKey: (key: string) => {
28
33
  }) => import("xstate").AnyState[];
29
34
  };
30
35
  /**
31
- * Escalate error action.
36
+ * Escalate context error action.
32
37
  * @remarks
33
38
  * Guard this call with a parent check to avoid warnings when there's no parent.
34
39
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOnB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM;;;;;;;CASrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAGvB,CAAC"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/core/actions.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAYnB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM;;;;;;;CAgBrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAA2C,CAAC"}
@@ -24,7 +24,7 @@ export declare class GenesisServerError extends Error {
24
24
  * @param error - An error.
25
25
  * @public
26
26
  */
27
- export declare const isGenesisServerError: (error: unknown) => boolean;
27
+ export declare const isGenesisServerError: (error: unknown) => error is GenesisServerError;
28
28
  /**
29
29
  * MappingError.
30
30
  * @public
@@ -37,5 +37,5 @@ export declare class MappingError extends Error {
37
37
  * @param error - An error.
38
38
  * @public
39
39
  */
40
- export declare const isMappingError: (error: unknown) => boolean;
40
+ export declare const isMappingError: (error: unknown) => error is MappingError;
41
41
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,IAAI,CAAC,EAAE,OAAO;IACd,QAAQ,CAAC,EAAE,OAAO;gBADlB,IAAI,CAAC,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,OAAO,EACzB,OAAO,GAAE,MAAwC;IAOnD;;;;OAIG;IACH,gBAAgB;IAUhB,eAAe;IAMf,eAAe,IAAI,MAAM;IAMzB,YAAY,CAAC,IAAI,EAAE,MAAM;IAMzB,OAAO,CAAC,oBAAoB;CAG7B;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,YAAwC,CAAC;AAE5F;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,CAAC,EAAE,OAAO;gBAAb,GAAG,CAAC,EAAE,OAAO,EACpB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,YAAkC,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,IAAI,CAAC,EAAE,OAAO;IACd,QAAQ,CAAC,EAAE,OAAO;gBADlB,IAAI,CAAC,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,OAAO,EACzB,OAAO,GAAE,MAAwC;IAOnD;;;;OAIG;IACH,gBAAgB;IAUhB,eAAe;IAMf,eAAe,IAAI,MAAM;IAMzB,YAAY,CAAC,IAAI,EAAE,MAAM;IAMzB,OAAO,CAAC,oBAAoB;CAG7B;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,UAAW,OAAO,gCACd,CAAC;AAEtC;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,CAAC,EAAE,OAAO;gBAAb,GAAG,CAAC,EAAE,OAAO,EACpB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,0BACd,CAAC"}
@@ -1,4 +1,4 @@
1
- import { DoneInvokeEvent, ErrorEvent, EventObject } from 'xstate';
1
+ import { AnyEventObject, DoneInvokeEvent, ErrorEvent, EventObject, ParameterizedObject } from 'xstate';
2
2
  /**
3
3
  * assertEvent.
4
4
  * @privateRemarks
@@ -37,6 +37,12 @@ export declare const isErrorCustomEvent: <TData = any>(event: EventObject | Erro
37
37
  * @public
38
38
  */
39
39
  export declare const isActorErrorEvent: <TData = any>(actorId: string, event: EventObject | ErrorEvent<TData>) => event is ErrorEvent<TData>;
40
+ /**
41
+ * isEventWithParams.
42
+ * @param event - An event.
43
+ * @public
44
+ */
45
+ export declare const isEventWithParams: (event: AnyEventObject) => event is ParameterizedObject;
40
46
  /**
41
47
  * isErrorType.
42
48
  * @param type - An event type.
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../../src/core/guards.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAElE;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,EAClE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,GACnB,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAI5D;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,+FAEuC,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,YAAY,qFAE0C,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,qFAEkC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,yBACnB,MAAM,uEAE8E,CAAC;AAEhG;;;;GAIG;AACH,eAAO,MAAM,WAAW,0EAOrB,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,WAAW;;aAA+C,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,aAAa;;aAAiD,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,YAAY;;aAQxB,CAAC"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../../src/core/guards.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,eAAe,EACf,UAAU,EACV,WAAW,EACX,mBAAmB,EACpB,MAAM,QAAQ,CAAC;AAEhB;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,EAClE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,GACnB,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAI5D;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,+FAEuC,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,YAAY,qFAE0C,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,qFAEkC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,yBACnB,MAAM,uEAE8E,CAAC;AAEhG;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAAW,cAAc,iCAC3B,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,WAAW,0EAOrB,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,WAAW;;aAA+C,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,aAAa;;aAAiD,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,YAAY;;aAQxB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ErrorDetailMap, ErrorMap } from '@genesislcap/foundation-utils';
2
2
  import { BindingObserver, ExecutionContext } from '@microsoft/fast-element';
3
3
  import { Container } from '@microsoft/fast-foundation';
4
- import type { AnyEventObject, EventObject, InternalMachineImplementations, InterpreterFrom, InterpreterOptions, MachineContext as XMachineContext, NoInfer, ParameterizedObject, ProvidedActor, ResolveTypegenMeta, StateMachine, StateValue, StateValueFrom, TypegenDisabled } from 'xstate';
4
+ import type { AnyEventObject, EventObject, InternalMachineImplementations, InterpreterFrom, InterpreterOptions, MachineContext as XMachineContext, NoInfer, ParameterizedObject, ProvidedActor, ResolveTypegenMeta, State, StateMachine, StateValue, StateValueFrom, TypegenDisabled } from 'xstate';
5
5
  import { SubscriberChangeCallback } from './binding';
6
6
  /**
7
7
  * MachineContext interface.
@@ -97,6 +97,10 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
97
97
  * Callers can decide to reuse/reference if set or create their own.
98
98
  */
99
99
  readonly actor?: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
100
+ /**
101
+ * The last `snapshot` from the actor.
102
+ */
103
+ readonly snapshot: State<TContext, TEvent, TActor, TResolvedTypesMeta>;
100
104
  /**
101
105
  * The current `state` of the machine itself. This is not to be confused with state in the data or store sense.
102
106
  */
@@ -116,6 +120,10 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
116
120
  * The `context` of the machine when started.
117
121
  */
118
122
  readonly startingContext: Partial<TContext>;
123
+ /**
124
+ * The `meta` from the current `state`.
125
+ */
126
+ readonly meta: Record<string, any>;
119
127
  /**
120
128
  * Indicates if the machine has completed the happy path.
121
129
  */
@@ -201,6 +209,15 @@ export interface Machine<TContext extends MachineContext, TEvent extends EventOb
201
209
  * @param tag - A tag.
202
210
  */
203
211
  hasTag(tag: string): boolean;
212
+ /**
213
+ * Get `meta` values by key.
214
+ *
215
+ * @remarks
216
+ * Meta is cumulative across all state nodes represented by the state value.
217
+ *
218
+ * @param key - A key within the `meta` object. Defaults to `content`.
219
+ */
220
+ getMetaValuesByKey<T = string>(key?: string): T[];
204
221
  /**
205
222
  * An api to send events to the machine.
206
223
  *
@@ -276,6 +293,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
276
293
  machine: StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>;
277
294
  /** {@inheritDoc Machine.actor} */
278
295
  actor: InterpreterFrom<StateMachine<TContext, TEvent, TAction, TActor, TInput, TResolvedTypesMeta>>;
296
+ /** {@inheritDoc Machine.snapshot} */
297
+ snapshot: State<TContext, TEvent, TActor, TResolvedTypesMeta>;
279
298
  /** {@inheritDoc Machine.state} */
280
299
  state: StateValue;
281
300
  /** {@inheritDoc Machine.startingState} */
@@ -284,6 +303,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
284
303
  context: Partial<TContext>;
285
304
  /** {@inheritDoc Machine.startingContext} */
286
305
  startingContext: Partial<TContext>;
306
+ /** {@inheritDoc Machine.meta} */
307
+ meta: Record<string, any>;
287
308
  /** {@inheritDoc Machine.complete} */
288
309
  complete: boolean;
289
310
  /** {@inheritDoc Machine.output} */
@@ -308,6 +329,10 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
308
329
  * @internal
309
330
  */
310
331
  protected subscribe(): void;
332
+ /**
333
+ * @internal
334
+ */
335
+ protected applySnapshot(snapshot?: typeof this.snapshot): void;
311
336
  /**
312
337
  * @internal
313
338
  */
@@ -326,6 +351,8 @@ export declare abstract class AbstractMachine<TContext extends MachineContext, T
326
351
  matches(value: StateValueFrom<typeof this.machine>): boolean;
327
352
  /** {@inheritDoc Machine.hasTag} */
328
353
  hasTag(tag: string): boolean;
354
+ /** {@inheritDoc Machine.getMetaValuesByKey} */
355
+ getMetaValuesByKey<T = string>(key?: string): T[];
329
356
  /** {@inheritDoc Machine.send} */
330
357
  send(event: TEvent): void;
331
358
  /** {@inheritDoc Machine.onSendEvent} */
@@ -1 +1 @@
1
- {"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../../../src/core/machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,EACL,eAAe,EAEf,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,8BAA8B,EAC9B,eAAe,EACf,kBAAkB,EAClB,cAAc,IAAI,eAAe,EACjC,OAAO,EACP,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,EAEd,eAAe,EAChB,MAAM,QAAQ,CAA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AClC,OAAO,GAAE,gBAA0C,GAClD,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC;IAc1C,6CAA6C;IAC7C,QAAQ,CAAC,gBAAgB,IAAI,IAAI;CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/core/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAC1B,MAAM,gBACG,MAAM,UACb,OAAO,KACb,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAgBpC,CAAC"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/core/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAC1B,MAAM,gBACG,MAAM,UACb,OAAO,KACb,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CA4BpC,CAAC"}
@@ -18,22 +18,33 @@ export declare class APIError extends Error {
18
18
  status: number;
19
19
  data?: unknown;
20
20
  constructor(status: number, data?: unknown, message?: string);
21
+ /**
22
+ * @public
23
+ */
24
+ isUnauthorized(): boolean;
21
25
  }
22
26
  /**
23
27
  * @param error - An error.
24
28
  * @public
25
29
  */
26
- export declare const isAPIError: (error: unknown) => boolean;
30
+ export declare const isAPIError: (error: unknown) => error is APIError;
27
31
  /**
28
32
  * @param error - An error.
29
33
  * @public
30
34
  */
31
- export declare const isNetworkError: (error: unknown) => boolean;
35
+ export declare const isNetworkError: (error: unknown) => error is NetworkError;
32
36
  /**
33
37
  * @param error - An error.
34
38
  * @public
35
39
  */
36
40
  export declare const isNotFoundError: (error: {
37
41
  status?: number;
38
- }) => boolean;
42
+ }) => error is APIError;
43
+ /**
44
+ * @param error - An error.
45
+ * @public
46
+ */
47
+ export declare const isUnauthorizedError: (error: {
48
+ status?: number;
49
+ }) => error is APIError;
39
50
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAClB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,OAAO;gBADd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACrB,OAAO,GAAE,MAA6B;CAMzC;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,YAA8B,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,YAEwB,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,eAAe,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,YACG,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAE5B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAClB,OAAO,GAAE,MAAiC;CAM7C;AAED;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,CAAC,EAAE,OAAO;gBADd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACrB,OAAO,GAAE,MAA6B;IAOxC;;OAEG;IACH,cAAc;CAGf;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,OAAO,sBAAiD,CAAC;AAE3F;;;GAGG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,0BAEwB,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,eAAe,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,sBACG,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAW;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,sBACjB,CAAC"}
@@ -2,45 +2,60 @@ import { createErrorMap } from '@genesislcap/foundation-utils';
2
2
  import { assign } from 'xstate';
3
3
  import { escalate } from 'xstate/actions';
4
4
  import { logger } from '../utils';
5
- import { isErrorEvent } from './guards';
5
+ import { isDoneInvokeEvent, isErrorEvent } from './guards';
6
6
  /**
7
7
  * Set error action.
8
8
  * @remarks
9
9
  * Used to set a top level error on the machine. This may equal to {@link @genesislcap/foundation-utils#ErrorMap} `lastError` in the `errors` property.
10
+ * @privateRemarks
11
+ * Contains done event handling to deal with 200 Nacks.
10
12
  * @public
11
13
  */
12
14
  export const setError = assign(({ event }) => {
13
- logger.debug('setError', event, isErrorEvent(event));
14
15
  if (isErrorEvent(event)) {
15
16
  return {
16
17
  error: event.data,
17
18
  };
18
19
  }
20
+ if (isDoneInvokeEvent(event)) {
21
+ logger.debug(`setError action called with non error event type.`, event);
22
+ return {
23
+ error: event.output,
24
+ };
25
+ }
19
26
  });
20
27
  /**
21
28
  * Set error by key action.
22
29
  * @remarks
23
30
  * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
31
+ * @privateRemarks
32
+ * Contains done event handling to deal with 200 Nacks. If done output is an error use it, or fallback to `context.error`
33
+ * and set that under the provided key.
24
34
  * @param key - The error key.
25
35
  * @public
26
36
  */
27
37
  export const setErrorByKey = (key) => assign(({ context, event }) => {
28
38
  var _a;
39
+ let error;
29
40
  if (isErrorEvent(event)) {
41
+ error = event.data;
42
+ }
43
+ else if (isDoneInvokeEvent(event)) {
44
+ logger.debug(`setErrorByKey action called with non error event type.`, event);
45
+ error = event.output instanceof Error ? event.output : context.error;
46
+ }
47
+ if (error) {
30
48
  const errors = (_a = context.errors) !== null && _a !== void 0 ? _a : createErrorMap(logger.error);
31
- errors.set(key, event.data);
49
+ errors.set(key, error);
32
50
  return {
33
51
  errors,
34
52
  };
35
53
  }
36
54
  });
37
55
  /**
38
- * Escalate error action.
56
+ * Escalate context error action.
39
57
  * @remarks
40
58
  * Guard this call with a parent check to avoid warnings when there's no parent.
41
59
  * @public
42
60
  */
43
- export const escalateError = escalate(({ context }) => ({
44
- error: context.error,
45
- data: context.error,
46
- }));
61
+ export const escalateError = escalate(({ context }) => context.error);
@@ -39,6 +39,12 @@ export const isErrorCustomEvent = (event) => /^xstate.error/.test(event.type);
39
39
  * @public
40
40
  */
41
41
  export const isActorErrorEvent = (actorId, event) => { var _a, _b; return ((_a = event.type) === null || _a === void 0 ? void 0 : _a.includes('error')) && ((_b = event.type) === null || _b === void 0 ? void 0 : _b.includes(actorId)); };
42
+ /**
43
+ * isEventWithParams.
44
+ * @param event - An event.
45
+ * @public
46
+ */
47
+ export const isEventWithParams = (event) => event.params !== undefined;
42
48
  /**
43
49
  * isErrorType.
44
50
  * @param type - An event type.
@@ -42,12 +42,13 @@ export class AbstractMachine {
42
42
  this.startingContext = (options.input
43
43
  ? Object.assign(Object.assign({}, contextWithErrors), options.input) : contextWithErrors);
44
44
  this.actor = interpret(this.machine, Object.assign(Object.assign({}, options), { input: this.startingContext, state: this.startingState }));
45
- const { value: currentValue, context: currentContext } = this.actor.getSnapshot();
46
- this.state = currentValue;
47
- this.context = currentContext;
45
+ this.snapshot = this.actor.getSnapshot();
46
+ this.state = this.snapshot.value;
47
+ this.context = this.snapshot.context;
48
+ this.meta = this.snapshot.meta;
48
49
  this.complete = false;
49
50
  this.output = undefined;
50
- this.errors = currentContext.errors;
51
+ this.errors = this.context.errors;
51
52
  this.error = undefined;
52
53
  }
53
54
  /**
@@ -59,24 +60,34 @@ export class AbstractMachine {
59
60
  }
60
61
  this.subscription = this.actor.subscribe({
61
62
  next: (snapshot) => {
62
- var _a;
63
- this.state = snapshot.value;
64
- this.context = snapshot.context;
65
- this.errors = this.context.errors;
66
- this.error = (_a = this.context.error) !== null && _a !== void 0 ? _a : this.errors.lastError;
63
+ this.applySnapshot(snapshot);
67
64
  logger.debug(`${this.machine.id} changed, state:`, this.state, `context:`, this.context);
68
65
  },
69
66
  error: (err) => {
67
+ this.applySnapshot();
70
68
  this.error = err;
71
69
  logger.error(`${this.machine.id} error:`, err);
72
70
  },
73
71
  complete: () => {
72
+ this.applySnapshot();
74
73
  this.complete = true;
75
- this.output = this.actor.getSnapshot().output;
74
+ this.output = this.snapshot.output;
76
75
  logger.debug(`${this.machine.id} complete:`, this.output);
77
76
  },
78
77
  });
79
78
  }
79
+ /**
80
+ * @internal
81
+ */
82
+ applySnapshot(snapshot = this.actor.getSnapshot()) {
83
+ var _a;
84
+ this.snapshot = snapshot;
85
+ this.state = this.snapshot.value;
86
+ this.context = this.snapshot.context;
87
+ this.meta = this.snapshot.meta;
88
+ this.errors = this.context.errors;
89
+ this.error = (_a = this.context.error) !== null && _a !== void 0 ? _a : this.errors.lastError;
90
+ }
80
91
  /**
81
92
  * @internal
82
93
  */
@@ -117,14 +128,24 @@ export class AbstractMachine {
117
128
  if (!this.actor) {
118
129
  throw new Error('Call interpret() before calling matches()');
119
130
  }
120
- return this.actor.getSnapshot().matches(value);
131
+ return this.snapshot.matches(value);
121
132
  }
122
133
  /** {@inheritDoc Machine.hasTag} */
123
134
  hasTag(tag) {
124
135
  if (!this.actor) {
125
136
  throw new Error('Call interpret() before calling hasTag()');
126
137
  }
127
- return this.actor.getSnapshot().hasTag(tag);
138
+ return this.snapshot.hasTag(tag);
139
+ }
140
+ /** {@inheritDoc Machine.getMetaValuesByKey} */
141
+ getMetaValuesByKey(key = 'content') {
142
+ const metaValues = [];
143
+ if (this.meta) {
144
+ for (const value of Object.values(this.meta)) {
145
+ metaValues.push(typeof value === 'object' ? value[key] : value);
146
+ }
147
+ }
148
+ return metaValues;
128
149
  }
129
150
  /** {@inheritDoc Machine.send} */
130
151
  send(event) {
@@ -154,6 +175,9 @@ __decorate([
154
175
  __decorate([
155
176
  observable
156
177
  ], AbstractMachine.prototype, "actor", void 0);
178
+ __decorate([
179
+ observable
180
+ ], AbstractMachine.prototype, "snapshot", void 0);
157
181
  __decorate([
158
182
  observable
159
183
  ], AbstractMachine.prototype, "state", void 0);
@@ -166,6 +190,9 @@ __decorate([
166
190
  __decorate([
167
191
  observable
168
192
  ], AbstractMachine.prototype, "startingContext", void 0);
193
+ __decorate([
194
+ observable
195
+ ], AbstractMachine.prototype, "meta", void 0);
169
196
  __decorate([
170
197
  observable
171
198
  ], AbstractMachine.prototype, "complete", void 0);
@@ -1,4 +1,4 @@
1
- import { setErrorByKey } from './actions';
1
+ import { escalateError, setErrorByKey } from './actions';
2
2
  /**
3
3
  * Creates an error state node.
4
4
  *
@@ -8,19 +8,31 @@ import { setErrorByKey } from './actions';
8
8
  * @public
9
9
  */
10
10
  export const createErrorStateNode = (key, metaContent, final = true) => {
11
+ /**
12
+ * Raised question on reuse and dynamic parent detection, regarding error escalation.
13
+ * https://github.com/statelyai/xstate/discussions/4268
14
+ */
15
+ let hasParentMachine = false;
16
+ let sentToParentMachine = false;
11
17
  return {
12
18
  tags: ['error', key],
13
19
  meta: {
14
20
  content: metaContent ? metaContent : `${key} error.`,
15
21
  },
16
- entry: [setErrorByKey(`${key}-error`)],
22
+ entry: [
23
+ setErrorByKey(`${key}-error`),
24
+ (args) => (hasParentMachine = args.self._parent !== undefined),
25
+ ],
26
+ always: [
27
+ {
28
+ guard: () => hasParentMachine && !sentToParentMachine,
29
+ actions: [escalateError, () => (sentToParentMachine = true)],
30
+ },
31
+ ],
17
32
  /**
18
33
  * Provide final output to parent machines.
19
34
  */
20
35
  type: final ? 'final' : 'atomic',
21
- output: ({ context }) => ({
22
- error: context.error,
23
- data: context.error,
24
- }),
36
+ output: ({ context }) => context.error,
25
37
  };
26
38
  };
@@ -27,6 +27,12 @@ export class APIError extends Error {
27
27
  this.name = 'APIError';
28
28
  Object.setPrototypeOf(this, APIError.prototype);
29
29
  }
30
+ /**
31
+ * @public
32
+ */
33
+ isUnauthorized() {
34
+ return this.status === StatusCodes.UNAUTHORIZED;
35
+ }
30
36
  }
31
37
  /**
32
38
  * @param error - An error.
@@ -44,3 +50,8 @@ export const isNetworkError = (error) => error instanceof NetworkError ||
44
50
  * @public
45
51
  */
46
52
  export const isNotFoundError = (error) => isAPIError(error) && error.status === StatusCodes.NOT_FOUND;
53
+ /**
54
+ * @param error - An error.
55
+ * @public
56
+ */
57
+ export const isUnauthorizedError = (error) => isAPIError(error) && error.isUnauthorized();
@@ -33,11 +33,11 @@ export const createFetchPolicy = (maxAttempts = 2, retryCodes = defaultRetryStat
33
33
  const timeoutPolicy = timeout(timeoutDuration, TimeoutStrategy.Aggressive);
34
34
  const policy = wrap(retryPolicy, timeoutPolicy);
35
35
  if (logEvents) {
36
- retryPolicy.onRetry((data) => logger.info('Fetch retrying...', data));
37
- retryPolicy.onFailure((data) => logger.info('Fetch failed:', data));
38
- retryPolicy.onSuccess((data) => logger.info('Fetch success:', data));
39
- retryPolicy.onGiveUp((data) => logger.info('Fetch gave up:', data));
40
- timeoutPolicy.onTimeout(() => logger.info('Fetch timed out'));
36
+ retryPolicy.onRetry((data) => logger.debug('Fetch retrying...', data));
37
+ retryPolicy.onFailure((data) => logger.debug('Fetch failed:', data));
38
+ retryPolicy.onSuccess((data) => logger.debug('Fetch success:', data));
39
+ retryPolicy.onGiveUp((data) => logger.debug('Fetch gave up:', data));
40
+ timeoutPolicy.onTimeout(() => logger.debug('Fetch timed out'));
41
41
  }
42
42
  return policy;
43
43
  };