@miso.ai/server-sdk 0.6.3-beta.0 → 0.6.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.
package/cli/index.js CHANGED
@@ -5,6 +5,7 @@ import upload from './upload.js';
5
5
  import del from './delete.js';
6
6
  import ids from './ids.js';
7
7
  import transform from './transform.js';
8
+ import status from './status.js';
8
9
 
9
10
  const interactions = {
10
11
  command: 'interactions',
@@ -21,7 +22,8 @@ const products = {
21
22
  builder: yargs => _buildForApi(yargs)
22
23
  .command(upload('products'))
23
24
  .command(del('products'))
24
- .command(ids('products')),
25
+ .command(ids('products'))
26
+ .command(status('products')),
25
27
  };
26
28
 
27
29
  const users = {
@@ -31,7 +33,8 @@ const users = {
31
33
  builder: yargs => _buildForApi(yargs)
32
34
  .command(upload('users'))
33
35
  .command(del('users'))
34
- .command(ids('users')),
36
+ .command(ids('users'))
37
+ .command(status('users')),
35
38
  };
36
39
 
37
40
  const experiments = {
@@ -80,5 +83,9 @@ function _buildForApi(yargs) {
80
83
  type: 'array',
81
84
  coerce: yargs.coerceToArray,
82
85
  })
86
+ .option('debug', {
87
+ describe: 'Set log level to debug',
88
+ type: 'boolean',
89
+ })
83
90
  .demandOption(['key'], 'API key is required.');
84
91
  }
package/cli/status.js ADDED
@@ -0,0 +1,49 @@
1
+ import split2 from 'split2';
2
+ import { stream } from '@miso.ai/server-commons';
3
+ import { MisoClient } from '../src/index.js';
4
+
5
+ const build = type => yargs => {
6
+ return yargs;
7
+ };
8
+
9
+ const run = type => async ({
10
+ key,
11
+ server,
12
+ taskId,
13
+ }) => {
14
+ const client = new MisoClient({ key, server });
15
+ if (taskId) {
16
+ runOne(client, type, taskId);
17
+ } else {
18
+ runStream(client, type, { key, server });
19
+ }
20
+ };
21
+
22
+ async function runOne(client, type, taskId) {
23
+ try {
24
+ console.log(await client.api[type].status(taskId));
25
+ } catch (err) {
26
+ console.error(err);
27
+ throw err;
28
+ }
29
+ }
30
+
31
+ async function runStream(client, type) {
32
+ await stream.pipeline([
33
+ process.stdin,
34
+ split2(),
35
+ client.api[type].statusStream(),
36
+ new stream.OutputStream({
37
+ objectMode: true,
38
+ }),
39
+ ]);
40
+ }
41
+
42
+ export default function(type) {
43
+ return {
44
+ command: 'status [taskId]',
45
+ description: false,
46
+ builder: build(type),
47
+ handler: run(type),
48
+ };
49
+ }
package/cli/transform.js CHANGED
@@ -1,10 +1,6 @@
1
- import { join } from 'path';
2
- import { Transform } from 'stream';
3
1
  import split2 from 'split2';
4
2
  import { stream } from '@miso.ai/server-commons';
5
3
 
6
- const PWD = process.env.PWD;
7
-
8
4
  function build(yargs) {
9
5
  return yargs
10
6
  .positional('file', {
@@ -14,7 +10,7 @@ function build(yargs) {
14
10
  }
15
11
 
16
12
  async function run({ file }) {
17
- const transform = await getTransformStream(file);
13
+ const transform = await stream.getTransformStream(file);
18
14
  const streams = [
19
15
  process.stdin,
20
16
  split2(),
@@ -30,26 +26,6 @@ async function run({ file }) {
30
26
  await stream.pipeline(...streams);
31
27
  }
32
28
 
33
- async function getTransformStream(loc) {
34
- const mod = await import(join(PWD, loc));
35
- return mod.default ? new mod.default() : new Transform(normalizeOptions(mod));
36
- }
37
-
38
- function normalizeOptions({
39
- objectMode,
40
- readableObjectMode,
41
- writableObjectMode,
42
- ...options
43
- } = {}) {
44
- readableObjectMode = readableObjectMode !== undefined ? readableObjectMode : objectMode !== undefined ? objectMode : true;
45
- writableObjectMode = writableObjectMode !== undefined ? writableObjectMode : objectMode !== undefined ? objectMode : true;
46
- return {
47
- readableObjectMode,
48
- writableObjectMode,
49
- ...options
50
- };
51
- }
52
-
53
29
  export default {
54
30
  command: 'transform [file]',
55
31
  alias: ['t'],
package/cli/upload.js CHANGED
@@ -24,10 +24,6 @@ function build(yargs) {
24
24
  alias: ['bps'],
25
25
  describe: 'How many bytes to send per second',
26
26
  })
27
- .option('debug', {
28
- describe: 'Set log level to debug',
29
- type: 'boolean',
30
- })
31
27
  .option('progress', {
32
28
  alias: ['p'],
33
29
  describe: 'Set log format progress',
@@ -75,7 +71,6 @@ const run = type => async ({
75
71
  dryRun,
76
72
  params,
77
73
  heartbeatInterval: logFormat === logger.FORMAT.PROGRESS ? 250 : false,
78
- //heartbeat: logFormat === logger.FORMAT.PROGRESS ? 250 : undefined,
79
74
  recordsPerRequest,
80
75
  bytesPerRequest,
81
76
  bytesPerSecond,
package/package.json CHANGED
@@ -16,11 +16,11 @@
16
16
  "simonpai <simon.pai@askmiso.com>"
17
17
  ],
18
18
  "dependencies": {
19
- "@miso.ai/server-commons": "0.6.3-beta.0",
19
+ "@miso.ai/server-commons": "0.6.3-beta.2",
20
20
  "axios": "^0.27.2",
21
21
  "dotenv": "^16.0.1",
22
22
  "split2": "^4.1.0",
23
23
  "yargs": "^17.5.1"
24
24
  },
25
- "version": "0.6.3-beta.0"
25
+ "version": "0.6.3-beta.2"
26
26
  }
package/src/api/base.js CHANGED
@@ -2,6 +2,7 @@ import axios from 'axios';
2
2
  import { upload, batchDelete, buildUrl } from './helpers.js';
3
3
  import UploadStream from '../stream/upload.js';
4
4
  import DeleteStream from '../stream/delete.js';
5
+ import StatusStream from '../stream/status.js';
5
6
 
6
7
  export class Queries {
7
8
 
@@ -59,4 +60,13 @@ export class Entities extends Writable {
59
60
  return new DeleteStream(this._client, this._type, options);
60
61
  }
61
62
 
63
+ async status(taskId) {
64
+ const url = buildUrl(this._client, `${this._type}/_status/${taskId}`);
65
+ return (await axios.get(url)).data;
66
+ }
67
+
68
+ statusStream() {
69
+ return new StatusStream(this._client, this._type);
70
+ }
71
+
62
72
  }
@@ -0,0 +1,45 @@
1
+ import { Transform } from 'stream';
2
+
3
+ export default class StatusStream extends Transform {
4
+
5
+ constructor(client, type) {
6
+ super({
7
+ objectMode: true,
8
+ });
9
+ this._client = client;
10
+ this._type = type;
11
+ }
12
+
13
+ async _transform(task_id, _) {
14
+ try {
15
+ this.push({
16
+ task_id,
17
+ ...(await this._client.api[this._type].status(task_id)),
18
+ });
19
+ } catch (err) {
20
+ this.push({
21
+ task_id,
22
+ errors: true,
23
+ error: summarizeError(err),
24
+ });
25
+ }
26
+ }
27
+
28
+ }
29
+
30
+ function summarizeError(error) {
31
+ if (error.response) {
32
+ const { status, data } = error.response;
33
+ return {
34
+ response: { status, data },
35
+ };
36
+ } else if (error.message) {
37
+ return {
38
+ message: error.message,
39
+ };
40
+ } else {
41
+ return {
42
+ message: `${error}`,
43
+ };
44
+ }
45
+ }
@@ -36,8 +36,8 @@ class ExperimentEventUploadSink extends UploadSink {
36
36
 
37
37
  async _execute(payload) {
38
38
  const { experimentId } = this._options;
39
- const response = await this._client.api.experiments.uploadEvent(experimentId, payload);
40
- return response.data;
39
+ const { data } = await this._client.api.experiments.uploadEvent(experimentId, payload);
40
+ return data;
41
41
  }
42
42
 
43
43
  }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.6.3-beta.0';
1
+ export default '0.6.3-beta.2';