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

chore(lint): enforce strict types #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Lint with eslint 🧹
- name: Lint 🧹
run: pnpm lint
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
"lint:js": "eslint .",
"lint:js:fix": "eslint . --fix",
"lint:ts": "tsc",
"lint:css": "stylelint \"./src/**/*.css\"",
"lint:css:fix": "stylelint \"./src/**/*.css\" -- --fix"
},
Expand Down Expand Up @@ -54,4 +55,4 @@
"solid-js": "1.8.11",
"solid-toast": "^0.5.0"
}
}
}
22 changes: 8 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { invoke } from '@tauri-apps/api/tauri';
import { Icon } from 'solid-heroicons';
import { lockClosed, magnifyingGlass } from 'solid-heroicons/outline';
import { createEffect, createResource, For, Show, type Component } from 'solid-js';
Expand All @@ -11,16 +10,9 @@ import Search from './Search';
import SearchIndex from './SearchIndex';
import SecretList from './SecretList';
import SecretView from './SecretView';
import { Toaster, toast } from 'solid-toast';
import { Toaster } from 'solid-toast';
import { setState, state } from './state';

const listKVS = async (): Promise<null | string[]> => {
try {
return await invoke('list_kvs');
} catch (e) {
toast.error(e);
}
};
import { fetchKVS } from './utils';

const Home = () => <strong>Select a KV to get started</strong>;

Expand All @@ -34,7 +26,7 @@ const pageMap: { [key: string]: Component } = {
};

