@miso.ai/client-sdk-core 1.7.2 → 1.7.3-beta.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.
@@ -6,78 +6,79 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
8
  var _base = _interopRequireDefault(require("./base"));
9
- const _excluded = ["iterable"],
10
- _excluded2 = ["pollingInternal"];
9
+ const _excluded = ["pollingInternal"];
11
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
11
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
12
  class Ask extends _base.default {
14
13
  constructor(api) {
15
14
  super(api, 'ask');
16
15
  }
17
- questions(payload) {
18
- let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
19
- let {
20
- iterable = false
21
- } = _ref,
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);
16
+ async questions(payload) {
17
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
+ const response = await this._run('questions', payload, options);
19
+ return new Answer(this, response);
25
20
  }
26
21
  async _questions(payload, options) {
27
22
  return this._run('questions', payload, options);
28
23
  }
29
- async _get(answerId, options) {
30
- return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
24
+ async _get(questionId, options) {
25
+ return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
31
26
  method: 'GET'
32
27
  }));
33
28
  }
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;
29
+ _iterable(questionId) {
30
+ let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
+ let {
32
+ pollingInternal = 500
33
+ } = _ref,
34
+ options = _objectWithoutPropertiesLoose(_ref, _excluded);
35
+ // TODO: abort signal
36
+ let apiErrorCount = 0;
37
+ const buffer = new _commons.ValueBuffer();
38
+ const intervalId = setInterval(async () => {
39
+ let response;
40
+ try {
41
+ response = await this._get(questionId, options);
42
+ } catch (error) {
43
+ apiErrorCount++;
44
+ if (apiErrorCount > 10) {
45
+ clearInterval(intervalId);
46
+ // TODO: cascade to buffer and user
51
47
  }
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
48
 
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
- }
49
+ console.error(error); // TODO
50
+ return;
51
+ }
52
+ const {
53
+ finished
54
+ } = response;
55
+ buffer.update(response, finished);
56
+ if (response.finished) {
57
+ clearInterval(intervalId);
58
+ }
59
+ }, pollingInternal);
60
+ return buffer;
81
61
  }
82
62
  }
83
- exports.default = Ask;
63
+ exports.default = Ask;
64
+ class Answer {
65
+ constructor(api, _ref2) {
66
+ let {
67
+ question_id
68
+ } = _ref2;
69
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
70
+ this._api = api;
71
+ this._id = question_id;
72
+ this._options = options;
73
+ }
74
+ get id() {
75
+ return this._id;
76
+ }
77
+ async get(options) {
78
+ options = Object.assign({}, this._options, options);
79
+ return this._api._get(this._id, options);
80
+ }
81
+ [Symbol.asyncIterator]() {
82
+ return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
83
+ }
84
+ }
@@ -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';
7
+ var _default = '1.7.3-beta.1';
8
8
  exports.default = _default;
@@ -1,5 +1,4 @@
1
- const _excluded = ["iterable"],
2
- _excluded2 = ["pollingInternal"];
1
+ const _excluded = ["pollingInternal"];
3
2
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
3
  import { ValueBuffer } from '@miso.ai/commons';
5
4
  import ApiBase from './base';
@@ -7,69 +6,71 @@ export default class Ask extends ApiBase {
7
6
  constructor(api) {
8
7
  super(api, 'ask');
9
8
  }
10
- questions(payload) {
11
- let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12
- let {
13
- iterable = false
14
- } = _ref,
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);
9
+ async questions(payload) {
10
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
11
+ const response = await this._run('questions', payload, options);
12
+ return new Answer(this, response);
18
13
  }
19
14
  async _questions(payload, options) {
20
15
  return this._run('questions', payload, options);
21
16
  }
22
- async _get(answerId, options) {
23
- return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
17
+ async _get(questionId, options) {
18
+ return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
24
19
  method: 'GET'
25
20
  }));
26
21
  }
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;
22
+ _iterable(questionId) {
23
+ let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24
+ let {
25
+ pollingInternal = 500
26
+ } = _ref,
27
+ options = _objectWithoutPropertiesLoose(_ref, _excluded);
28
+ // TODO: abort signal
29
+ let apiErrorCount = 0;
30
+ const buffer = new ValueBuffer();
31
+ const intervalId = setInterval(async () => {
32
+ let response;
33
+ try {
34
+ response = await this._get(questionId, options);
35
+ } catch (error) {
36
+ apiErrorCount++;
37
+ if (apiErrorCount > 10) {
38
+ clearInterval(intervalId);
39
+ // TODO: cascade to buffer and user
44
40
  }
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
41
 
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
- }
42
+ console.error(error); // TODO
43
+ return;
44
+ }
45
+ const {
46
+ finished
47
+ } = response;
48
+ buffer.update(response, finished);
49
+ if (response.finished) {
50
+ clearInterval(intervalId);
51
+ }
52
+ }, pollingInternal);
53
+ return buffer;
54
+ }
55
+ }
56
+ class Answer {
57
+ constructor(api, _ref2) {
58
+ let {
59
+ question_id
60
+ } = _ref2;
61
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
62
+ this._api = api;
63
+ this._id = question_id;
64
+ this._options = options;
65
+ }
66
+ get id() {
67
+ return this._id;
68
+ }
69
+ async get(options) {
70
+ options = Object.assign({}, this._options, options);
71
+ return this._api._get(this._id, options);
72
+ }
73
+ [Symbol.asyncIterator]() {
74
+ return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
74
75
  }
75
76
  }
@@ -1 +1 @@
1
- export default '1.7.2';
1
+ export default '1.7.3-beta.1';
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"
32
+ "@miso.ai/commons": "1.7.3-beta.1"
33
33
  },
34
- "version": "1.7.2"
34
+ "version": "1.7.3-beta.1"
35
35
  }