-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v3' into persist-secrets
- Loading branch information
Showing
24 changed files
with
571 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Lint | ||
|
||
on: | ||
# temporarily "v3"; change to "main" after merge | ||
push: | ||
branches: ["v3"] | ||
pull_request: | ||
branches: ["v3"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Lint (nodeJS 22.x) | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22.x | ||
cache: "npm" | ||
- run: npm ci | ||
- run: npm run lint | ||
env: | ||
TERM: xterm-256color | ||
# Set to the correct color level; 2 is 256 colors | ||
# https://github.com/chalk/chalk?tab=readme-ov-file#supportscolor | ||
FORCE_COLOR: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18 | ||
22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//@ts-check | ||
|
||
import { container } from "../cli.mjs"; | ||
|
||
async function listDatabases(profile) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
//@ts-check | ||
|
||
import repl from "node:repl"; | ||
|
||
import { container } from "../cli.mjs"; | ||
import { | ||
// ensureDbScopeClient, | ||
commonConfigurableQueryOptions, | ||
} from "../lib/command-helpers.mjs"; | ||
import { performQuery } from "./eval.mjs"; | ||
|
||
async function doShell(argv) { | ||
const logger = container.resolve("logger"); | ||
let completionPromise; | ||
|
||
if (argv.dbPath) logger.stdout(`Starting shell for database ${argv.dbPath}`); | ||
logger.stdout("Type Ctrl+D or .exit to exit the shell"); | ||
|
||
/** @type {import('node:repl').ReplOptions} */ | ||
const replArgs = { | ||
prompt: `${argv.db_path || ""}> `, | ||
ignoreUndefined: true, | ||
preview: argv.version !== "10", | ||
// TODO: integrate with fql-analyzer for completions | ||
completer: argv.version === "10" ? () => [] : undefined, | ||
output: container.resolve("stdoutStream"), | ||
input: container.resolve("stdinStream"), | ||
eval: await buildCustomEval(argv), | ||
terminal: true, | ||
}; | ||
|
||
const shell = repl.start(replArgs); | ||
// eslint-disable-next-line no-console | ||
shell.on("error", console.error); | ||
|
||
completionPromise = new Promise((resolve) => { | ||
shell.on("exit", resolve); | ||
}); | ||
|
||
[ | ||
{ | ||
cmd: "clear", | ||
help: "Clear the repl", | ||
action: () => { | ||
// eslint-disable-next-line no-console | ||
console.clear(); | ||
shell.prompt(); | ||
}, | ||
}, | ||
{ | ||
cmd: "last_error", | ||
help: "Display the last error", | ||
action: () => { | ||
logger.stdout(shell.context.lastError); | ||
shell.prompt(); | ||
}, | ||
}, | ||
].forEach(({ cmd, ...cmdOptions }) => shell.defineCommand(cmd, cmdOptions)); | ||
|
||
return completionPromise; | ||
} | ||
|
||
// caches the logger, client, and performQuery for subsequent shell calls | ||
async function buildCustomEval(argv) { | ||
const client = await container.resolve("getSimpleClient")(argv); | ||
|
||
return async (cmd, ctx, filename, cb) => { | ||
try { | ||
const logger = container.resolve("logger"); | ||
|
||
if (cmd.trim() === "") return cb(); | ||
|
||
let res; | ||
try { | ||
res = await performQuery(client, cmd, undefined, { | ||
...argv, | ||
format: "shell", | ||
}); | ||
} catch (err) { | ||
let errString = ""; | ||
if (err.code) { | ||
errString = errString.concat(`${err.code}\n`); | ||
} | ||
errString = errString.concat(err.message); | ||
logger.stderr(errString); | ||
return cb(null); | ||
} | ||
|
||
logger.stdout(res); | ||
|
||
return cb(null); | ||
} catch (e) { | ||
return cb(e); | ||
} | ||
}; | ||
} | ||
|
||
function buildShellCommand(yargs) { | ||
return yargs | ||
.options({ | ||
...commonConfigurableQueryOptions, | ||
}) | ||
.example([["$0 shell"], ["$0 shell root_db/child_db"]]) | ||
.version(false) | ||
.help("help", "show help"); | ||
} | ||
|
||
export default { | ||
builder: buildShellCommand, | ||
handler: doShell, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.