@notion-headless-cms/core 0.3.8 → 0.3.10

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/index.d.mts CHANGED
@@ -1,8 +1,6 @@
1
- import { a as CachedItemMeta, c as ContentBlock, d as InlineNode, i as CachedItemList, l as ContentResult, n as CMSSchemaProperties, o as ItemContentPayload, r as CachedItemContent, s as StorageBinary, t as BaseContentItem, u as ImageRef } from "./content-DyrOwjbA.mjs";
2
- import { a as CollectionConfig, c as InferCollectionItem, d as PropertyDef, f as PropertyMap, i as CMSSchema, l as InvalidateKind, n as DocumentCacheAdapter, o as DataSource, p as WebhookConfig, r as ImageCacheAdapter, s as DataSourceFactory, t as CacheConfig, u as InvalidateScope } from "./cache-QrXdXYMs.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-CPRRo9IN.mjs";
4
- import { MemoryDocumentCacheOptions, MemoryImageCacheOptions, memoryDocumentCache, memoryImageCache } from "./cache/memory.mjs";
5
- import { noopDocumentCache, noopImageCache } from "./cache/noop.mjs";
1
+ import { a as CachedItemMeta, c as ContentResult, i as CachedItemList, l as ImageRef, n as CMSSchemaProperties, o as StorageBinary, r as CachedItemContent, s as ContentBlock, t as BaseContentItem, u as InlineNode } from "./content-Bffid8da.mjs";
2
+ import { a as CacheAdapter, c as DataSource, d as PropertyDef, f as PropertyMap, i as memoryCache, l as InvalidateKind, o as DocumentCacheOps, p as WebhookConfig, s as ImageCacheOps, t as MemoryCacheOptions, u as InvalidateScope } from "./memory-CA1uTRbr.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-CqqVxrYg.mjs";
6
4
  import { BuiltInCMSErrorCode, CMSError, CMSErrorCode, CMSErrorContext, isCMSError, isCMSErrorInNamespace } from "./errors.mjs";
7
5
 
8
6
  //#region src/types/collection.d.ts
@@ -11,12 +9,12 @@ interface SortOption<T extends BaseContentItem = BaseContentItem> {
11
9
  /** ソートするプロパティ名。 */
12
10
  by: keyof T & string;
13
11
  /** 昇順 / 降順。デフォルト "desc"。 */
14
- direction?: "asc" | "desc";
12
+ dir?: "asc" | "desc";
15
13
  }
