All Systems Operational
Powered By
profound-logo
profound-logoProfound CMS
⌘K
Admin

빠른 시작

스키마에 대한 게시물

Continue Reading
NextJSON과 Claude 코드›

타입 안전한 Zod 스키마 생성

이 기능을 사용하면 스키마 설명을 타입 안전한 Zod 스키마 형태로 받아 다음과 같은 이점을 제공합니다:

  • TypeScript 우선 스키마 검증
  • 정적 타입 추론

자세히 알아보기: https://zod.dev

설정

Zod 스키마를 가져오려면 다음을 수행합니다:

  1. 필요한 종속성을 로드합니다
  2. cms-renderer의 유틸리티를 사용해 스크립트를 생성합니다

프로젝트 구조

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts   # 스크립트 파일

스크립트: generated-schema.ts

import { fetchAllCustomSchemaFields, saveZodSchemaCode } from 'cms-renderer/lib/custom-schemas';
import { cmsConfig } from '../lib/cms-config';

async function main() {
  const { cmsUrl, websiteId } = cmsConfig;

  if (!cmsUrl) {
    throw new Error(
      '[generate-schemas] NEXT_PUBLIC_CMS_API_URL is not set. Set it in your environment or .env file.'
    );
  }

  if (!websiteId) {
    throw new Error(
      '[generate-schemas] CMS_WEBSITE_ID is not set. Set it in your environment or .env file.'
    );
  }

  await saveZodSchemaCode(
    await fetchAllCustomSchemaFields(cmsConfig),
    './generated/cms-schemas.ts'
  );

  console.log('[generate-schemas] Done.');
}

main().catch((err) => {
  console.error('[generate-schemas] Failed:', err);
  process.exit(1);
});

CMS 구성 예시

export const cmsConfig = {
  cmsUrl: process.env.NEXT_PUBLIC_CMS_API_URL,
  apiKey: process.env.CMS_API_KEY,
  websiteId: '...',
};

package.json 구성

참고: tsconfig.json이 없다면 --tsconfig 플래그를 제거하세요.

{
  "name": "web",
  "version": "0.1.0",
  "type": "module",
  "private": true,
  "scripts": {
    "generate-schemas": "tsx --tsconfig tsconfig.json scripts/generate-schemas.ts",
    "...": "..."
  },
  "dependencies": {

스크립트 실행

bun run generate-schemas

예시 출력:

tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] Done.

업데이트된 프로젝트 구조

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts
    generated/
      cms-schemas.ts   # 생성된 Zod 스키마

page.tsx에서 사용

import type { PetFoodPost, SiteConfig } from '@/generated/cms-schemas';
import { petFoodPostSchema } from '@/generated/cms-schemas';

// 타입 안전한 파싱에 사용
petFoodPostSchema.parse(obj);

참고 사항

  • 스키마 구조를 이해하기 위해 생성된 파일을 확인하세요
  • 스키마가 변경될 때마다 스크립트를 다시 실행하세요:
bun run generate-schemas
  • 이를 개발 또는 빌드 워크플로에 통합할 수 있습니다
  • 관리자 패널을 통해 스키마를 업데이트한 다음, 로컬에서 다시 생성하세요
"cms-renderer"
:
"0.3.1"
,
"zod": "^4.3.6",
"...": "..."
},
"devDependencies": {
"tsx": "^4.21.0",
"object-hash": "^3.0.0",
"...": "..."
}
}

하이브리드

렌더러 프로젝트매개변수 라우팅컴포넌트 유형Sse관리자 패널 프록시 설정편집 모드 지원이 있는 정적 렌더링템플릿 빌더에서 스크립팅Create Profound Next

헤드리스

빠른 시작JSON과 Claude 코드Component Zod Pull

Mcp

Mcp

CMS 기능

기능 문서 템플릿템플릿 빌더 기능기능 번역기기능 조직

동기부여

우리의 접근법

용어

하이브리드 대 헤드리스