@apollo-annotation/cli 0.1.20 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import { dirname } from 'node:path';
2
+ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { test } from '@oclif/test';
5
5
  import { CONFIG_FILE, TEST_DATA_DIR, VERBOSE, copyFile, } from '../../test/fixtures.js';
@@ -15,7 +15,7 @@ describe.skip('apollo change get: Get changes as YAML string', () => {
15
15
  const cmd = ['change:get'];
16
16
  test
17
17
  .stdout()
18
- .command(cmd, { root: dirname(dirname(__dirname)) })
18
+ .command(cmd, { root: path.dirname(path.dirname(__dirname)) })
19
19
  .it(cmd.join(' '), (output) => {
20
20
  JSON.parse(output.stdout);
21
21
  });
@@ -47,8 +47,7 @@ export default class ApolloConfig extends BaseCommand {
47
47
  },
48
48
  ];
49
49
  async run() {
50
- const { args } = await this.parse(ApolloConfig);
51
- const { flags } = await this.parse(ApolloConfig);
50
+ const { args, flags } = await this.parse(ApolloConfig);
52
51
  let configFile = flags['config-file'];
53
52
  configFile =
54
53
  configFile === undefined
@@ -71,7 +71,7 @@ to retrive the parent ID of interest and to populate the child feature with attr
71
71
  }
72
72
  const res = await queryApollo(address, accessToken, 'refSeqs');
73
73
  const refSeqs = (await res.json());
74
- const { refSeq } = parentFeature;
74
+ const { refSeq, _id } = parentFeature;
75
75
  let assembly = '';
76
76
  for (const x of refSeqs) {
77
77
  if (x['_id'] === refSeq) {
@@ -81,8 +81,7 @@ to retrive the parent ID of interest and to populate the child feature with attr
81
81
  }
82
82
  const change = {
83
83
  typeName: 'AddFeatureChange',
84
- // eslint-disable-next-line unicorn/consistent-destructuring
85
- changedIds: [parentFeature._id],
84
+ changedIds: [_id],
86
85
  assembly,
87
86
  addedFeature: {
88
87
  _id: new ObjectId().toHexString(),
@@ -91,8 +90,7 @@ to retrive the parent ID of interest and to populate the child feature with attr
91
90
  max,
92
91
  type,
93
92
  },
94
- // eslint-disable-next-line unicorn/consistent-destructuring
95
- parentFeatureId: parentFeature._id,
93
+ parentFeatureId: _id,
96
94
  };
97
95
  const url = new URL(localhostToAddress(`${address}/changes`));
98
96
  const auth = {
@@ -6,8 +6,10 @@ export default class Import extends FileCommand {
6
6
  description: string;
7
7
  command: string;
8
8
  }[];
9
+ static args: {
10
+ 'input-file': import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
11
+ };
9
12
  static flags: {
10
- 'input-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
13
  assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
14
  'delete-existing': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
13
15
  };
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'node:fs';
2
- import { Flags } from '@oclif/core';
2
+ import { Args, Flags } from '@oclif/core';
3
3
  import { Agent, fetch } from 'undici';
4
4
  import { FileCommand } from '../../fileCommand.js';
5
5
  import { convertAssemblyNameToId, createFetchErrorMessage, localhostToAddress, } from '../../utils.js';
@@ -9,15 +9,16 @@ export default class Import extends FileCommand {
9
9
  static examples = [
10
10
  {
11
11
  description: 'Delete features in myAssembly and then import features.gff3:',
12
- command: '<%= config.bin %> <%= command.id %> -d -i features.gff3 -a myAssembly',
12
+ command: '<%= config.bin %> <%= command.id %> features.gff3 -d -a myAssembly',
13
13
  },
14
14
  ];
15
- static flags = {
16
- 'input-file': Flags.string({
17
- char: 'i',
15
+ static args = {
16
+ 'input-file': Args.string({
18
17
  description: 'Input gff file',
19
18
  required: true,
20
19
  }),
20
+ };
21
+ static flags = {
21
22
  assembly: Flags.string({
22
23
  char: 'a',
23
24
  description: 'Import into this assembly name or assembly ID',
@@ -29,16 +30,16 @@ export default class Import extends FileCommand {
29
30
  }),
30
31
  };
31
32
  async run() {
32
- const { flags } = await this.parse(Import);
33
- if (!fs.existsSync(flags['input-file'])) {
34
- this.error(`File "${flags['input-file']}" does not exist`);
33
+ const { args, flags } = await this.parse(Import);
34
+ if (!fs.existsSync(args['input-file'])) {
35
+ this.error(`File "${args['input-file']}" does not exist`);
35
36
  }
36
37
  const access = await this.getAccess();
37
38
  const assembly = await convertAssemblyNameToId(access.address, access.accessToken, [flags.assembly]);
38
39
  if (assembly.length === 0) {
39
40
  this.error(`Assembly "${flags.assembly}" does not exist. Perhaps you want to create this assembly first`);
40
41
  }
41
- const uploadId = await this.uploadFile(access.address, access.accessToken, flags['input-file'], 'text/x-gff3', false);
42
+ const uploadId = await this.uploadFile(access.address, access.accessToken, args['input-file'], 'text/x-gff3', false);
42
43
  const body = {
43
44
  typeName: 'AddFeaturesFromFileChange',
44
45
  assembly: assembly[0],
@@ -6,8 +6,10 @@ export default class Upload extends FileCommand {
6
6
  description: string;
7
7
  command: string;
8
8
  }[];
9
+ static args: {
10
+ 'input-file': import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
11
+ };
9
12
  static flags: {
10
- 'input-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
13
  type: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
14
  gzip: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
13
15
  decompressed: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
@@ -1,4 +1,4 @@
1
- import { Flags } from '@oclif/core';
1
+ import { Args, Flags } from '@oclif/core';
2
2
  import { FileCommand } from '../../fileCommand.js';
3
3
  import { filterJsonList, queryApollo } from '../../utils.js';
4
4
  export default class Upload extends FileCommand {
@@ -9,15 +9,16 @@ export default class Upload extends FileCommand {
9
9
  static examples = [
10
10
  {
11
11
  description: 'Upload local file, type auto-detected:',
12
- command: '<%= config.bin %> <%= command.id %> -i genome.fa > file.json',
12
+ command: '<%= config.bin %> <%= command.id %> genome.fa > file.json',
13
13
  },
14
14
  ];
15
- static flags = {
16
- 'input-file': Flags.string({
17
- char: 'i',
15
+ static args = {
16
+ 'input-file': Args.string({
18
17
  description: 'Local file to upload',
19
18
  required: true,
20
19
  }),
20
+ };
21
+ static flags = {
21
22
  type: Flags.string({
22
23
  char: 't',
23
24
  description: 'Set file type or autodetected it if not set.\n\
@@ -42,14 +43,15 @@ export default class Upload extends FileCommand {
42
43
  }),
43
44
  };
44
45
  async run() {
45
- const { flags } = await this.parse(Upload);
46
+ const { args, flags } = await this.parse(Upload);
46
47
  const access = await this.getAccess();
47
48
  let { type } = flags;
49
+ const { gzip, decompressed } = flags;
48
50
  if (type === undefined) {
49
- const hasGzipExt = flags['input-file'].endsWith('.gz');
50
- const infile = flags['input-file'].replace(/\.gz$/, '');
51
+ const hasGzipExt = args['input-file'].endsWith('.gz');
52
+ const infile = args['input-file'].replace(/\.gz$/, '');
51
53
  if (/\.fasta$|\.fas$|\.fa$|\.fna$/.test(infile) && hasGzipExt) {
52
- this.error(`Unable to auto-detect file type for "${flags['input-file']}" since it may be gzip or bgzip compressed. Please set the -t/--type option`);
54
+ this.error(`Unable to auto-detect file type for "${args['input-file']}" since it may be gzip or bgzip compressed. Please set the -t/--type option`);
53
55
  }
54
56
  else if (/\.fasta$|\.fas$|\.fa$|\.fna$/.test(infile)) {
55
57
  type = 'text/x-fasta';
@@ -64,20 +66,18 @@ export default class Upload extends FileCommand {
64
66
  type = 'application/x-gzi';
65
67
  }
66
68
  else {
67
- this.error(`Unable to auto-detect the type of file "${flags['input-file']}". Please set the --type/-t option.`);
69
+ this.error(`Unable to auto-detect the type of file "${args['input-file']}". Please set the --type/-t option.`);
68
70
  }
69
71
  }
70
- let isGzip = flags['input-file'].endsWith('.gz');
71
- // eslint-disable-next-line unicorn/consistent-destructuring
72
- if (flags.gzip) {
72
+ let isGzip = args['input-file'].endsWith('.gz');
73
+ if (gzip) {
73
74
  isGzip = true;
74
75
  }
75
- // eslint-disable-next-line unicorn/consistent-destructuring
76
- if (flags.decompressed) {
76
+ if (decompressed) {
77
77
  isGzip = false;
78
78
  }
79
79
  this.logToStderr(`Input is gzip'd: ${isGzip}`);
80
- const fileId = await this.uploadFile(access.address, access.accessToken, flags['input-file'], type, isGzip);
80
+ const fileId = await this.uploadFile(access.address, access.accessToken, args['input-file'], type, isGzip);
81
81
  const res = await queryApollo(access.address, access.accessToken, 'files');
82
82
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
83
83
  const json = JSON.parse(await res.text());
@@ -6,8 +6,10 @@ export default class AddRefNameAlias extends BaseCommand<typeof AddRefNameAlias>
6
6
  description: string;
7
7
  command: string;
8
8
  }[];
9
+ static args: {
10
+ 'input-file': import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
11
+ };
9
12
  static flags: {
10
- 'input-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
13
  assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
14
  };
13
15
  run(): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'node:fs';
2
2
  import { Agent, fetch } from 'undici';
3
- import { Flags } from '@oclif/core';
3
+ import { Args, Flags } from '@oclif/core';
4
4
  import { BaseCommand } from '../../baseCommand.js';
5
5
  import { createFetchErrorMessage, localhostToAddress, queryApollo, } from '../../utils.js';
6
6
  import { ConfigError } from '../../ApolloConf.js';
@@ -10,15 +10,16 @@ export default class AddRefNameAlias extends BaseCommand {
10
10
  static examples = [
11
11
  {
12
12
  description: 'Add reference name aliases:',
13
- command: '<%= config.bin %> <%= command.id %> -i alias.txt -a myAssembly',
13
+ command: '<%= config.bin %> <%= command.id %> alias.txt -a myAssembly',
14
14
  },
15
15
  ];
16
- static flags = {
17
- 'input-file': Flags.string({
18
- char: 'i',
16
+ static args = {
17
+ 'input-file': Args.string({
19
18
  description: 'Input refname alias file',
20
19
  required: true,
21
20
  }),
21
+ };
22
+ static flags = {
22
23
  assembly: Flags.string({
23
24
  char: 'a',
24
25
  description: 'Name for this assembly.',
@@ -26,12 +27,12 @@ export default class AddRefNameAlias extends BaseCommand {
26
27
  }),
27
28
  };
28
29
  async run() {
29
- const { flags } = await this.parse(AddRefNameAlias);
30
- if (!fs.existsSync(flags['input-file'])) {
31
- this.error(`File ${flags['input-file']} does not exist`);
30
+ const { args, flags } = await this.parse(AddRefNameAlias);
31
+ if (!fs.existsSync(args['input-file'])) {
32
+ this.error(`File ${args['input-file']} does not exist`);
32
33
  }
33
34
  const access = await this.getAccess();
34
- const filehandle = await fs.promises.open(flags['input-file']);
35
+ const filehandle = await fs.promises.open(args['input-file']);
35
36
  const fileContent = await filehandle.readFile({ encoding: 'utf8' });
36
37
  await filehandle.close();
37
38
  const lines = fileContent.split('\n');
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import { dirname } from 'node:path';
2
+ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { expect, test } from '@oclif/test';
5
5
  import { CONFIG_FILE, TEST_DATA_DIR, VERBOSE, copyFile, } from '../../test/fixtures.js';
@@ -15,7 +15,7 @@ describe.skip('apollo user get: Get users as YAML string', () => {
15
15
  const cmd = ['user:get'];
16
16
  test
17
17
  .stdout()
18
- .command(cmd, { root: dirname(dirname(__dirname)) })
18
+ .command(cmd, { root: path.dirname(path.dirname(__dirname)) })
19
19
  .it(cmd.join(' '), (output) => {
20
20
  const str = JSON.stringify(JSON.parse(output.stdout));
21
21
  expect(str).contain('username');
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'node:fs';
2
- import * as path from 'node:path';
2
+ import path from 'node:path';
3
3
  import { Transform, pipeline, } from 'node:stream';
4
4
  import { SingleBar } from 'cli-progress';
5
5
  import { Agent, fetch } from 'undici';
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
+ import type { SerializedAddAssemblyAndFeaturesFromFileChange, SerializedAddAssemblyFromExternalChange, SerializedAddAssemblyFromFileChange } from '@apollo-annotation/shared';
2
3
  import { Response } from 'undici';
3
4
  import { ApolloConf } from './ApolloConf.js';
4
5
  import { ApolloAssemblySnapshot } from '@apollo-annotation/mst';
@@ -34,32 +35,6 @@ export declare const generatePkceChallenge: () => {
34
35
  codeChallenge: string;
35
36
  };
36
37
  export declare const waitFor: <T>(eventName: string, emitter: EventEmitter) => Promise<T>;
37
- interface bodyFastaFile {
38
- assemblyName: string;
39
- typeName: string;
40
- fileIds: {
41
- fa: string;
42
- };
43
- assembly: string;
44
- }
45
- interface bodyIndexedFiles {
46
- assemblyName: string;
47
- typeName: string;
48
- fileIds: {
49
- fa: string;
50
- fai: string;
51
- gzi: string;
52
- };
53
- }
54
- interface bodyExternalFile {
55
- assemblyName: string;
56
- typeName: string;
57
- externalLocation: {
58
- fa: string;
59
- fai: string;
60
- };
61
- }
62
- export declare function submitAssembly(address: string, accessToken: string, body: bodyFastaFile | bodyExternalFile | bodyIndexedFiles, force: boolean): Promise<object>;
38
+ export declare function submitAssembly(address: string, accessToken: string, body: SerializedAddAssemblyFromFileChange | SerializedAddAssemblyFromExternalChange | SerializedAddAssemblyAndFeaturesFromFileChange, force: boolean): Promise<object>;
63
39
  export declare function readStdin(): Promise<string>;
64
40
  export declare function idReader(input: string[], removeDuplicates?: boolean): Promise<string[]>;
65
- export {};
package/dist/utils.js CHANGED
@@ -231,7 +231,12 @@ export const generatePkceChallenge = () => {
231
231
  export const waitFor = (eventName, emitter) => {
232
232
  const promise = new Promise((resolve, reject) => {
233
233
  const handleEvent = (eventData) => {
234
- eventData instanceof Error ? reject(eventData) : resolve(eventData);
234
+ if (eventData instanceof Error) {
235
+ reject(eventData);
236
+ }
237
+ else {
238
+ resolve(eventData);
239
+ }
235
240
  emitter.removeListener(eventName, handleEvent);
236
241
  };
237
242
  emitter.addListener(eventName, handleEvent);
@@ -241,12 +246,15 @@ export const waitFor = (eventName, emitter) => {
241
246
  export async function submitAssembly(address, accessToken, body, force) {
242
247
  let assemblies = await queryApollo(address, accessToken, 'assemblies');
243
248
  for (const x of (await assemblies.json())) {
244
- if (x['name'] === body.assemblyName) {
245
- if (force) {
246
- await deleteAssembly(address, accessToken, x['_id']);
247
- }
248
- else {
249
- throw new Error(`Error: Assembly "${body.assemblyName}" already exists`);
249
+ const addedAssemblies = 'changes' in body ? body.changes : [body];
250
+ for (const addedAssembly of addedAssemblies) {
251
+ if (x.name === addedAssembly.assemblyName) {
252
+ if (force) {
253
+ await deleteAssembly(address, accessToken, x._id);
254
+ }
255
+ else {
256
+ throw new Error(`Error: Assembly "${addedAssembly.assemblyName}" already exists`);
257
+ }
250
258
  }
251
259
  }
252
260
  }
@@ -267,11 +275,14 @@ export async function submitAssembly(address, accessToken, body, force) {
267
275
  }
268
276
  assemblies = await queryApollo(address, accessToken, 'assemblies');
269
277
  for (const x of (await assemblies.json())) {
270
- if (x['name'] === body.assemblyName) {
271
- return x;
278
+ const addedAssemblies = 'changes' in body ? body.changes : [body];
279
+ for (const addedAssembly of addedAssemblies) {
280
+ if (x.name === addedAssembly.assemblyName) {
281
+ return x;
282
+ }
272
283
  }
273
284
  }
274
- throw new Error(`Failed to retrieve assembly ${body.assemblyName}`);
285
+ throw new Error(`Failed to retrieve assembly from ${body.assembly}`);
275
286
  }
276
287
  export async function readStdin() {
277
288
  const chunks = [];