Skip to content

Commit 4e34ec0

Browse files
committed
containerize fauna-client
1 parent 416152c commit 4e34ec0

18 files changed

Lines changed: 73 additions & 69 deletions

src/commands/database/create.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { container } from "../../cli.mjs";
55
import { validateDatabaseOrSecret } from "../../lib/command-helpers.mjs";
66
import { CommandError } from "../../lib/errors.mjs";
77
import { faunaToCommandError } from "../../lib/fauna.mjs";
8-
import { getSecret, retryInvalidCredsOnce } from "../../lib/fauna-client.mjs";
98
import { colorize, Format } from "../../lib/formatting/colorize.mjs";
109

1110
async function runCreateQuery(secret, argv) {
@@ -25,6 +24,8 @@ async function runCreateQuery(secret, argv) {
2524
}
2625

2726
async function createDatabase(argv) {
27+
const { getSecret, retryInvalidCredsOnce } = container.resolve("faunaClient");
28+
2829
const secret = await getSecret();
2930
const logger = container.resolve("logger");
3031

src/commands/database/delete.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { container } from "../../cli.mjs";
66
import { validateDatabaseOrSecret } from "../../lib/command-helpers.mjs";
77
import { CommandError } from "../../lib/errors.mjs";
88
import { faunaToCommandError } from "../../lib/fauna.mjs";
9-
import { getSecret, retryInvalidCredsOnce } from "../../lib/fauna-client.mjs";
109

1110
async function runDeleteQuery(secret, argv) {
1211
const { fql } = container.resolve("fauna");
@@ -19,6 +18,8 @@ async function runDeleteQuery(secret, argv) {
1918
}
2019

2120
async function deleteDatabase(argv) {
21+
const { getSecret, retryInvalidCredsOnce } = container.resolve("faunaClient");
22+
2223
const secret = await getSecret();
2324
const logger = container.resolve("logger");
2425

src/commands/query.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import {
1111
isUnknownError,
1212
ValidationError,
1313
} from "../lib/errors.mjs";
14-
import {
15-
formatError,
16-
formatQueryResponse,
17-
getSecret,
18-
} from "../lib/fauna-client.mjs";
1914
import { isTTY } from "../lib/misc.mjs";
2015

2116
function validate(argv) {
@@ -70,7 +65,14 @@ const resolveInput = (argv) => {
7065
};
7166

7267
async function queryCommand(argv) {
73-
const formatQueryInfo = container.resolve("formatQueryInfo");
68+
const {
69+
formatError,
70+
formatQueryInfo,
71+
formatQueryResponse,
72+
getSecret,
73+
runQueryFromString,
74+
} = container.resolve("faunaClient");
75+
7476
const logger = container.resolve("logger");
7577

7678
// Run validation here instead of via check for more control over output
@@ -99,7 +101,7 @@ async function queryCommand(argv) {
99101
// Using --json takes precedence over --format
100102
const outputFormat = resolveFormat(argv);
101103

102-
const results = await container.resolve("runQueryFromString")(expression, {
104+
const results = await runQueryFromString(expression, {
103105
apiVersion,
104106
secret,
105107
url,

src/commands/schema/abandon.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import { container } from "../../cli.mjs";
44
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
55
import { CommandError } from "../../lib/errors.mjs";
6-
import { getSecret } from "../../lib/fauna-client.mjs";
76

87
async function doAbandon(argv) {
9-
const makeFaunaRequest = container.resolve("makeFaunaRequest");
10-
const logger = container.resolve("logger");
118
const confirm = container.resolve("confirm");
9+
const { getSecret } = container.resolve("faunaClient");
10+
const logger = container.resolve("logger");
11+
const makeFaunaRequest = container.resolve("makeFaunaRequest");
12+
1213
const secret = await getSecret();
1314

1415
if (!argv.input) {

src/commands/schema/commit.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import { container } from "../../cli.mjs";
44
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
55
import { CommandError } from "../../lib/errors.mjs";
6-
import { getSecret } from "../../lib/fauna-client.mjs";
76

87
async function doCommit(argv) {
9-
const makeFaunaRequest = container.resolve("makeFaunaRequest");
10-
const logger = container.resolve("logger");
118
const confirm = container.resolve("confirm");
9+
const { getSecret } = container.resolve("faunaClient");
10+
const logger = container.resolve("logger");
11+
const makeFaunaRequest = container.resolve("makeFaunaRequest");
12+
1213
const secret = await getSecret();
1314

1415
if (!argv.input) {

src/commands/schema/diff.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import chalk from "chalk";
55
import { container } from "../../cli.mjs";
66
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
77
import { ValidationError } from "../../lib/errors.mjs";
8-
import { getSecret } from "../../lib/fauna-client.mjs";
98
import { reformatFSL } from "../../lib/schema.mjs";
109
import { localSchemaOptions } from "./schema.mjs";
1110

@@ -57,11 +56,12 @@ function buildValidateParams(argv, version) {
5756
}
5857

5958
async function doDiff(argv) {
60-
const [source, target] = parseTarget(argv);
61-
59+
const { getSecret } = container.resolve("faunaClient");
6260
const gatherFSL = container.resolve("gatherFSL");
6361
const logger = container.resolve("logger");
6462
const makeFaunaRequest = container.resolve("makeFaunaRequest");
63+
64+
const [source, target] = parseTarget(argv);
6565
const secret = await getSecret();
6666
const files = reformatFSL(await gatherFSL(argv.dir));
6767

src/commands/schema/pull.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { container } from "../../cli.mjs";
44
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
5-
import { getSecret } from "../../lib/fauna-client.mjs";
65
import { localSchemaOptions } from "./schema.mjs";
76

87
async function determineFileState(argv, filenames) {
@@ -50,9 +49,11 @@ function logDiff({ argv, adds, overwrites, deletes, source }) {
5049
}
5150

5251
async function doPull(argv) {
53-
const logger = container.resolve("logger");
5452
const confirm = container.resolve("confirm");
53+
const { getSecret } = container.resolve("faunaClient");
54+
const logger = container.resolve("logger");
5555
const makeFaunaRequest = container.resolve("makeFaunaRequest");
56+
5657
const secret = await getSecret();
5758

5859
// Get the staged schema status

src/commands/schema/push.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import path from "path";
55
import { container } from "../../cli.mjs";
66
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
77
import { ValidationError } from "../../lib/errors.mjs";
8-
import { getSecret } from "../../lib/fauna-client.mjs";
98
import { reformatFSL } from "../../lib/schema.mjs";
109
import { localSchemaOptions } from "./schema.mjs";
1110

@@ -14,9 +13,10 @@ import { localSchemaOptions } from "./schema.mjs";
1413
* @param {import("yargs").Argv & {dir: string, active: boolean, input: boolean}} argv
1514
*/
1615
export async function pushSchema(argv) {
16+
const { getSecret } = container.resolve("faunaClient");
17+
const gatherFSL = container.resolve("gatherFSL");
1718
const logger = container.resolve("logger");
1819
const makeFaunaRequest = container.resolve("makeFaunaRequest");
19-
const gatherFSL = container.resolve("gatherFSL");
2020

2121
const isStagedPush = !argv.active;
2222
const secret = await getSecret();

src/commands/schema/status.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import path from "path";
66
import { container } from "../../cli.mjs";
77
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
88
import { CommandError } from "../../lib/errors.mjs";
9-
import { getSecret } from "../../lib/fauna-client.mjs";
109
import { reformatFSL } from "../../lib/schema.mjs";
1110
import { localSchemaOptions } from "./schema.mjs";
1211

1312
async function doStatus(argv) {
13+
const { getSecret } = container.resolve("faunaClient");
14+
const gatherFSL = container.resolve("gatherFSL");
1415
const logger = container.resolve("logger");
1516
const makeFaunaRequest = container.resolve("makeFaunaRequest");
1617

1718
const secret = await getSecret();
1819
const absoluteDirPath = path.resolve(argv.dir);
19-
const gatherFSL = container.resolve("gatherFSL");
2020
const fslFiles = await gatherFSL(argv.dir);
2121
const hasLocalSchema = fslFiles.length > 0;
2222
const fsl = reformatFSL(fslFiles);

src/commands/shell.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ import {
1212
validateDatabaseOrSecret,
1313
yargsWithCommonConfigurableQueryOptions,
1414
} from "../lib/command-helpers.mjs";
15-
import { formatQueryResponse, getSecret } from "../lib/fauna-client.mjs";
1615
import { clearHistoryStorage, initHistoryStorage } from "../lib/file-util.mjs";
1716

1817
async function shellCommand(argv) {
18+
const { getSecret, isQueryable } = container.resolve("faunaClient");
1919
const { query: v4Query } = container.resolve("faunadb");
2020

2121
validateDatabaseOrSecret(argv);
2222

2323
// Fast fail if the database is not queryable
24-
const isQueryable = container.resolve("isQueryable");
2524
await isQueryable({ ...argv, secret: await getSecret() });
2625

2726
const logger = container.resolve("logger");
@@ -146,9 +145,13 @@ const getArgvOrCtx = (key, argv, ctx) => {
146145

147146
// caches the logger, client, and performQuery for subsequent shell calls
148147
async function buildCustomEval(argv) {
149-
const formatError = container.resolve("formatError");
150-
const formatQueryInfo = container.resolve("formatQueryInfo");
151-
const runQueryFromString = container.resolve("runQueryFromString");
148+
const {
149+
formatError,
150+
getSecret,
151+
formatQueryInfo,
152+
formatQueryResponse,
153+
runQueryFromString,
154+
} = container.resolve("faunaClient");
152155

153156
return async (cmd, ctx, _filename, cb) => {
154157
try {

0 commit comments

Comments
 (0)