@mandujs/core 0.2.0 → 0.2.2

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