@miso.ai/client-sdk-core 1.7.2-beta.0 → 1.7.3-beta.0

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.
@@ -14,70 +14,76 @@ class Ask extends _base.default {
14
14
  constructor(api) {
15
15
  super(api, 'ask');
16
16
  }
17
- questions(payload) {
17
+ async questions(payload) {
18
18
  let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
19
19
  let {
20
20
  iterable = false
21
21
  } = _ref,
22
22
  options = _objectWithoutPropertiesLoose(_ref, _excluded);
23
- // TODO: it's possible to merge _iterator and _answer
24
- return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterator(payload, options) : this._questions(payload, options);
23
+ const response = await this._run('questions', payload, options);
24
+ return new Answer(this, response);
25
25
  }
26
26
  async _questions(payload, options) {
27
27
  return this._run('questions', payload, options);
28
28
  }
29
- async _get(answerId, options) {
30
- return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
29
+ async _get(questionId, options) {
30
+ return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
31
31
  method: 'GET'
32
32
  }));
33
33
  }
34
- _iterator(payload) {
35
- try {
36
- var _this = this;
37
- let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
- return async function* () {
39
- let {
40
- pollingInternal = 500
41
- } = _ref2,
42
- options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
43
- const response = await _this._questions(payload, options);
44
- yield response;
45
- const {
46
- question_id,
47
- finished
48
- } = response;
49
- if (finished) {
50
- return;
34
+ _iterable(questionId) {
35
+ let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
+ let {
37
+ pollingInternal = 500
38
+ } = _ref2,
39
+ options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
40
+ // TODO: abort signal
41
+ let apiErrorCount = 0;
42
+ const buffer = new _commons.ValueBuffer();
43
+ const intervalId = setInterval(async () => {
44
+ let response;
45
+ try {
46
+ response = await this._get(questionId, options);
47
+ } catch (error) {
48
+ apiErrorCount++;
49
+ if (apiErrorCount > 10) {
50
+ clearInterval(intervalId);
51
+ // TODO: cascade to buffer and user
51
52
  }
52
- let apiErrorCount = 0;
53
- const buffer = new _commons.ValueBuffer();
54
- const intervalId = setInterval(async () => {
55
- let response;
56
- try {
57
- response = await _this._get(question_id, options);
58
- } catch (error) {
59
- apiErrorCount++;
60
- if (apiErrorCount > 10) {
61
- clearInterval(intervalId);
62
- // TODO: cascade to buffer and user
63
- }
64
53
 
65
- console.error(error); // TODO
66
- return;
67
- }
68
- const {
69
- finished
70
- } = response;
71
- buffer.update(response, finished);
72
- if (response.finished) {
73
- clearInterval(intervalId);
74
- }
75
- }, pollingInternal);
76
- yield* buffer;
77
- }();
78
- } catch (e) {
79
- return Promise.reject(e);
80
- }
54
+ console.error(error); // TODO
55
+ return;
56
+ }
57
+ const {
58
+ finished
59
+ } = response;
60
+ buffer.update(response, finished);
61
+ if (response.finished) {
62
+ clearInterval(intervalId);
63
+ }
64
+ }, pollingInternal);
65
+ return buffer;
81
66
  }
82
67
  }
83
- exports.default = Ask;
68
+ exports.default = Ask;
69
+ class Answer {
70
+ constructor(api, _ref3) {
71
+ let {
72
+ question_id
73
+ } = _ref3;
74
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
75
+ this._api = api;
76
+ this._id = question_id;
77
+ this._options = options;
78
+ }
79
+ get id() {
80
+ return this._id;
81
+ }
82
+ async get(options) {
83
+ options = Object.assign({}, this._options, options);
84
+ return this._api._get(this._id, options);
85
+ }
86
+ [Symbol.asyncIterator]() {
87
+ return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
88
+ }
89
+ }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '1.7.2-beta.0';
7
+ var _default = '1.7.3-beta.0';
8
8
  exports.default = _default;
@@ -7,69 +7,75 @@ export default class Ask extends ApiBase {
7
7
  constructor(api) {
8
8
  super(api, 'ask');
9
9
  }
10
- questions(payload) {
10
+ async questions(payload) {
11
11
  let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12
12
  let {
13
13
  iterable = false
14
14
  } = _ref,
15
15
  options = _objectWithoutPropertiesLoose(_ref, _excluded);
16
- // TODO: it's possible to merge _iterator and _answer
17
- return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterator(payload, options) : this._questions(payload, options);
16
+ const response = await this._run('questions', payload, options);
17
+ return new Answer(this, response);
18
18
  }
19
19
  async _questions(payload, options) {
20
20
  return this._run('questions', payload, options);
21
21
  }
22
- async _get(answerId, options) {
23
- return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
22
+ async _get(questionId, options) {
23
+ return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
24
24
  method: 'GET'
25
25
  }));
26
26
  }
27
- _iterator(payload) {
28
- try {
29
- var _this = this;
30
- let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
- return async function* () {
32
- let {
33
- pollingInternal = 500
34
- } = _ref2,
35
- options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
36
- const response = await _this._questions(payload, options);
37
- yield response;
38
- const {
39
- question_id,
40
- finished
41
- } = response;
42
- if (finished) {
43
- return;
27
+ _iterable(questionId) {
28
+ let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29
+ let {
30
+ pollingInternal = 500
31
+ } = _ref2,
32
+ options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
33
+ // TODO: abort signal
34
+ let apiErrorCount = 0;
35
+ const buffer = new ValueBuffer();
36
+ const intervalId = setInterval(async () => {
37
+ let response;
38
+ try {
39
+ response = await this._get(questionId, options);
40
+ } catch (error) {
41
+ apiErrorCount++;
42
+ if (apiErrorCount > 10) {
43
+ clearInterval(intervalId);
44
+ // TODO: cascade to buffer and user
44
45
  }
45
- let apiErrorCount = 0;
46
- const buffer = new ValueBuffer();
47
- const intervalId = setInterval(async () => {
48
- let response;
49
- try {
50
- response = await _this._get(question_id, options);
51
- } catch (error) {
52
- apiErrorCount++;
53
- if (apiErrorCount > 10) {
54
- clearInterval(intervalId);
55
- // TODO: cascade to buffer and user
56
- }
57
46
 
58
- console.error(error); // TODO
59
- return;
60
- }
61
- const {
62
- finished
63
- } = response;
64
- buffer.update(response, finished);
65
- if (response.finished) {
66
- clearInterval(intervalId);
67
- }
68
- }, pollingInternal);
69
- yield* buffer;
70
- }();
71
- } catch (e) {
72
- return Promise.reject(e);
73
- }
47
+ console.error(error); // TODO
48
+ return;
49
+ }
50
+ const {
51
+ finished
52
+ } = response;
53
+ buffer.update(response, finished);
54
+ if (response.finished) {
55
+ clearInterval(intervalId);
56
+ }
57
+ }, pollingInternal);
58
+ return buffer;
59
+ }
60
+ }
61
+ class Answer {
62
+ constructor(api, _ref3) {
63
+ let {
64
+ question_id
65
+ } = _ref3;
66
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
67
+ this._api = api;
68
+ this._id = question_id;
69
+ this._options = options;
70
+ }
71
+ get id() {
72
+ return this._id;
73
+ }
74
+ async get(options) {
75
+ options = Object.assign({}, this._options, options);
76
+ return this._api._get(this._id, options);
77
+ }
78
+ [Symbol.asyncIterator]() {
79
+ return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
74
80
  }
75
81
  }
@@ -1 +1 @@
1
- export default '1.7.2-beta.0';
1
+ export default '1.7.3-beta.0';
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@miso.ai/commons": "1.7.2-beta.0"
32
+ "@miso.ai/commons": "1.7.3-beta.0"
33
33
  },
34
- "version": "1.7.2-beta.0"
34
+ "version": "1.7.3-beta.0"
35
35
  }