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