@mandujs/core 0.9.17 → 0.9.19

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