@miso.ai/client-sdk-ui 1.12.3-beta.0 → 1.12.3-beta.2

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.
@@ -42,12 +42,6 @@ class DataActor {
42
42
  this._ac = new AbortController();
43
43
  }
44
44
  this._session = session;
45
-
46
- // TODO: move this to workflow
47
- // reflect session update
48
- this._emitResponse({
49
- session
50
- });
51
45
  }
52
46
  async _handleRequest(event) {
53
47
  // protocol: inactive -> no reaction
@@ -55,15 +49,9 @@ class DataActor {
55
49
  return;
56
50
  }
57
51
  const {
58
- session
59
- } = this._hub.states;
60
- const request = _objectWithoutPropertiesLoose(event, _excluded);
61
-
62
- // emit response to update request
63
- this._emitResponse({
64
- session,
65
- request
66
- });
52
+ session
53
+ } = event,
54
+ request = _objectWithoutPropertiesLoose(event, _excluded);
67
55
  try {
68
56
  const {
69
57
  signal
@@ -73,7 +61,7 @@ class DataActor {
73
61
  });
74
62
  const response = await this._source(Object.assign({
75
63
  session
76
- }, event, {
64
+ }, request, {
77
65
  options
78
66
  }));
79
67
  // takes an iterable, either sync or async
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.12.3-beta.0';
7
+ var _default = exports.default = '1.12.3-beta.2';
@@ -213,8 +213,8 @@ class AnswerBasedWorkflow extends _base.default {
213
213
  this._updateUrlIfNecessary(data);
214
214
  }
215
215
  _handleHeadResponse(data) {}
216
- _defaultProcessData(data) {
217
- data = super._defaultProcessData(data);
216
+ _defaultProcessData(data, oldData) {
217
+ data = super._defaultProcessData(data, oldData);
218
218
  data = (0, _index3.processData)(data);
219
219
  data = (0, _processors.writeAnswerStageToMeta)(data);
220
220
  return data;
@@ -90,7 +90,7 @@ class Workflow extends _commons.Component {
90
90
  _initSubscriptions({
91
91
  roles
92
92
  }) {
93
- this._unsubscribes = [this._hub.on(_index.fields.response(), data => this.updateData(data)), this._hub.on(_index.fields.tracker(), args => this._onTracker(args))];
93
+ this._unsubscribes = [this._hub.on(_index.fields.session(), session => this._onSession(session)), this._hub.on(_index.fields.response(), data => this.updateData(data)), this._hub.on(_index.fields.tracker(), args => this._onTracker(args))];
94
94
  if (roles.main) {
95
95
  this._unsubscribes.push(this._hub.on(_index.fields.view(roles.main), state => this._onMainViewUpdate(state)));
96
96
  }
@@ -166,6 +166,11 @@ class Workflow extends _commons.Component {
166
166
  this._emitLifecycleEvent('finally', state);
167
167
  }
168
168
  }
169
+ _onSession(session) {
170
+ this.updateData({
171
+ session
172
+ });
173
+ }
169
174
  _onMainViewUpdate(state) {
170
175
  const {
171
176
  status
@@ -202,10 +207,14 @@ class Workflow extends _commons.Component {
202
207
  const {
203
208
  session
204
209
  } = this;
205
- const event = (0, _index3.mergeApiOptions)(this._options.resolved.api, Object.assign({}, options, {
210
+ const request = (0, _index3.mergeApiOptions)(this._options.resolved.api, options);
211
+ this.updateData({
212
+ session,
213
+ request
214
+ });
215
+ this._hub.update(_index.fields.request(), Object.assign({}, request, {
206
216
  session
207
217
  }));
208
- this._hub.update(_index.fields.request(), event);
209
218
  }
210
219
 
211
220
  // data //
@@ -238,13 +247,15 @@ class Workflow extends _commons.Component {
238
247
  return this;
239
248
  }
240
249
  _updateData(data) {
241
- data = this._defaultProcessData(data);
250
+ const oldData = this._hub.states[_index.fields.data()];
251
+ data = this._defaultProcessData(data, oldData);
242
252
  for (const process of this._options.resolved.dataProcessor) {
243
- data = process(data);
253
+ data = process(data, oldData);
244
254
  }
245
- this._updateDataInHub(data);
255
+ this._updateDataInHub(data, oldData);
246
256
  }
247
- _defaultProcessData(data) {
257
+ _defaultProcessData(data, oldData) {
258
+ data = (0, _processors.writeRequestFromPreviousData)(data, oldData);
248
259
  data = (0, _processors.writeDataStatus)(data);
249
260
  data = (0, _processors.writeMisoIdToMeta)(data);
250
261
  return data;
@@ -129,8 +129,8 @@ class Explore extends _unit.default {
129
129
  super.notifyViewUpdate(role, ...args);
130
130
  return this;
131
131
  }
132
- _defaultProcessData(data) {
133
- data = super._defaultProcessData(data);
132
+ _defaultProcessData(data, oldData) {
133
+ data = super._defaultProcessData(data, oldData);
134
134
  data = this._addUrlToRelatedQuestions(data);
135
135
  return data;
136
136
  }
@@ -67,8 +67,8 @@ class HybridSearchAnswer extends _answerBased.default {
67
67
  }
68
68
 
69
69
  // data //
70
- _defaultProcessData(data) {
71
- data = super._defaultProcessData(data);
70
+ _defaultProcessData(data, oldData) {
71
+ data = super._defaultProcessData(data, oldData);
72
72
  data = (0, _processors.writeKeywordsToData)(data);
73
73
  data = (0, _processors.writeMisoIdFromSession)(data);
74
74
  data = (0, _processors.writeUnanswerableToMeta)(data);
@@ -69,8 +69,8 @@ class HybridSearchResults extends _searchBased.default {
69
69
  }
70
70
 
71
71
  // data //
72
- _defaultProcessData(data) {
73
- data = super._defaultProcessData(data);
72
+ _defaultProcessData(data, oldData) {
73
+ data = super._defaultProcessData(data, oldData);
74
74
  (0, _processors.writeMisoIdToSession)(data);
75
75
  return data;
76
76
  }
@@ -23,6 +23,7 @@ exports.writeMisoIdAsRootMisoId = writeMisoIdAsRootMisoId;
23
23
  exports.writeMisoIdFromSession = writeMisoIdFromSession;
24
24
  exports.writeMisoIdToMeta = writeMisoIdToMeta;
25
25
  exports.writeMisoIdToSession = writeMisoIdToSession;
26
+ exports.writeRequestFromPreviousData = writeRequestFromPreviousData;
26
27
  exports.writeUnanswerableToMeta = writeUnanswerableToMeta;
27
28
  var _commons = require("@miso.ai/commons");
28
29
  var _constants = require("../constants.js");
@@ -114,6 +115,18 @@ function mappingFollowUpQuestionsData(data) {
114
115
  function getRevision(data) {
115
116
  return data && data.value && data.value.revision;
116
117
  }
118
+ function writeRequestFromPreviousData(data, oldData) {
119
+ // patch request in case user call updateData() without request object in custom data scenario
120
+ if (!data || !data.value || data.request || !oldData || !oldData.request) {
121
+ return data;
122
+ }
123
+ const {
124
+ request
125
+ } = oldData;
126
+ return Object.assign({}, data, {
127
+ request
128
+ });
129
+ }
117
130
  function writeDataStatus(data) {
118
131
  const status = getStatus(data);
119
132
  const ongoing = status === _constants.STATUS.READY ? data.ongoing : undefined;
@@ -215,8 +215,8 @@ class SearchBasedWorkflow extends _base.default {
215
215
  }
216
216
 
217
217
  // data //
218
- _defaultProcessData(data) {
219
- data = super._defaultProcessData(data);
218
+ _defaultProcessData(data, oldData) {
219
+ data = super._defaultProcessData(data, oldData);
220
220
  data = (0, _processors.writeKeywordsToData)(data);
221
221
  data = (0, _processors.retainFacetCountsInData)(data, this._currentFacetCounts);
222
222
  data = (0, _processors.writeExhaustionToData)(data, {
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.12.3-beta.0"
29
+ "@miso.ai/commons": "1.12.3-beta.2"
30
30
  },
31
- "version": "1.12.3-beta.0"
31
+ "version": "1.12.3-beta.2"
32
32
  }
package/src/actor/data.js CHANGED
@@ -38,10 +38,6 @@ export default class DataActor {
38
38
  this._ac = new AbortController();
39
39
  }
40
40
  this._session = session;
41
-
42
- // TODO: move this to workflow
43
- // reflect session update
44
- this._emitResponse({ session });
45
41
  }
46
42
 
47
43
  async _handleRequest(event) {
@@ -49,16 +45,12 @@ export default class DataActor {
49
45
  if (!this.active) {
50
46
  return;
51
47
  }
52
- const { session } = this._hub.states;
53
- const { session: _, ...request } = event;
54
-
55
- // emit response to update request
56
- this._emitResponse({ session, request });
48
+ const { session, ...request } = event;
57
49
 
58
50
  try {
59
51
  const { signal } = this._ac || {};
60
52
  const options = { ...event.options, signal };
61
- const response = await this._source({ session, ...event, options });
53
+ const response = await this._source({ session, ...request, options });
62
54
  // takes an iterable, either sync or async
63
55
  if (response && response[Symbol.asyncIterator]) {
64
56
  // also emit reponse of the head request, if available
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.12.3-beta.0';
1
+ export default '1.12.3-beta.2';
@@ -209,8 +209,8 @@ export default class AnswerBasedWorkflow extends Workflow {
209
209
 
210
210
  _handleHeadResponse(data) {}
211
211
 
212
- _defaultProcessData(data) {
213
- data = super._defaultProcessData(data);
212
+ _defaultProcessData(data, oldData) {
213
+ data = super._defaultProcessData(data, oldData);
214
214
  data = processAffiliationData(data);
215
215
  data = writeAnswerStageToMeta(data);
216
216
  return data;
@@ -4,7 +4,7 @@ import * as sources from '../source.js';
4
4
  import { STATUS, ROLE } from '../constants.js';
5
5
  import { ContainerLayout, ErrorLayout } from '../layout/index.js';
6
6
  import { WorkflowOptions, mergeApiOptions, makeConfigurable } from './options/index.js';
7
- import { getRevision, writeDataStatus, writeMisoIdToMeta, buildBaseInteraction, writeAffiliationInfoToInteraction, mergeInteraction } from './processors.js';
7
+ import { getRevision, writeRequestFromPreviousData, writeDataStatus, writeMisoIdToMeta, buildBaseInteraction, writeAffiliationInfoToInteraction, mergeInteraction } from './processors.js';
8
8
 
9
9
  const DEFAULT_API_OPTIONS = Object.freeze({});
10
10
 
@@ -75,6 +75,7 @@ export default class Workflow extends Component {
75
75
 
76
76
  _initSubscriptions({ roles }) {
77
77
  this._unsubscribes = [
78
+ this._hub.on(fields.session(), session => this._onSession(session)),
78
79
  this._hub.on(fields.response(), data => this.updateData(data)),
79
80
  this._hub.on(fields.tracker(), args => this._onTracker(args)),
80
81
  ];
@@ -154,6 +155,10 @@ export default class Workflow extends Component {
154
155
  }
155
156
  }
156
157
 
158
+ _onSession(session) {
159
+ this.updateData({ session });
160
+ }
161
+
157
162
  _onMainViewUpdate(state) {
158
163
  const { status } = state;
159
164
  const done = status === STATUS.READY;
@@ -186,8 +191,9 @@ export default class Workflow extends Component {
186
191
  // request //
187
192
  _request(options = {}) {
188
193
  const { session } = this;
189
- const event = mergeApiOptions(this._options.resolved.api, { ...options, session });
190
- this._hub.update(fields.request(), event);
194
+ const request = mergeApiOptions(this._options.resolved.api, options);
195
+ this.updateData({ session, request });
196
+ this._hub.update(fields.request(), { ...request, session });
191
197
  }
192
198
 
193
199
  // data //
@@ -221,15 +227,17 @@ export default class Workflow extends Component {
221
227
  }
222
228
 
223
229
  _updateData(data) {
224
- data = this._defaultProcessData(data);
230
+ const oldData = this._hub.states[fields.data()];
231
+ data = this._defaultProcessData(data, oldData);
225
232
  for (const process of this._options.resolved.dataProcessor) {
226
- data = process(data);
233
+ data = process(data, oldData);
227
234
  }
228
235
 
229
- this._updateDataInHub(data);
236
+ this._updateDataInHub(data, oldData);
230
237
  }
231
238
 
232
- _defaultProcessData(data) {
239
+ _defaultProcessData(data, oldData) {
240
+ data = writeRequestFromPreviousData(data, oldData);
233
241
  data = writeDataStatus(data);
234
242
  data = writeMisoIdToMeta(data);
235
243
  return data;
@@ -121,8 +121,8 @@ export default class Explore extends UnitWorkflow {
121
121
  return this;
122
122
  }
123
123
 
124
- _defaultProcessData(data) {
125
- data = super._defaultProcessData(data);
124
+ _defaultProcessData(data, oldData) {
125
+ data = super._defaultProcessData(data, oldData);
126
126
  data = this._addUrlToRelatedQuestions(data);
127
127
  return data;
128
128
  }
@@ -60,8 +60,8 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
60
60
  }
61
61
 
62
62
  // data //
63
- _defaultProcessData(data) {
64
- data = super._defaultProcessData(data);
63
+ _defaultProcessData(data, oldData) {
64
+ data = super._defaultProcessData(data, oldData);
65
65
  data = writeKeywordsToData(data);
66
66
  data = writeMisoIdFromSession(data);
67
67
  data = writeUnanswerableToMeta(data);
@@ -71,8 +71,8 @@ export default class HybridSearchResults extends SearchBasedWorkflow {
71
71
  }
72
72
 
73
73
  // data //
74
- _defaultProcessData(data) {
75
- data = super._defaultProcessData(data);
74
+ _defaultProcessData(data, oldData) {
75
+ data = super._defaultProcessData(data, oldData);
76
76
  writeMisoIdToSession(data);
77
77
  return data;
78
78
  }
@@ -66,6 +66,18 @@ export function getRevision(data) {
66
66
  return data && data.value && data.value.revision;
67
67
  }
68
68
 
69
+ export function writeRequestFromPreviousData(data, oldData) {
70
+ // patch request in case user call updateData() without request object in custom data scenario
71
+ if (!data || !data.value || data.request || !oldData || !oldData.request) {
72
+ return data;
73
+ }
74
+ const { request } = oldData;
75
+ return {
76
+ ...data,
77
+ request,
78
+ };
79
+ }
80
+
69
81
  export function writeDataStatus(data) {
70
82
  const status = getStatus(data);
71
83
  const ongoing = status === STATUS.READY ? data.ongoing : undefined;
@@ -225,8 +225,8 @@ export default class SearchBasedWorkflow extends Workflow {
225
225
  }
226
226
 
227
227
  // data //
228
- _defaultProcessData(data) {
229
- data = super._defaultProcessData(data);
228
+ _defaultProcessData(data, oldData) {
229
+ data = super._defaultProcessData(data, oldData);
230
230
  data = writeKeywordsToData(data);
231
231
  data = retainFacetCountsInData(data, this._currentFacetCounts);
232
232
  data = writeExhaustionToData(data, { role: this._roles.main });