From eda1fb929fa04ccb2d7294925df0f4715c0fbe8b Mon Sep 17 00:00:00 2001 From: Guilherme_F Date: Fri, 28 Jun 2024 16:35:53 +0100 Subject: [PATCH] Fixes * Set client production ready * Removed unused dependencies and exports * Fixed CheckedListItem import path --- code/client/package.json | 14 ++------ code/client/src/contexts/auth/AuthContext.tsx | 2 +- .../src/contexts/error/ErrorContext.tsx | 2 +- .../contexts/workspace/WorkspaceContext.tsx | 2 +- .../plugins/markdown/rendering/renderers.tsx | 2 +- .../editor/slate/plugins/markdown/rules.ts | 4 +-- .../slate/plugins/markdown/withMarkdown.ts | 2 +- code/client/src/domain/editor/slate/types.ts | 4 +-- .../domain/editor/slate/utils/selection.ts | 16 ++------- code/client/src/pwa/inject-config.ts | 6 ---- code/client/src/pwa/manifest-config.ts | 35 ------------------- code/client/src/pwa/pwa-assets.config.ts | 9 ----- code/client/src/pwa/pwa-config.ts | 13 ------- .../components/editor/hooks/useCursors.ts | 2 +- code/client/src/utils/logging.ts | 14 -------- code/client/src/utils/utils.ts | 2 +- code/client/tests/mocks/global-mocks.ts | 12 ------- code/client/tests/mocks/mock-handlers.ts | 1 - code/client/tests/mocks/mock-server.ts | 4 --- code/client/tests/test-utils.ts | 24 ------------- code/client/tsconfig.json | 8 ++--- code/client/vite.config.ts | 14 +++++--- code/server/package.json | 9 ----- code/server/src/databases/memory/Memory.ts | 2 +- code/server/src/domain/errors/errors.ts | 2 +- code/server/src/utils/logging.ts | 5 +-- 26 files changed, 32 insertions(+), 178 deletions(-) delete mode 100644 code/client/src/pwa/inject-config.ts delete mode 100644 code/client/src/pwa/manifest-config.ts delete mode 100644 code/client/src/pwa/pwa-assets.config.ts delete mode 100644 code/client/src/pwa/pwa-config.ts delete mode 100644 code/client/src/utils/logging.ts delete mode 100644 code/client/tests/mocks/global-mocks.ts delete mode 100644 code/client/tests/mocks/mock-handlers.ts delete mode 100644 code/client/tests/mocks/mock-server.ts delete mode 100644 code/client/tests/test-utils.ts diff --git a/code/client/package.json b/code/client/package.json index f5ce5137..9d14597a 100644 --- a/code/client/package.json +++ b/code/client/package.json @@ -23,13 +23,10 @@ "@emotion/styled": "^11.11.5", "@mui/material": "^5.15.18", "@notespace/shared": "file:..\\shared", - "@testing-library/jest-dom": "^6.4.5", "dotenv": "^16.4.5", "eslint-plugin-playwright": "^1.6.0", "firebase": "^10.12.2", - "js-cookie": "^3.0.5", "lodash": "^4.17.21", - "msw": "^2.2.14", "react": "^18.3.1", "react-dom": "^18.3.1", "react-icons": "^5.2.1", @@ -39,18 +36,12 @@ "socket.io-client": "^4.7.5" }, "devDependencies": { - "@testing-library/dom": "^10.1.0", - "@testing-library/react": "^15.0.7", - "@testing-library/user-event": "^14.5.2", "@types/firebase": "^3.2.1", - "@types/jest": "^29.5.12", - "@types/js-cookie": "^3.0.6", "@types/lodash": "^4.17.1", - "@types/node": "^20.12.10", + "@types/node": "^20.14.9", "@types/react": "^18.3.1", "@types/react-dom": "^18.3.0", "@types/react-router-dom": "^5.3.3", - "@types/uuid": "^9.0.8", "@typescript-eslint/eslint-plugin": "^7.8.0", "@typescript-eslint/parser": "^7.8.0", "@vite-pwa/assets-generator": "^0.2.4", @@ -68,9 +59,8 @@ "knip": "^5.12.3", "prettier": "^3.2.5", "sass": "^1.77.0", - "typescript": "^5.4.5", + "typescript": "^5.5.2", "vite": "^5.2.11", - "vite-plugin-pwa": "^0.20.0", "vite-tsconfig-paths": "^4.3.2", "vitest": "^1.6.0" } diff --git a/code/client/src/contexts/auth/AuthContext.tsx b/code/client/src/contexts/auth/AuthContext.tsx index 6cff5b3e..a8bedf52 100644 --- a/code/client/src/contexts/auth/AuthContext.tsx +++ b/code/client/src/contexts/auth/AuthContext.tsx @@ -27,7 +27,7 @@ type AuthProviderProps = { children: ReactNode; }; -export function AuthProvider({ children }: AuthProviderProps) { +function AuthProvider({ children }: AuthProviderProps) { const [currentUser, setCurrentUser] = useState(null); const [loading, setLoading] = useState(true); const { publishError } = useError(); diff --git a/code/client/src/contexts/error/ErrorContext.tsx b/code/client/src/contexts/error/ErrorContext.tsx index 96fd79e6..fe0cf01b 100644 --- a/code/client/src/contexts/error/ErrorContext.tsx +++ b/code/client/src/contexts/error/ErrorContext.tsx @@ -6,7 +6,7 @@ const ERROR_TIMEOUT = 5000; export type ErrorHandler = (fn: () => T) => Promise; -export type ErrorContextType = { +type ErrorContextType = { publishError: (error: Error) => void; errorHandler: ErrorHandler; }; diff --git a/code/client/src/contexts/workspace/WorkspaceContext.tsx b/code/client/src/contexts/workspace/WorkspaceContext.tsx index 4e8c4951..f497a73f 100644 --- a/code/client/src/contexts/workspace/WorkspaceContext.tsx +++ b/code/client/src/contexts/workspace/WorkspaceContext.tsx @@ -17,7 +17,7 @@ export type WorkspaceOperations = { moveResource: (id: string, parent: string) => Promise; }; -export type WorkspaceContextType = { +type WorkspaceContextType = { workspace?: WorkspaceMeta; resources?: Resources; operations?: WorkspaceOperations; diff --git a/code/client/src/domain/editor/slate/plugins/markdown/rendering/renderers.tsx b/code/client/src/domain/editor/slate/plugins/markdown/rendering/renderers.tsx index 126324fc..baf7d91d 100644 --- a/code/client/src/domain/editor/slate/plugins/markdown/rendering/renderers.tsx +++ b/code/client/src/domain/editor/slate/plugins/markdown/rendering/renderers.tsx @@ -4,7 +4,7 @@ import Selection from '@ui/pages/document/components/cursor/Selection'; import Cursor from '@ui/pages/document/components/cursor/Cursor'; import { Range } from 'slate'; import { type BlockStyle, BlockStyles } from '@notespace/shared/src/document/types/styles'; -import CheckListItem from '@domain/editor/slate/plugins/markdown/rendering/components/elements/CheckListItem'; +import { CheckListItem } from '@domain/editor/slate/plugins/markdown/rendering/components/components'; import { isStatefulBlock } from '@domain/editor/slate/utils/slate'; /** diff --git a/code/client/src/domain/editor/slate/plugins/markdown/rules.ts b/code/client/src/domain/editor/slate/plugins/markdown/rules.ts index f4a04c49..a6f30d67 100644 --- a/code/client/src/domain/editor/slate/plugins/markdown/rules.ts +++ b/code/client/src/domain/editor/slate/plugins/markdown/rules.ts @@ -13,13 +13,13 @@ export enum RuleType { Inline = 'inline', } -export type Rule = { +type Rule = { type: RuleType; triggers: RegExp[]; apply: ApplyFunction; }; -export type ApplyFunction = (handler: ApplyBlockStyle | ApplyInlineStyle) => (editor: Editor, range: Range) => void; +type ApplyFunction = (handler: ApplyBlockStyle | ApplyInlineStyle) => (editor: Editor, range: Range) => void; export function blockRules(style: BlockStyle, ...triggerCharacters: string[]): Rule { const triggers = triggerCharacters.map(trigger => new RegExp(`^(${escapeRegExp(trigger)})$`)); diff --git a/code/client/src/domain/editor/slate/plugins/markdown/withMarkdown.ts b/code/client/src/domain/editor/slate/plugins/markdown/withMarkdown.ts index 83df86a4..e73bb9d9 100644 --- a/code/client/src/domain/editor/slate/plugins/markdown/withMarkdown.ts +++ b/code/client/src/domain/editor/slate/plugins/markdown/withMarkdown.ts @@ -7,7 +7,7 @@ import { MarkdownConnector } from '@domain/editor/connectors/markdown/types'; * @param editor * @param connector */ -export function withMarkdown(editor: Editor, connector: MarkdownConnector) { +function withMarkdown(editor: Editor, connector: MarkdownConnector) { const { deleteBackward, insertText, isInline, delete: deleteOperation } = editor; const editorOperations = operations(editor, connector); diff --git a/code/client/src/domain/editor/slate/types.ts b/code/client/src/domain/editor/slate/types.ts index 9c8240c1..8b5b615d 100644 --- a/code/client/src/domain/editor/slate/types.ts +++ b/code/client/src/domain/editor/slate/types.ts @@ -3,7 +3,7 @@ import { type ReactEditor } from 'slate-react'; import { type BlockStyle, InlineStyle } from '@notespace/shared/src/document/types/styles'; import { CursorData } from '@ui/pages/document/components/editor/hooks/useCursors'; -export interface CustomFormat { +interface CustomFormat { bold?: boolean; italic?: boolean; underline?: boolean; @@ -16,7 +16,7 @@ export interface CustomText extends CustomFormat { cursor?: CursorData; } -export interface CustomElement { +interface CustomElement { type: BlockStyle | InlineStyle; children: Descendant[]; } diff --git a/code/client/src/domain/editor/slate/utils/selection.ts b/code/client/src/domain/editor/slate/utils/selection.ts index ab7f520e..ce9683be 100644 --- a/code/client/src/domain/editor/slate/utils/selection.ts +++ b/code/client/src/domain/editor/slate/utils/selection.ts @@ -1,6 +1,6 @@ import { Editor, Node, Path, Point, Range, Text } from 'slate'; -import { Cursor, emptyCursor, emptySelection, Selection } from '@domain/editor/cursor'; -import { first, isEqual } from 'lodash'; +import { Cursor, emptySelection, Selection } from '@domain/editor/cursor'; +import { first } from 'lodash'; /** * Checks if the current selection is active @@ -39,7 +39,7 @@ const pointsToSelection = (editor: Editor, start: Point, end: Point): Selection * @param editor * @param point */ -export function pointToCursor(editor: Editor, point: Point): Cursor { +function pointToCursor(editor: Editor, point: Point): Cursor { const line = point.path[0]; const cursor: Cursor = { line, column: point.offset }; if (point.path[1] === 0) return cursor; @@ -72,13 +72,3 @@ export function getSelectionByRange(editor: Editor, range: Range, offset: number selection.end.column += offset; return selection; } - -/** - * Checks if the selection is empty - * @param selection - */ -export function isSelectionEmpty(selection: Selection): boolean { - const { start, end } = selection; - const startCursor = emptyCursor(); - return isEqual(startCursor, start) && isEqual(start, end); -} diff --git a/code/client/src/pwa/inject-config.ts b/code/client/src/pwa/inject-config.ts deleted file mode 100644 index 71cf901b..00000000 --- a/code/client/src/pwa/inject-config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { CustomInjectManifestOptions } from 'vite-plugin-pwa'; - -export const injectConfig: Partial = { - minify: false, - enableWorkboxModulesLogs: true, -}; diff --git a/code/client/src/pwa/manifest-config.ts b/code/client/src/pwa/manifest-config.ts deleted file mode 100644 index 49c43374..00000000 --- a/code/client/src/pwa/manifest-config.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ManifestOptions } from 'vite-plugin-pwa'; - -export const manifestConfig: Partial = { - name: 'NoteSpace', - short_name: 'NoteSpace', - start_url: '/', - scope: '.', - display: 'standalone', - background_color: '#ffffff', - theme_color: '#ffffff', - orientation: 'portrait-primary', - icons: [ - { - src: 'pwa-64x64.png', - sizes: '64x64', - type: 'image/png', - }, - { - src: 'pwa-192x192.png', - sizes: '192x192', - type: 'image/png', - }, - { - src: 'pwa-512x512.png', - sizes: '512x512', - type: 'image/png', - }, - { - src: 'maskable-icon-512x512.png', - sizes: '512x512', - type: 'image/png', - purpose: 'maskable', - }, - ], -}; diff --git a/code/client/src/pwa/pwa-assets.config.ts b/code/client/src/pwa/pwa-assets.config.ts deleted file mode 100644 index 0801d15e..00000000 --- a/code/client/src/pwa/pwa-assets.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig, minimal2023Preset as preset } from '@vite-pwa/assets-generator/config'; - -export default defineConfig({ - headLinkOptions: { - preset: '2023', - }, - preset, - images: ['public/notespace.png'], -}); diff --git a/code/client/src/pwa/pwa-config.ts b/code/client/src/pwa/pwa-config.ts deleted file mode 100644 index 64df15db..00000000 --- a/code/client/src/pwa/pwa-config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { manifestConfig } from '@pwa/manifest-config'; -import { VitePWAOptions } from 'vite-plugin-pwa'; - -export const pwaConfig: Partial = { - mode: 'development', - strategies: 'generateSW', - manifest: manifestConfig, - devOptions: { - enabled: true, - navigateFallback: 'index.html', - type: 'module', - }, -}; diff --git a/code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts b/code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts index b12cfed7..f85d3289 100644 --- a/code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts +++ b/code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts @@ -10,7 +10,7 @@ export type CursorData = { styles: InlineStyle[]; }; -export function useCursors(connector: ServiceConnector) { +function useCursors(connector: ServiceConnector) { const [cursors, setCursors] = useState([]); const onCursorChange = (cursor: CursorData) => { diff --git a/code/client/src/utils/logging.ts b/code/client/src/utils/logging.ts deleted file mode 100644 index b58a05ba..00000000 --- a/code/client/src/utils/logging.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ColorWrap, LogColor } from '@notespace/shared/src/utils/logging'; -import getLogger from '@notespace/shared/src/utils/logging'; - -export const ClientLogCaller = { - React: ColorWrap(LogColor.Blue, 'React'), - Services: ColorWrap(LogColor.Yellow, 'Services'), - Domain: ColorWrap(LogColor.Green, 'Domain'), - PWA: ColorWrap(LogColor.Red, 'PWA'), -}; - -export const DomainLogCaller = getLogger(ClientLogCaller.Domain); -export const ServicesLogCaller = getLogger(ClientLogCaller.Services); -export const ReactLogCaller = getLogger(ClientLogCaller.React); -export const PWALogCaller = getLogger(ClientLogCaller.PWA); diff --git a/code/client/src/utils/utils.ts b/code/client/src/utils/utils.ts index 7580e0ac..b8e70952 100644 --- a/code/client/src/utils/utils.ts +++ b/code/client/src/utils/utils.ts @@ -9,7 +9,7 @@ export function formatDate(isoString: string) { }); } -export function formatTime(time: number, unit: string) { +function formatTime(time: number, unit: string) { return `${time} ${unit}${time === 1 ? '' : 's'} ago`; } diff --git a/code/client/tests/mocks/global-mocks.ts b/code/client/tests/mocks/global-mocks.ts deleted file mode 100644 index 7db00eb0..00000000 --- a/code/client/tests/mocks/global-mocks.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { RequestHandler } from 'msw'; -import { setupServer } from 'msw/node'; -import { beforeAll, afterAll, afterEach } from 'vitest'; - -// This configures a Service Worker with the given request handlers. -export const mockServer = (...handlers: RequestHandler[]) => { - const server = setupServer(...handlers); - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })); - afterAll(() => server.close()); - afterEach(() => server.resetHandlers()); - return server; -}; diff --git a/code/client/tests/mocks/mock-handlers.ts b/code/client/tests/mocks/mock-handlers.ts deleted file mode 100644 index d6d1738d..00000000 --- a/code/client/tests/mocks/mock-handlers.ts +++ /dev/null @@ -1 +0,0 @@ -export default []; diff --git a/code/client/tests/mocks/mock-server.ts b/code/client/tests/mocks/mock-server.ts deleted file mode 100644 index ab15ce3f..00000000 --- a/code/client/tests/mocks/mock-server.ts +++ /dev/null @@ -1,4 +0,0 @@ -import handlers from './mock-handlers'; -import { mockServer } from '@tests/mocks/global-mocks'; - -export const server = mockServer(...handlers); diff --git a/code/client/tests/test-utils.ts b/code/client/tests/test-utils.ts deleted file mode 100644 index 44782336..00000000 --- a/code/client/tests/test-utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -import '@testing-library/jest-dom'; -import { cleanup, render } from '@testing-library/react'; -import { ReactElement } from 'react'; -import { afterEach } from 'vitest'; -import userEvent from '@testing-library/user-event'; - -afterEach(cleanup); - -function setup(ui: ReactElement, options = {}) { - return { - user: userEvent.setup(), - render: customRender(ui, options), - }; -} - -function customRender(ui: ReactElement, options = {}) { - return render(ui, { - wrapper: ({ children }) => children, - ...options, - }); -} - -export * from '@testing-library/react'; -export { setup, customRender as render, userEvent }; diff --git a/code/client/tsconfig.json b/code/client/tsconfig.json index 738c74b3..8115de57 100644 --- a/code/client/tsconfig.json +++ b/code/client/tsconfig.json @@ -2,15 +2,15 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"], + "lib": ["DOM", "DOM.Iterable", "ESNext"], "allowJs": false, - "skipLibCheck": false, + "skipLibCheck": true, "esModuleInterop": false, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "ES2022", - "moduleResolution": "Bundler", + "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, @@ -32,5 +32,5 @@ } }, "include": ["src", "tests"], - "exclude": ["vite.config.ts"] + "exclude": ["node_modules", "vite.config.ts"] } diff --git a/code/client/vite.config.ts b/code/client/vite.config.ts index f1bf17bf..5ffc1750 100644 --- a/code/client/vite.config.ts +++ b/code/client/vite.config.ts @@ -6,6 +6,7 @@ import react from '@vitejs/plugin-react'; import tsconfigPaths from 'vite-tsconfig-paths'; import { config } from 'dotenv'; +// Load environment variables from .env file config(); export default defineConfig({ @@ -13,16 +14,19 @@ export default defineConfig({ server: { port: Number.parseInt(process.env.VITE_PORT) || 5173, }, - plugins: [tsconfigPaths(), react() /*VitePWA(pwaConfig)*/], + plugins: [tsconfigPaths(), react()], build: { - //sourcemap: true, + // Enable sourcemaps if needed + // sourcemap: true, rollupOptions: { output: { manualChunks: (id: string) => { - //if(id.includes('node_modules')) return 'vendor'; + if (id.includes('node_modules')) { + if (id.includes('react')) return 'react'; + if (id.includes('slate')) return 'slate'; + return 'vendor'; + } if (id.includes('src')) return 'app'; - if (id.includes('slate')) return 'slate'; - if (id.includes('react')) return 'react'; }, entryFileNames: 'assets/[name].js', chunkFileNames: 'assets/[name].js', diff --git a/code/server/package.json b/code/server/package.json index 5fc97cad..e3e16bd6 100644 --- a/code/server/package.json +++ b/code/server/package.json @@ -15,9 +15,7 @@ }, "dependencies": { "@notespace/shared": "file:..\\shared", - "@types/cookie": "^0.6.0", "@types/socket.io": "^3.0.2", - "cookie": "^0.6.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.4.5", @@ -26,7 +24,6 @@ "lodash": "^4.17.21", "postgres": "^3.4.4", "socket.io": "^4.7.5", - "supertest": "^6.3.4", "uuid": "^9.0.1" }, "devDependencies": { @@ -35,11 +32,8 @@ "@types/cookie-parser": "^1.4.7", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", - "@types/jest": "^29.5.12", "@types/lodash": "^4.17.1", "@types/node": "^20.14.8", - "@types/pg": "^8.11.6", - "@types/supertest": "^6.0.2", "@types/uuid": "^9.0.8", "@typescript-eslint/eslint-plugin": "^7.8.0", "@typescript-eslint/parser": "^7.8.0", @@ -49,9 +43,6 @@ "jest": "^29.7.0", "knip": "^5.12.3", "prettier": "^3.2.5", - "socket.io-client": "^4.7.5", - "superagent": "^9.0.0", - "test-jest": "^1.0.1", "ts-jest": "^29.1.2", "tsconfig-paths": "^4.2.0", "tsx": "^4.9.3", diff --git a/code/server/src/databases/memory/Memory.ts b/code/server/src/databases/memory/Memory.ts index f8bf5501..8fbcdba5 100644 --- a/code/server/src/databases/memory/Memory.ts +++ b/code/server/src/databases/memory/Memory.ts @@ -1,7 +1,7 @@ import { Resource } from '@notespace/shared/src/workspace/types/resource'; import { User } from '@notespace/shared/src/users/types'; -export interface WorkspaceStorage { +interface WorkspaceStorage { id: string; name: string; isPrivate: boolean; diff --git a/code/server/src/domain/errors/errors.ts b/code/server/src/domain/errors/errors.ts index fac421b1..b4b2e6b4 100644 --- a/code/server/src/domain/errors/errors.ts +++ b/code/server/src/domain/errors/errors.ts @@ -11,4 +11,4 @@ export const NotFoundError = error('NotFoundError'); export const InvalidParameterError = error('InvalidParameterError'); export const UnauthorizedError = error('UnauthorizedError'); export const ForbiddenError = error('ForbiddenError'); -export const ConflictError = error('ConflictError'); +//export const ConflictError = error('ConflictError'); diff --git a/code/server/src/utils/logging.ts b/code/server/src/utils/logging.ts index c7f66caf..acd2d6e8 100644 --- a/code/server/src/utils/logging.ts +++ b/code/server/src/utils/logging.ts @@ -1,7 +1,7 @@ import { ColorWrap, LogColor } from '@notespace/shared/src/utils/logging'; import getLogger from '@notespace/shared/src/utils/logging'; -export const Loggers = { +const Loggers = { Server: ColorWrap(LogColor.Blue, 'Server'), Database: ColorWrap(LogColor.Green, 'Database'), Services: ColorWrap(LogColor.Yellow, 'Services'), @@ -10,9 +10,6 @@ export const Loggers = { }; export const ServerLogger = getLogger(Loggers.Server); -export const DatabaseLogger = (module: string) => getLogger(Loggers.Database + '-' + ColorWrap(LogColor.Green, module)); -export const ServicesLogger = (module: string) => - getLogger(Loggers.Services + '-' + ColorWrap(LogColor.Yellow, module)); export const ControllersLogger = (module: string) => getLogger(Loggers.Controllers + '-' + ColorWrap(LogColor.Red, module)); export const ErrorLogger = getLogger(Loggers.Error);