@mandujs/core 0.41.2 → 0.43.0

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 (88) hide show
  1. package/package.json +21 -4
  2. package/src/auth/__tests__/login.test.ts +420 -419
  3. package/src/auth/__tests__/reset.test.ts +296 -296
  4. package/src/brain/adapters/anthropic-oauth.ts +421 -420
  5. package/src/brain/adapters/index.ts +2 -1
  6. package/src/brain/adapters/ollama.ts +1 -1
  7. package/src/brain/adapters/openai-oauth.ts +534 -533
  8. package/src/brain/brain.ts +2 -1
  9. package/src/brain/redactor.ts +196 -196
  10. package/src/bundler/__tests__/cli-bench-utils.test.ts +149 -149
  11. package/src/bundler/__tests__/cold-start.test.ts +504 -504
  12. package/src/bundler/__tests__/fast-refresh.test.ts +607 -606
  13. package/src/bundler/__tests__/hdr.test.ts +1 -1
  14. package/src/bundler/analyzer.ts +958 -958
  15. package/src/bundler/build.ts +104 -14
  16. package/src/bundler/dev.ts +125 -0
  17. package/src/bundler/hmr-types.ts +1 -0
  18. package/src/bundler/plugins/__tests__/react-compiler-lint.test.ts +110 -0
  19. package/src/bundler/plugins/index.ts +14 -0
  20. package/src/bundler/plugins/react-compiler-lint.ts +253 -0
  21. package/src/bundler/plugins/react-compiler.ts +162 -0
  22. package/src/bundler/types.ts +12 -0
  23. package/src/change/integrity.ts +2 -1
  24. package/src/client/index.ts +10 -0
  25. package/src/client/island.ts +38 -11
  26. package/src/client/router.ts +6 -1
  27. package/src/config/mandu.ts +57 -0
  28. package/src/config/validate.ts +42 -0
  29. package/src/content/collection.ts +844 -809
  30. package/src/content/content-layer.ts +316 -314
  31. package/src/content/content.test.ts +433 -433
  32. package/src/content/digest.ts +133 -133
  33. package/src/content/generate-types.ts +168 -168
  34. package/src/content/index.ts +6 -1
  35. package/src/content/llms-txt.ts +277 -277
  36. package/src/contract/define.ts +474 -474
  37. package/src/contract/route-helpers.ts +2 -1
  38. package/src/contract/zod-utils.ts +158 -155
  39. package/src/db/index.ts +513 -513
  40. package/src/desktop/__tests__/smoke.test.ts +100 -100
  41. package/src/desktop/webview-fallback.ts +583 -583
  42. package/src/desktop/window.ts +3 -1
  43. package/src/dev-error-overlay/overlay-client.ts +300 -300
  44. package/src/devtools/ai/mcp-connector.ts +499 -498
  45. package/src/devtools/client/components/kitchen-root.tsx +7 -2
  46. package/src/email/resend.ts +163 -163
  47. package/src/guard/__tests__/tsgolint-bridge.test.ts +347 -0
  48. package/src/guard/ast-analyzer.ts +806 -806
  49. package/src/guard/graph.ts +898 -898
  50. package/src/guard/index.ts +16 -0
  51. package/src/guard/statistics.ts +578 -578
  52. package/src/guard/tsgolint-bridge.ts +512 -0
  53. package/src/i18n/locale-resolver.ts +214 -214
  54. package/src/id/__tests__/id.test.ts +120 -120
  55. package/src/intent/index.ts +321 -321
  56. package/src/island/index.ts +39 -23
  57. package/src/kitchen/api/contract-api.ts +15 -8
  58. package/src/kitchen/kitchen-ui.ts +2137 -2137
  59. package/src/lockfile/index.ts +3 -2
  60. package/src/middleware/oauth/__tests__/oauth.test.ts +575 -574
  61. package/src/middleware/rate-limit/__tests__/rate-limit.test.ts +642 -642
  62. package/src/middleware/secure/index.ts +417 -417
  63. package/src/observability/event-bus.ts +2 -2
  64. package/src/observability/metrics.ts +334 -334
  65. package/src/observability/tracing.ts +694 -694
  66. package/src/openapi/generator.ts +1 -1
  67. package/src/perf/user-marks.ts +553 -553
  68. package/src/plugins/registry.ts +387 -387
  69. package/src/resource/ddl/diff.ts +392 -392
  70. package/src/resource/ddl/snapshot.ts +448 -447
  71. package/src/resource/generator-schema.ts +477 -476
  72. package/src/resource/parser.ts +4 -2
  73. package/src/resource/schema.ts +1 -1
  74. package/src/router/fs-patterns.ts +422 -422
  75. package/src/runtime/fast-refresh-types.ts +126 -128
  76. package/src/runtime/image-handler.ts +206 -195
  77. package/src/runtime/router.test.ts +476 -476
  78. package/src/runtime/security.ts +155 -155
  79. package/src/runtime/server.ts +36 -19
  80. package/src/runtime/session-key.ts +328 -328
  81. package/src/scheduler/__tests__/scheduler.test.ts +514 -514
  82. package/src/seo/resolve/index.ts +353 -353
  83. package/src/spec/load.ts +1 -1
  84. package/src/testing/reporter.ts +676 -676
  85. package/src/testing/server.ts +196 -196
  86. package/src/testing/snapshot.ts +444 -444
  87. package/src/utils/__tests__/lru-cache.test.ts +186 -186
  88. package/src/utils/bun.ts +8 -8
