@notion-headless-cms/core 0.3.3 → 0.3.5
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/dist/{hooks-DwCisXsr.d.mts → hooks-D8Lgf-Co.d.mts} +13 -3
- package/dist/hooks.d.mts +1 -1
- package/dist/hooks.mjs +2 -0
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +32 -5
- package/dist/index.mjs +178 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CachedItem, t as BaseContentItem } from "./content-WydAfQtk.mjs";
|
|
1
|
+
import { i as CachedItemList, r as CachedItem, t as BaseContentItem } from "./content-WydAfQtk.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/types/hooks.d.ts
|
|
4
4
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -7,8 +7,12 @@ interface CMSHooks<T extends BaseContentItem = BaseContentItem> {
|
|
|
7
7
|
afterRender?: (html: string, item: T) => MaybePromise<string>;
|
|
8
8
|
onCacheHit?: (slug: string, item: CachedItem<T>) => void;
|
|
9
9
|
onCacheMiss?: (slug: string) => void;
|
|
10
|
-
|
|
10
|
+
/** SWR バックグラウンド差分チェックで更新を検出し、キャッシュを差し替えたときに呼ばれる。 */
|
|
11
|
+
onCacheRevalidated?: (slug: string, item: CachedItem<T>) => void;
|
|
12
|
+
onListCacheHit?: (list: CachedItemList<T>) => void;
|
|
11
13
|
onListCacheMiss?: () => void;
|
|
14
|
+
/** SWR バックグラウンド差分チェックでリスト更新を検出し、キャッシュを差し替えたときに呼ばれる。 */
|
|
15
|
+
onListCacheRevalidated?: (list: CachedItemList<T>) => void;
|
|
12
16
|
onError?: (error: Error) => void;
|
|
13
17
|
onRenderStart?: (slug: string) => void;
|
|
14
18
|
onRenderEnd?: (slug: string, durationMs: number) => void;
|
|
@@ -27,6 +31,12 @@ interface LogContext {
|
|
|
27
31
|
attempt?: number;
|
|
28
32
|
status?: number;
|
|
29
33
|
error?: string;
|
|
34
|
+
collection?: string;
|
|
35
|
+
cacheAdapter?: string;
|
|
36
|
+
/** キャッシュが保存された時刻(ms)。ヒット時の鮮度確認用 */
|
|
37
|
+
cachedAt?: number;
|
|
38
|
+
/** 画像キャッシュの SHA256 ハッシュキー。ストレージと対応付け用 */
|
|
39
|
+
imageHash?: string;
|
|
30
40
|
[key: string]: unknown;
|
|
31
41
|
}
|
|
32
42
|
interface Logger {
|
|
@@ -57,4 +67,4 @@ declare function mergeLoggers(plugins: Array<{
|
|
|
57
67
|
}>, directLogger?: Logger): Logger | undefined;
|
|
58
68
|
//#endregion
|
|
59
69
|
export { Logger as a, definePlugin as i, mergeLoggers as n, CMSHooks as o, CMSPlugin as r, MaybePromise as s, mergeHooks as t };
|
|
60
|
-
//# sourceMappingURL=hooks-
|
|
70
|
+
//# sourceMappingURL=hooks-D8Lgf-Co.d.mts.map
|
package/dist/hooks.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as mergeLoggers, t as mergeHooks } from "./hooks-
|
|
1
|
+
import { n as mergeLoggers, t as mergeHooks } from "./hooks-D8Lgf-Co.mjs";
|
|
2
2
|
export { mergeHooks, mergeLoggers };
|
package/dist/hooks.mjs
CHANGED
|
@@ -12,8 +12,10 @@ function mergeHooks(plugins, directHooks, logger) {
|
|
|
12
12
|
afterRender: buildRenderPipeline(allHooks),
|
|
13
13
|
onCacheHit: buildObserver(allHooks, "onCacheHit", logger),
|
|
14
14
|
onCacheMiss: buildObserver(allHooks, "onCacheMiss", logger),
|
|
15
|
+
onCacheRevalidated: buildObserver(allHooks, "onCacheRevalidated", logger),
|
|
15
16
|
onListCacheHit: buildObserver(allHooks, "onListCacheHit", logger),
|
|
16
17
|
onListCacheMiss: buildObserver(allHooks, "onListCacheMiss", logger),
|
|
18
|
+
onListCacheRevalidated: buildObserver(allHooks, "onListCacheRevalidated", logger),
|
|
17
19
|
onError: buildObserver(allHooks, "onError", logger),
|
|
18
20
|
onRenderStart: buildObserver(allHooks, "onRenderStart", logger),
|
|
19
21
|
onRenderEnd: buildObserver(allHooks, "onRenderEnd", logger)
|
package/dist/hooks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.mjs","names":[],"sources":["../src/hooks.ts"],"sourcesContent":["import type { BaseContentItem } from \"./types/content\";\nimport type { CMSHooks, MaybePromise } from \"./types/hooks\";\nimport type { Logger } from \"./types/logger\";\nimport type { CMSPlugin } from \"./types/plugin\";\n\n/**\n * プラグイン配列とダイレクトフックを合成して単一の CMSHooks を返す。\n * beforeCache / afterRender はパイプライン(前の出力が次の入力)。\n * onCacheHit などオブザーバー系は全員に同じ値を渡し、例外は logger に流して握りつぶす。\n */\nexport function mergeHooks<T extends BaseContentItem>(\n\tplugins: CMSPlugin<T>[],\n\tdirectHooks?: CMSHooks<T>,\n\tlogger?: Logger,\n): CMSHooks<T> {\n\tconst allHooks: CMSHooks<T>[] = [\n\t\t...plugins.map((p) => p.hooks ?? {}),\n\t\t...(directHooks ? [directHooks] : []),\n\t];\n\n\tif (allHooks.length === 0) return {};\n\n\treturn {\n\t\tbeforeCache: buildPipeline(allHooks, \"beforeCache\"),\n\t\tafterRender: buildRenderPipeline(allHooks),\n\t\tonCacheHit: buildObserver(allHooks, \"onCacheHit\", logger),\n\t\tonCacheMiss: buildObserver(allHooks, \"onCacheMiss\", logger),\n\t\tonListCacheHit: buildObserver(allHooks, \"onListCacheHit\", logger),\n\t\tonListCacheMiss: buildObserver(allHooks, \"onListCacheMiss\", logger),\n\t\tonError: buildObserver(allHooks, \"onError\", logger),\n\t\tonRenderStart: buildObserver(allHooks, \"onRenderStart\", logger),\n\t\tonRenderEnd: buildObserver(allHooks, \"onRenderEnd\", logger),\n\t};\n}\n\nfunction buildPipeline<T extends BaseContentItem>(\n\thooks: CMSHooks<T>[],\n\tkey: \"beforeCache\",\n): CMSHooks<T>[\"beforeCache\"] {\n\tconst fns = hooks.map((h) => h[key]).filter(Boolean) as NonNullable<\n\t\tCMSHooks<T>[\"beforeCache\"]\n\t>[];\n\tif (fns.length === 0) return undefined;\n\treturn async (item) => {\n\t\tlet current = item;\n\t\tfor (const fn of fns) {\n\t\t\tcurrent = await (fn(current) as MaybePromise<typeof item>);\n\t\t}\n\t\treturn current;\n\t};\n}\n\nfunction buildRenderPipeline<T extends BaseContentItem>(\n\thooks: CMSHooks<T>[],\n): CMSHooks<T>[\"afterRender\"] {\n\tconst fns = hooks.map((h) => h.afterRender).filter(Boolean) as NonNullable<\n\t\tCMSHooks<T>[\"afterRender\"]\n\t>[];\n\tif (fns.length === 0) return undefined;\n\treturn async (html, item) => {\n\t\tlet current = html;\n\t\tfor (const fn of fns) {\n\t\t\tcurrent = await (fn(current, item) as MaybePromise<string>);\n\t\t}\n\t\treturn current;\n\t};\n}\n\nfunction buildObserver<T extends BaseContentItem, K extends keyof CMSHooks<T>>(\n\thooks: CMSHooks<T>[],\n\tkey: K,\n\tlogger?: Logger,\n): CMSHooks<T>[K] {\n\tconst fns = hooks.map((h) => h[key]).filter(Boolean);\n\tif (fns.length === 0) return undefined;\n\treturn ((...args: unknown[]) => {\n\t\tfor (const fn of fns) {\n\t\t\ttry {\n\t\t\t\t(fn as (...a: unknown[]) => void)(...args);\n\t\t\t} catch (err) {\n\t\t\t\tlogger?.error?.(\"観測フックで例外が発生\", {\n\t\t\t\t\thook: String(key),\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}) as CMSHooks<T>[K];\n}\n\n/** プラグイン配列とダイレクトロガーを合成して単一の Logger を返す。 */\nexport function mergeLoggers(\n\tplugins: Array<{ logger?: Partial<Logger> }>,\n\tdirectLogger?: Logger,\n): Logger | undefined {\n\tconst loggers: Partial<Logger>[] = [\n\t\t...plugins.map((p) => p.logger ?? {}),\n\t\t...(directLogger ? [directLogger] : []),\n\t];\n\tif (loggers.length === 0) return undefined;\n\n\tconst merged: Logger = {};\n\tfor (const level of [\"debug\", \"info\", \"warn\", \"error\"] as const) {\n\t\tconst fns = loggers.map((l) => l[level]).filter(Boolean) as NonNullable<\n\t\t\tLogger[typeof level]\n\t\t>[];\n\t\tif (fns.length > 0) {\n\t\t\tmerged[level] = (message, context) => {\n\t\t\t\tfor (const fn of fns) fn(message, context);\n\t\t\t};\n\t\t}\n\t}\n\treturn merged;\n}\n"],"mappings":";;;;;;AAUA,SAAgB,WACf,SACA,aACA,QACc;CACd,MAAM,WAA0B,CAC/B,GAAG,QAAQ,KAAK,MAAM,EAAE,SAAS,EAAE,CAAC,EACpC,GAAI,cAAc,CAAC,YAAY,GAAG,EAAE,CACpC;AAED,KAAI,SAAS,WAAW,EAAG,QAAO,EAAE;AAEpC,QAAO;EACN,aAAa,cAAc,UAAU,cAAc;EACnD,aAAa,oBAAoB,SAAS;EAC1C,YAAY,cAAc,UAAU,cAAc,OAAO;EACzD,aAAa,cAAc,UAAU,eAAe,OAAO;EAC3D,gBAAgB,cAAc,UAAU,kBAAkB,OAAO;EACjE,iBAAiB,cAAc,UAAU,mBAAmB,OAAO;EACnE,SAAS,cAAc,UAAU,WAAW,OAAO;EACnD,eAAe,cAAc,UAAU,iBAAiB,OAAO;EAC/D,aAAa,cAAc,UAAU,eAAe,OAAO;EAC3D;;AAGF,SAAS,cACR,OACA,KAC6B;CAC7B,MAAM,MAAM,MAAM,KAAK,MAAM,EAAE,KAAK,CAAC,OAAO,QAAQ;AAGpD,KAAI,IAAI,WAAW,EAAG,QAAO,KAAA;AAC7B,QAAO,OAAO,SAAS;EACtB,IAAI,UAAU;AACd,OAAK,MAAM,MAAM,IAChB,WAAU,MAAO,GAAG,QAAQ;AAE7B,SAAO;;;AAIT,SAAS,oBACR,OAC6B;CAC7B,MAAM,MAAM,MAAM,KAAK,MAAM,EAAE,YAAY,CAAC,OAAO,QAAQ;AAG3D,KAAI,IAAI,WAAW,EAAG,QAAO,KAAA;AAC7B,QAAO,OAAO,MAAM,SAAS;EAC5B,IAAI,UAAU;AACd,OAAK,MAAM,MAAM,IAChB,WAAU,MAAO,GAAG,SAAS,KAAK;AAEnC,SAAO;;;AAIT,SAAS,cACR,OACA,KACA,QACiB;CACjB,MAAM,MAAM,MAAM,KAAK,MAAM,EAAE,KAAK,CAAC,OAAO,QAAQ;AACpD,KAAI,IAAI,WAAW,EAAG,QAAO,KAAA;AAC7B,UAAS,GAAG,SAAoB;AAC/B,OAAK,MAAM,MAAM,IAChB,KAAI;AACF,MAAiC,GAAG,KAAK;WAClC,KAAK;AACb,WAAQ,QAAQ,eAAe;IAC9B,MAAM,OAAO,IAAI;IACjB,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;IACvD,CAAC;;;;;AAON,SAAgB,aACf,SACA,cACqB;CACrB,MAAM,UAA6B,CAClC,GAAG,QAAQ,KAAK,MAAM,EAAE,UAAU,EAAE,CAAC,EACrC,GAAI,eAAe,CAAC,aAAa,GAAG,EAAE,CACtC;AACD,KAAI,QAAQ,WAAW,EAAG,QAAO,KAAA;CAEjC,MAAM,SAAiB,EAAE;AACzB,MAAK,MAAM,SAAS;EAAC;EAAS;EAAQ;EAAQ;EAAQ,EAAW;EAChE,MAAM,MAAM,QAAQ,KAAK,MAAM,EAAE,OAAO,CAAC,OAAO,QAAQ;AAGxD,MAAI,IAAI,SAAS,EAChB,QAAO,UAAU,SAAS,YAAY;AACrC,QAAK,MAAM,MAAM,IAAK,IAAG,SAAS,QAAQ;;;AAI7C,QAAO"}
|
|
1
|
+
{"version":3,"file":"hooks.mjs","names":[],"sources":["../src/hooks.ts"],"sourcesContent":["import type { BaseContentItem } from \"./types/content\";\nimport type { CMSHooks, MaybePromise } from \"./types/hooks\";\nimport type { Logger } from \"./types/logger\";\nimport type { CMSPlugin } from \"./types/plugin\";\n\n/**\n * プラグイン配列とダイレクトフックを合成して単一の CMSHooks を返す。\n * beforeCache / afterRender はパイプライン(前の出力が次の入力)。\n * onCacheHit などオブザーバー系は全員に同じ値を渡し、例外は logger に流して握りつぶす。\n */\nexport function mergeHooks<T extends BaseContentItem>(\n\tplugins: CMSPlugin<T>[],\n\tdirectHooks?: CMSHooks<T>,\n\tlogger?: Logger,\n): CMSHooks<T> {\n\tconst allHooks: CMSHooks<T>[] = [\n\t\t...plugins.map((p) => p.hooks ?? {}),\n\t\t...(directHooks ? [directHooks] : []),\n\t];\n\n\tif (allHooks.length === 0) return {};\n\n\treturn {\n\t\tbeforeCache: buildPipeline(allHooks, \"beforeCache\"),\n\t\tafterRender: buildRenderPipeline(allHooks),\n\t\tonCacheHit: buildObserver(allHooks, \"onCacheHit\", logger),\n\t\tonCacheMiss: buildObserver(allHooks, \"onCacheMiss\", logger),\n\t\tonCacheRevalidated: buildObserver(allHooks, \"onCacheRevalidated\", logger),\n\t\tonListCacheHit: buildObserver(allHooks, \"onListCacheHit\", logger),\n\t\tonListCacheMiss: buildObserver(allHooks, \"onListCacheMiss\", logger),\n\t\tonListCacheRevalidated: buildObserver(\n\t\t\tallHooks,\n\t\t\t\"onListCacheRevalidated\",\n\t\t\tlogger,\n\t\t),\n\t\tonError: buildObserver(allHooks, \"onError\", logger),\n\t\tonRenderStart: buildObserver(allHooks, \"onRenderStart\", logger),\n\t\tonRenderEnd: buildObserver(allHooks, \"onRenderEnd\", logger),\n\t};\n}\n\nfunction buildPipeline<T extends BaseContentItem>(\n\thooks: CMSHooks<T>[],\n\tkey: \"beforeCache\",\n): CMSHooks<T>[\"beforeCache\"] {\n\tconst fns = hooks.map((h) => h[key]).filter(Boolean) as NonNullable<\n\t\tCMSHooks<T>[\"beforeCache\"]\n\t>[];\n\tif (fns.length === 0) return undefined;\n\treturn async (item) => {\n\t\tlet current = item;\n\t\tfor (const fn of fns) {\n\t\t\tcurrent = await (fn(current) as MaybePromise<typeof item>);\n\t\t}\n\t\treturn current;\n\t};\n}\n\nfunction buildRenderPipeline<T extends BaseContentItem>(\n\thooks: CMSHooks<T>[],\n): CMSHooks<T>[\"afterRender\"] {\n\tconst fns = hooks.map((h) => h.afterRender).filter(Boolean) as NonNullable<\n\t\tCMSHooks<T>[\"afterRender\"]\n\t>[];\n\tif (fns.length === 0) return undefined;\n\treturn async (html, item) => {\n\t\tlet current = html;\n\t\tfor (const fn of fns) {\n\t\t\tcurrent = await (fn(current, item) as MaybePromise<string>);\n\t\t}\n\t\treturn current;\n\t};\n}\n\nfunction buildObserver<T extends BaseContentItem, K extends keyof CMSHooks<T>>(\n\thooks: CMSHooks<T>[],\n\tkey: K,\n\tlogger?: Logger,\n): CMSHooks<T>[K] {\n\tconst fns = hooks.map((h) => h[key]).filter(Boolean);\n\tif (fns.length === 0) return undefined;\n\treturn ((...args: unknown[]) => {\n\t\tfor (const fn of fns) {\n\t\t\ttry {\n\t\t\t\t(fn as (...a: unknown[]) => void)(...args);\n\t\t\t} catch (err) {\n\t\t\t\tlogger?.error?.(\"観測フックで例外が発生\", {\n\t\t\t\t\thook: String(key),\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}) as CMSHooks<T>[K];\n}\n\n/** プラグイン配列とダイレクトロガーを合成して単一の Logger を返す。 */\nexport function mergeLoggers(\n\tplugins: Array<{ logger?: Partial<Logger> }>,\n\tdirectLogger?: Logger,\n): Logger | undefined {\n\tconst loggers: Partial<Logger>[] = [\n\t\t...plugins.map((p) => p.logger ?? {}),\n\t\t...(directLogger ? [directLogger] : []),\n\t];\n\tif (loggers.length === 0) return undefined;\n\n\tconst merged: Logger = {};\n\tfor (const level of [\"debug\", \"info\", \"warn\", \"error\"] as const) {\n\t\tconst fns = loggers.map((l) => l[level]).filter(Boolean) as NonNullable<\n\t\t\tLogger[typeof level]\n\t\t>[];\n\t\tif (fns.length > 0) {\n\t\t\tmerged[level] = (message, context) => {\n\t\t\t\tfor (const fn of fns) fn(message, context);\n\t\t\t};\n\t\t}\n\t}\n\treturn merged;\n}\n"],"mappings":";;;;;;AAUA,SAAgB,WACf,SACA,aACA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AAG,QAAO,KAAA;AAC7B,UAAS,GAAG,SAAoB;AAC/B,OAAK,MAAM,MAAM,IAChB,KAAI;AACF,MAAiC,GAAG,KAAK;WAClC,KAAK;AACb,WAAQ,QAAQ,eAAe;IAC9B,MAAM,OAAO,IAAI;IACjB,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;IACvD,CAAC;;;;;AAON,SAAgB,aACf,SACA,cACqB;CACrB,MAAM,UAA6B,CAClC,GAAG,QAAQ,KAAK,MAAM,EAAE,UAAU,EAAE,CAAC,EACrC,GAAI,eAAe,CAAC,aAAa,GAAG,EAAE,CACtC;AACD,KAAI,QAAQ,WAAW,EAAG,QAAO,KAAA;CAEjC,MAAM,SAAiB,EAAE;AACzB,MAAK,MAAM,SAAS;EAAC;EAAS;EAAQ;EAAQ;EAAQ,EAAW;EAChE,MAAM,MAAM,QAAQ,KAAK,MAAM,EAAE,OAAO,CAAC,OAAO,QAAQ;AAGxD,MAAI,IAAI,SAAS,EAChB,QAAO,UAAU,SAAS,YAAY;AACrC,QAAK,MAAM,MAAM,IAAK,IAAG,SAAS,QAAQ;;;AAI7C,QAAO"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as StorageBinary, c as ImageRef, i as CachedItemList, l as InlineNode, n as CMSSchemaProperties, o as ContentBlock, r as CachedItem, s as ContentResult, t as BaseContentItem } from "./content-WydAfQtk.mjs";
|
|
2
2
|
import { a as CollectionConfig, c as InferCollectionItem, d as PropertyMap, f as WebhookConfig, i as CMSSchema, l as InvalidateScope, n as DocumentCacheAdapter, o as DataSource, r as ImageCacheAdapter, s as DataSourceFactory, t as CacheConfig, u as PropertyDef } from "./cache-D051BP4G.mjs";
|
|
3
|
-
import { a as Logger, i as definePlugin, n as mergeLoggers, o as CMSHooks, r as CMSPlugin, s as MaybePromise, t as mergeHooks } from "./hooks-
|
|
3
|
+
import { a as Logger, i as definePlugin, n as mergeLoggers, o as CMSHooks, r as CMSPlugin, s as MaybePromise, t as mergeHooks } from "./hooks-D8Lgf-Co.mjs";
|
|
4
4
|
import { MemoryDocumentCacheOptions, MemoryImageCacheOptions, memoryDocumentCache, memoryImageCache } from "./cache/memory.mjs";
|
|
5
5
|
import { noopDocumentCache, noopImageCache } from "./cache/noop.mjs";
|
|
6
6
|
import { CMSError, CMSErrorCode, CMSErrorContext, isCMSError, isCMSErrorInNamespace } from "./errors.mjs";
|
|
@@ -71,6 +71,8 @@ interface CollectionClient<T extends BaseContentItem = BaseContentItem> {
|
|
|
71
71
|
}
|
|
72
72
|
//#endregion
|
|
73
73
|
//#region src/types/config.d.ts
|
|
74
|
+
/** `Logger` の出力を絞り込むログレベル。指定したレベル未満のログを抑制する。 */
|
|
75
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
74
76
|
/**
|
|
75
77
|
* renderer プラグインの不透明型。
|
|
76
78
|
* core は unified / remark / rehype に依存せず、このリストをそのまま renderer に渡すだけ。
|
|
@@ -113,8 +115,12 @@ type DataSourceMap = Record<string, DataSource<any>>;
|
|
|
113
115
|
/**
|
|
114
116
|
* コレクション別のページ構成セマンティクス。
|
|
115
117
|
* `createCMS({ collections: { posts: { ... } } })` に渡す。
|
|
118
|
+
*
|
|
119
|
+
* `T` を指定するとコレクション固有の型付きフックを定義できる。
|
|
120
|
+
* `createCMS` の `dataSources` から `T` が自動推論されるため、アプリ側が
|
|
121
|
+
* `CMSHooks<Post>` などを直接記述する必要がなくなる。
|
|
116
122
|
*/
|
|
117
|
-
interface CollectionSemantics {
|
|
123
|
+
interface CollectionSemantics<T extends BaseContentItem = BaseContentItem> {
|
|
118
124
|
/**
|
|
119
125
|
* slug として使うフィールド名(必須)。
|
|
120
126
|
* DataSource の `properties` マップのキーと一致させる。
|
|
@@ -131,6 +137,12 @@ interface CollectionSemantics {
|
|
|
131
137
|
* アクセス許可するステータス値。DataSource 側の `accessibleStatuses` より優先される。
|
|
132
138
|
*/
|
|
133
139
|
accessibleStatuses?: readonly string[];
|
|
140
|
+
/**
|
|
141
|
+
* コレクション固有のライフサイクルフック。
|
|
142
|
+
* トップレベルの `hooks` と合成して実行される(グローバルフック → コレクションフックの順)。
|
|
143
|
+
* `T` が確定しているため `item.item.myField` など独自フィールドに型安全にアクセスできる。
|
|
144
|
+
*/
|
|
145
|
+
hooks?: CMSHooks<T>;
|
|
134
146
|
}
|
|
135
147
|
/** `DataSourceMap` から各 T を抽出するユーティリティ型。 */
|
|
136
148
|
type InferDataSourceItem<D> = D extends DataSource<infer T> ? T : BaseContentItem;
|
|
@@ -182,28 +194,43 @@ interface CreateCMSOptions<D extends DataSourceMap = DataSourceMap> {
|
|
|
182
194
|
plugins?: CMSPlugin<any>[];
|
|
183
195
|
/** ロガー。 */
|
|
184
196
|
logger?: Logger;
|
|
197
|
+
/**
|
|
198
|
+
* ログレベルの下限。指定したレベル未満のログを内部で抑制する。
|
|
199
|
+
* Cloudflare Workers の Observability のように debug ログが課金対象になる環境では
|
|
200
|
+
* `"info"` を指定すると debug ログを出力しなくなる。
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* createCMS({ ..., logLevel: "info" }) // debug ログを抑制
|
|
204
|
+
*/
|
|
205
|
+
logLevel?: LogLevel;
|
|
185
206
|
/** レートリミット・リトライ設定。 */
|
|
186
207
|
rateLimiter?: RateLimiterConfig;
|
|
187
208
|
/**
|
|
188
209
|
* コレクション別のページ構成セマンティクス。
|
|
189
|
-
* slug・status
|
|
210
|
+
* slug・status・公開条件・コレクション固有フックを指定する。
|
|
190
211
|
* 指定したコレクションでは `slug` が必須(未指定時はエラー)。
|
|
191
212
|
* 指定したコレクションの `publishedStatuses`/`accessibleStatuses` は
|
|
192
213
|
* DataSource 側の設定より優先される。
|
|
193
214
|
*
|
|
215
|
+
* `hooks` にコレクション固有フックを定義すると、`dataSources` の型から `T` が
|
|
216
|
+
* 自動推論されるため `CMSHooks<Post>` などを直接書かずに済む。
|
|
217
|
+
*
|
|
194
218
|
* @example
|
|
195
219
|
* createCMS({
|
|
196
|
-
* dataSources: { posts: createNotionCollection({ ... }) },
|
|
220
|
+
* dataSources: { posts: createNotionCollection<Post>({ ... }) },
|
|
197
221
|
* collections: {
|
|
198
222
|
* posts: {
|
|
199
223
|
* slug: "slug",
|
|
200
224
|
* status: "status",
|
|
201
225
|
* publishedStatuses: ["公開済み"],
|
|
226
|
+
* hooks: {
|
|
227
|
+
* onCacheHit: (slug, item) => console.log(item.item.title),
|
|
228
|
+
* },
|
|
202
229
|
* }
|
|
203
230
|
* }
|
|
204
231
|
* })
|
|
205
232
|
*/
|
|
206
|
-
collections?:
|
|
233
|
+
collections?: { [K in keyof D]?: CollectionSemantics<InferDataSourceItem<D[K]>> };
|
|
207
234
|
}
|
|
208
235
|
//#endregion
|
|
209
236
|
//#region src/cache.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -31,10 +31,22 @@ function inferContentType(url, responseContentType) {
|
|
|
31
31
|
* Notion画像URLをfetchしてImageCacheAdapterにキャッシュし、プロキシURL を返す。
|
|
32
32
|
* 既存キャッシュがあれば再fetchしない。
|
|
33
33
|
*/
|
|
34
|
-
async function fetchAndCacheImage(cache, notionUrl, imageProxyBase) {
|
|
34
|
+
async function fetchAndCacheImage(cache, notionUrl, imageProxyBase, logger) {
|
|
35
35
|
const hash = await sha256Hex(notionUrl);
|
|
36
36
|
const proxyUrl = `${imageProxyBase}/${hash}`;
|
|
37
|
-
if (await cache.get(hash))
|
|
37
|
+
if (await cache.get(hash)) {
|
|
38
|
+
logger?.debug?.("画像キャッシュヒット", {
|
|
39
|
+
operation: "fetchAndCacheImage",
|
|
40
|
+
cacheAdapter: cache.name,
|
|
41
|
+
imageHash: hash
|
|
42
|
+
});
|
|
43
|
+
return proxyUrl;
|
|
44
|
+
}
|
|
45
|
+
logger?.debug?.("画像キャッシュミス、Notion からフェッチ", {
|
|
46
|
+
operation: "fetchAndCacheImage",
|
|
47
|
+
cacheAdapter: cache.name,
|
|
48
|
+
imageHash: hash
|
|
49
|
+
});
|
|
38
50
|
try {
|
|
39
51
|
const response = await fetch(notionUrl, { signal: AbortSignal.timeout(1e4) });
|
|
40
52
|
if (!response.ok) throw new CMSError({
|
|
@@ -49,6 +61,11 @@ async function fetchAndCacheImage(cache, notionUrl, imageProxyBase) {
|
|
|
49
61
|
const data = await response.arrayBuffer();
|
|
50
62
|
const contentType = inferContentType(notionUrl, response.headers.get("content-type"));
|
|
51
63
|
await cache.set(hash, data, contentType);
|
|
64
|
+
logger?.debug?.("画像をキャッシュに保存", {
|
|
65
|
+
operation: "fetchAndCacheImage",
|
|
66
|
+
cacheAdapter: cache.name,
|
|
67
|
+
imageHash: hash
|
|
68
|
+
});
|
|
52
69
|
} catch (err) {
|
|
53
70
|
if (isCMSError(err)) throw err;
|
|
54
71
|
throw new CMSError({
|
|
@@ -64,8 +81,8 @@ async function fetchAndCacheImage(cache, notionUrl, imageProxyBase) {
|
|
|
64
81
|
return proxyUrl;
|
|
65
82
|
}
|
|
66
83
|
/** ImageCacheAdapter と imageProxyBase から cacheImage 関数を構築するファクトリ。 */
|
|
67
|
-
function buildCacheImageFn(cache, imageProxyBase) {
|
|
68
|
-
return (notionUrl) => fetchAndCacheImage(cache, notionUrl, imageProxyBase);
|
|
84
|
+
function buildCacheImageFn(cache, imageProxyBase, logger) {
|
|
85
|
+
return (notionUrl) => fetchAndCacheImage(cache, notionUrl, imageProxyBase, logger);
|
|
69
86
|
}
|
|
70
87
|
//#endregion
|
|
71
88
|
//#region src/rendering.ts
|
|
@@ -106,7 +123,7 @@ async function buildCachedItem(item, ctx) {
|
|
|
106
123
|
});
|
|
107
124
|
blocks = [];
|
|
108
125
|
}
|
|
109
|
-
const cacheImage = ctx.hasImageCache ? buildCacheImageFn(ctx.imgCache, ctx.imageProxyBase) : void 0;
|
|
126
|
+
const cacheImage = ctx.hasImageCache ? buildCacheImageFn(ctx.imgCache, ctx.imageProxyBase, ctx.logger) : void 0;
|
|
110
127
|
let html;
|
|
111
128
|
const rendererFn = ctx.rendererFn ?? await loadDefaultRenderer();
|
|
112
129
|
try {
|
|
@@ -212,6 +229,12 @@ var CollectionClientImpl = class {
|
|
|
212
229
|
const cached = await this.ctx.docCache.getItem(slug);
|
|
213
230
|
if (cached) {
|
|
214
231
|
if (this.ctx.ttlMs !== void 0 && isStale(cached.cachedAt, this.ctx.ttlMs)) {
|
|
232
|
+
this.ctx.logger?.debug?.("キャッシュ期限切れ(TTL)、フェッチ", {
|
|
233
|
+
operation: "getItem",
|
|
234
|
+
slug,
|
|
235
|
+
collection: this.ctx.collection,
|
|
236
|
+
cacheAdapter: this.ctx.docCache.name
|
|
237
|
+
});
|
|
215
238
|
this.ctx.hooks.onCacheMiss?.(slug);
|
|
216
239
|
const item = await this.findRaw(slug);
|
|
217
240
|
if (!item) return null;
|
|
@@ -221,12 +244,32 @@ var CollectionClientImpl = class {
|
|
|
221
244
|
}
|
|
222
245
|
const bg = this.checkAndUpdateItemBg(slug, cached);
|
|
223
246
|
if (this.ctx.waitUntil) this.ctx.waitUntil(bg);
|
|
247
|
+
this.ctx.logger?.debug?.("キャッシュヒット", {
|
|
248
|
+
operation: "getItem",
|
|
249
|
+
slug,
|
|
250
|
+
collection: this.ctx.collection,
|
|
251
|
+
cacheAdapter: this.ctx.docCache.name,
|
|
252
|
+
cachedAt: cached.cachedAt
|
|
253
|
+
});
|
|
224
254
|
this.ctx.hooks.onCacheHit?.(slug, cached);
|
|
225
255
|
return this.attachContent(cached.item, cached);
|
|
226
256
|
}
|
|
257
|
+
this.ctx.logger?.debug?.("キャッシュミス、フェッチ", {
|
|
258
|
+
operation: "getItem",
|
|
259
|
+
slug,
|
|
260
|
+
collection: this.ctx.collection,
|
|
261
|
+
cacheAdapter: this.ctx.docCache.name
|
|
262
|
+
});
|
|
227
263
|
this.ctx.hooks.onCacheMiss?.(slug);
|
|
228
264
|
const item = await this.findRaw(slug);
|
|
229
|
-
if (!item)
|
|
265
|
+
if (!item) {
|
|
266
|
+
this.ctx.logger?.debug?.("アイテムが見つかりません", {
|
|
267
|
+
operation: "getItem",
|
|
268
|
+
slug,
|
|
269
|
+
collection: this.ctx.collection
|
|
270
|
+
});
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
230
273
|
const entry = await buildCachedItem(item, this.ctx.render);
|
|
231
274
|
const save = this.ctx.docCache.setItem(slug, entry);
|
|
232
275
|
if (this.ctx.waitUntil) this.ctx.waitUntil(save);
|
|
@@ -255,6 +298,12 @@ var CollectionClientImpl = class {
|
|
|
255
298
|
};
|
|
256
299
|
}
|
|
257
300
|
async revalidate(scope) {
|
|
301
|
+
this.ctx.logger?.debug?.("キャッシュを無効化", {
|
|
302
|
+
operation: "revalidate",
|
|
303
|
+
collection: this.ctx.collection,
|
|
304
|
+
cacheAdapter: this.ctx.docCache.name,
|
|
305
|
+
slug: typeof scope === "object" ? scope.slug : void 0
|
|
306
|
+
});
|
|
258
307
|
if (!this.ctx.docCache.invalidate) return;
|
|
259
308
|
if (scope === void 0 || scope === "all") await this.ctx.docCache.invalidate({ collection: this.ctx.collection });
|
|
260
309
|
else await this.ctx.docCache.invalidate({
|
|
@@ -325,6 +374,11 @@ var CollectionClientImpl = class {
|
|
|
325
374
|
const cached = await this.ctx.docCache.getList();
|
|
326
375
|
if (cached) {
|
|
327
376
|
if (this.ctx.ttlMs !== void 0 && isStale(cached.cachedAt, this.ctx.ttlMs)) {
|
|
377
|
+
this.ctx.logger?.debug?.("リストキャッシュ期限切れ(TTL)、フェッチ", {
|
|
378
|
+
operation: "getList",
|
|
379
|
+
collection: this.ctx.collection,
|
|
380
|
+
cacheAdapter: this.ctx.docCache.name
|
|
381
|
+
});
|
|
328
382
|
this.ctx.hooks.onListCacheMiss?.();
|
|
329
383
|
const items = await this.fetchListRaw();
|
|
330
384
|
await this.ctx.docCache.setList({
|
|
@@ -335,9 +389,19 @@ var CollectionClientImpl = class {
|
|
|
335
389
|
}
|
|
336
390
|
const bg = this.checkAndUpdateListBg(cached);
|
|
337
391
|
if (this.ctx.waitUntil) this.ctx.waitUntil(bg);
|
|
338
|
-
this.ctx.
|
|
392
|
+
this.ctx.logger?.debug?.("リストキャッシュヒット", {
|
|
393
|
+
operation: "getList",
|
|
394
|
+
collection: this.ctx.collection,
|
|
395
|
+
cacheAdapter: this.ctx.docCache.name
|
|
396
|
+
});
|
|
397
|
+
this.ctx.hooks.onListCacheHit?.(cached);
|
|
339
398
|
return cached.items;
|
|
340
399
|
}
|
|
400
|
+
this.ctx.logger?.debug?.("リストキャッシュミス、フェッチ", {
|
|
401
|
+
operation: "getList",
|
|
402
|
+
collection: this.ctx.collection,
|
|
403
|
+
cacheAdapter: this.ctx.docCache.name
|
|
404
|
+
});
|
|
341
405
|
this.ctx.hooks.onListCacheMiss?.();
|
|
342
406
|
const items = await this.fetchListRaw();
|
|
343
407
|
const cachedAt = Date.now();
|
|
@@ -356,13 +420,28 @@ var CollectionClientImpl = class {
|
|
|
356
420
|
if (this.ctx.source.getLastModified(item) !== cached.notionUpdatedAt) {
|
|
357
421
|
const entry = await buildCachedItem(item, this.ctx.render);
|
|
358
422
|
await this.ctx.docCache.setItem(slug, entry);
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
423
|
+
this.ctx.logger?.debug?.("SWR: 差分を検出、キャッシュを差し替え", {
|
|
424
|
+
operation: "getItem:bg",
|
|
425
|
+
slug,
|
|
426
|
+
collection: this.ctx.collection,
|
|
427
|
+
notionUpdatedAt: cached.notionUpdatedAt
|
|
428
|
+
});
|
|
429
|
+
this.ctx.hooks.onCacheRevalidated?.(slug, entry);
|
|
430
|
+
} else if (this.ctx.ttlMs !== void 0) {
|
|
431
|
+
await this.ctx.docCache.setItem(slug, {
|
|
432
|
+
...cached,
|
|
433
|
+
cachedAt: Date.now()
|
|
434
|
+
});
|
|
435
|
+
this.ctx.logger?.debug?.("SWR: 差分なし、TTL をリセット", {
|
|
436
|
+
operation: "getItem:bg",
|
|
437
|
+
slug,
|
|
438
|
+
collection: this.ctx.collection
|
|
439
|
+
});
|
|
440
|
+
}
|
|
363
441
|
} catch (err) {
|
|
364
442
|
this.ctx.logger?.warn?.("SWR: アイテムのバックグラウンド差分チェックに失敗", {
|
|
365
443
|
slug,
|
|
444
|
+
collection: this.ctx.collection,
|
|
366
445
|
error: err instanceof Error ? err.message : String(err)
|
|
367
446
|
});
|
|
368
447
|
}
|
|
@@ -370,16 +449,32 @@ var CollectionClientImpl = class {
|
|
|
370
449
|
async checkAndUpdateListBg(cached) {
|
|
371
450
|
try {
|
|
372
451
|
const items = await this.fetchListRaw();
|
|
373
|
-
if (this.ctx.source.getListVersion(items) !== this.ctx.source.getListVersion(cached.items))
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
452
|
+
if (this.ctx.source.getListVersion(items) !== this.ctx.source.getListVersion(cached.items)) {
|
|
453
|
+
const listEntry = {
|
|
454
|
+
items,
|
|
455
|
+
cachedAt: Date.now()
|
|
456
|
+
};
|
|
457
|
+
await this.ctx.docCache.setList(listEntry);
|
|
458
|
+
this.ctx.logger?.debug?.("SWR: リスト差分を検出、キャッシュを差し替え", {
|
|
459
|
+
operation: "getList:bg",
|
|
460
|
+
collection: this.ctx.collection
|
|
461
|
+
});
|
|
462
|
+
this.ctx.hooks.onListCacheRevalidated?.(listEntry);
|
|
463
|
+
} else if (this.ctx.ttlMs !== void 0) {
|
|
464
|
+
await this.ctx.docCache.setList({
|
|
465
|
+
...cached,
|
|
466
|
+
cachedAt: Date.now()
|
|
467
|
+
});
|
|
468
|
+
this.ctx.logger?.debug?.("SWR: リスト差分なし、TTL をリセット", {
|
|
469
|
+
operation: "getList:bg",
|
|
470
|
+
collection: this.ctx.collection
|
|
471
|
+
});
|
|
472
|
+
}
|
|
381
473
|
} catch (err) {
|
|
382
|
-
this.ctx.logger?.warn?.("SWR: リストのバックグラウンド差分チェックに失敗", {
|
|
474
|
+
this.ctx.logger?.warn?.("SWR: リストのバックグラウンド差分チェックに失敗", {
|
|
475
|
+
collection: this.ctx.collection,
|
|
476
|
+
error: err instanceof Error ? err.message : String(err)
|
|
477
|
+
});
|
|
383
478
|
}
|
|
384
479
|
}
|
|
385
480
|
fetchListRaw() {
|
|
@@ -562,13 +657,27 @@ function hasImageCacheConfigured(cache) {
|
|
|
562
657
|
*/
|
|
563
658
|
function scopeDocumentCache(base, collection) {
|
|
564
659
|
const itemKey = (slug) => `${collection}:${slug}`;
|
|
660
|
+
let listSlot = null;
|
|
661
|
+
let listInitialized = false;
|
|
565
662
|
return {
|
|
566
663
|
name: `${base.name}@${collection}`,
|
|
567
|
-
getList: () =>
|
|
568
|
-
|
|
664
|
+
getList: async () => {
|
|
665
|
+
if (!listInitialized) {
|
|
666
|
+
listInitialized = true;
|
|
667
|
+
listSlot = await base.getList();
|
|
668
|
+
}
|
|
669
|
+
return listSlot;
|
|
670
|
+
},
|
|
671
|
+
setList: (data) => {
|
|
672
|
+
listSlot = data;
|
|
673
|
+
listInitialized = true;
|
|
674
|
+
return Promise.resolve();
|
|
675
|
+
},
|
|
569
676
|
getItem: (slug) => base.getItem(itemKey(slug)),
|
|
570
677
|
setItem: (slug, data) => base.setItem(itemKey(slug), data),
|
|
571
678
|
async invalidate(scope) {
|
|
679
|
+
listSlot = null;
|
|
680
|
+
listInitialized = true;
|
|
572
681
|
if (!base.invalidate) return;
|
|
573
682
|
if (scope === "all") return base.invalidate({ collection });
|
|
574
683
|
if ("slug" in scope) return base.invalidate({
|
|
@@ -579,6 +688,25 @@ function scopeDocumentCache(base, collection) {
|
|
|
579
688
|
}
|
|
580
689
|
};
|
|
581
690
|
}
|
|
691
|
+
const LOG_LEVEL_ORDER = {
|
|
692
|
+
debug: 0,
|
|
693
|
+
info: 1,
|
|
694
|
+
warn: 2,
|
|
695
|
+
error: 3
|
|
696
|
+
};
|
|
697
|
+
/** `logger` から `minLevel` 未満のレベルを除いた新しい Logger を返す。 */
|
|
698
|
+
function applyLogLevel(logger, minLevel) {
|
|
699
|
+
if (!logger) return void 0;
|
|
700
|
+
const minOrder = LOG_LEVEL_ORDER[minLevel];
|
|
701
|
+
const filtered = {};
|
|
702
|
+
for (const level of [
|
|
703
|
+
"debug",
|
|
704
|
+
"info",
|
|
705
|
+
"warn",
|
|
706
|
+
"error"
|
|
707
|
+
]) if (LOG_LEVEL_ORDER[level] >= minOrder) filtered[level] = logger[level];
|
|
708
|
+
return filtered;
|
|
709
|
+
}
|
|
582
710
|
/**
|
|
583
711
|
* `preset` オプションを解決して `cache` / `renderer` のデフォルトを補完する内部関数。
|
|
584
712
|
* 明示的な `cache` / `renderer` がある場合はそちらが優先される。
|
|
@@ -643,7 +771,8 @@ function createCMS(opts) {
|
|
|
643
771
|
const contentConfig = opts.content;
|
|
644
772
|
const rendererFn = resolved.renderer;
|
|
645
773
|
const waitUntil = opts.waitUntil;
|
|
646
|
-
const
|
|
774
|
+
const baseLogger = mergeLoggers(opts.plugins ?? [], opts.logger);
|
|
775
|
+
const logger = opts.logLevel ? applyLogLevel(baseLogger, opts.logLevel) : baseLogger;
|
|
647
776
|
const hooks = mergeHooks(opts.plugins ?? [], opts.hooks, logger);
|
|
648
777
|
const maxConcurrent = opts.rateLimiter?.maxConcurrent ?? 3;
|
|
649
778
|
const retryConfig = {
|
|
@@ -652,26 +781,32 @@ function createCMS(opts) {
|
|
|
652
781
|
};
|
|
653
782
|
const collectionNames = Object.keys(opts.dataSources);
|
|
654
783
|
const collections = {};
|
|
784
|
+
const scopedCaches = [];
|
|
655
785
|
for (const name of collectionNames) {
|
|
656
786
|
const source = opts.dataSources[name];
|
|
657
787
|
const scopedCache = scopeDocumentCache(baseDocCache, name);
|
|
658
|
-
|
|
659
|
-
source,
|
|
660
|
-
rendererFn,
|
|
661
|
-
imgCache,
|
|
662
|
-
hasImageCache,
|
|
663
|
-
imageProxyBase,
|
|
664
|
-
contentConfig,
|
|
665
|
-
hooks,
|
|
666
|
-
logger
|
|
667
|
-
};
|
|
788
|
+
scopedCaches.push(scopedCache);
|
|
668
789
|
const col = opts.collections?.[name];
|
|
790
|
+
const colHooks = col?.hooks;
|
|
791
|
+
const collectionHooks = colHooks ? mergeHooks([{
|
|
792
|
+
name: `${name}:global`,
|
|
793
|
+
hooks
|
|
794
|
+
}], colHooks, logger) : hooks;
|
|
669
795
|
collections[name] = new CollectionClientImpl({
|
|
670
796
|
collection: name,
|
|
671
797
|
source,
|
|
672
798
|
docCache: scopedCache,
|
|
673
|
-
render:
|
|
674
|
-
|
|
799
|
+
render: {
|
|
800
|
+
source,
|
|
801
|
+
rendererFn,
|
|
802
|
+
imgCache,
|
|
803
|
+
hasImageCache,
|
|
804
|
+
imageProxyBase,
|
|
805
|
+
contentConfig,
|
|
806
|
+
hooks: collectionHooks,
|
|
807
|
+
logger
|
|
808
|
+
},
|
|
809
|
+
hooks: collectionHooks,
|
|
675
810
|
logger,
|
|
676
811
|
ttlMs,
|
|
677
812
|
publishedStatuses: col?.publishedStatuses ? [...col.publishedStatuses] : [],
|
|
@@ -685,8 +820,14 @@ function createCMS(opts) {
|
|
|
685
820
|
const globalOps = {
|
|
686
821
|
$collections: collectionNames,
|
|
687
822
|
async $revalidate(scope) {
|
|
688
|
-
|
|
689
|
-
|
|
823
|
+
logger?.debug?.("グローバルキャッシュを無効化", {
|
|
824
|
+
operation: "$revalidate",
|
|
825
|
+
cacheAdapter: baseDocCache.name
|
|
826
|
+
});
|
|
827
|
+
for (const cache of scopedCaches) {
|
|
828
|
+
if (!cache.invalidate) continue;
|
|
829
|
+
await cache.invalidate(scope ?? "all");
|
|
830
|
+
}
|
|
690
831
|
},
|
|
691
832
|
$handler(handlerOpts) {
|
|
692
833
|
return createHandler({
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/cache.ts","../src/image.ts","../src/rendering.ts","../src/retry.ts","../src/collection.ts","../src/handler.ts","../src/preset-node.ts","../src/cms.ts","../src/types/plugin.ts"],"sourcesContent":["/** 文字列をSHA-256でハッシュ化し、16進数文字列として返す。画像キーの生成に使用。 */\nexport async function sha256Hex(input: string): Promise<string> {\n\tconst data = new TextEncoder().encode(input);\n\tconst hash = await crypto.subtle.digest(\"SHA-256\", data);\n\treturn Array.from(new Uint8Array(hash))\n\t\t.map((b) => b.toString(16).padStart(2, \"0\"))\n\t\t.join(\"\");\n}\n\n/**\n * キャッシュが有効期限切れかどうかを判定する。\n * ttlMs が未指定の場合は常に false(無期限有効)を返す。\n */\nexport function isStale(cachedAt: number, ttlMs?: number): boolean {\n\tif (ttlMs === undefined) return false;\n\treturn Date.now() - cachedAt > ttlMs;\n}\n","import { sha256Hex } from \"./cache\";\nimport { CMSError, isCMSError } from \"./errors\";\nimport type { ImageCacheAdapter, StorageBinary } from \"./types/index\";\n\n/** レスポンスヘッダまたはURLの拡張子からContent-Typeを推測する。 */\nfunction inferContentType(\n\turl: string,\n\tresponseContentType: string | null,\n): string {\n\tif (responseContentType?.startsWith(\"image/\")) {\n\t\treturn responseContentType.split(\";\")[0].trim();\n\t}\n\tif (url.includes(\".png\")) return \"image/png\";\n\tif (url.includes(\".gif\")) return \"image/gif\";\n\tif (url.includes(\".webp\")) return \"image/webp\";\n\treturn \"image/jpeg\";\n}\n\n/**\n * Notion画像URLをfetchしてImageCacheAdapterにキャッシュし、プロキシURL を返す。\n * 既存キャッシュがあれば再fetchしない。\n */\nasync function fetchAndCacheImage(\n\tcache: ImageCacheAdapter,\n\tnotionUrl: string,\n\timageProxyBase: string,\n): Promise<string> {\n\tconst hash = await sha256Hex(notionUrl);\n\tconst proxyUrl = `${imageProxyBase}/${hash}`;\n\n\tconst existing = await cache.get(hash);\n\tif (existing) return proxyUrl;\n\n\ttry {\n\t\tconst response = await fetch(notionUrl, {\n\t\t\tsignal: AbortSignal.timeout(10_000),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new CMSError({\n\t\t\t\tcode: \"cache/image_fetch_failed\",\n\t\t\t\tmessage: `Failed to fetch Notion image: HTTP ${response.status}`,\n\t\t\t\tcontext: {\n\t\t\t\t\toperation: \"fetchAndCacheImage\",\n\t\t\t\t\tnotionUrl,\n\t\t\t\t\thttpStatus: response.status,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\tconst data = await response.arrayBuffer();\n\t\tconst contentType = inferContentType(\n\t\t\tnotionUrl,\n\t\t\tresponse.headers.get(\"content-type\"),\n\t\t);\n\t\tawait cache.set(hash, data, contentType);\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"cache/io_failed\",\n\t\t\tmessage: \"Failed to fetch or cache Notion image.\",\n\t\t\tcause: err,\n\t\t\tcontext: { operation: \"fetchAndCacheImage\", notionUrl },\n\t\t});\n\t}\n\n\treturn proxyUrl;\n}\n\n/** ImageCacheAdapter と imageProxyBase から cacheImage 関数を構築するファクトリ。 */\nexport function buildCacheImageFn(\n\tcache: ImageCacheAdapter,\n\timageProxyBase: string,\n): (notionUrl: string) => Promise<string> {\n\treturn (notionUrl) => fetchAndCacheImage(cache, notionUrl, imageProxyBase);\n}\n\nexport type { StorageBinary };\n","import type { ContentBlock } from \"./content/blocks\";\nimport { CMSError, isCMSError } from \"./errors\";\nimport { buildCacheImageFn } from \"./image\";\nimport type {\n\tBaseContentItem,\n\tCachedItem,\n\tCMSHooks,\n\tContentConfig,\n\tDataSource,\n\tImageCacheAdapter,\n\tLogger,\n\tRendererFn,\n} from \"./types/index\";\n\n/** `buildCachedItem` に必要な CMS の依存を束ねたコンテキスト。 */\nexport interface RenderContext<T extends BaseContentItem> {\n\tsource: DataSource<T>;\n\trendererFn: RendererFn | undefined;\n\timgCache: ImageCacheAdapter;\n\thasImageCache: boolean;\n\timageProxyBase: string;\n\tcontentConfig: ContentConfig | undefined;\n\thooks: CMSHooks<T>;\n\tlogger: Logger | undefined;\n}\n\n/**\n * コンテンツアイテムをソースから Markdown ロード → blocks 生成 → HTML レンダリング\n * → フック適用まで実行し、キャッシュ保存用の `CachedItem` を返す。\n */\nexport async function buildCachedItem<T extends BaseContentItem>(\n\titem: T,\n\tctx: RenderContext<T>,\n): Promise<CachedItem<T>> {\n\tconst start = Date.now();\n\tctx.logger?.info?.(\"コンテンツのレンダリング開始\", {\n\t\tslug: item.slug,\n\t\tpageId: item.id,\n\t});\n\tctx.hooks.onRenderStart?.(item.slug);\n\n\tlet markdown: string;\n\ttry {\n\t\tmarkdown = await ctx.source.loadMarkdown(item);\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"source/load_markdown_failed\",\n\t\t\tmessage: \"Failed to load markdown from source.\",\n\t\t\tcause: err,\n\t\t\tcontext: {\n\t\t\t\toperation: \"buildCachedItem:loadMarkdown\",\n\t\t\t\tpageId: item.id,\n\t\t\t\tslug: item.slug,\n\t\t\t},\n\t\t});\n\t}\n\n\tlet blocks: ContentBlock[] = [];\n\ttry {\n\t\tblocks = await ctx.source.loadBlocks(item);\n\t} catch (err) {\n\t\tctx.logger?.warn?.(\"loadBlocks に失敗したため raw フォールバック\", {\n\t\t\tslug: item.slug,\n\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t});\n\t\tblocks = [];\n\t}\n\n\tconst cacheImage = ctx.hasImageCache\n\t\t? buildCacheImageFn(ctx.imgCache, ctx.imageProxyBase)\n\t\t: undefined;\n\n\tlet html: string;\n\tconst rendererFn = ctx.rendererFn ?? (await loadDefaultRenderer());\n\ttry {\n\t\thtml = await rendererFn(markdown, {\n\t\t\timageProxyBase: ctx.imageProxyBase,\n\t\t\tcacheImage,\n\t\t\tremarkPlugins: ctx.contentConfig?.remarkPlugins,\n\t\t\trehypePlugins: ctx.contentConfig?.rehypePlugins,\n\t\t});\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"renderer/failed\",\n\t\t\tmessage: \"Failed to render markdown.\",\n\t\t\tcause: err,\n\t\t\tcontext: {\n\t\t\t\toperation: \"buildCachedItem:renderMarkdown\",\n\t\t\t\tpageId: item.id,\n\t\t\t\tslug: item.slug,\n\t\t\t},\n\t\t});\n\t}\n\n\tif (ctx.hooks.afterRender) {\n\t\thtml = await ctx.hooks.afterRender(html, item);\n\t}\n\n\tlet result: CachedItem<T> = {\n\t\thtml,\n\t\tblocks,\n\t\tmarkdown,\n\t\titem,\n\t\tnotionUpdatedAt: ctx.source.getLastModified(item),\n\t\tcachedAt: Date.now(),\n\t};\n\n\tif (ctx.hooks.beforeCache) {\n\t\tresult = (await ctx.hooks.beforeCache(result)) as CachedItem<T>;\n\t}\n\n\tconst durationMs = Date.now() - start;\n\tctx.logger?.info?.(\"コンテンツのレンダリング完了\", {\n\t\tslug: item.slug,\n\t\tdurationMs,\n\t});\n\tctx.hooks.onRenderEnd?.(item.slug, durationMs);\n\n\treturn result;\n}\n\n/**\n * renderer オプション未指定時のフォールバック。\n * @notion-headless-cms/renderer を動的 import する。\n * createCMS({ renderer }) で明示注入された場合はこのパスを通らない。\n */\nexport async function loadDefaultRenderer(): Promise<RendererFn> {\n\ttry {\n\t\tconst mod = await import(\"@notion-headless-cms/renderer\");\n\t\treturn mod.renderMarkdown as RendererFn;\n\t} catch (err) {\n\t\tthrow new CMSError({\n\t\t\tcode: \"renderer/failed\",\n\t\t\tmessage:\n\t\t\t\t\"renderer オプションが未指定で @notion-headless-cms/renderer が見つかりません。\" +\n\t\t\t\t\" createCMS({ renderer }) でレンダラーを注入するか、@notion-headless-cms/renderer をインストールしてください。\",\n\t\t\tcause: err,\n\t\t\tcontext: { operation: \"loadDefaultRenderer\" },\n\t\t});\n\t}\n}\n","export interface RetryConfig {\n\tretryOn: number[];\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\t/** true のとき指数バックオフにランダムジッターを加える(Thundering Herd 対策)。デフォルト: true */\n\tjitter?: boolean;\n\tonRetry?: (attempt: number, status: number) => void;\n}\n\nexport const DEFAULT_RETRY_CONFIG: RetryConfig = {\n\tretryOn: [429, 502, 503],\n\tmaxRetries: 4,\n\tbaseDelayMs: 1000,\n\tjitter: true,\n};\n\n/** 指数バックオフ(オプションでジッター付き)でリトライする。retryOn に含まれる HTTP エラーのみ対象。 */\nexport async function withRetry<T>(\n\tfn: () => Promise<T>,\n\tconfig: RetryConfig,\n): Promise<T> {\n\tlet lastError: unknown;\n\tfor (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} catch (err) {\n\t\t\tconst status = (err as { status?: number }).status;\n\t\t\tif (status === undefined || !config.retryOn.includes(status)) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tlastError = err;\n\t\t\tif (attempt < config.maxRetries) {\n\t\t\t\tconfig.onRetry?.(attempt + 1, status);\n\t\t\t\tconst jitterFactor =\n\t\t\t\t\tconfig.jitter !== false ? 0.5 + Math.random() * 0.5 : 1;\n\t\t\t\tconst delay = config.baseDelayMs * 2 ** attempt * jitterFactor;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay));\n\t\t\t}\n\t\t}\n\t}\n\tthrow lastError;\n}\n","import { isStale } from \"./cache\";\nimport type { ContentBlock, ContentResult } from \"./content/blocks\";\nimport type { RenderContext } from \"./rendering\";\nimport { buildCachedItem } from \"./rendering\";\nimport type { RetryConfig } from \"./retry\";\nimport { withRetry } from \"./retry\";\nimport type {\n\tAdjacencyOptions,\n\tBaseContentItem,\n\tCachedItem,\n\tCachedItemList,\n\tCMSHooks,\n\tCollectionClient,\n\tDataSource,\n\tDocumentCacheAdapter,\n\tGetListOptions,\n\tItemWithContent,\n\tLogger,\n\tSortOption,\n} from \"./types/index\";\n\n/**\n * コレクション別キャッシュキーを生成する。\n * item: `{collection}:{slug}` / list: `{collection}`\n */\nexport function collectionKey(collection: string, slug?: string): string {\n\treturn slug ? `${collection}:${slug}` : collection;\n}\n\n/** 単一コレクションの DataSource + SWR キャッシュ依存を束ねたコンテキスト。 */\nexport interface CollectionContext<T extends BaseContentItem> {\n\tcollection: string;\n\tsource: DataSource<T>;\n\tdocCache: DocumentCacheAdapter<T>;\n\trender: RenderContext<T>;\n\thooks: CMSHooks<T>;\n\tlogger: Logger | undefined;\n\tttlMs: number | undefined;\n\tpublishedStatuses: string[];\n\taccessibleStatuses: string[];\n\tretryConfig: RetryConfig;\n\tmaxConcurrent: number;\n\twaitUntil: ((p: Promise<unknown>) => void) | undefined;\n\t/**\n\t * slug として使うフィールド名。\n\t * `createCMS({ collections })` で指定した値。\n\t * 設定時は `source.properties[slugField].notion` を Notion プロパティ名として\n\t * `findByProp` を呼び出す。\n\t */\n\tslugField?: string;\n}\n\n/** CollectionClient の実装。ユーザーは `createCMS` 経由でインスタンスを受け取る。 */\nexport class CollectionClientImpl<T extends BaseContentItem>\n\timplements CollectionClient<T>\n{\n\tconstructor(private readonly ctx: CollectionContext<T>) {}\n\n\t// ── 基本取得 ──────────────────────────────────────────────────────────\n\n\tasync getItem(slug: string): Promise<ItemWithContent<T> | null> {\n\t\tconst cached = await this.ctx.docCache.getItem(slug);\n\t\tif (cached) {\n\t\t\tif (\n\t\t\t\tthis.ctx.ttlMs !== undefined &&\n\t\t\t\tisStale(cached.cachedAt, this.ctx.ttlMs)\n\t\t\t) {\n\t\t\t\t// TTL 設定あり + 期限切れ: ブロッキングフェッチ(stale を返さない)\n\t\t\t\tthis.ctx.hooks.onCacheMiss?.(slug);\n\t\t\t\tconst item = await this.findRaw(slug);\n\t\t\t\tif (!item) return null;\n\t\t\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\t\t\tawait this.ctx.docCache.setItem(slug, entry);\n\t\t\t\treturn this.attachContent(entry.item, entry);\n\t\t\t}\n\t\t\t// TTL 未設定 or 期限内: キャッシュを即時返却し、バックグラウンドで差分チェック\n\t\t\tconst bg = this.checkAndUpdateItemBg(slug, cached);\n\t\t\tif (this.ctx.waitUntil) {\n\t\t\t\tthis.ctx.waitUntil(bg);\n\t\t\t}\n\t\t\tthis.ctx.hooks.onCacheHit?.(slug, cached);\n\t\t\treturn this.attachContent(cached.item, cached);\n\t\t}\n\n\t\t// キャッシュなし: 同期フェッチ\n\t\tthis.ctx.hooks.onCacheMiss?.(slug);\n\t\tconst item = await this.findRaw(slug);\n\t\tif (!item) return null;\n\n\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\tconst save = this.ctx.docCache.setItem(slug, entry);\n\t\tif (this.ctx.waitUntil) {\n\t\t\tthis.ctx.waitUntil(save);\n\t\t} else {\n\t\t\tawait save;\n\t\t}\n\n\t\treturn this.attachContent(entry.item, entry);\n\t}\n\n\tasync getList(opts?: GetListOptions<T>): Promise<T[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn applyGetListOptions(items, opts);\n\t}\n\n\t// ── SSG / ナビゲーション ─────────────────────────────────────────────\n\n\tasync getStaticParams(): Promise<{ slug: string }[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn items.map((item) => ({ slug: item.slug }));\n\t}\n\n\tasync getStaticPaths(): Promise<string[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn items.map((item) => item.slug);\n\t}\n\n\tasync adjacent(\n\t\tslug: string,\n\t\topts?: AdjacencyOptions<T>,\n\t): Promise<{ prev: T | null; next: T | null }> {\n\t\tconst items = applyGetListOptions(await this.fetchList(), {\n\t\t\tsort: opts?.sort,\n\t\t});\n\t\tconst index = items.findIndex((it) => it.slug === slug);\n\t\tif (index === -1) return { prev: null, next: null };\n\t\treturn {\n\t\t\tprev: index > 0 ? (items[index - 1] ?? null) : null,\n\t\t\tnext: index < items.length - 1 ? (items[index + 1] ?? null) : null,\n\t\t};\n\t}\n\n\t// ── キャッシュ ────────────────────────────────────────────────────────\n\n\tasync revalidate(scope?: \"all\" | { slug: string }): Promise<void> {\n\t\tif (!this.ctx.docCache.invalidate) return;\n\t\tif (scope === undefined || scope === \"all\") {\n\t\t\tawait this.ctx.docCache.invalidate({ collection: this.ctx.collection });\n\t\t} else {\n\t\t\tawait this.ctx.docCache.invalidate({\n\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\tslug: scope.slug,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync prefetch(opts?: {\n\t\tconcurrency?: number;\n\t\tonProgress?: (done: number, total: number) => void;\n\t}): Promise<{ ok: number; failed: number }> {\n\t\tconst items = await this.fetchListRaw();\n\t\tconst concurrency = opts?.concurrency ?? this.ctx.maxConcurrent;\n\t\tlet ok = 0;\n\t\tlet failed = 0;\n\n\t\tfor (let i = 0; i < items.length; i += concurrency) {\n\t\t\tconst chunk = items.slice(i, i + concurrency);\n\t\t\tawait Promise.all(\n\t\t\t\tchunk.map(async (item) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst rendered = await buildCachedItem(item, this.ctx.render);\n\t\t\t\t\t\tawait this.ctx.docCache.setItem(item.slug, rendered);\n\t\t\t\t\t\tok++;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tfailed++;\n\t\t\t\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\t\t\t\"prefetch: アイテムの事前レンダリングに失敗\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tslug: item.slug,\n\t\t\t\t\t\t\t\tpageId: item.id,\n\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t\topts?.onProgress?.(Math.min(i + concurrency, items.length), items.length);\n\t\t}\n\n\t\tawait this.ctx.docCache.setList({ items, cachedAt: Date.now() });\n\t\treturn { ok, failed };\n\t}\n\n\t// ── 内部 ──────────────────────────────────────────────────────────────\n\n\tprivate attachContent(item: T, cached: CachedItem<T>): ItemWithContent<T> {\n\t\tconst ctx = this.ctx;\n\t\tlet blocksCache: ContentBlock[] | undefined;\n\t\tlet htmlCache: string | undefined = cached.html;\n\t\tlet markdownCache: string | undefined;\n\n\t\tconst content: ContentResult = {\n\t\t\tget blocks(): ContentBlock[] {\n\t\t\t\tif (!blocksCache) {\n\t\t\t\t\t// lazy: キャッシュに blocks が保存されていない場合、簡易な single-raw に落とす\n\t\t\t\t\tblocksCache = [\n\t\t\t\t\t\t{ type: \"raw\", html: cached.html } satisfies ContentBlock,\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\treturn blocksCache;\n\t\t\t},\n\t\t\tasync html(): Promise<string> {\n\t\t\t\tif (htmlCache !== undefined) return htmlCache;\n\t\t\t\thtmlCache = cached.html;\n\t\t\t\treturn htmlCache;\n\t\t\t},\n\t\t\tasync markdown(): Promise<string> {\n\t\t\t\tif (markdownCache !== undefined) return markdownCache;\n\t\t\t\tmarkdownCache = await ctx.source.loadMarkdown(item);\n\t\t\t\treturn markdownCache;\n\t\t\t},\n\t\t};\n\n\t\tif (cached.blocks) blocksCache = cached.blocks;\n\n\t\treturn Object.assign(Object.create(null) as object, item, {\n\t\t\tcontent,\n\t\t}) as ItemWithContent<T>;\n\t}\n\n\tprivate async fetchList(): Promise<T[]> {\n\t\tconst cached = await this.ctx.docCache.getList();\n\t\tif (cached) {\n\t\t\tif (\n\t\t\t\tthis.ctx.ttlMs !== undefined &&\n\t\t\t\tisStale(cached.cachedAt, this.ctx.ttlMs)\n\t\t\t) {\n\t\t\t\t// TTL 設定あり + 期限切れ: ブロッキングフェッチ(stale を返さない)\n\t\t\t\tthis.ctx.hooks.onListCacheMiss?.();\n\t\t\t\tconst items = await this.fetchListRaw();\n\t\t\t\tawait this.ctx.docCache.setList({ items, cachedAt: Date.now() });\n\t\t\t\treturn items;\n\t\t\t}\n\t\t\t// TTL 未設定 or 期限内: キャッシュを即時返却し、バックグラウンドで差分チェック\n\t\t\tconst bg = this.checkAndUpdateListBg(cached);\n\t\t\tif (this.ctx.waitUntil) {\n\t\t\t\tthis.ctx.waitUntil(bg);\n\t\t\t}\n\t\t\tthis.ctx.hooks.onListCacheHit?.(cached.items, cached.cachedAt);\n\t\t\treturn cached.items;\n\t\t}\n\n\t\t// キャッシュなし: 同期フェッチ\n\t\tthis.ctx.hooks.onListCacheMiss?.();\n\t\tconst items = await this.fetchListRaw();\n\t\tconst cachedAt = Date.now();\n\t\tconst save = this.ctx.docCache.setList({ items, cachedAt });\n\t\tif (this.ctx.waitUntil) {\n\t\t\tthis.ctx.waitUntil(save);\n\t\t} else {\n\t\t\tawait save;\n\t\t}\n\t\treturn items;\n\t}\n\n\tprivate async checkAndUpdateItemBg(\n\t\tslug: string,\n\t\tcached: CachedItem<T>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst item = await this.findRaw(slug);\n\t\t\tif (!item) return;\n\t\t\tif (this.ctx.source.getLastModified(item) !== cached.notionUpdatedAt) {\n\t\t\t\t// 更新あり: 再レンダリングしてキャッシュを差し替える\n\t\t\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\t\t\tawait this.ctx.docCache.setItem(slug, entry);\n\t\t\t} else if (this.ctx.ttlMs !== undefined) {\n\t\t\t\t// 変更なし + TTL あり: cachedAt をリセットして次回の期限切れを先送りする\n\t\t\t\tawait this.ctx.docCache.setItem(slug, {\n\t\t\t\t\t...cached,\n\t\t\t\t\tcachedAt: Date.now(),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\"SWR: アイテムのバックグラウンド差分チェックに失敗\",\n\t\t\t\t{\n\t\t\t\t\tslug,\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async checkAndUpdateListBg(cached: CachedItemList<T>): Promise<void> {\n\t\ttry {\n\t\t\tconst items = await this.fetchListRaw();\n\t\t\tif (\n\t\t\t\tthis.ctx.source.getListVersion(items) !==\n\t\t\t\tthis.ctx.source.getListVersion(cached.items)\n\t\t\t) {\n\t\t\t\t// 更新あり: リストを差し替える\n\t\t\t\tawait this.ctx.docCache.setList({ items, cachedAt: Date.now() });\n\t\t\t} else if (this.ctx.ttlMs !== undefined) {\n\t\t\t\t// 変更なし + TTL あり: cachedAt をリセットする\n\t\t\t\tawait this.ctx.docCache.setList({\n\t\t\t\t\t...cached,\n\t\t\t\t\tcachedAt: Date.now(),\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\"SWR: リストのバックグラウンド差分チェックに失敗\",\n\t\t\t\t{\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate fetchListRaw(): Promise<T[]> {\n\t\treturn withRetry(\n\t\t\t() =>\n\t\t\t\tthis.ctx.source.list({\n\t\t\t\t\tpublishedStatuses:\n\t\t\t\t\t\tthis.ctx.publishedStatuses.length > 0\n\t\t\t\t\t\t\t? this.ctx.publishedStatuses\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t}),\n\t\t\t{\n\t\t\t\t...this.ctx.retryConfig,\n\t\t\t\tonRetry: (attempt, status) => {\n\t\t\t\t\tthis.ctx.logger?.warn?.(\"getList() リトライ中\", { attempt, status });\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async findRaw(slug: string): Promise<T | null> {\n\t\tconst retryOpts = {\n\t\t\t...this.ctx.retryConfig,\n\t\t\tonRetry: (attempt: number, status: number) => {\n\t\t\t\tthis.ctx.logger?.warn?.(\"getItem() リトライ中\", {\n\t\t\t\t\tattempt,\n\t\t\t\t\tstatus,\n\t\t\t\t\tslug,\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\n\t\t// slug フィールドが指定され、DataSource が findByProp を持つ場合は\n\t\t// Notion プロパティ名を解決して効率的なフィルタクエリを実行する。\n\t\tconst slugField = this.ctx.slugField;\n\t\tconst notionPropName = slugField\n\t\t\t? this.ctx.source.properties?.[slugField]?.notion\n\t\t\t: undefined;\n\n\t\tlet item: T | null;\n\t\tconst findByProp = this.ctx.source.findByProp?.bind(this.ctx.source);\n\t\tif (notionPropName && findByProp) {\n\t\t\titem = await withRetry(() => findByProp(notionPropName, slug), retryOpts);\n\t\t} else {\n\t\t\t// フォールバック: list して線形探索\n\t\t\tconst all = await withRetry(() => this.ctx.source.list(), retryOpts);\n\t\t\titem = all.find((i) => i.slug === slug) ?? null;\n\t\t}\n\n\t\tif (!item) return null;\n\t\tif (\n\t\t\tthis.ctx.accessibleStatuses.length > 0 &&\n\t\t\t(!item.status || !this.ctx.accessibleStatuses.includes(item.status))\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn item;\n\t}\n}\n\nfunction applyGetListOptions<T extends BaseContentItem>(\n\titems: T[],\n\topts?: GetListOptions<T>,\n): T[] {\n\tif (!opts) return items;\n\tlet result = items;\n\n\tif (opts.statuses && opts.statuses.length > 0) {\n\t\tconst allow = new Set(opts.statuses);\n\t\tresult = result.filter(\n\t\t\t(it) => it.status !== undefined && allow.has(it.status),\n\t\t);\n\t}\n\n\tif (opts.tag) {\n\t\tconst tag = opts.tag;\n\t\tresult = result.filter((it) => {\n\t\t\tconst tags = (it as unknown as { tags?: unknown }).tags;\n\t\t\treturn Array.isArray(tags) && tags.includes(tag);\n\t\t});\n\t}\n\n\tif (opts.where) {\n\t\tconst where = opts.where;\n\t\tresult = result.filter((it) =>\n\t\t\tObject.entries(where).every(\n\t\t\t\t([key, value]) => (it as Record<string, unknown>)[key] === value,\n\t\t\t),\n\t\t);\n\t}\n\n\tif (opts.sort) {\n\t\tresult = [...result].sort(makeComparator(opts.sort));\n\t}\n\n\tconst skip = opts.skip ?? 0;\n\tconst limit = opts.limit;\n\tif (skip > 0 || limit !== undefined) {\n\t\tresult = result.slice(skip, limit !== undefined ? skip + limit : undefined);\n\t}\n\n\treturn result;\n}\n\nfunction makeComparator<T extends BaseContentItem>(\n\tsort: SortOption<T>,\n): (a: T, b: T) => number {\n\tconst by = sort.by;\n\tconst dir = sort.direction === \"asc\" ? 1 : -1;\n\treturn (a, b) => {\n\t\tconst av = (a as Record<string, unknown>)[by];\n\t\tconst bv = (b as Record<string, unknown>)[by];\n\t\tif (av === bv) return 0;\n\t\tif (av === undefined) return 1;\n\t\tif (bv === undefined) return -1;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: 汎用比較\n\t\treturn (av as any) > (bv as any) ? dir : -dir;\n\t};\n}\n","import type { ImageCacheAdapter, InvalidateScope } from \"./types/index\";\n\n/** `$handler()` の挙動設定。 */\nexport interface HandlerOptions {\n\t/** マウントするベースパス。デフォルト `/api/cms`。 */\n\tbasePath?: string;\n\t/** 画像プロキシのパス (basePath 相対)。デフォルト `/images/:hash`。 */\n\timagesPath?: string;\n\t/** revalidate webhook のパス (basePath 相対)。デフォルト `/revalidate`。 */\n\trevalidatePath?: string;\n\t/** Webhook 署名検証用シークレット (未指定なら検証スキップ)。 */\n\twebhookSecret?: string;\n\t/** デフォルト実装を無効化する場合 true。 */\n\tdisabled?: boolean;\n}\n\n/** `$handler()` が内部で依存する CMS 機能の最小セット。 */\nexport interface HandlerAdapter {\n\timageCache: ImageCacheAdapter;\n\t/** コレクション名で DataSource を取り出し parseWebhook にフォワードする。 */\n\tparseWebhook(\n\t\treq: Request,\n\t\twebhookSecret: string | undefined,\n\t): Promise<InvalidateScope | null>;\n\trevalidate(scope: InvalidateScope): Promise<void>;\n}\n\nconst DEFAULT_OPTS = {\n\tbasePath: \"/api/cms\",\n\timagesPath: \"/images\",\n\trevalidatePath: \"/revalidate\",\n} as const;\n\n/**\n * Web Standard な Request → Response ルーター。\n * Next.js / React Router / Hono / Cloudflare Workers いずれでも使える。\n *\n * ルート:\n * - GET `{basePath}/images/:hash` — 画像プロキシ\n * - POST `{basePath}/revalidate` — Webhook 受信 + $revalidate()\n */\nexport function createHandler(\n\tadapter: HandlerAdapter,\n\topts: HandlerOptions = {},\n): (req: Request) => Promise<Response> {\n\tconst basePath = trimTrailingSlash(opts.basePath ?? DEFAULT_OPTS.basePath);\n\tconst imagesPath = opts.imagesPath ?? DEFAULT_OPTS.imagesPath;\n\tconst revalidatePath = opts.revalidatePath ?? DEFAULT_OPTS.revalidatePath;\n\n\treturn async (req: Request): Promise<Response> => {\n\t\tconst url = new URL(req.url);\n\t\tconst path = url.pathname;\n\n\t\tif (!path.startsWith(basePath)) {\n\t\t\treturn new Response(\"Not Found\", { status: 404 });\n\t\t}\n\t\tconst rel = path.slice(basePath.length) || \"/\";\n\n\t\t// 画像: GET {basePath}/images/:hash\n\t\tif (req.method === \"GET\" && rel.startsWith(`${imagesPath}/`)) {\n\t\t\tconst hash = rel.slice(imagesPath.length + 1);\n\t\t\tif (!hash) return new Response(\"Bad Request\", { status: 400 });\n\t\t\tconst object = await adapter.imageCache.get(hash);\n\t\t\tif (!object) return new Response(\"Not Found\", { status: 404 });\n\t\t\tconst headers = new Headers();\n\t\t\tif (object.contentType) headers.set(\"content-type\", object.contentType);\n\t\t\theaders.set(\"cache-control\", \"public, max-age=31536000, immutable\");\n\t\t\treturn new Response(object.data, { headers });\n\t\t}\n\n\t\t// Revalidate: POST {basePath}/revalidate\n\t\tif (req.method === \"POST\" && rel === revalidatePath) {\n\t\t\tconst scope = await adapter.parseWebhook(req, opts.webhookSecret);\n\t\t\tif (!scope) {\n\t\t\t\treturn new Response(JSON.stringify({ ok: false, reason: \"invalid\" }), {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait adapter.revalidate(scope);\n\t\t\treturn new Response(JSON.stringify({ ok: true, scope }), {\n\t\t\t\tstatus: 200,\n\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t});\n\t\t}\n\n\t\treturn new Response(\"Not Found\", { status: 404 });\n\t};\n}\n\nfunction trimTrailingSlash(s: string): string {\n\treturn s.endsWith(\"/\") ? s.slice(0, -1) : s;\n}\n","import { memoryDocumentCache, memoryImageCache } from \"./cache/memory\";\nimport type { CacheConfig, CreateCMSOptions, RendererFn } from \"./types/index\";\n\n/** `nodePreset()` のオプション。 */\nexport interface NodePresetOptions {\n\t/**\n\t * キャッシュ設定。\n\t * - 省略時: memoryDocumentCache + memoryImageCache をデフォルト有効化\n\t * - `\"disabled\"`: キャッシュを完全無効化\n\t * - オブジェクト: 任意の cache adapter を差し込む\n\t */\n\tcache?: CacheConfig | \"disabled\";\n\t/** SWR の TTL (ミリ秒)。`cache` をオブジェクトで渡した場合はそちらが優先される。 */\n\tttlMs?: number;\n\t/** カスタムレンダラー。未指定時は core が @notion-headless-cms/renderer を動的ロード。 */\n\trenderer?: RendererFn;\n}\n\n/**\n * Node.js ランタイム向けの `createCMS` オプションプリセット。\n * メモリキャッシュをデフォルト有効にした `{ cache, renderer }` を返す。\n *\n * @example\n * import { createCMS, nodePreset } from \"@notion-headless-cms/core\";\n * import { cmsDataSources } from \"./generated/cms-schema\";\n *\n * const cms = createCMS({\n * ...nodePreset({ ttlMs: 5 * 60_000 }),\n * dataSources: cmsDataSources,\n * });\n */\nexport function nodePreset(\n\topts: NodePresetOptions = {},\n): Pick<CreateCMSOptions, \"cache\" | \"renderer\"> {\n\tif (opts.cache === \"disabled\") {\n\t\treturn { cache: undefined, renderer: opts.renderer };\n\t}\n\treturn {\n\t\tcache: opts.cache ?? {\n\t\t\tdocument: memoryDocumentCache(),\n\t\t\timage: memoryImageCache(),\n\t\t\tttlMs: opts.ttlMs,\n\t\t},\n\t\trenderer: opts.renderer,\n\t};\n}\n","import { noopDocumentCache, noopImageCache } from \"./cache/noop\";\nimport { CollectionClientImpl, type CollectionContext } from \"./collection\";\nimport { CMSError } from \"./errors\";\nimport { createHandler, type HandlerOptions } from \"./handler\";\nimport { mergeHooks, mergeLoggers } from \"./hooks\";\nimport { nodePreset } from \"./preset-node\";\nimport type { RenderContext } from \"./rendering\";\nimport type { RetryConfig } from \"./retry\";\nimport { DEFAULT_RETRY_CONFIG } from \"./retry\";\nimport type {\n\tBaseContentItem,\n\tCacheConfig,\n\tCMSHooks,\n\tCollectionClient,\n\tCollectionSemantics,\n\tCreateCMSOptions,\n\tDataSource,\n\tDataSourceMap,\n\tDocumentCacheAdapter,\n\tImageCacheAdapter,\n\tInferDataSourceItem,\n\tInvalidateScope,\n\tLogger,\n\tRendererFn,\n} from \"./types/index\";\n\nconst DEFAULT_IMAGE_PROXY_BASE = \"/api/images\";\n\n/** `CMSClient<D>` — コレクション別アクセス + グローバル操作の合成型。 */\nexport type CMSClient<D extends DataSourceMap> = {\n\t[K in keyof D]: CollectionClient<InferDataSourceItem<D[K]>>;\n} & CMSGlobalOps<D>;\n\n/** `CMSClient` のグローバル名前空間。`$` プレフィックス。 */\nexport interface CMSGlobalOps<D extends DataSourceMap> {\n\t/** 登録されているコレクション名の一覧。 */\n\treadonly $collections: readonly (keyof D & string)[];\n\t/** 全コレクションまたは特定コレクションのキャッシュを無効化する。 */\n\t$revalidate(scope?: InvalidateScope): Promise<void>;\n\t/** Web Standard なルーティングハンドラ (画像プロキシ / webhook) を生成する。 */\n\t$handler(opts?: HandlerOptions): (req: Request) => Promise<Response>;\n\t/** ハッシュキーでキャッシュ画像を取得する。 */\n\t$getCachedImage(hash: string): ReturnType<ImageCacheAdapter[\"get\"]>;\n}\n\nfunction resolveDocumentCache(\n\tcache: CacheConfig | undefined,\n\t// biome-ignore lint/suspicious/noExplicitAny: 横断的に利用\n): DocumentCacheAdapter<any> {\n\tif (!cache || cache === \"disabled\" || !cache.document) {\n\t\treturn noopDocumentCache();\n\t}\n\treturn cache.document;\n}\n\nfunction resolveImageCache(cache: CacheConfig | undefined): ImageCacheAdapter {\n\tif (!cache || cache === \"disabled\" || !cache.image) {\n\t\treturn noopImageCache();\n\t}\n\treturn cache.image;\n}\n\nfunction resolveTtl(cache: CacheConfig | undefined): number | undefined {\n\tif (!cache || cache === \"disabled\") return undefined;\n\treturn cache.ttlMs;\n}\n\nfunction hasImageCacheConfigured(cache: CacheConfig | undefined): boolean {\n\tif (!cache || cache === \"disabled\") return false;\n\treturn !!cache.image;\n}\n\n/**\n * `{collection}:{slug}` キー空間で動作するコレクション別キャッシュビューを生成する。\n * 単一の `DocumentCacheAdapter` に複数コレクションを同居させるためのアダプタ。\n */\nfunction scopeDocumentCache<T extends BaseContentItem>(\n\t// biome-ignore lint/suspicious/noExplicitAny: 共有ストレージのため\n\tbase: DocumentCacheAdapter<any>,\n\tcollection: string,\n): DocumentCacheAdapter<T> {\n\tconst itemKey = (slug: string): string => `${collection}:${slug}`;\n\n\treturn {\n\t\tname: `${base.name}@${collection}`,\n\t\tgetList: () => base.getList(),\n\t\tsetList: (data) => base.setList(data),\n\t\tgetItem: (slug) => base.getItem(itemKey(slug)),\n\t\tsetItem: (slug, data) => base.setItem(itemKey(slug), data),\n\t\tasync invalidate(scope) {\n\t\t\tif (!base.invalidate) return;\n\t\t\tif (scope === \"all\") {\n\t\t\t\treturn base.invalidate({ collection });\n\t\t\t}\n\t\t\tif (\"slug\" in scope) {\n\t\t\t\t// アイテムは `{collection}:{slug}` で保存されるため正しいキーに変換する\n\t\t\t\treturn base.invalidate({\n\t\t\t\t\tcollection: scope.collection,\n\t\t\t\t\tslug: itemKey(scope.slug),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn base.invalidate(scope);\n\t\t},\n\t};\n}\n\n/**\n * `preset` オプションを解決して `cache` / `renderer` のデフォルトを補完する内部関数。\n * 明示的な `cache` / `renderer` がある場合はそちらが優先される。\n * `preset` 未指定時は opts をそのまま返す。\n */\nfunction resolvePreset<D extends DataSourceMap>(\n\topts: CreateCMSOptions<D>,\n): CreateCMSOptions<D> {\n\tif (opts.preset === \"disabled\") {\n\t\treturn { ...opts, cache: undefined };\n\t}\n\tif (opts.preset === \"node\") {\n\t\tconst presetResult = nodePreset({ ttlMs: opts.ttlMs });\n\t\treturn {\n\t\t\t...opts,\n\t\t\tcache: opts.cache ?? presetResult.cache,\n\t\t\trenderer: opts.renderer ?? presetResult.renderer,\n\t\t};\n\t}\n\treturn opts;\n}\n\n/**\n * 複数の DataSource を束ねた CMS クライアントを生成する。\n *\n * @example\n * // Node.js(preset を使った簡潔な記法)\n * const cms = createCMS({ dataSources: cmsDataSources, preset: \"node\", ttlMs: 5 * 60_000 });\n *\n * @example\n * // 従来の spread パターン(引き続き動作する)\n * const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources: cmsDataSources });\n *\n * @example\n * // キャッシュを細かく指定する場合\n * const cms = createCMS({\n * dataSources,\n * cache: { document, image, ttlMs: 60_000 },\n * });\n */\nexport function createCMS<D extends DataSourceMap>(\n\topts: CreateCMSOptions<D>,\n): CMSClient<D> {\n\tif (!opts.dataSources || Object.keys(opts.dataSources).length === 0) {\n\t\tthrow new CMSError({\n\t\t\tcode: \"core/config_invalid\",\n\t\t\tmessage:\n\t\t\t\t\"createCMS: dataSources に少なくとも1つのコレクションを指定してください。\",\n\t\t\tcontext: { operation: \"createCMS\" },\n\t\t});\n\t}\n\n\t// collections が指定されたコレクションは slug が必須。\n\tfor (const [name, col] of Object.entries(opts.collections ?? {})) {\n\t\tconst c = col as CollectionSemantics | undefined;\n\t\tif (c && !c.slug) {\n\t\t\tthrow new CMSError({\n\t\t\t\tcode: \"core/config_invalid\",\n\t\t\t\tmessage: `createCMS: コレクション \"${name}\" の collections.slug は必須です。slug として使うフィールド名を指定してください。`,\n\t\t\t\tcontext: { operation: \"createCMS\", collection: name },\n\t\t\t});\n\t\t}\n\t}\n\n\tconst resolved = resolvePreset(opts);\n\n\tconst baseDocCache = resolveDocumentCache(resolved.cache);\n\tconst imgCache = resolveImageCache(resolved.cache);\n\tconst hasImageCache = hasImageCacheConfigured(resolved.cache);\n\tconst ttlMs = resolveTtl(resolved.cache);\n\tconst imageProxyBase =\n\t\topts.content?.imageProxyBase ?? DEFAULT_IMAGE_PROXY_BASE;\n\tconst contentConfig = opts.content;\n\tconst rendererFn: RendererFn | undefined = resolved.renderer;\n\tconst waitUntil = opts.waitUntil;\n\tconst logger: Logger | undefined = mergeLoggers(\n\t\topts.plugins ?? [],\n\t\topts.logger,\n\t);\n\tconst hooks: CMSHooks<BaseContentItem> = mergeHooks(\n\t\topts.plugins ?? [],\n\t\topts.hooks,\n\t\tlogger,\n\t);\n\tconst maxConcurrent = opts.rateLimiter?.maxConcurrent ?? 3;\n\tconst retryConfig: RetryConfig = {\n\t\t...DEFAULT_RETRY_CONFIG,\n\t\t...(opts.rateLimiter ?? {}),\n\t};\n\n\tconst collectionNames = Object.keys(opts.dataSources) as (keyof D & string)[];\n\n\t// biome-ignore lint/suspicious/noExplicitAny: 各 T を保持\n\tconst collections: Record<string, CollectionClient<any>> = {};\n\tfor (const name of collectionNames) {\n\t\tconst source = opts.dataSources[name] as DataSource<BaseContentItem>;\n\t\tconst scopedCache = scopeDocumentCache<BaseContentItem>(baseDocCache, name);\n\t\tconst renderCtx: RenderContext<BaseContentItem> = {\n\t\t\tsource,\n\t\t\trendererFn,\n\t\t\timgCache,\n\t\t\thasImageCache,\n\t\t\timageProxyBase,\n\t\t\tcontentConfig,\n\t\t\thooks,\n\t\t\tlogger,\n\t\t};\n\t\tconst col = opts.collections?.[name] as CollectionSemantics | undefined;\n\t\tconst ctx: CollectionContext<BaseContentItem> = {\n\t\t\tcollection: name,\n\t\t\tsource,\n\t\t\tdocCache: scopedCache,\n\t\t\trender: renderCtx,\n\t\t\thooks,\n\t\t\tlogger,\n\t\t\tttlMs,\n\t\t\t// 公開条件は CollectionSemantics(createCMS の collections オプション)が権威\n\t\t\tpublishedStatuses: col?.publishedStatuses\n\t\t\t\t? [...col.publishedStatuses]\n\t\t\t\t: [],\n\t\t\taccessibleStatuses: col?.accessibleStatuses\n\t\t\t\t? [...col.accessibleStatuses]\n\t\t\t\t: [],\n\t\t\tretryConfig,\n\t\t\tmaxConcurrent,\n\t\t\twaitUntil,\n\t\t\tslugField: col?.slug,\n\t\t};\n\t\tcollections[name] = new CollectionClientImpl(ctx);\n\t}\n\n\tconst globalOps: CMSGlobalOps<D> = {\n\t\t$collections: collectionNames,\n\t\tasync $revalidate(scope?: InvalidateScope): Promise<void> {\n\t\t\tif (!baseDocCache.invalidate) return;\n\t\t\tawait baseDocCache.invalidate(scope ?? \"all\");\n\t\t},\n\t\t$handler(handlerOpts?: HandlerOptions) {\n\t\t\treturn createHandler(\n\t\t\t\t{\n\t\t\t\t\timageCache: imgCache,\n\t\t\t\t\tparseWebhook: async (req, webhookSecret) => {\n\t\t\t\t\t\t// 各 DataSource の parseWebhook を順に試す\n\t\t\t\t\t\tfor (const name of collectionNames) {\n\t\t\t\t\t\t\tconst ds = opts.dataSources[name] as DataSource<BaseContentItem>;\n\t\t\t\t\t\t\tif (ds.parseWebhook) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst scope = await ds.parseWebhook(req.clone(), {\n\t\t\t\t\t\t\t\t\t\tsecret: webhookSecret,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn scope;\n\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\tlogger?.warn?.(\"parseWebhook 失敗\", {\n\t\t\t\t\t\t\t\t\t\tcollection: name,\n\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// フォールバック: { slug } だけの汎用 JSON body\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst body = (await req.json()) as {\n\t\t\t\t\t\t\t\tslug?: string;\n\t\t\t\t\t\t\t\tcollection?: string;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (body.slug && body.collection) {\n\t\t\t\t\t\t\t\treturn { collection: body.collection, slug: body.slug };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (body.collection) {\n\t\t\t\t\t\t\t\treturn { collection: body.collection };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// ignore\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t},\n\t\t\t\t\trevalidate: (scope) => globalOps.$revalidate(scope),\n\t\t\t\t},\n\t\t\t\thandlerOpts,\n\t\t\t);\n\t\t},\n\t\t$getCachedImage(hash) {\n\t\t\treturn imgCache.get(hash);\n\t\t},\n\t};\n\n\treturn Object.assign(\n\t\tObject.create(null) as object,\n\t\tcollections,\n\t\tglobalOps,\n\t) as CMSClient<D>;\n}\n","import type { BaseContentItem } from \"./content\";\nimport type { CMSHooks } from \"./hooks\";\nimport type { Logger } from \"./logger\";\n\nexport interface CMSPlugin<T extends BaseContentItem = BaseContentItem> {\n\tname: string;\n\thooks?: CMSHooks<T>;\n\tlogger?: Partial<Logger>;\n}\n\nexport function definePlugin<T extends BaseContentItem>(\n\tplugin: CMSPlugin<T>,\n): CMSPlugin<T> {\n\treturn plugin;\n}\n"],"mappings":";;;;;;AACA,eAAsB,UAAU,OAAgC;CAC/D,MAAM,OAAO,IAAI,aAAa,CAAC,OAAO,MAAM;CAC5C,MAAM,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AACxD,QAAO,MAAM,KAAK,IAAI,WAAW,KAAK,CAAC,CACrC,KAAK,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAC3C,KAAK,GAAG;;;;;;AAOX,SAAgB,QAAQ,UAAkB,OAAyB;AAClE,KAAI,UAAU,KAAA,EAAW,QAAO;AAChC,QAAO,KAAK,KAAK,GAAG,WAAW;;;;;ACVhC,SAAS,iBACR,KACA,qBACS;AACT,KAAI,qBAAqB,WAAW,SAAS,CAC5C,QAAO,oBAAoB,MAAM,IAAI,CAAC,GAAG,MAAM;AAEhD,KAAI,IAAI,SAAS,OAAO,CAAE,QAAO;AACjC,KAAI,IAAI,SAAS,OAAO,CAAE,QAAO;AACjC,KAAI,IAAI,SAAS,QAAQ,CAAE,QAAO;AAClC,QAAO;;;;;;AAOR,eAAe,mBACd,OACA,WACA,gBACkB;CAClB,MAAM,OAAO,MAAM,UAAU,UAAU;CACvC,MAAM,WAAW,GAAG,eAA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lD,MAAM,YAA6B;EAClC,cAAc;EACd,MAAM,YAAY,OAAwC;AACzD,OAAI,CAAC,aAAa,WAAY;AAC9B,SAAM,aAAa,WAAW,SAAS,MAAM;;EAE9C,SAAS,aAA8B;AACtC,UAAO,cACN;IACC,YAAY;IACZ,cAAc,OAAO,KAAK,kBAAkB;AAE3C,UAAK,MAAM,QAAQ,iBAAiB;MACnC,MAAM,KAAK,KAAK,YAAY;AAC5B,UAAI,GAAG,aACN,KAAI;AAIH,cAAO,MAHa,GAAG,aAAa,IAAI,OAAO,EAAE,EAChD,QAAQ,eACR,CAAC;eAEM,KAAK;AACb,eAAQ,OAAO,mBAAmB;QACjC,YAAY;QACZ,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;QACvD,CAAC;;;AAKL,SAAI;MACH,MAAM,OAAQ,MAAM,IAAI,MAAM;AAI9B,UAAI,KAAK,QAAQ,KAAK,WACrB,QAAO;OAAE,YAAY,KAAK;OAAY,MAAM,KAAK;OAAM;AAExD,UAAI,KAAK,WACR,QAAO,EAAE,YAAY,KAAK,YAAY;aAEhC;AAGR,YAAO;;IAER,aAAa,UAAU,UAAU,YAAY,MAAM;IACnD,EACD,YACA;;EAEF,gBAAgB,MAAM;AACrB,UAAO,SAAS,IAAI,KAAK;;EAE1B;AAED,QAAO,OAAO,OACb,OAAO,OAAO,KAAK,EACnB,aACA,UACA;;;;AC9RF,SAAgB,aACf,QACe;AACf,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/cache.ts","../src/image.ts","../src/rendering.ts","../src/retry.ts","../src/collection.ts","../src/handler.ts","../src/preset-node.ts","../src/cms.ts","../src/types/plugin.ts"],"sourcesContent":["/** 文字列をSHA-256でハッシュ化し、16進数文字列として返す。画像キーの生成に使用。 */\nexport async function sha256Hex(input: string): Promise<string> {\n\tconst data = new TextEncoder().encode(input);\n\tconst hash = await crypto.subtle.digest(\"SHA-256\", data);\n\treturn Array.from(new Uint8Array(hash))\n\t\t.map((b) => b.toString(16).padStart(2, \"0\"))\n\t\t.join(\"\");\n}\n\n/**\n * キャッシュが有効期限切れかどうかを判定する。\n * ttlMs が未指定の場合は常に false(無期限有効)を返す。\n */\nexport function isStale(cachedAt: number, ttlMs?: number): boolean {\n\tif (ttlMs === undefined) return false;\n\treturn Date.now() - cachedAt > ttlMs;\n}\n","import { sha256Hex } from \"./cache\";\nimport { CMSError, isCMSError } from \"./errors\";\nimport type { ImageCacheAdapter, Logger, StorageBinary } from \"./types/index\";\n\n/** レスポンスヘッダまたはURLの拡張子からContent-Typeを推測する。 */\nfunction inferContentType(\n\turl: string,\n\tresponseContentType: string | null,\n): string {\n\tif (responseContentType?.startsWith(\"image/\")) {\n\t\treturn responseContentType.split(\";\")[0].trim();\n\t}\n\tif (url.includes(\".png\")) return \"image/png\";\n\tif (url.includes(\".gif\")) return \"image/gif\";\n\tif (url.includes(\".webp\")) return \"image/webp\";\n\treturn \"image/jpeg\";\n}\n\n/**\n * Notion画像URLをfetchしてImageCacheAdapterにキャッシュし、プロキシURL を返す。\n * 既存キャッシュがあれば再fetchしない。\n */\nasync function fetchAndCacheImage(\n\tcache: ImageCacheAdapter,\n\tnotionUrl: string,\n\timageProxyBase: string,\n\tlogger?: Logger,\n): Promise<string> {\n\tconst hash = await sha256Hex(notionUrl);\n\tconst proxyUrl = `${imageProxyBase}/${hash}`;\n\n\tconst existing = await cache.get(hash);\n\tif (existing) {\n\t\tlogger?.debug?.(\"画像キャッシュヒット\", {\n\t\t\toperation: \"fetchAndCacheImage\",\n\t\t\tcacheAdapter: cache.name,\n\t\t\timageHash: hash,\n\t\t});\n\t\treturn proxyUrl;\n\t}\n\n\tlogger?.debug?.(\"画像キャッシュミス、Notion からフェッチ\", {\n\t\toperation: \"fetchAndCacheImage\",\n\t\tcacheAdapter: cache.name,\n\t\timageHash: hash,\n\t});\n\n\ttry {\n\t\tconst response = await fetch(notionUrl, {\n\t\t\tsignal: AbortSignal.timeout(10_000),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow new CMSError({\n\t\t\t\tcode: \"cache/image_fetch_failed\",\n\t\t\t\tmessage: `Failed to fetch Notion image: HTTP ${response.status}`,\n\t\t\t\tcontext: {\n\t\t\t\t\toperation: \"fetchAndCacheImage\",\n\t\t\t\t\tnotionUrl,\n\t\t\t\t\thttpStatus: response.status,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\tconst data = await response.arrayBuffer();\n\t\tconst contentType = inferContentType(\n\t\t\tnotionUrl,\n\t\t\tresponse.headers.get(\"content-type\"),\n\t\t);\n\t\tawait cache.set(hash, data, contentType);\n\t\tlogger?.debug?.(\"画像をキャッシュに保存\", {\n\t\t\toperation: \"fetchAndCacheImage\",\n\t\t\tcacheAdapter: cache.name,\n\t\t\timageHash: hash,\n\t\t});\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"cache/io_failed\",\n\t\t\tmessage: \"Failed to fetch or cache Notion image.\",\n\t\t\tcause: err,\n\t\t\tcontext: { operation: \"fetchAndCacheImage\", notionUrl },\n\t\t});\n\t}\n\n\treturn proxyUrl;\n}\n\n/** ImageCacheAdapter と imageProxyBase から cacheImage 関数を構築するファクトリ。 */\nexport function buildCacheImageFn(\n\tcache: ImageCacheAdapter,\n\timageProxyBase: string,\n\tlogger?: Logger,\n): (notionUrl: string) => Promise<string> {\n\treturn (notionUrl) =>\n\t\tfetchAndCacheImage(cache, notionUrl, imageProxyBase, logger);\n}\n\nexport type { StorageBinary };\n","import type { ContentBlock } from \"./content/blocks\";\nimport { CMSError, isCMSError } from \"./errors\";\nimport { buildCacheImageFn } from \"./image\";\nimport type {\n\tBaseContentItem,\n\tCachedItem,\n\tCMSHooks,\n\tContentConfig,\n\tDataSource,\n\tImageCacheAdapter,\n\tLogger,\n\tRendererFn,\n} from \"./types/index\";\n\n/** `buildCachedItem` に必要な CMS の依存を束ねたコンテキスト。 */\nexport interface RenderContext<T extends BaseContentItem> {\n\tsource: DataSource<T>;\n\trendererFn: RendererFn | undefined;\n\timgCache: ImageCacheAdapter;\n\thasImageCache: boolean;\n\timageProxyBase: string;\n\tcontentConfig: ContentConfig | undefined;\n\thooks: CMSHooks<T>;\n\tlogger: Logger | undefined;\n}\n\n/**\n * コンテンツアイテムをソースから Markdown ロード → blocks 生成 → HTML レンダリング\n * → フック適用まで実行し、キャッシュ保存用の `CachedItem` を返す。\n */\nexport async function buildCachedItem<T extends BaseContentItem>(\n\titem: T,\n\tctx: RenderContext<T>,\n): Promise<CachedItem<T>> {\n\tconst start = Date.now();\n\tctx.logger?.info?.(\"コンテンツのレンダリング開始\", {\n\t\tslug: item.slug,\n\t\tpageId: item.id,\n\t});\n\tctx.hooks.onRenderStart?.(item.slug);\n\n\tlet markdown: string;\n\ttry {\n\t\tmarkdown = await ctx.source.loadMarkdown(item);\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"source/load_markdown_failed\",\n\t\t\tmessage: \"Failed to load markdown from source.\",\n\t\t\tcause: err,\n\t\t\tcontext: {\n\t\t\t\toperation: \"buildCachedItem:loadMarkdown\",\n\t\t\t\tpageId: item.id,\n\t\t\t\tslug: item.slug,\n\t\t\t},\n\t\t});\n\t}\n\n\tlet blocks: ContentBlock[] = [];\n\ttry {\n\t\tblocks = await ctx.source.loadBlocks(item);\n\t} catch (err) {\n\t\tctx.logger?.warn?.(\"loadBlocks に失敗したため raw フォールバック\", {\n\t\t\tslug: item.slug,\n\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t});\n\t\tblocks = [];\n\t}\n\n\tconst cacheImage = ctx.hasImageCache\n\t\t? buildCacheImageFn(ctx.imgCache, ctx.imageProxyBase, ctx.logger)\n\t\t: undefined;\n\n\tlet html: string;\n\tconst rendererFn = ctx.rendererFn ?? (await loadDefaultRenderer());\n\ttry {\n\t\thtml = await rendererFn(markdown, {\n\t\t\timageProxyBase: ctx.imageProxyBase,\n\t\t\tcacheImage,\n\t\t\tremarkPlugins: ctx.contentConfig?.remarkPlugins,\n\t\t\trehypePlugins: ctx.contentConfig?.rehypePlugins,\n\t\t});\n\t} catch (err) {\n\t\tif (isCMSError(err)) throw err;\n\t\tthrow new CMSError({\n\t\t\tcode: \"renderer/failed\",\n\t\t\tmessage: \"Failed to render markdown.\",\n\t\t\tcause: err,\n\t\t\tcontext: {\n\t\t\t\toperation: \"buildCachedItem:renderMarkdown\",\n\t\t\t\tpageId: item.id,\n\t\t\t\tslug: item.slug,\n\t\t\t},\n\t\t});\n\t}\n\n\tif (ctx.hooks.afterRender) {\n\t\thtml = await ctx.hooks.afterRender(html, item);\n\t}\n\n\tlet result: CachedItem<T> = {\n\t\thtml,\n\t\tblocks,\n\t\tmarkdown,\n\t\titem,\n\t\tnotionUpdatedAt: ctx.source.getLastModified(item),\n\t\tcachedAt: Date.now(),\n\t};\n\n\tif (ctx.hooks.beforeCache) {\n\t\tresult = (await ctx.hooks.beforeCache(result)) as CachedItem<T>;\n\t}\n\n\tconst durationMs = Date.now() - start;\n\tctx.logger?.info?.(\"コンテンツのレンダリング完了\", {\n\t\tslug: item.slug,\n\t\tdurationMs,\n\t});\n\tctx.hooks.onRenderEnd?.(item.slug, durationMs);\n\n\treturn result;\n}\n\n/**\n * renderer オプション未指定時のフォールバック。\n * @notion-headless-cms/renderer を動的 import する。\n * createCMS({ renderer }) で明示注入された場合はこのパスを通らない。\n */\nexport async function loadDefaultRenderer(): Promise<RendererFn> {\n\ttry {\n\t\tconst mod = await import(\"@notion-headless-cms/renderer\");\n\t\treturn mod.renderMarkdown as RendererFn;\n\t} catch (err) {\n\t\tthrow new CMSError({\n\t\t\tcode: \"renderer/failed\",\n\t\t\tmessage:\n\t\t\t\t\"renderer オプションが未指定で @notion-headless-cms/renderer が見つかりません。\" +\n\t\t\t\t\" createCMS({ renderer }) でレンダラーを注入するか、@notion-headless-cms/renderer をインストールしてください。\",\n\t\t\tcause: err,\n\t\t\tcontext: { operation: \"loadDefaultRenderer\" },\n\t\t});\n\t}\n}\n","export interface RetryConfig {\n\tretryOn: number[];\n\tmaxRetries: number;\n\tbaseDelayMs: number;\n\t/** true のとき指数バックオフにランダムジッターを加える(Thundering Herd 対策)。デフォルト: true */\n\tjitter?: boolean;\n\tonRetry?: (attempt: number, status: number) => void;\n}\n\nexport const DEFAULT_RETRY_CONFIG: RetryConfig = {\n\tretryOn: [429, 502, 503],\n\tmaxRetries: 4,\n\tbaseDelayMs: 1000,\n\tjitter: true,\n};\n\n/** 指数バックオフ(オプションでジッター付き)でリトライする。retryOn に含まれる HTTP エラーのみ対象。 */\nexport async function withRetry<T>(\n\tfn: () => Promise<T>,\n\tconfig: RetryConfig,\n): Promise<T> {\n\tlet lastError: unknown;\n\tfor (let attempt = 0; attempt <= config.maxRetries; attempt++) {\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} catch (err) {\n\t\t\tconst status = (err as { status?: number }).status;\n\t\t\tif (status === undefined || !config.retryOn.includes(status)) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tlastError = err;\n\t\t\tif (attempt < config.maxRetries) {\n\t\t\t\tconfig.onRetry?.(attempt + 1, status);\n\t\t\t\tconst jitterFactor =\n\t\t\t\t\tconfig.jitter !== false ? 0.5 + Math.random() * 0.5 : 1;\n\t\t\t\tconst delay = config.baseDelayMs * 2 ** attempt * jitterFactor;\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delay));\n\t\t\t}\n\t\t}\n\t}\n\tthrow lastError;\n}\n","import { isStale } from \"./cache\";\nimport type { ContentBlock, ContentResult } from \"./content/blocks\";\nimport type { RenderContext } from \"./rendering\";\nimport { buildCachedItem } from \"./rendering\";\nimport type { RetryConfig } from \"./retry\";\nimport { withRetry } from \"./retry\";\nimport type {\n\tAdjacencyOptions,\n\tBaseContentItem,\n\tCachedItem,\n\tCachedItemList,\n\tCMSHooks,\n\tCollectionClient,\n\tDataSource,\n\tDocumentCacheAdapter,\n\tGetListOptions,\n\tItemWithContent,\n\tLogger,\n\tSortOption,\n} from \"./types/index\";\n\n/**\n * コレクション別キャッシュキーを生成する。\n * item: `{collection}:{slug}` / list: `{collection}`\n */\nexport function collectionKey(collection: string, slug?: string): string {\n\treturn slug ? `${collection}:${slug}` : collection;\n}\n\n/** 単一コレクションの DataSource + SWR キャッシュ依存を束ねたコンテキスト。 */\nexport interface CollectionContext<T extends BaseContentItem> {\n\tcollection: string;\n\tsource: DataSource<T>;\n\tdocCache: DocumentCacheAdapter<T>;\n\trender: RenderContext<T>;\n\thooks: CMSHooks<T>;\n\tlogger: Logger | undefined;\n\tttlMs: number | undefined;\n\tpublishedStatuses: string[];\n\taccessibleStatuses: string[];\n\tretryConfig: RetryConfig;\n\tmaxConcurrent: number;\n\twaitUntil: ((p: Promise<unknown>) => void) | undefined;\n\t/**\n\t * slug として使うフィールド名。\n\t * `createCMS({ collections })` で指定した値。\n\t * 設定時は `source.properties[slugField].notion` を Notion プロパティ名として\n\t * `findByProp` を呼び出す。\n\t */\n\tslugField?: string;\n}\n\n/** CollectionClient の実装。ユーザーは `createCMS` 経由でインスタンスを受け取る。 */\nexport class CollectionClientImpl<T extends BaseContentItem>\n\timplements CollectionClient<T>\n{\n\tconstructor(private readonly ctx: CollectionContext<T>) {}\n\n\t// ── 基本取得 ──────────────────────────────────────────────────────────\n\n\tasync getItem(slug: string): Promise<ItemWithContent<T> | null> {\n\t\tconst cached = await this.ctx.docCache.getItem(slug);\n\t\tif (cached) {\n\t\t\tif (\n\t\t\t\tthis.ctx.ttlMs !== undefined &&\n\t\t\t\tisStale(cached.cachedAt, this.ctx.ttlMs)\n\t\t\t) {\n\t\t\t\t// TTL 設定あり + 期限切れ: ブロッキングフェッチ(stale を返さない)\n\t\t\t\tthis.ctx.logger?.debug?.(\"キャッシュ期限切れ(TTL)、フェッチ\", {\n\t\t\t\t\toperation: \"getItem\",\n\t\t\t\t\tslug,\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t\t\t});\n\t\t\t\tthis.ctx.hooks.onCacheMiss?.(slug);\n\t\t\t\tconst item = await this.findRaw(slug);\n\t\t\t\tif (!item) return null;\n\t\t\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\t\t\tawait this.ctx.docCache.setItem(slug, entry);\n\t\t\t\treturn this.attachContent(entry.item, entry);\n\t\t\t}\n\t\t\t// TTL 未設定 or 期限内: キャッシュを即時返却し、バックグラウンドで差分チェック\n\t\t\tconst bg = this.checkAndUpdateItemBg(slug, cached);\n\t\t\tif (this.ctx.waitUntil) {\n\t\t\t\tthis.ctx.waitUntil(bg);\n\t\t\t}\n\t\t\tthis.ctx.logger?.debug?.(\"キャッシュヒット\", {\n\t\t\t\toperation: \"getItem\",\n\t\t\t\tslug,\n\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t\t\tcachedAt: cached.cachedAt,\n\t\t\t});\n\t\t\tthis.ctx.hooks.onCacheHit?.(slug, cached);\n\t\t\treturn this.attachContent(cached.item, cached);\n\t\t}\n\n\t\t// キャッシュなし: 同期フェッチ\n\t\tthis.ctx.logger?.debug?.(\"キャッシュミス、フェッチ\", {\n\t\t\toperation: \"getItem\",\n\t\t\tslug,\n\t\t\tcollection: this.ctx.collection,\n\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t});\n\t\tthis.ctx.hooks.onCacheMiss?.(slug);\n\t\tconst item = await this.findRaw(slug);\n\t\tif (!item) {\n\t\t\tthis.ctx.logger?.debug?.(\"アイテムが見つかりません\", {\n\t\t\t\toperation: \"getItem\",\n\t\t\t\tslug,\n\t\t\t\tcollection: this.ctx.collection,\n\t\t\t});\n\t\t\treturn null;\n\t\t}\n\n\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\tconst save = this.ctx.docCache.setItem(slug, entry);\n\t\tif (this.ctx.waitUntil) {\n\t\t\tthis.ctx.waitUntil(save);\n\t\t} else {\n\t\t\tawait save;\n\t\t}\n\n\t\treturn this.attachContent(entry.item, entry);\n\t}\n\n\tasync getList(opts?: GetListOptions<T>): Promise<T[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn applyGetListOptions(items, opts);\n\t}\n\n\t// ── SSG / ナビゲーション ─────────────────────────────────────────────\n\n\tasync getStaticParams(): Promise<{ slug: string }[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn items.map((item) => ({ slug: item.slug }));\n\t}\n\n\tasync getStaticPaths(): Promise<string[]> {\n\t\tconst items = await this.fetchList();\n\t\treturn items.map((item) => item.slug);\n\t}\n\n\tasync adjacent(\n\t\tslug: string,\n\t\topts?: AdjacencyOptions<T>,\n\t): Promise<{ prev: T | null; next: T | null }> {\n\t\tconst items = applyGetListOptions(await this.fetchList(), {\n\t\t\tsort: opts?.sort,\n\t\t});\n\t\tconst index = items.findIndex((it) => it.slug === slug);\n\t\tif (index === -1) return { prev: null, next: null };\n\t\treturn {\n\t\t\tprev: index > 0 ? (items[index - 1] ?? null) : null,\n\t\t\tnext: index < items.length - 1 ? (items[index + 1] ?? null) : null,\n\t\t};\n\t}\n\n\t// ── キャッシュ ────────────────────────────────────────────────────────\n\n\tasync revalidate(scope?: \"all\" | { slug: string }): Promise<void> {\n\t\tthis.ctx.logger?.debug?.(\"キャッシュを無効化\", {\n\t\t\toperation: \"revalidate\",\n\t\t\tcollection: this.ctx.collection,\n\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t\tslug: typeof scope === \"object\" ? scope.slug : undefined,\n\t\t});\n\t\tif (!this.ctx.docCache.invalidate) return;\n\t\tif (scope === undefined || scope === \"all\") {\n\t\t\tawait this.ctx.docCache.invalidate({ collection: this.ctx.collection });\n\t\t} else {\n\t\t\tawait this.ctx.docCache.invalidate({\n\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\tslug: scope.slug,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync prefetch(opts?: {\n\t\tconcurrency?: number;\n\t\tonProgress?: (done: number, total: number) => void;\n\t}): Promise<{ ok: number; failed: number }> {\n\t\tconst items = await this.fetchListRaw();\n\t\tconst concurrency = opts?.concurrency ?? this.ctx.maxConcurrent;\n\t\tlet ok = 0;\n\t\tlet failed = 0;\n\n\t\tfor (let i = 0; i < items.length; i += concurrency) {\n\t\t\tconst chunk = items.slice(i, i + concurrency);\n\t\t\tawait Promise.all(\n\t\t\t\tchunk.map(async (item) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst rendered = await buildCachedItem(item, this.ctx.render);\n\t\t\t\t\t\tawait this.ctx.docCache.setItem(item.slug, rendered);\n\t\t\t\t\t\tok++;\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tfailed++;\n\t\t\t\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\t\t\t\"prefetch: アイテムの事前レンダリングに失敗\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tslug: item.slug,\n\t\t\t\t\t\t\t\tpageId: item.id,\n\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t\topts?.onProgress?.(Math.min(i + concurrency, items.length), items.length);\n\t\t}\n\n\t\tawait this.ctx.docCache.setList({ items, cachedAt: Date.now() });\n\t\treturn { ok, failed };\n\t}\n\n\t// ── 内部 ──────────────────────────────────────────────────────────────\n\n\tprivate attachContent(item: T, cached: CachedItem<T>): ItemWithContent<T> {\n\t\tconst ctx = this.ctx;\n\t\tlet blocksCache: ContentBlock[] | undefined;\n\t\tlet htmlCache: string | undefined = cached.html;\n\t\tlet markdownCache: string | undefined;\n\n\t\tconst content: ContentResult = {\n\t\t\tget blocks(): ContentBlock[] {\n\t\t\t\tif (!blocksCache) {\n\t\t\t\t\t// lazy: キャッシュに blocks が保存されていない場合、簡易な single-raw に落とす\n\t\t\t\t\tblocksCache = [\n\t\t\t\t\t\t{ type: \"raw\", html: cached.html } satisfies ContentBlock,\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\treturn blocksCache;\n\t\t\t},\n\t\t\tasync html(): Promise<string> {\n\t\t\t\tif (htmlCache !== undefined) return htmlCache;\n\t\t\t\thtmlCache = cached.html;\n\t\t\t\treturn htmlCache;\n\t\t\t},\n\t\t\tasync markdown(): Promise<string> {\n\t\t\t\tif (markdownCache !== undefined) return markdownCache;\n\t\t\t\tmarkdownCache = await ctx.source.loadMarkdown(item);\n\t\t\t\treturn markdownCache;\n\t\t\t},\n\t\t};\n\n\t\tif (cached.blocks) blocksCache = cached.blocks;\n\n\t\treturn Object.assign(Object.create(null) as object, item, {\n\t\t\tcontent,\n\t\t}) as ItemWithContent<T>;\n\t}\n\n\tprivate async fetchList(): Promise<T[]> {\n\t\tconst cached = await this.ctx.docCache.getList();\n\t\tif (cached) {\n\t\t\tif (\n\t\t\t\tthis.ctx.ttlMs !== undefined &&\n\t\t\t\tisStale(cached.cachedAt, this.ctx.ttlMs)\n\t\t\t) {\n\t\t\t\t// TTL 設定あり + 期限切れ: ブロッキングフェッチ(stale を返さない)\n\t\t\t\tthis.ctx.logger?.debug?.(\"リストキャッシュ期限切れ(TTL)、フェッチ\", {\n\t\t\t\t\toperation: \"getList\",\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t\t\t});\n\t\t\t\tthis.ctx.hooks.onListCacheMiss?.();\n\t\t\t\tconst items = await this.fetchListRaw();\n\t\t\t\tawait this.ctx.docCache.setList({ items, cachedAt: Date.now() });\n\t\t\t\treturn items;\n\t\t\t}\n\t\t\t// TTL 未設定 or 期限内: キャッシュを即時返却し、バックグラウンドで差分チェック\n\t\t\tconst bg = this.checkAndUpdateListBg(cached);\n\t\t\tif (this.ctx.waitUntil) {\n\t\t\t\tthis.ctx.waitUntil(bg);\n\t\t\t}\n\t\t\tthis.ctx.logger?.debug?.(\"リストキャッシュヒット\", {\n\t\t\t\toperation: \"getList\",\n\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t\t});\n\t\t\tthis.ctx.hooks.onListCacheHit?.(cached);\n\t\t\treturn cached.items;\n\t\t}\n\n\t\t// キャッシュなし: 同期フェッチ\n\t\tthis.ctx.logger?.debug?.(\"リストキャッシュミス、フェッチ\", {\n\t\t\toperation: \"getList\",\n\t\t\tcollection: this.ctx.collection,\n\t\t\tcacheAdapter: this.ctx.docCache.name,\n\t\t});\n\t\tthis.ctx.hooks.onListCacheMiss?.();\n\t\tconst items = await this.fetchListRaw();\n\t\tconst cachedAt = Date.now();\n\t\tconst save = this.ctx.docCache.setList({ items, cachedAt });\n\t\tif (this.ctx.waitUntil) {\n\t\t\tthis.ctx.waitUntil(save);\n\t\t} else {\n\t\t\tawait save;\n\t\t}\n\t\treturn items;\n\t}\n\n\tprivate async checkAndUpdateItemBg(\n\t\tslug: string,\n\t\tcached: CachedItem<T>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst item = await this.findRaw(slug);\n\t\t\tif (!item) return;\n\t\t\tif (this.ctx.source.getLastModified(item) !== cached.notionUpdatedAt) {\n\t\t\t\t// 更新あり: 再レンダリングしてキャッシュを差し替える\n\t\t\t\tconst entry = await buildCachedItem(item, this.ctx.render);\n\t\t\t\tawait this.ctx.docCache.setItem(slug, entry);\n\t\t\t\tthis.ctx.logger?.debug?.(\"SWR: 差分を検出、キャッシュを差し替え\", {\n\t\t\t\t\toperation: \"getItem:bg\",\n\t\t\t\t\tslug,\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\tnotionUpdatedAt: cached.notionUpdatedAt,\n\t\t\t\t});\n\t\t\t\tthis.ctx.hooks.onCacheRevalidated?.(slug, entry);\n\t\t\t} else if (this.ctx.ttlMs !== undefined) {\n\t\t\t\t// 変更なし + TTL あり: cachedAt をリセットして次回の期限切れを先送りする\n\t\t\t\tawait this.ctx.docCache.setItem(slug, {\n\t\t\t\t\t...cached,\n\t\t\t\t\tcachedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\tthis.ctx.logger?.debug?.(\"SWR: 差分なし、TTL をリセット\", {\n\t\t\t\t\toperation: \"getItem:bg\",\n\t\t\t\t\tslug,\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\"SWR: アイテムのバックグラウンド差分チェックに失敗\",\n\t\t\t\t{\n\t\t\t\t\tslug,\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async checkAndUpdateListBg(cached: CachedItemList<T>): Promise<void> {\n\t\ttry {\n\t\t\tconst items = await this.fetchListRaw();\n\t\t\tif (\n\t\t\t\tthis.ctx.source.getListVersion(items) !==\n\t\t\t\tthis.ctx.source.getListVersion(cached.items)\n\t\t\t) {\n\t\t\t\t// 更新あり: リストを差し替える\n\t\t\t\tconst listEntry = { items, cachedAt: Date.now() };\n\t\t\t\tawait this.ctx.docCache.setList(listEntry);\n\t\t\t\tthis.ctx.logger?.debug?.(\n\t\t\t\t\t\"SWR: リスト差分を検出、キャッシュを差し替え\",\n\t\t\t\t\t{\n\t\t\t\t\t\toperation: \"getList:bg\",\n\t\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tthis.ctx.hooks.onListCacheRevalidated?.(listEntry);\n\t\t\t} else if (this.ctx.ttlMs !== undefined) {\n\t\t\t\t// 変更なし + TTL あり: cachedAt をリセットする\n\t\t\t\tawait this.ctx.docCache.setList({\n\t\t\t\t\t...cached,\n\t\t\t\t\tcachedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\tthis.ctx.logger?.debug?.(\"SWR: リスト差分なし、TTL をリセット\", {\n\t\t\t\t\toperation: \"getList:bg\",\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthis.ctx.logger?.warn?.(\n\t\t\t\t\"SWR: リストのバックグラウンド差分チェックに失敗\",\n\t\t\t\t{\n\t\t\t\t\tcollection: this.ctx.collection,\n\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate fetchListRaw(): Promise<T[]> {\n\t\treturn withRetry(\n\t\t\t() =>\n\t\t\t\tthis.ctx.source.list({\n\t\t\t\t\tpublishedStatuses:\n\t\t\t\t\t\tthis.ctx.publishedStatuses.length > 0\n\t\t\t\t\t\t\t? this.ctx.publishedStatuses\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t}),\n\t\t\t{\n\t\t\t\t...this.ctx.retryConfig,\n\t\t\t\tonRetry: (attempt, status) => {\n\t\t\t\t\tthis.ctx.logger?.warn?.(\"getList() リトライ中\", { attempt, status });\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async findRaw(slug: string): Promise<T | null> {\n\t\tconst retryOpts = {\n\t\t\t...this.ctx.retryConfig,\n\t\t\tonRetry: (attempt: number, status: number) => {\n\t\t\t\tthis.ctx.logger?.warn?.(\"getItem() リトライ中\", {\n\t\t\t\t\tattempt,\n\t\t\t\t\tstatus,\n\t\t\t\t\tslug,\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\n\t\t// slug フィールドが指定され、DataSource が findByProp を持つ場合は\n\t\t// Notion プロパティ名を解決して効率的なフィルタクエリを実行する。\n\t\tconst slugField = this.ctx.slugField;\n\t\tconst notionPropName = slugField\n\t\t\t? this.ctx.source.properties?.[slugField]?.notion\n\t\t\t: undefined;\n\n\t\tlet item: T | null;\n\t\tconst findByProp = this.ctx.source.findByProp?.bind(this.ctx.source);\n\t\tif (notionPropName && findByProp) {\n\t\t\titem = await withRetry(() => findByProp(notionPropName, slug), retryOpts);\n\t\t} else {\n\t\t\t// フォールバック: list して線形探索\n\t\t\tconst all = await withRetry(() => this.ctx.source.list(), retryOpts);\n\t\t\titem = all.find((i) => i.slug === slug) ?? null;\n\t\t}\n\n\t\tif (!item) return null;\n\t\tif (\n\t\t\tthis.ctx.accessibleStatuses.length > 0 &&\n\t\t\t(!item.status || !this.ctx.accessibleStatuses.includes(item.status))\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn item;\n\t}\n}\n\nfunction applyGetListOptions<T extends BaseContentItem>(\n\titems: T[],\n\topts?: GetListOptions<T>,\n): T[] {\n\tif (!opts) return items;\n\tlet result = items;\n\n\tif (opts.statuses && opts.statuses.length > 0) {\n\t\tconst allow = new Set(opts.statuses);\n\t\tresult = result.filter(\n\t\t\t(it) => it.status !== undefined && allow.has(it.status),\n\t\t);\n\t}\n\n\tif (opts.tag) {\n\t\tconst tag = opts.tag;\n\t\tresult = result.filter((it) => {\n\t\t\tconst tags = (it as unknown as { tags?: unknown }).tags;\n\t\t\treturn Array.isArray(tags) && tags.includes(tag);\n\t\t});\n\t}\n\n\tif (opts.where) {\n\t\tconst where = opts.where;\n\t\tresult = result.filter((it) =>\n\t\t\tObject.entries(where).every(\n\t\t\t\t([key, value]) => (it as Record<string, unknown>)[key] === value,\n\t\t\t),\n\t\t);\n\t}\n\n\tif (opts.sort) {\n\t\tresult = [...result].sort(makeComparator(opts.sort));\n\t}\n\n\tconst skip = opts.skip ?? 0;\n\tconst limit = opts.limit;\n\tif (skip > 0 || limit !== undefined) {\n\t\tresult = result.slice(skip, limit !== undefined ? skip + limit : undefined);\n\t}\n\n\treturn result;\n}\n\nfunction makeComparator<T extends BaseContentItem>(\n\tsort: SortOption<T>,\n): (a: T, b: T) => number {\n\tconst by = sort.by;\n\tconst dir = sort.direction === \"asc\" ? 1 : -1;\n\treturn (a, b) => {\n\t\tconst av = (a as Record<string, unknown>)[by];\n\t\tconst bv = (b as Record<string, unknown>)[by];\n\t\tif (av === bv) return 0;\n\t\tif (av === undefined) return 1;\n\t\tif (bv === undefined) return -1;\n\t\t// biome-ignore lint/suspicious/noExplicitAny: 汎用比較\n\t\treturn (av as any) > (bv as any) ? dir : -dir;\n\t};\n}\n","import type { ImageCacheAdapter, InvalidateScope } from \"./types/index\";\n\n/** `$handler()` の挙動設定。 */\nexport interface HandlerOptions {\n\t/** マウントするベースパス。デフォルト `/api/cms`。 */\n\tbasePath?: string;\n\t/** 画像プロキシのパス (basePath 相対)。デフォルト `/images/:hash`。 */\n\timagesPath?: string;\n\t/** revalidate webhook のパス (basePath 相対)。デフォルト `/revalidate`。 */\n\trevalidatePath?: string;\n\t/** Webhook 署名検証用シークレット (未指定なら検証スキップ)。 */\n\twebhookSecret?: string;\n\t/** デフォルト実装を無効化する場合 true。 */\n\tdisabled?: boolean;\n}\n\n/** `$handler()` が内部で依存する CMS 機能の最小セット。 */\nexport interface HandlerAdapter {\n\timageCache: ImageCacheAdapter;\n\t/** コレクション名で DataSource を取り出し parseWebhook にフォワードする。 */\n\tparseWebhook(\n\t\treq: Request,\n\t\twebhookSecret: string | undefined,\n\t): Promise<InvalidateScope | null>;\n\trevalidate(scope: InvalidateScope): Promise<void>;\n}\n\nconst DEFAULT_OPTS = {\n\tbasePath: \"/api/cms\",\n\timagesPath: \"/images\",\n\trevalidatePath: \"/revalidate\",\n} as const;\n\n/**\n * Web Standard な Request → Response ルーター。\n * Next.js / React Router / Hono / Cloudflare Workers いずれでも使える。\n *\n * ルート:\n * - GET `{basePath}/images/:hash` — 画像プロキシ\n * - POST `{basePath}/revalidate` — Webhook 受信 + $revalidate()\n */\nexport function createHandler(\n\tadapter: HandlerAdapter,\n\topts: HandlerOptions = {},\n): (req: Request) => Promise<Response> {\n\tconst basePath = trimTrailingSlash(opts.basePath ?? DEFAULT_OPTS.basePath);\n\tconst imagesPath = opts.imagesPath ?? DEFAULT_OPTS.imagesPath;\n\tconst revalidatePath = opts.revalidatePath ?? DEFAULT_OPTS.revalidatePath;\n\n\treturn async (req: Request): Promise<Response> => {\n\t\tconst url = new URL(req.url);\n\t\tconst path = url.pathname;\n\n\t\tif (!path.startsWith(basePath)) {\n\t\t\treturn new Response(\"Not Found\", { status: 404 });\n\t\t}\n\t\tconst rel = path.slice(basePath.length) || \"/\";\n\n\t\t// 画像: GET {basePath}/images/:hash\n\t\tif (req.method === \"GET\" && rel.startsWith(`${imagesPath}/`)) {\n\t\t\tconst hash = rel.slice(imagesPath.length + 1);\n\t\t\tif (!hash) return new Response(\"Bad Request\", { status: 400 });\n\t\t\tconst object = await adapter.imageCache.get(hash);\n\t\t\tif (!object) return new Response(\"Not Found\", { status: 404 });\n\t\t\tconst headers = new Headers();\n\t\t\tif (object.contentType) headers.set(\"content-type\", object.contentType);\n\t\t\theaders.set(\"cache-control\", \"public, max-age=31536000, immutable\");\n\t\t\treturn new Response(object.data, { headers });\n\t\t}\n\n\t\t// Revalidate: POST {basePath}/revalidate\n\t\tif (req.method === \"POST\" && rel === revalidatePath) {\n\t\t\tconst scope = await adapter.parseWebhook(req, opts.webhookSecret);\n\t\t\tif (!scope) {\n\t\t\t\treturn new Response(JSON.stringify({ ok: false, reason: \"invalid\" }), {\n\t\t\t\t\tstatus: 400,\n\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait adapter.revalidate(scope);\n\t\t\treturn new Response(JSON.stringify({ ok: true, scope }), {\n\t\t\t\tstatus: 200,\n\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t});\n\t\t}\n\n\t\treturn new Response(\"Not Found\", { status: 404 });\n\t};\n}\n\nfunction trimTrailingSlash(s: string): string {\n\treturn s.endsWith(\"/\") ? s.slice(0, -1) : s;\n}\n","import { memoryDocumentCache, memoryImageCache } from \"./cache/memory\";\nimport type { CacheConfig, CreateCMSOptions, RendererFn } from \"./types/index\";\n\n/** `nodePreset()` のオプション。 */\nexport interface NodePresetOptions {\n\t/**\n\t * キャッシュ設定。\n\t * - 省略時: memoryDocumentCache + memoryImageCache をデフォルト有効化\n\t * - `\"disabled\"`: キャッシュを完全無効化\n\t * - オブジェクト: 任意の cache adapter を差し込む\n\t */\n\tcache?: CacheConfig | \"disabled\";\n\t/** SWR の TTL (ミリ秒)。`cache` をオブジェクトで渡した場合はそちらが優先される。 */\n\tttlMs?: number;\n\t/** カスタムレンダラー。未指定時は core が @notion-headless-cms/renderer を動的ロード。 */\n\trenderer?: RendererFn;\n}\n\n/**\n * Node.js ランタイム向けの `createCMS` オプションプリセット。\n * メモリキャッシュをデフォルト有効にした `{ cache, renderer }` を返す。\n *\n * @example\n * import { createCMS, nodePreset } from \"@notion-headless-cms/core\";\n * import { cmsDataSources } from \"./generated/cms-schema\";\n *\n * const cms = createCMS({\n * ...nodePreset({ ttlMs: 5 * 60_000 }),\n * dataSources: cmsDataSources,\n * });\n */\nexport function nodePreset(\n\topts: NodePresetOptions = {},\n): Pick<CreateCMSOptions, \"cache\" | \"renderer\"> {\n\tif (opts.cache === \"disabled\") {\n\t\treturn { cache: undefined, renderer: opts.renderer };\n\t}\n\treturn {\n\t\tcache: opts.cache ?? {\n\t\t\tdocument: memoryDocumentCache(),\n\t\t\timage: memoryImageCache(),\n\t\t\tttlMs: opts.ttlMs,\n\t\t},\n\t\trenderer: opts.renderer,\n\t};\n}\n","import { noopDocumentCache, noopImageCache } from \"./cache/noop\";\nimport { CollectionClientImpl, type CollectionContext } from \"./collection\";\nimport { CMSError } from \"./errors\";\nimport { createHandler, type HandlerOptions } from \"./handler\";\nimport { mergeHooks, mergeLoggers } from \"./hooks\";\nimport { nodePreset } from \"./preset-node\";\nimport type { RenderContext } from \"./rendering\";\nimport type { RetryConfig } from \"./retry\";\nimport { DEFAULT_RETRY_CONFIG } from \"./retry\";\nimport type {\n\tBaseContentItem,\n\tCacheConfig,\n\tCachedItemList,\n\tCMSHooks,\n\tCollectionClient,\n\tCollectionSemantics,\n\tCreateCMSOptions,\n\tDataSource,\n\tDataSourceMap,\n\tDocumentCacheAdapter,\n\tImageCacheAdapter,\n\tInferDataSourceItem,\n\tInvalidateScope,\n\tLogger,\n\tLogLevel,\n\tRendererFn,\n} from \"./types/index\";\n\nconst DEFAULT_IMAGE_PROXY_BASE = \"/api/images\";\n\n/** `CMSClient<D>` — コレクション別アクセス + グローバル操作の合成型。 */\nexport type CMSClient<D extends DataSourceMap> = {\n\t[K in keyof D]: CollectionClient<InferDataSourceItem<D[K]>>;\n} & CMSGlobalOps<D>;\n\n/** `CMSClient` のグローバル名前空間。`$` プレフィックス。 */\nexport interface CMSGlobalOps<D extends DataSourceMap> {\n\t/** 登録されているコレクション名の一覧。 */\n\treadonly $collections: readonly (keyof D & string)[];\n\t/** 全コレクションまたは特定コレクションのキャッシュを無効化する。 */\n\t$revalidate(scope?: InvalidateScope): Promise<void>;\n\t/** Web Standard なルーティングハンドラ (画像プロキシ / webhook) を生成する。 */\n\t$handler(opts?: HandlerOptions): (req: Request) => Promise<Response>;\n\t/** ハッシュキーでキャッシュ画像を取得する。 */\n\t$getCachedImage(hash: string): ReturnType<ImageCacheAdapter[\"get\"]>;\n}\n\nfunction resolveDocumentCache(\n\tcache: CacheConfig | undefined,\n\t// biome-ignore lint/suspicious/noExplicitAny: 横断的に利用\n): DocumentCacheAdapter<any> {\n\tif (!cache || cache === \"disabled\" || !cache.document) {\n\t\treturn noopDocumentCache();\n\t}\n\treturn cache.document;\n}\n\nfunction resolveImageCache(cache: CacheConfig | undefined): ImageCacheAdapter {\n\tif (!cache || cache === \"disabled\" || !cache.image) {\n\t\treturn noopImageCache();\n\t}\n\treturn cache.image;\n}\n\nfunction resolveTtl(cache: CacheConfig | undefined): number | undefined {\n\tif (!cache || cache === \"disabled\") return undefined;\n\treturn cache.ttlMs;\n}\n\nfunction hasImageCacheConfigured(cache: CacheConfig | undefined): boolean {\n\tif (!cache || cache === \"disabled\") return false;\n\treturn !!cache.image;\n}\n\n/**\n * `{collection}:{slug}` キー空間で動作するコレクション別キャッシュビューを生成する。\n * 単一の `DocumentCacheAdapter` に複数コレクションを同居させるためのアダプタ。\n */\nfunction scopeDocumentCache<T extends BaseContentItem>(\n\t// biome-ignore lint/suspicious/noExplicitAny: 共有ストレージのため\n\tbase: DocumentCacheAdapter<any>,\n\tcollection: string,\n): DocumentCacheAdapter<T> {\n\tconst itemKey = (slug: string): string => `${collection}:${slug}`;\n\t// リストはコレクション別にクロージャ変数で管理する。\n\t// base.getList/setList はコレクション名前空間を持たないため、\n\t// 複数コレクションが同じ base を共有すると上書きし合うバグが起きる。\n\t// 初回アクセスのみ base から読み込むことで pre-populate されたキャッシュを活かしつつ、\n\t// 以降の読み書きはコレクション固有のスロットに限定する。\n\tlet listSlot: CachedItemList<T> | null = null;\n\tlet listInitialized = false;\n\n\treturn {\n\t\tname: `${base.name}@${collection}`,\n\t\tgetList: async () => {\n\t\t\tif (!listInitialized) {\n\t\t\t\tlistInitialized = true;\n\t\t\t\tlistSlot = (await base.getList()) as CachedItemList<T> | null;\n\t\t\t}\n\t\t\treturn listSlot;\n\t\t},\n\t\tsetList: (data) => {\n\t\t\tlistSlot = data as CachedItemList<T>;\n\t\t\tlistInitialized = true;\n\t\t\treturn Promise.resolve();\n\t\t},\n\t\tgetItem: (slug) => base.getItem(itemKey(slug)),\n\t\tsetItem: (slug, data) => base.setItem(itemKey(slug), data),\n\t\tasync invalidate(scope) {\n\t\t\tlistSlot = null;\n\t\t\tlistInitialized = true; // 無効化後は base を再読みしない\n\t\t\tif (!base.invalidate) return;\n\t\t\tif (scope === \"all\") {\n\t\t\t\treturn base.invalidate({ collection });\n\t\t\t}\n\t\t\tif (\"slug\" in scope) {\n\t\t\t\t// アイテムは `{collection}:{slug}` で保存されるため正しいキーに変換する\n\t\t\t\treturn base.invalidate({\n\t\t\t\t\tcollection: scope.collection,\n\t\t\t\t\tslug: itemKey(scope.slug),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn base.invalidate(scope);\n\t\t},\n\t};\n}\n\nconst LOG_LEVEL_ORDER: Record<LogLevel, number> = {\n\tdebug: 0,\n\tinfo: 1,\n\twarn: 2,\n\terror: 3,\n};\n\n/** `logger` から `minLevel` 未満のレベルを除いた新しい Logger を返す。 */\nfunction applyLogLevel(\n\tlogger: Logger | undefined,\n\tminLevel: LogLevel,\n): Logger | undefined {\n\tif (!logger) return undefined;\n\tconst minOrder = LOG_LEVEL_ORDER[minLevel];\n\tconst filtered: Logger = {};\n\tfor (const level of [\"debug\", \"info\", \"warn\", \"error\"] as const) {\n\t\tif (LOG_LEVEL_ORDER[level] >= minOrder) {\n\t\t\tfiltered[level] = logger[level];\n\t\t}\n\t}\n\treturn filtered;\n}\n\n/**\n * `preset` オプションを解決して `cache` / `renderer` のデフォルトを補完する内部関数。\n * 明示的な `cache` / `renderer` がある場合はそちらが優先される。\n * `preset` 未指定時は opts をそのまま返す。\n */\nfunction resolvePreset<D extends DataSourceMap>(\n\topts: CreateCMSOptions<D>,\n): CreateCMSOptions<D> {\n\tif (opts.preset === \"disabled\") {\n\t\treturn { ...opts, cache: undefined };\n\t}\n\tif (opts.preset === \"node\") {\n\t\tconst presetResult = nodePreset({ ttlMs: opts.ttlMs });\n\t\treturn {\n\t\t\t...opts,\n\t\t\tcache: opts.cache ?? presetResult.cache,\n\t\t\trenderer: opts.renderer ?? presetResult.renderer,\n\t\t};\n\t}\n\treturn opts;\n}\n\n/**\n * 複数の DataSource を束ねた CMS クライアントを生成する。\n *\n * @example\n * // Node.js(preset を使った簡潔な記法)\n * const cms = createCMS({ dataSources: cmsDataSources, preset: \"node\", ttlMs: 5 * 60_000 });\n *\n * @example\n * // 従来の spread パターン(引き続き動作する)\n * const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources: cmsDataSources });\n *\n * @example\n * // キャッシュを細かく指定する場合\n * const cms = createCMS({\n * dataSources,\n * cache: { document, image, ttlMs: 60_000 },\n * });\n */\nexport function createCMS<D extends DataSourceMap>(\n\topts: CreateCMSOptions<D>,\n): CMSClient<D> {\n\tif (!opts.dataSources || Object.keys(opts.dataSources).length === 0) {\n\t\tthrow new CMSError({\n\t\t\tcode: \"core/config_invalid\",\n\t\t\tmessage:\n\t\t\t\t\"createCMS: dataSources に少なくとも1つのコレクションを指定してください。\",\n\t\t\tcontext: { operation: \"createCMS\" },\n\t\t});\n\t}\n\n\t// collections が指定されたコレクションは slug が必須。\n\tfor (const [name, col] of Object.entries(opts.collections ?? {})) {\n\t\tconst c = col as CollectionSemantics | undefined;\n\t\tif (c && !c.slug) {\n\t\t\tthrow new CMSError({\n\t\t\t\tcode: \"core/config_invalid\",\n\t\t\t\tmessage: `createCMS: コレクション \"${name}\" の collections.slug は必須です。slug として使うフィールド名を指定してください。`,\n\t\t\t\tcontext: { operation: \"createCMS\", collection: name },\n\t\t\t});\n\t\t}\n\t}\n\n\tconst resolved = resolvePreset(opts);\n\n\tconst baseDocCache = resolveDocumentCache(resolved.cache);\n\tconst imgCache = resolveImageCache(resolved.cache);\n\tconst hasImageCache = hasImageCacheConfigured(resolved.cache);\n\tconst ttlMs = resolveTtl(resolved.cache);\n\tconst imageProxyBase =\n\t\topts.content?.imageProxyBase ?? DEFAULT_IMAGE_PROXY_BASE;\n\tconst contentConfig = opts.content;\n\tconst rendererFn: RendererFn | undefined = resolved.renderer;\n\tconst waitUntil = opts.waitUntil;\n\tconst baseLogger: Logger | undefined = mergeLoggers(\n\t\topts.plugins ?? [],\n\t\topts.logger,\n\t);\n\tconst logger = opts.logLevel\n\t\t? applyLogLevel(baseLogger, opts.logLevel)\n\t\t: baseLogger;\n\tconst hooks: CMSHooks<BaseContentItem> = mergeHooks(\n\t\topts.plugins ?? [],\n\t\topts.hooks,\n\t\tlogger,\n\t);\n\tconst maxConcurrent = opts.rateLimiter?.maxConcurrent ?? 3;\n\tconst retryConfig: RetryConfig = {\n\t\t...DEFAULT_RETRY_CONFIG,\n\t\t...(opts.rateLimiter ?? {}),\n\t};\n\n\tconst collectionNames = Object.keys(opts.dataSources) as (keyof D & string)[];\n\n\t// biome-ignore lint/suspicious/noExplicitAny: 各 T を保持\n\tconst collections: Record<string, CollectionClient<any>> = {};\n\t// biome-ignore lint/suspicious/noExplicitAny: 横断的に利用\n\tconst scopedCaches: DocumentCacheAdapter<any>[] = [];\n\tfor (const name of collectionNames) {\n\t\tconst source = opts.dataSources[name] as DataSource<BaseContentItem>;\n\t\tconst scopedCache = scopeDocumentCache<BaseContentItem>(baseDocCache, name);\n\t\tscopedCaches.push(scopedCache);\n\t\tconst col = opts.collections?.[name] as CollectionSemantics | undefined;\n\t\tconst colHooks = col?.hooks as CMSHooks<BaseContentItem> | undefined;\n\t\tconst collectionHooks: CMSHooks<BaseContentItem> = colHooks\n\t\t\t? mergeHooks([{ name: `${name}:global`, hooks }], colHooks, logger)\n\t\t\t: hooks;\n\t\tconst renderCtx: RenderContext<BaseContentItem> = {\n\t\t\tsource,\n\t\t\trendererFn,\n\t\t\timgCache,\n\t\t\thasImageCache,\n\t\t\timageProxyBase,\n\t\t\tcontentConfig,\n\t\t\thooks: collectionHooks,\n\t\t\tlogger,\n\t\t};\n\t\tconst ctx: CollectionContext<BaseContentItem> = {\n\t\t\tcollection: name,\n\t\t\tsource,\n\t\t\tdocCache: scopedCache,\n\t\t\trender: renderCtx,\n\t\t\thooks: collectionHooks,\n\t\t\tlogger,\n\t\t\tttlMs,\n\t\t\t// 公開条件は CollectionSemantics(createCMS の collections オプション)が権威\n\t\t\tpublishedStatuses: col?.publishedStatuses\n\t\t\t\t? [...col.publishedStatuses]\n\t\t\t\t: [],\n\t\t\taccessibleStatuses: col?.accessibleStatuses\n\t\t\t\t? [...col.accessibleStatuses]\n\t\t\t\t: [],\n\t\t\tretryConfig,\n\t\t\tmaxConcurrent,\n\t\t\twaitUntil,\n\t\t\tslugField: col?.slug,\n\t\t};\n\t\tcollections[name] = new CollectionClientImpl(ctx);\n\t}\n\n\tconst globalOps: CMSGlobalOps<D> = {\n\t\t$collections: collectionNames,\n\t\tasync $revalidate(scope?: InvalidateScope): Promise<void> {\n\t\t\tlogger?.debug?.(\"グローバルキャッシュを無効化\", {\n\t\t\t\toperation: \"$revalidate\",\n\t\t\t\tcacheAdapter: baseDocCache.name,\n\t\t\t});\n\t\t\t// baseDocCache を直接呼ばず各スコープキャッシュ経由で呼ぶ。\n\t\t\t// 直接呼ぶと scopeDocumentCache の listSlot がクリアされず stale になる。\n\t\t\tfor (const cache of scopedCaches) {\n\t\t\t\tif (!cache.invalidate) continue;\n\t\t\t\tawait cache.invalidate(scope ?? \"all\");\n\t\t\t}\n\t\t},\n\t\t$handler(handlerOpts?: HandlerOptions) {\n\t\t\treturn createHandler(\n\t\t\t\t{\n\t\t\t\t\timageCache: imgCache,\n\t\t\t\t\tparseWebhook: async (req, webhookSecret) => {\n\t\t\t\t\t\t// 各 DataSource の parseWebhook を順に試す\n\t\t\t\t\t\tfor (const name of collectionNames) {\n\t\t\t\t\t\t\tconst ds = opts.dataSources[name] as DataSource<BaseContentItem>;\n\t\t\t\t\t\t\tif (ds.parseWebhook) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst scope = await ds.parseWebhook(req.clone(), {\n\t\t\t\t\t\t\t\t\t\tsecret: webhookSecret,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn scope;\n\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\tlogger?.warn?.(\"parseWebhook 失敗\", {\n\t\t\t\t\t\t\t\t\t\tcollection: name,\n\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// フォールバック: { slug } だけの汎用 JSON body\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst body = (await req.json()) as {\n\t\t\t\t\t\t\t\tslug?: string;\n\t\t\t\t\t\t\t\tcollection?: string;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tif (body.slug && body.collection) {\n\t\t\t\t\t\t\t\treturn { collection: body.collection, slug: body.slug };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (body.collection) {\n\t\t\t\t\t\t\t\treturn { collection: body.collection };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// ignore\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t},\n\t\t\t\t\trevalidate: (scope) => globalOps.$revalidate(scope),\n\t\t\t\t},\n\t\t\t\thandlerOpts,\n\t\t\t);\n\t\t},\n\t\t$getCachedImage(hash) {\n\t\t\treturn imgCache.get(hash);\n\t\t},\n\t};\n\n\treturn Object.assign(\n\t\tObject.create(null) as object,\n\t\tcollections,\n\t\tglobalOps,\n\t) as CMSClient<D>;\n}\n","import type { BaseContentItem } from \"./content\";\nimport type { CMSHooks } from \"./hooks\";\nimport type { Logger } from \"./logger\";\n\nexport interface CMSPlugin<T extends BaseContentItem = BaseContentItem> {\n\tname: string;\n\thooks?: CMSHooks<T>;\n\tlogger?: Partial<Logger>;\n}\n\nexport function definePlugin<T extends BaseContentItem>(\n\tplugin: CMSPlugin<T>,\n): CMSPlugin<T> {\n\treturn plugin;\n}\n"],"mappings":";;;;;;AACA,eAAsB,UAAU,OAAgC;CAC/D,MAAM,OAAO,IAAI,aAAa,CAAC,OAAO,MAAM;CAC5C,MAAM,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AACxD,QAAO,MAAM,KAAK,IAAI,WAAW,KAAK,CAAC,CACrC,KAAK,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAC3C,KAAK,GAAG;;;;;;AAOX,SAAgB,QAAQ,UAAkB,OAAyB;AAClE,KAAI,UAAU,KAAA,EAAW,QAAO;AAChC,QAAO,KAAK,KAAK,GAAG,WAAW;;;;;ACVhC,SAAS,iBACR,KACA,qBACS;AACT,KAAI,qBAAqB,WAAW,SAAS,CAC5C,QAAO,oBAAoB,MAAM,IAAI,CAAC,GAAG,MAAM;AA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