Skip to content

Commit

Permalink
improve type inference on things pulled from awilix
Browse files Browse the repository at this point in the history
the types for the container were broken; this commit fixes them. as a
result, typescript server can properly infer the type of things resolved
off the awilix container. unfortunately, it's likely not going to work
in all situations - for instance, i've noticed that JSDoc comments are
dropped.
  • Loading branch information
echo-bravo-yahoo committed Nov 23, 2024
1 parent 82d4fa9 commit 275eea8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import chalk from "chalk";
import yargs from "yargs";

import keyCommand from "./commands/key.mjs";
import databaseCommand from "./commands/database/database.mjs";
import evalCommand from "./commands/eval.mjs";
import shellCommand from "./commands/shell.mjs";
import keyCommand from "./commands/key.mjs";
import loginCommand from "./commands/login.mjs";
import schemaCommand from "./commands/schema/schema.mjs";
import databaseCommand from "./commands/database/database.mjs";

import shellCommand from "./commands/shell.mjs";
import { authNZMiddleware } from "./lib/auth/authNZ.mjs";
import { checkForUpdates, fixPaths, logArgv } from "./lib/middleware.mjs";

/** @typedef {import('awilix').AwilixContainer<import('./config/setup-container.mjs').modifiedInjectables>} cliContainer */
/** @typedef {import('awilix').AwilixContainer<import('./config/setup-container.mjs').modifiedInjectables> } cliContainer */

/** @type {cliContainer} */
export let container;
Expand All @@ -36,8 +35,10 @@ export async function run(argvInput, _container) {
builtYargs = buildYargs(argvInput);
await parseYargs(builtYargs);
} catch (e) {
let subMessage = chalk.reset("Use 'fauna <command> --help' for more information about a command.");

let subMessage = chalk.reset(
"Use 'fauna <command> --help' for more information about a command.",
);

if (argvInput.length > 0) {
subMessage = chalk.red(e.message);
}
Expand Down
11 changes: 1 addition & 10 deletions src/config/setup-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import {
writeSchemaFiles,
} from "../lib/schema.mjs";

// import { findUpSync } from 'find-up'
// import fs from 'node:fs'
// const __dirname = import.meta.dirname;
// export const configPath = findUpSync(['dice.json'], { cwd: __dirname })
// export const config = configPath ? JSON.parse(fs.readFileSync(configPath)) : {}

export function setupCommonContainer() {
const container = awilix.createContainer({
injectionMode: awilix.InjectionMode.PROXY,
Expand All @@ -44,12 +38,9 @@ export function setupCommonContainer() {
}

/**
* @template T
* @typedef {{ [P in keyof T[P]]: ReturnType<T[P]['resolve']> }} Resolvers<T>
* @typedef {{ [Property in keyof injectables]: ReturnType<injectables[Property]["resolve"]> }} modifiedInjectables
*/

/** @typedef {Resolvers<injectables>} modifiedInjectables */

export const injectables = {
// process specifics
stdinStream: awilix.asValue(process.stdin),
Expand Down

0 comments on commit 275eea8

Please sign in to comment.