Skip to content

Commit 8c1999d

Browse files
committed
Use is_terminal rather than waiting on states.
1 parent 6c009f8 commit 8c1999d

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

src/commands/export/create.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-check
22

33
import { container } from "../../config/container.mjs";
4-
import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs";
54
import { ValidationError } from "../../lib/errors.mjs";
65
import { colorize, Format } from "../../lib/formatting/colorize.mjs";
76
import { DATABASE_PATH_OPTIONS } from "../../lib/options.mjs";
@@ -40,7 +39,7 @@ async function createS3Export(argv) {
4039
format,
4140
});
4241

43-
if (wait && !EXPORT_TERMINAL_STATES.includes(createdExport.state)) {
42+
if (wait && !createdExport.is_terminal) {
4443
createdExport = await waitUntilExportIsReady({
4544
id: createdExport.id,
4645
opts: {

src/commands/export/get.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { container } from "../../config/container.mjs";
2-
import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs";
32
import { colorize, Format } from "../../lib/formatting/colorize.mjs";
43
import { WAIT_OPTIONS, waitUntilExportIsReady } from "./wait.mjs";
54

@@ -9,7 +8,7 @@ async function getExport(argv) {
98
const { exportId, json, color, wait, maxWait, quiet } = argv;
109

1110
let response = await getExport({ exportId });
12-
if (wait && !EXPORT_TERMINAL_STATES.includes(response.state)) {
11+
if (wait && !response.is_terminal) {
1312
response = await waitUntilExportIsReady({
1413
id: exportId,
1514
opts: {

src/commands/export/wait.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-check
22

33
import { container } from "../../config/container.mjs";
4-
import { EXPORT_TERMINAL_STATES } from "../../lib/account-api.mjs";
54
import { CommandError } from "../../lib/errors.mjs";
65
import { colorize, Format } from "../../lib/formatting/colorize.mjs";
76
import { isTTY } from "../../lib/utils.mjs";
@@ -169,7 +168,7 @@ export async function waitAndCheckExportState({
169168
const data = await getExport({ exportId: id });
170169

171170
// If the export is ready, return the data
172-
if (EXPORT_TERMINAL_STATES.includes(data.state)) {
171+
if (data.is_terminal) {
173172
statusHandler(
174173
colorize(`${id} has a terminal state of ${data.state}.`, {
175174
format: Format.LOG,

src/lib/account-api.mjs

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export const ExportState = {
2222
};
2323

2424
export const EXPORT_STATES = Object.values(ExportState);
25-
export const EXPORT_TERMINAL_STATES = [
26-
ExportState.Complete,
27-
ExportState.Failed,
28-
];
2925

3026
let accountUrl = process.env.FAUNA_ACCOUNT_URL ?? "https://account.fauna.com";
3127

test/commands/export/wait.mjs

+7-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("export wait helpers", () => {
2424
describe("waitUntilExportIsReady", () => {
2525
it("should return export data when export completes successfully", async () => {
2626
const exportId = "test-export-id";
27-
const exportData = { id: exportId, state: ExportState.Complete };
27+
const exportData = { id: exportId, is_terminal: true, state: ExportState.Complete };
2828
const statusHandler = sinon.stub();
2929

3030
getExport.resolves(exportData);
@@ -40,17 +40,14 @@ describe("export wait helpers", () => {
4040
expect(statusHandler).to.have.been.calledWith(
4141
`test-export-id is Pending and not yet started.`,
4242
);
43-
expect(statusHandler).to.have.been.calledWith(
44-
"test-export-id is Pending and not yet started.",
45-
);
4643
expect(statusHandler).to.have.been.calledWith(
4744
"test-export-id has a terminal state of Complete.",
4845
);
4946
});
5047

5148
it("should not print status when quiet is true", async () => {
5249
const exportId = "test-export-id";
53-
const exportData = { id: exportId, state: ExportState.Complete };
50+
const exportData = { id: exportId, is_terminal: true };
5451
const statusHandler = sinon.stub();
5552

5653
getExport.resolves(exportData);
@@ -92,9 +89,9 @@ describe("export wait helpers", () => {
9289

9390
getExport
9491
.onFirstCall()
95-
.resolves({ id: exportId, state: ExportState.Pending })
92+
.resolves({ id: exportId, is_terminal: false, state: ExportState.Pending })
9693
.onSecondCall()
97-
.resolves({ id: exportId, state: ExportState.Complete });
94+
.resolves({ id: exportId, is_terminal: true, state: ExportState.Complete });
9895

9996
const result = await waitAndCheckExportState({
10097
id: exportId,
@@ -134,11 +131,11 @@ describe("export wait helpers", () => {
134131

135132
getExport
136133
.onFirstCall()
137-
.resolves({ id: exportId, state: ExportState.Pending })
134+
.resolves({ id: exportId, is_terminal: false })
138135
.onSecondCall()
139-
.resolves({ id: exportId, state: ExportState.Pending })
136+
.resolves({ id: exportId, is_terminal: false })
140137
.onThirdCall()
141-
.resolves({ id: exportId, state: ExportState.Complete });
138+
.resolves({ id: exportId, is_terminal: true });
142139

143140
await waitAndCheckExportState({
144141
id: exportId,

0 commit comments

Comments
 (0)