@mandujs/core 0.12.2 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +304 -304
- package/package.json +1 -1
- package/src/brain/architecture/analyzer.ts +28 -26
- package/src/brain/doctor/analyzer.ts +1 -1
- package/src/bundler/dev.ts +0 -1
- package/src/change/history.ts +3 -3
- package/src/change/snapshot.ts +10 -9
- package/src/change/transaction.ts +2 -2
- package/src/config/mandu.ts +103 -96
- package/src/config/validate.ts +225 -215
- package/src/error/classifier.ts +2 -2
- package/src/error/formatter.ts +32 -32
- package/src/error/stack-analyzer.ts +5 -0
- package/src/filling/context.ts +592 -569
- package/src/filling/index.ts +2 -0
- package/src/filling/sse.test.ts +168 -0
- package/src/filling/sse.ts +162 -0
- package/src/generator/contract-glue.ts +2 -1
- package/src/generator/generate.ts +12 -10
- package/src/generator/templates.ts +80 -79
- package/src/guard/auto-correct.ts +1 -1
- package/src/guard/check.ts +128 -128
- package/src/guard/presets/cqrs.test.ts +35 -14
- package/src/index.ts +7 -1
- package/src/paths.test.ts +47 -0
- package/src/paths.ts +47 -0
- package/src/report/build.ts +1 -1
- package/src/router/fs-routes.ts +344 -401
- package/src/router/fs-types.ts +270 -278
- package/src/router/index.ts +81 -81
- package/src/runtime/escape.ts +44 -0
- package/src/runtime/server.ts +281 -24
- package/src/runtime/ssr.ts +362 -367
- package/src/runtime/streaming-ssr.ts +1236 -1245
- package/src/watcher/rules.ts +5 -5
package/README.ko.md
CHANGED
|
@@ -1,304 +1,304 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/konamgil/mandu/main/mandu_only_simbol.png" alt="Mandu" width="200" />
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
<h1 align="center">@mandujs/core</h1>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<strong>Mandu Framework Core</strong><br/>
|
|
9
|
-
Spec, Generator, Guard, Runtime, Filling
|
|
10
|
-
</p>
|
|
11
|
-
|
|
12
|
-
<p align="center">
|
|
13
|
-
<a href="./README.md"><strong>English</strong></a> | 한국어
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
## 설치
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
bun add @mandujs/core
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
> 일반적으로 `@mandujs/cli`를 통해 사용합니다. 직접 사용은 고급 사용 사례입니다.
|
|
23
|
-
|
|
24
|
-
## 모듈 구조
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
@mandujs/core
|
|
28
|
-
├── router/ # 파일 시스템 기반 라우팅
|
|
29
|
-
├── guard/ # 아키텍처 검사 및 자동 수정
|
|
30
|
-
├── runtime/ # 서버, SSR, 스트리밍
|
|
31
|
-
├── filling/ # 핸들러 체인 API
|
|
32
|
-
├── contract/ # 타입 안전 API 계약
|
|
33
|
-
├── content/ # Content Layer - 빌드 타임 콘텐츠 로딩 🆕
|
|
34
|
-
├── bundler/ # 클라이언트 번들링, HMR
|
|
35
|
-
├── client/ # Island 하이드레이션, 클라이언트 라우터
|
|
36
|
-
├── brain/ # Doctor, Watcher, 아키텍처 분석
|
|
37
|
-
└── change/ # 트랜잭션 & 히스토리
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Spec 모듈
|
|
41
|
-
|
|
42
|
-
라우트 manifest 스키마 정의 및 로딩.
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { loadManifest, RoutesManifest, RouteSpec } from "@mandujs/core";
|
|
46
|
-
|
|
47
|
-
// manifest 로드 및 검증
|
|
48
|
-
const result = await loadManifest("
|
|
49
|
-
|
|
50
|
-
if (result.success && result.data) {
|
|
51
|
-
const manifest: RoutesManifest = result.data;
|
|
52
|
-
manifest.routes.forEach((route: RouteSpec) => {
|
|
53
|
-
console.log(route.id, route.pattern, route.kind);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Lock 파일
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { writeLock, readLock } from "@mandujs/core";
|
|
62
|
-
|
|
63
|
-
// lock 파일 쓰기
|
|
64
|
-
const lock = await writeLock("
|
|
65
|
-
console.log(lock.routesHash);
|
|
66
|
-
|
|
67
|
-
// lock 파일 읽기
|
|
68
|
-
const existing = await readLock("
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Generator 모듈
|
|
72
|
-
|
|
73
|
-
Spec 기반 코드 생성.
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
import { generateRoutes, GenerateResult } from "@mandujs/core";
|
|
77
|
-
|
|
78
|
-
const result: GenerateResult = await generateRoutes(manifest, "./");
|
|
79
|
-
|
|
80
|
-
console.log("생성됨:", result.created);
|
|
81
|
-
console.log("건너뜀:", result.skipped); // 이미 존재하는 slot 파일
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 템플릿 함수
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import {
|
|
88
|
-
generateApiHandler,
|
|
89
|
-
generateApiHandlerWithSlot,
|
|
90
|
-
generateSlotLogic,
|
|
91
|
-
generatePageComponent
|
|
92
|
-
} from "@mandujs/core";
|
|
93
|
-
|
|
94
|
-
// API 핸들러 생성
|
|
95
|
-
const code = generateApiHandler(route);
|
|
96
|
-
|
|
97
|
-
// Slot이 있는 API 핸들러
|
|
98
|
-
const codeWithSlot = generateApiHandlerWithSlot(route);
|
|
99
|
-
|
|
100
|
-
// Slot 로직 파일
|
|
101
|
-
const slotCode = generateSlotLogic(route);
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Guard 모듈
|
|
105
|
-
|
|
106
|
-
아키텍처 규칙 검사 및 자동 수정.
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
import {
|
|
110
|
-
runGuardCheck,
|
|
111
|
-
runAutoCorrect,
|
|
112
|
-
GuardResult,
|
|
113
|
-
GuardViolation
|
|
114
|
-
} from "@mandujs/core";
|
|
115
|
-
|
|
116
|
-
// 검사 실행
|
|
117
|
-
const result: GuardResult = await runGuardCheck(manifest, "./");
|
|
118
|
-
|
|
119
|
-
if (!result.passed) {
|
|
120
|
-
result.violations.forEach((v: GuardViolation) => {
|
|
121
|
-
console.log(`${v.rule}: ${v.message}`);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// 자동 수정 실행
|
|
125
|
-
const corrected = await runAutoCorrect(result.violations, manifest, "./");
|
|
126
|
-
console.log("수정됨:", corrected.steps);
|
|
127
|
-
console.log("남은 위반:", corrected.remainingViolations);
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### Guard 규칙
|
|
132
|
-
|
|
133
|
-
| 규칙 ID | 설명 | 자동 수정 |
|
|
134
|
-
|---------|------|----------|
|
|
135
|
-
| `SPEC_HASH_MISMATCH` | spec과 lock 해시 불일치 | ✅ |
|
|
136
|
-
| `GENERATED_MANUAL_EDIT` | generated 파일 수동 수정 | ✅ |
|
|
137
|
-
| `HANDLER_NOT_FOUND` | 핸들러 파일 없음 | ❌ |
|
|
138
|
-
| `COMPONENT_NOT_FOUND` | 컴포넌트 파일 없음 | ❌ |
|
|
139
|
-
| `SLOT_NOT_FOUND` | slot 파일 없음 | ✅ |
|
|
140
|
-
|
|
141
|
-
## Content Layer 🆕
|
|
142
|
-
|
|
143
|
-
Astro에서 영감받은 빌드 타임 콘텐츠 로딩 시스템.
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
// content.config.ts
|
|
147
|
-
import { defineContentConfig, glob, file, api } from "@mandujs/core/content";
|
|
148
|
-
import { z } from "zod";
|
|
149
|
-
|
|
150
|
-
const postSchema = z.object({
|
|
151
|
-
title: z.string(),
|
|
152
|
-
date: z.coerce.date(),
|
|
153
|
-
tags: z.array(z.string()).default([]),
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
export default defineContentConfig({
|
|
157
|
-
collections: {
|
|
158
|
-
// Markdown 파일 (프론트매터 지원)
|
|
159
|
-
posts: {
|
|
160
|
-
loader: glob({ pattern: "content/posts/**/*.md" }),
|
|
161
|
-
schema: postSchema,
|
|
162
|
-
},
|
|
163
|
-
// 단일 JSON/YAML 파일
|
|
164
|
-
settings: {
|
|
165
|
-
loader: file({ path: "data/settings.json" }),
|
|
166
|
-
},
|
|
167
|
-
// 외부 API
|
|
168
|
-
products: {
|
|
169
|
-
loader: api({
|
|
170
|
-
url: "https://api.example.com/products",
|
|
171
|
-
cacheTTL: 3600,
|
|
172
|
-
}),
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### 콘텐츠 조회
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
import { getCollection, getEntry } from "@mandujs/core/content";
|
|
182
|
-
|
|
183
|
-
// 전체 컬렉션 조회
|
|
184
|
-
const posts = await getCollection("posts");
|
|
185
|
-
|
|
186
|
-
// 단일 엔트리 조회
|
|
187
|
-
const post = await getEntry("posts", "hello-world");
|
|
188
|
-
console.log(post?.data.title, post?.body);
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### 내장 로더
|
|
192
|
-
|
|
193
|
-
| 로더 | 설명 | 예시 |
|
|
194
|
-
|------|------|------|
|
|
195
|
-
| `file()` | 단일 파일 (JSON, YAML, TOML) | `file({ path: "data/config.json" })` |
|
|
196
|
-
| `glob()` | 패턴 매칭 (Markdown, JSON) | `glob({ pattern: "content/**/*.md" })` |
|
|
197
|
-
| `api()` | HTTP API (캐싱 지원) | `api({ url: "https://...", cacheTTL: 3600 })` |
|
|
198
|
-
|
|
199
|
-
### 주요 기능
|
|
200
|
-
|
|
201
|
-
- **Digest 기반 캐싱**: 변경된 파일만 재파싱
|
|
202
|
-
- **Zod 검증**: 스키마 기반 타입 안전 콘텐츠
|
|
203
|
-
- **프론트매터 지원**: Markdown YAML 프론트매터
|
|
204
|
-
- **Dev 모드 감시**: 콘텐츠 변경 시 자동 리로드
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
## Contract 모듈
|
|
209
|
-
|
|
210
|
-
Zod 기반 계약(Contract) 정의 및 타입 안전 클라이언트 생성.
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
import { Mandu } from "@mandujs/core";
|
|
214
|
-
import { z } from "zod";
|
|
215
|
-
|
|
216
|
-
const userContract = Mandu.contract({
|
|
217
|
-
request: {
|
|
218
|
-
GET: { query: z.object({ id: z.string() }) },
|
|
219
|
-
POST: { body: z.object({ name: z.string() }) },
|
|
220
|
-
},
|
|
221
|
-
response: {
|
|
222
|
-
200: z.object({ data: z.any() }),
|
|
223
|
-
400: z.object({ error: z.string() }),
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// 클라이언트에 노출할 스키마만 선택
|
|
228
|
-
const clientContract = Mandu.clientContract(userContract, {
|
|
229
|
-
request: { POST: { body: true } },
|
|
230
|
-
response: [200],
|
|
231
|
-
includeErrors: true,
|
|
232
|
-
});
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## Runtime 모듈
|
|
236
|
-
|
|
237
|
-
서버 시작 및 라우팅.
|
|
238
|
-
|
|
239
|
-
```typescript
|
|
240
|
-
import {
|
|
241
|
-
startServer,
|
|
242
|
-
registerApiHandler,
|
|
243
|
-
registerPageLoader
|
|
244
|
-
} from "@mandujs/core";
|
|
245
|
-
|
|
246
|
-
// API 핸들러 등록
|
|
247
|
-
registerApiHandler("getUsers", async (req) => {
|
|
248
|
-
return { users: [] };
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// 페이지 로더 등록
|
|
252
|
-
registerPageLoader("homePage", () => import("./pages/Home"));
|
|
253
|
-
|
|
254
|
-
// 서버 시작
|
|
255
|
-
const server = startServer(manifest, { port: 3000 });
|
|
256
|
-
|
|
257
|
-
// 종료
|
|
258
|
-
server.stop();
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Report 모듈
|
|
262
|
-
|
|
263
|
-
Guard 결과 리포트 생성.
|
|
264
|
-
|
|
265
|
-
```typescript
|
|
266
|
-
import { buildGuardReport } from "@mandujs/core";
|
|
267
|
-
|
|
268
|
-
const report = buildGuardReport(guardResult, lockPath);
|
|
269
|
-
console.log(report); // 포맷된 텍스트 리포트
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## 타입
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
import type {
|
|
276
|
-
RoutesManifest,
|
|
277
|
-
RouteSpec,
|
|
278
|
-
RouteKind,
|
|
279
|
-
SpecLock,
|
|
280
|
-
GuardResult,
|
|
281
|
-
GuardViolation,
|
|
282
|
-
GenerateResult,
|
|
283
|
-
AutoCorrectResult,
|
|
284
|
-
// Content Layer
|
|
285
|
-
DataEntry,
|
|
286
|
-
ContentConfig,
|
|
287
|
-
CollectionConfig,
|
|
288
|
-
Loader,
|
|
289
|
-
} from "@mandujs/core";
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
## 요구 사항
|
|
293
|
-
|
|
294
|
-
- Bun >= 1.0.0
|
|
295
|
-
- React >= 19.0.0
|
|
296
|
-
- Zod >= 3.0.0
|
|
297
|
-
|
|
298
|
-
## 관련 패키지
|
|
299
|
-
|
|
300
|
-
- [@mandujs/cli](https://www.npmjs.com/package/@mandujs/cli) - CLI 도구
|
|
301
|
-
|
|
302
|
-
## 라이선스
|
|
303
|
-
|
|
304
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/konamgil/mandu/main/mandu_only_simbol.png" alt="Mandu" width="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">@mandujs/core</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Mandu Framework Core</strong><br/>
|
|
9
|
+
Spec, Generator, Guard, Runtime, Filling
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="./README.md"><strong>English</strong></a> | 한국어
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
## 설치
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun add @mandujs/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> 일반적으로 `@mandujs/cli`를 통해 사용합니다. 직접 사용은 고급 사용 사례입니다.
|
|
23
|
+
|
|
24
|
+
## 모듈 구조
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
@mandujs/core
|
|
28
|
+
├── router/ # 파일 시스템 기반 라우팅
|
|
29
|
+
├── guard/ # 아키텍처 검사 및 자동 수정
|
|
30
|
+
├── runtime/ # 서버, SSR, 스트리밍
|
|
31
|
+
├── filling/ # 핸들러 체인 API
|
|
32
|
+
├── contract/ # 타입 안전 API 계약
|
|
33
|
+
├── content/ # Content Layer - 빌드 타임 콘텐츠 로딩 🆕
|
|
34
|
+
├── bundler/ # 클라이언트 번들링, HMR
|
|
35
|
+
├── client/ # Island 하이드레이션, 클라이언트 라우터
|
|
36
|
+
├── brain/ # Doctor, Watcher, 아키텍처 분석
|
|
37
|
+
└── change/ # 트랜잭션 & 히스토리
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Spec 모듈
|
|
41
|
+
|
|
42
|
+
라우트 manifest 스키마 정의 및 로딩.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { loadManifest, RoutesManifest, RouteSpec } from "@mandujs/core";
|
|
46
|
+
|
|
47
|
+
// manifest 로드 및 검증
|
|
48
|
+
const result = await loadManifest(".mandu/routes.manifest.json");
|
|
49
|
+
|
|
50
|
+
if (result.success && result.data) {
|
|
51
|
+
const manifest: RoutesManifest = result.data;
|
|
52
|
+
manifest.routes.forEach((route: RouteSpec) => {
|
|
53
|
+
console.log(route.id, route.pattern, route.kind);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Lock 파일
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { writeLock, readLock } from "@mandujs/core";
|
|
62
|
+
|
|
63
|
+
// lock 파일 쓰기
|
|
64
|
+
const lock = await writeLock(".mandu/spec.lock.json", manifest);
|
|
65
|
+
console.log(lock.routesHash);
|
|
66
|
+
|
|
67
|
+
// lock 파일 읽기
|
|
68
|
+
const existing = await readLock(".mandu/spec.lock.json");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Generator 모듈
|
|
72
|
+
|
|
73
|
+
Spec 기반 코드 생성.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { generateRoutes, GenerateResult } from "@mandujs/core";
|
|
77
|
+
|
|
78
|
+
const result: GenerateResult = await generateRoutes(manifest, "./");
|
|
79
|
+
|
|
80
|
+
console.log("생성됨:", result.created);
|
|
81
|
+
console.log("건너뜀:", result.skipped); // 이미 존재하는 slot 파일
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 템플릿 함수
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import {
|
|
88
|
+
generateApiHandler,
|
|
89
|
+
generateApiHandlerWithSlot,
|
|
90
|
+
generateSlotLogic,
|
|
91
|
+
generatePageComponent
|
|
92
|
+
} from "@mandujs/core";
|
|
93
|
+
|
|
94
|
+
// API 핸들러 생성
|
|
95
|
+
const code = generateApiHandler(route);
|
|
96
|
+
|
|
97
|
+
// Slot이 있는 API 핸들러
|
|
98
|
+
const codeWithSlot = generateApiHandlerWithSlot(route);
|
|
99
|
+
|
|
100
|
+
// Slot 로직 파일
|
|
101
|
+
const slotCode = generateSlotLogic(route);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Guard 모듈
|
|
105
|
+
|
|
106
|
+
아키텍처 규칙 검사 및 자동 수정.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import {
|
|
110
|
+
runGuardCheck,
|
|
111
|
+
runAutoCorrect,
|
|
112
|
+
GuardResult,
|
|
113
|
+
GuardViolation
|
|
114
|
+
} from "@mandujs/core";
|
|
115
|
+
|
|
116
|
+
// 검사 실행
|
|
117
|
+
const result: GuardResult = await runGuardCheck(manifest, "./");
|
|
118
|
+
|
|
119
|
+
if (!result.passed) {
|
|
120
|
+
result.violations.forEach((v: GuardViolation) => {
|
|
121
|
+
console.log(`${v.rule}: ${v.message}`);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// 자동 수정 실행
|
|
125
|
+
const corrected = await runAutoCorrect(result.violations, manifest, "./");
|
|
126
|
+
console.log("수정됨:", corrected.steps);
|
|
127
|
+
console.log("남은 위반:", corrected.remainingViolations);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Guard 규칙
|
|
132
|
+
|
|
133
|
+
| 규칙 ID | 설명 | 자동 수정 |
|
|
134
|
+
|---------|------|----------|
|
|
135
|
+
| `SPEC_HASH_MISMATCH` | spec과 lock 해시 불일치 | ✅ |
|
|
136
|
+
| `GENERATED_MANUAL_EDIT` | generated 파일 수동 수정 | ✅ |
|
|
137
|
+
| `HANDLER_NOT_FOUND` | 핸들러 파일 없음 | ❌ |
|
|
138
|
+
| `COMPONENT_NOT_FOUND` | 컴포넌트 파일 없음 | ❌ |
|
|
139
|
+
| `SLOT_NOT_FOUND` | slot 파일 없음 | ✅ |
|
|
140
|
+
|
|
141
|
+
## Content Layer 🆕
|
|
142
|
+
|
|
143
|
+
Astro에서 영감받은 빌드 타임 콘텐츠 로딩 시스템.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// content.config.ts
|
|
147
|
+
import { defineContentConfig, glob, file, api } from "@mandujs/core/content";
|
|
148
|
+
import { z } from "zod";
|
|
149
|
+
|
|
150
|
+
const postSchema = z.object({
|
|
151
|
+
title: z.string(),
|
|
152
|
+
date: z.coerce.date(),
|
|
153
|
+
tags: z.array(z.string()).default([]),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export default defineContentConfig({
|
|
157
|
+
collections: {
|
|
158
|
+
// Markdown 파일 (프론트매터 지원)
|
|
159
|
+
posts: {
|
|
160
|
+
loader: glob({ pattern: "content/posts/**/*.md" }),
|
|
161
|
+
schema: postSchema,
|
|
162
|
+
},
|
|
163
|
+
// 단일 JSON/YAML 파일
|
|
164
|
+
settings: {
|
|
165
|
+
loader: file({ path: "data/settings.json" }),
|
|
166
|
+
},
|
|
167
|
+
// 외부 API
|
|
168
|
+
products: {
|
|
169
|
+
loader: api({
|
|
170
|
+
url: "https://api.example.com/products",
|
|
171
|
+
cacheTTL: 3600,
|
|
172
|
+
}),
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 콘텐츠 조회
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { getCollection, getEntry } from "@mandujs/core/content";
|
|
182
|
+
|
|
183
|
+
// 전체 컬렉션 조회
|
|
184
|
+
const posts = await getCollection("posts");
|
|
185
|
+
|
|
186
|
+
// 단일 엔트리 조회
|
|
187
|
+
const post = await getEntry("posts", "hello-world");
|
|
188
|
+
console.log(post?.data.title, post?.body);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 내장 로더
|
|
192
|
+
|
|
193
|
+
| 로더 | 설명 | 예시 |
|
|
194
|
+
|------|------|------|
|
|
195
|
+
| `file()` | 단일 파일 (JSON, YAML, TOML) | `file({ path: "data/config.json" })` |
|
|
196
|
+
| `glob()` | 패턴 매칭 (Markdown, JSON) | `glob({ pattern: "content/**/*.md" })` |
|
|
197
|
+
| `api()` | HTTP API (캐싱 지원) | `api({ url: "https://...", cacheTTL: 3600 })` |
|
|
198
|
+
|
|
199
|
+
### 주요 기능
|
|
200
|
+
|
|
201
|
+
- **Digest 기반 캐싱**: 변경된 파일만 재파싱
|
|
202
|
+
- **Zod 검증**: 스키마 기반 타입 안전 콘텐츠
|
|
203
|
+
- **프론트매터 지원**: Markdown YAML 프론트매터
|
|
204
|
+
- **Dev 모드 감시**: 콘텐츠 변경 시 자동 리로드
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Contract 모듈
|
|
209
|
+
|
|
210
|
+
Zod 기반 계약(Contract) 정의 및 타입 안전 클라이언트 생성.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { Mandu } from "@mandujs/core";
|
|
214
|
+
import { z } from "zod";
|
|
215
|
+
|
|
216
|
+
const userContract = Mandu.contract({
|
|
217
|
+
request: {
|
|
218
|
+
GET: { query: z.object({ id: z.string() }) },
|
|
219
|
+
POST: { body: z.object({ name: z.string() }) },
|
|
220
|
+
},
|
|
221
|
+
response: {
|
|
222
|
+
200: z.object({ data: z.any() }),
|
|
223
|
+
400: z.object({ error: z.string() }),
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// 클라이언트에 노출할 스키마만 선택
|
|
228
|
+
const clientContract = Mandu.clientContract(userContract, {
|
|
229
|
+
request: { POST: { body: true } },
|
|
230
|
+
response: [200],
|
|
231
|
+
includeErrors: true,
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Runtime 모듈
|
|
236
|
+
|
|
237
|
+
서버 시작 및 라우팅.
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import {
|
|
241
|
+
startServer,
|
|
242
|
+
registerApiHandler,
|
|
243
|
+
registerPageLoader
|
|
244
|
+
} from "@mandujs/core";
|
|
245
|
+
|
|
246
|
+
// API 핸들러 등록
|
|
247
|
+
registerApiHandler("getUsers", async (req) => {
|
|
248
|
+
return { users: [] };
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// 페이지 로더 등록
|
|
252
|
+
registerPageLoader("homePage", () => import("./pages/Home"));
|
|
253
|
+
|
|
254
|
+
// 서버 시작
|
|
255
|
+
const server = startServer(manifest, { port: 3000 });
|
|
256
|
+
|
|
257
|
+
// 종료
|
|
258
|
+
server.stop();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Report 모듈
|
|
262
|
+
|
|
263
|
+
Guard 결과 리포트 생성.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { buildGuardReport } from "@mandujs/core";
|
|
267
|
+
|
|
268
|
+
const report = buildGuardReport(guardResult, lockPath);
|
|
269
|
+
console.log(report); // 포맷된 텍스트 리포트
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## 타입
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import type {
|
|
276
|
+
RoutesManifest,
|
|
277
|
+
RouteSpec,
|
|
278
|
+
RouteKind,
|
|
279
|
+
SpecLock,
|
|
280
|
+
GuardResult,
|
|
281
|
+
GuardViolation,
|
|
282
|
+
GenerateResult,
|
|
283
|
+
AutoCorrectResult,
|
|
284
|
+
// Content Layer
|
|
285
|
+
DataEntry,
|
|
286
|
+
ContentConfig,
|
|
287
|
+
CollectionConfig,
|
|
288
|
+
Loader,
|
|
289
|
+
} from "@mandujs/core";
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 요구 사항
|
|
293
|
+
|
|
294
|
+
- Bun >= 1.0.0
|
|
295
|
+
- React >= 19.0.0
|
|
296
|
+
- Zod >= 3.0.0
|
|
297
|
+
|
|
298
|
+
## 관련 패키지
|
|
299
|
+
|
|
300
|
+
- [@mandujs/cli](https://www.npmjs.com/package/@mandujs/cli) - CLI 도구
|
|
301
|
+
|
|
302
|
+
## 라이선스
|
|
303
|
+
|
|
304
|
+
MPL-2.0
|