@mandujs/core 0.5.4 → 0.5.6

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.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
- English | <a href="./README.ko.md"><strong>한국어</strong></a>
14
- </p>
15
-
16
- ## Installation
17
-
18
- ```bash
19
- bun add @mandujs/core
20
- ```
21
-
22
- > Typically used through `@mandujs/cli`. Direct usage is for advanced use cases.
23
-
24
- ## Module Structure
25
-
26
- ```
27
- @mandujs/core
28
- ├── spec/ # Spec schema and loading
29
- ├── generator/ # Code generation
30
- ├── guard/ # Architecture checking and auto-correction
31
- ├── runtime/ # Server and router
32
- └── report/ # Guard report generation
33
- ```
34
-
35
- ## Spec Module
36
-
37
- Route manifest schema definition and loading.
38
-
39
- ```typescript
40
- import { loadManifest, RoutesManifest, RouteSpec } from "@mandujs/core";
41
-
42
- // Load and validate 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 File
54
-
55
- ```typescript
56
- import { writeLock, readLock } from "@mandujs/core";
57
-
58
- // Write lock file
59
- const lock = await writeLock("spec/spec.lock.json", manifest);
60
- console.log(lock.routesHash);
61
-
62
- // Read lock file
63
- const existing = await readLock("spec/spec.lock.json");
64
- ```
65
-
66
- ## Generator Module
67
-
68
- Spec-based code generation.
69
-
70
- ```typescript
71
- import { generateRoutes, GenerateResult } from "@mandujs/core";
72
-
73
- const result: GenerateResult = await generateRoutes(manifest, "./");
74
-
75
- console.log("Created:", result.created);
76
- console.log("Skipped:", result.skipped); // Existing slot files
77
- ```
78
-
79
- ### Template Functions
80
-
81
- ```typescript
82
- import {
83
- generateApiHandler,
84
- generateApiHandlerWithSlot,
85
- generateSlotLogic,
86
- generatePageComponent
87
- } from "@mandujs/core";
88
-
89
- // Generate API handler
90
- const code = generateApiHandler(route);
91
-
92
- // API handler with slot
93
- const codeWithSlot = generateApiHandlerWithSlot(route);
94
-
95
- // Slot logic file
96
- const slotCode = generateSlotLogic(route);
97
- ```
98
-
99
- ## Guard Module
100
-
101
- Architecture rule checking and auto-correction.
102
-
103
- ```typescript
104
- import {
105
- runGuardCheck,
106
- runAutoCorrect,
107
- GuardResult,
108
- GuardViolation
109
- } from "@mandujs/core";
110
-
111
- // Run check
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
- // Run auto-correction
120
- const corrected = await runAutoCorrect(result.violations, manifest, "./");
121
- console.log("Fixed:", corrected.steps);
122
- console.log("Remaining violations:", corrected.remainingViolations);
123
- }
124
- ```
125
-
126
- ### Guard Rules
127
-
128
- | Rule ID | Description | Auto-correctable |
129
- |---------|-------------|------------------|
130
- | `SPEC_HASH_MISMATCH` | Spec and lock hash mismatch | ✅ |
131
- | `GENERATED_MANUAL_EDIT` | Manual edit to generated file | ✅ |
132
- | `HANDLER_NOT_FOUND` | Handler file not found | ❌ |
133
- | `COMPONENT_NOT_FOUND` | Component file not found | ❌ |
134
- | `SLOT_NOT_FOUND` | Slot file not found | ✅ |
135
-
136
- ## Runtime Module
137
-
138
- Server startup and routing.
139
-
140
- ```typescript
141
- import {
142
- startServer,
143
- registerApiHandler,
144
- registerPageLoader
145
- } from "@mandujs/core";
146
-
147
- // Register API handler
148
- registerApiHandler("getUsers", async (req) => {
149
- return { users: [] };
150
- });
151
-
152
- // Register page loader
153
- registerPageLoader("homePage", () => import("./pages/Home"));
154
-
155
- // Start server
156
- const server = startServer(manifest, { port: 3000 });
157
-
158
- // Stop
159
- server.stop();
160
- ```
161
-
162
- ## Report Module
163
-
164
- Guard result report generation.
165
-
166
- ```typescript
167
- import { buildGuardReport } from "@mandujs/core";
168
-
169
- const report = buildGuardReport(guardResult, lockPath);
170
- console.log(report); // Formatted text report
171
- ```
172
-
173
- ## Types
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
- ## Requirements
189
-
190
- - Bun >= 1.0.0
191
- - React >= 18.0.0
192
- - Zod >= 3.0.0
193
-
194
- ## Related Packages
195
-
196
- - [@mandujs/cli](https://www.npmjs.com/package/@mandujs/cli) - CLI tool
197
-
198
- ## License
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
+ English | <a href="./README.ko.md"><strong>한국어</strong></a>
14
+ </p>
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ bun add @mandujs/core
20
+ ```
21
+
22
+ > Typically used through `@mandujs/cli`. Direct usage is for advanced use cases.
23
+
24
+ ## Module Structure
25
+
26
+ ```
27
+ @mandujs/core
28
+ ├── spec/ # Spec schema and loading
29
+ ├── generator/ # Code generation
30
+ ├── guard/ # Architecture checking and auto-correction
31
+ ├── runtime/ # Server and router
32
+ └── report/ # Guard report generation
33
+ ```
34
+
35
+ ## Spec Module
36
+
37
+ Route manifest schema definition and loading.
38
+
39
+ ```typescript
40
+ import { loadManifest, RoutesManifest, RouteSpec } from "@mandujs/core";
41
+
42
+ // Load and validate 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 File
54
+
55
+ ```typescript
56
+ import { writeLock, readLock } from "@mandujs/core";
57
+
58
+ // Write lock file
59
+ const lock = await writeLock("spec/spec.lock.json", manifest);
60
+ console.log(lock.routesHash);
61
+
62
+ // Read lock file
63
+ const existing = await readLock("spec/spec.lock.json");
64
+ ```
65
+
66
+ ## Generator Module
67
+
68
+ Spec-based code generation.
69
+
70
+ ```typescript
71
+ import { generateRoutes, GenerateResult } from "@mandujs/core";
72
+
73
+ const result: GenerateResult = await generateRoutes(manifest, "./");
74
+
75
+ console.log("Created:", result.created);
76
+ console.log("Skipped:", result.skipped); // Existing slot files
77
+ ```
78
+
79
+ ### Template Functions
80
+
81
+ ```typescript
82
+ import {
83
+ generateApiHandler,
84
+ generateApiHandlerWithSlot,
85
+ generateSlotLogic,
86
+ generatePageComponent
87
+ } from "@mandujs/core";
88
+
89
+ // Generate API handler
90
+ const code = generateApiHandler(route);
91
+
92
+ // API handler with slot
93
+ const codeWithSlot = generateApiHandlerWithSlot(route);
94
+
95
+ // Slot logic file
96
+ const slotCode = generateSlotLogic(route);
97
+ ```
98
+
99
+ ## Guard Module
100
+
101
+ Architecture rule checking and auto-correction.
102
+
103
+ ```typescript
104
+ import {
105
+ runGuardCheck,
106
+ runAutoCorrect,
107
+ GuardResult,
108
+ GuardViolation
109
+ } from "@mandujs/core";
110
+
111
+ // Run check
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
+ // Run auto-correction
120
+ const corrected = await runAutoCorrect(result.violations, manifest, "./");
121
+ console.log("Fixed:", corrected.steps);
122
+ console.log("Remaining violations:", corrected.remainingViolations);
123
+ }
124
+ ```
125
+
126
+ ### Guard Rules
127
+
128
+ | Rule ID | Description | Auto-correctable |
129
+ |---------|-------------|------------------|
130
+ | `SPEC_HASH_MISMATCH` | Spec and lock hash mismatch | ✅ |
131
+ | `GENERATED_MANUAL_EDIT` | Manual edit to generated file | ✅ |
132
+ | `HANDLER_NOT_FOUND` | Handler file not found | ❌ |
133
+ | `COMPONENT_NOT_FOUND` | Component file not found | ❌ |
134
+ | `SLOT_NOT_FOUND` | Slot file not found | ✅ |
135
+
136
+ ## Runtime Module
137
+
138
+ Server startup and routing.
139
+
140
+ ```typescript
141
+ import {
142
+ startServer,
143
+ registerApiHandler,
144
+ registerPageLoader
145
+ } from "@mandujs/core";
146
+
147
+ // Register API handler
148
+ registerApiHandler("getUsers", async (req) => {
149
+ return { users: [] };
150
+ });
151
+
152
+ // Register page loader
153
+ registerPageLoader("homePage", () => import("./pages/Home"));
154
+
155
+ // Start server
156
+ const server = startServer(manifest, { port: 3000 });
157
+
158
+ // Stop
159
+ server.stop();
160
+ ```
161
+
162
+ ## Report Module
163
+
164
+ Guard result report generation.
165
+
166
+ ```typescript
167
+ import { buildGuardReport } from "@mandujs/core";
168
+
169
+ const report = buildGuardReport(guardResult, lockPath);
170
+ console.log(report); // Formatted text report
171
+ ```
172
+
173
+ ## Types
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
+ ## Requirements
189
+
190
+ - Bun >= 1.0.0
191
+ - React >= 18.0.0
192
+ - Zod >= 3.0.0
193
+
194
+ ## Related Packages
195
+
196
+ - [@mandujs/cli](https://www.npmjs.com/package/@mandujs/cli) - CLI tool
197
+
198
+ ## License
199
+
200
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "repository": {
24
24
  "type": "git",
25
- "url": "https://github.com/konamgil/mandu.git",
25
+ "url": "git+https://github.com/konamgil/mandu.git",
26
26
  "directory": "packages/core"
27
27
  },
28
28
  "author": "konamgil",
@@ -205,8 +205,8 @@ export class ContractValidator {
205
205
  */
206
206
  getStatusCodes(): number[] {
207
207
  return Object.keys(this.contract.response)
208
- .map((k) => parseInt(k, 10))
209
- .filter((n) => !isNaN(n));
208
+ .filter((k) => /^\d+$/.test(k))
209
+ .map((k) => parseInt(k, 10));
210
210
  }
211
211
 
212
212
  /**