@genesislcap/foundation-state-machine 15.23.3 → 15.24.0-FUI-2603.10

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.
@@ -18,9 +18,14 @@ export declare const setError: {
18
18
  * Set error by key action.
19
19
  * @remarks
20
20
  * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
21
+ * Prefers an existing `context.error` over the current event. Callers that start a new
22
+ * operation must clear the previous error first (e.g. `clearErrors` / `resetContext`);
23
+ * otherwise a stale `context.error` is re-keyed under this key and a later done-output
24
+ * Error is ignored. When `setError` matches no branch it returns `undefined` and leaves
25
+ * the prior `context.error` in place — which is what makes clearing mandatory.
21
26
  * @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.
27
+ * Contains done event handling to deal with 200 Nacks. Precedence: `context.error`, then
28
+ * `event.data` (error event), then done `event.output` when it is an `Error`.
24
29
  * @param key - The error key.
25
30
  * @public
26
31
  */
@@ -1 +1 @@
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,GAAI,KAAK,MAAM;;;;;;;CAgBrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAA2C,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;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM;;;;;;;CAkBrC,CAAC;AAEL;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAA2C,CAAC"}
@@ -2,6 +2,10 @@ import type { StateNodeConfig } from 'xstate';
2
2
  /**
3
3
  * Creates an error state node.
4
4
  *
5
+ * @remarks
6
+ * Entry runs {@link setErrorByKey}, which prefers an existing `context.error`. Ensure
7
+ * the prior error was cleared before entering a new operation that may land here.
8
+ *
5
9
  * @param key - An error state key.
6
10
  * @param metaContent - An optional meta content value.
7
11
  * @param final - An optional flag which adds final with output functionality.
@@ -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;AAI9C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,MAAM,EACX,cAAc,MAAM,EACpB,QAAO,OAAc,KACpB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CA4BpC,CAAC"}
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;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAC/B,KAAK,MAAM,EACX,cAAc,MAAM,EACpB,QAAO,OAAc,KACpB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAcpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../../../../src/machines/fetch/machine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EACL,eAAe,EAOf,OAAO,EAER,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EAEjB,qBA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AE,OAAO,KAAK,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,mEAAoC,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;CAAG;AAExF;;;GAGG;AACH,qBAAa,mBACX,SAAQ,eAAe,CAAC,mBAAmB,EAAE,iBAAiB,CAC9D,YAAW,YAAY;IAEY,OAAO,CAAC,MAAM;gBAAN,MAAM,cAAqB;IAwLtE,kCAAkC;IAClC,KAAK,CACH,OAAO,GAAE,kBAAkB,CAAC,OAAO,IAAI,CAAC,OAAO,CAE9C;IAKH,6CAA6C;IAC7C,gBAAgB,IAAI,IAAI;CAGzB;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,oEAExB,CAAC"}
@@ -28,21 +28,28 @@ export const setError = assign(({ event }) => {
28
28
  * Set error by key action.
29
29
  * @remarks
30
30
  * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
31
+ * Prefers an existing `context.error` over the current event. Callers that start a new
32
+ * operation must clear the previous error first (e.g. `clearErrors` / `resetContext`);
33
+ * otherwise a stale `context.error` is re-keyed under this key and a later done-output
34
+ * Error is ignored. When `setError` matches no branch it returns `undefined` and leaves
35
+ * the prior `context.error` in place — which is what makes clearing mandatory.
31
36
  * @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.
37
+ * Contains done event handling to deal with 200 Nacks. Precedence: `context.error`, then
38
+ * `event.data` (error event), then done `event.output` when it is an `Error`.
34
39
  * @param key - The error key.
35
40
  * @public
36
41
  */
37
42
  export const setErrorByKey = (key) => assign(({ context, event }) => {
38
43
  var _a;
39
- let error;
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;
44
+ let error = context.error;
45
+ if (!error) {
46
+ if (isErrorEvent(event)) {
47
+ error = event.data;
48
+ }
49
+ else if (isDoneInvokeEvent(event)) {
50
+ logger.debug(`setErrorByKey action called with non error event type.`, event);
51
+ error = event.output instanceof Error ? event.output : undefined;
52
+ }
46
53
  }
47
54
  if (error) {
48
55
  const errors = (_a = context.errors) !== null && _a !== void 0 ? _a : createErrorMap(logger.error);
@@ -1,36 +1,26 @@
1
- import { escalateError, setErrorByKey } from './actions';
1
+ import { setErrorByKey } from './actions';
2
2
  /**
3
3
  * Creates an error state node.
4
4
  *
5
+ * @remarks
6
+ * Entry runs {@link setErrorByKey}, which prefers an existing `context.error`. Ensure
7
+ * the prior error was cleared before entering a new operation that may land here.
8
+ *
5
9
  * @param key - An error state key.
6
10
  * @param metaContent - An optional meta content value.
7
11
  * @param final - An optional flag which adds final with output functionality.
8
12
  * @public
9
13
  */
10
14
  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;
17
15
  return {
18
16
  tags: ['error', key],
19
17
  meta: {
20
18
  content: metaContent ? metaContent : `${key} error.`,
21
19
  },
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
- ],
20
+ entry: [setErrorByKey(`${key}-error`)],
32
21
  /**
33
22
  * Provide final output to parent machines.
23
+ * Notification of invoked parents is via this output / top-level `failed`, not escalate closures.
34
24
  */
35
25
  type: final ? 'final' : 'atomic',
36
26
  output: ({ context }) => context.error,
@@ -92,6 +92,12 @@ let DefaultFetchMachine = class DefaultFetchMachine extends AbstractMachine {
92
92
  abort: createErrorStateNode('abort', 'Abort error.'),
93
93
  syntax: createErrorStateNode('syntax', 'Syntax error.'),
94
94
  },
95
+ onDone: 'failed',
96
+ },
97
+ failed: {
98
+ tags: ['error'],
99
+ type: 'final',
100
+ output: ({ context }) => context.error,
95
101
  },
96
102
  },
97
103
  on: {
@@ -1715,7 +1715,7 @@
1715
1715
  {
1716
1716
  "kind": "Function",
1717
1717
  "canonicalReference": "@genesislcap/foundation-state-machine!createErrorStateNode:function(1)",
1718
- "docComment": "/**\n * Creates an error state node.\n *\n * @param key - An error state key.\n *\n * @param metaContent - An optional meta content value.\n *\n * @param final - An optional flag which adds final with output functionality.\n *\n * @public\n */\n",
1718
+ "docComment": "/**\n * Creates an error state node.\n *\n * @remarks\n *\n * Entry runs {@link setErrorByKey}, which prefers an existing `context.error`. Ensure the prior error was cleared before entering a new operation that may land here.\n *\n * @param key - An error state key.\n *\n * @param metaContent - An optional meta content value.\n *\n * @param final - An optional flag which adds final with output functionality.\n *\n * @public\n */\n",
1719
1719
  "excerptTokens": [
1720
1720
  {
1721
1721
  "kind": "Content",
@@ -6424,7 +6424,7 @@
6424
6424
  {
6425
6425
  "kind": "Function",
6426
6426
  "canonicalReference": "@genesislcap/foundation-state-machine!setErrorByKey:function(1)",
6427
- "docComment": "/**\n * Set error by key action.\n *\n * @remarks\n *\n * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.\n *\n * @param key - The error key.\n *\n * @public\n */\n",
6427
+ "docComment": "/**\n * Set error by key action.\n *\n * @remarks\n *\n * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key. Prefers an existing `context.error` over the current event. Callers that start a new operation must clear the previous error first (e.g. `clearErrors` / `resetContext`); otherwise a stale `context.error` is re-keyed under this key and a later done-output Error is ignored. When `setError` matches no branch it returns `undefined` and leaves the prior `context.error` in place — which is what makes clearing mandatory.\n *\n * @param key - The error key.\n *\n * @public\n */\n",
6428
6428
  "excerptTokens": [
6429
6429
  {
6430
6430
  "kind": "Content",
@@ -166,6 +166,10 @@ export { assign }
166
166
  /**
167
167
  * Creates an error state node.
168
168
  *
169
+ * @remarks
170
+ * Entry runs {@link setErrorByKey}, which prefers an existing `context.error`. Ensure
171
+ * the prior error was cleared before entering a new operation that may land here.
172
+ *
169
173
  * @param key - An error state key.
170
174
  * @param metaContent - An optional meta content value.
171
175
  * @param final - An optional flag which adds final with output functionality.
@@ -914,9 +918,14 @@ export declare const setError: {
914
918
  * Set error by key action.
915
919
  * @remarks
916
920
  * Used to set an error in the {@link @genesislcap/foundation-utils#ErrorMap} by key.
921
+ * Prefers an existing `context.error` over the current event. Callers that start a new
922
+ * operation must clear the previous error first (e.g. `clearErrors` / `resetContext`);
923
+ * otherwise a stale `context.error` is re-keyed under this key and a later done-output
924
+ * Error is ignored. When `setError` matches no branch it returns `undefined` and leaves
925
+ * the prior `context.error` in place — which is what makes clearing mandatory.
917
926
  * @privateRemarks
918
- * Contains done event handling to deal with 200 Nacks. If done output is an error use it, or fallback to `context.error`
919
- * and set that under the provided key.
927
+ * Contains done event handling to deal with 200 Nacks. Precedence: `context.error`, then
928
+ * `event.data` (error event), then done `event.output` when it is an `Error`.
920
929
  * @param key - The error key.
921
930
  * @public
922
931
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-state-machine",
3
3
  "description": "Genesis Foundation State Machine",
4
- "version": "15.23.3",
4
+ "version": "15.24.0-FUI-2603.10",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -54,18 +54,18 @@
54
54
  }
55
55
  },
56
56
  "devDependencies": {
57
- "@genesislcap/foundation-testing": "15.23.3",
58
- "@genesislcap/genx": "15.23.3",
59
- "@genesislcap/rollup-builder": "15.23.3",
60
- "@genesislcap/ts-builder": "15.23.3",
61
- "@genesislcap/uvu-playwright-builder": "15.23.3",
62
- "@genesislcap/vite-builder": "15.23.3",
63
- "@genesislcap/webpack-builder": "15.23.3"
57
+ "@genesislcap/foundation-testing": "15.24.0-FUI-2603.10",
58
+ "@genesislcap/genx": "15.24.0-FUI-2603.10",
59
+ "@genesislcap/rollup-builder": "15.24.0-FUI-2603.10",
60
+ "@genesislcap/ts-builder": "15.24.0-FUI-2603.10",
61
+ "@genesislcap/uvu-playwright-builder": "15.24.0-FUI-2603.10",
62
+ "@genesislcap/vite-builder": "15.24.0-FUI-2603.10",
63
+ "@genesislcap/webpack-builder": "15.24.0-FUI-2603.10"
64
64
  },
65
65
  "dependencies": {
66
- "@genesislcap/foundation-comms": "15.23.3",
67
- "@genesislcap/foundation-logger": "15.23.3",
68
- "@genesislcap/foundation-utils": "15.23.3",
66
+ "@genesislcap/foundation-comms": "15.24.0-FUI-2603.10",
67
+ "@genesislcap/foundation-logger": "15.24.0-FUI-2603.10",
68
+ "@genesislcap/foundation-utils": "15.24.0-FUI-2603.10",
69
69
  "@microsoft/fast-element": "1.14.0",
70
70
  "@microsoft/fast-foundation": "2.50.0",
71
71
  "cockatiel": "^3.1.1",