Skip to content

Commit

Permalink
Merge pull request #11 from nikolovlazar/refactor/fix-di
Browse files Browse the repository at this point in the history
Refactoring to achieve Vercel Edge (and other runtimes)
  • Loading branch information
nikolovlazar authored Oct 30, 2024
2 parents 62162f9 + 82799a3 commit 5ff2421
Show file tree
Hide file tree
Showing 96 changed files with 1,888 additions and 1,867 deletions.
35 changes: 28 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": ["next/core-web-vitals"],
"plugins": ["boundaries"],
"settings": {
"boundaries/include": ["src/**/*", "app/**/*"],
"boundaries/include": ["src/**/*", "app/**/*", "di/**/*"],
"boundaries/elements": [
{
"mode": "full",
Expand All @@ -11,8 +11,8 @@
},
{
"mode": "full",
"type": "interface-adapters",
"pattern": ["src/interface-adapters/**/*"]
"type": "controllers",
"pattern": ["src/interface-adapters/controllers/**/*"]
},
{
"mode": "full",
Expand All @@ -38,6 +38,11 @@
"mode": "full",
"type": "infrastructure",
"pattern": ["src/infrastructure/**/*"]
},
{
"mode": "full",
"type": "di",
"pattern": ["di/**/*"]
}
]
},
Expand All @@ -51,19 +56,24 @@
"rules": [
{
"from": "web",
"allow": ["web", "interface-adapters", "entities"]
"allow": ["web", "entities", "di"]
},
{
"from": "interface-adapters",
"allow": ["use-cases", "entities"]
"from": "controllers",
"allow": [
"entities",
"service-interfaces",
"repository-interfaces",
"use-cases"
]
},
{
"from": "infrastructure",
"allow": ["service-interfaces", "repository-interfaces", "entities"]
},
{
"from": "use-cases",
"allow": ["entities"]
"allow": ["entities", "service-interfaces", "repository-interfaces"]
},
{
"from": "service-interfaces",
Expand All @@ -76,6 +86,17 @@
{
"from": "entities",
"allow": ["entities"]
},
{
"from": "di",
"allow": [
"di",
"controllers",
"service-interfaces",
"repository-interfaces",
"use-cases",
"infrastructure"
]
}
]
}
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"tabWidth": 2,
"arrowParens": "always",
"bracketSpacing": true,
"trailingComma": "es5",
"singleQuote": true,
"proseWrap": "always"
}
265 changes: 200 additions & 65 deletions README.md

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions app/(auth)/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

