Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to stream file uploads instead of use multipart form data #409

Merged
merged 14 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ jobs:
- name: Run CLI tests
run: python3 ./test/test.py TestCLI
working-directory: packages/apollo-cli
- name: Run docker tests
working-directory: packages/apollo-cli
run: python3 ./test/test_docker.py
# - name: Run docker tests
# working-directory: packages/apollo-cli
# run: python3 ./test/test_docker.py
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions packages/apollo-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@oclif/core": "^3.18.2",
"@oclif/plugin-help": "^6.0.8",
"bson": "^6.3.0",
"cli-progress": "^3.12.0",
"conf": "^12.0.0",
"joi": "^17.7.0",
"open": "^10.1.0",
Expand All @@ -53,6 +54,7 @@
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@oclif/test": "^3.1.3",
"@types/chai": "^4",
"@types/cli-progress": "^3",
"@types/inquirer": "^9.0.7",
"@types/mocha": "^10",
"@types/node": "^18.14.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/apollo-cli/src/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
}

protected async catch(err: Error & { exitCode?: number }): Promise<unknown> {
// add any custom logic to handle errors from the command
// or simply return the parent class error handling
if (err.cause instanceof Error) {
console.error(err.cause)

Check warning on line 61 in packages/apollo-cli/src/baseCommand.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/baseCommand.ts#L61

Added line #L61 was not covered by tests
}
return super.catch(err)
}

Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/assembly/add-fasta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default class Get extends BaseCommand<typeof Get> {
)
throw new Error(errorMessage)
}
this.exit(0)
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/assembly/add-gff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,5 @@ export default class AddGff extends BaseCommand<typeof AddGff> {
)
throw new Error(errorMessage)
}
this.exit(0)
}
}
15 changes: 3 additions & 12 deletions packages/apollo-cli/src/commands/assembly/sequence.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { Flags } from '@oclif/core'
import { Response, fetch } from 'undici'
import { Agent, RequestInit, Response, fetch } from 'undici'

import { BaseCommand } from '../../baseCommand.js'
import {
Expand Down Expand Up @@ -29,19 +29,11 @@
url.search = searchParams.toString()
const uri = url.toString()

const controller = new AbortController()
setTimeout(
() => {
controller.abort()
},
24 * 60 * 60 * 1000,
)

const auth = {
const auth: RequestInit = {

Check warning on line 32 in packages/apollo-cli/src/commands/assembly/sequence.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/assembly/sequence.ts#L32

Added line #L32 was not covered by tests
headers: {
authorization: `Bearer ${accessToken}`,
},
signal: controller.signal,
dispatcher: new Agent({ headersTimeout: 60 * 60 * 1000 }),
}
const response = await fetch(uri, auth)
if (!response.ok) {
Expand Down Expand Up @@ -147,7 +139,6 @@
this.log(header)
this.log(splitStringIntoChunks(seq, 80).join('\n'))
}
this.exit(0)
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/add-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default class Get extends BaseCommand<typeof Get> {
)
throw new Error(errorMessage)
}
this.exit(0)
}

private async addChild(
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export default class Copy extends BaseCommand<typeof Copy> {
)
throw new Error(errorMessage)
}
this.exit(0)
}

private async copyFeature(
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,5 @@ export default class Delete extends BaseCommand<typeof Delete> {
}
}
}
this.exit(0)
}
}
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/edit-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,5 @@ export default class EditAttibute extends BaseCommand<typeof EditAttibute> {
)
throw new Error(errorMessage)
}
this.exit(0)
}
}
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/edit-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,5 @@ export default class Get extends BaseCommand<typeof Get> {
)
throw new Error(errorMessage)
}
this.exit(0)
}
}
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@ export default class Get extends BaseCommand<typeof Get> {
throw new Error(errorMessage)
}
}
this.exit(0)
}
}
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/get-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default class Get extends BaseCommand<typeof Get> {
results.push(res)
}
this.log(JSON.stringify(results, null, 2))
this.exit(0)
}

private async getFeatureId(
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/commands/feature/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default class Get extends BaseCommand<typeof Get> {
}
}
this.log(JSON.stringify(results, null, 2))
this.exit(0)
}

private async getFeatures(
Expand Down
78 changes: 22 additions & 56 deletions packages/apollo-cli/src/commands/feature/import.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'node:fs'

import { Flags } from '@oclif/core'
import { Response, fetch } from 'undici'
import { Agent, RequestInit, fetch } from 'undici'

import { BaseCommand } from '../../baseCommand.js'
import {
Expand Down Expand Up @@ -69,64 +69,30 @@
'text/x-gff3',
)

const res: Response = await importFeatures(
access.address,
access.accessToken,
assembly[0],
uploadId,
flags['delete-existing'],
)
if (!res.ok) {
const body = {

Check warning on line 72 in packages/apollo-cli/src/commands/feature/import.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/feature/import.ts#L72

Added line #L72 was not covered by tests
typeName: 'AddFeaturesFromFileChange',
assembly: assembly[0],
fileId: uploadId,
deleteExistingFeatures: flags['delete-existing'],
}
const auth: RequestInit = {

Check warning on line 78 in packages/apollo-cli/src/commands/feature/import.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/feature/import.ts#L78

Added line #L78 was not covered by tests
method: 'POST',
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${access.accessToken}`,
'Content-Type': 'application/json',
},
dispatcher: new Agent({ headersTimeout: 60 * 60 * 1000 }),
}

const url = new URL(localhostToAddress(`${access.address}/changes`))
const response = await fetch(url, auth)

Check warning on line 89 in packages/apollo-cli/src/commands/feature/import.ts

View check run for this annotation

Codecov / codecov/patch

packages/apollo-cli/src/commands/feature/import.ts#L88-L89

Added lines #L88 - L89 were not covered by tests
if (!response.ok) {
const errorMessage = await createFetchErrorMessage(
res,
'Import features failed',
response,
'importFeatures failed',
)
throw new Error(errorMessage)
}
this.exit(0)
}
}

async function importFeatures(
address: string,
accessToken: string,
assembly: string,
fileId: string,
deleteExistingFeatures: boolean,
): Promise<Response> {
const body = {
typeName: 'AddFeaturesFromFileChange',
assembly,
fileId,
deleteExistingFeatures,
}

const controller = new AbortController()
setTimeout(
() => {
controller.abort()
},
24 * 60 * 60 * 1000,
)

const auth = {
method: 'POST',
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
signal: controller.signal,
}

const url = new URL(localhostToAddress(`${address}/changes`))
const response = await fetch(url, auth)
if (!response.ok) {
const errorMessage = await createFetchErrorMessage(
response,
'importFeatures failed',
)
throw new Error(errorMessage)
}
return response
}
Loading