@mandujs/core 0.7.1 → 0.7.3
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/package.json +1 -1
- package/src/bundler/build.ts +11 -5
- package/src/filling/auth.ts +40 -40
- package/src/filling/context.ts +438 -464
- package/src/filling/filling.ts +252 -552
- package/src/filling/index.ts +21 -21
- package/src/filling/tmpclaude-2f8d-cwd +1 -0
- package/src/filling/tmpclaude-2fc1-cwd +1 -0
- package/src/filling/tmpclaude-59ee-cwd +1 -0
- package/src/filling/tmpclaude-7608-cwd +1 -0
- package/src/filling/tmpclaude-a102-cwd +1 -0
- package/src/filling/tmpclaude-bf2c-cwd +1 -0
- package/src/filling/tmpclaude-fb5a-cwd +1 -0
- package/src/runtime/index.ts +3 -2
- package/src/runtime/lifecycle.ts +25 -4
- package/src/runtime/ssr.ts +315 -313
- package/src/runtime/tmpclaude-1f31-cwd +1 -0
- package/src/runtime/tmpclaude-8527-cwd +1 -0
- package/src/runtime/tmpclaude-e62c-cwd +1 -0
- package/src/runtime/trace.ts +85 -0
package/src/filling/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mandu Filling Module - 만두소 🥟
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { ManduContext,
|
|
6
|
-
export type { CookieOptions } from "./context";
|
|
7
|
-
export { ManduFilling, Mandu, LoaderTimeoutError } from "./filling";
|
|
8
|
-
export type { Handler, Guard, HttpMethod, Loader, LoaderOptions } from "./filling";
|
|
9
|
-
|
|
10
|
-
// Auth Guards
|
|
11
|
-
export {
|
|
12
|
-
AuthenticationError,
|
|
13
|
-
AuthorizationError,
|
|
14
|
-
requireUser,
|
|
15
|
-
requireRole,
|
|
16
|
-
requireAnyRole,
|
|
17
|
-
requireAllRoles,
|
|
18
|
-
createAuthGuard,
|
|
19
|
-
createRoleGuard,
|
|
20
|
-
} from "./auth";
|
|
21
|
-
export type { BaseUser, UserWithRole, UserWithRoles } from "./auth";
|
|
1
|
+
/**
|
|
2
|
+
* Mandu Filling Module - 만두소 🥟
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { ManduContext, ValidationError, CookieManager } from "./context";
|
|
6
|
+
export type { CookieOptions } from "./context";
|
|
7
|
+
export { ManduFilling, Mandu, LoaderTimeoutError } from "./filling";
|
|
8
|
+
export type { Handler, Guard, HttpMethod, Loader, LoaderOptions } from "./filling";
|
|
9
|
+
|
|
10
|
+
// Auth Guards
|
|
11
|
+
export {
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
AuthorizationError,
|
|
14
|
+
requireUser,
|
|
15
|
+
requireRole,
|
|
16
|
+
requireAnyRole,
|
|
17
|
+
requireAllRoles,
|
|
18
|
+
createAuthGuard,
|
|
19
|
+
createRoleGuard,
|
|
20
|
+
} from "./auth";
|
|
21
|
+
export type { BaseUser, UserWithRole, UserWithRoles } from "./auth";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/c/Users/LamySolution/workspace/mandu/packages/core/src/filling
|
package/src/runtime/index.ts
CHANGED
package/src/runtime/lifecycle.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { ManduContext } from "../filling/context";
|
|
21
|
+
import { createTracer } from "./trace";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* 훅 스코프
|
|
@@ -115,6 +116,8 @@ export function createLifecycleStore(): LifecycleStore {
|
|
|
115
116
|
export interface ExecuteOptions {
|
|
116
117
|
/** 바디 파싱이 필요한 메서드 */
|
|
117
118
|
parseBodyMethods?: string[];
|
|
119
|
+
/** 트레이스 활성화 */
|
|
120
|
+
trace?: boolean;
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
const DEFAULT_PARSE_BODY_METHODS = ["POST", "PUT", "PATCH"];
|
|
@@ -147,59 +150,74 @@ export async function executeLifecycle(
|
|
|
147
150
|
options: ExecuteOptions = {}
|
|
148
151
|
): Promise<Response> {
|
|
149
152
|
const { parseBodyMethods = DEFAULT_PARSE_BODY_METHODS } = options;
|
|
153
|
+
const tracer = createTracer(ctx, options.trace);
|
|
150
154
|
let response: Response;
|
|
151
155
|
|
|
152
156
|
try {
|
|
153
157
|
// 1. onRequest
|
|
158
|
+
const endRequest = tracer.begin("request");
|
|
154
159
|
for (const hook of lifecycle.onRequest) {
|
|
155
160
|
await hook.fn(ctx);
|
|
156
161
|
}
|
|
162
|
+
endRequest();
|
|
157
163
|
|
|
158
164
|
// 2. onParse (바디가 있는 메서드만)
|
|
159
165
|
if (parseBodyMethods.includes(ctx.req.method)) {
|
|
166
|
+
const endParse = tracer.begin("parse");
|
|
160
167
|
for (const hook of lifecycle.onParse) {
|
|
161
168
|
await hook.fn(ctx);
|
|
162
169
|
}
|
|
170
|
+
endParse();
|
|
163
171
|
}
|
|
164
172
|
|
|
165
173
|
// 3. beforeHandle (Guard 역할)
|
|
174
|
+
const endBefore = tracer.begin("beforeHandle");
|
|
166
175
|
for (const hook of lifecycle.beforeHandle) {
|
|
167
176
|
const result = await hook.fn(ctx);
|
|
168
177
|
if (result instanceof Response) {
|
|
169
178
|
// Response 반환 시 체인 중단, afterHandle/mapResponse 건너뜀
|
|
170
179
|
response = result;
|
|
180
|
+
endBefore();
|
|
171
181
|
// afterResponse는 실행
|
|
172
|
-
scheduleAfterResponse(lifecycle.afterResponse, ctx);
|
|
182
|
+
scheduleAfterResponse(lifecycle.afterResponse, ctx, tracer);
|
|
173
183
|
return response;
|
|
174
184
|
}
|
|
175
185
|
}
|
|
186
|
+
endBefore();
|
|
176
187
|
|
|
177
188
|
// 4. 메인 핸들러 실행
|
|
189
|
+
const endHandle = tracer.begin("handle");
|
|
178
190
|
response = await handler();
|
|
191
|
+
endHandle();
|
|
179
192
|
|
|
180
193
|
// 5. afterHandle
|
|
194
|
+
const endAfter = tracer.begin("afterHandle");
|
|
181
195
|
for (const hook of lifecycle.afterHandle) {
|
|
182
196
|
response = await hook.fn(ctx, response);
|
|
183
197
|
}
|
|
198
|
+
endAfter();
|
|
184
199
|
|
|
185
200
|
// 6. mapResponse
|
|
201
|
+
const endMap = tracer.begin("mapResponse");
|
|
186
202
|
for (const hook of lifecycle.mapResponse) {
|
|
187
203
|
response = await hook.fn(ctx, response);
|
|
188
204
|
}
|
|
205
|
+
endMap();
|
|
189
206
|
|
|
190
207
|
// 7. afterResponse (비동기)
|
|
191
|
-
scheduleAfterResponse(lifecycle.afterResponse, ctx);
|
|
208
|
+
scheduleAfterResponse(lifecycle.afterResponse, ctx, tracer);
|
|
192
209
|
|
|
193
210
|
return response;
|
|
194
211
|
} catch (err) {
|
|
195
212
|
// onError 처리
|
|
196
213
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
214
|
+
tracer.error("error", error);
|
|
197
215
|
|
|
198
216
|
for (const hook of lifecycle.onError) {
|
|
199
217
|
const result = await hook.fn(ctx, error);
|
|
200
218
|
if (result instanceof Response) {
|
|
201
219
|
// afterResponse는 에러 시에도 실행
|
|
202
|
-
scheduleAfterResponse(lifecycle.afterResponse, ctx);
|
|
220
|
+
scheduleAfterResponse(lifecycle.afterResponse, ctx, tracer);
|
|
203
221
|
return result;
|
|
204
222
|
}
|
|
205
223
|
}
|
|
@@ -214,12 +232,14 @@ export async function executeLifecycle(
|
|
|
214
232
|
*/
|
|
215
233
|
function scheduleAfterResponse(
|
|
216
234
|
hooks: HookContainer<AfterResponseHandler>[],
|
|
217
|
-
ctx: ManduContext
|
|
235
|
+
ctx: ManduContext,
|
|
236
|
+
tracer?: ReturnType<typeof createTracer>
|
|
218
237
|
): void {
|
|
219
238
|
if (hooks.length === 0) return;
|
|
220
239
|
|
|
221
240
|
// queueMicrotask로 응답 후 실행
|
|
222
241
|
queueMicrotask(async () => {
|
|
242
|
+
const endAfterResponse = tracer?.begin("afterResponse") ?? (() => {});
|
|
223
243
|
for (const hook of hooks) {
|
|
224
244
|
try {
|
|
225
245
|
await hook.fn(ctx);
|
|
@@ -227,6 +247,7 @@ function scheduleAfterResponse(
|
|
|
227
247
|
console.error("[Mandu] afterResponse hook error:", err);
|
|
228
248
|
}
|
|
229
249
|
}
|
|
250
|
+
endAfterResponse();
|
|
230
251
|
});
|
|
231
252
|
}
|
|
232
253
|
|