@@ -1,353 +1,353 @@
1
- /**
2
- * Mandu SEO - Metadata Resolution
3
- *
4
- * Layout 체인에서 메타데이터를 수집하고 병합
5
- */
6
-
7
- import type {
8
- Metadata,
9
- ResolvedMetadata,
10
- MetadataItem,
11
- MetadataParams,
12
- Author,
13
- Icons,
14
- IconDescriptor,
15
- ResolvedIcons,
16
- Verification,
17
- ResolvedVerification,
18
- JsonLd,
19
- ThemeColor,
20
- ResourceHint,
21
- FormatDetection,
22
- GoogleMeta,
23
- AppLinks,
24
- } from '../types'
25
- import { resolveTitle, extractTitleTemplate } from './title'
26
- import { normalizeMetadataBase, resolveUrl } from './url'
27
- import { resolveRobots } from './robots'
28
- import { resolveOpenGraph } from './opengraph'
29
- import { resolveTwitter } from './twitter'
30
-
31
- /**
32
- * 기본 메타데이터 생성
33
- */
34
- export function createDefaultMetadata(): ResolvedMetadata {
35
- return {
36
- metadataBase: null,
37
- title: null,
38
- description: null,
39
- applicationName: null,
40
- authors: null,
41
- generator: 'Mandu',
42
- keywords: null,
43
- referrer: null,
44
- creator: null,
45
- publisher: null,
46
- robots: null,
47
- alternates: null,
48
- icons: null,
49
- manifest: null,
50
- openGraph: null,
51
- twitter: null,
52
- verification: null,
53
- category: null,
54
- classification: null,
55
- jsonLd: null,
56
- // Google SEO 최적화
57
- google: null,
58
- formatDetection: null,
59
- resourceHints: null,
60
- themeColor: null,
61
- viewport: null,
62
- appLinks: null,
63
- other: null,
64
- }
65
- }
66
-
67
- /**
68
- * Author 배열로 정규화
69
- */
70
- function resolveAuthors(authors: Author | Author[] | null | undefined): Author[] | null {
71
- if (!authors) return null
72
- return Array.isArray(authors) ? authors : [authors]
73
- }
74
-
75
- /**
76
- * Keywords 배열로 정규화
77
- */
78
- function resolveKeywords(keywords: string | string[] | null | undefined): string[] | null {
79
- if (!keywords) return null
80
- if (typeof keywords === 'string') {
81
- return keywords.split(',').map(k => k.trim())
82
- }
83
- return keywords
84
- }
85
-
86
- /**
87
- * Icons 해석
88
- */
89
- function resolveIcons(icons: Metadata['icons'], metadataBase: URL | null): ResolvedIcons | null {
90
- if (!icons) return null
91
-
92
- const result: ResolvedIcons = {
93
- icon: [],
94
- apple: [],
95
- shortcut: [],
96
- other: [],
97
- }
98
-
99
- // 단순 문자열 URL
100
- if (typeof icons === 'string') {
101
- const url = resolveUrl(icons, metadataBase)
102
- if (url) {
103
- result.icon.push({ url: url.href })
104
- }
105
- return result
106
- }
107
-
108
- // 배열
109
- if (Array.isArray(icons)) {
110
- for (const icon of icons) {
111
- const descriptor = typeof icon === 'string'
112
- ? { url: icon }
113
- : icon instanceof URL
114
- ? { url: icon.href }
115
- : { ...icon, url: typeof icon.url === 'string' ? icon.url : icon.url.href }
116
-
117
- const resolvedUrl = resolveUrl(descriptor.url, metadataBase)
118
- if (resolvedUrl) {
119
- result.icon.push({ ...descriptor, url: resolvedUrl.href })
120
- }
121
- }
122
- return result
123
- }
124
-
125
- // Icons 객체
126
- const iconsObj = icons as Icons
127
-
128
- const processIconArray = (
129
- items: typeof iconsObj.icon,
130
- target: IconDescriptor[]
131
- ) => {
132
- if (!items) return
133
- const arr = Array.isArray(items) ? items : [items]
134
- for (const item of arr) {
135
- const descriptor = typeof item === 'string'
136
- ? { url: item }
137
- : item instanceof URL
138
- ? { url: item.href }
139
- : { ...item, url: typeof item.url === 'string' ? item.url : item.url.href }
140
-
141
- const resolvedUrl = resolveUrl(descriptor.url, metadataBase)
142
- if (resolvedUrl) {
143
- target.push({ ...descriptor, url: resolvedUrl.href })
144
- }
145
- }
146
- }
147
-
148
- processIconArray(iconsObj.icon, result.icon)
149
- processIconArray(iconsObj.apple, result.apple)
150
- processIconArray(iconsObj.shortcut, result.shortcut)
151
-
152
- if (iconsObj.other) {
153
- const others = Array.isArray(iconsObj.other) ? iconsObj.other : [iconsObj.other]
154
- for (const other of others) {
155
- const resolvedUrl = resolveUrl(other.url, metadataBase)
156
- if (resolvedUrl) {
157
- result.other.push({ ...other, url: resolvedUrl.href })
158
- }
159
- }
160
- }
161
-
162
- return result
163
- }
164
-
165
- /**
166
- * Verification 해석
167
- */
168
- function resolveVerification(verification: Verification | null | undefined): ResolvedVerification | null {
169
- if (!verification) return null
170
-
171
- const toArray = (val: string | string[] | undefined): string[] | null => {
172
- if (!val) return null
173
- return Array.isArray(val) ? val : [val]
174
- }
175
-
176
- return {
177
- google: toArray(verification.google),
178
- yahoo: toArray(verification.yahoo),
179
- yandex: toArray(verification.yandex),
180
- me: toArray(verification.me),
181
- other: verification.other
182
- ? Object.fromEntries(
183
- Object.entries(verification.other).map(([k, v]) => [k, toArray(v)!])
184
- )
185
- : null,
186
- }
187
- }
188
-
189
- /**
190
- * JSON-LD 배열로 정규화
191
- */
192
- function resolveJsonLd(jsonLd: JsonLd | JsonLd[] | null | undefined): JsonLd[] | null {
193
- if (!jsonLd) return null
194
- const arr = Array.isArray(jsonLd) ? jsonLd : [jsonLd]
195
- // @context 기본값 추가
196
- return arr.map(item => ({
197
- '@context': 'https://schema.org',
198
- ...item,
199
- }))
200
- }
201
-
202
- /**
203
- * Theme Color 배열로 정규화
204
- */
205
- function resolveThemeColor(
206
- themeColor: string | ThemeColor | ThemeColor[] | null | undefined
207
- ): ThemeColor[] | null {
208
- if (!themeColor) return null
209
- if (typeof themeColor === 'string') {
210
- return [{ color: themeColor }]
211
- }
212
- return Array.isArray(themeColor) ? themeColor : [themeColor]
213
- }
214
-
215
- /**
216
- * Viewport 문자열로 정규화
217
- */
218
- function resolveViewport(
219
- viewport: Metadata['viewport']
220
- ): string | null {
221
- if (!viewport) return null
222
- if (typeof viewport === 'string') return viewport
223
-
224
- const parts: string[] = []
225
-
226
- if (viewport.width !== undefined) {
227
- parts.push(`width=${viewport.width}`)
228
- }
229
- if (viewport.height !== undefined) {
230
- parts.push(`height=${viewport.height}`)
231
- }
232
- if (viewport.initialScale !== undefined) {
233
- parts.push(`initial-scale=${viewport.initialScale}`)
234
- }
235
- if (viewport.minimumScale !== undefined) {
236
- parts.push(`minimum-scale=${viewport.minimumScale}`)
237
- }
238
- if (viewport.maximumScale !== undefined) {
239
- parts.push(`maximum-scale=${viewport.maximumScale}`)
240
- }
241
- if (viewport.userScalable !== undefined) {
242
- parts.push(`user-scalable=${viewport.userScalable ? 'yes' : 'no'}`)
243
- }
244
- if (viewport.viewportFit !== undefined) {
245
- parts.push(`viewport-fit=${viewport.viewportFit}`)
246
- }
247
-
248
- return parts.length > 0 ? parts.join(', ') : null
249
- }
250
-
251
- /**
252
- * 두 메타데이터 객체 병합
253
- */
254
- export function mergeMetadata(
255
- parent: ResolvedMetadata,
256
- child: Metadata
257
- ): ResolvedMetadata {
258
- const metadataBase = normalizeMetadataBase(child.metadataBase) || parent.metadataBase
259
-
260
- // 부모의 title template 추출
261
- const parentTemplate = parent.title?.template || null
262
-
263
- return {
264
- metadataBase,
265
- title: resolveTitle(child.title, parentTemplate) ?? parent.title,
266
- description: child.description ?? parent.description,
267
- applicationName: child.applicationName ?? parent.applicationName,
268
- authors: resolveAuthors(child.authors) ?? parent.authors,
269
- generator: child.generator ?? parent.generator,
270
- keywords: resolveKeywords(child.keywords) ?? parent.keywords,
271
- referrer: child.referrer ?? parent.referrer,
272
- creator: child.creator ?? parent.creator,
273
- publisher: child.publisher ?? parent.publisher,
274
- robots: resolveRobots(child.robots) ?? parent.robots,
275
- alternates: parent.alternates, // TODO: resolve alternates
276
- icons: resolveIcons(child.icons, metadataBase) ?? parent.icons,
277
- manifest: resolveUrl(child.manifest, metadataBase) ?? parent.manifest,
278
- openGraph: resolveOpenGraph(child.openGraph, metadataBase) ?? parent.openGraph,
279
- twitter: resolveTwitter(child.twitter, metadataBase) ?? parent.twitter,
280
- verification: resolveVerification(child.verification) ?? parent.verification,
281
- category: child.category ?? parent.category,
282
- classification: child.classification ?? parent.classification,
283
- jsonLd: resolveJsonLd(child.jsonLd) ?? parent.jsonLd,
284
- // Google SEO 최적화
285
- google: child.google ?? parent.google,
286
- formatDetection: child.formatDetection ?? parent.formatDetection,
287
- resourceHints: child.resourceHints ?? parent.resourceHints,
288
- themeColor: resolveThemeColor(child.themeColor) ?? parent.themeColor,
289
- viewport: resolveViewport(child.viewport) ?? parent.viewport,
290
- appLinks: child.appLinks ?? parent.appLinks,
291
- other: child.other ?? parent.other,
292
- }
293
- }
294
-
295
- /**
296
- * 메타데이터 항목 해석 (정적/동적)
297
- */
298
- async function resolveMetadataItem(
299
- item: MetadataItem,
300
- params: MetadataParams,
301
- parentPromise: Promise<ResolvedMetadata>
302
- ): Promise<Metadata | null> {
303
- if (!item) return null
304
-
305
- // 정적 메타데이터
306
- if (typeof item !== 'function') {
307
- return item
308
- }
309
-
310
- // 동적 메타데이터 (generateMetadata)
311
- return await item(params, parentPromise)
312
- }
313
-
314
- /**
315
- * 전체 메타데이터 해석 파이프라인
316
- *
317
- * Layout 체인을 순회하며 메타데이터를 병합
318
- *
319
- * @param metadataItems - [rootLayout, ...nestedLayouts, page]
320
- * @param params - URL 파라미터
321
- * @param searchParams - 쿼리 파라미터
322
- */
323
- export async function resolveMetadata(
324
- metadataItems: MetadataItem[],
325
- params: Record<string, string> = {},
326
- searchParams: Record<string, string> = {}
327
- ): Promise<ResolvedMetadata> {
328
- let resolved = createDefaultMetadata()
329
-
330
- for (const item of metadataItems) {
331
- // 현재 resolved를 Promise로 래핑 (generateMetadata의 parent 파라미터용)
332
- const parentPromise = Promise.resolve(resolved)
333
-
334
- const metadata = await resolveMetadataItem(
335
- item,
336
- { params, searchParams },
337
- parentPromise
338
- )
339
-
340
- if (metadata) {
341
- resolved = mergeMetadata(resolved, metadata)
342
- }
343
- }
344
-
345
- return resolved
346
- }
347
-
348
- // Re-export sub-modules
349
- export { resolveTitle, extractTitleTemplate } from './title'
350
- export { normalizeMetadataBase, resolveUrl, urlToString } from './url'
351
- export { resolveRobots } from './robots'
352
- export { resolveOpenGraph } from './opengraph'
353
- export { resolveTwitter } from './twitter'
1
+ /**
2
+ * Mandu SEO - Metadata Resolution
3
+ *
4
+ * Layout 체인에서 메타데이터를 수집하고 병합
5
+ */
6
+
7
+ import type {
8
+ Metadata,
9
+ ResolvedMetadata,
10
+ MetadataItem,
11
+ MetadataParams,
12
+ Author,
13
+ Icons,
14
+ IconDescriptor,
15
+ ResolvedIcons,
16
+ Verification,
17
+ ResolvedVerification,
18
+ JsonLd,
19
+ ThemeColor,
20
+ ResourceHint,
21
+ FormatDetection,
22
+ GoogleMeta,
23
+ AppLinks,
24
+ } from '../types'
25
+ import { resolveTitle, extractTitleTemplate } from './title'
26
+ import { normalizeMetadataBase, resolveUrl } from './url'
27
+ import { resolveRobots } from './robots'
28
+ import { resolveOpenGraph } from './opengraph'
29
+ import { resolveTwitter } from './twitter'
30
+
31
+ /**
32
+ * 기본 메타데이터 생성
33
+ */
34
+ export function createDefaultMetadata(): ResolvedMetadata {
35
+ return {
36
+ metadataBase: null,
37
+ title: null,
38
+ description: null,
39
+ applicationName: null,
40
+ authors: null,
41
+ generator: 'Mandu',
42
+ keywords: null,
43
+ referrer: null,
44
+ creator: null,
45
+ publisher: null,
46
+ robots: null,
47
+ alternates: null,
48
+ icons: null,
49
+ manifest: null,
50
+ openGraph: null,
51
+ twitter: null,
52
+ verification: null,
53
+ category: null,
54
+ classification: null,
55
+ jsonLd: null,
56
+ // Google SEO 최적화
57
+ google: null,
58
+ formatDetection: null,
59
+ resourceHints: null,
60
+ themeColor: null,
61
+ viewport: null,
62
+ appLinks: null,
63
+ other: null,
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Author 배열로 정규화
69
+ */
70
+ function resolveAuthors(authors: Author | Author[] | null | undefined): Author[] | null {
71
+ if (!authors) return null
72
+ return Array.isArray(authors) ? authors : [authors]
73
+ }
74
+
75
+ /**
76
+ * Keywords 배열로 정규화
77
+ */
78
+ function resolveKeywords(keywords: string | string[] | null | undefined): string[] | null {
79
+ if (!keywords) return null
80
+ if (typeof keywords === 'string') {
81
+ return keywords.split(',').map(k => k.trim())
82
+ }
83
+ return keywords
84
+ }
85
+
86
+ /**
87
+ * Icons 해석
88
+ */
89
+ function resolveIcons(icons: Metadata['icons'], metadataBase: URL | null): ResolvedIcons | null {
90
+ if (!icons) return null
91
+
92
+ const result: ResolvedIcons = {
93
+ icon: [],
94
+ apple: [],
95
+ shortcut: [],
96
+ other: [],
97
+ }
98
+
99
+ // 단순 문자열 URL
100
+ if (typeof icons === 'string') {
101
+ const url = resolveUrl(icons, metadataBase)
102
+ if (url) {
103
+ result.icon.push({ url: url.href })
104
+ }
105
+ return result
106
+ }
107
+
108
+ // 배열
109
+ if (Array.isArray(icons)) {
110
+ for (const icon of icons) {
111
+ const descriptor = typeof icon === 'string'
112
+ ? { url: icon }
113
+ : icon instanceof URL
114
+ ? { url: icon.href }
115
+ : { ...icon, url: typeof icon.url === 'string' ? icon.url : icon.url.href }
116
+
117
+ const resolvedUrl = resolveUrl(descriptor.url, metadataBase)
118
+ if (resolvedUrl) {
119
+ result.icon.push({ ...descriptor, url: resolvedUrl.href })
120
+ }
121
+ }
122
+ return result
123
+ }
124
+
125
+ // Icons 객체
126
+ const iconsObj = icons as Icons
127
+
128
+ const processIconArray = (
129
+ items: typeof iconsObj.icon,
130
+ target: IconDescriptor[]
131
+ ) => {
132
+ if (!items) return
133
+ const arr = Array.isArray(items) ? items : [items]
134
+ for (const item of arr) {
135
+ const descriptor = typeof item === 'string'
136
+ ? { url: item }
137
+ : item instanceof URL
138
+ ? { url: item.href }
139
+ : { ...item, url: typeof item.url === 'string' ? item.url : item.url.href }
140
+
141
+ const resolvedUrl = resolveUrl(descriptor.url, metadataBase)
142
+ if (resolvedUrl) {
143
+ target.push({ ...descriptor, url: resolvedUrl.href })
144
+ }
145
+ }
146
+ }
147
+
148
+ processIconArray(iconsObj.icon, result.icon)
149
+ processIconArray(iconsObj.apple, result.apple)
150
+ processIconArray(iconsObj.shortcut, result.shortcut)
151
+
152
+ if (iconsObj.other) {
153
+ const others = Array.isArray(iconsObj.other) ? iconsObj.other : [iconsObj.other]
154
+ for (const other of others) {
155
+ const resolvedUrl = resolveUrl(other.url, metadataBase)
156
+ if (resolvedUrl) {
157
+ result.other.push({ ...other, url: resolvedUrl.href })
158
+ }
159
+ }
160
+ }
161
+
162
+ return result
163
+ }
164
+
165
+ /**
166
+ * Verification 해석
167
+ */
168
+ function resolveVerification(verification: Verification | null | undefined): ResolvedVerification | null {
169
+ if (!verification) return null
170
+
171
+ const toArray = (val: string | string[] | undefined): string[] | null => {
172
+ if (!val) return null
173
+ return Array.isArray(val) ? val : [val]
174
+ }
175
+
176
+ return {
177
+ google: toArray(verification.google),
178
+ yahoo: toArray(verification.yahoo),
179
+ yandex: toArray(verification.yandex),
180
+ me: toArray(verification.me),
181
+ other: verification.other
182
+ ? Object.fromEntries(
183
+ Object.entries(verification.other).map(([k, v]) => [k, toArray(v)!])
184
+ )
185
+ : null,
186
+ }
187
+ }
188
+
189
+ /**
190
+ * JSON-LD 배열로 정규화
191
+ */
192
+ function resolveJsonLd(jsonLd: JsonLd | JsonLd[] | null | undefined): JsonLd[] | null {
193
+ if (!jsonLd) return null
194
+ const arr = Array.isArray(jsonLd) ? jsonLd : [jsonLd]
195
+ // @context 기본값 추가
196
+ return arr.map(item => ({
197
+ '@context': 'https://schema.org',
198
+ ...item,
199
+ }))
200
+ }
201
+
202
+ /**
203
+ * Theme Color 배열로 정규화
204
+ */
205
+ function resolveThemeColor(
206
+ themeColor: string | ThemeColor | ThemeColor[] | null | undefined
207
+ ): ThemeColor[] | null {
208
+ if (!themeColor) return null
209
+ if (typeof themeColor === 'string') {
210
+ return [{ color: themeColor }]
211
+ }
212
+ return Array.isArray(themeColor) ? themeColor : [themeColor]
213
+ }
214
+
215
+ /**
216
+ * Viewport 문자열로 정규화
217
+ */
218
+ function resolveViewport(
219
+ viewport: Metadata['viewport']
220
+ ): string | null {
221
+ if (!viewport) return null
222
+ if (typeof viewport === 'string') return viewport
223
+
224
+ const parts: string[] = []
225
+
226
+ if (viewport.width !== undefined) {
227
+ parts.push(`width=${viewport.width}`)
228
+ }
229
+ if (viewport.height !== undefined) {
230
+ parts.push(`height=${viewport.height}`)
231
+ }
232
+ if (viewport.initialScale !== undefined) {
233
+ parts.push(`initial-scale=${viewport.initialScale}`)
234
+ }
235
+ if (viewport.minimumScale !== undefined) {
236
+ parts.push(`minimum-scale=${viewport.minimumScale}`)
237
+ }
238
+ if (viewport.maximumScale !== undefined) {
239
+ parts.push(`maximum-scale=${viewport.maximumScale}`)
240
+ }
241
+ if (viewport.userScalable !== undefined) {
242
+ parts.push(`user-scalable=${viewport.userScalable ? 'yes' : 'no'}`)
243
+ }
244
+ if (viewport.viewportFit !== undefined) {
245
+ parts.push(`viewport-fit=${viewport.viewportFit}`)
246
+ }
247
+
248
+ return parts.length > 0 ? parts.join(', ') : null
249
+ }
250
+
251
+ /**
252
+ * 두 메타데이터 객체 병합
253
+ */
254
+ export function mergeMetadata(
255
+ parent: ResolvedMetadata,
256
+ child: Metadata
257
+ ): ResolvedMetadata {
258
+ const metadataBase = normalizeMetadataBase(child.metadataBase) || parent.metadataBase
259
+
260
+ // 부모의 title template 추출
261
+ const parentTemplate = parent.title?.template || null
262
+
263
+ return {
264
+ metadataBase,
265
+ title: resolveTitle(child.title, parentTemplate) ?? parent.title,
266
+ description: child.description ?? parent.description,
267
+ applicationName: child.applicationName ?? parent.applicationName,
268
+ authors: resolveAuthors(child.authors) ?? parent.authors,
269
+ generator: child.generator ?? parent.generator,
270
+ keywords: resolveKeywords(child.keywords) ?? parent.keywords,
271
+ referrer: child.referrer ?? parent.referrer,
272
+ creator: child.creator ?? parent.creator,
273
+ publisher: child.publisher ?? parent.publisher,
274
+ robots: resolveRobots(child.robots) ?? parent.robots,
275
+ alternates: parent.alternates, // TODO: resolve alternates
276
+ icons: resolveIcons(child.icons, metadataBase) ?? parent.icons,
277
+ manifest: resolveUrl(child.manifest, metadataBase) ?? parent.manifest,
278
+ openGraph: resolveOpenGraph(child.openGraph, metadataBase) ?? parent.openGraph,
279
+ twitter: resolveTwitter(child.twitter, metadataBase) ?? parent.twitter,
280
+ verification: resolveVerification(child.verification) ?? parent.verification,
281
+ category: child.category ?? parent.category,
282
+ classification: child.classification ?? parent.classification,
283
+ jsonLd: resolveJsonLd(child.jsonLd) ?? parent.jsonLd,
284
+ // Google SEO 최적화
285
+ google: child.google ?? parent.google,
286
+ formatDetection: child.formatDetection ?? parent.formatDetection,
287
+ resourceHints: child.resourceHints ?? parent.resourceHints,
288
+ themeColor: resolveThemeColor(child.themeColor) ?? parent.themeColor,
289
+ viewport: resolveViewport(child.viewport) ?? parent.viewport,
290
+ appLinks: child.appLinks ?? parent.appLinks,
291
+ other: child.other ?? parent.other,
292
+ }
293
+ }
294
+
295
+ /**
296
+ * 메타데이터 항목 해석 (정적/동적)
297
+ */
298
+ async function resolveMetadataItem(
299
+ item: MetadataItem,
300
+ params: MetadataParams,
301
+ parentPromise: Promise<ResolvedMetadata>
302
+ ): Promise<Metadata | null> {
303
+ if (!item) return null
304
+
305
+ // 정적 메타데이터
306
+ if (typeof item !== 'function') {
307
+ return item
308
+ }
309
+
310
+ // 동적 메타데이터 (generateMetadata)
311
+ return await item(params, parentPromise)
312
+ }
313
+
314
+ /**
315
+ * 전체 메타데이터 해석 파이프라인
316
+ *
317
+ * Layout 체인을 순회하며 메타데이터를 병합
318
+ *
319
+ * @param metadataItems - [rootLayout, ...nestedLayouts, page]
320
+ * @param params - URL 파라미터
321
+ * @param searchParams - 쿼리 파라미터
322
+ */
323
+ export async function resolveMetadata(
324
+ metadataItems: MetadataItem[],
325
+ params: Record<string, string> = {},
326
+ searchParams: Record<string, string> = {}
327
+ ): Promise<ResolvedMetadata> {
328
+ let resolved = createDefaultMetadata()
329
+
330
+ for (const item of metadataItems) {
331
+ // 현재 resolved를 Promise로 래핑 (generateMetadata의 parent 파라미터용)
332
+ const parentPromise = Promise.resolve(resolved)
333
+
334
+ const metadata = await resolveMetadataItem(
335
+ item,
336
+ { params, searchParams },
337
+ parentPromise
338
+ )
339
+
340
+ if (metadata) {
341
+ resolved = mergeMetadata(resolved, metadata)
342
+ }
343
+ }
344
+
345
+ return resolved
346
+ }
347
+
348
+ // Re-export sub-modules
349
+ export { resolveTitle, extractTitleTemplate } from './title'
350
+ export { normalizeMetadataBase, resolveUrl, urlToString } from './url'
351
+ export { resolveRobots } from './robots'
352
+ export { resolveOpenGraph } from './opengraph'
353
+ export { resolveTwitter } from './twitter'