@apollo-annotation/cli 0.1.20 → 0.1.21

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 * 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,14 @@ 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;
48
49
  if (type === undefined) {
49
- const hasGzipExt = flags['input-file'].endsWith('.gz');
50
- const infile = flags['input-file'].replace(/\.gz$/, '');
50
+ const hasGzipExt = args['input-file'].endsWith('.gz');
51
+ const infile = args['input-file'].replace(/\.gz$/, '');
51
52
  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`);
53
+ 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
54
  }
54
55
  else if (/\.fasta$|\.fas$|\.fa$|\.fna$/.test(infile)) {
55
56
  type = 'text/x-fasta';
@@ -64,10 +65,10 @@ export default class Upload extends FileCommand {
64
65
  type = 'application/x-gzi';
65
66
  }
66
67
  else {
67
- this.error(`Unable to auto-detect the type of file "${flags['input-file']}". Please set the --type/-t option.`);
68
+ this.error(`Unable to auto-detect the type of file "${args['input-file']}". Please set the --type/-t option.`);
68
69
  }
69
70
  }
70
- let isGzip = flags['input-file'].endsWith('.gz');
71
+ let isGzip = args['input-file'].endsWith('.gz');
71
72
  // eslint-disable-next-line unicorn/consistent-destructuring
72
73
  if (flags.gzip) {
73
74
  isGzip = true;
@@ -77,7 +78,7 @@ export default class Upload extends FileCommand {
77
78
  isGzip = false;
78
79
  }
79
80
  this.logToStderr(`Input is gzip'd: ${isGzip}`);
80
- const fileId = await this.uploadFile(access.address, access.accessToken, flags['input-file'], type, isGzip);
81
+ const fileId = await this.uploadFile(access.address, access.accessToken, args['input-file'], type, isGzip);
81
82
  const res = await queryApollo(access.address, access.accessToken, 'files');
82
83
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
83
84
  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');
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
@@ -241,12 +241,15 @@ export const waitFor = (eventName, emitter) => {
241
241
  export async function submitAssembly(address, accessToken, body, force) {
242
242
  let assemblies = await queryApollo(address, accessToken, 'assemblies');
243
243
  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`);
244
+ const addedAssemblies = 'changes' in body ? body.changes : [body];
245
+ for (const addedAssembly of addedAssemblies) {
246
+ if (x.name === addedAssembly.assemblyName) {
247
+ if (force) {
248
+ await deleteAssembly(address, accessToken, x._id);
249
+ }
250
+ else {
251
+ throw new Error(`Error: Assembly "${addedAssembly.assemblyName}" already exists`);
252
+ }
250
253
  }
251
254
  }
252
255
  }
@@ -267,11 +270,14 @@ export async function submitAssembly(address, accessToken, body, force) {
267
270
  }
268
271
  assemblies = await queryApollo(address, accessToken, 'assemblies');
269
272
  for (const x of (await assemblies.json())) {
270
- if (x['name'] === body.assemblyName) {
271
- return x;
273
+ const addedAssemblies = 'changes' in body ? body.changes : [body];
274
+ for (const addedAssembly of addedAssemblies) {
275
+ if (x.name === addedAssembly.assemblyName) {
276
+ return x;
277
+ }
272
278
  }
273
279
  }
274
- throw new Error(`Failed to retrieve assembly ${body.assemblyName}`);
280
+ throw new Error(`Failed to retrieve assembly from ${body.assembly}`);
275
281
  }
276
282
  export async function readStdin() {
277
283
  const chunks = [];