16
- /** `getList` のフィルタ / ソート / ページング。 */
17
- interface GetListOptions<T extends BaseContentItem = BaseContentItem> {
14
+ /** `list()` のオプション。ページ取得に必要な絞り込み・ソート・ページングを表現する。 */
15
+ interface ListOptions<T extends BaseContentItem = BaseContentItem> {
18
16
  /** ステータス絞り込み (`publishedStatuses` を上書き)。 */
19
- statuses?: string[];
17
+ status?: string | readonly string[];
20
18
  /** プロパティ一致フィルタ (in-memory フィルタ)。 */
21
19
  where?: Partial<Record<keyof T, unknown>>;
22
20
  /** タグ絞り込み (schema に tags: string[] フィールドがある場合)。 */
@@ -28,131 +26,78 @@ interface GetListOptions<T extends BaseContentItem = BaseContentItem> {
28
26
  /** スキップ件数。 */
29
27
  skip?: number;
30
28
  }
31
- /** `adjacent` の並び順指定。 */
29
+ /** `cache.adjacent` のオプション。 */
32
30
  interface AdjacencyOptions<T extends BaseContentItem = BaseContentItem> {
33
31
  sort?: SortOption<T>;
34
32
  }
35
- /**
36
- * `getItem` の返り値(メタデータ + lazy 本文アクセサ)。
37
- * `content.html()` / `content.markdown()` / `content.blocks` を呼んだ時点で
38
- * 初めてキャッシュ層から本文をロードする(または再生成する)。
39
- */
40
- type ItemWithContent<T extends BaseContentItem> = T & {
41
- content: ContentResult;
42
- };
43
- /**
44
- * `getList` の戻り値。アイテム配列とバージョン文字列を含む。
45
- * version は DataSource.getListVersion() が生成するフィルタ済みアイテムの識別子。
46
- */
47
- interface GetListResult<T extends BaseContentItem = BaseContentItem> {
48
- items: T[];
49
- /** フィルタ適用後のアイテム群を識別するバージョン文字列。 */
50
- version: string;
33
+ /** `get()` のオプション。 */
34
+ interface GetOptions {
35
+ /** true なら TTL に関わらずブロッキングで再取得し、本文 cache を破棄する。 */
36
+ fresh?: boolean;
51
37
  }
52
38
  /**
53
- * `checkForUpdate` の戻り値。
54
- *
55
- * **本文(HTML 等)は含めない**。差分判定はメタデータのみで完結し、
56
- * 本文は `invalidate({ kind: "content" })` で失効 + バックグラウンド再生成される。
57
- * クライアント側 (useSWR) は `mutate(metaKey, result.meta)` と `mutate(contentKey)` を
58
- * 順に呼ぶことで透過的に最新化できる。
59
- */
60
- type CheckForUpdateResult<T extends BaseContentItem = BaseContentItem> = {
61
- changed: false;
62
- } | {
63
- changed: true;
64
- meta: T;
65
- };
66
- /**
67
- * `checkListForUpdate` の戻り値。
68
- * changed: true の場合は最新のアイテム配列とバージョンを含む。
69
- */
70
- type CheckListForUpdateResult<T extends BaseContentItem = BaseContentItem> = {
71
- changed: false;
72
- } | {
73
- changed: true;
74
- items: T[];
75
- version: string;
76
- };
77
- /**
78
- * コレクション別の CMS クライアント。
79
- * `cms.posts.getItem(slug)` のようにアクセスする。
39
+ * `get()` の戻り値。アイテム本体に `render()` が生える。
40
+ * `render()` を呼んだ時点で初めて本文をロードする lazy 設計。
80
41
  */
81
- interface CollectionClient<T extends BaseContentItem = BaseContentItem> {
42
+ type ItemWithRender<T extends BaseContentItem> = T & {
82
43
  /**
83
- * スラッグで単件取得 (本文 lazy アクセサ付き)
84
- *
85
- * メタデータはキャッシュ or Notion から即時取得し、
86
- * 本文(html/markdown/blocks)は `result.content.*()` を呼んだ時点で初めてロードする。
87
- *
88
- * SWR: TTL 未設定 or 期限内ならキャッシュ即時返却 + バックグラウンド差分チェック。
89
- * TTL 期限切れならブロッキングフェッチ。
90
- *
91
- * @returns キャッシュまたは Notion から取得したアイテム。存在しない場合は null。
44
+ * 本文を文字列で返す。デフォルトは HTML
45
+ * `format: "markdown"` で Markdown を返す。
92
46
  */
93
- getItem(slug: string): Promise<ItemWithContent<T> | null>;
47
+ render(opts?: {
48
+ format?: "html" | "markdown";
49
+ }): Promise<string>;
50
+ };
51
+ /** `cache.warm()` のオプション。 */
52
+ interface WarmOptions {
53
+ /** 並列度。デフォルトは createCMS の rateLimiter.maxConcurrent。 */
54
+ concurrency?: number;
55
+ /** 進捗コールバック。 */
56
+ onProgress?: (done: number, total: number) => void;
57
+ }
58
+ /** コレクションごとのキャッシュ操作 namespace。 */
59
+ interface CollectionCacheOps<T extends BaseContentItem> {
94
60
  /**
95
- * メタデータのみを取得する軽量 API。
96
- * `useSWR("/api/.../meta", () => cms.posts.getItemMeta(slug))` のような形で
97
- * クライアントから fetcher として直接呼べる。本文は含まれない。
61
+ * 指定 slug、または slug 省略時はコレクション全体のキャッシュを失効させる。
62
+ * 次回 `get` / `list` source から再取得される。
98
63
  */
99
- getItemMeta(slug: string): Promise<T | null>;
64
+ invalidate(slug?: string): Promise<void>;
100
65
  /**
101
- * 本文ペイロード(html/markdown/blocks)を取得する。
102
- * `useSWR("/api/.../content", () => cms.posts.getItemContent(slug))` で利用。
103
- * 関数を含まない pure JSON を返す。
66
+ * 全アイテムを並列に事前取得・レンダリングしてキャッシュに格納する。
67
+ * SSG ビルド前のウォームアップに利用する。
104
68
  */
105
- getItemContent(slug: string): Promise<ItemContentPayload | null>;
106
- /** 公開済みアイテム一覧 (本文なし、一覧ページ向け)。items とバージョン文字列を返す。 */
107
- getList(opts?: GetListOptions<T>): Promise<GetListResult<T>>;
108
- /** Next App Router の `generateStaticParams` 向け。 */
109
- getStaticParams(): Promise<{
110
- slug: string;
111
- }[]>;
112
- /** SSG のパス一覧 (スラッグ配列)。 */
113
- getStaticPaths(): Promise<string[]>;
114
- /** 前後記事のナビゲーション。 */
69
+ warm(opts?: WarmOptions): Promise<{
70
+ ok: number;
71
+ failed: number;
72
+ }>;
73
+ /** 前後アイテムのナビゲーション (リスト順序ベース) */
115
74
  adjacent(slug: string, opts?: AdjacencyOptions<T>): Promise<{
116
75
  prev: T | null;
117
76
  next: T | null;
118
77
  }>;
78
+ }
79
+ /**
80
+ * コレクション別の CMS クライアント。
81
+ * `cms.posts.get(slug)` / `cms.posts.list()` のようにアクセスする。
82
+ */
83
+ interface CollectionClient<T extends BaseContentItem = BaseContentItem> {
119
84
  /**
120
- * 指定スラッグのアイテムキャッシュを無効化する(メタ + 本文両方)。
121
- * 次回の getItem 呼び出しで Notion から再取得される。
122
- */
123
- revalidate(slug: string): Promise<void>;
124
- /** コレクション全体のキャッシュを無効化する。 */
125
- revalidateAll(): Promise<void>;
126
- /**
127
- * 指定アイテムが since 以降に更新されたか確認する。
85
+ * スラッグで単件取得。アイテム本体に `render()` が生える。
128
86
  *
129
- * メタデータのみを比較する軽量 API(本文 cache は破棄しない)。
130
- * 差分があれば本文 cache `kind: "content"` で失効させ、
131
- * バックグラウンドで再生成を発火する(`waitUntil` あり時)。
87
+ * SWR: TTL 未設定 or 期限内ならキャッシュ即時返却 + バックグラウンド差分チェック。
88
+ * TTL 期限切れ、または `opts.fresh === true` でブロッキング取得。
132
89
  *
133
- * クライアント側 (useSWR) は戻り値の meta で `mutate(metaKey, meta)` し、
134
- * `mutate(contentKey)` を呼べば透過的に最新化される。
90
+ * @returns キャッシュまたは source から取得したアイテム。存在しない場合は null。
135
91
  */
136
- checkForUpdate(args: {
92
+ get(slug: string, opts?: GetOptions): Promise<ItemWithRender<T> | null>;
93
+ /** 公開済みアイテム一覧を取得する。 */
94
+ list(opts?: ListOptions<T>): Promise<T[]>;
95
+ /** SSG パラメータ生成 (Next App Router の `generateStaticParams` 互換)。 */
96
+ params(): Promise<{
137
97
  slug: string;
138
- since: string;
139
- }): Promise<CheckForUpdateResult<T>>;
140
- /**
141
- * リスト全体が since 以降に更新されたか確認する。
142
- * 差分があった場合のみリストキャッシュを書き換える(本文 cache は触らない)。
143
- */
144
- checkListForUpdate(args: {
145
- since: string;
146
- filter?: GetListOptions<T>;
147
- }): Promise<CheckListForUpdateResult<T>>;
148
- /** 全コンテンツをプリフェッチしてキャッシュ(メタ + 本文)に保存。 */
149
- prefetch(opts?: {
150
- concurrency?: number;
151
- onProgress?: (done: number, total: number) => void;
152
- }): Promise<{
153
- ok: number;
154
- failed: number;
155
- }>;
98
+ }[]>;
99
+ /** キャッシュ操作 namespace。 */
100
+ cache: CollectionCacheOps<T>;
156
101
  }
157
102
  //#endregion
158
103
  //#region src/types/config.d.ts
@@ -195,83 +140,67 @@ interface RateLimiterConfig {
195
140
  /** リトライ時の基準待機時間(ミリ秒)。デフォルト: 1000 */
196
141
  baseDelayMs?: number;
197
142
  }
198
- /** `createCMS({ dataSources })` の map 型。 */
199
- type DataSourceMap = Record<string, DataSource<any>>;
200
143
  /**
201
- * コレクション別のページ構成セマンティクス。
202
- * `createCMS({ collections: { posts: { ... } } })` に渡す。
144
+ * コレクション 1 件の定義。CLI が生成する `nhc.ts` から `createCMS` に渡される。
203
145
  *
204
- * `T` を指定するとコレクション固有の型付きフックを定義できる。
205
- * `createCMS` `dataSources` から `T` が自動推論されるため、アプリ側が
206
- * `CMSHooks<Post>` などを直接記述する必要がなくなる。
146
+ * `source` は notion-orm 等の DataSource 実装。
147
+ * `slugField` / `statusField` TS フィールド名 (DataSource の `properties` キーと一致)。
207
148
  */
208
- interface CollectionSemantics<T extends BaseContentItem = BaseContentItem> {
209
- /**
210
- * slug として使うフィールド名(必須)。
211
- * DataSource `properties` マップのキーと一致させる。
212
- */
213
- slug: string;
214
- /** status として使うフィールド名。 */
215
- status?: string;
216
- /**
217
- * 公開扱いするステータス値。DataSource 側の `publishedStatuses` より優先される。
218
- * 例: ["公開済み", "Published"]
219
- */
149
+ interface CollectionDef<T extends BaseContentItem = BaseContentItem> {
150
+ /** Notion etc. のデータソース実装。 */
151
+ source: DataSource<T>;
152
+ /** slug として使う TS フィールド名 (必須)。`source.properties[slugField]` で Notion プロパティ名を解決する。 */
153
+ slugField: string;
154
+ /** ステータスとして使う TS フィールド名。 */
155
+ statusField?: string;
156
+ /** 公開扱いするステータス値。`list()` のデフォルト絞り込みに使う。 */
220
157
  publishedStatuses?: readonly string[];
221
- /**
222
- * アクセス許可するステータス値。DataSource 側の `accessibleStatuses` より優先される。
223
- */
158
+ /** アクセス許可するステータス値。`get()` の閲覧可否判定に使う。 */
224
159
  accessibleStatuses?: readonly string[];
225
- /**
226
- * コレクション固有のライフサイクルフック。
227
- * トップレベルの `hooks` と合成して実行される(グローバルフック → コレクションフックの順)。
228
- * `T` が確定しているため `item.item.myField` など独自フィールドに型安全にアクセスできる。
229
- */
160
+ /** コレクション固有のライフサイクルフック。グローバル hooks の後に実行される。 */
230
161
  hooks?: CMSHooks<T>;
231
162
  }
232
- /** `DataSourceMap` から各 T を抽出するユーティリティ型。 */
233
- type InferDataSourceItem<D> = D extends DataSource<infer T> ? T : BaseContentItem;
234
163
  /**
235
- * `createCMS()` に渡すオプション。v1 の正式な入力シグネチャ。
236
- * ユーザーは `nhc generate` が生成した `cmsDataSources` を渡すだけ。
164
+ * `createCMS({ collections })` map 型。
165
+ * キーがコレクション名、値が `CollectionDef<T>`。
237
166
  */
238
- interface CreateCMSOptions<D extends DataSourceMap = DataSourceMap> {
239
- /** コレクション名 DataSource のマップ (CLI 生成の `cmsDataSources`)。 */
240
- dataSources: D;
241
- /**
242
- * ランタイムプリセット。`cache` / `renderer` のデフォルトを自動設定する。
243
- *
244
- * - `"node"`: Node.js 向け。`memoryDocumentCache` + `memoryImageCache` を有効化。
245
- * `ttlMs` と組み合わせて SWR の TTL を設定できる。
246
- * - `"disabled"`: キャッシュを完全無効化する。
247
- * - 省略: 従来の動作(`cache` / `renderer` をそのまま使用)。
248
- * `...nodePreset({ ttlMs })` のスプレッドパターンも引き続き動作する。
249
- *
250
- * `cache` を明示的に指定した場合は `preset` より `cache` が優先される。
251
- *
252
- * @example
253
- * // Before(スプレッドが必要だった)
254
- * const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources });
255
- *
256
- * // After
257
- * const cms = createCMS({ dataSources, preset: "node", ttlMs: 5 * 60_000 });
258
- */
259
- preset?: "node" | "disabled";
167
+ type CollectionsConfig = Record<string, CollectionDef<any>>;
168
+ /** `CollectionsConfig` から各 T を抽出するユーティリティ型。 */
169
+ type InferCollectionItem<C> = C extends CollectionDef<infer T> ? T : BaseContentItem;
170
+ /**
171
+ * `createCMS()` の入力。
172
+ * 通常は CLI が生成した `nhc.ts` の `createCMS` がこの型をラップする。
173
+ *
174
+ * @example
175
+ * createCMS({
176
+ * collections: {
177
+ * posts: {
178
+ * source: createNotionCollection({ token, dataSourceId, properties }),
179
+ * slugField: "slug",
180
+ * statusField: "status",
181
+ * publishedStatuses: ["公開済み"],
182
+ * }
183
+ * },
184
+ * cache: memoryCache({ ttlMs: 5 * 60_000 }),
185
+ * });
186
+ */
187
+ interface CreateCMSOptions<C extends CollectionsConfig = CollectionsConfig> {
188
+ /** コレクション定義のマップ。 */
189
+ collections: C;
260
190
  /**
261
- * SWR キャッシュの有効期間(ミリ秒)。`preset` と組み合わせて使用する。
262
- * `cache` オブジェクトを直接渡す場合は `cache.ttlMs` を使用すること。
263
- *
264
- * @example
265
- * const cms = createCMS({ dataSources, preset: "node", ttlMs: 5 * 60_000 });
191
+ * キャッシュアダプタ (単体または配列)。未指定時はキャッシュなし。
192
+ * - `memoryCache()` のように doc + image 両方を担当するもの
193
+ * - `r2Cache()` (image のみ)、`kvCache()` (doc のみ) のように片側のみ担当するもの
194
+ * - 配列で組み合わせると、各 adapter の `handles` で振り分けられる
266
195
  */
196
+ cache?: CacheAdapter | readonly CacheAdapter[];
197
+ /** SWR の有効期間 (ミリ秒)。未設定時は TTL なし (失効まで stale を返す)。 */
267
198
  ttlMs?: number;
268
- /** レンダラー関数。未指定時は @notion-headless-cms/renderer の renderMarkdown を使用。 */
199
+ /** カスタムレンダラー。未指定時は `@notion-headless-cms/renderer``renderMarkdown` を動的 import。 */
269
200
  renderer?: RendererFn;
270
- /** キャッシュ設定。未設定時はキャッシュなし。 */
271
- cache?: CacheConfig;
272
- /** レンダリング・コンテンツ処理設定。 */
273
- content?: ContentConfig;
274
- /** Cloudflare Workers の waitUntil に相当する非同期処理の登録関数。 */
201
+ /** 画像プロキシのベース URL。デフォルト `/api/images`。 */
202
+ imageProxyBase?: string;
203
+ /** Cloudflare Workers の `waitUntil` に相当する非同期処理の登録関数。 */
275
204
  waitUntil?: (p: Promise<unknown>) => void;
276
205
  /** ライフサイクルフック (全コレクション共通)。 */
277
206
  hooks?: CMSHooks<any>;
@@ -279,43 +208,12 @@ interface CreateCMSOptions<D extends DataSourceMap = DataSourceMap> {
279
208
  plugins?: CMSPlugin<any>[];
280
209
  /** ロガー。 */
281
210
  logger?: Logger;
282
- /**
283
- * ログレベルの下限。指定したレベル未満のログを内部で抑制する。
284
- * Cloudflare Workers の Observability のように debug ログが課金対象になる環境では
285
- * `"info"` を指定すると debug ログを出力しなくなる。
286
- *
287
- * @example
288
- * createCMS({ ..., logLevel: "info" }) // debug ログを抑制
289
- */
211
+ /** ログレベルの下限。指定したレベル未満のログを内部で抑制する。 */
290
212
  logLevel?: LogLevel;
291
213
  /** レートリミット・リトライ設定。 */
292
214
  rateLimiter?: RateLimiterConfig;
293
- /**
294
- * コレクション別のページ構成セマンティクス。
295
- * slug・status・公開条件・コレクション固有フックを指定する。
296
- * 指定したコレクションでは `slug` が必須(未指定時はエラー)。
297
- * 指定したコレクションの `publishedStatuses`/`accessibleStatuses` は
298
- * DataSource 側の設定より優先される。
299
- *
300
- * `hooks` にコレクション固有フックを定義すると、`dataSources` の型から `T` が
301
- * 自動推論されるため `CMSHooks<Post>` などを直接書かずに済む。
302
- *
303
- * @example
304
- * createCMS({
305
- * dataSources: { posts: createNotionCollection<Post>({ ... }) },
306
- * collections: {
307
- * posts: {
308
- * slug: "slug",
309
- * status: "status",
310
- * publishedStatuses: ["公開済み"],
311
- * hooks: {
312
- * onCacheHit: (slug, item) => console.log(item.item.title),
313
- * },
314
- * }
315
- * }
316
- * })
317
- */
318
- collections?: { [K in keyof D]?: CollectionSemantics<InferDataSourceItem<D[K]>> };
215
+ /** レンダリング・コンテンツ処理設定。 */
216
+ content?: ContentConfig;
319
217
  }
320
218
  //#endregion
321
219
  //#region src/cache.d.ts
@@ -327,6 +225,14 @@ declare function sha256Hex(input: string): Promise<string>;
327
225
  */
328
226
  declare function isStale(cachedAt: number, ttlMs?: number): boolean;
329
227
  //#endregion
228
+ //#region src/cache/noop.d.ts
229
+ /**
230
+ * 何もキャッシュしないアダプタ。`createCMS({ cache })` 未指定時の内部デフォルト。
231
+ * テストでも使える。
232
+ */
233
+ declare const noopDocOps: DocumentCacheOps;
234
+ declare const noopImgOps: ImageCacheOps;
235
+ //#endregion
330
236
  //#region src/handler.d.ts
331
237
  /** `$handler()` の挙動設定。 */
332
238
  interface HandlerOptions {
@@ -343,7 +249,7 @@ interface HandlerOptions {
343
249
  }
344
250
  /** `$handler()` が内部で依存する CMS 機能の最小セット。 */
345
251
  interface HandlerAdapter {
346
- imageCache: ImageCacheAdapter;
252
+ imageCache: ImageCacheOps;
347
253
  /** コレクション名で DataSource を取り出し parseWebhook にフォワードする。 */
348
254
  parseWebhook(req: Request, webhookSecret: string | undefined): Promise<InvalidateScope | null>;
349
255
  revalidate(scope: InvalidateScope): Promise<void>;
@@ -359,45 +265,47 @@ interface HandlerAdapter {
359
265
  declare function createHandler(adapter: HandlerAdapter, opts?: HandlerOptions): (req: Request) => Promise<Response>;
360
266
  //#endregion
361
267
  //#region src/cms.d.ts
362
- /** `CMSClient<D>` — コレクション別アクセス + グローバル操作の合成型。 */
363
- type CMSClient<D extends DataSourceMap> = { [K in keyof D]: CollectionClient<InferDataSourceItem<D[K]>> } & CMSGlobalOps<D>;
268
+ /** `CMSClient<C>` — コレクション別アクセス + グローバル操作の合成型。 */
269
+ type CMSClient<C extends CollectionsConfig> = { [K in keyof C]: CollectionClient<InferCollectionItem<C[K]>> } & CMSGlobalOps;
364
270
  /** `CMSClient` のグローバル名前空間。`$` プレフィックス。 */
365
- interface CMSGlobalOps<D extends DataSourceMap> {
271
+ interface CMSGlobalOps {
366
272
  /** 登録されているコレクション名の一覧。 */
367
- readonly $collections: readonly (keyof D & string)[];
368
- /** 全コレクションまたは特定コレクションのキャッシュを無効化する。 */
369
- $revalidate(scope?: InvalidateScope): Promise<void>;
273
+ readonly $collections: readonly string[];
274
+ /** 全コレクションまたは特定スコープのキャッシュを無効化する。 */
275
+ $invalidate(scope?: InvalidateScope): Promise<void>;
370
276
  /** Web Standard なルーティングハンドラ (画像プロキシ / webhook) を生成する。 */
371
277
  $handler(opts?: HandlerOptions): (req: Request) => Promise<Response>;
372
278
  /** ハッシュキーでキャッシュ画像を取得する。 */
373
- $getCachedImage(hash: string): ReturnType<ImageCacheAdapter["get"]>;
279
+ $getCachedImage(hash: string): Promise<StorageBinary | null>;
374
280
  }
375
281
  /**
376
- * 複数の DataSource を束ねた CMS クライアントを生成する。
377
- *
378
- * @example
379
- * // Node.js(preset を使った簡潔な記法)
380
- * const cms = createCMS({ dataSources: cmsDataSources, preset: "node", ttlMs: 5 * 60_000 });
282
+ * 複数の `CollectionDef` を束ねた CMS クライアントを生成する。
381
283
  *
382
- * @example
383
- * // 従来の spread パターン(引き続き動作する)
384
- * const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources: cmsDataSources });
284
+ * 通常はユーザーが直接呼ぶことはなく、CLI 生成の `nhc.ts` の `createCMS`
285
+ * (低レベルのこの関数をラップしたもの) を経由する。
385
286
  *
386
287
  * @example
387
- * // キャッシュを細かく指定する場合
388
- * const cms = createCMS({
389
- * dataSources,
390
- * cache: { document, image, ttlMs: 60_000 },
288
+ * createCMS({
289
+ * collections: {
290
+ * posts: {
291
+ * source: createNotionCollection({ token, dataSourceId, properties }),
292
+ * slugField: "slug",
293
+ * statusField: "status",
294
+ * publishedStatuses: ["公開済み"],
295
+ * }
296
+ * },
297
+ * cache: memoryCache({ ttlMs: 5 * 60_000 }),
391
298
  * });
392
299
  */
393
- declare function createCMS<D extends DataSourceMap>(opts: CreateCMSOptions<D>): CMSClient<D>;
300
+ declare function createCMS<C extends CollectionsConfig>(opts: CreateCMSOptions<C>): CMSClient<C>;
394
301
  //#endregion
395
302
  //#region src/rendering.d.ts
396
303
  /** 本文レンダリングに必要な依存を束ねたコンテキスト。 */
397
304
  interface RenderContext<T extends BaseContentItem> {
398
305
  source: DataSource<T>;
399
306
  rendererFn: RendererFn | undefined;
400
- imgCache: ImageCacheAdapter;
307
+ imgCache: ImageCacheOps;
308
+ imgCacheName: string;
401
309
  hasImageCache: boolean;
402
310
  imageProxyBase: string;
403
311
  contentConfig: ContentConfig | undefined;
@@ -429,13 +337,17 @@ declare function withRetry<T>(fn: () => Promise<T>, config: RetryConfig): Promis
429
337
  /**
430
338
  * コレクション別キャッシュキーを生成する。
431
339
  * item: `{collection}:{slug}` / list: `{collection}`
340
+ *
341
+ * (Cache adapter 内部のキー戦略はアダプタごとに異なるが、
342
+ * 表示や再計算用に core 側でも公開ヘルパーを提供する)
432
343
  */
433
344
  declare function collectionKey(collection: string, slug?: string): string;
434
345
  /** 単一コレクションの DataSource + SWR キャッシュ依存を束ねたコンテキスト。 */
435
346
  interface CollectionContext<T extends BaseContentItem> {
436
347
  collection: string;
437
348
  source: DataSource<T>;
438
- docCache: DocumentCacheAdapter<T>;
349
+ docCache: DocumentCacheOps;
350
+ docCacheName: string;
439
351
  render: RenderContext<T>;
440
352
  hooks: CMSHooks<T>;
441
353
  logger: Logger | undefined;
@@ -446,52 +358,25 @@ interface CollectionContext<T extends BaseContentItem> {
446
358
  maxConcurrent: number;
447
359
  waitUntil: ((p: Promise<unknown>) => void) | undefined;
448
360
  /**
449
- * slug として使うフィールド名。
450
- * `createCMS({ collections })` で指定した値。
451
- * 設定時は `source.properties[slugField].notion` を Notion プロパティ名として
361
+ * slug として使うフィールド名 (CLI 生成の `CollectionDef.slugField`)。
362
+ * `source.properties[slugField].notion` Notion プロパティ名として
452
363
  * `findByProp` を呼び出す。
453
364
  */
454
- slugField?: string;
365
+ slugField: string;
455
366
  }
456
367
  /** CollectionClient の実装。ユーザーは `createCMS` 経由でインスタンスを受け取る。 */
457
368
  declare class CollectionClientImpl<T extends BaseContentItem> implements CollectionClient<T> {
458
369
  private readonly ctx;
370
+ readonly cache: CollectionCacheOps<T>;
459
371
  constructor(ctx: CollectionContext<T>);
460
- getItem(slug: string): Promise<ItemWithContent<T> | null>;
461
- getItemMeta(slug: string): Promise<T | null>;
462
- getItemContent(slug: string): Promise<ItemContentPayload | null>;
463
- getList(opts?: GetListOptions<T>): Promise<GetListResult<T>>;
464
- getStaticParams(): Promise<{
372
+ get(slug: string, opts?: GetOptions): Promise<ItemWithRender<T> | null>;
373
+ list(opts?: ListOptions<T>): Promise<T[]>;
374
+ params(): Promise<{
465
375
  slug: string;
466
376
  }[]>;
467
- getStaticPaths(): Promise<string[]>;
468
- adjacent(slug: string, opts?: AdjacencyOptions<T>): Promise<{
469
- prev: T | null;
470
- next: T | null;
471
- }>;
472
- revalidate(slug: string): Promise<void>;
473
- revalidateAll(): Promise<void>;
474
- checkForUpdate({
475
- slug,
476
- since
477
- }: {
478
- slug: string;
479
- since: string;
480
- }): Promise<CheckForUpdateResult<T>>;
481
- checkListForUpdate({
482
- since,
483
- filter
484
- }: {
485
- since: string;
486
- filter?: GetListOptions<T>;
487
- }): Promise<CheckListForUpdateResult<T>>;
488
- prefetch(opts?: {
489
- concurrency?: number;
490
- onProgress?: (done: number, total: number) => void;
491
- }): Promise<{
492
- ok: number;
493
- failed: number;
494
- }>;
377
+ private invalidateImpl;
378
+ private warmImpl;
379
+ private adjacentImpl;
495
380
  private persistMeta;
496
381
  private invalidateContent;
497
382
  /**
@@ -499,10 +384,7 @@ declare class CollectionClientImpl<T extends BaseContentItem> implements Collect
499
384
  * 再生成して書き戻す。
500
385
  */
501
386
  private loadOrBuildContent;
502
- /**
503
- * メタは既知(差分検出済み or 直前にフェッチ済み)の状態で本文だけ
504
- * バックグラウンド再生成する。エラーは握りつぶしてログのみ。
505
- */
387
+ /** メタ既知の状態で本文だけバックグラウンド再生成する。エラーは握りつぶす。 */
506
388
  private rebuildContentBg;
507
389
  private attachLazyContent;
508
390
  private fetchList;
@@ -512,35 +394,5 @@ declare class CollectionClientImpl<T extends BaseContentItem> implements Collect
512
394
  private findRaw;
513
395
  }
514
396
  //#endregion
515
- //#region src/preset-node.d.ts
516
- /** `nodePreset()` のオプション。 */
517
- interface NodePresetOptions {
518
- /**
519
- * キャッシュ設定。
520
- * - 省略時: memoryDocumentCache + memoryImageCache をデフォルト有効化
521
- * - `"disabled"`: キャッシュを完全無効化
522
- * - オブジェクト: 任意の cache adapter を差し込む
523
- */
524
- cache?: CacheConfig | "disabled";
525
- /** SWR の TTL (ミリ秒)。`cache` をオブジェクトで渡した場合はそちらが優先される。 */
526
- ttlMs?: number;
527
- /** カスタムレンダラー。未指定時は core が @notion-headless-cms/renderer を動的ロード。 */
528
- renderer?: RendererFn;
529
- }
530
- /**
531
- * Node.js ランタイム向けの `createCMS` オプションプリセット。
532
- * メモリキャッシュをデフォルト有効にした `{ cache, renderer }` を返す。
533
- *
534
- * @example
535
- * import { createCMS, nodePreset } from "@notion-headless-cms/core";
536
- * import { cmsDataSources } from "./generated/cms-schema";
537
- *
538
- * const cms = createCMS({
539
- * ...nodePreset({ ttlMs: 5 * 60_000 }),
540
- * dataSources: cmsDataSources,
541
- * });
542
- */
543
- declare function nodePreset(opts?: NodePresetOptions): Pick<CreateCMSOptions, "cache" | "renderer">;
544
- //#endregion
545
- export { type AdjacencyOptions, type BaseContentItem, type BuiltInCMSErrorCode, type CMSClient, CMSError, type CMSErrorCode, type CMSErrorContext, type CMSGlobalOps, type CMSHooks, type CMSPlugin, type CMSSchema, type CMSSchemaProperties, type CacheConfig, type CachedItemContent, type CachedItemList, type CachedItemMeta, type CheckForUpdateResult, type CheckListForUpdateResult, type CollectionClient, CollectionClientImpl, type CollectionConfig, type CollectionContext, type CollectionSemantics, type ContentBlock, type ContentConfig, type ContentResult, type CreateCMSOptions, DEFAULT_RETRY_CONFIG, type DataSource, type DataSourceFactory, type DataSourceMap, type DocumentCacheAdapter, type GetListOptions, type GetListResult, type HandlerAdapter, type HandlerOptions, type ImageCacheAdapter, type ImageRef, type InferCollectionItem, type InferDataSourceItem, type InlineNode, type InvalidateKind, type InvalidateScope, type ItemContentPayload, type ItemWithContent, type Logger, type MaybePromise, type MemoryDocumentCacheOptions, type MemoryImageCacheOptions, type NodePresetOptions, type PropertyDef, type PropertyMap, type RateLimiterConfig, type RenderOptions, type RendererFn, type RendererPluginList, type RetryConfig, type SortOption, type StorageBinary, type WebhookConfig, collectionKey, createCMS, createHandler, definePlugin, isCMSError, isCMSErrorInNamespace, isStale, memoryDocumentCache, memoryImageCache, mergeHooks, mergeLoggers, nodePreset, noopDocumentCache, noopImageCache, sha256Hex, withRetry };
397
+ export { type AdjacencyOptions, type BaseContentItem, type BuiltInCMSErrorCode, type CMSClient, CMSError, type CMSErrorCode, type CMSErrorContext, type CMSGlobalOps, type CMSHooks, type CMSPlugin, type CMSSchemaProperties, type CacheAdapter, type CachedItemContent, type CachedItemList, type CachedItemMeta, type CollectionCacheOps, type CollectionClient, CollectionClientImpl, type CollectionContext, type CollectionDef, type CollectionsConfig, type ContentBlock, type ContentConfig, type ContentResult, type CreateCMSOptions, DEFAULT_RETRY_CONFIG, type DataSource, type DocumentCacheOps, type GetOptions, type HandlerAdapter, type HandlerOptions, type ImageCacheOps, type ImageRef, type InferCollectionItem, type InlineNode, type InvalidateKind, type InvalidateScope, type ItemWithRender, type ListOptions, type LogLevel, type Logger, type MaybePromise, type MemoryCacheOptions, type PropertyDef, type PropertyMap, type RateLimiterConfig, type RenderOptions, type RendererFn, type RendererPluginList, type RetryConfig, type SortOption, type StorageBinary, type WarmOptions, type WebhookConfig, collectionKey, createCMS, createHandler, definePlugin, isCMSError, isCMSErrorInNamespace, isStale, memoryCache, mergeHooks, mergeLoggers, noopDocOps, noopImgOps, sha256Hex, withRetry };
546
398
  //# sourceMappingURL=index.d.mts.map