style: Обновлены правила код стайла

This commit is contained in:
2026-05-08 08:21:34 +03:00
parent 7c0f597840
commit fec5ca78d0
32 changed files with 688 additions and 557 deletions

View File

@@ -15,13 +15,13 @@ Business-композиция используется, когда просто
- Нужно преобразовать DTO в доменную модель.
- Нужно спрятать бизнес-сценарий за доменным API.
Такая логика не пишется в `infrastructure/`. REST-клиент остаётся прозрачным адаптером к API.
Такая логика не пишется в `infra/`. REST-клиент остаётся прозрачным адаптером к API.
## Пример поверх одного GET-хука
```ts
// src/business/pets/hooks/use-available-pets.hook.ts
import { useGetPetList } from 'infrastructure/pet-store-api'
import { useGetPetList } from 'infra/pet-store-api'
/**
* Доменный список доступных питомцев.
@@ -36,13 +36,13 @@ export const useAvailablePets = () => {
}
```
`useGetPetList` — infrastructure-хук. `hasPets` — бизнес-интерпретация, поэтому она появляется в `business/pets`.
`useGetPetList` — infra-хук. `hasPets` — бизнес-интерпретация, поэтому она появляется в `business/pets`.
## Пример композиции нескольких GET-хуков
```ts
// src/business/pets/hooks/use-pets-dashboard.hook.ts
import { useGetPetList } from 'infrastructure/pet-store-api'
import { useGetPetList } from 'infra/pet-store-api'
/**
* Данные dashboard по питомцам.
@@ -64,13 +64,13 @@ export const usePetsDashboard = () => {
}
```
Композиция нескольких запросов не добавляется в `infrastructure/pet-store-api/hooks/`, потому что это уже сценарий потребления данных.
Композиция нескольких запросов не добавляется в `infra/pet-store-api/hooks/`, потому что это уже сценарий потребления данных.
## Пример auth-состояния
```ts
// src/business/auth/hooks/use-auth-state.hook.ts
import { useGetCurrentUser } from 'infrastructure/backend-api'
import { useGetCurrentUser } from 'infra/backend-api'
/**
* Состояние авторизации текущего пользователя.
@@ -107,7 +107,7 @@ src/business/
## Что запрещено
```ts
// Плохо — business-смысл внутри infrastructure-хука
// Плохо — business-смысл внутри infra-хука
export const useGetPetList = (status: PetStatus) => {
const query = useSWR(...)

View File

@@ -21,8 +21,8 @@ keywords: [rest, client components, swr, get-хук, client state]
'use client'
import { useState } from 'react'
import { useGetPetList } from 'infrastructure/pet-store-api'
import type { PetStatus } from 'infrastructure/pet-store-api'
import { useGetPetList } from 'infra/pet-store-api'
import type { PetStatus } from 'infra/pet-store-api'
const statuses: PetStatus[] = ['available', 'pending', 'sold']
@@ -60,7 +60,7 @@ export function PetTabs() {
Хук добавляется в REST-модуль сервиса:
```text
src/infrastructure/pet-store-api/hooks/use-get-pet-list.hook.ts
src/infra/pet-store-api/hooks/use-get-pet-list.hook.ts
```
Не создавайте локальный `useSWR` в компоненте.

View File

@@ -30,7 +30,7 @@ keywords: [rest, swr, fallback, initial data, client hooks, unstable_serialize,
## Ключ хука
```ts
// src/infrastructure/pet-store-api/hooks/use-get-pet-list.hook.ts
// src/infra/pet-store-api/hooks/use-get-pet-list.hook.ts
export const getPetListKey = (status: PetStatus) =>
['pet-store-api', 'pet', 'list', status] as const
```
@@ -46,7 +46,7 @@ import { SWRConfig, unstable_serialize } from 'swr'
import {
getPetListKey,
petStoreApi,
} from 'infrastructure/pet-store-api'
} from 'infra/pet-store-api'
type PetsLayoutProps = {
children: ReactNode
@@ -78,7 +78,7 @@ export default async function PetsLayout({ children }: PetsLayoutProps) {
```tsx
'use client'
import { useGetPetList } from 'infrastructure/pet-store-api'
import { useGetPetList } from 'infra/pet-store-api'
export function PetList() {
const { data: pets, isLoading } = useGetPetList('available')

View File

@@ -17,7 +17,7 @@ keywords: [rest, promise.all, параллельные запросы, server co
## Хорошо
```tsx
import { petStoreApi } from 'infrastructure/pet-store-api'
import { petStoreApi } from 'infra/pet-store-api'
import { PetsDashboardScreen } from 'screens/pets-dashboard'
export default async function PetsDashboardPage() {

View File

@@ -19,10 +19,10 @@ keywords: [rest, promise, suspense, streaming, server components]
```tsx
// src/app/(routes)/pets/page.tsx
import { Suspense } from 'react'
import { petStoreApi } from 'infrastructure/pet-store-api'
import { petStoreApi } from 'infra/pet-store-api'
import { PetListSection } from 'widgets/pet-list-section'
import { PetListSkeleton } from 'widgets/pet-list-section'
import type { Pet } from 'infrastructure/pet-store-api'
import type { Pet } from 'infra/pet-store-api'
export default function PetsPage() {
const petsPromise = petStoreApi.pet.findPetsByStatus({ status: 'available' })

View File

@@ -29,7 +29,7 @@ SSR/dynamic rendering нужен, когда данные зависят от т
```tsx
// src/app/(routes)/pets/page.tsx
import { petStoreApi } from 'infrastructure/pet-store-api'
import { petStoreApi } from 'infra/pet-store-api'
import { PetsScreen } from 'screens/pets'
export default async function PetsPage() {
@@ -48,7 +48,7 @@ export default async function PetsPage() {
```tsx
// src/app/(routes)/pets/[id]/page.tsx
import { notFound } from 'next/navigation'
import { petStoreApi } from 'infrastructure/pet-store-api'
import { petStoreApi } from 'infra/pet-store-api'
import { PetDetailScreen } from 'screens/pet-detail'
type PetPageProps = {