@apollo-annotation/cli 0.1.17 → 0.1.19
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/README.md +120 -58
- package/bin/dev.js +2 -2
- package/bin/run.js +2 -2
- package/dist/ApolloConf.d.ts +22 -0
- package/dist/ApolloConf.js +144 -0
- package/dist/baseCommand.js +7 -17
- package/dist/commands/assembly/add-fasta.js +16 -27
- package/dist/commands/assembly/add-gff.js +11 -24
- package/dist/commands/assembly/check.js +7 -18
- package/dist/commands/assembly/delete.js +1 -1
- package/dist/commands/assembly/get.test.js +3 -3
- package/dist/commands/assembly/sequence.js +7 -21
- package/dist/commands/change/get.test.js +1 -1
- package/dist/commands/config.js +21 -53
- package/dist/commands/feature/add-child.js +21 -29
- package/dist/commands/feature/check.js +5 -5
- package/dist/commands/feature/copy.js +20 -32
- package/dist/commands/feature/delete.js +16 -31
- package/dist/commands/feature/edit-attribute.js +15 -10
- package/dist/commands/feature/edit-coords.js +39 -27
- package/dist/commands/feature/edit-type.js +5 -8
- package/dist/commands/feature/edit.js +3 -16
- package/dist/commands/feature/get-id.js +0 -1
- package/dist/commands/feature/get.js +6 -18
- package/dist/commands/feature/import.js +22 -41
- package/dist/commands/feature/search.js +1 -1
- package/dist/commands/login.js +17 -29
- package/dist/commands/logout.js +5 -14
- package/dist/commands/refseq/add-alias.d.ts +14 -0
- package/dist/commands/refseq/add-alias.js +72 -0
- package/dist/commands/status.js +5 -13
- package/dist/commands/user/get.test.js +1 -1
- package/dist/test/fixtures.js +2 -2
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +50 -25
- package/oclif.manifest.json +163 -102
- package/package.json +11 -3
- package/dist/Config.d.ts +0 -43
- package/dist/Config.js +0 -233
- package/dist/commands/config.test.d.ts +0 -1
- package/dist/commands/config.test.js +0 -188
- package/dist/commands/login.test.d.ts +0 -1
- package/dist/commands/login.test.js +0 -52
- package/dist/commands/logout.test.d.ts +0 -1
- package/dist/commands/logout.test.js +0 -67
- package/dist/commands/status.test.d.ts +0 -1
- package/dist/commands/status.test.js +0 -54
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
1
|
import { Flags } from '@oclif/core';
|
|
6
2
|
import { fetch } from 'undici';
|
|
7
3
|
import { BaseCommand } from '../../baseCommand.js';
|
|
@@ -9,18 +5,15 @@ import { createFetchErrorMessage, getFeatureById, idReader, localhostToAddress,
|
|
|
9
5
|
async function deleteFeature(address, accessToken, feature) {
|
|
10
6
|
const changeJson = {
|
|
11
7
|
typeName: 'DeleteFeatureChange',
|
|
12
|
-
changedIds: [feature],
|
|
13
|
-
assembly:
|
|
8
|
+
changedIds: [feature._id],
|
|
9
|
+
assembly: '111222333444555666777888', // Use a placeholder objectId (i.e. some 24 chars)
|
|
14
10
|
deletedFeature: {
|
|
15
|
-
_id: feature
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
discontinuousLocations: feature['discontinuousLocations'],
|
|
22
|
-
score: feature['score'],
|
|
23
|
-
attributes: feature['attributes'],
|
|
11
|
+
_id: feature._id,
|
|
12
|
+
refSeq: feature.refSeq,
|
|
13
|
+
type: feature.type,
|
|
14
|
+
min: feature.min,
|
|
15
|
+
max: feature.max,
|
|
16
|
+
attributes: feature.attributes,
|
|
24
17
|
},
|
|
25
18
|
};
|
|
26
19
|
const url = new URL(localhostToAddress(`${address}/changes`));
|
|
@@ -67,33 +60,25 @@ export default class Delete extends BaseCommand {
|
|
|
67
60
|
}
|
|
68
61
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
69
62
|
for (const featureId of featureIds) {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
63
|
+
const res = await getFeatureById(access.address, access.accessToken, featureId);
|
|
64
|
+
if (res.status === 404 && flags.force) {
|
|
72
65
|
continue;
|
|
73
66
|
}
|
|
74
|
-
if (!
|
|
75
|
-
const errorMessage = await createFetchErrorMessage(
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
const errorMessage = await createFetchErrorMessage(res, 'getFeatureById failed');
|
|
76
69
|
throw new Error(errorMessage);
|
|
77
70
|
}
|
|
78
|
-
const feature = JSON.parse(await
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
const message = feature['message'];
|
|
81
|
-
this.logToStderr(message);
|
|
82
|
-
this.exit(1);
|
|
83
|
-
}
|
|
71
|
+
const feature = JSON.parse(await res.text());
|
|
84
72
|
if (flags['dry-run']) {
|
|
85
|
-
this.log(feature);
|
|
73
|
+
this.log(JSON.stringify(feature, null, 2));
|
|
86
74
|
}
|
|
87
75
|
else {
|
|
88
76
|
const delFet = await deleteFeature(access.address, access.accessToken, feature);
|
|
89
77
|
if (!delFet.ok) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
this.logToStderr(message);
|
|
93
|
-
this.exit(1);
|
|
78
|
+
const errorMessage = await createFetchErrorMessage(delFet, 'Delete feature failed');
|
|
79
|
+
throw new Error(errorMessage);
|
|
94
80
|
}
|
|
95
81
|
}
|
|
96
82
|
}
|
|
97
|
-
this.exit(0);
|
|
98
83
|
}
|
|
99
84
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
1
|
import { Flags } from '@oclif/core';
|
|
5
2
|
import { fetch } from 'undici';
|
|
6
3
|
import { BaseCommand } from '../../baseCommand.js';
|
|
@@ -47,12 +44,11 @@ export default class EditAttibute extends BaseCommand {
|
|
|
47
44
|
async run() {
|
|
48
45
|
const { flags } = await this.parse(EditAttibute);
|
|
49
46
|
if (flags.delete && flags.value) {
|
|
50
|
-
this.
|
|
51
|
-
this.exit(1);
|
|
47
|
+
this.error('Error: Options --delete and --value are mutually exclusive');
|
|
52
48
|
}
|
|
53
49
|
const ff = idReader([flags['feature-id']]);
|
|
54
50
|
if (ff.length !== 1) {
|
|
55
|
-
this.
|
|
51
|
+
this.error(`Expected only one feature identifier. Got ${ff.length}`);
|
|
56
52
|
}
|
|
57
53
|
const [featureId] = ff;
|
|
58
54
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
@@ -62,9 +58,12 @@ export default class EditAttibute extends BaseCommand {
|
|
|
62
58
|
throw new Error(errorMessage);
|
|
63
59
|
}
|
|
64
60
|
const featureJson = JSON.parse(await response.text());
|
|
61
|
+
if (featureJson.attributes === undefined) {
|
|
62
|
+
featureJson.attributes = {};
|
|
63
|
+
}
|
|
65
64
|
if (flags.value === undefined && !flags.delete) {
|
|
66
65
|
this.log(JSON.stringify(featureJson.attributes[flags.attribute]));
|
|
67
|
-
|
|
66
|
+
return;
|
|
68
67
|
}
|
|
69
68
|
if (flags.delete) {
|
|
70
69
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
@@ -73,13 +72,20 @@ export default class EditAttibute extends BaseCommand {
|
|
|
73
72
|
else {
|
|
74
73
|
featureJson.attributes[flags.attribute] = flags.value;
|
|
75
74
|
}
|
|
76
|
-
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson
|
|
75
|
+
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson.refSeq);
|
|
76
|
+
const attrs = {};
|
|
77
|
+
for (const [key, val] of Object.entries(featureJson.attributes)) {
|
|
78
|
+
if (!val) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
attrs[key] = [...val];
|
|
82
|
+
}
|
|
77
83
|
const changeJson = {
|
|
78
84
|
typeName: 'FeatureAttributeChange',
|
|
79
85
|
changedIds: [featureId],
|
|
80
86
|
assembly,
|
|
81
87
|
featureId,
|
|
82
|
-
attributes:
|
|
88
|
+
attributes: attrs,
|
|
83
89
|
};
|
|
84
90
|
const url = new URL(localhostToAddress(`${access.address}/changes`));
|
|
85
91
|
const auth = {
|
|
@@ -95,6 +101,5 @@ export default class EditAttibute extends BaseCommand {
|
|
|
95
101
|
const errorMessage = await createFetchErrorMessage(res, 'edit-attribute failed');
|
|
96
102
|
throw new Error(errorMessage);
|
|
97
103
|
}
|
|
98
|
-
this.exit(0);
|
|
99
104
|
}
|
|
100
105
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
1
|
import { Flags } from '@oclif/core';
|
|
5
2
|
import { fetch } from 'undici';
|
|
6
3
|
import { BaseCommand } from '../../baseCommand.js';
|
|
@@ -37,43 +34,40 @@ export default class Get extends BaseCommand {
|
|
|
37
34
|
async run() {
|
|
38
35
|
const { flags } = await this.parse(Get);
|
|
39
36
|
if (flags.start === undefined && flags.end === undefined) {
|
|
40
|
-
this.
|
|
41
|
-
this.exit(1);
|
|
37
|
+
this.error('Please provide new start and/or end coordinates to edit');
|
|
42
38
|
}
|
|
43
39
|
if (flags.start !== undefined && flags.start <= 0) {
|
|
44
|
-
this.
|
|
45
|
-
this.exit(1);
|
|
40
|
+
this.error('Coordinates must be greater than 0');
|
|
46
41
|
}
|
|
47
42
|
if (flags.start !== undefined &&
|
|
48
43
|
flags.end !== undefined &&
|
|
49
44
|
flags.end < flags.start) {
|
|
50
|
-
this.
|
|
51
|
-
this.exit(1);
|
|
45
|
+
this.error('Error: The new end coordinate is lower than the new start coordinate');
|
|
52
46
|
}
|
|
53
47
|
if (flags.start !== undefined) {
|
|
54
48
|
flags.start -= 1;
|
|
55
49
|
}
|
|
56
50
|
const ff = idReader([flags['feature-id']]);
|
|
57
51
|
if (ff.length !== 1) {
|
|
58
|
-
this.
|
|
52
|
+
this.error(`Expected only one feature identifier. Got ${ff.length}`);
|
|
59
53
|
}
|
|
60
54
|
const [featureId] = ff;
|
|
61
55
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const errorMessage = await createFetchErrorMessage(
|
|
56
|
+
const res = await getFeatureById(access.address, access.accessToken, featureId);
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
const errorMessage = await createFetchErrorMessage(res, 'getFeatureById failed');
|
|
65
59
|
throw new Error(errorMessage);
|
|
66
60
|
}
|
|
67
|
-
const featureJson = JSON.parse(await
|
|
68
|
-
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson
|
|
69
|
-
const currentEnd = featureJson
|
|
61
|
+
const featureJson = JSON.parse(await res.text());
|
|
62
|
+
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson.refSeq);
|
|
63
|
+
const currentEnd = featureJson.max;
|
|
70
64
|
let edit = ['Start', 'End'];
|
|
71
65
|
if (flags.start !== undefined && flags.start > currentEnd) {
|
|
72
|
-
// Edit End first so you avoid an intermediate start > end
|
|
66
|
+
// Edit End (Max) first so you avoid an intermediate start > end
|
|
73
67
|
edit = ['End', 'Start'];
|
|
74
68
|
}
|
|
75
69
|
for (const coord of edit) {
|
|
76
|
-
const currentStart = featureJson
|
|
70
|
+
const currentStart = featureJson.min;
|
|
77
71
|
if (coord === 'Start' &&
|
|
78
72
|
(flags.start === undefined || flags.start === currentStart)) {
|
|
79
73
|
continue;
|
|
@@ -82,18 +76,36 @@ export default class Get extends BaseCommand {
|
|
|
82
76
|
(flags.end === undefined || flags.end === currentEnd)) {
|
|
83
77
|
continue;
|
|
84
78
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
let body;
|
|
80
|
+
if (coord === 'Start' && flags.start !== undefined) {
|
|
81
|
+
const oldCoord = featureJson.min;
|
|
82
|
+
body = {
|
|
83
|
+
typeName: 'LocationStartChange',
|
|
84
|
+
changedIds: [featureId],
|
|
85
|
+
assembly,
|
|
86
|
+
featureId,
|
|
87
|
+
['oldStart']: oldCoord,
|
|
88
|
+
['newStart']: flags.start,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else if (coord === 'End' && flags.end !== undefined) {
|
|
92
|
+
const oldCoord = featureJson.max;
|
|
93
|
+
body = {
|
|
94
|
+
typeName: 'LocationEndChange',
|
|
95
|
+
changedIds: [featureId],
|
|
96
|
+
assembly,
|
|
97
|
+
featureId,
|
|
98
|
+
['oldEnd']: oldCoord,
|
|
99
|
+
['newEnd']: flags.end,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new Error(`Unexpected coordinate name: "${coord}"`);
|
|
104
|
+
}
|
|
93
105
|
const url = new URL(localhostToAddress(`${access.address}/changes`));
|
|
94
106
|
const auth = {
|
|
95
107
|
method: 'POST',
|
|
96
|
-
body: JSON.stringify(
|
|
108
|
+
body: JSON.stringify(body),
|
|
97
109
|
headers: {
|
|
98
110
|
authorization: `Bearer ${access.accessToken}`,
|
|
99
111
|
'Content-Type': 'application/json',
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
1
|
import { Flags } from '@oclif/core';
|
|
5
2
|
import { fetch } from 'undici';
|
|
6
3
|
import { BaseCommand } from '../../baseCommand.js';
|
|
@@ -24,7 +21,7 @@ export default class Get extends BaseCommand {
|
|
|
24
21
|
const { flags } = await this.parse(Get);
|
|
25
22
|
const ff = idReader([flags['feature-id']]);
|
|
26
23
|
if (ff.length !== 1) {
|
|
27
|
-
this.
|
|
24
|
+
this.error(`Expected only one feature identifier. Got ${ff.length}`);
|
|
28
25
|
}
|
|
29
26
|
const [featureId] = ff;
|
|
30
27
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
@@ -34,16 +31,16 @@ export default class Get extends BaseCommand {
|
|
|
34
31
|
throw new Error(errorMessage);
|
|
35
32
|
}
|
|
36
33
|
const featureJson = JSON.parse(await response.text());
|
|
37
|
-
const currentType = featureJson
|
|
34
|
+
const currentType = featureJson.type;
|
|
38
35
|
if (flags.type === undefined) {
|
|
39
36
|
this.log(currentType);
|
|
40
|
-
|
|
37
|
+
return;
|
|
41
38
|
}
|
|
42
39
|
if (flags.type === currentType) {
|
|
43
40
|
this.logToStderr(`NOTE: Feature ${featureId} is already of type "${flags.type}"`);
|
|
44
|
-
|
|
41
|
+
return;
|
|
45
42
|
}
|
|
46
|
-
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson
|
|
43
|
+
const assembly = await getAssemblyFromRefseq(access.address, access.accessToken, featureJson.refSeq);
|
|
47
44
|
const changeJson = {
|
|
48
45
|
typeName: 'TypeChange',
|
|
49
46
|
changedIds: [featureId],
|
|
@@ -42,21 +42,9 @@ export default class Get extends BaseCommand {
|
|
|
42
42
|
else if (fs.existsSync(flags['json-input'])) {
|
|
43
43
|
jsonStr = fs.readFileSync(flags['json-input']).toString();
|
|
44
44
|
}
|
|
45
|
-
let json;
|
|
46
|
-
|
|
47
|
-
json =
|
|
48
|
-
if (!Array.isArray(json)) {
|
|
49
|
-
json = [json];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (error instanceof Error) {
|
|
54
|
-
this.logToStderr(`Error parsing json input:\n${error.message}`);
|
|
55
|
-
this.exit(1);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
45
|
+
let json = JSON.parse(jsonStr);
|
|
46
|
+
if (!Array.isArray(json)) {
|
|
47
|
+
json = [json];
|
|
60
48
|
}
|
|
61
49
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
62
50
|
for (const change of json) {
|
|
@@ -76,6 +64,5 @@ export default class Get extends BaseCommand {
|
|
|
76
64
|
throw new Error(errorMessage);
|
|
77
65
|
}
|
|
78
66
|
}
|
|
79
|
-
this.exit(0);
|
|
80
67
|
}
|
|
81
68
|
}
|
|
@@ -33,7 +33,6 @@ export default class Get extends BaseCommand {
|
|
|
33
33
|
results.push(res);
|
|
34
34
|
}
|
|
35
35
|
this.log(JSON.stringify(results, null, 2));
|
|
36
|
-
this.exit(0);
|
|
37
36
|
}
|
|
38
37
|
async getFeatureId(address, token, featureId) {
|
|
39
38
|
const url = new URL(localhostToAddress(`${address}/features/${featureId}`));
|
|
@@ -37,21 +37,10 @@ export default class Get extends BaseCommand {
|
|
|
37
37
|
const { flags } = await this.parse(Get);
|
|
38
38
|
const endCoord = flags.end ?? Number.MAX_SAFE_INTEGER;
|
|
39
39
|
if (flags.start <= 0 || endCoord <= 0) {
|
|
40
|
-
this.
|
|
41
|
-
this.exit(1);
|
|
40
|
+
this.error('Start and end coordinates must be greater than 0.');
|
|
42
41
|
}
|
|
43
42
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
refseqIds = await getRefseqId(access.address, access.accessToken, flags.refseq, flags.assembly);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
this.logToStderr(error.message);
|
|
50
|
-
this.exit(1);
|
|
51
|
-
}
|
|
52
|
-
if (refseqIds.length === 0) {
|
|
53
|
-
this.logToStderr('No reference sequence found');
|
|
54
|
-
}
|
|
43
|
+
const refseqIds = await getRefseqId(access.address, access.accessToken, flags.refseq, flags.assembly);
|
|
55
44
|
const results = [];
|
|
56
45
|
for (const refseq of refseqIds) {
|
|
57
46
|
const features = await this.getFeatures(access.address, access.accessToken, refseq, flags.start, endCoord);
|
|
@@ -61,7 +50,6 @@ export default class Get extends BaseCommand {
|
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
this.log(JSON.stringify(results, null, 2));
|
|
64
|
-
this.exit(0);
|
|
65
53
|
}
|
|
66
54
|
async getFeatures(address, token, refSeq, start, end) {
|
|
67
55
|
const url = new URL(localhostToAddress(`${address}/features/getFeatures`));
|
|
@@ -77,11 +65,11 @@ export default class Get extends BaseCommand {
|
|
|
77
65
|
'Content-Type': 'application/json',
|
|
78
66
|
},
|
|
79
67
|
};
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
const errorMessage = await createFetchErrorMessage(
|
|
68
|
+
const res = await fetch(url, auth);
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
const errorMessage = await createFetchErrorMessage(res, 'Failed to access Apollo with the current address and/or access token\nThe server returned:\n');
|
|
83
71
|
throw new Error(errorMessage);
|
|
84
72
|
}
|
|
85
|
-
return
|
|
73
|
+
return res;
|
|
86
74
|
}
|
|
87
75
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
1
|
import * as fs from 'node:fs';
|
|
4
2
|
import { Flags } from '@oclif/core';
|
|
5
|
-
import { fetch } from 'undici';
|
|
3
|
+
import { Agent, fetch } from 'undici';
|
|
6
4
|
import { BaseCommand } from '../../baseCommand.js';
|
|
7
5
|
import { convertAssemblyNameToId, createFetchErrorMessage, localhostToAddress, uploadFile, } from '../../utils.js';
|
|
8
6
|
export default class Import extends BaseCommand {
|
|
@@ -33,51 +31,34 @@ export default class Import extends BaseCommand {
|
|
|
33
31
|
async run() {
|
|
34
32
|
const { flags } = await this.parse(Import);
|
|
35
33
|
if (!fs.existsSync(flags['input-file'])) {
|
|
36
|
-
this.
|
|
37
|
-
this.exit(1);
|
|
34
|
+
this.error(`File "${flags['input-file']}" does not exist`);
|
|
38
35
|
}
|
|
39
36
|
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
40
37
|
const assembly = await convertAssemblyNameToId(access.address, access.accessToken, [flags.assembly]);
|
|
41
38
|
if (assembly.length === 0) {
|
|
42
|
-
this.
|
|
43
|
-
this.exit(1);
|
|
39
|
+
this.error(`Assembly "${flags.assembly}" does not exist. Perhaps you want to create this assembly first`);
|
|
44
40
|
}
|
|
45
41
|
const uploadId = await uploadFile(access.address, access.accessToken, flags['input-file'], 'text/x-gff3');
|
|
46
|
-
const
|
|
42
|
+
const body = {
|
|
43
|
+
typeName: 'AddFeaturesFromFileChange',
|
|
44
|
+
assembly: assembly[0],
|
|
45
|
+
fileId: uploadId,
|
|
46
|
+
deleteExistingFeatures: flags['delete-existing'],
|
|
47
|
+
};
|
|
48
|
+
const auth = {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
body: JSON.stringify(body),
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: `Bearer ${access.accessToken}`,
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
},
|
|
55
|
+
dispatcher: new Agent({ headersTimeout: 60 * 60 * 1000 }),
|
|
56
|
+
};
|
|
57
|
+
const url = new URL(localhostToAddress(`${access.address}/changes`));
|
|
58
|
+
const response = await fetch(url, auth);
|
|
47
59
|
if (!response.ok) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
this.logToStderr(message);
|
|
51
|
-
this.exit(1);
|
|
60
|
+
const errorMessage = await createFetchErrorMessage(response, 'importFeatures failed');
|
|
61
|
+
throw new Error(errorMessage);
|
|
52
62
|
}
|
|
53
|
-
this.exit(0);
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
|
-
async function importFeatures(address, accessToken, assembly, fileId, deleteExistingFeatures) {
|
|
57
|
-
const body = {
|
|
58
|
-
typeName: 'AddFeaturesFromFileChange',
|
|
59
|
-
assembly,
|
|
60
|
-
fileId,
|
|
61
|
-
deleteExistingFeatures,
|
|
62
|
-
};
|
|
63
|
-
const controller = new AbortController();
|
|
64
|
-
setTimeout(() => {
|
|
65
|
-
controller.abort();
|
|
66
|
-
}, 24 * 60 * 60 * 1000);
|
|
67
|
-
const auth = {
|
|
68
|
-
method: 'POST',
|
|
69
|
-
body: JSON.stringify(body),
|
|
70
|
-
headers: {
|
|
71
|
-
Authorization: `Bearer ${accessToken}`,
|
|
72
|
-
'Content-Type': 'application/json',
|
|
73
|
-
},
|
|
74
|
-
signal: controller.signal,
|
|
75
|
-
};
|
|
76
|
-
const url = new URL(localhostToAddress(`${address}/changes`));
|
|
77
|
-
const response = await fetch(url, auth);
|
|
78
|
-
if (!response.ok) {
|
|
79
|
-
const errorMessage = await createFetchErrorMessage(response, 'importFeatures failed');
|
|
80
|
-
throw new Error(errorMessage);
|
|
81
|
-
}
|
|
82
|
-
return response;
|
|
83
|
-
}
|
|
@@ -73,7 +73,7 @@ export default class Search extends BaseCommand {
|
|
|
73
73
|
if (flags.assembly === undefined) {
|
|
74
74
|
const asm = await queryApollo(access.address, access.accessToken, 'assemblies');
|
|
75
75
|
for (const x of (await asm.json())) {
|
|
76
|
-
assemblyIds.push(x
|
|
76
|
+
assemblyIds.push(x._id);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
else {
|
package/dist/commands/login.js
CHANGED
|
@@ -8,8 +8,8 @@ import * as querystring from 'node:querystring';
|
|
|
8
8
|
import { Errors, Flags, ux } from '@oclif/core';
|
|
9
9
|
import open from 'open';
|
|
10
10
|
import { fetch } from 'undici';
|
|
11
|
+
import { ApolloConf } from '../ApolloConf.js';
|
|
11
12
|
import { BaseCommand } from '../baseCommand.js';
|
|
12
|
-
import { Config, ConfigError } from '../Config.js';
|
|
13
13
|
import { basicCheckConfig, createFetchErrorMessage, getUserCredentials, localhostToAddress, waitFor, wrapLines, } from '../utils.js';
|
|
14
14
|
export default class Login extends BaseCommand {
|
|
15
15
|
static summary = 'Login to Apollo';
|
|
@@ -55,27 +55,18 @@ export default class Login extends BaseCommand {
|
|
|
55
55
|
const { flags } = await this.parse(Login);
|
|
56
56
|
let configFile = flags['config-file'];
|
|
57
57
|
if (configFile === undefined) {
|
|
58
|
-
configFile = path.join(this.config.configDir, 'config.
|
|
58
|
+
configFile = path.join(this.config.configDir, 'config.yml');
|
|
59
59
|
}
|
|
60
60
|
let profileName = flags.profile;
|
|
61
61
|
if (profileName === undefined) {
|
|
62
62
|
profileName = process.env.APOLLO_PROFILE ?? 'default';
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (error instanceof ConfigError) {
|
|
69
|
-
this.logToStderr(error.message);
|
|
70
|
-
this.exit(1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const config = new Config(configFile);
|
|
74
|
-
const accessType = config.get('accessType', profileName);
|
|
75
|
-
const address = flags.address ?? config.get('address', profileName);
|
|
64
|
+
basicCheckConfig(configFile, profileName);
|
|
65
|
+
const config = new ApolloConf(configFile);
|
|
66
|
+
const accessType = config.get(`${profileName}.accessType`);
|
|
67
|
+
const address = flags.address ?? config.get(`${profileName}.address`);
|
|
76
68
|
if (address === undefined) {
|
|
77
|
-
this.
|
|
78
|
-
this.exit(1);
|
|
69
|
+
this.error('Address to apollo must be set');
|
|
79
70
|
}
|
|
80
71
|
let userCredentials = { accessToken: '' };
|
|
81
72
|
try {
|
|
@@ -83,11 +74,12 @@ export default class Login extends BaseCommand {
|
|
|
83
74
|
await this.checkUserAlreadyLoggedIn();
|
|
84
75
|
}
|
|
85
76
|
if (accessType === 'root' || flags.username !== undefined) {
|
|
86
|
-
const username = flags.username ??
|
|
87
|
-
|
|
77
|
+
const username = flags.username ??
|
|
78
|
+
config.get(`${profileName}.rootCredentials.username`);
|
|
79
|
+
const password = flags.password ??
|
|
80
|
+
config.get(`${profileName}.rootCredentials.password`);
|
|
88
81
|
if (username === undefined || password === undefined) {
|
|
89
|
-
this.
|
|
90
|
-
this.exit(1);
|
|
82
|
+
this.error('Username and password must be set');
|
|
91
83
|
}
|
|
92
84
|
userCredentials = await this.startRootLogin(address, username, password);
|
|
93
85
|
}
|
|
@@ -95,8 +87,7 @@ export default class Login extends BaseCommand {
|
|
|
95
87
|
userCredentials = await this.startGuestLogin(address);
|
|
96
88
|
}
|
|
97
89
|
else if (accessType === undefined) {
|
|
98
|
-
this.
|
|
99
|
-
this.exit(1);
|
|
90
|
+
this.error('Undefined access type');
|
|
100
91
|
}
|
|
101
92
|
else {
|
|
102
93
|
userCredentials = await this.startAuthorizationCodeFlow(address, accessType, flags.port);
|
|
@@ -105,16 +96,13 @@ export default class Login extends BaseCommand {
|
|
|
105
96
|
catch (error) {
|
|
106
97
|
if ((error instanceof Errors.CLIError && error.message === 'ctrl-c') ||
|
|
107
98
|
error instanceof Errors.ExitError) {
|
|
108
|
-
|
|
99
|
+
return;
|
|
109
100
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
ux.action.stop(error.message);
|
|
113
|
-
this.exit(1);
|
|
101
|
+
if (error instanceof Error) {
|
|
102
|
+
throw error;
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
|
-
config.set(
|
|
117
|
-
config.writeConfigFile();
|
|
105
|
+
config.set(`${profileName}.accessToken`, userCredentials.accessToken);
|
|
118
106
|
}
|
|
119
107
|
async checkUserAlreadyLoggedIn() {
|
|
120
108
|
const userCredentials = getUserCredentials();
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { ApolloConf, KEYS } from '../ApolloConf.js';
|
|
2
3
|
import { BaseCommand } from '../baseCommand.js';
|
|
3
|
-
import { Config, ConfigError, KEYS } from '../Config.js';
|
|
4
4
|
import { basicCheckConfig, wrapLines } from '../utils.js';
|
|
5
5
|
export default class Logout extends BaseCommand {
|
|
6
6
|
static summary = 'Logout of Apollo';
|
|
@@ -23,19 +23,10 @@ export default class Logout extends BaseCommand {
|
|
|
23
23
|
}
|
|
24
24
|
let configFile = flags['config-file'];
|
|
25
25
|
if (configFile === undefined) {
|
|
26
|
-
configFile = path.join(this.config.configDir, 'config.
|
|
26
|
+
configFile = path.join(this.config.configDir, 'config.yml');
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
if (error instanceof ConfigError) {
|
|
33
|
-
this.logToStderr(error.message);
|
|
34
|
-
this.exit(1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const config = new Config(configFile);
|
|
38
|
-
config.set(KEYS.accessToken, '', profileName);
|
|
39
|
-
config.writeConfigFile();
|
|
28
|
+
basicCheckConfig(configFile, profileName);
|
|
29
|
+
const config = new ApolloConf(configFile);
|
|
30
|
+
config.delete(`${profileName}.${KEYS.accessToken}`);
|
|
40
31
|
}
|
|
41
32
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
2
|
+
export default class AddRefNameAlias extends BaseCommand<typeof AddRefNameAlias> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static flags: {
|
|
10
|
+
'input-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|