@genesislcap/foundation-state-machine 14.70.2 → 14.70.4-es2021.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.
package/dist/esm/core/actions.js
CHANGED
|
@@ -25,9 +25,8 @@ export const setError = assign(({ event }) => {
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
export const setErrorByKey = (key) => assign(({ context, event }) => {
|
|
28
|
-
var _a;
|
|
29
28
|
if (isErrorEvent(event)) {
|
|
30
|
-
const errors =
|
|
29
|
+
const errors = context.errors ?? createErrorMap(logger.error);
|
|
31
30
|
errors.set(key, event.data);
|
|
32
31
|
return {
|
|
33
32
|
errors,
|
package/dist/esm/core/errors.js
CHANGED
|
@@ -18,28 +18,24 @@ export class GenesisServerError extends Error {
|
|
|
18
18
|
* This is ugly, lets figure out if this is still an issue and remove if not.
|
|
19
19
|
*/
|
|
20
20
|
isIgnorableError() {
|
|
21
|
-
|
|
22
|
-
if ((_d = (_c = (_b = (_a = this.received) === null || _a === void 0 ? void 0 : _a.DETAILS) === null || _b === void 0 ? void 0 : _b.ERROR) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === null || _d === void 0 ? void 0 : _d.includes('request needs the user to be logged')) {
|
|
21
|
+
if (this.received?.DETAILS?.ERROR?.toLowerCase()?.includes('request needs the user to be logged')) {
|
|
23
22
|
return true;
|
|
24
23
|
}
|
|
25
24
|
return false;
|
|
26
25
|
}
|
|
27
26
|
getMessageError() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
? (_b = this.received) === null || _b === void 0 ? void 0 : _b.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
27
|
+
return Array.isArray(this.received?.ERROR)
|
|
28
|
+
? this.received?.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
31
29
|
: '';
|
|
32
30
|
}
|
|
33
31
|
getDetailsError() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
? (_d = (_c = this.received) === null || _c === void 0 ? void 0 : _c.DETAILS) === null || _d === void 0 ? void 0 : _d.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
32
|
+
return Array.isArray(this.received?.DETAILS?.ERROR)
|
|
33
|
+
? this.received?.DETAILS?.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
|
|
37
34
|
: '';
|
|
38
35
|
}
|
|
39
36
|
hasErrorCode(code) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
? (_b = this.received) === null || _b === void 0 ? void 0 : _b.ERROR.some((error) => error.CODE === code)
|
|
37
|
+
return Array.isArray(this.received?.ERROR)
|
|
38
|
+
? this.received?.ERROR.some((error) => error.CODE === code)
|
|
43
39
|
: false;
|
|
44
40
|
}
|
|
45
41
|
errorDetailFormatter(error) {
|
package/dist/esm/core/guards.js
CHANGED
|
@@ -38,7 +38,7 @@ export const isErrorCustomEvent = (event) => /^xstate.error/.test(event.type);
|
|
|
38
38
|
* @param event - An event.
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
|
-
export const isActorErrorEvent = (actorId, event) =>
|
|
41
|
+
export const isActorErrorEvent = (actorId, event) => event.type?.includes('error') && event.type?.includes(actorId);
|
|
42
42
|
/**
|
|
43
43
|
* isErrorType.
|
|
44
44
|
* @param type - An event type.
|
package/dist/esm/core/machine.js
CHANGED
|
@@ -38,10 +38,18 @@ export class AbstractMachine {
|
|
|
38
38
|
errors: createErrorMap(logger.error),
|
|
39
39
|
error: undefined,
|
|
40
40
|
};
|
|
41
|
-
this.startingState = options
|
|
41
|
+
this.startingState = options?.state;
|
|
42
42
|
this.startingContext = (options.input
|
|
43
|
-
?
|
|
44
|
-
|
|
43
|
+
? {
|
|
44
|
+
...contextWithErrors,
|
|
45
|
+
...options.input,
|
|
46
|
+
}
|
|
47
|
+
: contextWithErrors);
|
|
48
|
+
this.actor = interpret(this.machine, {
|
|
49
|
+
...options,
|
|
50
|
+
input: this.startingContext,
|
|
51
|
+
state: this.startingState,
|
|
52
|
+
});
|
|
45
53
|
const { value: currentValue, context: currentContext } = this.actor.getSnapshot();
|
|
46
54
|
this.state = currentValue;
|
|
47
55
|
this.context = currentContext;
|
|
@@ -59,11 +67,10 @@ export class AbstractMachine {
|
|
|
59
67
|
}
|
|
60
68
|
this.subscription = this.actor.subscribe({
|
|
61
69
|
next: (snapshot) => {
|
|
62
|
-
var _a;
|
|
63
70
|
this.state = snapshot.value;
|
|
64
71
|
this.context = snapshot.context;
|
|
65
72
|
this.errors = this.context.errors;
|
|
66
|
-
this.error =
|
|
73
|
+
this.error = this.context.error ?? this.errors.lastError;
|
|
67
74
|
logger.debug(`${this.machine.id} changed, state:`, this.state, `context:`, this.context);
|
|
68
75
|
},
|
|
69
76
|
error: (err) => {
|
|
@@ -87,8 +94,7 @@ export class AbstractMachine {
|
|
|
87
94
|
* @internal
|
|
88
95
|
*/
|
|
89
96
|
startActor() {
|
|
90
|
-
|
|
91
|
-
if (((_a = this.actor) === null || _a === void 0 ? void 0 : _a.status) !== InterpreterStatus.Running) {
|
|
97
|
+
if (this.actor?.status !== InterpreterStatus.Running) {
|
|
92
98
|
this.actor.start();
|
|
93
99
|
}
|
|
94
100
|
}
|
|
@@ -96,8 +102,7 @@ export class AbstractMachine {
|
|
|
96
102
|
* @internal
|
|
97
103
|
*/
|
|
98
104
|
stopActor() {
|
|
99
|
-
|
|
100
|
-
if (((_a = this.actor) === null || _a === void 0 ? void 0 : _a.status) === InterpreterStatus.Running) {
|
|
105
|
+
if (this.actor?.status === InterpreterStatus.Running) {
|
|
101
106
|
this.actor.stop();
|
|
102
107
|
}
|
|
103
108
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate, __param } from "tslib";
|
|
2
2
|
import { DI, optional } from '@microsoft/fast-foundation';
|
|
3
3
|
import { assign, createMachine, fromPromise } from 'xstate';
|
|
4
4
|
import { AbstractMachine, createErrorStateNode, isAbortError, isDoneInvokeEvent, isErrorEvent, isSyntaxError, isTypeError, setError, } from '../../core';
|
|
@@ -20,7 +20,9 @@ let DefaultFetchMachine = class DefaultFetchMachine extends AbstractMachine {
|
|
|
20
20
|
this.config = config;
|
|
21
21
|
this.machine = createMachine({
|
|
22
22
|
id: 'fetchMachine',
|
|
23
|
-
context: ({ input }) => (
|
|
23
|
+
context: ({ input }) => ({
|
|
24
|
+
...input,
|
|
25
|
+
}),
|
|
24
26
|
initial: 'idle',
|
|
25
27
|
states: {
|
|
26
28
|
idle: {
|
|
@@ -36,7 +38,14 @@ let DefaultFetchMachine = class DefaultFetchMachine extends AbstractMachine {
|
|
|
36
38
|
},
|
|
37
39
|
invoke: {
|
|
38
40
|
src: 'fetch',
|
|
39
|
-
input: ({ context }) => (
|
|
41
|
+
input: ({ context }) => ({
|
|
42
|
+
...context.params,
|
|
43
|
+
controller: context.controller,
|
|
44
|
+
/**
|
|
45
|
+
* We can test response codes using a service like https://httpstat.us, for example:
|
|
46
|
+
* url: `https://httpstat.us/200`,
|
|
47
|
+
*/
|
|
48
|
+
}),
|
|
40
49
|
onDone: 'success',
|
|
41
50
|
onError: [
|
|
42
51
|
{
|
|
@@ -106,18 +115,20 @@ let DefaultFetchMachine = class DefaultFetchMachine extends AbstractMachine {
|
|
|
106
115
|
},
|
|
107
116
|
}, {
|
|
108
117
|
actors: {
|
|
109
|
-
fetch: fromPromise(({ input }) =>
|
|
110
|
-
var _a, _b, _c, _d, _e;
|
|
118
|
+
fetch: fromPromise(async ({ input }) => {
|
|
111
119
|
const { controller, fetchConfig, requestInit, url } = input;
|
|
112
|
-
const fetcher =
|
|
113
|
-
const fetchPolicy =
|
|
114
|
-
const init = requestInit
|
|
115
|
-
const okChecker =
|
|
116
|
-
const dataExtractor =
|
|
117
|
-
return fetchPolicy.execute(() =>
|
|
120
|
+
const fetcher = fetchConfig?.fetcher ?? this.config.fetcher ?? fetch;
|
|
121
|
+
const fetchPolicy = fetchConfig?.fetchPolicy ?? this.config.fetchPolicy;
|
|
122
|
+
const init = requestInit ?? { method: 'GET' };
|
|
123
|
+
const okChecker = fetchConfig?.responseOkChecker ?? this.config.responseOkChecker;
|
|
124
|
+
const dataExtractor = fetchConfig?.responseDataExtractor ?? this.config.responseDataExtractor;
|
|
125
|
+
return fetchPolicy.execute(async () => {
|
|
118
126
|
try {
|
|
119
|
-
const response =
|
|
120
|
-
|
|
127
|
+
const response = await fetcher(url, {
|
|
128
|
+
...init,
|
|
129
|
+
signal: controller.signal,
|
|
130
|
+
});
|
|
131
|
+
const data = await dataExtractor(response);
|
|
121
132
|
if (!okChecker(response)) {
|
|
122
133
|
throw new APIError(response.status, data);
|
|
123
134
|
}
|
|
@@ -129,8 +140,8 @@ let DefaultFetchMachine = class DefaultFetchMachine extends AbstractMachine {
|
|
|
129
140
|
}
|
|
130
141
|
throw error; // < API, Syntax / JS Error
|
|
131
142
|
}
|
|
132
|
-
})
|
|
133
|
-
})
|
|
143
|
+
});
|
|
144
|
+
}),
|
|
134
145
|
},
|
|
135
146
|
actions: {
|
|
136
147
|
setParams: assign(({ event }) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
1
|
import { JSONReviver } from '@genesislcap/foundation-utils';
|
|
3
2
|
import { defaultFetchPolicy } from './policies';
|
|
4
3
|
/**
|
|
@@ -10,22 +9,22 @@ export const defaultResponseOkChecker = (response) => response.ok;
|
|
|
10
9
|
* {@inheritDoc ResponseDataExtractor}
|
|
11
10
|
* @public
|
|
12
11
|
*/
|
|
13
|
-
export const defaultResponseDataExtractor = (response) =>
|
|
14
|
-
const text =
|
|
12
|
+
export const defaultResponseDataExtractor = async (response) => {
|
|
13
|
+
const text = await response.text();
|
|
15
14
|
const contentType = response.headers.get('content-type');
|
|
16
|
-
const expectingJson = contentType
|
|
15
|
+
const expectingJson = contentType?.includes('application/json');
|
|
17
16
|
return expectingJson ? JSON.parse(text, JSONReviver) : text;
|
|
18
|
-
}
|
|
17
|
+
};
|
|
19
18
|
/**
|
|
20
19
|
* Creates an extractor that applies a deserializer to the extracted response data.
|
|
21
20
|
* @param deserializer - The deserializer to apply.
|
|
22
21
|
* @param extractor - An optional data extractor. Defaults to {@link defaultResponseDataExtractor}.
|
|
23
22
|
* @public
|
|
24
23
|
*/
|
|
25
|
-
export const createResponseDataExtractorWithDeserializer = (deserializer, extractor = defaultResponseDataExtractor) => (response) =>
|
|
26
|
-
const json =
|
|
24
|
+
export const createResponseDataExtractorWithDeserializer = (deserializer, extractor = defaultResponseDataExtractor) => async (response) => {
|
|
25
|
+
const json = await extractor(response);
|
|
27
26
|
return deserializer(json);
|
|
28
|
-
}
|
|
27
|
+
};
|
|
29
28
|
/**
|
|
30
29
|
* The default fetch config.
|
|
31
30
|
* @public
|
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": "14.70.
|
|
4
|
+
"version": "14.70.4-es2021.1",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "SEE LICENSE IN license.txt",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"test": "genx test"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@genesislcap/foundation-testing": "14.70.
|
|
38
|
-
"@genesislcap/genx": "14.70.
|
|
37
|
+
"@genesislcap/foundation-testing": "14.70.4-es2021.1",
|
|
38
|
+
"@genesislcap/genx": "14.70.4-es2021.1",
|
|
39
39
|
"rimraf": "^3.0.2"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@genesislcap/foundation-comms": "14.70.
|
|
43
|
-
"@genesislcap/foundation-utils": "14.70.
|
|
42
|
+
"@genesislcap/foundation-comms": "14.70.4-es2021.1",
|
|
43
|
+
"@genesislcap/foundation-utils": "14.70.4-es2021.1",
|
|
44
44
|
"@microsoft/fast-element": "^1.7.0",
|
|
45
45
|
"@microsoft/fast-foundation": "^2.33.2",
|
|
46
46
|
"cockatiel": "^3.1.1",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5d0d8ee36cfd068cfc6211033b326d0a978cfc05"
|
|
60
60
|
}
|