Skip to content
Merged
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
6 changes: 3 additions & 3 deletions __test__/auth/AuthjsAccountsOAuthTokenRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test("It gets token for user ID and provider", async () => {
async disconnect() {},
}
},
async query(_query, values: any[] = []) {
async query(_query, values: readonly unknown[] = []) {
queryProvider = values[0]
queryUserId = values[1]
return {
Expand Down Expand Up @@ -44,7 +44,7 @@ test("It does not set token", async () => {
async disconnect() {},
}
},
async query(_query, _values: any[] = []) {
async query(_query, _values: readonly unknown[] = []) {
didSetToken = true
return { rows: [] }
}
Expand All @@ -67,7 +67,7 @@ test("It does not delete token", async () => {
async disconnect() {},
}
},
async query(_query, _values: any[] = []) {
async query(_query, _values: readonly unknown[] = []) {
didDeleteToken = true
return { rows: [] }
}
Expand Down
16 changes: 8 additions & 8 deletions __test__/auth/OAuthTokenRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ test("It reads the auth token for the specified user", async () => {
db: {
async connect() {
return {
async query(_query: string, _values: any[] = []) {
async query(_query: string, _values: readonly unknown[] = []) {
return { rows: [] }
},
async disconnect() {},
}
},
async query(_query: string, values: any[] = []) {
async query(_query: string, values: [string, string]) {
readProvider = values[0]
readUserId = values[1]
return {
Expand All @@ -36,20 +36,20 @@ test("It reads the auth token for the specified user", async () => {
test("It stores the auth token for the specified user", async () => {
let storedProvider: string | undefined
let storedUserId: string | undefined
let storedAccessToken: any | undefined
let storedRefreshToken: any | undefined
let storedAccessToken: string | undefined
let storedRefreshToken: string | undefined
const sut = new OAuthTokenRepository({
provider: "github",
db: {
async connect() {
return {
async query(_query: string, _values: any[] = []) {
async query(_query: string, _values: readonly unknown[] = []) {
return { rows: [] }
},
async disconnect() {},
}
},
async query(_query: string, values: any[] = []) {
async query(_query: string, values: [string, string, string, string]) {
storedProvider = values[0]
storedUserId = values[1]
storedAccessToken = values[2]
Expand All @@ -76,13 +76,13 @@ test("It deletes the auth token for the specified user", async () => {
db: {
async connect() {
return {
async query(_query: string, _values: any[] = []) {
async query(_query: string, _values: readonly unknown[] = []) {
return { rows: [] }
},
async disconnect() {},
}
},
async query(_query: string, values: any[] = []) {
async query(_query: string, values: [string, string]) {
deletedUserId = values[1]
return { rows: [] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ test("It does not refresh an OAuth token when the initial request was successful
},
oauthTokenRefresher: {
async refreshOAuthToken(_refreshToken) {
didRefreshOAuthToken = true
return {
accessToken: "newAccessToken",
refreshToken: "newRefreshToken"
Expand Down
2 changes: 1 addition & 1 deletion __test__/common/utils/saneParseInt.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { saneParseInt } from "@/common"

test("It parses an integer", async () => {
// @ts-ignore
// @ts-expect-error - verifying that non-string input is rejected
const val = saneParseInt(42 as string)
expect(val).toBe(42)
})
Expand Down
2 changes: 1 addition & 1 deletion __test__/projects/GitHubRepositoryDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ test("It queries for both .yml and .yaml file extension with no extension", asyn
})

test("It loads repositories for all logins", async () => {
let searchQueries: string[] = []
const searchQueries: string[] = []
const sut = new GitHubRepositoryDataSource({
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs",
Expand Down
55 changes: 55 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { defineConfig } from "eslint/config"
import typescriptEslint from "@typescript-eslint/eslint-plugin"
import tsParser from "@typescript-eslint/parser"
import path from "node:path"
import { fileURLToPath } from "node:url"
import js from "@eslint/js"
import { FlatCompat } from "@eslint/eslintrc"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

export default defineConfig([
{
ignores: ["next-env.d.ts", ".next"],
},
{
extends: [
...compat.extends("next/core-web-vitals"),
...compat.extends("eslint:recommended"),
...compat.extends("plugin:@typescript-eslint/recommended")
],

plugins: {
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
parser: tsParser,
},

rules: {
"array-callback-return": ["error"],
"no-await-in-loop": ["error"],
"no-constant-binary-expression": ["error"],
"no-constructor-return": ["error"],
"no-duplicate-imports": ["error"],
"no-new-native-nonconstructor": ["error"],
"no-self-compare": ["error"],
"no-template-curly-in-string": ["error"],
"no-unmodified-loop-condition": ["error"],
"no-unreachable-loop": ["error"],
"no-unused-private-class-members": ["error"],
"require-atomic-updates": ["error"],

"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
}],
},
}
])
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint --max-warnings=0",
"lint": "eslint --max-warnings=0 .",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest",
"testwatch": "node --experimental-vm-modules ./node_modules/.bin/jest --watch"
},
Expand Down
11 changes: 7 additions & 4 deletions src/common/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export async function downloadFile(params: {
let didExceedMaxBytes = false;
const reader = response.body.getReader();
const chunks: Uint8Array[] = [];
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line no-await-in-loop
const { done, value } = await reader.read();
Expand All @@ -55,11 +54,15 @@ export async function downloadFile(params: {
const error = new Error("Maximum file size exceeded");
error.name = ErrorName.MAX_FILE_SIZE_EXCEEDED;
throw error;
}
const allBytes = new Uint8Array(totalBytes);
let offset = 0;
for (const chunk of chunks) {
allBytes.set(chunk, offset);
offset += chunk.length;
}
const blob = new Blob(chunks);
const arrayBuffer = await blob.arrayBuffer();
const decoder = new TextDecoder();
return decoder.decode(arrayBuffer);
return decoder.decode(allBytes);
}

export function checkIfJsonOrYaml(fileText: string) {
Expand Down
15 changes: 9 additions & 6 deletions src/features/auth/view/SignInTexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { BASE_COLORS } from "@/common/theme/theme"
import { Box, Typography, SxProps } from "@mui/material"
import { useEffect, useState, useMemo } from "react"

const getRandomTextColor = ({ excluding }: { excluding?: string } = {}) => {
const colors = BASE_COLORS
.filter(e => e !== excluding)
return colors[Math.floor(Math.random() * colors.length)]
}

const INITIAL_TEXT_COLOR = getRandomTextColor()

const SignInTexts = ({ prefix }: { prefix: string }) => {
const getRandomTextColor = ({ excluding }: { excluding?: string }) => {
const colors = BASE_COLORS
.filter(e => e !== excluding)
return colors[Math.floor(Math.random() * colors.length)]
}
const [characterIndex, setCharacterIndex] = useState(0)
const [textIndex, setTextIndex] = useState(0)
const [displayedText, setDisplayedText] = useState("")
const [textColor, setTextColor] = useState(getRandomTextColor({}))
const [textColor, setTextColor] = useState(INITIAL_TEXT_COLOR)
const texts = useMemo(() => [
"is a great OpenAPI viewer",
"facilitates spec-driven development",
Expand Down
12 changes: 6 additions & 6 deletions src/features/encrypt/view/EncryptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { encrypt } from "./encryptAction"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faClipboard } from "@fortawesome/free-regular-svg-icons"

const EncryptedValueTextField = styled(TextField)({
'& .MuiInputBase-root': {
backgroundColor: '#F8F8F8'
}
})

export const EncryptionForm = () => {
const [inputText, setInputText] = useState('')
const [encryptedText, setEncryptedText] = useState('')
Expand All @@ -32,12 +38,6 @@ export const EncryptionForm = () => {
const handleCloseSnackbar = () => {
setOpenSnackbar(false)
}

const EncryptedValueTextField = styled(TextField)({
'& .MuiInputBase-root': {
backgroundColor: '#F8F8F8'
}
})

return <Box
component="form"
Expand Down
5 changes: 4 additions & 1 deletion src/features/projects/view/ProjectsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ const refreshProjects = useCallback(() => {

useEffect(() => {
// Initial refresh
refreshProjects();
const timeout = window.setTimeout(() => {
refreshProjects();
}, 0);
const handleVisibilityChange = () => {
if (!document.hidden) refreshProjects();
};
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
window.clearTimeout(timeout);
};
}, [refreshProjects]);

Expand Down
7 changes: 5 additions & 2 deletions src/features/sidebar/view/SecondarySplitHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ const ToggleSidebarButton = ({
const [isMac, setIsMac] = useState(false)
useEffect(() => {
// checkIsMac uses window so we delay the check.
setIsMac(checkIsMac())
}, [isMac, setIsMac])
const timeout = window.setTimeout(() => {
setIsMac(checkIsMac())
}, 0)
return () => window.clearTimeout(timeout)
}, [setIsMac])
const isSidebarTogglable = useContext(SidebarTogglableContext)
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + .)`
const tooltip = isSidebarOpen ? "Show Projects" : "Hide Projects"
Expand Down
1 change: 1 addition & 0 deletions types/@next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import NextAuth from "next-auth"

declare module "next-auth" {
Expand Down
2 changes: 1 addition & 1 deletion types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export {}

declare global {
interface Window {
SwaggerUIBundle: any
SwaggerUIBundle: (options: unknown) => unknown
}
}
Loading