@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/cache/memory.d.mts +2 -50
- package/dist/cache/memory.mjs +59 -45
- package/dist/cache/memory.mjs.map +1 -1
- package/dist/{content-DyrOwjbA.d.mts → content-Bffid8da.d.mts} +6 -16
- package/dist/{hooks-CPRRo9IN.d.mts → hooks-CqqVxrYg.d.mts} +2 -2
- package/dist/hooks.d.mts +1 -1
- package/dist/index.d.mts +158 -306
- package/dist/index.mjs +262 -364
- package/dist/index.mjs.map +1 -1
- package/dist/memory-CA1uTRbr.d.mts +146 -0
- package/package.json +4 -8
- package/dist/cache/noop.d.mts +0 -11
- package/dist/cache/noop.mjs +0 -50
- package/dist/cache/noop.mjs.map +0 -1
- package/dist/cache-QrXdXYMs.d.mts +0 -170
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { a as CachedItemMeta, c as
|
|
2
|
-
import { a as
|
|
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-
|
|
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
|
-
|
|
12
|
+
dir?: "asc" | "desc";
|
|
15
13
|
}
|
|
16
|
-
/** `
|
|
17
|
-
interface
|
|
14
|
+
/** `list()` のオプション。ページ取得に必要な絞り込み・ソート・ページングを表現する。 */
|
|
15
|
+
interface ListOptions<T extends BaseContentItem = BaseContentItem> {
|
|
18
16
|
/** ステータス絞り込み (`publishedStatuses` を上書き)。 */
|
|
19
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
* `
|
|
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
|
-
|
|
42
|
+
type ItemWithRender<T extends BaseContentItem> = T & {
|
|
82
43
|
/**
|
|
83
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
96
|
-
* `
|
|
97
|
-
* クライアントから fetcher として直接呼べる。本文は含まれない。
|
|
61
|
+
* 指定 slug、または slug 省略時はコレクション全体のキャッシュを失効させる。
|
|
62
|
+
* 次回 `get` / `list` で source から再取得される。
|
|
98
63
|
*/
|
|
99
|
-
|
|
64
|
+
invalidate(slug?: string): Promise<void>;
|
|
100
65
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* 関数を含まない pure JSON を返す。
|
|
66
|
+
* 全アイテムを並列に事前取得・レンダリングしてキャッシュに格納する。
|
|
67
|
+
* SSG ビルド前のウォームアップに利用する。
|
|
104
68
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* バックグラウンドで再生成を発火する(`waitUntil` あり時)。
|
|
87
|
+
* SWR: TTL 未設定 or 期限内ならキャッシュ即時返却 + バックグラウンド差分チェック。
|
|
88
|
+
* TTL 期限切れ、または `opts.fresh === true` でブロッキング取得。
|
|
132
89
|
*
|
|
133
|
-
*
|
|
134
|
-
* `mutate(contentKey)` を呼べば透過的に最新化される。
|
|
90
|
+
* @returns キャッシュまたは source から取得したアイテム。存在しない場合は null。
|
|
135
91
|
*/
|
|
136
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
* `
|
|
205
|
-
* `
|
|
206
|
-
* `CMSHooks<Post>` などを直接記述する必要がなくなる。
|
|
146
|
+
* `source` は notion-orm 等の DataSource 実装。
|
|
147
|
+
* `slugField` / `statusField` は TS フィールド名 (DataSource の `properties` キーと一致)。
|
|
207
148
|
*/
|
|
208
|
-
interface
|
|
209
|
-
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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()`
|
|
236
|
-
*
|
|
164
|
+
* `createCMS({ collections })` の map 型。
|
|
165
|
+
* キーがコレクション名、値が `CollectionDef<T>`。
|
|
237
166
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
*
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
*
|
|
262
|
-
* `
|
|
263
|
-
*
|
|
264
|
-
*
|
|
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
|
-
/**
|
|
199
|
+
/** カスタムレンダラー。未指定時は `@notion-headless-cms/renderer` の `renderMarkdown` を動的 import。 */
|
|
269
200
|
renderer?: RendererFn;
|
|
270
|
-
/**
|
|
271
|
-
|
|
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:
|
|
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<
|
|
363
|
-
type CMSClient<
|
|
268
|
+
/** `CMSClient<C>` — コレクション別アクセス + グローバル操作の合成型。 */
|
|
269
|
+
type CMSClient<C extends CollectionsConfig> = { [K in keyof C]: CollectionClient<InferCollectionItem<C[K]>> } & CMSGlobalOps;
|
|
364
270
|
/** `CMSClient` のグローバル名前空間。`$` プレフィックス。 */
|
|
365
|
-
interface CMSGlobalOps
|
|
271
|
+
interface CMSGlobalOps {
|
|
366
272
|
/** 登録されているコレクション名の一覧。 */
|
|
367
|
-
readonly $collections: readonly
|
|
368
|
-
/**
|
|
369
|
-
$
|
|
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):
|
|
279
|
+
$getCachedImage(hash: string): Promise<StorageBinary | null>;
|
|
374
280
|
}
|
|
375
281
|
/**
|
|
376
|
-
* 複数の
|
|
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
|
-
*
|
|
383
|
-
*
|
|
384
|
-
* const cms = createCMS({ ...nodePreset({ ttlMs: 5 * 60_000 }), dataSources: cmsDataSources });
|
|
284
|
+
* 通常はユーザーが直接呼ぶことはなく、CLI 生成の `nhc.ts` の `createCMS`
|
|
285
|
+
* (低レベルのこの関数をラップしたもの) を経由する。
|
|
385
286
|
*
|
|
386
287
|
* @example
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
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<
|
|
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:
|
|
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:
|
|
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
|
-
* `
|
|
451
|
-
* 設定時は `source.properties[slugField].notion` を Notion プロパティ名として
|
|
361
|
+
* slug として使うフィールド名 (CLI 生成の `CollectionDef.slugField`)。
|
|
362
|
+
* `source.properties[slugField].notion` を Notion プロパティ名として
|
|
452
363
|
* `findByProp` を呼び出す。
|
|
453
364
|
*/
|
|
454
|
-
slugField
|
|
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
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
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
|