import { Cookie } from '@/src/entities/models/cookie';
import { signInController } from '@/src/interface-adapters/controllers/auth/sign-in.controller';
import { signUpController } from '@/src/interface-adapters/controllers/auth/sign-up.controller';
import { signOutController } from '@/src/interface-adapters/controllers/auth/sign-out.controller';
import { SESSION_COOKIE } from '@/config';
import { InputParseError } from '@/src/entities/errors/common';
import {
Expand All @@ -27,6 +24,7 @@ export async function signUp(formData: FormData) {

let sessionCookie: Cookie;
try {
const signUpController = getInjection('ISignUpController');
const { cookie } = await signUpController({
username,
password,
Expand All @@ -40,6 +38,11 @@ export async function signUp(formData: FormData) {
'Invalid data. Make sure the Password and Confirm Password match.',
};
}
if (err instanceof AuthenticationError) {
return {
error: err.message,
};
}
const crashReporterService = getInjection('ICrashReporterService');
crashReporterService.report(err);

Expand Down Expand Up @@ -72,6 +75,7 @@ export async function signIn(formData: FormData) {

let sessionCookie: Cookie;
try {
const signInController = getInjection('ISignInController');
sessionCookie = await signInController({ username, password });
} catch (err) {
if (
Expand Down Expand Up @@ -112,6 +116,7 @@ export async function signOut() {

let blankCookie: Cookie;
try {
const signOutController = getInjection('ISignOutController');
blankCookie = await signOutController(sessionId);
} catch (err) {
if (
Expand Down
20 changes: 10 additions & 10 deletions app/(auth)/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"use client";
'use client';

import { useState } from "react";
import { useState } from 'react';

import Link from "next/link";
import { Button } from "../../_components/ui/button";
import Link from 'next/link';
import { Button } from '../../_components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "../../_components/ui/card";
import { Input } from "../../_components/ui/input";
import { Label } from "../../_components/ui/label";
import { Separator } from "../../_components/ui/separator";
import { signIn } from "../actions";
} from '../../_components/ui/card';
import { Input } from '../../_components/ui/input';
import { Label } from '../../_components/ui/label';
import { Separator } from '../../_components/ui/separator';
import { signIn } from '../actions';

export default function SignIn() {
const [error, setError] = useState<string>();
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function SignIn() {
</Button>
</div>
<div className="mt-4 text-center text-sm">
Don&apos;t have an account?{" "}
Don&apos;t have an account?{' '}
<Link href="/sign-up" className="underline">
Sign up
</Link>
Expand Down
26 changes: 13 additions & 13 deletions app/(auth)/sign-up/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"use client";
'use client';

import Link from "next/link";
import { useState } from "react";
import Link from 'next/link';
import { useState } from 'react';

import { Button } from "../../_components/ui/button";
import { Button } from '../../_components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "../../_components/ui/card";
import { Input } from "../../_components/ui/input";
import { Label } from "../../_components/ui/label";
import { Separator } from "../../_components/ui/separator";
import { signUp } from "../actions";
} from '../../_components/ui/card';
import { Input } from '../../_components/ui/input';
import { Label } from '../../_components/ui/label';
import { Separator } from '../../_components/ui/separator';
import { signUp } from '../actions';

export default function SignUp() {
const [error, setError] = useState<string>();
Expand All @@ -24,11 +24,11 @@ export default function SignUp() {

const formData = new FormData(event.currentTarget);

const password = formData.get("password")!.toString();
const confirmPassword = formData.get("confirm_password")!.toString();
const password = formData.get('password')!.toString();
const confirmPassword = formData.get('confirm_password')!.toString();

if (password !== confirmPassword) {
setError("Passwords must match");
setError('Passwords must match');
return;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ export default function SignUp() {
</Button>
</div>
<div className="mt-4 text-center text-sm">
Already have an account?{" "}
Already have an account?{' '}
<Link href="/sign-in" className="underline">
Sign in
</Link>
Expand Down
8 changes: 4 additions & 4 deletions app/_components/theme-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";
'use client';

import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { type ThemeProviderProps } from "next-themes/dist/types";
import * as React from 'react';
import { ThemeProvider as NextThemesProvider } from 'next-themes';
import { type ThemeProviderProps } from 'next-themes/dist/types';

export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
Expand Down
28 changes: 14 additions & 14 deletions app/_components/ui/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client"
'use client';

import * as React from "react"
import * as AvatarPrimitive from "@radix-ui/react-avatar"
import * as React from 'react';
import * as AvatarPrimitive from '@radix-ui/react-avatar';

import { cn } from "@/app/_components/utils"
import { cn } from '@/app/_components/utils';

const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
Expand All @@ -12,25 +12,25 @@ const Avatar = React.forwardRef<
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
'relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full',
className
)}
{...props}
/>
))
Avatar.displayName = AvatarPrimitive.Root.displayName
));
Avatar.displayName = AvatarPrimitive.Root.displayName;

const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full", className)}
className={cn('aspect-square h-full w-full', className)}
{...props}
/>
))
AvatarImage.displayName = AvatarPrimitive.Image.displayName
));
AvatarImage.displayName = AvatarPrimitive.Image.displayName;

const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
Expand All @@ -39,12 +39,12 @@ const AvatarFallback = React.forwardRef<
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
'flex h-full w-full items-center justify-center rounded-full bg-muted',
className
)}
{...props}
/>
))
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
));
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;

export { Avatar, AvatarImage, AvatarFallback }
export { Avatar, AvatarImage, AvatarFallback };
42 changes: 21 additions & 21 deletions app/_components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from "@/app/_components/utils";
import { cn } from '@/app/_components/utils';

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'text-primary underline-offset-4 hover:underline',
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
},
},
defaultVariants: {
variant: "default",
size: "default",
variant: 'default',
size: 'default',
},
},
}
);

export interface ButtonProps
Expand All @@ -41,16 +41,16 @@ export interface ButtonProps

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
const Comp = asChild ? Slot : 'button';
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
},
}
);
Button.displayName = "Button";
Button.displayName = 'Button';

export { Button, buttonVariants };
Loading

0 comments on commit 5ff2421

Please sign in to comment.