@mandujs/core 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +189 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # @mandujs/core
2
+
3
+ Mandu Framework Core - Spec, Generator, Guard, Runtime
4
+
5
+ ## 설치
6
+
7
+ ```bash
8
+ bun add @mandujs/core
9
+ ```
10
+
11
+ > 일반적으로 `@mandujs/cli`를 통해 사용합니다. 직접 사용은 고급 사용 사례입니다.
12
+
13
+ ## 모듈 구조
14
+
15
+ ```
16
+ @mandujs/core
17
+ ├── spec/ # Spec 스키마 및 로딩
18
+ ├── generator/ # 코드 생성
19
+ ├── guard/ # 아키텍처 검사 및 자동 수정
20
+ ├── runtime/ # 서버 및 라우터
21
+ └── report/ # Guard 리포트 생성
22
+ ```
23
+
24
+ ## Spec 모듈
25
+
26
+ 라우트 manifest 스키마 정의 및 로딩.
27
+
28
+ ```typescript
29
+ import { loadManifest, RoutesManifest, RouteSpec } from "@mandujs/core";
30
+
31
+ // manifest 로드 및 검증
32
+ const result = await loadManifest("spec/routes.manifest.json");
33
+
34
+ if (result.success && result.data) {
35
+ const manifest: RoutesManifest = result.data;
36
+ manifest.routes.forEach((route: RouteSpec) => {
37
+ console.log(route.id, route.pattern, route.kind);
38
+ });
39
+ }
40
+ ```
41
+
42
+ ### Lock 파일
43
+
44
+ ```typescript
45
+ import { writeLock, readLock } from "@mandujs/core";
46
+
47
+ // lock 파일 쓰기
48
+ const lock = await writeLock("spec/spec.lock.json", manifest);
49
+ console.log(lock.routesHash);
50
+
51
+ // lock 파일 읽기
52
+ const existing = await readLock("spec/spec.lock.json");
53
+ ```
54
+
55
+ ## Generator 모듈
56
+
57
+ Spec 기반 코드 생성.
58
+
59
+ ```typescript
60
+ import { generateRoutes, GenerateResult } from "@mandujs/core";
61
+
62
+ const result: GenerateResult = await generateRoutes(manifest, "./");
63
+
64
+ console.log("생성됨:", result.created);
65
+ console.log("건너뜀:", result.skipped); // 이미 존재하는 slot 파일
66
+ ```
67
+
68
+ ### 템플릿 함수
69
+
70
+ ```typescript
71
+ import {
72
+ generateApiHandler,
73
+ generateApiHandlerWithSlot,
74
+ generateSlotLogic,
75
+ generatePageComponent
76
+ } from "@mandujs/core";
77
+
78
+ // API 핸들러 생성
79
+ const code = generateApiHandler(route);
80
+
81
+ // Slot이 있는 API 핸들러
82
+ const codeWithSlot = generateApiHandlerWithSlot(route);
83
+
84
+ // Slot 로직 파일
85
+ const slotCode = generateSlotLogic(route);
86
+ ```
87
+
88
+ ## Guard 모듈
89
+
90
+ 아키텍처 규칙 검사 및 자동 수정.
91
+
92
+ ```typescript
93
+ import {
94
+ runGuardCheck,
95
+ runAutoCorrect,
96
+ GuardResult,
97
+ GuardViolation
98
+ } from "@mandujs/core";
99
+
100
+ // 검사 실행
101
+ const result: GuardResult = await runGuardCheck(manifest, "./");
102
+
103
+ if (!result.passed) {
104
+ result.violations.forEach((v: GuardViolation) => {
105
+ console.log(`${v.rule}: ${v.message}`);
106
+ });
107
+
108
+ // 자동 수정 실행
109
+ const corrected = await runAutoCorrect(result.violations, manifest, "./");
110
+ console.log("수정됨:", corrected.steps);
111
+ console.log("남은 위반:", corrected.remainingViolations);
112
+ }
113
+ ```
114
+
115
+ ### Guard 규칙
116
+
117
+ | 규칙 ID | 설명 | 자동 수정 |
118
+ |---------|------|----------|
119
+ | `SPEC_HASH_MISMATCH` | spec과 lock 해시 불일치 | ✅ |
120
+ | `GENERATED_MANUAL_EDIT` | generated 파일 수동 수정 | ✅ |
121
+ | `HANDLER_NOT_FOUND` | 핸들러 파일 없음 | ❌ |
122
+ | `COMPONENT_NOT_FOUND` | 컴포넌트 파일 없음 | ❌ |
123
+ | `SLOT_NOT_FOUND` | slot 파일 없음 | ✅ |
124
+
125
+ ## Runtime 모듈
126
+
127
+ 서버 시작 및 라우팅.
128
+
129
+ ```typescript
130
+ import {
131
+ startServer,
132
+ registerApiHandler,
133
+ registerPageLoader
134
+ } from "@mandujs/core";
135
+
136
+ // API 핸들러 등록
137
+ registerApiHandler("getUsers", async (req) => {
138
+ return { users: [] };
139
+ });
140
+
141
+ // 페이지 로더 등록
142
+ registerPageLoader("homePage", () => import("./pages/Home"));
143
+
144
+ // 서버 시작
145
+ const server = startServer(manifest, { port: 3000 });
146
+
147
+ // 종료
148
+ server.stop();
149
+ ```
150
+
151
+ ## Report 모듈
152
+
153
+ Guard 결과 리포트 생성.
154
+
155
+ ```typescript
156
+ import { buildGuardReport } from "@mandujs/core";
157
+
158
+ const report = buildGuardReport(guardResult, lockPath);
159
+ console.log(report); // 포맷된 텍스트 리포트
160
+ ```
161
+
162
+ ## 타입
163
+
164
+ ```typescript
165
+ import type {
166
+ RoutesManifest,
167
+ RouteSpec,
168
+ RouteKind,
169
+ SpecLock,
170
+ GuardResult,
171
+ GuardViolation,
172
+ GenerateResult,
173
+ AutoCorrectResult,
174
+ } from "@mandujs/core";
175
+ ```
176
+
177
+ ## 요구 사항
178
+
179
+ - Bun >= 1.0.0
180
+ - React >= 18.0.0
181
+ - Zod >= 3.0.0
182
+
183
+ ## 관련 패키지
184
+
185
+ - [@mandujs/cli](https://www.npmjs.com/package/@mandujs/cli) - CLI 도구
186
+
187
+ ## 라이선스
188
+
189
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",