Skip to content

Commit

Permalink
Merge pull request #56 from makeark/format
Browse files Browse the repository at this point in the history
Format
  • Loading branch information
kaulsh authored Aug 21, 2022
2 parents 79af0af + 2f19031 commit 312e6f9
Show file tree
Hide file tree
Showing 83 changed files with 2,061 additions and 2,997 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run format:prettier:diff
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
useTabs: true,
semi: true,
plugins: [require.resolve("prettier-plugin-organize-imports")],
trailingComma: "all",
printWidth: 120,
};
6 changes: 1 addition & 5 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ module.exports = {

config.module.rules.push({
test: /\.less$/,
use: [
require.resolve("style-loader"),
require.resolve("css-loader"),
require.resolve("less-loader"),
],
use: [require.resolve("style-loader"), require.resolve("css-loader"), require.resolve("less-loader")],
});

return config;
Expand Down
4 changes: 2 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "../src/common/styles/variables.less";
import "@blueprintjs/core/lib/css/blueprint.css";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
import "@blueprintjs/icons/lib/css/blueprint-icons.css";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
import "../src/common/styles/variables.less";

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
Expand Down
17 changes: 8 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.alwaysShowStatus": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
}
"typescript.tsdk": "node_modules/typescript/lib",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsserver.experimental.enableProjectDiagnostics": true
}
87 changes: 24 additions & 63 deletions electron/core/driver/connection/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { generateKeySync } from "crypto";
import { existsSync } from "fs";
import { mkdir, writeFile } from "fs/promises";
import { ListDatabasesResult, MongoClient } from "mongodb";
import { Server } from "net";
import { MemEntry } from "../../../modules/ipc/types";
import { resolve } from "path";
import { ERR_CODES } from "../../../../util/errors";
import { MemEntry } from "../../../modules/ipc/types";
import { ARK_FOLDER_PATH, ENCRYPTION_KEY_FILENAME } from "../../../utils/constants";
import {
createConnectionConfigurations,
decrypt,
Expand All @@ -11,22 +16,11 @@ import {
sshTunnel,
URIConfiguration,
} from "./library";
import { mkdir, writeFile } from "fs/promises";
import { generateKeySync } from "crypto";
import { resolve } from "path";
import { existsSync } from "fs";
import {
ARK_FOLDER_PATH,
ENCRYPTION_KEY_FILENAME,
} from "../../../utils/constants";

const CONNECTION_TIMEOUT_MS = 3000;

export interface Connection {
info(
dep: Ark.DriverDependency,
arg: { id: string }
): Promise<GetConnectionResult>;
info(dep: Ark.DriverDependency, arg: { id: string }): Promise<GetConnectionResult>;
/**
* Load all stored connections from disk.
*/
Expand All @@ -40,15 +34,12 @@ export interface Connection {
arg: {
type: "config" | "uri";
config: Ark.StoredConnection | URIConfiguration;
}
},
): Promise<{ status: boolean; message: string }>;
/**
* Load a single stored connection from disk.
*/
load(
dep: Ark.DriverDependency,
arg: { id: string }
): Promise<Ark.StoredConnection>;
load(dep: Ark.DriverDependency, arg: { id: string }): Promise<Ark.StoredConnection>;
/**
* Save a connection using a URI or granular configurations
*/
Expand All @@ -58,7 +49,7 @@ export interface Connection {
type: "config" | "uri";
config: Ark.StoredConnection | URIConfiguration;
icon?: Ark.StoredIcon;
}
},
): Promise<string>;
/**
* Delete a stored conneection from disk.
Expand All @@ -75,28 +66,19 @@ export interface Connection {
/**
* List databases for a cached connection
*/
listDatabases(
dep: Ark.DriverDependency,
arg: { id: string }
): Promise<ListDatabasesResult["databases"]>;
listDatabases(dep: Ark.DriverDependency, arg: { id: string }): Promise<ListDatabasesResult["databases"]>;
decryptPassword(
dep: Ark.DriverDependency,
arg: {
pwd: string;
iv: string;
}
},
): Promise<string>;
createEncryptionKey(
dep: Ark.DriverDependency,
arg: { path?: string }
): Promise<string>;
convertConnectionToUri(
dep: Ark.DriverDependency,
arg: { config: Ark.StoredConnection }
): Promise<{ uri: string }>;
createEncryptionKey(dep: Ark.DriverDependency, arg: { path?: string }): Promise<string>;
convertConnectionToUri(dep: Ark.DriverDependency, arg: { config: Ark.StoredConnection }): Promise<{ uri: string }>;
convertUriToConnection(
dep: Ark.DriverDependency,
arg: { config: URIConfiguration }
arg: { config: URIConfiguration },
): Promise<{ connection: Ark.StoredConnection }>;
}

