@miso.ai/server-sdk 0.6.0-beta.0 → 0.6.0-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.
- package/cli/index.js +22 -40
- package/cli/transform.js +44 -0
- package/package.json +2 -2
- package/src/version.js +1 -1
package/cli/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import '
|
|
3
|
-
import yargs from 'yargs/yargs';
|
|
4
|
-
import { hideBin } from 'yargs/helpers';
|
|
2
|
+
import { yargs } from '@miso.ai/server-commons';
|
|
5
3
|
import upload from './upload.js';
|
|
6
|
-
import
|
|
4
|
+
import del from './delete.js';
|
|
7
5
|
import ids from './ids.js';
|
|
6
|
+
import transform from './transform.js';
|
|
8
7
|
import version from '../src/version.js';
|
|
9
8
|
|
|
10
9
|
const interactions = {
|
|
11
10
|
command: 'interactions',
|
|
12
11
|
aliases: ['interaction', 'i'],
|
|
13
12
|
description: 'Interaction commands',
|
|
14
|
-
builder: yargs =>
|
|
13
|
+
builder: yargs => _buildForApi(yargs)
|
|
15
14
|
.command(upload('interactions')),
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
const products = {
|
|
19
18
|
command: 'products',
|
|
20
|
-
aliases: ['product', 'p'],
|
|
19
|
+
aliases: ['product', 'p', 'catalog'],
|
|
21
20
|
description: 'Product commands',
|
|
22
|
-
builder: yargs =>
|
|
21
|
+
builder: yargs => _buildForApi(yargs)
|
|
23
22
|
.command(upload('products'))
|
|
24
|
-
.command(
|
|
23
|
+
.command(del('products'))
|
|
25
24
|
.command(ids('products')),
|
|
26
25
|
};
|
|
27
26
|
|
|
@@ -29,9 +28,9 @@ const users = {
|
|
|
29
28
|
command: 'users',
|
|
30
29
|
aliases: ['user', 'u'],
|
|
31
30
|
description: 'User commands',
|
|
32
|
-
builder: yargs =>
|
|
31
|
+
builder: yargs => _buildForApi(yargs)
|
|
33
32
|
.command(upload('users'))
|
|
34
|
-
.command(
|
|
33
|
+
.command(del('users'))
|
|
35
34
|
.command(ids('users')),
|
|
36
35
|
};
|
|
37
36
|
|
|
@@ -39,7 +38,7 @@ const experiments = {
|
|
|
39
38
|
command: 'experiments',
|
|
40
39
|
aliases: ['experiment'],
|
|
41
40
|
description: 'Experiment commands',
|
|
42
|
-
builder: yargs =>
|
|
41
|
+
builder: yargs => _buildForApi(yargs)
|
|
43
42
|
.option('experiment-id', {
|
|
44
43
|
alias: ['exp-id'],
|
|
45
44
|
describe: 'Experiment ID for experiment API',
|
|
@@ -51,22 +50,21 @@ const experiments = {
|
|
|
51
50
|
}),
|
|
52
51
|
};
|
|
53
52
|
|
|
54
|
-
yargs(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.parse();
|
|
53
|
+
yargs.build(yargs => {
|
|
54
|
+
yargs
|
|
55
|
+
.env('MISO')
|
|
56
|
+
.command(interactions)
|
|
57
|
+
.command(products)
|
|
58
|
+
.command(users)
|
|
59
|
+
.command(experiments)
|
|
60
|
+
.command(transform)
|
|
61
|
+
.version(version);
|
|
62
|
+
});
|
|
65
63
|
|
|
66
64
|
|
|
67
65
|
|
|
68
66
|
// helpers //
|
|
69
|
-
function
|
|
67
|
+
function _buildForApi(yargs) {
|
|
70
68
|
return yargs
|
|
71
69
|
.option('key', {
|
|
72
70
|
alias: ['k', 'api-key'],
|
|
@@ -80,23 +78,7 @@ function _buildBase(yargs) {
|
|
|
80
78
|
alias: ['v', 'var'],
|
|
81
79
|
describe: 'Extra URL parameters',
|
|
82
80
|
type: 'array',
|
|
83
|
-
coerce:
|
|
81
|
+
coerce: yargs.coerceToArray,
|
|
84
82
|
})
|
|
85
83
|
.demandOption(['key'], 'API key is required.');
|
|
86
84
|
}
|
|
87
|
-
|
|
88
|
-
function _coerceToArray(arg) {
|
|
89
|
-
return Array.isArray(arg) ? arg :
|
|
90
|
-
typeof arg === 'string' ? arg.split(',') :
|
|
91
|
-
arg === undefined || arg === null ? [] : [arg];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function _handleFail(msg, err) {
|
|
95
|
-
if (err) {
|
|
96
|
-
throw err;
|
|
97
|
-
}
|
|
98
|
-
console.error(msg);
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
process.stdout.on('error', err => err.code == 'EPIPE' && process.exit(0));
|
package/cli/transform.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { Transform } from 'stream';
|
|
3
|
+
import split2 from 'split2';
|
|
4
|
+
import { stream } from '@miso.ai/server-commons';
|
|
5
|
+
|
|
6
|
+
const PWD = process.env.PWD;
|
|
7
|
+
|
|
8
|
+
function build(yargs) {
|
|
9
|
+
return yargs
|
|
10
|
+
.positional('file', {
|
|
11
|
+
describe: 'Transform function location',
|
|
12
|
+
default: 'transform.js',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function run({ file }) {
|
|
17
|
+
const transform = await getTransformStream(file);
|
|
18
|
+
const streams = [
|
|
19
|
+
process.stdin,
|
|
20
|
+
split2(),
|
|
21
|
+
];
|
|
22
|
+
if (transform.writableObjectMode) {
|
|
23
|
+
streams.push(stream.parse());
|
|
24
|
+
}
|
|
25
|
+
streams.push(transform);
|
|
26
|
+
streams.push(new stream.OutputStream({
|
|
27
|
+
objectMode: transform.readableObjectMode,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
await stream.pipeline(streams);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function getTransformStream(loc) {
|
|
34
|
+
const mod = await import(join(PWD, loc));
|
|
35
|
+
return mod.default ? new mod.default() : new Transform({ objectMode: mod.objectMode !== false, ...mod });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
command: 'transform [file]',
|
|
40
|
+
alias: ['t'],
|
|
41
|
+
description: `Transform records by a JavaScript module [file]. The module should contains a default export of a node Transform stream class. Object modes on both sides are respected.`,
|
|
42
|
+
builder: build,
|
|
43
|
+
handler: run,
|
|
44
|
+
};
|
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.0-beta.
|
|
19
|
+
"@miso.ai/server-commons": "0.6.0-beta.1",
|
|
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.0-beta.
|
|
25
|
+
"version": "0.6.0-beta.1"
|
|
26
26
|
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.0-beta.
|
|
1
|
+
export default '0.6.0-beta.1';
|