const App: Component = () => {
const [kvs, { refetch }] = createResource(listKVS);
const [kvs, { refetch }] = createResource(fetchKVS);

createEffect(() => {
if (state.page === 'home') refetch();
Expand Down Expand Up @@ -85,9 +77,11 @@ const App: Component = () => {
<strong>Loading...</strong>
)}
<Show when={state.page !== 'login' && kvs()}>
<For each={kvs().sort()}>
{(kv) => <Node kv={kv} path="" icon={lockClosed} />}
</For>
{(kvs) => (
<For each={kvs().sort()}>
{(kv) => <Node kv={kv} path="" icon={lockClosed} />}
</For>
)}
</Show>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Item: Component<ItemProps> = (props) => {
>
<Show
when={props.path === ''}
fallback={splitPath(props.path).at(-1).replace('/', '')}
fallback={splitPath(props.path).at(-1)?.replace('/', '')}
>
<span
classList={{
Expand Down
8 changes: 3 additions & 5 deletions src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { setState } from './state';
const Login: Component = () => {
const oidcAuth = async (): Promise<void> => {
try {
console.log(
await invoke('oidc_auth', { address: oidcURL(), mount: 'oidc' }),
);
setState('page', 'home');
await invoke('oidc_auth', { address: oidcURL(), mount: 'oidc' }),
setState('page', 'home');
} catch (e) {
toast.error(e);
toast.error(`${e}`);
}
};

Expand Down
9 changes: 3 additions & 6 deletions src/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ type NodeProps = {
icon: { path: JSXElement; outline: boolean; mini: boolean };
kv: string;
path: string;
displaySecret?: (path: string, kv: string) => void;
};

const Node: Component<NodeProps> = (props) => {
const [children, setChildren] = createSignal([]);
const [children, setChildren] = createSignal<NodeProps[]>([]);
const [expanded, setExpanded] = createSignal(false);

const chevron = () => (expanded() ? chevronDown : chevronRight);
Expand Down Expand Up @@ -53,11 +52,9 @@ const Node: Component<NodeProps> = (props) => {
<Item {...props} />
</div>
<div class="pl-4">
<Show when={expanded()}>
<Show when={expanded() && children()}>
<div>
<For each={children()}>
{(child) => <Node class="ml-10" {...child} />}
</For>
<For each={children()}>{(child) => <Node {...child} />}</For>
</div>
</Show>
</div>
Expand Down
17 changes: 3 additions & 14 deletions src/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { createSignal, For, Show, type Component } from 'solid-js';
import SearchResult from './SearchResult';
import { setState } from './state';
import toast from 'solid-toast';

type SearchIndexType = {
[key: string]: string[];
};

interface SearchResult {
kv: string;
Expand All @@ -16,18 +11,12 @@ const Search: Component = () => {
const [search, setSearch] = createSignal('');
const [searchResults, setSearchResults] = createSignal<SearchResult[]>([]);
const searchIndexRaw = localStorage.getItem('searchIndex');
const searchIndex = (): SearchIndexType => {
try {
return JSON.parse(searchIndexRaw) as SearchIndexType;
} catch (e) {
toast.error(e);
return {};
}
};
const runSearch = () => {
console.log(`searching for ${search()}`);
const searchTerm = search();
const results = Object.entries(searchIndex()).flatMap(([kv, paths]) =>
const results = Object.entries(
JSON.parse(searchIndexRaw ?? '{}') as Record<string, string[]>,
).flatMap(([kv, paths]) =>
paths
.filter((path) => path.includes(searchTerm))
.map((path) => ({ kv, path })),
Expand Down
7 changes: 6 additions & 1 deletion src/SearchIndex.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSignal, type Component } from 'solid-js';
import { fetchKVS, fetchPaths } from './utils';
import toast from 'solid-toast';

const SearchIndex: Component = () => {
const [progress, setProgress] = createSignal(0);
Expand Down Expand Up @@ -31,8 +32,12 @@ const SearchIndex: Component = () => {
};

const createSearchIndex = async () => {
const searchIndex = {};
const searchIndex: Record<string, string[]> = {};
const kvs = await fetchKVS();
if (!kvs) {
toast.error('Unable to create search index.');
return;
}
let totalPaths = 0;
setMaxProgress(kvs.length);
for await (const kv of kvs) {
Expand Down
72 changes: 37 additions & 35 deletions src/SecretView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,44 @@ const SecretView: Component = () => {
</thead>
<tbody>
<Show when={secrets()} fallback={<strong>Loading...</strong>}>
<For each={Object.entries(secrets())}>
{([key, value]) => (
<tr class="border-b bg-white dark:border-gray-700 dark:bg-gray-800">
<th
scope="row"
class="whitespace-nowrap px-6 py-4 font-medium text-gray-900 dark:text-white"
>
{key}
</th>
<td class="px-6 py-4">
<Show
when={
key === 'description' ||
key === 'username'
}
fallback="********"
{(secrets) => (
<For each={Object.entries(secrets())}>
{([key, value]) => (
<tr class="border-b bg-white dark:border-gray-700 dark:bg-gray-800">
<th
scope="row"
class="whitespace-nowrap px-6 py-4 font-medium text-gray-900 dark:text-white"
>
{value}
</Show>
</td>
<td class="px-6 py-4 text-right">
<a
class="cursor-pointer font-medium text-blue-600 hover:underline dark:text-blue-500"
onClick={() => {
writeText(value);
toast.success(
`Copied ${key} for ${state.path} to clipboard`,
);
}}
>
Copy
</a>
</td>
</tr>
)}
</For>
{key}
</th>
<td class="px-6 py-4">
<Show
when={
key === 'description' ||
key === 'username'
}
fallback="********"
>
{value}
</Show>
</td>
<td class="px-6 py-4 text-right">
<a
class="cursor-pointer font-medium text-blue-600 hover:underline dark:text-blue-500"
onClick={() => {
writeText(value);
toast.success(
`Copied ${key} for ${state.path} to clipboard`,
);
}}
>
Copy
</a>
</td>
</tr>
)}
</For>
)}
</Show>
</tbody>
</table>
Expand Down
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ import { render } from 'solid-js/web';
import App from './App';
import './index.css';

render(() => <App />, document.getElementById('root'));
const root = document.getElementById('root');

if (root) {
render(() => <App />, root);
}
12 changes: 6 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const fetchPaths = async ({
}: {
mount: string;
path: string;
}): Promise<string[] | null> => {
}): Promise<string[] | undefined> => {
try {
return await invoke('list_path', {
mount,
path,
});
} catch (e) {
toast.error(e);
toast.error(`${e}`);
}
};

Expand All @@ -30,22 +30,22 @@ const fetchSecret = async ({
}: {
mount: string;
path: string;
}): Promise<Record<string, string> | null> => {
}): Promise<Record<string, string> | undefined> => {
try {
return await invoke('get_secret', {
mount,
path,
});
} catch (e) {
toast.error(e);
toast.error(`${e}`);
}
};

const fetchKVS = async (): Promise<string[] | null> => {
const fetchKVS = async (): Promise<string[] | undefined> => {
try {
return await invoke('list_kvs');
} catch (e) {
toast.error(e);
toast.error(`${e}`);
}
};

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"strict": true,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "node",
Expand Down
Loading