@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.
@@ -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 ?? createErrorMap(logger.error);
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,
@@ -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
- if (this.received?.DETAILS?.ERROR?.toLowerCase()?.includes('request needs the user to be logged')) {
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
- return Array.isArray(this.received?.ERROR)
28
- ? this.received?.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
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
- return Array.isArray(this.received?.DETAILS?.ERROR)
33
- ? this.received?.DETAILS?.ERROR.map((error) => this.errorDetailFormatter(error)).join('\n')
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
- return Array.isArray(this.received?.ERROR)
38
- ? this.received?.ERROR.some((error) => error.CODE === code)
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) {
@@ -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?.includes('error') && event.type?.includes(actorId);
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.
@@ -38,18 +38,10 @@ export class AbstractMachine {
38
38
  errors: createErrorMap(logger.error),
39
39
  error: undefined,
40
40
  };
41
- this.startingState = options?.state;
41
+ this.startingState = options === null || options === void 0 ? void 0 : options.state;
42
42
  this.startingContext = (options.input
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
- });
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 ?? this.errors.lastError;
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
- if (this.actor?.status !== InterpreterStatus.Running) {
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
- if (this.actor?.status === InterpreterStatus.Running) {
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(async ({ input }) => {
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?.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 () => {
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 = await fetcher(url, {
128
- ...init,
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 = async (response) => {
13
- const text = await response.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?.includes('application/json');
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) => async (response) => {
25
- const json = await extractor(response);
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-es2021.1",
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-es2021.1",
38
- "@genesislcap/genx": "14.70.4-es2021.1",
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-es2021.1",
43
- "@genesislcap/foundation-utils": "14.70.4-es2021.1",
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": "5d0d8ee36cfd068cfc6211033b326d0a978cfc05"
59
+ "gitHead": "2414c66a7a84c61343d756e240cb4140d82f1311"
60
60
  }