Expand Down Expand Up @@ -133,17 +115,14 @@ export const Connection: Connection = {
Object.values(connections).map(async (connection) => ({
...connection,
uri: await getConnectionUri(connection, settings?.encryptionKey),
}))
})),
);
return populated;
},
load: async ({ storedConnection, _stores }) => {
if (storedConnection) {
const settings = await _stores.settingsStore.get("general");
const uri = await getConnectionUri(
storedConnection,
settings?.encryptionKey
);
const uri = await getConnectionUri(storedConnection, settings?.encryptionKey);
return { ...storedConnection, uri };
} else {
throw new Error(ERR_CODES.CORE$DRIVER$NO_STORED_CONNECTION);
Expand Down Expand Up @@ -173,10 +152,7 @@ export const Connection: Connection = {
}

const settings = await settingsStore.get("general");
const connectionUri = await getConnectionUri(
storedConnection,
settings?.encryptionKey
);
const connectionUri = await getConnectionUri(storedConnection, settings?.encryptionKey);
const client = new MongoClient(connectionUri, {
connectTimeoutMS: CONNECTION_TIMEOUT_MS,
serverSelectionTimeoutMS: CONNECTION_TIMEOUT_MS,
Expand Down Expand Up @@ -222,10 +198,7 @@ export const Connection: Connection = {
const { diskStore, iconStore } = stores;

const settings = await stores.settingsStore.get("general");
const config = await createConnectionConfigurations(
args,
settings?.encryptionKey
);
const config = await createConnectionConfigurations(args, settings?.encryptionKey);

if (config.id && args.icon) {
config.icon = true;
Expand All @@ -244,18 +217,12 @@ export const Connection: Connection = {
test: async ({ _stores: store }, args) => {
try {
const settings = await store.settingsStore.get("general");
const config = await createConnectionConfigurations(
args,
settings?.encryptionKey
);
const config = await createConnectionConfigurations(args, settings?.encryptionKey);
if (config.ssh && config.ssh.useSSH) {
await sshTunnel(config.ssh, config.hosts);
}

const connectionUri = await getConnectionUri(
config,
settings?.encryptionKey
);
const connectionUri = await getConnectionUri(config, settings?.encryptionKey);

const client = new MongoClient(connectionUri, {
connectTimeoutMS: CONNECTION_TIMEOUT_MS,
Expand Down Expand Up @@ -293,11 +260,7 @@ export const Connection: Connection = {
return {
status: false,
message:
err && err instanceof Error
? err.message
: typeof err === "string"
? err
: "Something unexpected happened.",
err && err instanceof Error ? err.message : typeof err === "string" ? err : "Something unexpected happened.",
};
}
},
Expand Down Expand Up @@ -327,9 +290,7 @@ export const Connection: Connection = {
return Promise.resolve(decrypt(pwd, settings?.encryptionKey, iv));
},
createEncryptionKey: async function (_, { path }) {
const key: string = generateKeySync("aes", { length: 256 })
.export()
.toString("hex");
const key: string = generateKeySync("aes", { length: 256 }).export().toString("hex");

if (path && !existsSync(path)) {
await mkdir(path, { recursive: true });
Expand Down Expand Up @@ -359,7 +320,7 @@ export const Connection: Connection = {
type: "uri",
config,
},
settings?.encryptionKey
settings?.encryptionKey,
);

return { connection: stored };
Expand Down
Loading

0 comments on commit 312e6f9

Please sign in to comment.