Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Dec 9, 2024
1 parent e1da8df commit ccf7cfb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
42 changes: 22 additions & 20 deletions src/commands/database/list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,36 @@ export async function listDatabasesWithAccountAPI(argv) {
pageSize,
path: database,
});

return pickOutputFields(response.results, argv);
}

export async function listDatabasesWithSecret(argv) {
const { url, secret, pageSize } = argv;
const { runQueryFromString } = container.resolve("faunaClientV10");
async function listAndFormatDatabasesWithAccountAPI(argv) {
const { json, color } = argv;
const output = await listDatabasesWithAccountAPI(argv);

if (json) {
container.resolve("logger").stdout(JSON.stringify(output));
} else {
container.resolve("logger").stdout(formatObjectForShell(output, { color }));
}
}

async function listDatabasesWithSecret(argv) {
const { url, secret, pageSize, json, color } = argv;
const { runQueryFromString, formatQueryResponse } =
container.resolve("faunaClientV10");

try {
return await runQueryFromString({
const result = await runQueryFromString({
url,
secret,
// This gives us back an array of database names. If we want to
// provide the after token at some point this query will need to be updated.
expression: `Database.all().paginate(${pageSize}).data { ${getOutputFields(argv)} }`,
});
container
.resolve("logger")
.stdout(formatQueryResponse(result, { json, color }));
} catch (e) {
if (e instanceof FaunaError) {
throwForError(e);
Expand All @@ -60,23 +74,11 @@ export async function listDatabasesWithSecret(argv) {
}

async function listDatabases(argv) {
let databases;
if (argv.secret) {
databases = listDatabasesWithSecret(argv);
return listDatabasesWithSecret(argv);
} else {
databases = listDatabasesWithAccountAPI(argv);
return listAndFormatDatabasesWithAccountAPI(argv);
}

if (argv.json) {
return JSON.stringify(databases);
} else {
return formatObjectForShell(databases, { color: argv.color });
}
}

async function doListDatabases(argv) {
const logger = container.resolve("logger");
logger.stdout(await listDatabases(argv));
}

function buildListCommand(yargs) {
Expand Down Expand Up @@ -113,5 +115,5 @@ export default {
command: "list",
description: "List databases.",
builder: buildListCommand,
handler: doListDatabases,
handler: listDatabases,
};
10 changes: 7 additions & 3 deletions src/commands/init.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ts-check
/* eslint-disable require-atomic-updates */
const __dirname = import.meta.dirname;
import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

import * as inquirer from "@inquirer/prompts";
import fileSelector from "inquirer-file-selector";
Expand Down Expand Up @@ -124,6 +127,7 @@ async function getDatabaseRunnable(argv /*, priorChoices*/) {

buildCredentials({
...argv,
user: "default",
database: runnable.choices.regionGroup,
});
runnable.fql = `Database.create({
Expand Down Expand Up @@ -289,11 +293,11 @@ async function getProjectRunnable(argv, priorChoices) {
// new db with demo data? create the demo data, then upload the schema
await Promise.all([
fsp.cp(
path.join(__dirname, "../lib/schema/demo-collection-schema.fsl"),
path.join(__dirname, "../src/lib/schema/demo-collection-schema.fsl"),
path.join(dirPath, dirName, "collections.fsl"),
),
fsp.cp(
path.join(__dirname, "../lib/schema/demo-function-schema.fsl"),
path.join(__dirname, "../src/lib/schema/demo-function-schema.fsl"),
path.join(dirPath, dirName, "functions.fsl"),
),
]);
Expand Down

0 comments on commit ccf7cfb

Please sign in to comment.