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

Updates for v10 release #224

Merged
merged 8 commits into from
Aug 16, 2023
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
357 changes: 181 additions & 176 deletions README.md

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ This is an attempt to describe what are the project goals, and give an architect

## Project Goals

1. Help people get started with FaunaDB.
1. Help people get started with Fauna.

The ideal path would be:

- Login to Fauna Cloud: `$ fauna cloud-login`
- Login to Fauna: `$ fauna cloud-login`
- Create a Database: `$ fauna create-database my_app`
- Start an interactive shell: `$ fauna shell my_app`
- Send queries to FaunaDB from the interactive Shell: `my_app> CreateCollection({ name: "posts" })`
- Send queries to Fauna from the interactive Shell: `my_app> CreateCollection({ name: "posts" })`

For that we offer installs via npm: https://www.npmjs.com/package/fauna-shell and Mac users have the option to also install via homebrew, so we support this repo: https://github.com/fauna/homebrew-fauna-shell-tap

The project uses the [faunadb-js](https://github.com/fauna/faunadb-js) client. The idea is to bundle it with the shell so the user doesn't need to install any extra software or libraries to get started with FaunaDB.
The project uses the [faunadb-js](https://github.com/fauna/faunadb-js) client. The idea is to bundle it with the shell so the user doesn't need to install any extra software or libraries to get started with Fauna.

2. Help people clear initial hurdles.

A required step before start experimenting with FaunaDB is to have a database with its respective key. The shell offers a set of commands that help the user with tasks like creating/deleting databases and keys.
A required step before start experimenting with Fauna is to have a database with its respective key. The shell offers a set of commands that help the user with tasks like creating/deleting databases and keys.

3. Help people connect to FaunaDB (cloud or self hosted)
3. Help people connect to Fauna (cloud or self hosted)

The user should have an easy way to handle the configuration to the various endpoints they might want to connect to.

For that the shell offers a file called `.fauna-shell`, stored at their home directory, where `fauna` will store the connection parameters for the endpoints.

Adding an endpoint should be as easy as typing: `$ fauna add-endpoint "https://example.org:443"`.

Connecting to the FaunaDB Cloud should be as easy as typing: `$ fauna cloud-login`. The user will be prompted for their email & passwords, and their key will be saved in the `.fauna-shell` file.
Connecting to Fauna should be as easy as typing: `$ fauna cloud-login`. The user will be prompted for their email & passwords, and their key will be saved in the `.fauna-shell` file.

3. Provide an easy to use shell (REPL) for interacting with FaunaDB.
3. Provide an easy to use shell (REPL) for interacting with Fauna.

When the user starts the shell by typing `$ fauna shell my_app`, they get an interactive prompt where they can type FaunaDB queries right away.
When the user starts the shell by typing `$ fauna shell my_app`, they get an interactive prompt where they can type Fauna queries right away.

Usually queries are wrapped around the `Query()` constructor. This is not required in the shell.

Expand All @@ -43,7 +43,7 @@ The less key strokes the user has to type, the better.

4. Make the experience as smooth as possible.

Commands should provide clear error messages. A confusing error message could put a user away from FaunaDB. We want to prevent that as much as possible.
Commands should provide clear error messages. A confusing error message could put a user away from Fauna. We want to prevent that as much as possible.

Commands should also provide guidance. For example `create-database` explains to the user how to go from there, like how to start a shell for that particular database.

Expand All @@ -53,15 +53,15 @@ The project uses the [oclif](https://oclif.io/) framework for creating CLI tools

All commands extend our custom [FaunaCommand](https://github.com/fauna/fauna-shell/blob/main/src/lib/fauna_command.js).

If your command needs to connect to FaunaDB and accept parameters `like`, `domain`, `scheme`, `port`, `timeout` or `secret`, then extending FaunaCommand will handle that for you. The only requisite is that you define your command [flags](https://oclif.io/docs/flags.html) like this:
If your command needs to connect to Fauna and accept parameters `like`, `domain`, `scheme`, `port`, `timeout` or `secret`, then extending FaunaCommand will handle that for you. The only requisite is that you define your command [flags](https://oclif.io/docs/flags.html) like this:

```javascript
MyNewCommandCommand.flags = {
...FaunaCommand.flags,
};
```

Besides that, `FaunaCommand` offers a set of helper methods that let you work with FaunaDB queries without worrying about having to create a connection:
Besides that, `FaunaCommand` offers a set of helper methods that let you work with Fauna queries without worrying about having to create a connection:

```javascript
class MyNewCommandCommand extends FaunaCommand {
Expand All @@ -76,7 +76,7 @@ See other commands for complete examples on how to do that, and check the FaunaC

Helper functions are defined in the [misc](https://github.com/fauna/fauna-shell/blob/main/src/lib/misc.js) module.

These functions let you do things from reading/writing the shell's config file, to building configuration options for creating a connection to FaunaDB.
These functions let you do things from reading/writing the shell's config file, to building configuration options for creating a connection to Fauna.

## Running Tests

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fauna-shell",
"description": "faunadb shell",
"version": "0.15.0",
"version": "1.0.0",
"author": "Fauna",
"bin": {
"fauna": "./bin/run"
Expand Down
8 changes: 4 additions & 4 deletions src/commands/add-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AddEndpointCommand extends FaunaCommand {
}

AddEndpointCommand.description = `
Adds a connection endpoint for FaunaDB
Adds a connection endpoint for Fauna.
`;

AddEndpointCommand.examples = [
Expand All @@ -51,19 +51,19 @@ AddEndpointCommand.examples = [
// clear the default FaunaCommand flags that accept --host, --port, etc.
AddEndpointCommand.flags = {
alias: Flags.string({
description: "FaunaDB server endpoint alias",
description: "Fauna server endpoint alias",
required: false,
}),
key: Flags.string({
description: "FaunaDB server endpoint key",
description: "Fauna server endpoint key",
required: false,
}),
};

AddEndpointCommand.args = {
endpoint: Args.string({
required: true,
description: "FaunaDB server endpoint",
description: "Fauna server endpoint",
}),
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/cloud-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class CloudLoginCommand extends FaunaCommand {
}
}

CloudLoginCommand.description = "Adds the FaunaDB Cloud endpoint";
CloudLoginCommand.description = "Adds a Fauna endpoint.";
CloudLoginCommand.examples = ["$ fauna cloud-login"];
CloudLoginCommand.flags = [];

Expand Down
2 changes: 1 addition & 1 deletion src/commands/default-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DefaultEndpointCommand.args = {
// eslint-disable-next-line camelcase
endpoint_alias: Args.string({
required: true,
description: "FaunaDB server endpoint alias",
description: "Fauna server endpoint alias",
}),
};

Expand Down
4 changes: 2 additions & 2 deletions src/commands/delete-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DeleteEndpoint extends FaunaCommand {
}

DeleteEndpoint.description = `
Deletes a connection endpoint for FaunaDB
Deletes a connection endpoint.
`;

DeleteEndpoint.examples = ["$ fauna delete-endpoint endpoint_alias"];
Expand All @@ -24,7 +24,7 @@ DeleteEndpoint.args = {
// eslint-disable-next-line camelcase
endpoint_alias: Args.string({
required: true,
description: "FaunaDB server endpoint alias",
description: "Fauna server endpoint alias",
}),
};

Expand Down
20 changes: 7 additions & 13 deletions src/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,8 @@ class EvalCommand extends FaunaCommand {
queryFromFile = await readFile(queriesFile);
}

// In v10, we check if its a TTY for shell/json format. In v4, default to json (to avoid breaking compatability).
const format =
this.flags.format ??
(this.flags.version === "10"
? process.stdout.isTTY
? "shell"
: "json"
: "json");
this.flags.format ?? (process.stdout.isTTY ? "shell" : "json");

const result = await this.performQuery(
client,
Expand Down Expand Up @@ -227,12 +221,12 @@ class EvalCommand extends FaunaCommand {
}

EvalCommand.examples = [
'$ fauna eval "Paginate(Collections())"',
'$ fauna eval nestedDbName "Paginate(Collections())"',
'$ fauna eval "Collection.all()"',
'$ fauna eval nestedDbName "Collection.all()"',
"$ fauna eval --file=/path/to/queries.fql",
'$ echo "Add(1,1)" | fauna eval --stdin',
'$ fauna eval "Add(2,3)" --output=/tmp/result"',
'$ fauna eval "Add(2,3)" --format=json --output=/tmp/result"',
'$ echo "1 + 1" | fauna eval',
'$ fauna eval "2 + 3" --output=/tmp/result"',
'$ fauna eval "2 + 3" --format=json --output=/tmp/result"',
];

EvalCommand.flags = {
Expand All @@ -255,7 +249,7 @@ EvalCommand.flags = {
}),
version: Flags.string({
description: "FQL Version",
default: "4",
default: "10",
options: ["4", "10"],
}),

Expand Down
2 changes: 1 addition & 1 deletion src/commands/list-endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ListEndpointsCommand extends FaunaCommand {
}

ListEndpointsCommand.description = `
Lists FaunaDB connection endpoints
Lists connection endpoints.
`;

ListEndpointsCommand.examples = ["$ fauna list-endpoints"];
Expand Down
4 changes: 2 additions & 2 deletions src/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class ShellCommand extends EvalCommand {
}

ShellCommand.description = `
Starts a FaunaDB shell
Starts an interactive shell.
`;

ShellCommand.examples = ["$ fauna shell dbname"];
Expand All @@ -164,7 +164,7 @@ ShellCommand.flags = {
...FaunaCommand.flags,
version: Flags.string({
description: "FQL Version",
default: "4",
default: "10",
options: ["4", "10"],
}),

Expand Down
6 changes: 3 additions & 3 deletions src/lib/fauna-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class FaunaCommand extends Command {
FaunaCommand.flags = {
...Command.flags,
domain: Flags.string({
description: "FaunaDB server domain",
description: "Fauna server domain",
}),
scheme: Flags.string({
description: "Connection scheme",
Expand All @@ -202,10 +202,10 @@ FaunaCommand.flags = {
description: "Connection timeout in milliseconds",
}),
secret: Flags.string({
description: "FaunaDB secret key",
description: "Fauna secret key",
}),
endpoint: Flags.string({
description: "FaunaDB server endpoint",
description: "Fauna server endpoint",
}),
graphqlHost: Flags.string({
description: "The Fauna GraphQL API host",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ERROR_NO_DEFAULT_ENDPOINT =
const ERROR_WRONG_CLOUD_ENDPOINT =
"You already have an endpoint 'cloud' defined and it doesn't point to 'db.fauna.com'.\nPlease fix your '~/.fauna-shell' file.";
const ERROR_SPECIFY_SECRET_KEY =
"You must specify a secret key to connect to FaunaDB";
"You must specify a secret key to connect to Fauna";

/**
* Takes a parsed endpointURL, an endpoint alias, and the endpoint secret,
Expand Down Expand Up @@ -137,7 +137,7 @@ function saveEndpoint(config, endpoint, alias, secret) {
if (res.headers.get("x-faunadb-build")) {
return saveConfig(addEndpoint(config, endpoint, alias, secret));
}
throw new Error(`'${alias}' is not a FaunaDB endopoint`);
throw new Error(`'${alias}' is not a Fauna endopoint`);
});
}

Expand Down