@mandujs/core 0.12.2 → 0.13.0
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/README.md +653 -653
- package/package.json +1 -1
- package/src/brain/architecture/analyzer.ts +28 -26
- package/src/brain/doctor/analyzer.ts +1 -1
- package/src/bundler/build.ts +91 -91
- package/src/bundler/css.ts +302 -302
- 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/client/Link.tsx +227 -227
- package/src/client/globals.ts +44 -44
- package/src/client/hooks.ts +267 -267
- package/src/client/index.ts +5 -5
- package/src/client/island.ts +8 -8
- package/src/client/router.ts +435 -435
- package/src/client/runtime.ts +23 -23
- package/src/client/serialize.ts +404 -404
- package/src/client/window-state.ts +101 -101
- package/src/config/mandu.ts +94 -96
- package/src/config/validate.ts +213 -215
- package/src/config/watcher.ts +311 -311
- package/src/constants.ts +40 -40
- package/src/content/content-layer.ts +314 -314
- package/src/content/content.test.ts +433 -433
- package/src/content/data-store.ts +245 -245
- package/src/content/digest.ts +133 -133
- package/src/content/index.ts +164 -164
- package/src/content/loader-context.ts +172 -172
- package/src/content/loaders/api.ts +216 -216
- package/src/content/loaders/file.ts +169 -169
- package/src/content/loaders/glob.ts +252 -252
- package/src/content/loaders/index.ts +34 -34
- package/src/content/loaders/types.ts +137 -137
- package/src/content/meta-store.ts +209 -209
- package/src/content/types.ts +282 -282
- package/src/content/watcher.ts +135 -135
- package/src/contract/client-safe.test.ts +42 -42
- package/src/contract/client-safe.ts +114 -114
- package/src/contract/client.ts +16 -16
- package/src/contract/define.ts +459 -459
- package/src/contract/handler.ts +10 -10
- package/src/contract/normalize.test.ts +276 -276
- package/src/contract/normalize.ts +404 -404
- package/src/contract/registry.test.ts +206 -206
- package/src/contract/registry.ts +568 -568
- package/src/contract/schema.ts +48 -48
- package/src/contract/types.ts +58 -58
- package/src/contract/validator.ts +32 -32
- package/src/devtools/ai/context-builder.ts +375 -375
- package/src/devtools/ai/index.ts +25 -25
- package/src/devtools/ai/mcp-connector.ts +465 -465
- package/src/devtools/client/catchers/error-catcher.ts +327 -327
- package/src/devtools/client/catchers/index.ts +18 -18
- package/src/devtools/client/catchers/network-proxy.ts +363 -363
- package/src/devtools/client/components/index.ts +39 -39
- package/src/devtools/client/components/kitchen-root.tsx +362 -362
- package/src/devtools/client/components/mandu-character.tsx +241 -241
- package/src/devtools/client/components/overlay.tsx +368 -368
- package/src/devtools/client/components/panel/errors-panel.tsx +259 -259
- package/src/devtools/client/components/panel/guard-panel.tsx +244 -244
- package/src/devtools/client/components/panel/index.ts +32 -32
- package/src/devtools/client/components/panel/islands-panel.tsx +304 -304
- package/src/devtools/client/components/panel/network-panel.tsx +292 -292
- package/src/devtools/client/components/panel/panel-container.tsx +259 -259
- package/src/devtools/client/filters/context-filters.ts +282 -282
- package/src/devtools/client/filters/index.ts +16 -16
- package/src/devtools/client/index.ts +63 -63
- package/src/devtools/client/persistence.ts +335 -335
- package/src/devtools/client/state-manager.ts +478 -478
- package/src/devtools/design-tokens.ts +263 -263
- package/src/devtools/hook/create-hook.ts +207 -207
- package/src/devtools/hook/index.ts +13 -13
- package/src/devtools/index.ts +439 -439
- package/src/devtools/init.ts +266 -266
- package/src/devtools/protocol.ts +237 -237
- package/src/devtools/server/index.ts +17 -17
- package/src/devtools/server/source-context.ts +444 -444
- package/src/devtools/types.ts +319 -319
- package/src/devtools/worker/index.ts +25 -25
- package/src/devtools/worker/redaction-worker.ts +222 -222
- package/src/devtools/worker/worker-manager.ts +409 -409
- package/src/error/classifier.ts +2 -2
- package/src/error/domains.ts +265 -265
- package/src/error/formatter.ts +32 -32
- package/src/error/result.ts +46 -46
- package/src/error/stack-analyzer.ts +5 -0
- package/src/error/types.ts +6 -6
- package/src/errors/extractor.ts +409 -409
- package/src/errors/index.ts +19 -19
- package/src/filling/auth.ts +308 -308
- package/src/filling/context.ts +569 -569
- package/src/filling/deps.ts +238 -238
- package/src/generator/contract-glue.ts +2 -1
- package/src/generator/generate.ts +12 -10
- package/src/generator/index.ts +3 -3
- package/src/generator/templates.ts +80 -79
- package/src/guard/analyzer.ts +360 -360
- package/src/guard/ast-analyzer.ts +806 -806
- package/src/guard/auto-correct.ts +1 -1
- package/src/guard/check.ts +128 -128
- package/src/guard/contract-guard.ts +9 -9
- package/src/guard/file-type.test.ts +24 -24
- package/src/guard/presets/atomic.ts +70 -70
- package/src/guard/presets/clean.ts +77 -77
- package/src/guard/presets/cqrs.test.ts +35 -14
- package/src/guard/presets/fsd.ts +79 -79
- package/src/guard/presets/hexagonal.ts +68 -68
- package/src/guard/presets/index.ts +291 -291
- package/src/guard/reporter.ts +445 -445
- package/src/guard/rules.ts +12 -12
- package/src/guard/statistics.ts +578 -578
- package/src/guard/suggestions.ts +358 -358
- package/src/guard/types.ts +348 -348
- package/src/guard/validator.ts +834 -834
- package/src/guard/watcher.ts +404 -404
- package/src/index.ts +1 -0
- package/src/intent/index.ts +310 -310
- package/src/island/index.ts +304 -304
- package/src/logging/index.ts +22 -22
- package/src/logging/transports.ts +365 -365
- package/src/paths.test.ts +47 -0
- package/src/paths.ts +47 -0
- package/src/plugins/index.ts +38 -38
- package/src/plugins/registry.ts +377 -377
- package/src/plugins/types.ts +363 -363
- package/src/report/build.ts +1 -1
- package/src/report/index.ts +1 -1
- package/src/router/fs-patterns.ts +387 -387
- package/src/router/fs-routes.ts +344 -401
- package/src/router/fs-scanner.ts +497 -497
- package/src/router/fs-types.ts +270 -278
- package/src/router/index.ts +81 -81
- package/src/runtime/boundary.tsx +232 -232
- package/src/runtime/compose.ts +222 -222
- package/src/runtime/lifecycle.ts +381 -381
- package/src/runtime/logger.test.ts +345 -345
- package/src/runtime/logger.ts +677 -677
- package/src/runtime/router.test.ts +476 -476
- package/src/runtime/router.ts +105 -105
- package/src/runtime/security.ts +155 -155
- package/src/runtime/server.ts +24 -24
- package/src/runtime/session-key.ts +328 -328
- package/src/runtime/ssr.ts +367 -367
- package/src/runtime/streaming-ssr.ts +1245 -1245
- package/src/runtime/trace.ts +144 -144
- package/src/seo/index.ts +214 -214
- package/src/seo/integration/ssr.ts +307 -307
- package/src/seo/render/basic.ts +427 -427
- package/src/seo/render/index.ts +143 -143
- package/src/seo/render/jsonld.ts +539 -539
- package/src/seo/render/opengraph.ts +191 -191
- package/src/seo/render/robots.ts +116 -116
- package/src/seo/render/sitemap.ts +137 -137
- package/src/seo/render/twitter.ts +126 -126
- package/src/seo/resolve/index.ts +353 -353
- package/src/seo/resolve/opengraph.ts +143 -143
- package/src/seo/resolve/robots.ts +73 -73
- package/src/seo/resolve/title.ts +94 -94
- package/src/seo/resolve/twitter.ts +73 -73
- package/src/seo/resolve/url.ts +97 -97
- package/src/seo/routes/index.ts +290 -290
- package/src/seo/types.ts +575 -575
- package/src/slot/validator.ts +39 -39
- package/src/spec/index.ts +3 -3
- package/src/spec/load.ts +76 -76
- package/src/spec/lock.ts +56 -56
- package/src/utils/bun.ts +8 -8
- package/src/utils/lru-cache.ts +75 -75
- package/src/utils/safe-io.ts +188 -188
- package/src/utils/string-safe.ts +298 -298
- 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("spec/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("spec/spec.lock.json", manifest);
|
|
65
|
-
console.log(lock.routesHash);
|
|
66
|
-
|
|
67
|
-
// lock 파일 읽기
|
|
68
|
-
const existing = await readLock("spec/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
|
-
MIT
|
|
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("spec/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("spec/spec.lock.json", manifest);
|
|
65
|
+
console.log(lock.routesHash);
|
|
66
|
+
|
|
67
|
+
// lock 파일 읽기
|
|
68
|
+
const existing = await readLock("spec/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
|
+
MIT
|