chore: update codestyle due to prettier/rule updates

This commit is contained in:
41666 2021-06-30 08:02:25 -04:00
parent f632bfa6e5
commit 10e095656f
16 changed files with 298 additions and 292 deletions

View file

@ -3,8 +3,8 @@ FROM node:14 AS builder
# Create the user and group files that will be used in the running container to
# run the process as an unprivileged user.
RUN mkdir /user \
&& echo 'nobody:x:65534:65534:nobody:/:' >/user/passwd \
&& echo 'nobody:x:65534:' >/user/group
&& echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd \
&& echo 'nobody:x:65534:' > /user/group
# Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /src

View file

@ -10,7 +10,8 @@ import {
} from '../utils/responses';
export const ClearGuildCache = withSession(
(session) => async (request: Request): Promise<Response> => {
(session) =>
async (request: Request): Promise<Response> => {
const url = new URL(request.url);
const [, , guildID] = url.pathname.split('/');
if (!guildID) {

View file

@ -5,7 +5,8 @@ import { getGuild, getGuildData, getGuildMemberRoles } from '../utils/guild';
const fail = () => respond({ error: 'guild not found' }, { status: 404 });
export const GetPickerData = withSession(
(session: SessionData) => async (request: Request): Promise<Response> => {
(session: SessionData) =>
async (request: Request): Promise<Response> => {
const url = new URL(request.url);
const [, , guildID] = url.pathname.split('/');

View file

@ -17,7 +17,8 @@ import {
} from '../utils/responses';
export const SyncFromLegacy = withSession(
(session) => async (request: Request): Promise<Response> => {
(session) =>
async (request: Request): Promise<Response> => {
const url = new URL(request.url);
const [, , guildID] = url.pathname.split('/');
if (!guildID) {

View file

@ -21,7 +21,8 @@ import {
const notFound = () => respond({ error: 'guild not found' }, { status: 404 });
export const UpdateRoles = withSession(
({ guilds, user: { id: userID } }: SessionData) => async (request: Request) => {
({ guilds, user: { id: userID } }: SessionData) =>
async (request: Request) => {
const updateRequest = (await request.json()) as RoleUpdate;
const [, , guildID] = new URL(request.url).pathname.split('/');

View file

@ -27,17 +27,19 @@ export const addCORS = (init: ResponseInit = {}) => ({
export const respond = (obj: Record<string, any>, init: ResponseInit = {}) =>
new Response(JSON.stringify(obj), addCORS(init));
export const resolveFailures = (
export const resolveFailures =
(
handleWith: () => Response,
handler: (request: Request) => Promise<Response> | Response
) => async (request: Request): Promise<Response> => {
) =>
async (request: Request): Promise<Response> => {
try {
return handler(request);
} catch (e) {
console.error(e);
return handleWith() || respond({ error: 'internal server error' }, { status: 500 });
}
};
};
export const parsePermissions = (
permissions: bigint,
@ -106,15 +108,17 @@ export const discordFetch = async <T>(
}
};
export const cacheLayer = <Identity, Data>(
export const cacheLayer =
<Identity, Data>(
kv: WrappedKVNamespace,
keyFactory: (identity: Identity) => string,
missHandler: (identity: Identity) => Promise<Data | null>,
ttlSeconds?: number
) => async (
) =>
async (
identity: Identity,
options: { skipCachePull?: boolean } = {}
): Promise<Data | null> => {
): Promise<Data | null> => {
const key = keyFactory(identity);
if (!options.skipCachePull) {
@ -132,7 +136,7 @@ export const cacheLayer = <Identity, Data>(
await kv.put(key, fallbackValue, ttlSeconds);
return fallbackValue;
};
};
const NotAuthenticated = (extra?: string) =>
respond(
@ -142,9 +146,9 @@ const NotAuthenticated = (extra?: string) =>
{ status: 403 }
);
export const withSession = (
wrappedHandler: (session: SessionData) => Handler
): Handler => async (request: Request): Promise<Response> => {
export const withSession =
(wrappedHandler: (session: SessionData) => Handler): Handler =>
async (request: Request): Promise<Response> => {
const sessionID = getSessionID(request);
if (!sessionID) {
return NotAuthenticated('missing authentication');
@ -156,7 +160,7 @@ export const withSession = (
}
return await wrappedHandler(session)(request);
};
};
export const setupStateSession = async <T>(data: T): Promise<string> => {
const stateID = (await KSUID.random()).string;

View file

@ -1,4 +1,4 @@
const self = (global as any) as Record<string, string>;
const self = global as any as Record<string, string>;
const env = (key: string) => self[key] ?? '';

View file

@ -53,11 +53,7 @@ class EmulatedKV implements KVNamespace {
this.data.delete(key);
}
async list(options?: {
prefix?: string;
limit?: number;
cursor?: string;
}): Promise<{
async list(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{
keys: { name: string; expiration?: number; metadata?: unknown }[];
list_complete: boolean;
cursor: string;
@ -83,7 +79,7 @@ class EmulatedKV implements KVNamespace {
const kvOrLocal = (namespace: KVNamespace | null): KVNamespace =>
namespace || new EmulatedKV();
const self = (global as any) as Record<string, any>;
const self = global as any as Record<string, any>;
export const Sessions = new WrappedKVNamespace(kvOrLocal(self.KV_SESSIONS ?? null));
export const GuildData = new WrappedKVNamespace(kvOrLocal(self.KV_GUILD_DATA ?? null));

View file

@ -1,10 +1,8 @@
import { WrappedKVNamespace } from './kv';
export const useRateLimiter = (
kv: WrappedKVNamespace,
key: string,
timeoutSeconds: number
) => async (): Promise<boolean> => {
export const useRateLimiter =
(kv: WrappedKVNamespace, key: string, timeoutSeconds: number) =>
async (): Promise<boolean> => {
const value = await kv.get<boolean>(key);
if (value) {
return true;
@ -12,4 +10,4 @@ export const useRateLimiter = (
await kv.put(key, true, timeoutSeconds);
return false;
};
};

View file

@ -1,5 +1,5 @@
import { roleypolyTheme } from './theme';
import { mdxComponents } from '../atoms/typography/mdx';
import { roleypolyTheme } from './theme';
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },

View file

@ -10,9 +10,10 @@ type DynamicLogoProps = LogoFlagProps & {
};
export const DynamicLogomark = (props: Partial<DynamicLogoProps>) => {
const variant = React.useMemo(() => getRelevantVariant(props.currentDate), [
props.currentDate,
]);
const variant = React.useMemo(
() => getRelevantVariant(props.currentDate),
[props.currentDate]
);
if (!variant) {
return <Logomark {...props} />;
@ -35,9 +36,10 @@ export const DynamicLogomark = (props: Partial<DynamicLogoProps>) => {
};
export const DynamicLogotype = (props: Partial<DynamicLogoProps>) => {
const variant = React.useMemo(() => getRelevantVariant(props.currentDate), [
props.currentDate,
]);
const variant = React.useMemo(
() => getRelevantVariant(props.currentDate),
[props.currentDate]
);
if (!variant) {
return <Logotype {...props} />;

View file

@ -38,9 +38,9 @@ export const EditorCategory = (props: Props) => {
const [roleSearchPopoverActive, setRoleSearchPopoverActive] = React.useState(false);
const [roleSearchTerm, updateSearchTerm] = React.useState('');
const onUpdate = (key: keyof typeof props.category, pred?: (newValue: any) => any) => (
newValue: any
) => {
const onUpdate =
(key: keyof typeof props.category, pred?: (newValue: any) => any) =>
(newValue: any) => {
props.onChange({
...props.category,
[key]: pred ? pred(newValue) : newValue,

View file

@ -1,12 +1,11 @@
import * as React from 'react';
import { FeatureFlag, FeatureFlagProvider, FeatureFlagsContext } from './FeatureFlags';
export const FeatureFlagDecorator = (flags: FeatureFlag[]) => (
storyFn: () => React.ReactNode
) => {
export const FeatureFlagDecorator =
(flags: FeatureFlag[]) => (storyFn: () => React.ReactNode) => {
return (
<FeatureFlagsContext.Provider value={new FeatureFlagProvider(flags)}>
{storyFn()}
</FeatureFlagsContext.Provider>
);
};
};

View file

@ -1,10 +1,13 @@
import * as React from 'react';
export const withContext = <T, K extends T>(
export const withContext =
<T, K extends T>(
Context: React.Context<T>,
Component: React.ComponentType<K>
): React.FunctionComponent<K> => (props) => (
): React.FunctionComponent<K> =>
(props) =>
(
<Context.Consumer>
{(context) => <Component {...props} {...context} />}
</Context.Consumer>
);
);

View file

@ -47,9 +47,8 @@ export const useSessionContext = () => React.useContext(SessionContext);
export const SessionContextProvider = (props: { children: React.ReactNode }) => {
const { fetch } = useApiContext();
const [sessionID, setSessionID] = React.useState<SessionContextT['sessionID']>(
undefined
);
const [sessionID, setSessionID] =
React.useState<SessionContextT['sessionID']>(undefined);
const [sessionState, setSessionState] = React.useState<SessionState>(
SessionState.NoAuth
);

View file

@ -41,9 +41,10 @@ const Picker = (props: PickerProps) => {
fetchPickerData();
}, [props.serverID, authedFetch, pushRecentGuild]);
React.useCallback((serverID) => pushRecentGuild(serverID), [pushRecentGuild])(
props.serverID
);
React.useCallback(
(serverID) => pushRecentGuild(serverID),
[pushRecentGuild]
)(props.serverID);
if (!isAuthenticated) {
return <Redirect to={`/auth/login?r=${props.serverID}`} replace />;